function SetDateDiff7(){	
	var NewDate = new Date();	
	if(document.form1.triptype.selectedIndex == 0){
		var DepDate = new Date(document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value); 
		var RetDate = new Date();
		var TimeToAdd; 
		TimeToAdd = DepDate - (-1)* 7 * 86400000; 
		RetDate.setTime(TimeToAdd); 
		document.form1.cmbMonthTo.options[RetDate.getMonth()].selected = '1';
		document.form1.cmbDayTo.options[RetDate.getDate()-1].selected = '1';
		//document.form1.cmbYearTo.options[RetDate.getFullYear()].selected = '1';
		document.form1.cmbYearTo.value=RetDate.getFullYear();
		document.form1.date1.value=document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value;			
		document.form1.date2.value=document.form1.cmbMonthTo.value + '/' + document.form1.cmbDayTo.value + '/' + document.form1.cmbYearTo.value;
	}
	else{
		document.form1.date1.value=document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value;	
	}	
}
function funPutCalDates(){	
	var NewDate = new Date();	
	if(document.form1.triptype.selectedIndex == 0){
		document.form1.date2.value=document.form1.cmbMonthTo.value + '/' + document.form1.cmbDayTo.value + '/' + NewDate.getFullYear();
		var RetDate = new Date(document.form1.cmbMonthTo.value + '/' + document.form1.cmbDayTo.value + '/' + document.form1.cmbYearTo.value); 
		var DepDate = new Date(document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value); 
		if(RetDate>=DepDate)return;
		document.form1.cmbMonthFrom.options[RetDate.getMonth()].selected = '1';
		document.form1.cmbDayFrom.options[RetDate.getDate()-1].selected = '1';
		//document.form1.cmbYearFrom.options[RetDate.getFullYear()].selected = '1';
		document.form1.cmbYearFrom.value=RetDate.getFullYear();
		document.form1.date1.value=document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value;			
		
	}
}

function objCheck(obj){
	objElement = obj;
}

