// JavaScript for flight search Inter tab + Dom tab
headerSelect = 'D';
function SEARCH_onClick(objForm){
	if(jsFn_CheckValidValue(objForm) && goSubmit()){
		objForm.submit();
	}//if
	return false;
}//jsfn

function TYPEOFTRIP_onClick(typeVal){
	document.getElementById("trReturnDate_input").style.display = "none";
	switch(typeVal){
		case "O" :	
			break;
		case "R" :		
		document.getElementById("trReturnDate_input").style.display = "";
			break;
	}//switch
}//jsfn


function jsFn_CheckValidValue(objForm){
	var typeOfTrip = jsFn_getRadioChecked(objForm.TYPEOFTRIP);
//Check  departure & arrival airport**************************************************************
		if(document.AirSearchForm.INTERorDOM.value=='2')
		{
			if(!jsFn_ChkField(objForm.txtDEPARTCITY,"text","สนามบินต้นทาง", 3, 50))	return false;
			if(!jsFn_ChkField(objForm.txtRETURNCITY,"text","สนามบินปลายทาง", 3, 50))	return false;

			if(!jsFn_ChkField(objForm.DEPARTDATE,"text","depart date", 3, 50))	return false;
			if(!jsFn_ChkField(objForm.RETURNDATE,"text","return date", 3, 50))	return false;
			if(objForm.txtDEPARTCITY.value.toLowerCase( ) == objForm.txtRETURNCITY.value.toLowerCase( ))
			{
				alert("เมืองต้นทางและปลายทางเหมือนกัน กรุณาเลือกใหม่อีกครั้ง");
				return false;
			}else{
				objForm.DEPARTCITY.value=objForm.txtDEPARTCITY.value;
				objForm.RETURNCITY.value=objForm.txtRETURNCITY.value;
			}
		}//if
		if(document.AirSearchForm.INTERorDOM.value=='1')
		{
			if(objForm.drpDEPARTCITY.value == objForm.drpRETURNCITY.value)
			{
				alert("เมืองต้นทางและปลายทางเหมือนกัน กรุณาเลือกใหม่อีกครั้ง");
				return false;
			}else
			{
				objForm.DEPARTCITY.value=objForm.drpDEPARTCITY.value;
				objForm.RETURNCITY.value=objForm.drpRETURNCITY.value;
			}
		}//if
//****************************************************************************************
	if(typeOfTrip=="R"){
		if(!jsFn_ChkField(objForm.DEPARTDATE,"date","วันออกเดินทาง"))	return false;
		if(!jsFn_ChkField(objForm.RETURNDATE,"date","วันเดินทางกลับ"))	return false;
		if(gfPop.fDateDiff(objForm.START_DEPART_DATE.value, objForm.DEPARTDATE.value) < 0){
			alert("ระบบอนุญาตวันเดินทางระหว่าง  "+objForm.START_DEPART_DATE.value+" และ "+objForm.TODAYADD9MONTH.value+". \nกรุณาเลือกวันเดินทางใหม่อีกครั้ง");			
			objForm.DEPARTDATE.focus();	return false;
		}//if
		if(!jsFn_ChkStartFinishDate(objForm.DEPARTDATE, objForm.RETURNDATE, "วันออกเดินทาง ต้องน้อยกว่าวันเดินทางกลับ")){	
			objForm.DEPARTDATE.focus();	return false;
		}//if
		if(gfPop.fDateDiff(objForm.RETURNDATE.value, objForm.TODAYADD9MONTH.value) < 0){
			alert("ระบบอนุญาตวันเดินทางระหว่าง  "+objForm.START_DEPART_DATE.value+" และ "+objForm.TODAYADD9MONTH.value+". \nกรุณาเลือกวันเดินทางใหม่อีกครั้ง");			
			objForm.RETURNDATE.focus();	return false;
		}//if		
		if(!jsFn_checkNumberSeat(objForm.ADULTS, objForm.CHILDS, objForm.INFANTS)){
			objForm.ADULTS.focus();	return false;
		}//if
		return true;
	}else if(typeOfTrip == "O"){
		if(!jsFn_checkNumberSeat(objForm.ADULTS, objForm.CHILDS, objForm.INFANTS)){
			objForm.ADULTS.focus();	return false;
		}//if
		return true;			
	}//if
}//fn
function jsFn_checkNumberSeat(objAdult, objChild, objInfant){//for check seat number
	var adultNo = parseInt(objAdult.value);
	var childNo = parseInt(objChild.value);
	var infantNo = parseInt(objInfant.value);
	var total = adultNo+childNo;
	if(total<=9){
		if(infantNo<=adultNo){	
			return true;
		}else{
			alert("Infant  more than adult");	return false;
		}//if
	}else{
		alert("Seats more than 9");	return false;
	}//if
}//jsfn

