function IsValidEmail(strEmail) {
if (!(/^([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.([a-z]{2,3}|(info|name|museum|coop|aero|biz)))$/i.test(strEmail)))
	return false;
else
	return true;
}


function IsValidPax(x,precision,scale,min,max) {
if ( (x==null) || (x.search(/[^ \r\n\t]/) < 0) )
	return false;					// no value
if ( precision == null )
	return false;					// no precision (total number of digits including decimals)
if (scale==null)
	scale = 0;						// default scale (number of decimals)
var limit = Math.pow(10,precision - scale) - Math.pow(10,-1*scale);
if (min==null)
	min = -1*limit;				// default min
if (max==null)
	max = limit;					// default max
var permit = '\\d';
var maxLen = parseInt(precision);
if (scale > 0) {
	permit+= '\\.';
	maxLen+=1;
}
if (min < 0) {
	permit+= '-';
	maxLen+=1;
}
//alert('precision=' + precision + '\nscale=' + scale + '\nmin=' + min + '\nmax=' + max + '\nmaxLen=' + maxLen);
var re = new RegExp('[^' + permit + ']');
if (x.search(re) >= 0 )
	return false;				// illegal character
re = new RegExp('.*-.*-.*|.*\\..*\\..*');
if ( x.search(re) >= 0 )
	return false;				// multiple dp or minus
var p = x.indexOf('-');
if ( (p > 0) && ( p != x.length - 1) )
	return false; 							// sign must be at start/end or not present
var temp = x.replace('-','');			// get sign out of the way
while (temp.charAt(0) == '0')
	temp = temp.substr(1);			// lose leading zeros
p = temp.indexOf('.');
if (p > precision - scale)
	return false;										// too many before dp
if ((p >= 0) && (temp.length - p - 1> scale))
	return false;										// too many after dp
if ((parseFloat(x) > max) || (parseFloat(x) < min))
	return false;
return true;
}

function validateForm() {
	if (document.travel.pax.value=="") {
		alert(ERROR_Passengers);
		document.travel.pax.focus();
		return false;
	}
	if (!IsValidPax(document.travel.pax.value,3,0,15)) {
		alert(ERROR_PassengerNum);
		document.travel.pax.focus();
		return false;
	}
	if (document.travel.frmName.value=="") {
		alert(ERROR_ContactName);
		document.travel.frmName.focus();
		return false;
	}
	if (document.travel.frmPhone.value=="") {
		alert(ERROR_Phone);
		document.travel.frmPhone.focus();
		return false;
	}
	if (!IsValidEmail(document.travel.frmEmail.value))	{
		alert(ERROR_Email);
		document.travel.frmEmail.focus();
		return false;
	}		
	if (document.travel.outDate.value=="") {
		alert(ERROR_OutboundDate);
		document.travel.outDate.focus();
		return false;
	}
	if (document.travel.rtnDate.value=="") {
		alert(ERROR_ReturnDate);
		document.travel.rtnDate.focus();
		return false;
	}
	if (document.travel.DEP.value=="" || document.travel.DEP.value=="-1") {
		alert(ERROR_DepAirport);
		document.travel.DEP.focus();
		return false;
	}
	if (document.travel.DEST.value=="" || document.travel.DEST.value=="-1") {
		alert(ERROR_DestAirport);
		document.travel.DEST.focus();
		return false;
	}


	
	

	//if hotel checkbox is ticked, check required fields have been completed
	if (document.travel.hotelcheckbox.checked)
	{	
		//check adult field has been completed		
		if (document.travel.NumHotelAdults.value=="") 
		{
			alert(ERROR_Adults);
			document.travel.NumHotelAdults.focus();
			return false;			
		}
		//check child field has been completed
		if (document.travel.NumHotelChild.value=="")
		{
			alert(ERROR_Children);
			document.travel.NumHotelChild.focus();
			return false; 
		}	
		//if other travel purposes is selected, ensure the user has states what it is.
		if (document.travel.HotelOther.checked)
		{
			if (document.travel.HotelPurposeOther.value=="")
			{
				alert(ERROR_SelectedOther);
				document.travel.HotelPurposeOther.focus();
				return false;
			}
		}	
	}
	//if hotel checkbox is not ticked ask user to confirm if they want a hotel quote or not
	else
	{		
		var where_to = confirm(ERROR_HotelQuote);
		//Continue Button
		if (where_to == true)
		{
			return true;
		}
		//Cancel Button
		else
		{
			document.travel.hotelcheckbox.focus()
			return false;
		}		
	}
	return true;
}


function hotel_checkbox()
{
	if (!document.travel.hotelcheckbox.checked)	
	{			
		//if table is visible, hide				
		document.getElementById('hotelConnectForm').style.display='none';
	}
	else
	{
		//if table is hidden make visible
		document.getElementById('hotelConnectForm').style.display='block';
		document.travel.NumHotelAdults.focus();
	}
}