function setDate(){
	var resultDate;
	resultDate = "";
	if (objElement == 'date1'){
		resultDate = document.form1.date1.value;
		var stringArray = resultDate.split("/");
		document.form1.cmbDayFrom.value = stringArray[1].length==1?'0'+stringArray[1]:stringArray[1];
		document.form1.cmbMonthFrom.value = stringArray[0].length==1?'0'+stringArray[0]:stringArray[0];
		document.form1.cmbYearFrom.value = stringArray[2];//.length==1?'0'+stringArray[2]:stringArray[2];
		SetDateDiff7();
	}		
	else if (objElement == 'date2'){
		resultDate = document.form1.date2.value;
		var stringArray = resultDate.split("/");
		document.form1.cmbDayTo.value = stringArray[1].length==1?'0'+stringArray[1]:stringArray[1];
		document.form1.cmbMonthTo.value = stringArray[0].length==1?'0'+stringArray[0]:stringArray[0];
		document.form1.cmbYearTo.value = stringArray[2];//.length==1?'0'+stringArray[2]:stringArray[2];
		funPutCalDates()
	}		
}
////////////////////
function InboundDest(){
	document.form1.txtOutboundDepCity.value = document.form1.txtOutboundDepCity.value.toUpperCase();
	if(document.form1.triptype.selectedIndex == 0){
		document.form1.txtInboundDestCity.value = document.form1.txtOutboundDepCity.value;
	}
}
function InboundDep(){
	document.form1.txtOutboundDestCity.value = document.form1.txtOutboundDestCity.value.toUpperCase();
	if(document.form1.triptype.selectedIndex == 0){
		document.form1.txtInboundDepCity.value = document.form1.txtOutboundDestCity.value;
	}
}
function checkDateValidation(eD){
	var AdvgCurrentDate = new Date();
	var valCurrMonth = AdvgCurrentDate.getMonth()+1;
	var tempAdvMaxDate = DateAdd(AdvgCurrentDate,330,0,0);
	var stringArray = eD.value.split("/");
	if(eval(stringArray[0])< eval(valCurrMonth)){
		eD.value = stringArray[0] + '/' + stringArray[1] + '/' + tempAdvMaxDate.getYear();
	}	
	var blnDate = isDateVal(eD.value);
	return 	blnDate;
}
function checkpassengers(){
	var checkDate;
	var travel_name=document.form1.travelname;
	document.form1.date1.value=document.form1.cmbMonthFrom.value + '/' + document.form1.cmbDayFrom.value + '/' + document.form1.cmbYearFrom.value;			
	document.form1.date2.value=document.form1.cmbMonthTo.value + '/' + document.form1.cmbDayTo.value + '/' + document.form1.cmbYearTo.value;
	if(its_whitespace(travel_name.value) || its_empty(travel_name.value)){
		travel_name.focus();
		alert("Please fill Valid Customer name");
		return;		
	}
	if(!valid_email(document.form1.travelemail)){
		return;		
	}	
	
	checkDate = checkDateValidation(document.form1.date1);
	if(!checkDate){
		alert("Please Select Valid Date For Departing");
		return;
	}
	if(document.form1.triptype.selectedIndex == 0){
		checkDate = "";
		checkDate = checkDateValidation(document.form1.date2);
		if(!checkDate){
			alert("Please Select Valid Date For Returning");
			return;
		}
	}
	if(document.form1.adultno.value == 0 && document.form1.childno.value == 0 && document.form1.infantno.value == 0)	{
		alert('Adult No or Child No or Infant No Should not be null.');
		return;
	}
	if(document.form1.txtOutboundDepCity.value != ''){
		if(funNumChar(document.form1.txtOutboundDepCity) == false){
			return;
		}
	}
	if(document.form1.txtOutboundDestCity.value != ''){
		if(funNumChar(document.form1.txtOutboundDestCity) == false){
			return;
		}
	}
	if(document.form1.triptype.selectedIndex == 0){
		if(document.form1.txtInboundDestCity.value != ''){
			if(funNumChar(document.form1.txtInboundDestCity) == false){
				return;
			}	
		}
		if(document.form1.txtInboundDepCity != ''){
			if(funNumChar(document.form1.txtInboundDepCity) == false){
				return;
			}
		}
	}
	if ( parseInt(document.form1.infantno.value, 10)> parseInt(document.form1.adultno.value,10 )){
		alert('There cannot be more than 1 INFANT per ADULT');
		document.form1.infantno.focus();
		return;
	}
	if (document.form1.txtOutboundDepCity.value ==''){
		alert('DEPARTURE for departure Itinerary is required')
		document.form1.txtOutboundDepCity.focus();
		return;
	}
	if (document.form1.txtOutboundDestCity.value ==''){
		alert('DESTINATION for departure Itinerary is required')
		document.form1.txtOutboundDestCity.focus();
		return;
	}
	if(document.form1.triptype.selectedIndex == 0){
		if (document.form1.txtInboundDepCity.value ==''){
			alert('DEPARTURE for return Itinerary is required')
			document.form1.txtInboundDepCity.focus();
			return;
		}
		if (document.form1.txtInboundDestCity.value ==''){
			alert('DESTINATION for return Itinerary is required')
			document.form1.txtInboundDestCity.focus();
			return;
		}
	}
	if((document.form1.dep_time.value != '') && (document.form1.Dep_Time_Dev.value=='') || (document.form1.dep_time.value == '') && (document.form1.Dep_Time_Dev.value !='')){	
		alert("Provide a valid Time for Departure.");
		GoAhead=0;
		return;
	}
	if (document.form1.selectedIndex == 0){
		if((document.form1.ret_time.value != '') && (document.form1.Ret_Time_Dev.value=='') || (document.form1.ret_time.value == '') && (document.form1.Ret_Time_Dev.value !='')){	
			alert("Provide a valid Time for Return.");
			GoAhead=0;
			return;
		}
	}
	document.form1.submit();
}
function changetimepref(seg){
	if(seg == "1"){
		if(document.form1.dep_time.value == ''){ 
			document.form1.Dep_Time_Dev.value='';
		}
		else if(document.form1.dep_time.value != ''){ 
			document.form1.Dep_Time_Dev.value='2';
		}
	}
	else if(seg == "2"){
		if(document.form1.ret_time.value == ''){ 
			document.form1.Ret_Time_Dev.value='';
		}
		else if(document.form1.ret_time.value != ''){ 
			document.form1.Ret_Time_Dev.value='2';
		}
	}
}
//////////////////////////
var entName = new Array();
var entValue = null;

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
var DefAmt
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++){
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false;
	}
