// JavaScript Document


/* Protocol
NOT_NULL //debe contener al menos un caracter alfanumerico
NOT_SPC //no permite espacios entre palabras
INT // debe ser un numero entero
FLOAT //numero real
ALFA// solo puede contener caracteres del abecedario, sin numeros ni tildes
ALFNUM // caracteres alfanumericos, especial para contraseņas
PORC //porcentaje
MAIL
*/



function validate(form)
{


if(!form|| !form.elements)
return true;

if(String(form["fecha_llegada"])!="undefined"&&String(form["fecha_salida"])!="undefined")
{
	
	date1=form["fecha_llegada"].value.split("/");
	
	date2=form["fecha_salida"].value.split("/");
	
	var current=new Date();
	var fecha1=new Date(date1[2],date1[1],date1[0]);
	var fecha2= new Date(date2[2],date2[1],date2[0]);
	
	
	if(fecha2<fecha1)
	{
		alert("The arrival date must be less than the Departure date");
		form["fecha_llegada"].focus();
		return false;
	}
	
	if(fecha1<document.currentDate)
	{
			alert("The arrival date cant't be less than the Current date");
			form["fecha_llegada"].focus();
			return false;
			
	}
	
}
var content;
var regExp;
var i;

  //regExp, anti registros vacios
  
for(i=0;i<form.elements.length;i++)
{
content=form.elements[i];

if(content.title=="")
content.title=content.name;

if(content.alt==undefined)
continue;


if(content.alt.indexOf("NOT_NULL")!=-1)
{
regExp=/\S/gi;

if(content.value.match(regExp)==null)
{
alert(content.title+" is Required ");
content.select();
return false;
}
//end if

}//end if


if(content.alt.indexOf("NOT_SPC")!=-1)
{
regExp=/( )/gi;

if(content.value.match(regExp)!=null)
{
alert(content.title+" can't contain spaces ");
content.select();
return false;

}
//end if

}//end if



	
	
if(content.value.length!=0&&content.alt.indexOf("INT")!=-1)
{
regExp=/\D/gi;//INT  esto debe devolver null

if(content.value.match(regExp)!=null)
{

alert("The tipe of "+content.title+" must be a number ");
content.select();
return false;
}
//end if

}//end if



if(content.value.length!=0&&content.alt.indexOf("MAIL")!=-1)
{
regExp=/.+@[a-z]+\.[a-z]+/gi;//INT  esto NO debe devolver null



if(content.value.match(regExp)==null)
{

alert(content.title+" must contain one email adress like: youremail@server.com ");
content.select();
return false;
}
//end if

}//end if




if(content.value.length!=0&&content.alt.indexOf("FLOAT")!=-1)
{
regExp=/(\d+|\d+\.\d+)/gi;//INT  esto debe devolver null


if(String(content.value).length>0 && (String(content.value.match(regExp))!= String(content.value)) )
{
alert("The content of "+content.title+" must be a real number, like 0.5 or 200.9 ");
content.select();
return false;
}
//end if

}//end if



if(content.value.length!=0&&content.alt.indexOf("ALFA")!=-1)
{
regExp=/[a-z ]+/gi;

if(String(content.value).length>0 && (String(content.value.match(regExp))!= String(content.value)) )
{
alert("The content of "+content.title+" must be Alfabetical ");
content.select();
return false;
}

}


if(content.value.length!=0&&content.alt.indexOf("ALFANUM")!=-1)
{
regExp=/[a-z0-9]+/gi;

if(String(content.value).length>0 && (String(content.value.match(regExp))!= String(content.value)) )
{
alert("The content of "+content.title+" must be Alfanumeric  ");
content.select();
return false;
}


}


}//end for


return true;
  

}


  
 
