﻿SearchFrm = createSingleton(SearchFrm = {});
SearchFrm.prototype.init = function(args) {
    this.searchForm = $("searchFormDiv");
    this.advFrmLnk = $("advFrmLnk");    
    this.advFrm = $("advSearchForm");    
    this.sysDate = new Date();
    this.displayDateFormat = "dd-mm-yy";
    this.saveDateFormat = "dd-mm-yy";

    if(this.advFrm) {
        this.statusForm = $("statusFormDiv");
        this.toggleFor = function(frm) {
            if(frm == "flights") {
                this.searchForm.style.display = "block";
                this.statusForm.style.display = "none";
            }
            else {
                this.searchForm.style.display = "none";
                this.statusForm.style.display = "block";
                if(frm == "schedule") {                    
                    this.byRoute.checked = true;
                    this.statusDeptCode.parentNode.style.display = "";
                    this.statusArrvCode.parentNode.style.display = "";
                    this.statusAirline.parentNode.style.display = "none";
                    this.statusFlight.parentNode.style.display = "none";
                }
                else {
                    this.byFlight.checked = true;                    
                    this.statusDeptCode.parentNode.style.display = "none";
                    this.statusArrvCode.parentNode.style.display = "none";
                    this.statusAirline.parentNode.style.display = "";
                    this.statusFlight.parentNode.style.display = "";
                }  
            }
        };
        this.chkStatusLnk = $("chkStatusLnk");
        this.viewScheduleLnk = $("viewScheduleLnk");
        this.quickSearchLnk = $("quickSearchLnk");
        
        this.byRoute = $("byRoute");
        this.byFlight = $("byFlight");
        
        this.statusDeptCode = $("statusDeptCode");
        this.statusArrvCode = $("statusArrvCode");
        this.intlStatusDeptCode = $("intlStatusDeptCode");
        this.statusintlArrvCode = $("statusintlArrvCode");
        
        this.statusAirline = $("statusAirline");
       // this.showAirline = $("showAirline");
        this.statusFlight = $("statusFlight");
        this.statusDeptDate = $("statusDeptDate");
        this.statusBtn = $("statusBtn");
        
        var dt3 = new Date(this.sysDate);
        dt3.setDate(dt3.getDate()-1);
        this.statusDeptDate[0] = new Option(Util.formatDate(dt3, "dd-mmm-yy"), "0");
        dt3.setDate(dt3.getDate()+1);
        this.statusDeptDate[1] = new Option(Util.formatDate(dt3, "dd-mmm-yy"), "1");
        dt3.setDate(dt3.getDate()+1);
        this.statusDeptDate[2] = new Option(Util.formatDate(dt3, "dd-mmm-yy"), "2");
        this.statusDeptDate.selectedIndex = 1;
    }
       
    this.searchType = [$("domesticSearchType"), $("intlSearchType")];
    this.tripType = [$("rtTripType"), $("owTripType")];
    
    this.domDeptFrom = $("domDeptCode");
    this.domArrvTo = $("domArrvCode");
    
    this.intlDeptFrom = $("intlDeptCode");
    this.intlArrvTo = $("intlArrvCode");
        
    this.deptDate = $("deptDate");
    this.deptDate.img = $("deptDateImg");
    this.arrvDate = $("arrvDate");
    this.arrvDate.img = $("arrvDateImg");
    
    this.adults = $("adults");
    this.children = $("children");
    this.infants = $("infants");	        
    this.cabin = $("cabin");
    
    this.currency = $("currency");
    
    this.deptTime = $("deptTime");
    this.arrvTime = $("arrvTime");
    this.domesticAirlines = $("domesticAirlines");
    this.intlAirlines = $("intlAirlines");
    
    this.searchBtn = $("searchBtn");
    
    var settings = Settings.getInstance();
    var cal = Calendar.getInstance({ root: settings.url.root });    
    var search = this;
    
    if(settings.url.mode == "US")    
        this.displayDateFormat = "mm-dd-yy";        
    
    var i, j, html;    
    this.initFields = function(dt) {
        var mode = settings.url.mode;
        if(mode == "US")
        {
            //this.searchType[0].parentNode.style.display = "none";
            //this.searchType[1].parentNode.style.display = "none";
            //this.searchType[1].checked = true;
            this.currency.selectedIndex = 1;
            this.currency.parentNode.style.display = "none";
            //this.intlStatusDeptCode.style.display = "none";
           // this.statusintlArrvCode.style.display = "none";
        }
        else
        {
            //this.searchType[0].parentNode.style.display = "none";
            //this.searchType[1].parentNode.style.display = "none";
            this.searchType[1].checked = true;            
            this.currency.selectedIndex = 0;
        }
            
        this.tripType[0].checked = true;
        
        this.intlDeptFrom.value = "";
        this.intlArrvTo.value = "";
        this.intlDeptFrom.style.display = "none";
        this.intlArrvTo.style.display = "none";
        
        var arr = settings.domesticAirports;
        this.domDeptFrom[0] = new Option("--- Select location ---", "");
        this.domArrvTo[0] = new Option("--- Select location ---", "");
        if(this.advFrm) {
            this.statusDeptCode[0] = new Option("--- Select location ---", "");
            this.statusArrvCode[0] = new Option("--- Select location ---", "");
        }
        for(i=0; i<arr.length; i++) {
            this.domDeptFrom[i+1] = new Option((arr[i].s + " (" + arr[i].v + ")"), arr[i].v);
            this.domArrvTo[i+1] = new Option((arr[i].s + " (" + arr[i].v + ")"), arr[i].v); 
            if(this.advFrm) {
                this.statusDeptCode[i+1] = new Option((arr[i].s + " (" + arr[i].v + ")"), arr[i].v);
                this.statusArrvCode[i+1] = new Option((arr[i].s + " (" + arr[i].v + ")"), arr[i].v); 
            }
        }
        for(i=0; i<settings.maxPax; i++) {
            this.adults[i] = new Option(i+1, i+1);
            this.children[i] = new Option(i, i);
            this.infants[i] = new Option(i, i);
        }
        
        arr = settings.classes;
        for(i=0; i<arr.length; i++) {
            this.cabin[i] = new Option(arr[i].c, arr[i].v);
        }
                    
        if(this.advFrm) {
            arr = settings.timePeriods;
            this.deptTime[0] = new Option("Anytime", "");
            this.arrvTime[0] = new Option("Anytime", "");
            for(i=0; i<arr.length; i++) {
                this.deptTime[i+1] = new Option(arr[i].c, arr[i].v);
                this.arrvTime[i+1] = new Option(arr[i].c, arr[i].v);
            }
            
            var html;
            arr = settings.airlines.domestic;   html = "";
            var j = 1;
            if(this.advFrm) this.statusAirline[0] = new Option("--- Select Airline ---", "");	            	            
            for(i=0; i<arr.length; i++) {
                html += "<div class='chkBox'><input type='checkbox' value='" + arr[i].c + "' name='domAirlinePref' id='" + arr[i].c + "_chkBox' />" + "<label for='" + arr[i].c + "_chkBox'>" + arr[i].n + "</label></div>";
                if(this.advFrm) 
                    this.statusAirline[j++] = new Option(arr[i].n, arr[i].c);          
            }
            this.domesticAirlines.innerHTML = html;
            
            arr = settings.airlines.international;   html = "";	            	            
            for(i=0; i<arr.length; i++) {
                html += "<div class='chkBox'><input type='checkbox' value='" + arr[i].c + "' name='domAirlinePref' id='" + arr[i].c + "_chkBox' />" + "<label for='" + arr[i].c + "_chkBox'>" + arr[i].n + "</label></div>";
                if(this.advFrm) 
                    this.statusAirline[j++] = new Option(arr[i].n, arr[i].c);          
            }
            this.intlAirlines.innerHTML = html;
            this.intlAirlines.style.display = "none";
            
        }    
        var dt = new Date(this.sysDate);
        dt.setDate(dt.getDate()+1);
        this.setDates(dt);
    };
    
    this.setDates = function(dt) {
        this.deptDate.value = Util.formatDate(dt, this.displayDateFormat);        
        this.deptDate.dateStr = Util.formatDate(dt, this.saveDateFormat);
        if(this.advFrm)
        {
            dt.setDate(dt.getDate()+1);
            
            if(this.arrvDate.value.length == 0 || isEmpty(this.arrvDate.dateStr))
            {
                this.arrvDate.value = Util.formatDate(dt, this.displayDateFormat);
                this.arrvDate.dateStr = Util.formatDate(dt, this.saveDateFormat);
            }
                
            var dt2 = Util.parseDate(this.arrvDate.dateStr);	            
            if(Util.compareTimes(dt2, dt, true) <= 1) {                     
                this.arrvDate.value = Util.formatDate(dt, this.displayDateFormat);
                this.arrvDate.dateStr = Util.formatDate(dt, this.saveDateFormat);
            }
        }
    };
    
    var deptArrvFunc, rtOwFunc;
    this.setHandlers = function() {
        deptArrvFunc = function(ev) {
            var intlShow, domShow;
            if(search.searchType[1].checked) {
                domShow = "none";
                intlShow = "";
            }
            else {
                domShow = "";
                intlShow = "none";
            }
            
            search.domDeptFrom.style.display = (settings.url.mode == "US") ?domShow :"";
            search.domArrvTo.style.display = domShow;
            search.intlDeptFrom.style.display = (settings.url.mode == "US") ?"" :"none";//intlShow;
            search.intlArrvTo.style.display = intlShow;
            if(search.advFrm)
                search.intlAirlines.style.display = intlShow;
        };
        deptArrvFunc();
        
        var arrvDate = "";
        rtOwFunc = function(ev) {
            var a = search.arrvDate.parentNode;

            if(search.tripType[1].checked) {
                a.style.display = "none";
            }
            else {
                a.style.display = "";
            }
        };
        
        var deptDateFunc = function(ev) {                        
            cal.date = Util.parseDate(search.deptDate.dateStr);
            if(search.cabin)
                search.cabin.style.display = "none";
            cal.show(function(dt) {
                var dstr = Util.formatDate(dt, "yyyymmdd");                
                var tdt = new Date(this.sysDate);
                tdt.setDate(tdt.getDate() + 1);
                var tstr = Util.formatDate(tdt, "yyyymmdd");

                if(search.searchType[1].checked && tstr > dstr) {                    
                    window.alert("Departure date should be after 1 days from current date");                    
                    search.deptDate.focus();
                }
                else
                    search.setDates(dt);
            }, function() {                 
                if(search.cabin) 
                    search.cabin.style.display = "";                 
            }, search.deptDate);                                   
        };
        var arrvDateFunc = function(ev) {

            cal.date = Util.parseDate(search.arrvDate.dateStr);
            cal.show(function(dt) {
                search.arrvDate.value = Util.formatDate(dt, search.displayDateFormat);
                search.arrvDate.dateStr = Util.formatDate(dt, search.saveDateFormat);
            }, null, search.arrvDate);                                   
        };

        DOM.addEvent(this.deptDate, "focus", deptDateFunc);
        DOM.addEvent(this.deptDate.img, "click", deptDateFunc);
        DOM.addEvent(this.arrvDate, "focus", arrvDateFunc);
        DOM.addEvent(this.arrvDate.img, "click", arrvDateFunc);
        DOM.addEvent(this.searchType[0], "click", deptArrvFunc);
        DOM.addEvent(this.searchType[1], "click", deptArrvFunc);
        DOM.addEvent(this.tripType[0], "click", rtOwFunc);
        DOM.addEvent(this.tripType[1], "click", rtOwFunc);
        
        if(this.advFrm) {
            DOM.addEvent(this.advFrmLnk, "click", function(ev) {
                var s = search.advFrm.style;
                if(s.display == "")
                    s.display = "none";
                else
                    s.display = "";
            });
            DOM.addEvent(this.chkStatusLnk, "click", function(ev) {
                search.toggleFor("status");
                var intlStatusShow, domStatusShow;
            if(search.searchType[1].checked) {
                domStatusShow = "none";
                intlStatusShow = "";
            }
            else {
                domStatusShow = "";
                intlStatusShow = "none";
            }
            
            search.statusDeptCode.style.display = (settings.url.mode == "US") ?domStatusShow :"";
            search.statusArrvCode.style.display = domStatusShow;
            search.intlStatusDeptCode.style.display = (settings.url.mode == "US") ?"" :"none";//intlShow;
            search.statusintlArrvCode.style.display = intlStatusShow;
            });
            DOM.addEvent(this.viewScheduleLnk, "click", function(ev) {
                search.toggleFor("schedule");
                 var intlScheduleShow, domScheduleShow;
            if(search.searchType[1].checked) {
                domScheduleShow = "none";
                intlScheduleShow = "";
            }
            else {
                domScheduleShow = "";
                intlScheduleShow = "none";
            }
            
            search.statusDeptCode.style.display = (settings.url.mode == "US") ?domScheduleShow :"";
            search.statusArrvCode.style.display = domScheduleShow;
            search.intlStatusDeptCode.style.display = (settings.url.mode == "US") ?"" :"none";//intlShow;
            search.statusintlArrvCode.style.display = intlScheduleShow;
            });
            DOM.addEvent(this.byRoute, "click", function(ev) {
                search.toggleFor("schedule");
            });
            DOM.addEvent(this.byFlight, "click", function(ev) {
                search.toggleFor("status");
            });
            DOM.addEvent(this.quickSearchLnk, "click", function(ev) {
                search.toggleFor("flights");
            });
//            DOM.addEvent(this.statusAirline, "change", function(ev) {
//                search.showAirline.value = search.statusAirline.value;
//            });
            if(this.advFrm)
            DOM.addEvent(this.statusBtn, "click", function(ev) {
   
                var validate = true;
                if(search.byRoute.checked) {
                 if(search.searchType[0].checked) {
                    if(search.statusDeptCode.selectedIndex == 0) {
                        validate = false;
                        window.alert("Select departure location");
                        search.statusDeptCode.focus();
                    }
                    else if(search.statusArrvCode.selectedIndex == 0) {
                        validate = false;
                        window.alert("Select arrival location");
                        search.statusArrvCode.focus();
                    }
                    else if(search.statusDeptCode.selectedIndex == search.statusArrvCode.selectedIndex) {
                        validate = false;
                        window.alert("Departure and Arrival location cannot be same");
                        search.statusDeptCode.focus();
                    }
                    }
                    else
                    {
                 if(settings.url.mode == "US" && (search.intlStatusDeptCode.value.length < 3 || isEmpty(search.intlStatusDeptCode.code))) {
                    validate = false;
                    window.alert("Select departure location");
                    search.intlStatusDeptCode.focus();
                }                
                else if(settings.url.mode == "NG" && search.statusDeptCode.selectedIndex == 0) {
                    validate = false;
                    window.alert("Select departure location");
                    search.statusDeptCode.focus();
                }
                else if(search.statusintlArrvCode.value.length < 3 || isEmpty(search.statusintlArrvCode.code)) {
                    validate = false;
                    window.alert("Select arrival location");
                    search.statusintlArrvCode.focus();
                }
                else {
                    var statusDeptCode = (settings.url.mode == "NG") ? (search.statusDeptCode.options[search.statusDeptCode.selectedIndex].value)
                        : search.intlStatusDeptCode.code;
                    if(statusDeptCode == search.statusintlArrvCode.code)
                    {
                        validate = false;
                        window.alert("Departure and Arrival location cannot be same");
                        //search.intlDeptFrom.focus();
                    }
                }
                     }
                }
                else {
                    if(search.statusAirline.value.length < 2 ) {
                        validate = false;
                        window.alert("Enter an airline");
                        search.statusAirline.focus();
                    }
                    else if(search.statusFlight.value.length == 0) {
                        validate = false;
                        window.alert("Enter a flight number");
                        search.statusFlight.focus();
                    }
                }                
                
                if(validate) {
               
                    var listingUrl = settings.url.status;
                    var airlineCode;
                    if(search.byFlight.checked) {
                     if(search.statusAirline.value.indexOf("(")>0)
                     {
                        var mySplitResult = search.statusAirline.value.split("(");
                        airlineCode= mySplitResult[1].replace(")","");
                     }
                     else
                     airlineCode= search.statusAirline.value;
                        var _mode;
                        if(search.searchType[1].checked)
                            _mode= "intl";
                        else
                            _mode= "dom";
                        listingUrl += "StatusDisplay.aspx?" +
                        "airline=" + airlineCode + 
                        "&airlineCode=" + airlineCode + 
                        "&flightNumber=" + search.statusFlight.value + 
                        "&deptDate=" + search.statusDeptDate.value+ 
                        "&Mode=" + _mode; 
                    }
                    else {
                        if(search.searchType[1].checked)
                            _mode= "intl";
                        else
                            _mode= "dom";
                        listingUrl += "TimeTableDisplay.aspx?" + 
                        "deptCode=" + search.statusDeptCode.value + 
                       "&arrvCode=" + ((search.searchType[0].checked) 
                            ? (search.statusArrvCode.options[search.statusArrvCode.selectedIndex].value)
                            : search.statusintlArrvCode.code)+
                        "&deptDate=" + search.statusDeptDate.value+
                         "&Mode=" + _mode; 
                       
                    }
                    
                    window.location.href = listingUrl;
                }
            });
        }
        DOM.addEvent(this.searchBtn, "click", function(ev) {
            var validate = true;
            if(search.searchType[0].checked) {
                if(search.domDeptFrom.selectedIndex == 0) {
                    validate = false;
                    window.alert("Select departure location");
                    search.domDeptFrom.focus();
                }
                else if(search.domArrvTo.selectedIndex == 0) {
                    validate = false;
                    window.alert("Select arrival location");
                    search.domArrvTo.focus();
                }
                else if(search.domDeptFrom.selectedIndex == search.domArrvTo.selectedIndex) {
                    validate = false;
                    window.alert("Departure and Arrival location cannot be same");
                    search.domDeptFrom.focus();
                }
               
            }
            else {
                
                if(settings.url.mode == "US" && (search.intlDeptFrom.value.length < 3 || isEmpty(search.intlDeptFrom.code))) {
                    validate = false;
                    window.alert("Select departure location");
                    search.intlDeptFrom.focus();
                }                
                else if(settings.url.mode == "NG" && search.domDeptFrom.selectedIndex == 0) {
                    validate = false;
                    window.alert("Select departure location");
                    search.domDeptFrom.focus();
                }
                else if(search.intlArrvTo.value.length < 3 || isEmpty(search.intlArrvTo.code)) {
                    validate = false;
                    window.alert("Select arrival location");
                    search.intlArrvTo.focus();
                }
                else {
                    var deptCode = (settings.url.mode == "NG") ? (search.domDeptFrom.options[search.domDeptFrom.selectedIndex].value)
                        : search.intlDeptFrom.code;
                    if(deptCode == search.intlArrvTo.code)
                    {
                        validate = false;
                        window.alert("Departure and Arrival location cannot be same");
                        //search.intlDeptFrom.focus();
                    }
                }
            }
            
            if(validate) {
                
                if((search.adults.selectedIndex+1) < search.infants.selectedIndex) {
                    validate = false;
                    window.alert("No. of infants cannot be greater than adults");
                    search.adults.focus();
                }
                else {
                    var total = (search.adults.selectedIndex+1);
                    total += search.children.selectedIndex + search.infants.selectedIndex;
                    if(total > settings.maxTravellers) {
                        validate = false;
                        window.alert("Total travellers cannot be more than 9");
                    }                                
                }
                
                if(search.tripType[0].checked) {
                    var dArr = search.deptDate.dateStr.split("-");
                    var rArr = search.arrvDate.dateStr.split("-");
                    var dstr = "20" + dArr[2] + dArr[1] + dArr[0];
                    var rstr = "20" + rArr[2] + rArr[1] + rArr[0];                    
                    
                    var dt = new Date(search.sysDate);
                    dt.setDate(dt.getDate() + 1);
                    var tstr = Util.formatDate(dt, "yyyymmdd");
                    
                    if(dstr > rstr) {
                        validate = false;
                        window.alert("Departure date cannot be greater than Return date");
                        search.deptDate.focus();
                    }
                    else if(search.searchType[1].checked && tstr > dstr) {
                        validate = false;
                        window.alert("Departure date should be after 1 days from current date");
                        search.deptDate.focus();
                    }
                }
            }
            
            if(validate) {
                //var listingUrl = ((search.searchType[0].checked) ?"listing.htm?" :"intl_listing.htm?"); ;
                var listingUrl = settings.url.fares + "?";
                listingUrl += "adults=" + search.adults.value + "&children="
                           + search.children.value + "&infants=" + search.infants.value;
                listingUrl += "&trip=" + ((search.tripType[0].checked) ?"RT" :"OW");
                if(settings.url.mode == "US")
                    listingUrl += "&deptCode=" + search.intlDeptFrom.code;
                else
                    listingUrl += "&deptCode=" + (search.domDeptFrom.options[search.domDeptFrom.selectedIndex].value);
                listingUrl += "&arrvCode=" + ((search.searchType[0].checked) 
                            ? (search.domArrvTo.options[search.domArrvTo.selectedIndex].value)
                            : search.intlArrvTo.code);
                
                listingUrl += "&searchType=" + ((search.searchType[0].checked) ?"D" :"I");
                var dArr = search.deptDate.dateStr.split("-");
                var rArr = search.arrvDate.dateStr.split("-");
                listingUrl += "&deptYear=" + "20" + dArr[2] + "&deptMonth=" + dArr[1] + "&deptDay=" + dArr[0];
                listingUrl += "&retYear=" + "20" + rArr[2] + "&retMonth=" + rArr[1] + "&retDay=" + rArr[0];

                listingUrl += "&cabin=" + search.cabin.options[search.cabin.selectedIndex].value;
                
                if(search.advFrm) {                    
                    listingUrl += "&currency=" + search.currency.options[search.currency.selectedIndex].value;
                    
                    listingUrl += "&deptTime=" + search.deptTime.value;
                    listingUrl += "&arrvTime=" + search.arrvTime.value;
                    var arr, pref = new Array();
                    if(search.searchType[0].checked)
                        arr = search.domesticAirlines.getElementsByTagName("input"); 
                    else
                        arr = search.intlAirlines.getElementsByTagName("input");
                    for(var j=0; j<arr.length; j++)
                        if(arr[j].checked)
                            pref.push(arr[j].value);
                    pref = pref.join(",");
                    listingUrl += "&airlinePref=" + pref;
                }
                else {
                    //alert("1...." + search.currency.value);
                    listingUrl += "&currency=" + search.currency.value; 
                    listingUrl += "&deptTime=";
                    listingUrl += "&arrvTime=";      
                    listingUrl += "&airlinePref=";
                }
                window.location.href = listingUrl;
            }
        });
    };
        
    this.initFields(this.sysDate);
    this.setHandlers();
    
    var getIndex = function(cmb, val) {
        for(var i=0; i<cmb.options.length; i++)
            if(cmb[i].value == val)
                return i;
        return 0;
    };
    var getIndex1 = function(cmb, val) {
        for(var i=0; i<cmb.options.length; i++)
            if(cmb[i].text == val)
                return i;
        return 0;
    };
    
    this.prefill = function(s) {
        if(s.searchType == "D")
        {
            this.searchType[0].checked = true;            
            search.domDeptFrom.selectedIndex = getIndex(search.domDeptFrom, s.deptCode);
            search.domArrvTo.selectedIndex = getIndex(search.domArrvTo, s.arrvCode);
        }
        else 
        {
            this.searchType[1].checked = true;
            if(settings.url.mode == "US")            
            {
                search.intlDeptFrom.code = s.deptCode;
                search.intlDeptFrom.value = s.deptName + '(' + s.deptCode + ')';
            }
            else 
                search.domDeptFrom.selectedIndex = getIndex(search.domDeptFrom, s.deptCode);
            
            search.intlArrvTo.code = s.arrvCode;            
            search.intlArrvTo.value = s.arrvName + '(' + s.arrvCode + ')';
        }
        
        search.deptDate.value = Util.formatDate(Util.getDate(s.deptDate), this.displayDateFormat);
        search.deptDate.dateStr = Util.formatDate(Util.getDate(s.deptDate), this.saveDateFormat);
        if(s.trip == "RT")
        {
            search.tripType[0].checked = true;
            search.arrvDate.value = Util.formatDate(Util.getDate(s.arrvDate), this.displayDateFormat);
            search.arrvDate.dateStr = Util.formatDate(Util.getDate(s.arrvDate), this.saveDateFormat);
        }
        else 
        {
            search.tripType[1].checked = true;
            search.arrvDate.value = Util.formatDate(Util.getDate(s.deptDate), this.displayDateFormat);
            search.arrvDate.dateStr = Util.formatDate(Util.getDate(s.deptDate), this.saveDateFormat);
        }
        
        rtOwFunc();
        deptArrvFunc();
        search.currency.value = s.currency;
        search.adults.selectedIndex = getIndex(search.adults, s.adults);
        search.children.selectedIndex = getIndex(search.children, s.children);
        search.infants.selectedIndex = getIndex(search.infants, s.infants);
        search.cabin.selectedIndex = getIndex1(search.cabin, s.cabin);
    };    
};

