// ListBox object code written by Nicolas Viau (Ekidev team)
// Validation code and citylist logic written by Benoit Larose (Ekidev team)
var isMouseOverList=false,currentList=null,origAirport,destAirport;
var POSITIVE_INFINITY=Math.pow(2,32),MAX_CITY_PAIRS=1,MAX_DEPARTURES=2,FLIGHT_PAGE=false,MAX_FLIGHT_SELECTION_MONTH=12,DATE_VALUE_PLANITGO="5";
POS="";
POS_arr="";
var WITHHOLD_SURCHARG=false,CARIBBEAN=new Array("AG","BS","BM","LC","TT","BB"),CARIBBEAN_FLAG=false,SP_CARIBBEAN="VE";
var FAREFAMILY = new Array(
	new Array("GB","LHR","MAN"),
	new Array("FR","CDG"),
	new Array("IL","TLV"),
	new Array("IT","FCO"),
	new Array("SE","ARN","GOT","JKG","LLA","KLR","VBY"),
	new Array("IE","DUB","SNN"),
	new Array("NO","OSL","BGO","SVG","TRD"),
	new Array("DK","CPH","AAL","AAR","BLL"),
	new Array("NL","AMS"));
// remove new Array("CH","ZRH") from the above array to remove switzerland farefamiy

