function MM_openBrWindow(theURL,winName,features) { //v2.0
  var w=window.open(theURL,winName,features);
  w.focus();
}
function abrirVentana(url, nombre, opciones)
{
	var w=window.open(url, nombre, opciones);
	if (!w)
	{
		alert("La ventana ha sido bloqueada\r\nPara utilizar la p\xE1gina adecuadamente desactive el bloqueador de ventanas.");
		return false;
	}
	try
	{
		var sTest = w.name ;
		w.focus();
	}
	catch(e)
	{
		alert("No ha sido posible activar la nueva ventana. Revise la configuraci\xF3n de su bloqueador de ventanas.");
		return false;
	}
	return true;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MenuaIkusi() { //v6.0
  var i,p,v,obj,args=MenuaIkusi.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'':(v=='hide')?'none':v; }
	obj.display=v; }
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' Debe ser un correo electrónico.\n';
	  } else if (test!='R') {
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es necesario.\n'; }
  } if (errors) alert('Son necesarios los siguientes datos:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function Validar() {
	
	MM_validateForm('Izena','','R','PostaElektonikoa','','R','HerriaAukeratu','','R');
	return document.MM_returnValue
}
function abrirCentro(ref, w, h, opc, nombre) {
	var centro="";
	if (screen && screen.availWidth) {
		centro+=", left=" + ((screen.availWidth-w)/2);
		centro+=", top=" + ((screen.availHeight-h)/2);
	}
	w=abrirVentana(ref, nombre, "width=" + w + ",height=" +h+centro + opc);
	return false;
}
function abrirCentro2(ref, w, h, opc, nombre) {
	var centro="";
	if (screen && screen.availWidth) {
		centro+=", left=" + ((screen.availWidth-w)/2);
		centro+=", top=" + ((screen.availHeight-h)/2);
	}
	w=abrirVentana(ref, nombre, "width=" + w + ",height=" +h+centro +  " scrollbars=1");
	return false;
}
function ArgazkiaIrekiIkusi(Argazkiak) { //v2.0
		  abrirCentro("Irudia.htm?" + Argazkiak, 550, 413);
		}
function VerVideo(Video, Nombre) { //v2.0
  abrirCentro("video.asp?Video=" + Video + "&Nombre=" + Nombre, 325, 470);
}
function VerAudio(Audio, Nombre) { //v2.0
  abrirCentro("Audio.asp?Audio=" + Audio + "&Nombre=" + Nombre, 220, 80);
}
function AbrirFormulario2(OfertaId) { //v2.0
	  abrirCentro("BolsaContacto.asp?IdOferta=" + OfertaId, 414, 510);
	}
function ArgazkiHaundiaE(IdArgazkiMota, IdArgazkia) { //v2.0
	  abrirCentro("FotoAmpliada.asp?IdArgazkiMota=" + IdArgazkiMota + "&IdArgazkia=" + IdArgazkia, 600, 650);
	}
function AbrirFormulario2(OfertaId) { //v2.0
	  abrirCentro("BolsaContacto.asp?IdOferta=" + OfertaId, 414, 510);
	}
function ImprimirPromocion(IdPromocion, IdTipoPromocion) { //v2.0
	  abrirCentro2("Imprimir.asp?IdPromocion=" + IdPromocion + "&IdTipoPromocion=" + IdTipoPromocion, 800, 510);
	}
function PeticionInformacion(IdPromocion, IdTipoPromocion) { //v2.0
	  abrirCentro("PeticionInformacion.asp?IdPromocion=" + IdPromocion + "&IdTipoPromocion=" + IdTipoPromocion, 500, 400);
	}
function EnviarAmigo(IdPromocion, IdTipoPromocion) { //v2.0
	  abrirCentro("EnviarAmigo.asp?IdPromocion=" + IdPromocion + "&IdTipoPromocion=" + IdTipoPromocion, 500, 400);
	}
function AbrirVistaAerea(IdPromocion) { //v2.0
	  abrirCentro("MapaLocalizacion.asp?IdPromocion=" + IdPromocion, 520, 380);
	}
function AbrirVistaAerea2(IdLocal) { //v2.0
	  abrirCentro("MapaLocalizacion2.asp?IdLocal=" + IdLocal, 520, 380);
	}

function AbrirVistaAereaLoc() { //v2.0
  abrirCentro("MapaAerea.htm", 550, 413);
}

function AbrirImprimirLoc() { //v2.0
  abrirCentro("MapaImprimir.htm", 599, 440);
}

function VisualizarImagen (cual, cuantos) {
	var obj=cual;
	for (i=1;i<=cuantos;i++) {
		campo="Foto" + i;
		document.getElementById(campo).style.display='none';
	}
	if (obj) obj.style.display='';
}
function VisualizarVentaja (cual) {
	OcultarZona ("apertura");
	OcultarZona ("Cambio");
	OcultarZona ("Amaestramiento");
	OcultarZona ("Mantenimiento");
	var obj=cual
	if (obj) obj.style.display='';
}
function OcultarZona (Tipo) {
	document.getElementById(Tipo).style.display='none';
}

function resizeImage(im,dim,posim) {
	// Ejemplo de HTML: <div id="dv1"><img src="exprimidito.jpg" id="img1"></div>
	// im: las imagenes tienen un id en el formato img1, img2, etc. im indica el numero ('img' + im)
	// dim: la dimension que debe tener la imagen en su dimension mas corta
	// posim [no | 0 | valor (px)] :
	//		no: no mueve la imagen
	//		0: centrado
	//		valor: mueve la imagen para centrarla en la dirección de su dimensión mas larga. En pixels

	x=document.getElementById("img" + im);
	y=document.getElementById("dv" + im);

	//Tamaño de la imagen
	if (x.width >= x.height) {
		x.height = dim;
	}
	else {
		//alert(x.width);
		x.width = dim;
	}
	//Tamaño del layer
	y.style.width=dim+'px';
	y.style.height=dim+'px';
	//Posicion
	x.style.position="relative";
	y.style.overflow="hidden";
	
	if (posim == "no") return;
	if (posim == 0) {
	//Centrado por defecto
		if (x.width >= x.height) {
			x.style.left=(-(((x.width*100/x.height) - 100)/2)) + "%";
		}
		else {
			x.style.top=-(((x.height*100/x.width) - 100)/2) + "%";
		}
	}
	else {
		//Posición indicada
		if (x.width >= x.height) {
			x.style.left=-posim + 'px';
		}
		else {
			x.style.top=-posim + 'px';
		}
	}
}

function ValidarFomrCont() {
	limpio = limpia(document.Formularioa.Nombre.value);
	if (limpio == "") {
		alert("Introduce tu nombre y apellidos");
		document.Formularioa.Nombre.focus();
		return (false);
	}
	limpio = limpia(document.Formularioa.Mensaje.value);
	if (limpio == "") {
		alert("Introduce tu mensaje.");
		document.Formularioa.Mensaje.focus();
		return (false);
	}
	return (true);
}

function limpia(entry) {
  out = " "; // reemplazar lel espacio en blanco
  add = ""; // por vacio
  temp = "" + entry;

  while (temp.indexOf(out)>-1) {
	pos= temp.indexOf(out);
	temp = "" + (temp.substring(0, pos) + add + 
	temp.substring((pos + out.length), temp.length));
  }
  return(temp);
}
