// JavaScript Document

function dissable_submition(isAgree){
	if(isAgree==1){
		document.getElementById("btn_submit").disabled="";
	}else{
		document.getElementById("btn_submit").disabled="disabled";
	}	
	
	
}

function validate_payment_form(form){
	var cents_amount = form.vpc_Amount.value;
	var cents_result = cents_amount.split(".");

	if(form.vpc_MerchTxnRef.value==''){
		alert("Please enter a valid invoice number");
		form.vpc_MerchTxnRef.focus();	
		return(false);
	}
	if(form.vpc_Amount.value==''){
		alert("Please enter the amount you wish to pay");
		form.vpc_Amount.focus();	
		return(false);
	}if(isNaN(Number(form.vpc_Amount.value)) || cents_result[1].length != 2){
		alert("Invalid Amount! Please enter amount in digits only. e.g. 100.00");
		form.vpc_Amount.focus();	
		return(false);
	}
	return(true);
}

function show_hide_child_ages(no_of_children){
	var child_agex = document.getElementById('child_age');
	if(no_of_children==0){
		child_agex.style.display = 'none';
	}
	else
	{
		child_agex.style.display = '';	
	}
}
function show_hide_srilankan_combo(val){
	var srilankanx = document.getElementById('srilankan');
	if(val==1){
		var non_srilankan_resx = document.getElementById('non_srilankan_res');
		non_srilankan_resx.style.display = 'none';
		srilankanx.style.display = '';	
		var nonsrilankanx = document.getElementById('nonsrilankan');
		nonsrilankanx.style.display = 'none';	
	}
	else
	{
		srilankanx.style.display = 'none';	
	}
}
function show_hide_non_srilankan_res_combo(val){
	var non_srilankan_resx = document.getElementById('non_srilankan_res');
	if(val==1){
		var srilankanx = document.getElementById('srilankan');
		srilankanx.style.display = 'none';
		var nonsrilankanx = document.getElementById('nonsrilankan');
		nonsrilankanx.style.display = 'none';	
		non_srilankan_resx.style.display = '';
	}
	else
	{
		non_srilankan_resx.style.display = 'none';
	}
}
function show_hide_nonsrilankan_combo(val){
	var nonsrilankanx = document.getElementById('nonsrilankan');
	if(val==1){
		var non_srilankan_resx = document.getElementById('non_srilankan_res');
		non_srilankan_resx.style.display = 'none';
		var srilankanx = document.getElementById('srilankan');
		srilankanx.style.display = 'none';	
		nonsrilankanx.style.display = '';	
	}
	else
	{
		nonsrilankanx.style.display = 'none';	
	}
}
function validate_reservation_form(form){
	if(form.hotel_id.value==''){
		alert("Please select a hotel");
		form.hotel_id.focus();
		return false;
	}	
	if(form.in_month.value==''){
		alert("Please select check-in month");
		form.in_month.focus();
		return false;
	}	
	if(form.in_date.value==''){
		alert("Please select check-in day");
		form.in_date.focus();
		return false;
	}	
	if(form.in_year.value==''){
		alert("Please select check-in year");
		form.in_year.focus();
		return false;
	}	
	if(form.out_month.value==''){
		alert("Please select check-out month");
		form.out_month.focus();
		return false;
	}	
	if(form.out_date.value==''){
		alert("Please select check-out day");
		form.out_date.focus();
		return false;
	}	
	if(form.out_year.value==''){
		alert("Please select check-out year");
		form.out_year.focus();
		return false;
	}		
	if(form.room_type.value=='-1'){
		alert("Please select room type");
		form.room_type.focus();
		return false;
	}	

	if(form.rooms.value==''){
		alert("Please select number of rooms you  need");
		form.rooms.focus();
		return false;
	}	
	if(form.adults.value==''){
		alert("Please select number of adults");
		form.adults.focus();
		return false;
	}		
	if(form.children.value==''){
		alert("Please select number of children");
		form.children.focus();
		return false;
	}
	
	if(form.children.value!=0){
		var children = form.children.value;
		var children_0_to_3 = form.children_0_to_3.value==''?0:form.children_0_to_3.value;
		var children_3_to_4 = form.children_3_to_4.value==''?0:form.children_3_to_4.value;
		var children_4_to_5 = form.children_4_to_5.value==''?0:form.children_4_to_5.value;
		var children_5_to_6 = form.children_5_to_6.value==''?0:form.children_5_to_6.value;
		var children_6_to_7 = form.children_6_to_7.value==''?0:form.children_6_to_7.value;
		var children_7_to_8 = form.children_7_to_8.value==''?0:form.children_7_to_8.value;
		var children_8_to_9 = form.children_8_to_9.value==''?0:form.children_8_to_9.value;
		var children_9_to_10 = form.children_9_to_10.value==''?0:form.children_9_to_10.value;
		var children_10_to_11 = form.children_10_to_11.value==''?0:form.children_10_to_11.value;
		var children_11_to_12 = form.children_11_to_12.value==''?0:form.children_11_to_12.value;
		
		
		//var children_4_to_12 = form.children_4_to_12.value==''?0:form.children_4_to_12.value;
		//var count_of_children = parseInt(children_0_to_3)+parseInt(children_4_to_12);
		var count_of_children = parseInt(children_0_to_3)+parseInt(children_3_to_4)+
								parseInt(children_4_to_5)+parseInt(children_5_to_6)+
								parseInt(children_6_to_7)+parseInt(children_7_to_8)+
								parseInt(children_8_to_9)+parseInt(children_9_to_10)+
								parseInt(children_10_to_11)+parseInt(children_11_to_12);
		if(count_of_children!=children){
			alert("No. of Children dosen't match with count of Age Range");
			//alert("No. of Children dosen't match with count of Age 0 - 3 Years and Age 4 - 12 Years");
			return false;
		}
	}
	if(form.title.value==""){
		alert("Please Select Title");
		form.title.focus();
		return false;
	}
	if(form.first_name.value==''){
		alert("Please enter your first name");
		form.first_name.focus();
		return false;
	}				
	if(form.last_name.value==''){
		alert("Please enter your last name");
		form.last_name.focus();
		return false;
	}
//
// email validation here
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (form.email_1.value.search(emailRegEx) == -1){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		form.email_1.focus();
		return(false);
	}
	if(form.email_2.value != form.email_1.value){
		alert("Email address does no match with confirmed email address");
		form.email_2.focus();
		return false;
	}


	if(form.last_name.value==''){
		alert("Please enter your last name");
		form.last_name.focus();
		return false;
	}
	if(form.address.value==''){
		alert("Please enter address");
		form.address.focus();
		return false;
	}
	if(form.city.value==''){
		alert("Please enter city");
		form.city.focus();
		return false;
	}
	if(form.state.value==''){
		alert("Please enter state");
		form.state.focus();
		return false;
	}
	if(form.postal_code.value==''){
		alert("Please enter postal code");
		form.postal_code.focus();
		return false;
	}	
	if(form.nationality_id[0].checked == true){
	    if(form.country_iso_2_national.value== ''){
			alert("Please select Residence of Country");
			form.country_iso_2_national.focus();
			return false;
		}if(form.passport_country_iso_2_national.value== ''){
			alert("Please select National of Country");
			form.passport_country_iso_2_national.focus();
			return false;
		}

	}
	if(form.nationality_id[1].checked == true){
	    if(form.country_iso_2_non_srilankan.value== ''){
			alert("Please select Residence of Country");
			form.country_iso_2_non_srilankan.focus();
			return false;
		}if(form.passport_country_iso_2_non_srilankan.value== ''){
			alert("Please select National of Country");
			form.passport_country_iso_2_non_srilankan.focus();
			return false;
		}

	}
	if(form.nationality_id[2].checked == true){
		if(form.passport_country_iso_2_non_srilankan_res.value== ''){
			alert("Please select National of Country");
			form.passport_country_iso_2_non_srilankan_res.focus();
			return false;
		}

	}	
	
	
	//---------phone code and telephone validate
		var country_code = form.country_code.value; 
		var telephone = form.telephone.value;
	if(country_code ==''){
		alert("Please select your country code");
		form.country_code.focus();
		return false;
	}
	
	if(country_code.length == telephone.length){
		alert("Please enter your telephone");
		form.telephone.focus();
		return false;
	}
	
	if(telephone.substring(country_code.length,(country_code.length+1)) == '0'){
		alert("A international telephone number can't start with 0 (zero) after the country code.");
		form.telephone.focus();
		return false;
	}
	
	if(telephone ==''){
		alert("Please enter telephone");
		form.telephone.focus();
		return false;
	}
	//--------------------------
	
	if(form.message.value==''){
		alert("Please enter you message");
		form.message.focus();
		return false;
	}	
		
	validation_code = String(form.validation_code.value);
	if(form.validation_code.value == '' || validation_code.length <8){
		alert("Please enter validation code as shown on screen");
		form.validation_code.focus();
		return false;	
	}
	
	form.btn_submit.disabled = "disabled";
	document.reserv_form.submit();
	return(true);	
}


