var nav4 = window.Event ? true : false;

var nav5 = window.Event ? true : false;

//var enviado=0;

function acceptNum(evt){ 

// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 

var key = nav4 ? evt.which : evt.keyCode; 

return (key <= 13 || (key >= 48 && key <= 57));

}

function acceptLet(evt){ 

var key = nav4 ? evt.which : evt.keyCode; 

return (key <= 13 || (key >= 65 && key <= 90 || key >= 97 && key <= 122));

}



function caracteres(cad)

{

  var sh = /\d+/

  if(sh.test(cad)) 

     {//document.form1.nombre.focus();alert("es falso");

	 return false;

	 }

  else

  {//alert("es verdadero");

  return true;

  }

}



function removeExtraSpaces(string, delimiter)

{

  var returnString = "";

  splitstring = string.split(delimiter);

  for(i = 0; i < splitstring.length; i++)

    {

    if (splitstring[i]!="") returnString += splitstring[i] + delimiter;

    }

  return returnString;

}



function quita_espacios_inicio_fin(inputString, removeChar) 

{

	var returnString = inputString;

	if (removeChar.length)

	{

	  while(''+returnString.charAt(0)==removeChar)

		{

		  returnString=returnString.substring(1,returnString.length);

		}

		while(''+returnString.charAt(returnString.length-1)==removeChar)

	  {

	    returnString=returnString.substring(0,returnString.length-1);

	  }

	}

	return returnString;

}

function revmail(txt)

 {

   var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/     //alert("Email " + (b.test(txt)?"":"no ") + "válido.")

   return b.test(txt)

}

function antispam(){

var msg=quita_espacios_inicio_fin(document.form1.mensaje.value," ");

var key_w=quita_espacios_inicio_fin(document.form1.nombre.value," ");

var key2;

key2=msg.indexOf(key_w);

	if (key2!=0)

		return false;

	else

		return true;

}

function valida()

{

var nom_usu=document.form1.nombre.value;

var mail=document.form1.email.value;

var mail2=document.form1.email2.value;

var tel=document.form1.telefono.value;

var cel=document.form1.celular.value;

var noc=document.form1.noches.value;

var fec=document.form1.fecha.value;



nom_usu=removeExtraSpaces(nom_usu," "); //quita espacios repetidos

nom_usu=quita_espacios_inicio_fin(nom_usu," "); //quita espacios al principio y al final



mail=removeExtraSpaces(mail," "); //quita espacios repetidos

mail=quita_espacios_inicio_fin(mail," "); //quita espacios al principio y al final



tel=removeExtraSpaces(tel," "); //quita espacios repetidos

tel=quita_espacios_inicio_fin(tel," "); //quita espacios al principio y al final



cel=removeExtraSpaces(cel," "); //quita espacios repetidos

cel=quita_espacios_inicio_fin(cel," "); //quita espacios al principio y al final



noc=removeExtraSpaces(noc," "); //quita espacios repetidos

noc=quita_espacios_inicio_fin(noc," "); //quita espacios al principio y al final





nom_usu=document.form1.nombre.value=nom_usu;

mail=document.form1.email.value=mail;

tel=document.form1.telefono.value=tel;

cel=document.form1.celular.value=cel;

noc=document.form1.noches.value=noc;



if (noc == "")

      {

	  alert("ERROR: It must provide I number of nights that wish to reserve");

	  document.form1.noches.focus();

	  return false;

	 }  

else

   if(noc<=0)

   	{

		alert("ERROR: It cannot register 0 nights ");

		document.form1.noches.focus();

		return false;	

	}



if(fec=="")

	{

	  alert("ERROR: It must provide a date ");

	  return false;

	}


/*
if (antispam()!=true)

	{

	  alert("ERROR: Como medida de seguridad para prevenir el envio de spam a nuestro servidor de correos y a su cuenta de correo, es necesario que escriba en el campo de mensaje su nombre igual como lo escribio en el campo nombre, e inmediatamente su mensaje o comentario, en caso de no tener comentarios o mensaje de todos modos escriba su nombre --Puede borrar éste contenido--");

	  return false;

	}
*/
	

if(caracteres(nom_usu) && nom_usu.length>=3)

	  {//2

		if(mail==mail2)	 

			if(revmail(mail))

			 {//3

			   if(confirm("Are you sure you want to submit your reservation?"))

				 {

					enviado=1;

					return true;

				 }

				else

				 return false; 

			 }//3

			else

			 {

			  alert("ERROR: Your email confirmation is wrong. Try again"); 

			  document.form1.email.focus();

			  return false;

			 }

		else

		  {

		   alert("ERROR: Its e-mail confirmation is incorrect."); 

		   document.form1.email2.focus();

		   return false;

		  }

	  }//2

	 else

	  {  

	  	alert("ERROR: The username is not valid. It must contain at least 3 characters and only letters."); 		document.form1.nombre.focus();

		return false;

	  } 

}//funcion	