return true;
}

function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}
function funNumChar(obj){
	var varccode,varlen;
	varccode=0;
	varlen=obj.value.length;
	for(i=0;i<varlen;i++){
		varccode=obj.value.charCodeAt(i);
		if((varccode>96 && varccode<123)||(varccode>64 && varccode <91)|| varccode==32 ||(varccode>47 && varccode<58))
		{}
		else{
				varMsg="Only Numbers and/or characters are allowed.";
				alert (varMsg);
				obj.value = "";
				obj.focus();
				return false;	
		}
	}
	return true;

}
function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
	    var c = s.charAt(i);
	    if (((c < "0") || (c > "9"))) return false;
	}
	return true;
}

function validDate(txtDate){
	if(isBlank(txtDate.value)== true) return false;
	if(isDate(txtDate.value) == false){
		alert("A0019: Please enter the valid date in DD/MM/YYYY format");
		txtDate.select();
		txtDate.focus();
	}
}

var NumChars = "0123456789";
function its_whitespace(string_value) {
    var whitespace = " \n\r\t;:'\"/.,[]{}`~!@#$%^&*()_-+=\\|";
    for (var counter = 0; counter < string_value.length; counter++) {
        current_char = string_value.charAt(counter);
        if (whitespace.indexOf(current_char) == -1) {
            return false;
        }
    }
    return true;
}
function its_empty(string_value) {
    if (string_value == "" || string_value == null) {
        return true;
    }
    return false;
}
function SCal(cP,eD,eDP,dmin,dmax,htm){
	clearTimeout(g_tid);
	var s=(g_eD==eD);
	g_cP=cP;
	g_eD=eD;
	g_eDP=eDP;
	g_dmin=dmin;
	g_dmax=dmax;
	g_htm=htm;
	WaitCal(true,s);
}
function WaitCal(i,s){
	if(!document.all)return;
	if(null==cW.g_fCL||false==cW.g_fCL){
		if(i){
			if(s&&"block"==cF.style.display){cF.style.display="none";return;}
			cW.location.replace(g_htm);
			PosCal(g_cP);
			cF.style.display="block";
		}
		g_tid=setTimeout("WaitCal()", 200);
	}
	else {		
		cW.DoCal(g_cP,g_eD,g_eDP,g_dmin,g_dmax);	
	}
}
function PosCal(cP){
	var dB=document.body;var eL=0;var eT=0;
	for(var p=cP;p&&p.tagName!='BODY';p=p.offsetParent){eL+=p.offsetLeft;eT+=p.offsetTop;}
	var eH=cP.offsetHeight;var dH=cF.style.pixelHeight;var sT=dB.scrollTop;
	if(eT-dH>=sT&&eT+eH+dH>dB.clientHeight+sT)eT-=dH;else eT+=eH;
	cF.style.left=eL;cF.style.top=eT;
}
function GetDowStart(){
	return 0;
}
function GetDateFmt(){
	return "mmddyy";
}
function GetDateSep(){
	return "/";
}
function ShowCalendar(eP,eD,eDP)
{
	var gCurrentDate = new Date();	
	var dmin,dmax,valMonth,valMaxYear,valMaxMonth,valMaxDay;
	var htm="cal.html";
	var currDate = new Date();
	valMonth = currDate.getMonth()+1;
	dmin = valMonth + "/" + currDate.getDate()+ "/" + currDate.getYear();
	var tempMaxDate = DateAdd(gCurrentDate,330,0,0);
	valMaxMonth = tempMaxDate.getMonth()+1; 
	valMaxYear = tempMaxDate.getYear(); 
	valMaxDay = tempMaxDate.getDate();
	dmax = valMaxMonth + "/" + valMaxDay + "/" + valMaxYear;
	var strEdDate;
	var stringArray = eD.value.split("/");
	if(stringArray[0] == ""){
		alert("Please select currect month.");
		return;
	}
	
	if(stringArray[1] == ""){
		alert("Please select currect day of the month.");
		return;
	}
	if(eval(stringArray[0])< eval(valMonth)){
		eD.value = stringArray[0] + '/' + stringArray[1] + '/' + valMaxYear;
	}	
	else{
		eD.value = eD.value;
	}
	
	var blnDate = isDateVal(eD.value);	
	if(blnDate){
		SCal(eP,eD,eDP,dmin,dmax,htm);
	}
	else{
		alert("Please Select Valid Date.");
	}	
}