function validate_contact_form(form){
	if(form.title_id.value==''){
		alert("Please enter your title");
		form.title_id.focus();
		return false;
	}
	
	if(form.first_name.value==''){
		alert("Please enter your first name");
		form.first_name.focus();
		return false;
	}
	
	if(form.last_name.value==''){
		alert("Please enter your last name");
		form.last_name.focus();
		return false;
	}
	
	
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (form.email.value.search(emailRegEx) == -1){
		alert("The format of the \"e-mail\" address is incorrect. Please enter in the format 'john@aol.com'");
		form.email.focus();
		return(false);
	}
	
	//---------phone code and telephone validate
		var country_code = form.country_code.value; 
		var telephone = form.telephone.value;
	if(country_code ==''){
		alert("Please select your country code");
		form.country_code.focus();
		return false;
	}
	
	if(country_code.length == telephone.length){
		alert("Please enter your telephone");
		form.telephone.focus();
		return false;
	}
	
	if(telephone.substring(country_code.length,(country_code.length+1)) == '0'){
		alert("A international telephone number can't start with 0 (zero) after the country code.");
		form.telephone.focus();
		return false;
	}
	
	if(telephone ==''){
		alert("Please enter telephone");
		form.telephone.focus();
		return false;
	}
	//--------------------------
	
	if(form.iso_2.value==''){
		alert("Please Select country");
		form.iso_2.focus();
		return false;
	}
	
	if(form.subject.value==''){
		alert("Please enter subject");
		form.subject.focus();
		return false;
	}
	
	if(form.message.value==''){
		alert("Please enter your message");
		form.message.focus();
		return false;
	}	
	
	validation_code = String(form.validation_code.value);
	
	if(form.validation_code.value == '' || validation_code.length <8){
		alert("Please enter validation code as shown on screen");
		form.validation_code.focus();
		return false;	
	}		
	
	form.btn_submit.disabled = "disabled";
	document.contact_form.submit();
	return true;
}

//reservation select country telephone code

	function onload_code(){
		var country_code = document.getElementById("country_code").value;
		document.getElementById("telephone").value = country_code;
	}
	
	function validate_phone_no(){
		var country_code = document.getElementById("country_code").value;
		var telephone = document.getElementById("telephone").value;
		var country_code_length = country_code.length;
		
		if(country_code_length > telephone.length){
			document.getElementById("telephone").value = country_code;
		} else if(telephone.substring(0,country_code_length) != country_code){
			document.getElementById("telephone").value = country_code;
		}
			
	}
	
function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}
