var PLEASE_ENTER="Please enter ";
var PLEASE_SELECT="Please select ";

var prefix = window.parent.document.location.protocol;
var WSPATH=(prefix=='https:'?prefix + "//secure92.nocdirect.com/~antrimho":"http://www.antrimhouseni.co.uk");

function validBookHotel1()
{
	var dt=document.frm_book_hotel1;
	if(trim(dt.hot_room_type.value)==''){
		alert(PLEASE_SELECT+"room type.");
		dt.hot_room_type.focus();
		return false;
	}
	if(trim(dt.hot_no_heads.value)==''){
		alert(PLEASE_ENTER+"number of persons.");
		dt.hot_no_heads.focus();
		return false;
	}
	else if(isNaN(dt.hot_no_heads.value)){
		alert(PLEASE_ENTER+"a numeric value for number of persons.")
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}
	if(trim(dt.hot_no_rooms.value)==''){
		alert(PLEASE_ENTER+"number of rooms.");
		dt.hot_no_rooms.focus();
		return false;
	}
	else if(isNaN(dt.hot_no_rooms.value)){
		alert(PLEASE_ENTER+"a numeric value for number of rooms.")
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}
	return true;
}
function nextHotBook(){
	var bookDArray=document.getElementById('bookDArray').value;
	if(bookDArray!=''){
		return true;
	}else{
		alert("Please select the dates you want to book for hotel.");
		return false;
	}
}

function hotbookValid(hot_book_id)
{
	var dt=document.frm_book_hotel3;
	var hot_room_type=trim(dt.hot_room_type.value);
	var hot_no_heads=trim(dt.hot_no_heads.value);
	var hot_no_rooms=trim(dt.hot_no_rooms.value);
	var hot_book_dates=trim(dt.hot_book_dates.value);
	
	if(hot_room_type==''){
		alert(PLEASE_SELECT+"room type.");
		dt.hot_room_type.focus();
		return false;
	}
	if(hot_no_heads==''){
		alert(PLEASE_ENTER+"number of persons.");
		dt.hot_no_heads.focus();
		return false;
	}
	else if(isNaN(hot_no_heads)){
		alert(PLEASE_ENTER+"a numeric value for number of persons.")
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}
	if(trim(hot_no_rooms)==''){
		alert(PLEASE_ENTER+"number of rooms.");
		dt.hot_no_rooms.focus();
		return false;
	}
	else if(isNaN(hot_no_rooms)){
		alert(PLEASE_ENTER+"a numeric value for number of rooms.")
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}
	
	var headallows=getAJAXcontent(WSPATH + "/hotel-booking-availability.php?hrt="+hot_room_type+"&hnh="+hot_no_heads+"&hnr="+hot_no_rooms);
	if(headallows==0){
		alert("You are not allowed to book "+hot_no_heads+" head(s) in "+hot_no_rooms+" rooms");
		dt.hot_no_heads.focus();
		dt.hot_no_heads.select();
		return false;
	}	

	hot_book_dates=str_replace("\r\n",",",hot_book_dates);
	hot_book_dates=str_replace("\n",",",hot_book_dates);
	
	var room_available=getAJAXcontent(WSPATH + "/hotel-booking-availability1.php?hrt="+hot_room_type+"&hnr="+hot_no_rooms+"&bdate="+hot_book_dates);
	var raArray=room_available.split(":;");
	if(raArray[0]=="0"){
		alert(raArray[2]+" room(s) available for the date "+raArray[1]);
		dt.hot_no_rooms.focus();
		dt.hot_no_rooms.select();
		return false;
	}
	if(trim(dt.user_first_name.value)==''){
		alert(PLEASE_ENTER+"first name.");
		dt.user_first_name.focus();
		return false;
	}
	if(trim(dt.user_last_name.value)==''){
		alert(PLEASE_ENTER+"last name.");
		dt.user_last_name.focus();
		return false;
	}
	if(trim(dt.user_email_address.value)==''){
		alert(PLEASE_ENTER+"email.");
		dt.user_email_address.focus();
		return false;
	}else{
		if(!validString(trim(dt.user_email_address.value),'email')){
			alert("Invalid email.");
			dt.user_email_address.focus();
			dt.user_email_address.select();
			return false;
		}
	}
	if(trim(dt.user_mobile.value)==''){
		alert(PLEASE_ENTER+"mobile.");
		dt.user_mobile.focus();
		return false;
	}
	if(trim(dt.hot_home_address.value)==''){
		alert(PLEASE_ENTER+"home address.");
		dt.hot_home_address.focus();
		return false;
	}
	if(trim(dt.hot_postcode.value)==''){
		alert(PLEASE_ENTER+"post code.");
		dt.hot_postcode.focus();
		return false;
	}
	if(trim(dt.hot_holder_name.value)==''){
		alert(PLEASE_ENTER+"name printed on card.");
		dt.hot_holder_name.focus();
		return false;
	}
	if(trim(dt.hot_card_type.value)==2){
		if(trim(dt.hot_issue_number.value)==''){
			alert(PLEASE_ENTER+"issue number.");
			dt.hot_issue_number.focus();
			return false;
		}	
	}
	if(trim(dt.hot_card_number.value)==''){
		alert(PLEASE_ENTER+"card number.");
		dt.hot_card_number.focus();
		return false;
	}
	else if(isNaN(trim(dt.hot_card_number.value))){
		alert(PLEASE_ENTER+"a numeric value for card number.");
		dt.hot_card_number.focus();
		dt.hot_card_number.select();
		return false;
	}
	else if((dt.hot_card_number.value).length<16){
		alert(PLEASE_ENTER+"a 16 digit numeric value for card number.");
		dt.hot_card_number.focus();
		dt.hot_card_number.select();
		return false;
	}
	var today = new Date();
	var crMon=eval(today.getMonth()+1);
 	var crYer=today.getFullYear();
 	var crDay=today.getDate();
	if(crYer==trim(dt.hot_srt_year.value) && trim(dt.hot_srt_mon.value)>=crMon){	
		alert("Your card is not valid, select valid start date.");
		return false;
	}
	if(crYer==trim(dt.hot_exp_year.value) && trim(dt.hot_exp_mon.value)<=crMon){	
		alert("Your card is not valid, select valid expiration date.");
		return false;
	}
	if(trim(dt.hot_sec_code.value)==''){
		alert(PLEASE_ENTER+"card security code.");
		dt.hot_sec_code.focus();
		return false;
	}
	else if(isNaN(trim(dt.hot_sec_code.value))){
		alert(PLEASE_ENTER+"a numeric value for card security code.");
		dt.hot_sec_code.focus();
		dt.hot_sec_code.select();
		return false;
	} 
	
	return true;
}
function hotbookConfirmValid(hbi,grTot)
{
	insertVal=getAJAXcontent(WSPATH + "/hotel_booking_confirm_post.php?hbi="+hbi+"&grTot="+grTot);
	alert("Your total booking charge is : "+'£'+grTot);
	location.href="hotel_booking_confirm.php?hbi="+hbi;
}

