// JavaScript Document
//booking  status
function showdetails(show){
	var bookingdetails = document.getElementById('details');	
	if (show) {
			bookingdetails.style.display='block';
	} else {
			bookingdetails.style.display ='none';		
	};		
}

function checkbookingmgt(){
	var bookingcode = window.document.fn.booking_code;
	var emailaddress = window.document.fn.email_address;
	var bookingdetails = window.document.fn.booking_details;
	
	for (i=0;i<document.fn.action.length;i++){
		if (document.fn.action[i].checked==true)
			var actiontype  = document.fn.action[i].value;	
	}

	if(!bookingcode.value){
		error_msg = "Please fill out booking code.";
		bookingcode.focus();
		alert(error_msg);
		return false;
	}
	
	if(bookingcode.value.length<10 || bookingcode.value.length>10){
		error_msg = "Please input a valid booking code.";
		bookingcode.focus();
		alert(error_msg);
		return false;
	}

	if(!emailaddress.value){
		error_msg = "Please fill out email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}
	
	if(isValidEmail(emailaddress.value)==false){
		error_msg = "Please input a valid email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}
	
	if(!(actiontype=='view')) {
		if(!bookingdetails.value){		
			error_msg = "Please fill out the booking details of Cancellation/ Amendment.";
			bookingdetails.focus();
			alert(error_msg);
			return false;
		}
	}

	return true;

}

function checksupportform(){
	var emailaddress = window.document.support_form.email_address;
	var name = window.document.support_form.name;
	var subject = window.document.support_form.subject;
	var message= window.document.support_form.message;

	if(!emailaddress.value){
		error_msg = "Please fill out the email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}
	
	if(isValidEmail(emailaddress.value)==false){
		error_msg = "Please input a valid email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}

	if(!name.value){
		error_msg = "Please fill out your name.";
		name.focus();
		alert(error_msg);
		return false;
	}	
	
	if(!subject.value){
		error_msg = "Please fill out subject.";
		subject.focus();
		alert(error_msg);
		return false;
	}	
	
	if(!message.value){
		error_msg = "Please fill out message.";
		message.focus();
		alert(error_msg);
		return false;
	}
	
	return true;

}

function checkenquiryform(){
	var emailaddress = window.document.enquiry_form.email_address;
	var name = window.document.enquiry_form.name;
	var clientoffer = window.document.enquiry_form.client_offer;
	var message= window.document.enquiry_form.message;
	var checkin= window.document.enquiry_form.check_in;
	var checkout= window.document.enquiry_form.check_out;	

	if(!emailaddress.value){
		error_msg = "Please fill out the email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}
	
	if(isValidEmail(emailaddress.value)==false){
		error_msg = "Please input a valid email Address.";
		emailaddress.focus();
		alert(error_msg);
		return false;
	}

	if(!name.value){
		error_msg = "Please fill out your name.";
		name.focus();
		alert(error_msg);
		return false;
	}	
	
	if(!clientoffer.value){
		error_msg = "Please fill out client offer.";
		clientoffer.focus();
		alert(error_msg);
		return false;
	}	
	
	if(checkin.value=="mm/dd/yyyy"){
		error_msg = "Please fill out your check in date.";
		checkin.focus();
		alert(error_msg);
		return false;
	}
	
	if(checkout.value=="mm/dd/yyyy"){
		error_msg = "Please fill out your check out date.";
		checkout.focus();
		alert(error_msg);		
		return false;
	}
	
	return true;

}

function isValidEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else{
		testresults=false
	}
	return (testresults)
}

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
win=window.open(mypage,myname,settings);}