/////////////////////////////////////////////////////////////////////////////
function echeck(str) { //valida el email.
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		{return false}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false}

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false}

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false}
		
		 if (str.indexOf(" ")!=-1){
		    return false}
 		 return true					
	}

/////////////////////////////////////////////////////////////////////////////
function checkPhone(str) /* Validate a telephone/fax number... */
{
	var num = "0123456789()- +.";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if ( num.indexOf(str.value.charAt(intLoop)) == -1 ) 
			{return false;}
}
/////////////////////////////////////////////////////////////////////////////
function checkNumber(str) /* Validate a NUMBER */
{
	var num = "0123456789";
	for (var intLoop = 0; intLoop < str.value.length; intLoop++) 
		if (-1 == num.indexOf(str.value.charAt(intLoop)) ) 
			{return false;}
}
/////////////////////////////////////////////////////////////////////////////
function validarWEDDING()
{
	var cadenaError = "";
	
	document.form.firstName.value = trim(document.form.firstName.value);
		if(document.form.firstName.value=="")
			{cadenaError = "You must provide your NAME.\n";}

	document.form.lastName.value = trim(document.form.lastName.value);
		if(document.form.lastName.value=="")
			{cadenaError += "You must provide your LAST NAME.\n";}

	document.form.email.value = trim(document.form.email.value);
		if( (document.form.email.value=="") || echeck(document.form.email.value)==false)
			{cadenaError +=  "You must provide your EMAIL ADDRESS or WRITE IT CORRECTLY.\n";}
	
	document.form.address.value = trim(document.form.address.value);
		if(document.form.address.value=="")
			{cadenaError += "You must provide your ADDRESS.\n";}
			
	document.form.city.value = trim(document.form.city.value);
		if(document.form.city.value=="")
			{cadenaError += "You must provide your CITY.\n";}

	document.form.telephone.value = trim(document.form.telephone.value);
		if( (document.form.telephone.value == "") || (checkPhone(document.form.telephone) == false) )
			{cadenaError += "You must provide your TELEPHONE or WRITE IT CORRECTLY.\n";}
			
	if(document.form.country.options[0].selected)
		{cadenaError += "You must provide your COUNTRY.\n";}

	document.form.meetingName.value = trim(document.form.meetingName.value);
		if(document.form.meetingName.value == "")
			{cadenaError += "You must provide the Name of bride and groom\n";}

	document.form.attendees.value = trim(document.form.attendees.value);
		if( (document.form.attendees.value == "") || (checkNumber(document.form.attendees)==false) )
			{cadenaError += "You must provide THE NUMBER OF GUESTS.\n";}

	if (document.form.arrivalDate.value == "")
		{cadenaError += "You must provide AN ARRIVAL DATE.\n";}		 
	if (document.form.departureDate.value == "")
		{cadenaError += "You must provide A DEPARTURE DATE.\n";}
	if ( (document.form.arrivalDate.value != "") && (document.form.departureDate.value != "") )
		{if( document.form.departureDate.value < document.form.arrivalDate.value )
			{cadenaError += "Your DEPARTURE DATE IS WRONG ACCORDING WITH YOUR ARRIVAL DATE.\n";}}
	
	if (document.form.altArrivalDate.value == "")
		{cadenaError += "You must provide AN ALTERNAL ARRIVAL DATE.\n";}		 
	if (document.form.altDepartureDate.value == "")
		{cadenaError += "You must provide AN ALTERNAL DEPARTURE DATE.\n";}
	if ( (document.form.altArrivalDate.value != "") && (document.form.altDepartureDate.value != "") )
		{if( document.form.altDepartureDate.value < document.form.altArrivalDate.value )
			{cadenaError += "Your ALTERNAL DEPARTURE DATE IS WRONG ACCORDING WITH YOUR ALTERNAL ARRIVAL DATE.\n";}}

	document.form.roomSingle.value = trim(document.form.roomSingle.value);
	document.form.roomDouble.value = trim(document.form.roomDouble.value);
	document.form.roomSuite.value = trim(document.form.roomSuite.value);
	if ( document.form.noRooms.checked == false )
		{
			if ( (document.form.roomSingle.value == "") && (document.form.roomDouble.value == "") && (document.form.roomSuite.value == "") )
					{cadenaError += "Your must provide at least one of the ROOMS NEEDED.\n";} 
			if (document.form.roomSingle.value != "")
					{if (checkNumber(document.form.roomSingle) == false)
						{cadenaError += "Your must provide the ROOM SINGLE CORRECTLY.\n";} }
			if (document.form.roomDouble.value != "")
					{if (checkNumber(document.form.roomDouble) == false)
						{cadenaError += "Your must provide the ROOM DOUBLE CORRECTLY.\n";} }
			if (document.form.roomSuite.value != "")
					{if (checkNumber(document.form.roomSuite) == false)
						{cadenaError += "Your must provide the ROOM SUITE CORRECTLY.\n";} }
		}

	if (cadenaError != "" ) 
		{
		alert(cadenaError);
		return false;
		}
	else 
		{return true;}


}
////////////////////////////////////////////////////////////////////////
function trim(s) { 	
	var temp = ""; 	
	var left; 	
	var right;  	
	
	// trim a la izquierda	 	
	for(left = 0; left < s.length; left++) { 		
		var c = s.charAt(left); 
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	
	
	// trim a la derecha	 	
	for(right = s.length-1; right >= 0; right--) { 		
		var c = s.charAt(right); 		
		if( (c != ' ') && (c != '\t') ) break; 	
	} 	 	
		
	temp = s.slice(left, right+1); 	return temp; 
}
////////////////////////////////////////////////////////////////////////