function ListBox(){
	this.div=null;
	this.list=new Array();
	this.codeField="value";
	this.valueField="text";
	this.maxLength=20;
	this.maxShownLength=8;
	this.maxHeight=160;
	this.minChars=3;
	this.currentIndex=-1;
	this.searchHandler=new function(entry){};
	this.fullListHandler=new function(entry){};
	this.codeInputs=new Object();
	this.valueInputs=new Object();
	this.targetObjects=new Object();
	this.targetBox;
	this.fieldsTohide=new Object();
	this.nextFocusField=new Object();
	this.scrollingIncrement=16;
}
var lP=ListBox.prototype;
lP.show=function(){
	for(var cpt in this.fieldsTohide[this.targetBox.id]){
		if(document.getElementById(this.fieldsTohide[this.targetBox.id][cpt])!=null)
		{
			var theSelect=document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]);
			var tmpValue = theSelect.options[theSelect.selectedIndex].text;
			document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]).style.display="none";
			if(document.getElementById((this.fieldsTohide[this.targetBox.id][cpt])+"_replacement")!=null)
			{
				 document.getElementById((this.fieldsTohide[this.targetBox.id][cpt])+"_replacement").style.display="inline";
				 document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]+"_replacement").value=tmpValue;
			}
		}
	}
	if(this.div!=null){
		this.position();
		this.div.style.display="block";
	}
}
lP.hide=function(){
	if(this.div!=null&&!isMouseOverList) this.div.style.display="none";
	if(!isMouseOverList){
		if(this.fieldsTohide[this.targetBox.id]!=null){
			for(var cpt=0;cpt<this.fieldsTohide[this.targetBox.id].length;cpt++){
				if(document.getElementById(this.fieldsTohide[this.targetBox.id][cpt])!=null)
				{
					if(document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]+"_replacement")!=null)
						document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]+"_replacement").style.display="none";
					document.getElementById(this.fieldsTohide[this.targetBox.id][cpt]).style.display="inline";
				}
			}
		}
	}
}
lP.open=function(list){
	this.list=list;
	this.currentIndex=(this.list!=null&&this.list.length>0)?0:-1;
	if(this.div==null){
		this.div=document.createElement("div");
		document.getElementsByTagName("body")[0].appendChild(this.div);
		if(ie){
			this.div.attachEvent("onmouseover",this.mover);
			this.div.attachEvent("onmouseout",this.mout);
			this.div.attachEvent("onclick",this.mclick);
		}else{
			this.div.addEventListener("mouseover",this.mover,true);
			this.div.addEventListener("mouseout",this.mout,true);
			this.div.addEventListener("click",this.mclick,true);
		}
	}
	if(list==null||list.length<=0) return;
	this.div.style.height=(list.length>=this.maxShownLength)?this.maxHeight+"px":"";
	this.div.innerHTML="";
	this.div.className="listbox";
	for(var i=0;(i<list.length)&&(i<this.maxLength);i++){
		var node=document.createElement("div");
		node.setAttribute("pos",i);
		node.setAttribute("code",list[i][this.codeField]);
		node.appendChild(document.createTextNode(list[i][this.valueField]));
		if(ie){
			node.attachEvent("onmouseover",this.mouseOverItem)
			node.attachEvent("onmouseout",this.mouseOutItem)
		}else{
			node.addEventListener("mouseover",this.mouseOverItem,true)
			node.addEventListener("mouseout",this.mouseOutItem,true)
		}
		this.div.appendChild(node);
	}
	if(this.currentIndex>=0) this.div.childNodes[this.currentIndex].className="over";
	this.show();
}
lP.mover=function(){isMouseOverList=true;}
lP.mout=function(){
	isMouseOverList=false;
	currentList.currentIndex=-1;
}
lP.mclick=function(){
	if(!isMouseOverList){
		var data=this.searchHandler(target.value);
		if(data.length==1){
			currentList.updateRegisteredInputs();
			currentList.targetBox.value=currentList.close();
			currentList.targetBox.className="";
			currentList.mout();
			currentList.nextFocus();
		}
	}
	else{
		currentList.updateRegisteredInputs();
		currentList.targetBox.value=currentList.close();
		currentList.targetBox.className="";
		currentList.mout();
		currentList.nextFocus();
	}
	currentList.hide();
}
lP.clickOut=function(o,e){
	if(!e) e=window.event;
	if(!isMouseOverList){
		var data=o.searchHandler(getEventTarget(e).value);
		if(data.length==1 && o.targetBox.id==getEventTarget(e).id){
			o.list=data;
			o.currentIndex=0;
			o.targetBox.value=o.close();
			o.updateRegisteredInputs();
			o.targetBox.className="";
			o.mout();
		}
	}
}
lP.close=function(){
	this.hide();
	return this.getSelectedValue();
}
lP.unselect=function(){for(var i=0;i<this.div.childNodes.length;i++) this.div.childNodes[i].className="";}
lP.mouseOverItem=function(event){
	var target=getEventTarget(event);
	currentList.unselect();
	currentList.currentIndex=target.getAttribute("pos");
	target.className="over";
}
lP.mouseOutItem=function(event){
	var target=getEventTarget(event);
	target.className="";
}
lP.selectFirst=function(){
	if(list.length<1) return;
	this.unselect();
	this.div.childNodes[0].className="on";
	this.currentIndex=0;
}
lP.scrollUp=function(){
	var presentVisible= parseInt((this.currentIndex) * this.scrollingIncrement);
	this.div.scrollTop=presentVisible-this.scrollingIncrement;
}
lP.scrollDown=function(){
	var presentVisible=parseInt((this.currentIndex-3) * this.scrollingIncrement);
	this.div.scrollTop=presentVisible+this.scrollingIncrement;
}
lP.selectNext=function(){
	this.unselect();
	if(this.currentIndex<0) this.currentIndex=0;
	else if(this.currentIndex<(this.div.childNodes.length-1)){this.currentIndex++;this.scrollDown();}
	this.div.childNodes[this.currentIndex].className="on";
}
lP.selectPrevious=function(){
	this.unselect();
	if(this.currentIndex>0){ this.currentIndex--;this.scrollUp();}
	this.div.childNodes[this.currentIndex].className="on";
}
lP.getSelectedCode=function(){return (this.currentIndex<0||this.currentIndex>=this.list.length)?null:this.list[this.currentIndex][this.codeField];}
lP.getSelectedObject=function(){return (this.currentIndex<0||this.currentIndex>=this.list.length)?null:this.list[this.currentIndex];}
lP.getSelectedValue=function(){return (this.currentIndex<0||this.currentIndex>=this.list.length)?null:this.list[this.currentIndex][this.valueField];}
lP.processKey=function(keyCode,target){ 
    switch(keyCode){ 
        case 38:break; 
        case 40:break; 
        case 9: case 13:;break; 
        default: if((target.value.length)>=this.minChars){ 
            var data=this.searchHandler(target.value); 
            if(data.length==0) {this.targetBox.className='invalid';this.hide();} 
            else{this.targetBox.className= '' ;this.open(data);} 
            if(this.div!=null&&this.div.scrollTop!=null)this.div.scrollTop=0; 
        }else{this.targetBox.className='';this.hide();} 
    } 
    return true; 
} 
lP.processKeyEvent=function(e,o){
	if(!e) e=window.event;
	var result=o.processKey(e['keyCode'],o.targetBox);
	if(!result){
		if(e.preventDefault) e.preventDefault();
		e.returnValue=false;
	}
}
lP.processKeyDownEvent=function(e,o){
	currentList=o;
	if(!e) e=window.event;
	if(o.targetBox!=getEventTarget(e)){
		o.targetBox=getEventTarget(e);
		o.list=null;
	}
	switch(e['keyCode']){
		case 38: this.selectPrevious(); break;
		case 40: this.selectNext(); break;
		case 9:	if(o.div.style.display=="block"&&o.currentIndex>=0){
			o.updateRegisteredInputs();
			o.targetBox.value=o.close();
			o.mout();
			o.hide();
		} break;
		case 13: if(o.div.style.display=="block"&&o.currentIndex>=0){
			o.updateRegisteredInputs();
			o.targetBox.value=o.close();
			o.mout();
			o.nextFocus();
			o.hide();
		} break;
	}
}
lP.processFullListing=function(target,o){
	currentList=o;
	if(currentList.targetBox!=target){
		currentList.targetBox=target;
		currentList.list=null;
	}
	//o.updateRegisteredInputs();
	var data=this.fullListHandler();
	(data.length==0)?currentList.hide():currentList.open(data);
	if(currentList.div!=null&&currentList.div.scrollTop!=null)currentList.div.scrollTop=0;
	//currentList.targetBox.value=currentList.close();
	currentList.mout();
	//currentList.hide();
}
lP.setSearchHandler=function(f){this.searchHandler=f;}
lP.setFullListHandler=function(f){this.fullListHandler=f;}
lP.updateRegisteredInputs=function(){
	if(this.codeInputs[this.targetBox.id]!=null){
		for(var cpt=0;cpt<this.codeInputs[this.targetBox.id].length;cpt++){
			if(document.getElementById(this.codeInputs[this.targetBox.id][cpt])!=null) document.getElementById(this.codeInputs[this.targetBox.id][cpt]).value=this.getSelectedCode();
		}
	}
	if(this.valueInputs[this.targetBox.id]!=null){
		for(cpt2=0;cpt2<this.valueInputs[this.targetBox.id].length;cpt2++){
			if(document.getElementById(this.valueInputs[this.targetBox.id][cpt2])!=null) document.getElementById(this.valueInputs[this.targetBox.id][cpt2]).value=this.getSelectedValue();
		}
	}
	this.targetObjects[this.targetBox.id]=this.getSelectedObject();
	showAndHide();
}
lP.registerCodeInput=function(toRegisterFor,codeInputToRegister){
	if(this.codeInputs[toRegisterFor]==null) this.codeInputs[toRegisterFor]=new Array();
	this.codeInputs[toRegisterFor].push(codeInputToRegister);
}
lP.registerValueInput=function(toRegisterFor,valueInputToRegister){
	if(this.valueInputs[toRegisterFor]==null)	this.valueInputs[toRegisterFor]=new Array();
	this.valueInputs[toRegisterFor].push(valueInputToRegister);
}
lP.registerNextFocusField=function(toRegisterFor,valueInputToRegister){
	if(this.nextFocusField[toRegisterFor]==null) this.nextFocusField[toRegisterFor]=new Array();
	this.nextFocusField[toRegisterFor].push(valueInputToRegister);
}
lP.registerTargetObject=function (toRegisterFor,targetObject){this.targetObjects[toRegisterFor]=targetObject;}
lP.registerFieldTohide=function(toRegisterFor,fieldName){
	if(this.fieldsTohide[toRegisterFor]==null) this.fieldsTohide[toRegisterFor]=new Array();
	this.fieldsTohide[toRegisterFor].push(fieldName);
}
lP.nextFocus=function(){
	if(this.nextFocusField[this.targetBox.id]!=null){
		for(var cpt=0;cpt<this.nextFocusField[this.targetBox.id].length;cpt++){
			if(document.getElementById(this.nextFocusField[this.targetBox.id][cpt])!=null) document.getElementById(this.nextFocusField[this.targetBox.id][cpt]).focus();
		}
	}
}
var ie=document.all;
function getEventTarget(event){
	if(ie) return window.event.srcElement;
	else return (event.target)?event.target:event;
}
lP.findPosX=function(obj){
	var curleft=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curleft+=obj.offsetLeft;
			obj=obj.offsetParent;
		}
	}
	else if(obj.x) curleft+=obj.x;
	return curleft;
}
lP.findPosY=function(obj){
	var curtop=0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curtop+=obj.offsetTop;
			obj=obj.offsetParent;
		}
	}
	else if(obj.y) curtop+=obj.y;
	return curtop;
}
lP.position=function(){
	var c=this.div;
	c.style.position="absolute";
	c.style.left=this.findPosX(this.targetBox)+"px";
	c.style.top=(this.findPosY(this.targetBox)+18)+"px";
	c.style.display="block";
}
function d(id,text){document.getElementById(id).value+=text;}
function hideDiv(divId){document.getElementById(divId).style.display="none";}
function showDiv(divId){document.getElementById(divId).style.display="block";}
function parseInputString(input){
	input=input.replace(/[eéèêëEÉÈÊË]/g,"e");
	input=input.replace(/[aàâäAÀÂÄ]/g,"a");
	input=input.replace(/[iïîìIÏÎÌ]/g,"i");
	input=input.replace(/[oôöòOÔÖÒ]/g,"o");
	input=input.replace(/[uûüùUÛÜÙ]/g,"u");
	input=input.replace(/[cçCÇ]/g,"c");
	input=input.replace(/[-]/g," ");
	return input.toLowerCase();
}
String.prototype.soundex=function(p){
	p=isNaN(p)?4:p>10?10:p<4?4:p;
	var m={BFPV:1,CGJKQSXZ:2,DT:3,L:4,MN:5,R:6},r=(s=this.toUpperCase().replace(/[^A-Z]/g,"").split("")).splice(0,1);
	for(var i in s){
		for(var j in m){
			if(j.indexOf(s[i])+1&&r[r.length-1]!=m[j]&&r.push(m[j])) break;
		}
	}
	return r.length>p&&(r.length=p),r.join("")+(new Array(p-r.length+1)).join("0");
}
function CityList(){
	this.cities=new Array();
	this.listInUse=false;
	this.countriesList=new CountriesList();
	this.statesList=new StatesList();
	this.populate();
}
var cP=CityList.prototype;
cP.add=function(ac,co,st,n,f,err,start,end){
	var airport=new Airport(ac,co,st,n,f,err,start,end);
	airport.setText(this.countriesList,this.statesList);
	this.cities.push(airport);
}
cP.populate=function(){populateCities(this);}
cP.sortAirportsByName=function(a,b)
{
	if(a.name==b.name)return 0;
	if(a.name<b.name){return -1};
	if(a.name>b.name){return 1};

}
cP.getFullAirportsList=function(){
	var airports=new Array();
		for(var cpt=0;cpt<this.cities.length;cpt++){
			airports.push(this.cities[cpt]);
		}
	airports.sort(cP.sortAirportsByName);
	return airports;
}
cP.findCity=function(name){
	var airports=new Array(),cleanName=parseInputString(name),reClean=new RegExp("\\b"+cleanName),re=new RegExp("\\b"+name);
	for(var cpt=0;cpt<this.cities.length;cpt++){
		if(this.cities[cpt].getCleanName().match(reClean)&&this.cities[cpt].isEndDateValid()) airports.push(this.cities[cpt]);
		else if((this.cities[cpt].text.match(re)||this.cities[cpt].text==name)&&this.cities[cpt].isEndDateValid()) airports.push(this.cities[cpt]);
	}
	return airports;
}
cP.findCode=function(code){
	code=parseInputString(code);
	var airports=new Array(),subLenght=code.length,re=new RegExp("\\b"+code);
	for(var cpt=0;cpt<this.cities.length;cpt++){
		if(parseInputString(this.cities[cpt].getCode()).match(re)&&this.cities[cpt].isEndDateValid()) airports.push(this.cities[cpt]);
	}
	return airports;
}
cP.findCountries=function(country){
	country=parseInputString(country);
	var airports=new Array(),subLenght=country.length,re=new RegExp("\\b"+country),countryList=new CountriesList();
	for(var cpt=0;cpt<this.cities.length;cpt++){
		var coComplete=null;
		coComplete=countryList.countries[this.cities[cpt].country];
			if(coComplete!=null&&(parseInputString(countryList.countries[this.cities[cpt].country]).match(re))&&this.cities[cpt].isEndDateValid())
				airports.push(this.cities[cpt]);
	}
	return airports;
}
cP.findStates=function(state){
	state=parseInputString(state);
	var airports=new Array(),subLenght=state.length,stateList=new StatesList();
	for(var cpt=0;cpt<this.cities.length;cpt++){
		var coComplete=stateList.states[this.cities[cpt].state];
		if(coComplete!=null&&(parseInputString(stateList.states[this.cities[cpt].state]).substring(0,subLenght)==state)&&this.cities[cpt].isEndDateValid()) airports.push(this.cities[cpt]);
	}
	return airports;
}
cP.findSoundex=function(givenValue){
	givenValue=parseInputString(givenValue);
	var airportsFromCountry=new Array(),airportsFromName=new Array(),subLenght=givenValue.length;
	if(givenValue.length>4){
		for(var cpt=0;cpt<this.cities.length;cpt++){
			if(this.cities[cpt].getCleanName().substring(0,1)==givenValue.substring(0,1)){
				if(parseInputString(this.cities[cpt].getCleanName().substring(0,subLenght)).soundex()==givenValue.soundex()&&this.cities[cpt].isEndDateValid())
					airportsFromName.push(this.cities[cpt]);
			}
		}
	}
	if(givenValue.length>4){
		for(cpt=0;cpt<this.cities.length;cpt++){
			if(parseInputString(this.cities[cpt].country).substring(0,subLenght).soundex()==givenValue.soundex()) airportsFromCountry.push(this.cities[cpt]);
		}
		return purgeDoubleEntries(airportsFromName,airportsFromCountry);
	}
	return airportsFromName;
}
function purgeDoubleEntries(airportArray1,airportArray2,nbresults){
	for(var nbap=0;nbap<airportArray1.length;nbap++){
		for(var nbap2=0;nbap2<airportArray2.length;nbap2++){
			if(airportArray1[nbap].getName()==airportArray2[nbap2].getName()) airportArray2.splice(nbap2,1);
		}
	}
	airportArray1=airportArray1.concat(airportArray2);
	if(nbresults!=null&&airportArray1.length>nbresults)	return airportArray1.slice(0,nbresults);
	return airportArray1;
}
function Airport(ac,co,st,n,f,err,stDate,enDate){
	this.code=ac;
	this.state=st;
	this.country=co;
	this.name=n;
	this.flag=f;
	this.cleanName=parseInputString(n);
	this.value=ac;
	this.text=null;
	this.errMsg=err;
	this.startDate=stDate;
	this.endDate=enDate;
}
var aP=Airport.prototype;
aP.getCode=function(){return this.code;}
aP.isEndDateValid=function(){
	if(this.endDate!=null&&this.endDate!=""){
		if(parseDateFromForm(this.endDate)<getGMTServerDate()) return false;
	}
	return true;
}
aP.setText=function(countriesList,statesList){
	this.text=this.name;
	if(this.state==""){
		if(countriesList.countries[this.country]!=null) this.text=this.text+", "+countriesList.countries[this.country];
	}else this.text=this.text+", "+statesList.states[this.state];
	this.text=this.text+" ("+this.code+")";
	return this.text;
}
aP.getValue=function(){return this.name;}
aP.getState=function(){return this.state;}
aP.getCountry=function(){return this.country;}
aP.getName=function(){return this.name;}
aP.getFlag=function(){return this.flag;}
aP.getCleanName=function(){return this.cleanName;}
function validateSubmit(formActionValue){
	//var objErr;
	//try{
		messagesList.errorMessages=new Array();
		var checkNeeded=fl.tripType[0].checked==true,inpageErrorFlag=false;
		origAirport=fetchAiport("org1","origin1");
		if(origAirport==null){
			processErrors();
			return false;
		}else{
			destAirport=fetchAiport("dest1","destination1");
			if(destAirport==null){
				processErrors();
				return false;
			}
		}
		if(origAirport.code==destAirport.code){
		  messagesList.addMessage("SAMEAIRPORTS",destAirport);
			fl.dest1.focus();
			processErrors();
			return false;
		}
		if(fl.tripType[0].checked==true){
			if(!isDateDefined(fl.date_from)){
				fl.date_from.focus();
				return false;
			}
			if(!isDateDefined(fl.date_to)){
				fl.date_to.focus();
				return false;
			}
		}else{
			if(!isDateDefined(fl.date_from)){
				fl.date_from.focus();
				return false;
			}
		}
		if(!isDatesValidForAirport(origAirport)) inpageErrorFlag=true;
		if(!isDatesValidForAirport(destAirport)) inpageErrorFlag=true;
		if(origAirport.errMsg!=null&&origAirport.errMsg!=""){
			messagesList.addMessage(origAirport.errMsg,origAirport);
			fl.org1.focus();
			inpageErrorFlag=true;
		}
		if(destAirport.errMsg!=null&&destAirport.errMsg!=""){
		  messagesList.addMessage(destAirport.errMsg,destAirport);
			fl.dest1.focus();
			inpageErrorFlag=true;
		}
		if((origAirport.country=="US"||destAirport.country=="US")&&(origAirport.country=="CU"||destAirport.country=="CU")){
			messagesList.addMessage("USACUBA");
			inpageErrorFlag=true;
		}
		if(origAirport.country=="US"&&destAirport.country=="US"){
			messagesList.addMessage("BOTHUSA");
			inpageErrorFlag=true;
		}
		if((Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)+Number(fl.numberOfChildren.options[fl.numberOfChildren.selectedIndex].value))>9){
			messagesList.addMessage("NBPASSENGERS");
			inpageErrorFlag=true;
		}
		if(document.getElementById("Infant").style.display!='none'&&Number(fl.numberOfInfants.options[fl.numberOfInfants.selectedIndex].value)>Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)){
			messagesList.addMessage("NBINFANTS");
			inpageErrorFlag=true;
		}
		if(document.getElementById('promotionCode')!=null){
			if(!validatePromotionCode()){
				messagesList.addMessage("PROMOTIONCODEERROR");
				inpageErrorFlag=true;
			}
			if(!validateInfantHomePromotion()){
				messagesList.addMessage("PROMOTIONCODEINFANTSERROR");
				inpageErrorFlag=true;
			}
		}
		if(inpageErrorFlag){
			processErrors();
			return false;
		}
		if(dpg.PRIVATE_LABEL.value!="AGENT"){
			fl.action=(getCookie("AC-Signon-Cookie"))?"https://www.aircanada.com/secure/aco/flights.do":"http://www.aircanada.com/aco/flights.do";
		}
		if(origAirport!=null&&destAirport!=null){
			checkforTyrolean(origAirport.code,destAirport.code);
			var cookieLife= 5*365;
			setCookie("cityCookie",fl.origin1.value,cookieLife,"/");
			var isReqFromOffers=false,agentRequest=false,promotionCodeReq=false;
			if(location.pathname.indexOf("offers")>-1) isReqFromOffers=true;
			if(dpg.PRIVATE_LABEL.value=="AGENT")	agentRequest=true;
			if(document.getElementById('Promotion Code')!=null){
				var resCountry=fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value;
				if(resCountry=="CA"||resCountry=="US"){
					if(fl.promotionCode!=null&&fl.promotionCode.value!="") promotionCodeReq=true;
				}else{
					dpg.NTP_AUTHORIZATION.value="true";
    	            fl.promotionCode.value = "";
				}
			}
			if(promotionCodeReq){
				fl.promotionCode.focus();
				var flag=checkAgentDetails();
				if(flag){
					if(document.flights.fromHomePage.value == "YES"){
						var objErrsub1;
						try{
							fl.submit();
						}catch(objErrsub1) {}
						WDSWaitingImage.pleaseWait("anim_waiting-bar");
					}else{
					setNTPFormFields("Flights");
		      document.FlightSearchNTPRequestForm.submit();
					WDSWaitingImage.pleaseWait("anim_waiting-bar");
						var objErrsub;
						try{
							fl.submit();
						}catch(objErrsub) {}
					}
				}
			}else{
				if((agentRequest&&isReqFromOffers)){
					WDSWaitingImage.pleaseWait("anim_waiting-bar");
					var objErrsub2;
					try{
						fl.submit();
					}catch(objErrsub2) {}
				}else{
					setFormFields();
					if(agentRequest&&!isReqFromOffers) setFlightSearchCookie("ADO");
					else if(!agentRequest&&!isReqFromOffers) setFlightSearchCookie("ACO");
					if(formActionValue)	dpg.action=formActionValue;
					WDSWaitingImage.pleaseWait("anim_waiting-bar");
					var objErr3
					try{
						dpg.submit();
					}catch(objErr3){}
					return;
				}
				WDSWaitingImage.pleaseWait("anim_waiting-bar");
			}
		}
		//}catch (objErr) { alert(objErr.message); }
	//fl.submit();
	return false;
}
function findAirportFromName(name){
	var airportName=name,airport=list.targetObjects[airportName];
	if(airportName!=null&&airportName!=""){
		if(airport!=null&&airport.text==airportName) return airport;
	}else return null;
	return null;
}
function isDateDefinedTest(f){return (f.value=="")?false:true;}
function refreshDiv(divName,contents){
	document.getElementById(divName).innerHTML=contents;
	(contents!="")?showDiv(divName):hideDiv(divName);
}
function processErrors(){
	var contents="",image="<img src=\"http://www.aircanada.com/shared/images/common/i_error.gif\" width=\"20\" height=\"20\" alt=\"!\" border=\"0\"/>";
	if(messagesList.errorMessages.length>0){
		contents+="<table  width='100%'>";
		for(var cpt=0;cpt<messagesList.errorMessages.length;cpt++){
			if(cpt==1) image="";
			contents+="<tr><td class='errors'>"+image+"</td><td class='errors'>"+messagesList.errorMessages[cpt]+"</td></tr>";
		}
		contents+="</table>";
	}
	refreshDiv("errorMsg",contents);
}
function fetchAiport(nameFieldId,codeFieldId){
	var msgToUse="NORESULTSORIGIN";
	if(nameFieldId == "dest1")msgToUse="NORESULTSDESTINATION";
	var airportName="";
	if(document.getElementById(nameFieldId)!=null&&document.getElementById(nameFieldId).value!=null) airportName=document.getElementById(nameFieldId).value;
	var airportCode="";
	if(document.getElementById(codeFieldId)!=null&&document.getElementById(codeFieldId).value!=null) airportCode=document.getElementById(codeFieldId).value;
	var airport=list.targetObjects[nameFieldId];
	if(airport==null&&airportCode!=""&&getAirportFromCode(airportCode).text==airportName)	airport=getAirportFromCode(airportCode);
	if(airportName!=null&&airportName!="")
	{
		if(airport!=null&&airport.text==airportName){
			document.getElementById(nameFieldId).className="";
			return airport;
		}else{
			document.getElementById(nameFieldId).className="";
			list.targetBox=document.getElementById(nameFieldId);
			var airPortslist = searchAirports(airportName,true);
			if(airPortslist.length == 1)
			{
				  document.getElementById(codeFieldId).value=airPortslist[0].code;
				  document.getElementById(nameFieldId).value=airPortslist[0].name;
					return airPortslist[0];
			}
			else if(airPortslist.length > 1){
				messagesList.addMessage("AMBIGUOUS");
				document.getElementById(nameFieldId).className="invalid";
				document.getElementById(nameFieldId).focus();
				processErrors();
				list.open(airPortslist);
			  return null;
			}
		}
	}
  messagesList.addMessage(msgToUse);
  document.getElementById(nameFieldId).className="invalid";
  document.getElementById(nameFieldId).focus();
  processErrors();
  return null;
}
function isDate1BeforeDate2(theDate1,theDate2){
	if(theDate1.getFullYear()!=theDate2.getFullYear()) return theDate1.getFullYear()<theDate2.getFullYear();
	if(theDate1.getMonth()!=theDate2.getMonth()) return theDate1.getMonth()<theDate2.getMonth();
	return theDate1.getDate()<theDate2.getDate();
}
function isDate1equalsDate2(theDate1,theDate2){
	return theDate1.getFullYear()==theDate2.getFullYear()&&theDate1.getMonth()==theDate2.getMonth()&&theDate1.getDate()==theDate2.getDate();
}
function parseDateFromForm(text){
	text = text.replace(/\*/,'');
	var parts=text.split(/[-\/]/),origPartsLenght=parts.length;
	if(parts.length<2||parts.length>3) return null;
	if(parts.length==2)	parts[2]=String((getGMTServerDate()).getFullYear());
	else if(parts[2].length<=2)	parts[2]=String(2000+Number(parts[2]));
	if(parts[0].length<1||parts[0].length>2||! parts[0].match(/[0-9]+/)) return null;
	if(parts[1].length<1||parts[1].length>2||! parts[1].match(/[0-9]+/)) return null;
	if(parts[2].length==0||parts[2].length==3||parts[2].length>4||! parts[2].match(/[0-9]+/))	return null;
	var newDate=new Date(parts[2],Number(parts[1])-1,parts[0]);
	return newDate;
}
function isDatesValidForAirport(airport){
	if(airport.startDate==null&&airport.endDate==null) return true;
	var msg,roundTrip=fl.tripType[0].checked==true,inboundDate=parseDateFromForm(document.getElementById("date_from").value),outboundDate;
	if(roundTrip) outboundDate=parseDateFromForm(document.getElementById("date_to").value);
	var airportStart, airportEnd, exclusion=false;
	if(airport.startDate!=""&&airport.startDate!=null){
		exclusion=airport.startDate.indexOf("*")!=-1;
		airportStart=parseDateFromForm(airport.startDate);
	}
	if(airport.endDate!=""&&airport.endDate!=null){
		exclusion=airport.endDate.indexOf("*")!=-1 || exclusion;
		airportEnd=parseDateFromForm(airport.endDate);
	}
	if(exclusion){
		 if((isDate1BeforeDate2(airportStart,inboundDate)||isDate1equalsDate2(airportStart,inboundDate))&&(isDate1BeforeDate2(inboundDate,airportEnd)||isDate1equalsDate2(inboundDate,airportEnd))){
			 document.getElementById("date_from").className="invalid";
			 messagesList.addMessage("EXCLUDEDDATES",airport);
			 return false;
		 }
		 if(roundTrip){
			 if((isDate1BeforeDate2(airportStart,outboundDate)||isDate1equalsDate2(airportStart,outboundDate))&&(isDate1BeforeDate2(outboundDate,airportEnd)||isDate1equalsDate2(outboundDate,airportEnd))){
				 document.getElementById("date_to").className="invalid";
				 messagesList.addMessage("EXCLUDEDDATES",airport);
				 return false;
		    }
		 }
		document.getElementById("date_from").className="";
		document.getElementById("date_to").className="";
		return true;
	}
	if((airportStart!=null||airportEnd!=null)&&(airportStart==null||airportEnd==null)){
		if(airportStart!=null){
			if(isDate1BeforeDate2(inboundDate,airportStart)){
				document.getElementById("date_from").className="invalid";
				messagesList.addMessage("BADSTARTDATE",airport);
				return false;
			}
		}
		if(airportEnd!=null&&roundTrip){
			if(isDate1BeforeDate2(airportEnd,outboundDate)){
				document.getElementById("date_to").className="invalid";
				messagesList.addMessage("BADENDDATE",airport);
				return false;
			}
		}else if(airportEnd!=null){
			if(isDate1BeforeDate2(airportEnd,inboundDate)){
				document.getElementById("date_from").className="invalid";
				messagesList.addMessage("BADENDDATE",airport);
				return false;
			}
		}
	}else if(airportStart!=null&&airportEnd!=null){
		var isRoundTripInvalid=false,startAndInbondDatesInvalid=false, oneWayInvalid=false;
		if(roundTrip){ isRoundTripInvalid=isDate1BeforeDate2(airportEnd,outboundDate);}
		else{oneWayInvalid=isDate1BeforeDate2(airportEnd,inboundDate);}
		startAndInbondDatesInvalid=isDate1BeforeDate2(inboundDate,airportStart);
		if(isRoundTripInvalid) document.getElementById("date_to").className="invalid";
		if(startAndInbondDatesInvalid||oneWayInvalid) document.getElementById("date_from").className="invalid";
		if(startAndInbondDatesInvalid||isRoundTripInvalid||oneWayInvalid){
			messagesList.addMessage("BADBOTHDATES",airport);
			return false;
		}
	}
	document.getElementById("date_from").className="";
	document.getElementById("date_to").className="";
	return true;
}
function isAirportsUsCuba(){
	var usCity=false,cubaCity=false;
	if(origAirport.country=="US"||destAirport.country=="US") usCity=true;
	if(origAirport.country=="CU"||destAirport.country=="CU") cubaCity=true;
	return usCity&&cubaCity;
}
function checkFlightType(domestic,transborder,international,faredriven){
	if(fl.fromHomePage!=null){
		if(international||CARIBBEAN_FLAG){
			document.getElementById('InfantText').style.display='block';
			document.getElementById('SeniorText').style.display='none';
		}else{
			document.getElementById('InfantText').style.display='none';
			document.getElementById('SeniorText').style.display='block';
		}
	}
	if((international||!faredriven)){
		document.getElementById('Shop').style.display='block';
	}else{
		document.getElementById('Shop').style.display='none';
	}
	if(international||CARIBBEAN_FLAG){
		document.getElementById('Infant').style.display='none';
	}else{
		document.getElementById('Infant').style.display='block';
	}
	if(international||!faredriven) document.getElementById('Flexible').style.display=(fl.searchType[1].checked)?'none':'block';
	else document.getElementById('Flexible').style.display='none';
	if(international&&fl.searchType[1].checked){
		document.getElementById('Class').style.display='block';
	}else{
		document.getElementById('Class').style.display='none';
	}
	countrydisplay=dpg.PRIVATE_LABEL.value!="AGENT"&&!(getCookie("AC-Signon-Cookie")&&getCookie("AC-Session-Cookie"));
	if(countrydisplay){
		corValue=fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value;
		if(corValue!="CA"&&corValue!="US"&&corValue!="O"&&POS==""){
			countryVal=getCookie('country_pref');
			(countryVal=="CA"||countryVal=="US"||countryVal==COUNTRY_POS.toString().match(countryVal))?popSelectionData(fl.countryOfResidence,countryVal):popSelectionData(fl.countryOfResidence,"CA");
		}
		document.getElementById('ResidenceBar').style.display='block';
	}else{
		document.getElementById('ResidenceBar').style.display='none';
	}
	if(document.getElementById('search_pref_section')){
		if(international){
			if(document.getElementById('calltable-search')) document.getElementById('calltable-search').style.borderBottom='1px solid #999999';
		}else{
			if(document.getElementById('calltable-search')) document.getElementById('calltable-search').style.borderBottom=0;
		}
	}
	countryValue=getCookie("country_pref");
	if (document.getElementById('Promotion Code')!= null){
		if(countryValue == "CA" || countryValue == "US") {
             		document.getElementById('Promotion Code').style.display='block';
             	}else
			document.getElementById('Promotion Code').style.display='none';
    	    //showHidePromotionCode();
	}
	if(document.getElementById('Direct')){
		var aBookingFlowVal=checkBookingFlow();
		document.getElementById('Direct').style.display=(aBookingFlowVal.indexOf("SCHEDULE")!=-1||aBookingFlowVal=="COMPLEX"||aBookingFlowVal=="AGENT_COMPLEX")?'block':'none';
	}
}
function checkFlightSegmentType(origCode,destcode){
	var tempOrigAirport=getAirportFromCode(origCode),tempDestAirport=getAirportFromCode(destcode);
	if(tempOrigAirport==null||tempDestAirport==null) return "";
	var depCountry=tempOrigAirport.country,arrCountry=tempDestAirport.country;
	return checkforIntnl(depCountry,arrCountry);
}
function checkBookingFlow(){
	var hasDomestic=false,hasTransborder=false,hasInternational=false,allFaredriven=true,i,tempFlightType;
	depCity=fl.origin1.value;
	arrCity=fl.destination1.value;
	if(depCity!=""&&arrCity!=""){
		tempFlightType=checkFlightSegmentType(depCity,arrCity);
		if(tempFlightType=="Domestic") hasDomestic=true;
		else if(tempFlightType=="Transborder") hasTransborder=true;
		else if(tempFlightType=="International") hasInternational=true;
		if((tempFlightType=="Domestic"||tempFlightType=="Transborder")&&!checkforFareDriven(depCity,arrCity)) allFaredriven=false;
		if(CARIBBEAN_FLAG) allFaredriven=false;
	}
	//SR97502207
	var listOAL = isOAL(depCity,arrCity);
	if(!( listOAL == "" || listOAL == "AC")){
		return (dpg.PRIVATE_LABEL.value=="AGENT")?"AGENT_SCHEDULE":"SCHEDULE";
	}else{
	if(((hasDomestic||hasTransborder )&&allFaredriven)||CARIBBEAN_FLAG){
		return (dpg.PRIVATE_LABEL.value=="AGENT")?"AGENT_DOMTRANSB":"DOMTRANSB";
	}else if((hasDomestic||hasTransborder)||hasInternational){
		if(fl.searchType[0].checked){
			return (dpg.PRIVATE_LABEL.value=="AGENT")?"AGENT_INTERNATIONAL":"INTERNATIONAL";
		}else{
			return (dpg.PRIVATE_LABEL.value=="AGENT")?"AGENT_SCHEDULE":"SCHEDULE";
			}
		}
	}
	return "";
}
function searchAirports(valueToSearch,fromSubmit){
	var resultAirportsList=purgeDoubleEntries(cityList.findCode(valueToSearch),cityList.findCity(valueToSearch),nbresults);
	resultAirportsList=purgeDoubleEntries(resultAirportsList,cityList.findCity(cleanUpAbreviation(valueToSearch)),nbresults);
	if(resultAirportsList.length<nbresults) resultAirportsList=purgeDoubleEntries(resultAirportsList,cityList.findCountries(valueToSearch),nbresults);
	if(resultAirportsList.length<nbresults) resultAirportsList=purgeDoubleEntries(resultAirportsList,cityList.findStates(valueToSearch),nbresults);
	if(fromSubmit!=null&&fromSubmit==true)
		if(resultAirportsList.length==0&&valueToSearch.length>4) resultAirportsList=cityList.findSoundex(valueToSearch);
	return	resultAirportsList;
}
function getAllAirportsList(){
	var resultAirportsList=cityList.getFullAirportsList();
	return	resultAirportsList;
}
function getCityName(airportCode){
	for(var i=0;i<cityList.cities.length;i++){
		if(cityList.cities[i].code==airportCode.toUpperCase()) return cityList.cities[i].text;
	}
	return "";
}
function getAirportFromCode(airportCode){
	for(var i=0;i<cityList.cities.length;i++){
		if(cityList.cities[i].code==airportCode.toUpperCase())	return cityList.cities[i];
	}
	return null;
}