function ADULTS_setOptions(frm, objAdult, objChild, objInfant) {
	var Maximum = 9;
    var adtultVal = objAdult.options[objAdult.selectedIndex].value;
	if(objInfant !=null ){
		objInfant.options.length = 0;
		for(q=0;q<=adtultVal;q++){
			 objInfant.options[objInfant.options.length] = new Option(q,q);
		}//for
	}//if
	if(objChild != null){
		objChild.options.length = 0;
		for(i=0 ; i <= Maximum ; i++){
			if(adtultVal == i) {
				objChild.options[objChild.options.length] = new Option(0,0);
				for(z=1;z <=(Maximum-i) ; z++){
				  objChild.options[objChild.options.length] = new Option(z,z);
				}//for
				break;
			}//if
		}//for

	}//if
}//fn

function jsFn_DOMInterTab(type){
	switch(type){
		case 1: //Domestic			
			document.AirSearchForm.INTERorDOM.value = "1";
			document.getElementById("imgDOM2").style.display = "";
			document.getElementById("imgInter2").style.display = "";
			document.getElementById("imgDOM1").style.display = "none";
			document.getElementById("imgInter1").style.display = "none";
			document.getElementById("spDepartCity_DOM").style.display = "";
			document.getElementById("spDepartCity_Inter").style.display = "none";
			document.getElementById("spReturnCity_DOM").style.display = "";
			document.getElementById("spReturnCity_Inter").style.display = "none";
			//setRadioChecked("AirSearchForm", "SEARCHMETHOD" , "3", true);
			break;
		case 2: //International
			document.AirSearchForm.INTERorDOM.value = "2";
			document.getElementById("imgDOM2").style.display = "none";
			document.getElementById("imgInter2").style.display = "none";
			document.getElementById("imgDOM1").style.display = "";
			document.getElementById("imgInter1").style.display = "";
			document.getElementById("spDepartCity_DOM").style.display = "none";
			document.getElementById("spDepartCity_Inter").style.display = "";
			document.getElementById("spReturnCity_DOM").style.display = "none";
			document.getElementById("spReturnCity_Inter").style.display = "";
			//setRadioChecked("AirSearchForm", "SEARCHMETHOD" , "6", true);
			break;
	}//switch
	jsFn_doOnload(); 
	
}//if


function jsFn_doOnload(){
	var objForm = document.AirSearchForm;
	var today = new Date();
	objForm.TODAY.value = today.getDate() +"/"+(today.getMonth()+1) +"/"+ today.getFullYear();
	objForm.TODAYADD9MONTH.value = gfPop.fDateAdd(objForm.TODAY.value, 0, 9, 0);
//	objForm.START_DEPART_DATE.value = gfPop.fDateAdd(objForm.TODAY.value, 3, 0, 0);
if(document.getElementById("imgDOM2").style.display ==""){
objForm.START_DEPART_DATE.value = gfPop.fDateAdd(objForm.TODAY.value, 1, 0, 0);
}else{
          objForm.START_DEPART_DATE.value = gfPop.fDateAdd(objForm.TODAY.value, 3, 0, 0);
}


	objForm.DEPARTDATE.value = objForm.START_DEPART_DATE.value;
	objForm.RETURNDATE.value = gfPop.fDateAdd(objForm.DEPARTDATE.value, 2, 0, 0);
	//alert(objForm.TODAY.value+"="+objForm.TODAYADD9MONTH.value+"="+objForm.START_DEPART_DATE.value);
}//fn

<!--
// The following script is used to hide the calendar whenever you click the document.
// When using it you should set the name of popup button or image to "popcal", otherwise the calendar won't show up.
document.onmousedown=function(e){
	var n=!e?self.event.srcElement.name:e.target.name;
	if (document.layers) {
		with (gfPop) var l=pageX, t=pageY, r=l+clip.width, b=t+clip.height;
		if (n!="popcal"&&(e.pageX>r||e.pageX<l||e.pageY>b||e.pageY<t)) gfPop.fHideCal();
		return routeEvent(e);	// must use return here.
	} else if (n!="popcal") gfPop.fHideCal();
}
if (document.layers) document.captureEvents(Event.MOUSEDOWN);
// This is just an example, no guarantee it working in all browsers. You may use your own.
//-->
submitted = false;
function goSubmit(){
	if(submitted==false){
		submitted = true;
		return true;
	}else{
		alert("Your request is processing (Please Wait).\nPlease Click Submit Once Only.\nClicking the Submit button multiple times will result in multiple charges on your credit card.");
		return false;
	}//if
}//jsfn