var _activeControl = null;    
window.onload = function() {
    var frm = SearchFrm.getInstance();
    
    AutoComplete_Create("intlDeptCode", new Array(), 15);
    AutoComplete_Create("intlArrvCode", new Array(), 15);
    if(frm.advFrm)
    {
        AutoComplete_Create("intlStatusDeptCode", new Array(), 15);
        AutoComplete_Create("statusintlArrvCode", new Array(), 15);
        AutoComplete_Create("statusAirline", new Array(), 15); 
        AutoComplete_Cache = {"intlDeptCode":[], "intlArrvCode":[], "intlStatusDeptCode":[], "statusintlArrvCode":[],"statusAirline":[]};    
    }
    else
      AutoComplete_Cache = {"intlDeptCode":[], "intlArrvCode":[]};    
};
    
//    function MakeCallBack(strPage)
//    {
//        MakeCallBack(strPage, 3);
//    }
    function SetControl(id)
    {   
        _activeControl = id;
        // MakeCallBack('AutoSuggest.aspx',3);
        MakeCallBack();
        if(document.getElementById("fc"))
            document.getElementById("fc").style.display = "none";
    }
    function MakeCallBack()
    {   
        var dataArr;
        var val = document.getElementById(_activeControl).value;
    
        //if(val.length >= parseInt(strValLength)  )
        if(val.length ==3)
        {
            if(typeof(AutoComplete_Cache[_activeControl][val.toLowerCase()]) == "undefined")
            {
                var httpObj = AJAX.createHttpReq();
                var settings = Settings.getInstance();
                 httpObj.open("GET", settings.url.root + "AutoSuggest.aspx?mode=" + settings.url.mode + "&prefix=" + val + "&name=" + _activeControl, true);
               // httpObj.open("GET", settings.url.root + "AutoSuggest.aspx?mode=" + settings.url.mode + "&prefix=" + val + "&name=" + _activeControl, true);                
                var ac = _activeControl;
                httpObj.onreadystatechange = function() {
                    if(httpObj.readyState == 4)
                    {
                        if(httpObj.status == 200)
                        {
                            AutoComplete_Cache[ac][val.toLowerCase()] = eval(httpObj.responseText);
                            __AutoComplete[ac]['data'] = eval(httpObj.responseText);
                            if(ac == _activeControl)
                                AutoComplete_UpdateDropdown(ac);
                        }                                        
                    }                
                };
                httpObj.send(null);
            }
            else
                __AutoComplete[_activeControl]['data'] = AutoComplete_Cache[_activeControl][val.toLowerCase()];
        }
        AutoComplete_UpdateDropdown(_activeControl);
    }
    
    function AirLinesSetControl(id,airline)
    {   
        _activeControl = id;
        //MakeCallBack('AirlinesAutoSuggest.aspx',2);
        AirlineMakeCallBack();
        if(document.getElementById("fc"))
            document.getElementById("fc").style.display = "none";
    }
    function AirlineMakeCallBack()
    {
        var dataArr;
        var val = document.getElementById(_activeControl).value;
    
        //if(val.length >= parseInt(strValLength)  )
       
        if(val.length >= 2  )
        {
            if(typeof(AutoComplete_Cache[_activeControl][val.toLowerCase()]) == "undefined")
            {
                var httpObj = AJAX.createHttpReq();
                var settings = Settings.getInstance();
		
                var _url = settings.url.root;
		        if(_url.indexOf("https") > -1)
			        _url = _url.replace('https','http');
		
                httpObj.open("GET", _url + "AirlinesAutoSuggest.aspx?mode=" + settings.url.mode + "&prefix=" + val + "&name=" + _activeControl, true);
                //httpObj.open("GET", settings.url.root + "AirlinesAutoSuggest.aspx?mode=" + settings.url.mode + "&prefix=" + val + "&name=" + _activeControl, true);                
                var ac = _activeControl;
                httpObj.onreadystatechange = function() {
                    if(httpObj.readyState == 4)
                    {
                        if(httpObj.status == 200)
                        {
                            AutoComplete_Cache[ac][val.toLowerCase()] = eval(httpObj.responseText);
                            __AutoComplete[ac]['data'] = eval(httpObj.responseText);
                            if(ac == _activeControl)
                                AutoComplete_UpdateDropdown(ac);
                        }                                        
                    }                
                };
                httpObj.send(null);
            }
            else
                __AutoComplete[_activeControl]['data'] = AutoComplete_Cache[_activeControl][val.toLowerCase()];
        }
        AutoComplete_UpdateDropdown(_activeControl);
    }
    
    