function assertValidDate(){
	checkNeeded=fl.tripType[0].checked==true;
	if(checkNeeded&&( getDateNumber("Dep")==getDateNumber("Ret") )&&( fl.departTime1.options[fl.departTime1.selectedIndex].value>=fl.departTime2.options[fl.departTime2.selectedIndex].value )){
		departTime=fl.departTime1.options[fl.departTime1.selectedIndex].value;
		for(c=0;c<fl.departTime2.length;c++){
			if(fl.departTime2.options[c].value==departTime){
				fl.departTime2.selectedIndex=c;
				return;
			}
		}
		fl.departTime2.selectedIndex=c-1;
	}
}

function WDSWaitingImage(){
	this.IMG_ID="moveimageID";
	this.DIV_ID="inpageFlightsWaitPage";
	this.pleaseWait=WDSWaitingImage_pleaseWait;
}
var WDSWaitingImage=new WDSWaitingImage();
function WDSWaitingImage_pleaseWait(waitingImg){
	var waitingImageDiv=document.getElementById(WDSWaitingImage.DIV_ID),container=document.getElementById("inpageSearchPage"),wiSrc="/shared/images/common/";
	wiSrc+=waitingImg+".gif";
	if(document.getElementById(WDSWaitingImage.IMG_ID))	document.getElementById(WDSWaitingImage.IMG_ID).src=wiSrc;
	else WDSTrace.dump("WDSWaitingImage_pleaseWait : element id = WDSWaitingImage.IMG_ID NOT FOUND and MANDATORY");
	waitingImageDiv.style.display="block";
	waitingImageDiv.style.visibility="visible";
	container.style.display="none";
	self.scrollTo(0,0);
}
function popSelectionData(optName,value){
	for(var i=0;i<optName.length;i++){
		if(optName.options[i].value==value){
			optName.selectedIndex=i;
			break;
		}
	}
}
function checkforIntnl(depCountry,arrCountry){
	POS="";
	POS_arr="";
	if(depCountry==""||arrCountry=="") return "";
	else if(depCountry=="CA"&&arrCountry=="CA") return "Domestic";
	else if((depCountry=="CA"&&arrCountry=="US")||(depCountry=="US"&&arrCountry=="CA")||(depCountry=="US"&&arrCountry=="US")) return "Transborder";
	else{
		if((depCountry=="CA"&&IsCaribbean(arrCountry))||(IsCaribbean(depCountry)&&arrCountry=="CA")||(IsCaribbean(depCountry)&&IsCaribbean(arrCountry))){
			CARIBBEAN_FLAG=true;
			if(IsCaribbean(depCountry)) POS=depCountry;
			if(IsCaribbean(arrCountry)) POS_arr=arrCountry;
			return "Domestic";
		}else if((depCountry=="CA"&&arrCountry==SP_CARIBBEAN)||(depCountry==SP_CARIBBEAN&&arrCountry=="CA")||(depCountry==SP_CARIBBEAN&&arrCountry==SP_CARIBBEAN)){
			CARIBBEAN_FLAG=true;
			return "Domestic";
		}else{
			for(var i=0;i<COUNTRY_POS.length;i++){
				if(depCountry==COUNTRY_POS[i]){
					POS=depCountry;
					break;
				}
				if(arrCountry==COUNTRY_POS[i]) POS_arr=arrCountry;
			}
			return "International";
		}
	}
}
function checkforFareDriven(origCode,destcode){
	var tempOrigAirport=getAirportFromCode(origCode),tempDestAirport=getAirportFromCode(destcode);
	if(tempOrigAirport==null||tempDestAirport==null) return false;
	var depAirportCountryCity=tempOrigAirport.country,arrAirportCountryCity=tempDestAirport.country,aFlightType=checkforIntnl(depAirportCountryCity,arrAirportCountryCity);
	return (aFlightType=="Domestic"||aFlightType=="Transborder")?tempOrigAirport.flag&&tempDestAirport.flag:true;
}
function execShowWarning(){return document.getElementById("ip-depdate2")&&document.getElementById("ip-depdate1within")&&document.getElementById("ip-depdate2within")&&document.getElementById("ip-passenger")&&document.getElementById("ip-infants")&&document.getElementById("ip-residence");}

