
function rover(item) { item.style.background="#EDEBE9"; }
function rout(item) { item.style.background="#F7F6F5"; }

function goURL(url) {
	window.location.href=url;
}

function doImg(url) {
	if ( document.main_pic )
		document.main_pic.src = '' + url;
}

function validateGB(theForm) {

	if (theForm.first_name.value == '') {
		alert("Please enter your first name");
		theForm.first_name.focus();
		return false;
	}

	 if (theForm.last_name.value == '') {
	 	alert("Please enter your last surname");
	 	theForm.last_name.focus();
	 	return false;
	 }

	if (!validEmail(theForm.email.value)) {
		theForm.email.focus();
		return false;
	}
 
	return true;
 		
}


/*  enquiry form validation  */

function validateGBenquiry(theForm) {

	if (theForm.full_name.value == '') {
		alert("Please enter your full name");
		theForm.full_name.focus();
		return false;
	}

	 if (theForm.contact_no.value == '') {
	 	alert("Please enter your contact number");
	 	theForm.contact_no.focus();
	 	return false;
	 }
	 
	 if (!validNum(theForm.contact_no.value)) {
		 alert("Please enter a valid number");
		theForm.contact_no.focus();
		return false;
	}
		
	 if (theForm.email.value == '') {
	 	alert("Please enter your email address");
	 	theForm.email.focus();
	 	return false;
	 }
	
	if (!validEmail(theForm.email.value)) {
		theForm.email.focus();
		return false;
	}
		
	 if (theForm.room_type.value == '') {
	 	alert("Please select a room type");
	 	theForm.room_type.focus();
	 	return false;
	 }
 
	return true;
 		
}



function validNum(telno) {
	var pattern = "0123456789+-)( ";
	var i = 0;
	do {

		var pos = 0;

		for ( var j = 0 ; j < pattern.length ; j++ )

			if ( telno.charAt(i) == pattern.charAt(j) )

				pos = 1;

		i++;

	}

	while ( pos == 1 && i < telno.length )
	if ( pos == 0 ) return false;
	return true;

}

// check email address pattern

function validEmail(addr) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if ( !regex.test(addr) ) {
		alert("Invalid email address");
		return false;
	}
	return true;
}

function y2k(year) { 
	return (year < 1000) ?year + 1900 : year; 
}

function check_dates_search(a_d,a_m,a_y,d_d,d_m,d_y) {
	a_m = a_m - 1;
	d_m = d_m - 1;

	var sys_date = new Date();
	var today = new Date(y2k(sys_date.getYear()),sys_date.getMonth(),sys_date.getDate());
	var arrival_date = new Date(a_y,a_m,a_d);
	var departure_date = new Date(d_y,d_m,d_d);
	
	if (arrival_date < today) {
		alert("Your arrival date is before today");
		return false;
	}
	if (departure_date < today) {
		alert("Your departure is before today");
		return false;
	}
	if (departure_date < arrival_date) {
		alert("Your departure date is before arrival date");
		return false;
	}
	if (arrival_date+'' == departure_date+'') {
		alert("Arrival and departure dates are the same");
		return false;
	}
	return true;
}
