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_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_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];}
}


//validación de fechas
function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}
function valSep(oTxt){
	var bOk = false;
	bOk = bOk || ((oTxt.charAt(2) == "-") && (oTxt.charAt(5) == "-"));
	bOk = bOk || ((oTxt.charAt(2) == "/") && (oTxt.charAt(5) == "/"));
	return bOk;
}
function finMes(oTxt){
	var nMes = parseInt(oTxt.substr(3, 2), 10);
	var nRes = 0;
	switch (nMes){
		case 1: nRes = 31; break;
		case 2: nRes = 29; break;
		case 3: nRes = 31; break;
		case 4: nRes = 30; break;
		case 5: nRes = 31; break;
		case 6: nRes = 30; break;
		case 7: nRes = 31; break;
		case 8: nRes = 31; break;
		case 9: nRes = 30; break;
		case 10: nRes = 31; break;
		case 11: nRes = 30; break;
		case 12: nRes = 31; break;
	}
	return nRes;
}
function valDia(oTxt){
	var bOk = false;
	var nDia = parseInt(oTxt.substr(0, 2), 10);
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
	return bOk;
}
function valMes(oTxt){
	var bOk = false;
	var nMes = parseInt(oTxt.substr(3, 2), 10);
	bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	return bOk;
}
function valAno(oTxt){
	var bOk = true;
	var nAno = oTxt.substr(6);
	bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
	if (bOk){
		for (var i = 0; i < nAno.length; i++){
				bOk = bOk && esDigito(nAno.charAt(i));
			}
	}
	return bOk;
}

function valFecha(cadena){
	var bOk = true;
	var oTxt = cadena;
	if (cadena != ""){
		bOk = bOk && (valAno(oTxt));
		bOk = bOk && (valMes(oTxt));
		bOk = bOk && (valDia(oTxt));
		bOk = bOk && (valSep(oTxt));
		if (!bOk){
			alert("Fecha inválida");
			bOk = false
		}
	}
	return bOk;
}

function ventanaSecundaria (URL){
window.open(URL,"ventana1","width=500, height=350, scrollbars=no, menubar=no, location=no, resizable=no")
} 

function isEmailAddress(theElement, nombre_del_elemento,msgError )
{
	var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
		return true;
	else
		alert(msgError);
		
	theElement.focus();
	return false;
}

//validaciones
//validar autentificacion de usuario
function auth() {
  //validar que la contraseña y el email no estén vacios
  if (document.auth_login.login.value=="")  {
    alert ("Debes introducir tu email");
    document.auth_login.login.focus();
    return;
  }
  
  //validar email valido
  /*if (emailValido(document.auth.login.value)) {
    alert("El email introducido no es válido")
    return;
  }*/
  
  if (document.auth_login.pass.value=="") {
    alert ("Debes introducir una contraseña");
    document.auth_login.pass.focus();
    return;
  }
  
  document.auth_login.submit();
  
}

//validaciones
//validar autentificacion de usuario
function auth_en() {
  //validar que la contraseña y el email no estén vacios
  if (document.auth_login.login.value=="")  {
    alert ("You must fill the email");
    document.auth_login.login.focus();
    return;
  }
  
  //validar email valido
  /*if (emailValido(document.auth.login.value)) {
    alert("El email introducido no es válido")
    return;
  }*/
  
  if (document.auth_login.pass.value=="") {
    alert ("You must fill the password");
    document.auth_login.pass.focus();
    return;
  }
  
  document.auth_login.submit();
  
}


function enviarModificar() {
  document.formularioModificarDatos.submit();
}

function validarMasInformacion() {
  if (document.formularioContacto.nombre.value=="") {
    alert("Debes rellenar el nombre");
    document.formularioContacto.nombre.focus();
    return;
  }
  if (document.formularioContacto.email.value=="") {
    alert("Debes rellenar el email");
    document.formularioContacto.email.focus();
    return;
  }
  if (document.formularioContacto.telefono.value=="") {
    alert("Debes rellenar el teléfono");
    document.formularioContacto.telefono.focus();
    return;
  }
  if (document.formularioContacto.captcha_code.value=="") {
    alert("Debes rellenarlo con el código de la imagen");
    document.formularioContacto.captcha_code.focus();
    return;
  }
  document.formularioContacto.submit();
}

function validarMasInformacion_en() {
  if (document.formularioContacto.nombre.value=="") {
    alert("You must fill the name");
    document.formularioContacto.nombre.focus();
    return;
  }
  if (document.formularioContacto.email.value=="") {
    alert("You must fill the email");
    document.formularioContacto.email.focus();
    return;
  }
  if (document.formularioContacto.telefono.value=="") {
    alert("You must fill the telephone");
    document.formularioContacto.telefono.focus();
    return;
  }
  if (document.formularioContacto.captcha_code.value=="") {
    alert("You must fill the image code");
    document.formularioContacto.captcha_code.focus();
    return;
  }
  document.formularioContacto.submit();
}