function showAndHide(formSubmit,fromFacade){
	var hasDomestic=false, hasTransborder=false, hasInternational=false, allFaredriven=true, i, tempFlightType;
	CARIBBEAN_FLAG=false;
	if (document.getElementById('Promotion Code')!= null){
		 if(fl.org1.value == ""){
	    fl.org1.value = document.FlightSearchNTPRequestForm.origin.value;
			fl.origin1.value=getCityName(fl.org1.value);
		 }
	   if ((fl.dest1.value == "") && (fl.dest1.value == null)){
	    fl.dest1.value = document.FlightSearchNTPRequestForm.destination.value;
		  fl.destination1.value=getCityName(fl.dest1.value);
		 }
	}
	
	if(formSubmit){
		if(!(fl.org1.value == "")){
			if(fl.org1.value.length == 3){
				fl.origin1.value = fl.org1.value;
				fl.org1.value=getCityName(fl.org1.value);
			}else if(fl.org1.value.indexOf(" - ") != -1){
				fl.origin1.value = fl.org1.value.substring(fl.org1.value.indexOf(" - ")+3,fl.org1.value.length);
				fl.org1.value=getCityName(fl.origin1.value);
			}		
		}
		if(!(fl.dest1.value =="")){
			if(fl.dest1.value.length == 3){
				fl.destination1.value=fl.dest1.value;
				fl.dest1.value=getCityName(fl.dest1.value);
			}else if(fl.dest1.value.indexOf(" - ") != -1){
				fl.destination1.value = fl.dest1.value.substring(fl.dest1.value.indexOf(" - ")+3,fl.dest1.value.length);
				fl.dest1.value=getCityName(fl.destination1.value);
			}
		}
	}
	depCity=fl.origin1.value;
	arrCity=fl.destination1.value;
	if(depCity!=""&&arrCity!=""){
		tempFlightType=checkFlightSegmentType(depCity,arrCity);
		if(tempFlightType=="Domestic") hasDomestic=true;
		else if(tempFlightType=="Transborder") hasTransborder=true;
		else if(tempFlightType=="International") hasInternational=true;
		if(!checkforFareDriven(depCity,arrCity)) allFaredriven=false;
		if(CARIBBEAN_FLAG) allFaredriven=true;
	}
	WITHHOLD_SURCHARG=false;
	if(hasTransborder|| hasInternational){
		var tempOrgCity=getAirportFromCode(depCity).country;
		if(tempOrgCity=="US") WITHHOLD_SURCHARG=true;
	}
	checkFlightType(hasDomestic,hasTransborder,hasInternational,allFaredriven);

	if (!fromFacade && formSubmit)
		showWarning();
	
}
function checkEmbeddedTransaction(bookingFlow){
	if(bookingFlow.indexOf("COMPLEX_DOMTRANSB")!=-1) return "FlexPricerComplexItineraryAvailabilityServlet";
	else if(bookingFlow.indexOf("DOMTRANSB")!=-1||bookingFlow.indexOf("INTERNATIONAL")!=-1)	return "FlexPricerAvailabilityServlet";
	else if(bookingFlow.indexOf("SCHEDULE")!=-1) return "AirAvailabilityServlet";
	else return "AirComplexAvailabilityServlet";
}
function setFormFields(){
	var aBookingFlowVal=checkBookingFlow();
	dpg.BOOKING_FLOW.value=aBookingFlowVal;
	if(CARIBBEAN_FLAG) DATE_VALUE_PLANITGO="5";
	if(aBookingFlowVal.indexOf("DOMTRANSB")!=-1){
		if(fl.classType.selectedIndex<=1){
			dpg.COMMERCIAL_FARE_FAMILY_1.value="NORAMECO";
			dpg.COMMERCIAL_FARE_FAMILY_2.value="EXCLUSIVE";
		}else{
			dpg.COMMERCIAL_FARE_FAMILY_1.value="EXCLUSIVE";
			dpg.COMMERCIAL_FARE_FAMILY_2.value="";
		}
		if(CARIBBEAN_FLAG){
			var triptype="";
			if(fl.tripType[0].checked) triptype=fl.tripType[0].value;
			else if(fl.tripType[1].checked)	triptype=fl.tripType[1].value;
			if(triptype=="O"){
				dpg.COMMERCIAL_FARE_FAMILY_1.value="YOUNGFUNUS";
				dpg.COMMERCIAL_FARE_FAMILY_2.value="EXCLUSIVE";
			}else if(triptype=="R"){
				dpg.COMMERCIAL_FARE_FAMILY_1.value="CFA7M5SY";
				dpg.COMMERCIAL_FARE_FAMILY_2.value="YOUNGFUNUS";
				dpg.COMMERCIAL_FARE_FAMILY_3.value="EXCLUSIVE";
			}
		}
		dpg.PRICING_TYPE.value="C";
		dpg.DISPLAY_TYPE.value="2";
		dpg.CORPORATE_NUMBER_1.value="URIGET";
		dpg.CORPORATE_NUMBER_2.value="BHVQLN";
		dpg.TYPE_OF_CORPORATE_FARE.value="2";
		dpg.DATE_RANGE_QUALIFIER_1.value="C";
		dpg.DATE_RANGE_VALUE_1.value=DATE_VALUE_PLANITGO;
		if(fl.tripType[0].checked){
			dpg.DATE_RANGE_QUALIFIER_2.value="C";
			dpg.DATE_RANGE_VALUE_2.value=DATE_VALUE_PLANITGO;
		}
	}else if(aBookingFlowVal.indexOf("INTERNATIONAL")!=-1){
		dpg.COMMERCIAL_FARE_FAMILY_1.value="WORLTRAVEL";
		dpg.PRICING_TYPE.value="I";
		if(!fl.Flexible.checked){
			dpg.DATE_RANGE_QUALIFIER_1.value="C";
			dpg.DATE_RANGE_VALUE_1.value="0";
			dpg.DATE_RANGE_VALUE_2.value="0";
			if(fl.tripType[0].checked){
				dpg.DISPLAY_TYPE.value="1";
				dpg.DATE_RANGE_QUALIFIER_2.value="C";
			}else dpg.DISPLAY_TYPE.value="2";
		}else if(fl.tripType[1].checked){
			dpg.DISPLAY_TYPE.value="2";
			dpg.DATE_RANGE_QUALIFIER_1.value="C";
			dpg.DATE_RANGE_VALUE_1.value="5";
			dpg.DATE_RANGE_VALUE_2.value="5";
		}else{
			dpg.DISPLAY_TYPE.value="1";
			dpg.DATE_RANGE_QUALIFIER_1.value="C";
			dpg.DATE_RANGE_VALUE_1.value="3";
			dpg.DATE_RANGE_QUALIFIER_2.value="C";
			dpg.DATE_RANGE_VALUE_2.value="3";
		}
	}
	setFareFamily();
	var country;
	if(dpg.PRIVATE_LABEL.value!="AGENT"){
		var signOnCookie=getCookie("AC-Signon-Cookie"),sessionCookie=getCookie("AC-Session-Cookie");
		if(signOnCookie&&sessionCookie){
			var signOnCookieValue=signOnCookie.split('^'),sessionCookieValue=sessionCookie.split('^');
			dpg.USERID.value=signOnCookieValue[0];
			dpg.TITLE.value=signOnCookieValue[1];
			dpg.LNAME.value=signOnCookieValue[4];
			dpg.MNAME.value=signOnCookieValue[3];
			dpg.FNAME.value=signOnCookieValue[2];
			dpg.FFMILES.value=signOnCookieValue[5];
			country=signOnCookieValue[6];
			dpg.EXTERNAL_ID.value=sessionCookieValue[0];
		}else{
			dpg.USERID.value="GUEST";
			dpg.EXTERNAL_ID.value="GUEST";
			if(document.getElementById("ResidenceBar").style.display!='none') country=fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value;
		}
	}else country=dpg.AGENCY_ADDRESS_COUNTRY.value;
	if(fl.tripType[0].checked) dpg.TRIP_TYPE.value=fl.tripType[0].value;
	else if(fl.tripType[1].checked)	dpg.TRIP_TYPE.value=fl.tripType[1].value;
	dpg.B_LOCATION_1.value=fl.origin1.value;
	dpg.E_LOCATION_1.value=fl.destination1.value;
	if(aBookingFlowVal=="DOMTRANSB"||aBookingFlowVal=="AGENT_DOMTRANSB"||aBookingFlowVal.indexOf("INTERNATIONAL")!=-1){
		if(fl.tripType[0].checked){
			dpg.B_LOCATION_2.value=dpg.E_LOCATION_1.value;
			dpg.E_LOCATION_2.value=dpg.B_LOCATION_1.value;
		}
	}
	var selectedTimeOption, submitfield;
	for(i=1;i<=MAX_DEPARTURES;i++){
		selectedTimeOption="0000"
		if(!dpg.PRIVATE_LABEL.value=="AGENT"){
			if(i==2&&fl.tripType[1]&&fl.tripType[1].checked){
				eval("document.flightsPlanitgo.B_DATE_"+i+".value = getDateNumber(1)+document.flights.departTime1.options[document.flights.departTime1.selectedIndex].value;");
				selectedTimeOption=eval("document.flights.departTime1.options[document.flights.departTime1.selectedIndex].value");
			}else{
				eval("document.flightsPlanitgo.B_DATE_"+i+".value = getDateNumber("+i+")+document.flights.departTime"+i+".options[document.flights.departTime"+i+".selectedIndex].value;");
				selectedTimeOption=eval("document.flights.departTime"+i+".options[document.flights.departTime"+i+".selectedIndex].value");
			}
		}else{
			if(i==2&&fl.tripType[1]&&fl.tripType[1].checked){
				eval("document.flightsPlanitgo.B_DATE_"+i+".value = getDateNumber(1)+selectedTimeOption;");
				selectedTimeOption="0000";
			}else{
				eval("document.flightsPlanitgo.B_DATE_"+i+".value = getDateNumber("+i+")+selectedTimeOption;");
				selectedTimeOption="0000";
			}
		}
		(selectedTimeOption=="0000")?eval("document.flightsPlanitgo.B_ANY_TIME_"+i+".value = \"TRUE\";"):eval("document.flightsPlanitgo.B_ANY_TIME_"+i+".value = \"FALSE\";");
	}
	totadults=Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value);
	totpassengers=Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)+Number(fl.numberOfChildren.options[fl.numberOfChildren.selectedIndex].value);
	adult="ADT";
	child="CHD";
	for(i=1;i<=totadults;i++) eval('document.flightsPlanitgo.TRAVELLER_TYPE_'+i+'.value = adult;');
	for(j=i;j<=totpassengers;j++) eval('document.flightsPlanitgo.TRAVELLER_TYPE_'+j+'.value = child;');
	for(k=j;k<=9;k++) eval('document.flightsPlanitgo.TRAVELLER_TYPE_'+k+'.value = "";');
	if(document.getElementById("Infant").style.display!='none'){
		totinfants=Number(fl.numberOfInfants.options[fl.numberOfInfants.selectedIndex].value);
		for(i=1; i<=totinfants; i++) eval('document.flightsPlanitgo.HAS_INFANT_'+i+'.value = "TRUE";');
		for(j=i; j<=totpassengers; j++) eval('document.flightsPlanitgo.HAS_INFANT_'+j+'.value = "FALSE";');
	}else{
		for(i=1; i<=9; i++) eval('document.flightsPlanitgo.HAS_INFANT_'+i+'.value = "";');
	}
	var soSiteVal="", soTicketVal="";
	if((origAirport.country=="US"||destAirport.country=="US")&&(origAirport.country=="CU"||destAirport.country=="CU")){
		if(country=="CA"||country=="US") soSiteVal="YWG";
	}
	else {
	        if (country == "CA"){soSiteVal = "YOW";}
	        else if (country == "US") { soSiteVal = "WAS";}
        }
	if(country==COUNTRY_POS.toString().match(country)){
		for(i=0;i<COUNTRY_POS.length;i++){
			if(country==COUNTRY_POS[i]){
				soSiteVal=ETVparameters[i][2]
				soTicketVal=ETVparameters[i][3]
			}
		}
	}else if(IsCaribbean(country)){
		soSiteVal="TPA";
		soTicketVal=(country=="BB")?"BGI":"NAS";
	}
	if(soTicketVal=="") soTicketVal=soSiteVal;
	if(dpg.action.indexOf("jsessionid")!=-1&&soSiteVal==dpg.SO_SITE_POINT_OF_SALE.value){
		var controllerIndex=dpg.action.lastIndexOf("OverrideServlet");
		dpg.action=dpg.action.substr(0,controllerIndex)+checkEmbeddedTransaction(aBookingFlowVal)+dpg.action.substr(controllerIndex+15);
		dpg.SO_SITE_POINT_OF_SALE.value="";
		dpg.SO_SITE_POINT_OF_TICKETING.value="";
	}else{
		dpg.EMBEDDED_TRANSACTION.value=checkEmbeddedTransaction(aBookingFlowVal);
		dpg.SO_SITE_POINT_OF_SALE.value=soSiteVal;
		dpg.SO_SITE_POINT_OF_TICKETING.value=soTicketVal;
	}
	if(!(dpg.PRIVATE_LABEL.value=="AGENT")&&typeof(dpg.SO_SITE_EDITION)!='undefined'){
		var ACsignOnCookie=getCookie("AC-Signon-Cookie");
		if(ACsignOnCookie){
			var ACsignOnCookieValue=ACsignOnCookie.split('^');
			dpg.SO_SITE_EDITION.value=(ACsignOnCookieValue[6]=='CA'||ACsignOnCookieValue[6]=='US')?ACsignOnCookieValue[6]:"";
		}else{
			dpg.SO_SITE_EDITION.value=(getCookie('country_pref')=="CA")?"CA":(getCookie('country_pref')=="US")?"US":"";
		}
	}
	else if (typeof(dpg.SO_SITE_EDITION) != 'undefined'){
		if (dpg.AGENCY_ADDRESS_COUNTRY.value == "CA" || dpg.AGENCY_ADDRESS_COUNTRY.value == "US")dpg.SO_SITE_EDITION.value = dpg.AGENCY_ADDRESS_COUNTRY.value;
		else dpg.SO_SITE_EDITION.value = "";
	}
	dpg.DIRECT_NON_STOP.value=(fl.directFlight&&fl.directFlight.checked)?"TRUE":"FALSE";
	if(document.getElementById("Flexible").style.display!='none')
		dpg.SEVEN_DAY_SEARCH.value=(fl.Flexible.checked==true)?"TRUE":"FALSE";
	else dpg.SEVEN_DAY_SEARCH.value="";
	if(aBookingFlowVal.indexOf("INTERNATIONAL")==-1){
		if(fl.classType.selectedIndex==0) dpg.CABIN.value="R";
		else if(fl.classType.selectedIndex==1) dpg.CABIN.value="E";
		else if(fl.classType.selectedIndex==2) dpg.CABIN.value="N";
		else if(fl.classType.selectedIndex==3) dpg.CABIN.value="B";
	}
	if(Language=="french") dpg.LANGUAGE.value="FR";
	else if(Language=="de") dpg.LANGUAGE.value="DE";
	else if(Language=="it") dpg.LANGUAGE.value="IT";
	else dpg.LANGUAGE.value="US";
	temp_cor="";
	if(document.getElementById("ResidenceBar").style.display!='none')
		temp_cor=fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value;
	thisCountry=getCookie("country_pref");
	if(temp_cor!=""&&temp_cor!="O"){
		if(temp_cor==thisCountry){
		}else if((temp_cor=="CA"||temp_cor=="US")&&(thisCountry=="CA"||thisCountry=="US")){
		}else if(IsCaribbean(temp_cor)){
		}
		else{
			if(temp_cor=="CA"||thisCountry==COUNTRY_POS.toString().match(thisCountry)) writeCookie('new_lang_pref','english');
			else if(temp_cor=="US") writeCookie('new_lang_pref','us');
			else{
				lang="";
				for(i=0;i<countryCookieArray.length;i++){
					if(temp_cor==countryCookieArray[i][0]){
						lang=countryCookieArray[i][1];
						break;
					}
				}
				(lang==""||lang=="en")?writeCookie('new_lang_pref','english'):writeCookie('new_lang_pref',lang);
			}
			writeCookie('country_pref',temp_cor);
			if(checkLangCookie("new_lang_pref")=="english"||checkLangCookie("new_lang_pref")=="us") dpg.LANGUAGE.value="US";
			if(!(temp_cor=="FR"||temp_cor=="CA"||temp_cor=="US")) dpg.LANGUAGE.value="US";
			setCountry_path();
		}
	}
	if(country==COUNTRY_POS.toString().match(country)){
		for(i=0;i<COUNTRY_POS.length;i++){
			if(country==COUNTRY_POS[i]||(country=="O"&&POS==COUNTRY_POS[i])) dpg.MARKET.value=ETVparameters[i][1];
		}
	}else if(IsCaribbean(country)||(country=="O"&&IsCaribbean(POS))) dpg.MARKET.value="SUN";
	else{
		countryVal=getCookie("country_pref");
		dpg.MARKET.value=(countryVal=="US"||checkLangCookie('new_lang_pref')=="us")?"US":"CA";
		for(i=0;i<COUNTRY_POS.length;i++) if(countryVal==COUNTRY_POS[i]) dpg.MARKET.value=ETVparameters[i][1];
	}
	countryVal=getCookie("country_pref");
	dpg.COUNTRY.value=(countryVal=="US"||checkLangCookie('new_lang_pref')=="us")?"US":"CA";
	for(i=0;i<COUNTRY_POS.length;i++){
		if(countryVal==COUNTRY_POS[i]){
			dpg.COUNTRY.value=ETVparameters[i][0];
			if(!(countryVal=="FR"||countryVal=="US"||countryVal=="CA"||countryVal=="DE"||countryVal=="IT"|| countryVal == "CH"))	dpg.LANGUAGE.value="US";
		}
	}
	dpg.SO_SITE_FP_WITHHOLD_SURCHARG.value=(dpg.MARKET.value=="US"&&dpg.SO_SITE_POINT_OF_SALE.value=="WAS"&&WITHHOLD_SURCHARG==true)?"NO":"TRUE";
	if(CARIBBEAN_FLAG) dpg.BOOKING_FLOW.value=(dpg.PRIVATE_LABEL.value=="AGENT")?"AGENT_INTERNATIONAL":"INTERNATIONAL";

	if (document.getElementById('Promotion Code')!= null){
		if (fl.promotionCode.value!= null && fl.promotionCode.value!=""){
			dpg.AUTHORIZATION_ID.value = fl.promotionCode.value;
			if (fl.IATA_AGENCY_PNR.value!= null && fl.IATA_AGENCY_PNR.value!="")dpg.TRAVEL_AGENT_PNR.value = fl.IATA_AGENCY_PNR.value;
			if (fl.AGENCY_ID.value!= null && fl.AGENCY_ID.value!="")dpg.IATA_AGENT_ID_NUMBER.value = fl.AGENCY_ID.value;
			if (fl.AGENT_LASTNAME.value!= null && fl.AGENT_LASTNAME.value!="")dpg.IATA_AGENT_LAST_NAME.value = fl.AGENT_LASTNAME.value;
			if (fl.AGENT_FIRSTNAME.value!= null && fl.AGENT_FIRSTNAME.value!="")dpg.IATA_AGENT_FIRST_NAME.value = fl.AGENT_FIRSTNAME.value;
			}
	}
	
	//SR97502207
	var listOAL = isOAL(depCity,arrCity);
	if( listOAL!= ""){
		document.flightsPlanitgo.SO_SITE_REST_AIRLINES_LST.value = listOAL;
	}
}
function init(){
	loaded=true;
	fl.tripType[0].checked=true;
	fl.org1.value="";
	fl.dest1.value="";
	fl.origin1.value="";
	fl.destination1.value="";
	fl.departTime1.selectedIndex=0;
	fl.departTime2.selectedIndex=0;
	fl.numberOfAdults.selectedIndex=0;
	fl.numberOfChildren.selectedIndex=0;
	fl.numberOfInfants.selectedIndex=0;
	countryVal=getCookie('country_pref');
	(countryVal=="CA"||countryVal=="US"||countryVal==COUNTRY_POS.toString().match(countryVal))?popSelectionData(fl.countryOfResidence,countryVal):popSelectionData(fl.countryOfResidence,"CA");
	document.getElementById('Class').style.display='none';
	if(fl.searchType[0]) fl.searchType[0].checked=true;
	if(countryCookieValue == "IL")document.flights.Flexible.checked = true;
}
function initFlightSearch(processFacade){
var objErr4;
try{
	//initNewCalendar();
	init();
    var countrycookie=getCookie("country_pref");
	(countrycookie==COUNTRY_POS.toString().match(countrycookie))?checkFlightType(false,false,true,true):checkFlightType(false,false,false,true);
	}catch(objErr4) { alert("error in 4");}
	var cityCookie=getCookie("cityCookie"), displayedCity="",populateFlag=false,isReqFromOffers=false;
	if(location.pathname.indexOf("offers")>-1) isReqFromOffers=true;
	if((!isReqFromOffers)&&(processFacade!="block"))
	(dpg.PRIVATE_LABEL.value=="AGENT")?populateFlag=getFlightSearchCookie("ADO"):populateFlag=getFlightSearchCookie("ACO");
	if(populateFlag==false&&cityCookie!==null){
		if(!(dpg.PRIVATE_LABEL.value=="AGENT")) {
		if(cityCookie.length==3){
				displayedCity=getCityName(cityCookie);
				fl.origin1.value=cityCookie;
			}
			fl.org1.value=(displayedCity!="")?displayedCity:cityCookie;
		}
		//if(dpg.PRIVATE_LABEL.value=="AGENT") fl.org1.value="";
	}
	
	var parameters= new Array(); 
	var auxParametersList =(document.location.search.split("?"));
	if (auxParametersList[1] != null){
		var attributes= auxParametersList[1].split("&") 
		for (var i=0; i< attributes.length; i++){
			var text=attributes[i].split("=");
			parameters[text[0]]=text[1];
		}
	}
		
	wstriptype = parameters['triptype'];
	wsfrom = parameters['from'];
	wsorign = parameters['dept'];
	wsorign1 = parameters['origin'];

	wsdest = parameters['arrive'];
	wsdest1 = parameters['dest'];

	wsdepday = parameters['deptdateday'];
	wsdepmonth = parameters['deptdatemonth'];
	wsdepyear = parameters['deptdateyear'];
	wsarrday = parameters['arrivedateday'];
	wsarrmonth = parameters['arrivedatemonth'];
	wsarryear = parameters['arrivedateyear'];
	wsnbadult = eval(parameters['adult']);
	wsnbchild = eval(parameters['child']);
	
    if(typeof(wsorign)!="undefined") document.getElementById("org1").value = wsorign
    if(typeof(wsdest)!="undefined")  document.getElementById("dest1").value = wsdest

    if(typeof(wsfrom)!="undefined") document.getElementById("org1").value = getCityName(wsfrom);
    if(typeof(wsdest1)!="undefined")  document.getElementById("dest1").value = getCityName(wsdest1);

    if(typeof(wsorign1)!="undefined") document.getElementById("org1").value = getCityName(wsorign1);

    if(typeof(wsdepday)!="undefined") document.getElementById("date_from").value = wsdepday + "/" + wsdepmonth + "/20" + wsdepyear;
    if(typeof(wsarrday)!="undefined") document.getElementById("date_to").value = wsarrday + "/" + wsarrmonth + "/20" + wsarryear;

    if(typeof(wsnbadult)!="undefined"){wsnbadult = wsnbadult-1; document.getElementById("numberOfAdults").options[wsnbadult].selected = true;}
    if(typeof(wsnbchild)!="undefined") document.getElementById("numberOfChildren").options[wsnbchild].selected = true;

    if(typeof(wstriptype)!="undefined") wstriptype=="round"? document.flights.tripType[0].checked = true:document.flights.tripType[1].checked = true;
}
matchAmbiArray=false;
function getDateNumber(index){
	if(index=="Dep") index=1;
	else if(index=="Ret") index=2;
	var datefield=eval("document.flights.departure"+index),dv=datefield.value;
	return dv.substring(6,10)+dv.substring(3,5)+dv.substring(0,2);
}
function getZeroPadded(input,len){
	retString=new String(input);
	while(retString.length<len) retString="0"+retString;
	return retString;
}
function setCookie(cookie_name,cookie_value,cookie_life,cookie_path){
	var today=getGMTServerDate(),expiry=new Date(today.getTime()+cookie_life*24*60*60*1000);
	if(cookie_value!=null&&cookie_value!=""){
		var cookie_string=cookie_name+"="+escape(cookie_value);
		if(cookie_life) cookie_string+="; expires="+expiry.toGMTString();
		if(cookie_path) cookie_string+="; path="+cookie_path;
		document.cookie=cookie_string;
	}
}
function getCookie(name){
	var index=document.cookie.indexOf(name+"=")
	if(index==-1) return null;
	index=document.cookie.indexOf("=",index)+1;
	var end_string=document.cookie.indexOf(";",index);
	if(end_string==-1) end_string=document.cookie.length;
	return unescape(document.cookie.substring(index,end_string));
}
function cookieEnable(){
	var testout="",cookie_enable=false;
	setCookie('cookietest','yes','1','/');
	testout=getCookie('cookietest');
	if(testout!=null) cookie_enable=true;
	return cookie_enable;
}
function classType_onChange(){
	if(fl.searchType&&document.getElementById('Shop').style.display!='none') searchType_onChange();
}
function searchType_onChange(){
	var searchTyp=fl.searchType[0].value;
	if(fl.searchType[1].checked) searchTyp=fl.searchType[1].value;
  var origApCode=document.getElementById('origin1').value, destApCode=document.getElementById('destination1').value;
	var aFlightSegmentType = checkFlightSegmentType(origApCode, destApCode), fareDriven=checkforFareDriven(origApCode, destApCode);
	if(searchTyp=="F"){
		fl.searchType[0].checked=true;
		document.getElementById('Flexible').style.display='block';
		if(aFlightSegmentType=="International"||!fareDriven){
			document.getElementById('Class').style.display='none';
			document.getElementById('ClassText').style.display='none';
		}else{
			document.getElementById('Class').style.display='block';
			document.getElementById('ClassText').style.display='block';
		}
		if(document.getElementById('Direct')) document.getElementById('Direct').style.display='none';
	}else if(searchTyp=="S"){
		fl.searchType[1].checked=true;
		document.getElementById('Flexible').style.display='none';

		document.getElementById('Class').style.display='block';
		document.getElementById('ClassText').style.display='block';
		if(document.getElementById('Direct')) document.getElementById('Direct').style.display='block';
	}else fl.tripType[0].checked=true;
}
function checkforTyrolean(orgCode,destCode){
	var tyroleanFlightSegment=false;
	if(orgCode=="GRZ"||orgCode=="INN"||orgCode=="KLU"||orgCode=="LNZ"||orgCode=="SZG"||destCode=="GRZ"||destCode=="INN"||destCode=="KLU"||destCode=="LNZ"||destCode=="SZG") tyroleanFlightSegment=true;
	if(tyroleanFlightSegment) displayTyroleanPopup();
}
var tyrolean_window=null;
function displayTyroleanPopup(){
	if(tyrolean_window==null){
		if(Language=="french") tyrolean_window=window.open('/shared/includes/fr/common/city/pop_tyrolean.html','Error','scrollbars=yes,width=300,height=200,resizeable=yes');
		else tyrolean_window=window.open('/shared/includes/en/common/city/pop_tyrolean.html','Error','scrollbars=yes,width=300,height=200,resizeable=yes');
	}
}
function doNothing(){}
function _openWindow(dependant,FileName,windowName,width,height){
	wh=window.open(FileName,windowName,'dependant='+(dependant ? 'yes' : 'no')+',resizable=yes'+',width='+width+',height='+height);
	wh.topwin=self;
	wh.focus();
}
mouseDown=new Array();
function setMouseDown(e,target){mouseDown[target.name]=true;}
function clearMouseDown(e,target){mouseDown[target.name]=false;}
function checkMouseDown(e,target){
	if(mouseDown[target.name]){
		mouseDown[target.name]=false;
		return true;
	}else return false;
}
function openWindow(event,target,FileName,windowName,width,height){
	if(!(width&&height)){
		width=800;
		height=600;
	}
	if(checkMouseDown(event,target)) _openWindow(false,FileName,windowName,width,height);
}
function checkTripType(RoundTrip){document.getElementById('ReturnTextbar').style.display=(RoundTrip=="O")?"none":"block";}
function setFlightSearchCookie(site){
	cookieName=(site=="ADO")?"AC-AgentFlightSearch-Cookie":"AC-ConsFlightSearch-Cookie";
	var domain=".aircanada.com",cookiePath="/",TripType="NULL",SearchOptions="NULL",FlightSegment1="NULL",FlightSegment2="NULL";
	var FlightSegment3="NULL",FlightSegment4="NULL",FlightSegment5="NULL",FlightSegment6="NULL",noInfants=0,i=1;
	TripType=(fl.tripType[0].checked)?TripType="R":TripType="O";
	for(i=1;i<=9;i++){
		eval("hasInfant=document.flightsPlanitgo.HAS_INFANT_"+i+".value;");
		if(hasInfant=="TRUE") noInfants=noInfants+1;
	}
	SearchOptions=fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value+"|"+fl.numberOfChildren.options[fl.numberOfChildren.selectedIndex].value+"|"+noInfants;
	SearchOptions=(fl.countryOfResidence)?SearchOptions+"|"+fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value:SearchOptions+"|"+"NULL";
	SearchOptions=SearchOptions+"|"+fl.classType.options[fl.classType.selectedIndex].value;
	SearchOptions=(dpg.SEVEN_DAY_SEARCH.value=="TRUE")?SearchOptions+"|"+"true":SearchOptions=SearchOptions+"|"+"false";
	SearchOptions=(fl.searchType&&fl.searchType[1].checked)?SearchOptions+"|"+"S":SearchOptions+"|"+"F";
	SearchOptions=(dpg.DIRECT_NON_STOP.value=="TRUE")?SearchOptions+"|"+"true":SearchOptions+"|"+"false";
	if(TripType=="O") FlightSegment1=fl.origin1.value+"|"+fl.destination1.value+"|"+dpg.B_DATE_1.value+"|"+"NULL";
	else FlightSegment1=fl.origin1.value+"|"+fl.destination1.value+"|"+dpg.B_DATE_1.value+"|"+dpg.B_DATE_2.value;
	var cookieValue=TripType+"^"+SearchOptions+"^"+FlightSegment1+"^"+FlightSegment2+"^"+FlightSegment3+"^"+FlightSegment4+"^"+FlightSegment5+"^"+FlightSegment6;
	document.cookie=cookieName+"="+cookieValue+"; path="+cookiePath+"; domain="+domain;
}
function getFlightSearchCookie(site){
	cookieName=(site=="ADO")?"AC-AgentFlightSearch-Cookie":"AC-ConsFlightSearch-Cookie";
	populateCookie=getCookie(cookieName);
	var TripType="",SearchOptions="",FlightSegment1="",FlightSegment2="",FlightSegment3="",FlightSegment4="",FlightSegment5="",FlightSegment6="";
	if(populateCookie){
		cookieValue=populateCookie.split('^');
		TripType=cookieValue[0];
		SearchOptions=cookieValue[1];
		FlightSegment1==cookieValue[2];
		FlightSegment2==cookieValue[3];
		FlightSegment3==cookieValue[4];
		FlightSegment4==cookieValue[5];
		FlightSegment5==cookieValue[6];
		FlightSegment6==cookieValue[7];
		if(TripType=="O"){
			fl.tripType[1].checked=true;
			checkTripType("O");
		}
		searchValues=cookieValue[1].split('|');
		fl.numberOfAdults.selectedIndex=Number(searchValues[0])-1;
		fl.numberOfChildren.selectedIndex=searchValues[1];
		fl.numberOfInfants.selectedIndex=searchValues[2];
		flightSegment1Value=cookieValue[2].split('|');
		var OneWayTrip=((fl.tripType[1]&&fl.tripType[1].checked)||(location.href.indexOf("oneway=YES")>-1))?true:false;
		if(OneWayTrip){
			if(flightSegment1Value[0]!=null&&flightSegment1Value[0]!="NULL"){
				if(flightSegment1Value[0].length==3){
					origCity=getCityName(flightSegment1Value[0]);
					if(origCity!=null||origCity!=""){
						origAirport=getAirportFromCode(flightSegment1Value[0]);
						fl.origin1.value=origAirport.code;
					}
				}
				fl.org1.value=(origCity!="")?origCity:flightSegment1Value[0];
			}
			if(flightSegment1Value[1]!=null&&flightSegment1Value[1]!="NULL"){
				if(flightSegment1Value[1].length==3){
					destCity=getCityName(flightSegment1Value[1]);
					if(destCity!=null||destCity!="") {
						destAirport=getAirportFromCode(flightSegment1Value[1]);
						fl.destination1.value=destAirport.code;
					}
				}
				fl.dest1.value=(destCity!="")?destCity:flightSegment1Value[1];
			}
			if(flightSegment1Value[2]!=null&&flightSegment1Value[2]!="NULL"){
				month=flightSegment1Value[2].substring(4,6);
				day=flightSegment1Value[2].substring(6,8);
				val=months[Number(month-1)][1]+flightSegment1Value[2].substring(0,4);
				timeval=flightSegment1Value[2].substring(8,12);
				popSelectionData(fl.departTime1,timeval);
				if(OneWayTrip) popSelectionData(fl.departTime2,timeval);
			}
		}else{
			if(flightSegment1Value[0]!=null&&flightSegment1Value[0]!="NULL"){
				if(flightSegment1Value[0].length==3){
					origCity=getCityName(flightSegment1Value[0]);
					if(origCity!=null||origCity!=""){
						origAirport=getAirportFromCode(flightSegment1Value[0]);
						fl.origin1.value=origAirport.code;
					}
				}
				fl.org1.value=(origCity!="")?origCity:flightSegment1Value[0];
			}
			if(flightSegment1Value[1]!=null&&flightSegment1Value[1]!="NULL"){
				if(flightSegment1Value[1].length==3){
					destCity=getCityName(flightSegment1Value[1]);
					if(destCity!=null||destCity!=""){
						destAirport=getAirportFromCode(flightSegment1Value[1]);
						fl.destination1.value=destAirport.code;
					}
				}
				fl.dest1.value=(destCity!="")?destCity:flightSegment1Value[1];
			}
			if(flightSegment1Value[2]!=null&&flightSegment1Value[2]!="NULL"){
				month=flightSegment1Value[2].substring(4,6);
				day=flightSegment1Value[2].substring(6,8);
				val=months[Number(month-1)][1]+flightSegment1Value[2].substring(0,4);
				setDateField(flightSegment1Value[2],fl.date_from);
				timeval=flightSegment1Value[2].substring(8,12);
				popSelectionData(fl.departTime1,timeval);
			}
			if((flightSegment1Value[3]!=null)&&(flightSegment1Value[3]!="NULL")){
				month=flightSegment1Value[3].substring(4,6);
				day=flightSegment1Value[3].substring(6,8);
				val=months[Number(month-1)][1]+flightSegment1Value[3].substring(0,4);
				setDateField(flightSegment1Value[3],fl.date_to);
				timeval=flightSegment1Value[3].substring(8,12);
				popSelectionData(fl.departTime2,timeval);
			}else popSelectionData(fl.departTime2,timeval);
		}
		var i=2,lastSegment=1;
		i=lastSegment+1;
		for(i=lastSegment+1; i<=MAX_CITY_PAIRS; i++) eval("popSelectionData(document.flights.departTime"+i+",timeval);");
		popSelectionData(fl.countryOfResidence,searchValues[3]);
		popSelectionData(fl.classType,searchValues[4]);
		if(searchValues[5]=="true")	fl.Flexible.checked=true;
		(searchValues[6]=="S")?fl.searchType[1].checked=true:fl.searchType[0].checked=true;
		if(searchValues[7]=="true") fl.directFlight.checked=true;
		showAndHide();
		return true;
	}else return false;
}
function IsCaribbean(checkCountry){
	for(var i=0;i<CARIBBEAN.length;i++){
		if(checkCountry==CARIBBEAN[i]){
			return true;
			break;
		}
	}
	return false;
}
function setDateField(v,f){f.value=v.substring(6,8)+'/'+v.substring(4,6)+'/'+v.substring(0,4);}
function setFareFamily(){
	var FARE_FLAG="",depCity=fl.origin1.value,arrCity=fl.destination1.value,depCountry=origAirport.country,arrCountry=destAirport.country;
	for(var i=0;i<FAREFAMILY.length;i++){
		for(var j=1;j<FAREFAMILY[i].length;j++){
			if(depCity==FAREFAMILY[i][j]&&arrCountry=="CA"||arrCity==FAREFAMILY[i][j]&&depCountry=="CA"){
				FARE_FLAG=FAREFAMILY[i][0];
				break;
			}
		}
	}
	//if(FARE_FLAG=="GB"||FARE_FLAG=="IL"||FARE_FLAG=="IT"||FARE_FLAG=="FR"||FARE_FLAG=="DK"||FARE_FLAG=="SE"||FARE_FLAG=="IE"||FARE_FLAG=="NO"||FARE_FLAG=="CH"|| FARE_FLAG=="NL" ){
	// comment above to remove switzerland option
	if(FARE_FLAG=="GB"||FARE_FLAG=="IL"||FARE_FLAG=="IT"||FARE_FLAG=="FR"||FARE_FLAG=="DK"||FARE_FLAG=="SE"||FARE_FLAG=="IE"||FARE_FLAG=="NO"|| FARE_FLAG=="NL" ){
		if(fl.tripType[1].checked){
			dpg.COMMERCIAL_FARE_FAMILY_1.value="HIGHWORLD";
			dpg.DISPLAY_TYPE.value = "2";
		}else{
			dpg.COMMERCIAL_FARE_FAMILY_1.value="FLEXIWORLD";
			dpg.DISPLAY_TYPE.value = "3";
		}
		dpg.COMMERCIAL_FARE_FAMILY_2.value="";
		dpg.CORPORATE_NUMBER_1.value="";
		dpg.CORPORATE_NUMBER_2.value="";
		dpg.TYPE_OF_CORPORATE_FARE.value="";
	}
}
function isInvalidCityPair(orig,dest){
	if((orig.length!=3)||(dest.length!=3)) return false;
	var invalidCityArray=new Array("LAXAKL","AKLLAX");
	for(c=0;c<invalidCityArray.length;c++){
		if((orig==invalidCityArray[c].substring(0,3))&&( dest==invalidCityArray[c].substring(3,6))) return true;
	}
	return false;
}
function printForm(f){for(i=0;i<f.elements.length;i++) alert(f.elements[i].name+" = "+f.elements[i].value);}

