function isValidFlight(formName,obDate,ibDate)
{
	var formN=document.forms[""+formName];
	var CHD=formN.CHD.value;
	var ADT=formN.ADT.value;
	var INF=formN.INF.value;
	if(formN.departure.value.indexOf('(')!=-1){formN.departure.value=(formN.departure.value.match("\\([A-Z]{3}\\)\ \-\ ")[0]).match("[A-Z]{3}")[0];}
	if(formN.arrival.value.indexOf('(')!=-1){formN.arrival.value=(formN.arrival.value.match("\\([A-Z]{3}\\)\ \-\ ")[0]).match("[A-Z]{3}")[0];}
	var a=formN.departure.value;
	var d =formN.arrival.value;
	var totPax=parseInt(ADT)+parseInt(CHD)+parseInt(INF);
	if(a==''|| a=='No match found. Try entering first 3 letters and select from the list'){
        alert("Please enter your origin city")
        return false;
        }
        if(d=='' || d=='No match found. Try entering first 3 letters and select from the list'){
        alert("Please enter your destination city")
        return false;
        }
        if(d==a){
        alert("Depart and arrival airport can't be same")
        return false;
        }

	var isvalidD = true;
        var isvalidR = true;
	 isvalidD=isDate(obDate,'ddate');
        if(!isvalidD) return false;
        if(document.forms[""+formName].type[1].checked == true) {
          isvalidR=isDate(ibDate,'rdate')
          if(!isvalidR) return false;
        }

	
	var obDate=obDate.split('/');
	var ibDate=ibDate.split('/');
	var obDay=obDate[0];
	var obYear=obDate[2];
	var obMonth=(obDate[1]-1)
	var ibDay=ibDate[0];
	var ibYear=ibDate[2];
	var ibMonth=(ibDate[1]-1)
	var today=new Date();
	var D=today.getDate();if(D<10){D="0"+D;}
	var M=today.getMonth();if(M<10){M="0"+M;}
	var Y=today.getFullYear();
	var objDiff=daysElapsed(new Date(ibYear,ibMonth,ibDay),new Date(obYear,obMonth,obDay));
	var objDt=daysElapsed(new Date(obYear,obMonth,obDay),new Date(Y,M,D));
	
	if((objDt<0) || (parseInt(ibYear)-parseInt(Y)) < 0){
                alert("Depart date can't be in past")
                return false;
        }
	if(a==''|| a=='No match found. Try entering first 3 letters and select from the list'){
	alert("Please enter your origin city")
	return false;
	}
	if(d=='' || d=='No match found. Try entering first 3 letters and select from the list'){
	alert("Please enter your destination city")
	return false;
	}
	if(d==a){
	alert("Depart and arrival airport can't be same")
	return false;
	}
	if(totPax>9)
	{
	alert("You are allowed a maximum of 9 passengers per Flight booking online.\nIf your group is larger than this, please call our call center.")
	return false;
	}
	if(INF>ADT)
	{
	alert("Total number of infants can't be greater than adults.")
	return false;
	}

	if(objDiff<0 && !document.getElementById('type2').checked)
	{
		alert("Return date must occur after the Depart date.")
		return false;
	}
	else{return true;}
}
function daysElapsed(date1,date2) 
{
 var difference =
        Date.UTC(date1.getYear(),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(date2.getYear(),date2.getMonth(),date2.getDate(),0,0,0);
   return  difference=(difference)/(1000*60*60*24);
}
//to check if date is valid or not;
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
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 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
}

function isDate(dtStr,dt){
	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)
	var str = "Departure";
        if(dt == 'rdate') {
           str = "Return";
        }
        if (pos1==-1 || pos2==-1){
                alert('The '+str+' date format should be : dd/mm/yyyy')
                return false
        }
        if (strMonth.length<1 || month<1 || month>12){
                alert("Please enter a valid "+str+" month")
                return false
        }
        if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
                alert("Please enter a valid "+str+" day")
                return false
        }
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                alert("Please enter a valid 4 digit year between "+str+" "+minYear+" and "+str+" "+maxYear)
                return false
        }
        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
                alert("Please enter a valid "+str+" date")
                return false
        }

return true
}
function showHidert(fName)
{

if(document.forms[""+fName].type[0].checked)
		{
		document.forms[""+fName].rdate.disabled=true;
		document.getElementById('ReturnIcon').style.display='none';
		document.getElementById('ReturnIcon2').style.display='';
		if(document.getElementById('flexicheck')){
		//	document.forms[""+fName].flexisearchcheck.disabled=true;
		}
		/*
		if(document.getElementById("outbound").value == "true")  {
			document.getElementById("flexi_div").style.display = "none";
		}else{
			document.getElementById("flexi_div").style.display = "";
		}
		*/
		}
if(document.forms[""+fName].type[1].checked)
        {
		document.forms[""+fName].rdate.disabled=false;
		document.getElementById('ReturnIcon').style.display='';
		document.getElementById('ReturnIcon2').style.display='none';

        if(document.getElementById('flexicheck')){
		//	document.forms[""+fName].flexisearchcheck.disabled=false;
		}		
		//document.getElementById("flexi_div").style.display = "";
        }
}


// for js error - BUG#1289

function datefill(fn){

var date=new Date();
var d=date.getDate();
var m=date.getMonth()+1;
var y=date.getFullYear();

if(d<10){d="0"+d}
if(m<10){m="0"+m}
var t=d+"/"+m+"/"+y
var r=new Date(m+"/"+d+"/"+y)
r.setDate(date.getDate()+14)

var rD=r.getDate();
var rM=r.getMonth()+1;
var rY=r.getFullYear();
if(rD<10){rD="0"+rD}
if(rM<10){rM="0"+rM}
var rt=rD+"/"+rM+"/"+rY;
//alert(document.form1.ddate.value)
//document.contactForm.ddate.value=t;
//document.form1.rdate.value=rt;
document.forms[""+fn].rdate.value=rt;
//document.form1.rdate.value=rt;
//document.hotelform.cidate.value=t;
//document.hotelform.codate.value=rt;
}



// wait page function

function random_content()
{
	var mycontent=new Array()

	mycontent[1]='<span class=waitText2><b>Special Offer:</b></span> Upto <b>Rs. 3000 cash back</b> on International Air Tickets. <br/>Exclusively for <b>ICICI Bank Internet Banking</b> Customers';
	mycontent[2]='<span class=waitText2><b>Special Offer:</b></span> <b>Flat 10% Cash Back</b> for MasterCard Customers';

	var ry=Math.floor(Math.random()*mycontent.length);

	if (ry==0) ry=1;
	
	//document.getElementById('deal').innerHTML=mycontent[ry];   // Disable for image banner
	//document.write(mycontent[ry]);
}