function authCuenta() {
    
    //validar email valido
    /*if (emailValido(document.auth.login.value)) {
      alert("El email introducido no es válido")
      return;
    }*/
    
    if (document.cuenta.pass.value=="") {
      alert ("Debes de introducir la contraseña antigua");
      document.cuenta.pass.focus();
      return;
    }
    
    if (document.cuenta.nuevaPassword.value=="") {
      alert ("Debes de introducir la contraseña nueva");
      document.cuenta.nuevaPassword.focus();
      return;
    }
    
    if (document.cuenta.repetirPassword.value=="") {
      alert ("Debes de repetir la nueva contraseña");
      document.cuenta.Repetirpassword.focus();
      return;
    }
    if (document.cuenta.nuevaPassword.value!=document.cuenta.repetirPassword.value) {
      alert ("La nueva contraseña no coincide, vuelva a introducirlas");
      document.cuenta.nuevaPassword.value='';
      document.cuenta.repetirPassword.value='';      
      document.cuenta.password.focus();
      return;
    }
        
    document.cuenta.submit();
} 

function authCuenta_en() {
    
    //validar email valido
    /*if (emailValido(document.auth.login.value)) {
      alert("El email introducido no es válido")
      return;
    }*/
    
    if (document.cuenta.pass.value=="") {
      alert ("You must fill the old password");
      document.cuenta.pass.focus();
      return;
    }
    
    if (document.cuenta.nuevaPassword.value=="") {
      alert ("You must fill the new password");
      document.cuenta.nuevaPassword.focus();
      return;
    }
    
    if (document.cuenta.repetirPassword.value=="") {
      alert ("You must repeat the new password");
      document.cuenta.Repetirpassword.focus();
      return;
    }
    if (document.cuenta.nuevaPassword.value!=document.cuenta.repetirPassword.value) {
      alert ("Passwords must match");
      document.cuenta.nuevaPassword.value='';
      document.cuenta.repetirPassword.value='';      
      document.cuenta.password.focus();
      return;
    }
        
    document.cuenta.submit();
} 

function validarMasInformacionMaquina() {
    if (document.masInformacion.nombre.value=="") {
      alert("Debes rellenar el nombre");
      document.masInformacion.nombre.focus();
      return;
    }
    if (document.masInformacion.email.value=="") {
      alert("Debes rellenar el email");
      document.masInformacion.email.focus();
      return;
    }
    if (document.masInformacion.telefono.value=="") {
      alert("Debes rellenar el teléfono");
      document.masInformacion.telefono.focus();
      return;
    }
/*    if (document.masInformacion.captcha_code.value=="") {
	    alert("Debes rellenarlo con el código de la imagen");
	    document.masInformacion.captcha_code.focus();
	    return;
	  }*/
    document.masInformacion.submit();
}

function validarMasInformacionMaquina_en() {
    if (document.masInformacion.nombre.value=="") {
      alert("You must fill the name");
      document.masInformacion.nombre.focus();
      return;
    }
    if (document.masInformacion.email.value=="") {
      alert("You must fill the email");
      document.masInformacion.email.focus();
      return;
    }
    if (document.masInformacion.telefono.value=="") {
      alert("You must fill the telephone");
      document.masInformacion.telefono.focus();
      return;
    }
    /*if (document.masInformacion.captcha_code.value=="") {
      alert("You must fill the image code");
      document.masInformacion.captcha_code.focus();
      return;
    }    */
    document.masInformacion.submit();
}

function no_imagen2 (imagen) {
  imagen.src="<?=$appConfig['IMAGE_NOFOTO2'] ?>";
}

function no_imagen (imagen) {
  imagen.src="<?=$appConfig['IMAGE_NOFOTO'] ?>";
}

function no_imagen_en (imagen) {
  imagen.src="<?=$appConfig['IMAGE_NOFOTO_EN'] ?>";
}
function no_imagen2_en (imagen) {
  imagen.src="<?=$appConfig['IMAGE_NOFOTO2_EN'] ?>";
}

function validarRecordarContrasena() {
  if (document.formularioRecordar.email.value=="") {
    alert("Debes rellenar el email");
    document.formularioRecordar.email.focus();
    return;
  }
  if (document.formularioRecordar.captcha_code.value=="") {
    alert("Debes rellenarlo con el código de la imagen");
    document.formularioRecordar.captcha_code.focus();
    return;
  }
  
  document.formularioRecordar.submit();
}

function validarRecordarContrasena_en() {
  if (document.formularioRecordar.email.value=="") {
    alert("You must fill the email");
    document.formularioRecordar.email.focus();
    return;
  }
  if (document.formularioRecordar.captcha_code.value=="") {
    alert("You must fill the imagen code");
    document.formularioRecordar.captcha_code.focus();
    return;
  }
  
  document.formularioRecordar.submit();
}