function displayFacadeError(facadeParam) {
}


function getAirportCode(countryCityName){
	var acode="";
	var iLen = String(countryCityName).length;
	if(iLen == 3)
		acode=countryCityName;
	else if(iLen > 4){
		subcode = String(countryCityName).substring(iLen,iLen-5);
		if(subcode.substring(0,1) == "(" && subcode.substring(5,4) == ")")
			acode = subcode.substring(1,4);
		else if(countryCityName == fl.org1.value)
			acode = fl.origin1.value;
		else if(countryCityName == fl.dest1.value)
			acode	= fl.destination1.value;
	}
	return acode;
}		


// This function will parse the complete country list and get the city codes for select cities
function filterCityList(Domestic, Transborder, Sun, International){
	// we can have combinations - so receiving parameters in order - value Y or N for each
	var CityList1 = "";
	var CityList2 = "";
	var CityList3 = "";
	var cityListA = "";
	//alert(Domestic);
	//alert(Transborder);
	//alert(Sun);
	//alert(International);
	
	if(Domestic == "Y" && Transborder == "N"){
		CityList1 = subCityList("D");
	}else if((Domestic == "Y" && Transborder == "Y") || (Domestic == "N" && Transborder == "Y")){
		CityList1 = subCityList("T");
	}
	if(Sun == "Y")
		CityList2 = subCityList("S");
	if(International == "Y")
		CityList3 = subCityList("I");
	cityListA = CityList1 + CityList2 + CityList3;
	
	iLen = cityListA.length;
	if(iLen != 0)
		if(cityListA.substring(iLen-1,iLen) == ",")
			cityListA = cityListA.substring(0,iLen-1);	
	return cityListA;		
		
}	

