function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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 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 contener una dirección de e-mail válida.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe contener un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe contener un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es necesario.\n'; }
  } if (errors) {alert('Atención:\n'+errors);}else{document.contacto.submit();};
  document.MM_returnValue = (errors == '');
}

/***********************************************/
//INICIO REDIMENSIÓN DE IFRAMES

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["iframe_1"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

function redimensiona_frame(nombre){
	if(document.getElementById(nombre))
	{
		resizeCaller();
	}
}
//FIN REDIMENSIÓN DE IFRAMES
/***********************************************/

  // ****************************************************************************
  // Valida el codigo postal
  function validarCodigoPostal(codigoPostal) {
   if ( !validarNumero(codigoPostal.value) )
	{
      alert("El Código Postal solo puede contener números");
      codigoPostal.focus();
	  return false;
	}
   if (codigoPostal.value.length < 5)
    {
      alert("El Código Postal debe de tener 5 dígitos");
      codigoPostal.focus();
	  return false;
    }
	return true;
  }
  // ****************************************************************************
  // Rules for the email regular expression:
  // The start of the email must have at least one character
  // before the @ sign
  // There may be either a . or a -, but not together before the @ sign
  // There must be an @ sign
  // At least once character must follow the @ sign
  // There may be either a . or a -, but not together in the address
  // The address must end with a && either 2 or 3 characters
  function validarEmail(myEmail) {
   var re;
   re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
   if (re.test(myEmail.value) == true) {
    return true;
   } else {
	alert('El E-Mail no está bien escrito, compruébelo.');
	myEmail.focus();
    return false;
   }
  }  
// ****************************************************************************
  // Validar url(http://_._)
  function validarUrl(url,etiquetaCampo) {
   var re;
   re = /http:...../;
   if (re.test(url.value) != true || ((url.value.indexOf("http://")==-1) || (url.value.indexOf(".")==-1)) ) 
   {
    alert('El campo "' + etiquetaCampo + '" no está bien escrito, compruébelo');
    url.focus();
    return false;
   } else {
    return true;
   }
  }
   // ****************************************************************************
  // validar si es número
  function validarNumero(numero) {
  	var valid     = "0123456789+-";
  	var ok        = true;
  	var temp;

  	for (var i=0; i<numero.length; i++) {
  		temp = "" + numero.substring(i, i+1);
  		if (valid.indexOf(temp) == "-1") ok = false;
  	}

  	if (numero == "" || !ok)
  	{
  		return false;
  	}else{
  		return true;
  	}

  }
  // ****************************************************************************
  //Para comprobar un campo es vacio o no.
  function esVacio(valor,valorNulo) {
   if(valor==valorNulo || todoVacio(valor))
    return true;
    return false
  }
  function todoVacio(valor) {
   var vacio = true;
   for (i=0;i<valor.length;i++) {
    if (valor.charAt(i)==" ")
     vacio=true;
    else {
  	  return false;
  	 }
   }
   return vacio;
  }
  // ****************************************************************************
  // Valida que se haya completado el campo
  function validacionObligatorio(campo, valorNulo, etiquetaCampo) {
   if (esVacio(campo.value,valorNulo)) {
    alert('El campo "' + etiquetaCampo + '" es obligatorio');
    campo.focus();
    return false;
   } else {
    return true;
   }
  }
  
function esFecha (fecha) {
	var expreg = /^((?:0?[1-9])|(?:[12]\d)|(?:3[01]))\/((?:0?[1-9])|(?:1[0-2]))\/((?:19|20)\d\d)$/;
	var res = expreg.test(fecha);
	if (! res) {
		alert ("Debe introducir una fecha válida. DD/MM/AA");
	}
	return res;
}
  
// ****************************************************************************
  
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1 
		c_end=document.cookie.indexOf(";",c_start)
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end))
		} 
	  }
	return ""
}
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
  
// ****************************************************************************

