// JavaScript Document

function validateFormIndexPage()
{
	var selectedHot = document.getElementById('select_room');					
	if (document.frmMain.select_hotel[document.frmMain.select_room.selectedIndex].value== ""){
		alert('Please select Room type.');
		document.frmMain.select_room.focus();
		return false;		
	}
	
if(isEmpty(document.getElementById('checkin').value))
	{
		alert('Please enter the check in date.');
		document.frmMain.checkin.focus();
		return false;
	}
	
	if(isEmpty(document.getElementById('checkout').value))
	{
		alert('Please enter the check out date.');
		document.frmMain.checkout.focus();
		return false;
	}
	
	if (document.frmMain.room[document.frmMain.room.selectedIndex].value== ""){
		alert('Please select the number of room(s).');
		document.frmMain.room.focus();
		return false;
	}
	
	if (document.frmMain.adults[document.frmMain.adults.selectedIndex].value== "")
	{
		alert('Please select the number of adult(s).');
		document.frmMain.adults.focus();
		return false;
	}
	
	
	if(isEmpty(document.getElementById('name').value))
	{
		alert('Please enter your Name.');
		document.frmMain.name.focus();
		return false;
	}
	
	if(document.getElementById('name').value=="Name")
	{
		alert('Please enter valid Name.');
		document.frmMain.name.focus();
		return false;
	}
	
	var email = document.getElementById("email").value;
	if(isEmpty(email))
	{
		alert('Please enter email address.');
		document.frmMain.email.focus();
		return false;
	}
	
	if(!IsValidEMail(document.getElementById('email').value))
	{
		alert('Please enter a valid email.');
		document.frmMain.email.focus();
		return false;
	}
	
	
	
	return true;
}



function validateFormContactPage()
{
	
	if(isEmpty(document.getElementById('name').value))
	{
		alert('Please enter your Name.');
		document.frmContact.name.focus();
		return false;
	}
	
	if(document.getElementById('name').value=="Name:")
	{
		alert('Please enter valid Name.');
		document.frmContact.name.focus();
		return false;
	}
	
	var email = document.getElementById("email").value;
	if(isEmpty(email))
	{
		alert('Please enter email address.');
		document.frmContact.email.focus();
		return false;
	}
	
	if(!IsValidEMail(document.getElementById('email').value))
	{
		alert('Please enter a valid email.');
		document.frmContact.email.focus();
		return false;
	}
	
	if(isEmpty(document.getElementById('query').value))
	{
		alert('Please enter your query.');
		document.frmContact.query.focus();
		return false;
	}
	
	if(document.getElementById('query').value=="Query:")
	{
		alert('Please enter your query.');
		document.frmContact.query.focus();
		return false;
	}
	
	
	return true;
}



function validateForm()
{
	if(isEmpty(document.getElementById('name').value))
	{
		alert('Please enter your Name.');
		document.frmHotelReservation.name.focus();
		return false;
	}
	var email = document.getElementById("email").value;
	if(isEmpty(email))
	{
		alert('Please enter email address.');
		document.frmHotelReservation.email.focus();
		return false;
	}
	if(!IsValidEMail(document.getElementById('email').value))
	{
		alert('Please enter a valid email.');
		document.frmHotelReservation.email.focus();
		return false;
	}
	if(isEmpty(document.getElementById('inday').value))
	{
		alert('Please enter the check in day.');
		document.frmHotelReservation.inday.focus();
		return false;
	}
	if(!isNumeric(document.getElementById('inday'), 'helper'))
	 {
		alert('Check in day should be numeric.');
		document.frmHotelReservation.inday.focus();
		return false;
	 }
	
	if(isEmpty(document.getElementById('inmonth').value))
	{
		alert('Please enter the check in month.');
		document.frmHotelReservation.inmonth.focus();
		return false;
	}
	
	if(!isNumeric(document.getElementById('inmonth'), 'helper'))
	 {
		alert('Check in month should be numeric.');
		document.frmHotelReservation.inmonth.focus();
		return false;
	 }
	
	if(isEmpty(document.getElementById('inyear').value))
	{
		alert('Please enter the check in month.');
		document.frmHotelReservation.inyear.focus();
		return false;
	}
	
	if(!isNumeric(document.getElementById('inyear'), 'helper'))
	 {
		alert('Check in year should be numeric.');
		document.frmHotelReservation.inyear.focus();
		return false;
	 }
	
	if(isEmpty(document.getElementById('outday').value))
	{
		alert('Please enter the check out day.');
		document.frmHotelReservation.outday.focus();
		return false;
	}
	
	if(!isNumeric(document.getElementById('outday'), 'helper'))
	 {
		alert('Check out day should be numeric.');
		document.frmHotelReservation.outday.focus();
		return false;
	 }
	 
	if(isEmpty(document.getElementById('outmonth').value))
	{
		alert('Please enter the check out month.');
		document.frmHotelReservation.outmonth.focus();
		return false;
	}
	
	if(!isNumeric(document.getElementById('outmonth'), 'helper'))
	 {
		alert('Check out month should be numeric.');
		document.frmHotelReservation.outmonth.focus();
		return false;
	 }
	
	if(isEmpty(document.getElementById('outyear').value))
	{
		alert('Please enter the check out month.');
		document.frmHotelReservation.outyear.focus();
		return false;
	}
	
	if(!isNumeric(document.getElementById('outyear'), 'helper'))
	 {
		alert('Check out month should be numeric.');
		document.frmHotelReservation.outyear.focus();
		return false;
	 }
	
	
	return true;
}

function isEmpty(elementValue)
{
	if( (elementValue=="") || (elementValue==null) )
	{
		return true;	//if empty
	}
	else
	{
		return false;	//if not empty
	}
}


//////////function to validate email address
function IsValidEMail(strValue)
{
	nNoOfArguments = IsValidEMail.arguments.length;
	//if no parameter is supplied
	if(nNoOfArguments < 1)
	{
		return false;
	}	
	
	var strVal	= new String(strValue);
	var bReturn1 = false;
	var bReturn2 = false;
	var bReturn3 = false;
	var bReturn4 = false;
	var bReturn5 = false;
	var bReturn5 = false;
	
	//if '@' comes after first character then true
	bReturn1	=	(strValue.indexOf("@") > 0);							
	
	//if '.' comes after first character then true
	bReturn2	=	(strValue.indexOf(".") > 0);							
	
	//if single '@' exist in string then true
	bReturn3	=	(strValue.indexOf("@") == strValue.lastIndexOf("@"));	
	
	//if '.' exist after @ in string then true
	bReturn4	=	(strValue.indexOf(".",strValue.indexOf("@")) > (strValue.indexOf("@")));		
	
	//if '.' does not comes immediatly after @ then true
	bReturn5	=	(strValue.indexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")+1));		
	
	//if '.' does not comes immediatly before @ then true
	bReturn6	=	(strValue.lastIndexOf(".",strValue.indexOf("@")) != (strValue.indexOf("@")-1)); 
	
	//if all values are true return true else false.
	return(bReturn1 && bReturn2 && bReturn3 && bReturn4 && bReturn5 && bReturn6);
}


////to check numeric
function isNumeric(elem, helperMsg) 
{
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression))
	{
		return true ;
	}
	else
	{
		return false;
	}
}