function subCityList(listType){
	var ObjErr;
	try{
	var cityListA = "";
	var searchCountry = new Array();
	if (listType == "D"){
		searchCountry[0]= "CA";
	}else if(listType == "T"){
		searchCountry[1]= "CA";
		searchCountry[0]= "US";
	}else if(listType == "I"){
		searchCountry[0]= "CA";
		searchCountry[1]= "US";
		searchCountry[2] = "AG";
		searchCountry[3] = "BS";
		searchCountry[4] = "BM";
		searchCountry[5] = "LC";
		searchCountry[6] = "TT";
		searchCountry[7] = "BB";
	}else if(listType == "S"){
		searchCountry[0] = "AG";
		searchCountry[1] = "BS";
		searchCountry[2] = "BM";
		searchCountry[3] = "LC";
		searchCountry[4] = "TT";
		searchCountry[5] = "BB";
	}else
		searchCountry[0] = "";
	if(listType == "I"){
		for (i=0;i<cityList.cities.length;i++){
			foundflag = false;	
			for(j=0;j<searchCountry.length;j++){
				if (cityList.cities[i].country ==  searchCountry[j])
					foundflag = true;
			}	
			if (foundflag == false)
				cityListA = cityListA + cityList.cities[i].code+",";
		}
	}else{	
		for (i=0;i<cityList.cities.length;i++){
			for(j=0;j<searchCountry.length;j++){
				if(cityList.cities[i].country ==  searchCountry[j]){
					cityListA= cityListA + cityList.cities[i].code+","; 
				}	
			}
		}
	}
	
	return(cityListA);			
	}catch(ObjErr) {alert(ObjErr.message);}
}