function isDateVal(dtStr){
	var daysInMonth = DaysArrayVal(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	var strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false;
	}
	
	if (strMonth.length<1 || month<1 || month>12){
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false;
	}
return true;
}

function DaysArrayVal(n) {
	for (var i = 1; i <= n; i++){
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11){this[i] = 30}
		if (i==2){this[i] = 29;}
   } 
   return this;
}



function DateAdd(startDate, numDays, numMonths, numYears){
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	var month = returnDate.getMonth()+numMonths;
	if (month > 11){
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	return returnDate;
}


function ifblank(a,b){
	if (a == null || a.value == '')return b;
	return a;
}
function CancelCal(){
	clearTimeout(g_tid);cF.style.display="none";
}
var werd;
function open_(w_,h_){
	var up_=50;
	var left_=50;
	param = 'top='+up_+',left='+left_+',width='+w_+',height='+h_;
	if (werd==null||werd.closed){
		werd=window.open('','', param+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
	}
	else{
		werd.close();
		werd=window.open('','', param+',status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no');
	}

	str_='Our agent may need to contact you for information pertaining to'+ 
	'<ol><li>Travel originating outside the USA.'+
	'<li>Access to additional fares and schedule options (some airlines have great fares but don’t allow them to be published on the web-sites)'+
	'<li>Possible airline flight changes. '+
	'<li>Possible server outage</ol>'+
	'We guarantee that we will not sell or rent your e-mail address to any third party, nor will we send any additional e-mails regarding other offers.';
	werd.document.writeln("<html><head><title>Why should you give your e-mail address?</title><link href='search.css' rel='stylesheet' type='text/css'></head><body><table height=100% width=100%><tr valign=top><td height=80%><b>Why should you give your e-mail address?</b><br>"+str_+"</td></tr><tr><td valign=bottom align=right height=20%><a href=\"javascript:window.close();\">Close window</a></td></tr></table></body></html>");
	werd.focus();
}
//email
function valid_email(obj_email_address) {
	var email_address=obj_email_address.value;
	var err='The Field "E-mail contact" must be a valid email address (like name@yourdomain.com). Please reenter it now.';
    if (email_address.length < 5) {
		alert(err);
        return false;
    }
    // Check @ and .
    at_location = email_address.indexOf("@");
    dot_location = email_address.lastIndexOf(".");
    if (at_location == -1 || dot_location == -1 || at_location > dot_location ) {
		alert(err);
		obj_email_address.focus();
        return false;
    }
	   // Is there at least one character before @?
    if (at_location == 0) {
		alert(err);
		obj_email_address.focus();
        return false;
    }
    // Is there at least one character between @ and .?
    if (dot_location - at_location < 2 ) {
		alert(err);
		obj_email_address.focus();
        return false;
    }
    // Is there at least one character after .?
    if (email_address.length - dot_location < 2) {
		alert(err);
		obj_email_address.focus();
        return false;
    }
    // Otherwise, it's a valid address, so return true
    return true;
}