function changeCaptcha()
{
	document.getElementById("loading").src="images/loading1.gif";
	capimg=getAJAXcontent(WSPATH + "/get_captcha.php");
	document.getElementById("codeHidden").value=capimg;
	document.getElementById("codeImage").src=capimg;
	document.getElementById("loading").src="images/ic-refresh.jpg";
}
function uniqueUser(userName)
{
	unique_user=getAJAXcontent(WSPATH + "/unique_user.php?username="+userName);
	return (unique_user=="1"?true:false);
}
function loginValidation()
{
	var dt=document.frm_login;
	if(trim(dt.user_name.value)==''){
		alert(PLEASE_ENTER+"username.");
		dt.user_name.focus();
		return false;
	}
	if(trim(dt.user_password.value)==''){
		alert(PLEASE_ENTER+"password.");
		dt.user_password.focus();
		return false;
	}
	if(validUser(trim(dt.user_name.value),trim(dt.user_password.value)))
	{
		YAHOO.com.thecodecentral.dialog3.hide();		
		location.href="index.php?v=login";		
		
		return false;
	}else{
		alert("Invalid username or password.");
		dt.user_name.focus();
		dt.user_name.select();
		return false;
	}
	return false;
}
function validUser(userName,passWord)
{
	unique_user=getAJAXcontent(WSPATH + "/login_user_valid.php?username="+encodeURI(userName)+"&password="+encodeURI(passWord));
	return (unique_user=="1"?true:false);
}
function forPassValidation()
{
	var dt=document.frm_forgot;
	if(trim(dt.user_email_address.value)==''){
		alert(PLEASE_ENTER+"email.");
		dt.user_email_address.focus();
		return false;
	}else{
		if(!validString(trim(dt.user_email_address.value),'email')){
			alert("Invalid email address");
			dt.user_email_address.focus()
			dt.user_email_address.select();
			return false;
		}
	}
	if(checkUserEmail(trim(dt.user_email_address.value)))
	{
		alert("Email does not match.");
		return false;
	}
	
	submitStr="submitAction=Forgot"+"&user_email_address="+encodeURI(trim(dt.user_email_address.value));
	postAjaxContent(WSPATH + "/forgot_email_post.php",submitStr,"frm_forgot_success","frm_input_forgot");
	return false;
}
function checkUserEmail(userEmail)
{
	unique_user=getAJAXcontent(WSPATH + "/forgot_email_valid.php?useremail="+userEmail);
	return (unique_user=="1"?false:true);
}
function logOut()
{
	unique_user=getAJAXcontent(WSPATH + "/logout.php");
	location.href="index.php?v=logout";		
	return false;
}

function checkValidDate(bookDate)
{
	var dtAry=bookDate.split("-");
	
	var today = new Date();
	var crMon=eval(today.getMonth()+1);
 	var crYer=today.getFullYear();
 	var crDay=today.getDate();
 	var vld=1;
 	
	if(dtAry[0]<crYer){
		vld=0;
	}else if(dtAry[0]==crYer && dtAry[1]<crMon){
		vld=0;
	}else if(dtAry[0]==crYer && dtAry[1]==crMon && dtAry[2]<crDay){
		vld=0;
	}
	return vld;
}
function changeRoomDeail(id)
{
	document.getElementById("charge_"+id).style.display="block";
	var slctroom=document.getElementById("selectroom").value;
	document.getElementById("charge_"+slctroom).style.display="none";
	document.getElementById("selectroom").value=id;
}
function validCaptch(ccode,pccode)
{
	var captchacode=getAJAXcontent(WSPATH + "/captcha_validate.php?ccode="+ccode+"&pccode="+pccode);
	return (captchacode=="1"?true:false);
}
function uniqueNwlUser(email)
{
	unique_email=getAJAXcontent(WSPATH + "/unique_email.php?email="+email);
	return (unique_email=="1"?true:false);
}
function showdetailBooking(tabname,tabid)
{
	var max_tbl=document.getElementById("max_tbl").value;	
	for(k=1;k<=max_tbl;k++){
		if(document.getElementById(tabname+"_"+k))
			document.getElementById(tabname+"_"+k).style.display=(k==tabid?'block':'none');
	}			
}
function termsValid()
{
	if(!document.getElementById("terms").checked){
		alert("You have to accept hotel terms and conditions.");
		return false;		
	}
	return true;
}