function imprimir() { if (window.print) window.print(); else alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" + " desde la web. Actualizate o hazlo desde los menús"); } 

function winopen(enlace,width,height,scrol) {
	window.open(enlace,'newWin','width='+width+',height='+height+',scrollbars='+scrol)
	return false
}

//Aumentar y reducir el tamaño del texto
function aumentaLetra(campo) {
	var conjunto = document.getElementById(campo).getElementsByTagName("font");
	for(var i=0;i<conjunto.length;i++)
	{
		if(conjunto[i].size < 7)
		{
			conjunto[i].size++;	
		}
	}		
}

function disminuyeLetra(campo) {
	var conjunto = document.getElementById(campo).getElementsByTagName("font");
	for(var i=0;i<conjunto.length;i++)
	{
		if(conjunto[i].size > 1)
		{
			conjunto[i].size--;	
		}
	}	
}

function recogerOpcionEncuesta() {
	var ops = document.getElementsByName("op_escogida");
	for(var i=0;i<ops.length;i++){
		if(ops[i].checked) {
			document.getElementById("encuesta_votar").href = "encuesta.php?op=1&op_escogida=" + ops[i].value;
		}
	}
}

function enviarComentario() {

	if(document.getElementById("usuario").value == "") {
		alert('Nombre ó apodo obligatorio.');
		document.getElementById("usuario").focus();
		return;
	}
	if(document.getElementById("comentario").value == "") {
		alert('Comentario obligatorio.');
		document.getElementById("comentario").focus();
		return;
	}	
	document.getElementById("valid").value = 's';	
	document.getElementById("comment_form").submit();
}

// ****************************************************************************

// highslide
function loadHighslide() {
	if(hs) {
		hs.lang.loadingText = 'Cargando...';
		hs.lang.loadingTitle = 'Haga clic para cancelar';
		hs.lang.focusTitle = 'Haga clic para ampliar';
		hs.lang.fullExpandTitle = 'Expandir a tamaño actual';
		hs.lang.previousText = 'Anterior';
		hs.lang.nextText = 'Próximo';
		hs.lang.moveText = 'Mover';
		hs.lang.closeText = 'Cerrar';
		hs.lang.closeTitle = 'Cerrar (esc)';
		hs.lang.resizeTitle = 'Redimensionar';
		hs.lang.playText = 'Ejecutar';
		hs.lang.playTitle = 'Ejecutar';
		hs.lang.pauseText = 'Pausa';
		hs.lang.pauseTitle = 'Pausa';
		hs.lang.previousTitle = 'Anterior (flecha izquierda)';
		hs.lang.nextTitle = 'Próximo (flecha derecha)';
		hs.lang.moveTitle = 'Mover';
		hs.lang.fullExpandText = 'Tamaño máximo';
		hs.lang.number = 'Imagen %1 de %2';
		hs.lang.restoreTitle = 'Haga clic para cerrar la imagen. Use las teclas de direccion para avanzar y retroceder.';
	
		hs.graphicsDir = '/highslide/graphics/';
		hs.allowMultipleInstances = false;	
		hs.showCredits = false;
		hs.objectLoadTime = 'before';
	}
}
		
// ****************************************************************************

window.onload=function(){
	//BLOQUES NIFTYCUBE
	if(document.getElementById("bloque1")) Nifty("div.bloque1","br tr bl tl fixed-height big");	
	if(document.getElementById("bloque2")) Nifty("div.bloque2","br tr bl tl fixed-height big transparent");
	if(document.getElementById("bloque3")) Nifty("div.bloque3","br tr bl tl fixed-height big");
	if(document.getElementById("bloque4")) Nifty("div.bloque4","tr tl");
	if(document.getElementById("bloque5")) Nifty("div.bloque5","br tr bl tl fixed-height big");
	if(document.getElementById("bloque6")) Nifty("div.bloque6","br tr bl tl big transparent");
	if(document.getElementById("bloque7")) Nifty("div.bloque7","none fixed-height big transparent");
}