// JavaScript Document


//Alojamiento----------------------------------------------------

function cuenta2(){ 
       document.frmAlta.Caracteres2.value=document.frmAlta.Servicios.value.length;
}

function ValidoCheck(){
if(document.frmAlta.CheckAnimales.checked){
document.frmAlta.AdminAnimales.value="si";
}else{
document.frmAlta.AdminAnimales.value="no";  
}
ValidoCheckServicios();
}


function ValidoAlojamiento(){
if (document.frmAlta.Servicios.value.length >= 1600){
  alert("El campo Servicios no puede contener mas de 1600 carácteres");
  return false;   
}

ValidoCheck();

document.frmAlta.submit();
}
//-----------------------------------------------------------------
 
function cuenta(){ 
       document.frmAlta.Caracteres.value=document.frmAlta.DescripcionLarga.value.length;	   
} 
function cuenta3(){ 
       document.frmAlta.Caracteres3.value=document.frmAlta.ComoLlegar.value.length;	   
}

function mayusculas(aqui){  
        var pepe="KarlanKas"; 
		if(aqui.name=="Nombre"){
         var maximo=2; 
		}else{
		 var maximo=6; 	
		}
        var p_mayusculas=0; 
        var palabras=aqui.value.split(" ");  
        for(a=0;a<palabras.length;a++){  
            if(palabras[a]==palabras[a].toUpperCase() && palabras[a] != "" && palabras[a].length > 3){ 
            p_mayusculas+=1; 
            } 
        }  
        if (p_mayusculas>=maximo){ 
		  if(aqui.name=="Nombre"){
           alert("Por favor desactive la tecla 'Bloq Mayús' para insertar el nombre.");
		  }else{
		   alert("Solo está permitido usar 5 palabras que estén formadas por todas sus letras en mayúsculas. Si tiene activada la tecla 'Bloq Mayús', desactívela para introducir los datos.");
		  }        
		aqui.focus();
        } 
         
    }


function ValidaDatos()
				{
					if (document.frmAlta.Nombre.value=='')
						{
							alert('Debe rellenar el campo Nombre comercial.');
							document.frmAlta.Nombre.focus();
							return;						}		
													
					if (document.frmAlta.Direccion.value=='')
						{
							alert('Debe rellenar el campo Dirección.');
							document.frmAlta.Direccion.focus();
							return;
						}	
	
	
	if (document.frmAlta.CodigoPostal.value.length < 1 ){
    alert('Debe rellenar el campo Código Postal.');
	document.frmAlta.CodigoPostal.focus();
	return false;	
	
 }else{
  
  var checkOK= "0123456789";
  var checkStr = document.frmAlta.CodigoPostal.value; 
  var allValid = true; 
  var decPoints = 0; 
  var allNum = ""; 
  
  for (i = 0; i < checkStr.length; i++) { 
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++) 
      if (ch == checkOK.charAt(j))
        break; 
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    } 
    allNum += ch; 
  } 
  
  if (!allValid) { 
    alert('El campo Código Postal solo puede contener dígitos.  No deje espacios entre los dígitos');
    document.frmAlta.CodigoPostal.focus(); 
    return (false); 
  }
  
  }  
  
  
																																			
					if (document.frmAlta.DescripcionLarga.value=='')
						{
							alert('Debe rellenar el campo Descripción larga.');
							document.frmAlta.DescripcionLarga.focus();
							return;
						}					
				  if (document.frmAlta.DescripcionLarga.value.length >= 1600){
		              alert("El campo Descripcion larga no puede contener mas de 1600 carácteres");
                	  return false;   
                 	   }					
					  if (document.frmAlta.ComoLlegar.value.length >= 1600){
		              alert("El campo Como llegar no puede contener mas de 1600 carácteres");
                	  return false;   
                 	   } 
					if (document.frmAlta.Telefono.value=='' & document.frmAlta.EMail.value=='' )
						{
							alert('Los campos Teléfono y Email están vacios, debe proporcionar algún dato de contacto rellenando almenos alguno de los dos campos.');
							document.frmAlta.Telefono.focus();
							return;
						}		
						
						
  if (document.frmAlta.Telefono.value.length > 1 ){  
  var checkOK= "0123456789";
  var checkStr = document.frmAlta.Telefono.value; 
  var allValid = true; 
  var decPoints = 0; 
  var allNum = ""; 
  
  for (i = 0; i < checkStr.length; i++) { 
    ch = checkStr.charAt(i); 
    for (j = 0; j < checkOK.length; j++) 
      if (ch == checkOK.charAt(j))
        break; 
    if (j == checkOK.length) { 
      allValid = false; 
      break; 
    } 
    allNum += ch; 
  } 
  
  if (!allValid) { 
    alert('El campo Teléfono solo puede contener dígitos. No deje espacios entre los dígitos');
    document.frmAlta.Telefono.focus(); 
    return (false); 
  }
  
  }  
					
					if(document.forms.frmAlta.EMail.value == '')
					{
					    alert('Debe introducir un Email Válido en el campo E-mail. Si no dispone de email, puede crear uno ahora mismo pulsando el vínculo "Crear una cuenta de email"');
						Divemail=document.getElementById('divEmail');
						Divemail.style.display='block';
						document.frmAlta.EMail.focus();
						return;	
					}
					
								
					if(document.forms.frmAlta.EMail.value != ''){
					var email = document.forms.frmAlta.EMail.value;
					var pos = email.indexOf("@");
					if (pos == -1)
						{
							alert('Debe introducir un valor e-mail válido en el campo E-Mail.');
							document.frmAlta.EMail.focus();
							return;
						}
					if ((pos == 0) || (pos == email.lenght-1)) 
						{
							alert('Debe introducir un valor e-mail válido en el campo E-Mail.');
							document.frmAlta.EMail.focus();
							return;
						}
					var pos2 = email.indexOf(".");
					if (pos2 == -1 || pos2 == email.lenght-1)
						{
							alert('Debe introducir un valor e-mail válido en el campo E-Mail.');
							document.frmAlta.EMail.focus();
							return;
						}
					
					for (i=0;i<email.lenght;i++)
						{
							if (email.charAt(i) == '' )
								{
									alert('Debe introducir un valor e-mail correcto en el campo E-Mail.');
									document.frmAlta.EMail.focus();
									return;
								}

						}}
					
					if (document.forms.frmAlta.ConfirmaEMail.value != document.forms.frmAlta.EMail.value)
						{
							alert('Los campos E-Mail y Confirmación E-Mail deben coincidir.');
							document.frmAlta.ConfirmaEMail.focus();
							return;
						}					
					document.frmAlta.submit();	
}
					
					