// new calendar functions

function initNewCalendar() {
	if(Language == "english")
		lang = "en";
	else if(Language == "french")
		lang= "fr";
	else if (Language =="de" || Language == "it")
		lang = Language;
	initCalendar("date_from", "date_to");
	
	registerSelect("date_from", "showid");
	registerSelect("date_from", "type_id2");
	registerSelect("date_from", "est_id");
	registerSelect("date_to", "showid");
	registerSelect("date_to", "type_id2");
	registerSelect("date_to", "est_id");
	
	setNextFocusField("date_from", "departTime1");
	setNextFocusField("date_to", "departTime2");


	initCalendarNtp();
	
}

function initHomeCalendar(){
	if(Language == "english")
		lang = "en";
	else if(Language == "french")
		lang= "fr";
	else if (Language =="de" || Language == "it")
		lang = Language;
	initCalendar("date_from", "date_to");
		registerSelect("date_from", "showid");
		registerSelect("date_from", "type_id2");
		registerSelect("date_from", "est_id");
		registerSelect("date_to", "showid");
		registerSelect("date_to", "type_id2");
		registerSelect("date_to", "est_id");
}

// Added to support the valid Travel dates from NTP
function initCalendarNtp(){
	if(document.flights && document.flights.TravelStartDate && document.flights.TravelStartDate.value != ""){
		var newTSDate = parseDate(document.flights.TravelStartDate.value);
		if(! isDateBeforeToday(newTSDate))
			today = newTSDate;
	}

	if(document.flights && document.flights.TravelEndDate && document.flights.TravelEndDate.value != "" && document.flights.TravelStartDate.value != "")
		daysLimit = daysElapsed(parseDate(document.flights.TravelEndDate.value),today);
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function daysElapsed(date1,date2) {
    var difference =
        Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
}


function submitFlightSearch(){
	//var objErr;
	//try{
		messagesList.errorMessages=new Array();
		var checkNeeded=fl.tripType[0].checked==true,inpageErrorFlag=false;
		origAirport=fetchAiport("org1","origin1");
		if(origAirport==null){
			processErrors();
			return false;
		}else{
			destAirport=fetchAiport("dest1","destination1");
			if(destAirport==null){
				processErrors();
				return false;
			}
		}
		if(origAirport.code==destAirport.code){
		  messagesList.addMessage("SAMEAIRPORTS",destAirport);
			fl.dest1.focus();
			processErrors();
			return false;
		}
		if(fl.tripType[0].checked==true){
			if(!isDateDefined(fl.date_from)){
				fl.date_from.focus();
				return false;
			}
			if(!isDateDefined(fl.date_to)){
				fl.date_to.focus();
				return false;
			}
		}else{
			if(!isDateDefined(fl.date_from)){
				fl.date_from.focus();
				return false;
			}
		}
		if(!isDatesValidForAirport(origAirport)) inpageErrorFlag=true;
		if(!isDatesValidForAirport(destAirport)) inpageErrorFlag=true;
		if(origAirport.errMsg!=null&&origAirport.errMsg!=""){
			messagesList.addMessage(origAirport.errMsg,origAirport);
			fl.org1.focus();
			inpageErrorFlag=true;
		}
		if(destAirport.errMsg!=null&&destAirport.errMsg!=""){
		  messagesList.addMessage(destAirport.errMsg,destAirport);
			fl.dest1.focus();
			inpageErrorFlag=true;
		}
		if((origAirport.country=="US"||destAirport.country=="US")&&(origAirport.country=="CU"||destAirport.country=="CU")){
			messagesList.addMessage("USACUBA");
			inpageErrorFlag=true;
		}
		if(origAirport.country=="US"&&destAirport.country=="US"){
			messagesList.addMessage("BOTHUSA");
			inpageErrorFlag=true;
		}
		if((Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)+Number(fl.numberOfChildren.options[fl.numberOfChildren.selectedIndex].value))>9){
			messagesList.addMessage("NBPASSENGERS");
			inpageErrorFlag=true;
		}
		if(document.getElementById("Infant").style.display!='none'&&Number(fl.numberOfInfants.options[fl.numberOfInfants.selectedIndex].value)>Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)){
			messagesList.addMessage("NBINFANTS");
			inpageErrorFlag=true;
		}
		if(document.getElementById('promotionCode')!=null){
			if(!validatePromotionCode()){
				messagesList.addMessage("PROMOTIONCODEERROR");
				inpageErrorFlag=true;
			}
			if(!validateInfantHomePromotion()){
				messagesList.addMessage("PROMOTIONCODEINFANTSERROR");
				inpageErrorFlag=true;
			}
		}
		if(inpageErrorFlag){
			processErrors();
			return false;
		}
		// NTP service is initiated to authorize. only if authorized, we send data returned
	// from NTP service to ETV, else display errors
	var countryCookie = getCookie("country_pref");
	if (countryCookie == "CA" || countryCookie == "US"){
    var resCountry = fl.countryOfResidence.options[fl.countryOfResidence.selectedIndex].value;
	   if (resCountry == "CA" || resCountry == "US") { 
	    	if (document.getElementById('Promotion Code')!= null){
	    	   if (checkAgentDetails()) {
		          setNTPFormFields("Flights");
					var objErrNTP;
					try{
			         document.FlightSearchNTPRequestForm.submit();	          
					}catch(objErrNTP){}
		       }
		    }
	   } else {
			if (dpg.NTP_AUTHORIZATION)
	       		dpg.NTP_AUTHORIZATION.value="true";
		    if (fl.promotionCode != null)
    		   	 fl.promotionCode.value = "";
		}
		   	
	}else{
		if (dpg.NTP_AUTHORIZATION)
	   	   dpg.NTP_AUTHORIZATION.value="true";
	   	if (fl.promotionCode != null)
    		   fl.promotionCode.value = "";
	}
    	if (!(dpg.NTP_AUTHORIZATION) ||  dpg.NTP_AUTHORIZATION.value=="true") {
			if (document.getElementById("bodyPage") && document.getElementById("bodyPage").style.display == 'none')
				document.getElementById("bodyPage").style.display='block';
			checkforTyrolean();
			setFormFields();
			var cookie_Life= 5*365;
			setCookie("cityCookie", fl.origin1.value, cookie_Life, "/")
			if (dpg.PRIVATE_LABEL.value == "AGENT")
				setFlightSearchCookie("ADO");
			else	
				setFlightSearchCookie("ACO");
			var objErr2;
			try{
				dpg.submit();
			}catch(objErr2) {}
			WDSWaitingImage.pleaseWait("anim_waiting-bar");
		} else {
			if (document.getElementById("bodyPage") && document.getElementById("bodyPage").style.display == 'none')
				document.getElementById("bodyPage").style.display='block';
		}
	
}
function displayDate(d)
{
	return formatToTwoDigits(d.getDate()) + "/" + formatToTwoDigits(d.getMonth()+1) + "/" + d.getFullYear();
}

function showWarning() {
  messagesList.errorMessages=new Array();
		var checkNeeded=fl.tripType[0].checked==true,inpageErrorFlag=false;
		origAirport=fetchAiport("org1","origin1");
		if(origAirport==null){
			processErrors();
			return false;
		}else{
			destAirport=fetchAiport("dest1","destination1");
			if(destAirport==null){
				processErrors();
				return false;
			}
		}
		if(origAirport.code==destAirport.code){
		  messagesList.addMessage("SAMEAIRPORTS",destAirport);
			fl.dest1.focus();
			processErrors();
			return false;
		}
		if(fl.tripType[0].checked==true){
			if(getDateNumber(1) > getDateNumber(2)){
				messagesList.addMessage("WRONGDATES");
				fl.date_to.focus();
				processErrors();
				return false;
			}
			else if ( getDateNumber(1) == getDateNumber(2) ) {
				if (!dpg.PRIVATE_LABEL.value == "AGENT"){
					if (fl.departTime1.options[fl.departTime1.selectedIndex].value > dfl.departTime2.options[fl.departTime2.selectedIndex].value) {
						messagesList.addMessage("WRONGDATES");
						fl.departTime2.focus();
						processErrors();
						return false;
					}
				}
			}
							
		}
		if(!isDatesValidForAirport(origAirport)) inpageErrorFlag=true;
		if(!isDatesValidForAirport(destAirport)) inpageErrorFlag=true;
		if(origAirport.errMsg!=null&&origAirport.errMsg!=""){
			messagesList.addMessage(origAirport.errMsg,origAirport);
			fl.org1.focus();
			inpageErrorFlag=true;
		}
		if(destAirport.errMsg!=null&&destAirport.errMsg!=""){
		  messagesList.addMessage(destAirport.errMsg,destAirport);
			fl.dest1.focus();
			inpageErrorFlag=true;
		}
		if((origAirport.country=="US"||destAirport.country=="US")&&(origAirport.country=="CU"||destAirport.country=="CU")){
			messagesList.addMessage("USACUBA");
			inpageErrorFlag=true;
		}
		if(origAirport.country=="US"&&destAirport.country=="US"){
			messagesList.addMessage("BOTHUSA");
			inpageErrorFlag=true;
		}
		if((Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)+Number(fl.numberOfChildren.options[fl.numberOfChildren.selectedIndex].value))>9){
			messagesList.addMessage("NBPASSENGERS");
			inpageErrorFlag=true;
		}
		if(document.getElementById("Infant").style.display!='none'&&Number(fl.numberOfInfants.options[fl.numberOfInfants.selectedIndex].value)>Number(fl.numberOfAdults.options[fl.numberOfAdults.selectedIndex].value)){
			messagesList.addMessage("NBINFANTS");
			inpageErrorFlag=true;
		}
		if(document.getElementById('promotionCode')!=null){
			if(!validatePromotionCode()){
				messagesList.addMessage("PROMOTIONCODEERROR");
				inpageErrorFlag=true;
			}
			if(!validateInfantHomePromotion()){
				messagesList.addMessage("PROMOTIONCODEINFANTSERROR");
				inpageErrorFlag=true;
			}
		}
		if(inpageErrorFlag){
			processErrors();
			return false;
		}
}
function getDateNumber(index)
{
	if (index == "Dep")
		index = 1;
	else if (index == "Ret")
		index = 2;
	//index starts from 1, not 0
	var datefield = eval("document.flights.departure"+index);
	var dv = datefield.value;
	return dv.substring(6,10)+dv.substring(3,5)+dv.substring(0,2);
}
function initAgentHomeCalendar(){

	if(Language == "english")
		lang = "en";
	else if(Language == "french")
		lang= "fr";
	else if (Language =="de" || Language == "it")
		lang = Language;
	initCalendar("date_from", "date_to");
	registerSelect("date_from", "departTime2");
	registerSelect("date_from", "numberOfAdults");
	registerSelect("date_from", "numberOfChildren");
	registerSelect("date_from", "numberOfInfants");
	registerSelect("date_to", "numberOfAdults");
	registerSelect("date_to", "numberOfChildren");
	registerSelect("date_to", "numberOfInfants");
	
	setNextFocusField("date_from", "date_to");
	setNextFocusField("date_to", "numberOfAdults");
	
	if(Language == "french"){
		registerSelect("date_from", "numberOfInfants");
		registerSelect("date_to", "numberOfInfants");
		
	}

	
}

// SR97502207
function isOAL(origCode, destCode){
	var tempOrigAirport=getAirportFromCode(origCode),tempDestAirport=getAirportFromCode(destCode);
	if(tempOrigAirport==null||tempDestAirport==null) return "";
	var depCountry=tempOrigAirport.country,arrCountry=tempDestAirport.country;
	var depAirport=tempOrigAirport.code, arrAirport= tempDestAirport.code;
	
	var foundOAL = false;
	var airlinelist = "";
	if(typeof(listOAL) == "undefined")
		return "AC";
	for (i=0;i<listOAL.length;i++){
		if(listOAL[i][0] == depAirport || listOAL[i][0] == arrAirport){
			if(listOAL[i][1].length == "3"){
				 if(listOAL[i][1] == depAirport || listOAL[i][1] == arrAirport){
					foundOAL = true;
					airlinelist = listOAL[i][2];
					break;
				 }
			}else if(listOAL[i][1].length == "2"){
				if((listOAL[i][0] == depAirport && listOAL[i][1] == arrCountry)||(listOAL[i][0] == arrAirport && listOAL[i][1] == depCountry)){
					foundOAL = true;
					airlinelist = listOAL[i][2];
					break;
				}	
			}else if(listOAL[i][1] == "*"){
				foundOAL = true;
				airlinelist = listOAL[i][2];
				break;
			}
		}
	}
	if (airlinelist == "")
		return "AC"
	else
	return "AC;"+airlinelist;
}


