/* common.js: common functions used anywhere on the site */
function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
            node = document;
    if ( tag == null )
            tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
            if ( pattern.test(els[i].className) ) {
                    classElements[j] = els[i];
                    j++;
            }
    }
    return classElements;
} // getElementsByClass

function setDatumInitieel() {
    //jaren gaan veranderen in de selYear in form op pagina:
    var jaar1 = jaar;
    var jaar2 = jaar+1;

    var dates = document.dates;
    var datesT = document.datesT;

    dates.selYear.options[0]=new Option(jaar1);
    dates.selYear.options[1]=new Option(jaar2);

    datesT.selYearT.options[0]=new Option(jaar1);
    datesT.selYearT.options[1]=new Option(jaar2);

    maandheen = currentheendatum.getMonth() ;
    dagheen = currentheendatum.getDate();
    jaarheen = currentheendatum.getFullYear();

    maandterug = currentterugdatum.getMonth() ;
    dagterug = currentterugdatum.getDate();
    jaarterug = currentterugdatum.getFullYear();

    dates.selDay.selectedIndex = dagheen-1;

    dates.selMonth.selectedIndex = maandheen;
    if (jaar1 == jaarheen) {
        dates.selYear.selectedIndex = (0);
    }
    else {
        dates.selYear.selectedIndex = (1);
    }

    datesT.selDayT.selectedIndex = dagterug-1;
    datesT.selMonthT.selectedIndex = maandterug;
    if (jaar1 == jaarterug) {
        datesT.selYearT.selectedIndex = (0);
    }
    else {
        datesT.selYearT.selectedIndex = (1);
    }
}

function showLayer(layerName)
{
    if (document.layers){ //ns4
        if (document.layers[layerName]) {
            document.layers[layerName].visibility = "show";
            document.layers[layerName].left = window.innerWidth/2 -134;
        }

    } else if (document.getElementById){ //ie4, NS6
//        document.getElementById(layerName).style.visibility='visible';
        document.getElementById(layerName).style.display='block';
    }
}
function hideLayer(layerName)
{
    if (document.layers){ //ns4

        document.layers[layerName].visibility = "hide";

    } else if (document.getElementById){ //ie4
//        alert('setting display to none for ' + layerName + ': '+ document.getElementById(layerName));
//        document.getElementById(layerName).style.visibility="hidden";
        document.getElementById(layerName).style.display='none';
    }
}

function toggle(obj) {
    var el = document.getElementById(obj);
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
    //alert('new display value: ' + el.style.display);
}

function switchVisibility(layerName) {
    if (verbose) {showMessage('style.display = ' + document.getElementById(layerName).style.display);}
    if (document.getElementById(layerName).style.display === 'none') {
        showLayer(layerName);
    } else {
        hideLayer(layerName);
    }
}

function loadServletURL() {
    var http = window.XMLHttpRequest ? new XMLHttpRequest()
                                     : new ActiveXObject('Microsoft.XMLHTTP');
    http.onreadystatechange = function() {
        if(http.readyState == 4){
            servletURL = http.responseText;
            //alert('got servlet URL: ' + servletURL);
        }
    }
    http.open("GET", "/scripts/getServletURL.php?" + getRandomString(), true);
    http.send("");
}

function expandFlightDetails(index) {
    document.getElementById("flightDetails"+index).style.display = 'block';
    /*document.getElementById("expandLink"+index).innerHTML =
                    "<a class='blueLinkNoLine' href='#' onclick="
                    + "'collapseFlightDetails(" + index + "); return false;'>"
                    + "</a>";*/
}
function collapseFlightDetails(index) {
    document.getElementById("flightDetails"+index).style.display = 'none';
    /*document.getElementById("expandLink"+index).innerHTML =
                    "<a class='blueLinkNoLine' href='#' onclick="
                    + "'expandFlightDetails(" + index + "); return false;'>"
                    + "vluchtdetails &raquo;</a>";*/
}

function getTimeDifference(time1, time2) {
    var hour1 = parseInt(time1.substring(0,2),10); // parse as decimal number
    var hour2 = parseInt(time2.substring(0,2),10);
    var mins1 = parseInt(time1.substring(3,5),10);
    var mins2 = parseInt(time2.substring(3,5),10);
    var t;

    if (hour1 > hour2) {
        hour2 += 24; // correction for overnight changes
    }
    t = ((hour2 - hour1) * 60) + (mins2 - mins1);
    return Math.floor(t/60) + "h" + ((t % 60 < 10) ? ("0" + t % 60) : (t % 60));
}

function checkHashParams() {
    var hash = window.location.hash;
    if (hash.indexOf("uq") == -1) {
        return; // don't do anything
    }
    postdat = hash;
    sessionID = hash.substring(hash.indexOf("uq=")+3, 24);

    // check if the session exists in the cache
    var now = new Date();
    YAHOO.util.Connect.asyncRequest('GET', '/req/' + sessionID + '.xml?' + now.getTime(),
                   {success:loadSession,
                    failure:repeatSearch});
}

function urlencode(str) {
    var chars = ["à","á","ã","ä","ç","è","é","ê","ë","ì","í","î","ï",
                 "ò","ó","ô","õ","ö","ù","ú","û","ü","ý","ÿ","ø"];
    var trans = ["a","a","a","a","c","e","e","e","e","i","i","i","i",
                 "o","o","o","o","o","u","u","u","u","y","y","o"];
    for (var i=0; i<chars.length; i++) {
        var re = new RegExp(chars[i],"g");
        str = str.replace(re, trans[i]);
    }
    //alert('str 1: ' + str);
    str = escape(str); // replace symbols and spaces
    //alert('str 2: ' + str);
    str = str.replace(/%20/g, '+');
    
    return str;
}

function urldecode(str) {
    str = str.replace(/\+/g, ' ');
    str = unescape(str);
    return str;
}

function setFormInputs() {
    // get index of origin and destination
    var depStart = postdat.indexOf("&autocompheen")+"&autocompheen=".length;
    var retStart = postdat.indexOf("&autocompterug")+"&autocompterug=".length;
    var depEnd = postdat.indexOf("&autocompterug");
    var retEnd = postdat.indexOf("&datumheen");
    // dep and ret dates
    var depDateStart = postdat.indexOf("&datumheen")+"&datumheen=".length;
    var retDateStart = postdat.indexOf("&datumterug")+"&datumterug=".length;
    var depDateEnd = postdat.indexOf("&datumterug");
    var retDateEnd = postdat.indexOf("&retourenkel");
    // trip type & num of adults
    var tripTypeStart =  postdat.indexOf("&retourenkel")+"&retourenkel=".length;
    var tripTypeEnd =    postdat.indexOf("&aantalreiz");
    var numAdultsStart = postdat.indexOf("&aantalreiz")+"&aantalreiz=".length;
    var numAdultsEnd =   postdat.indexOf("&aantalkin");

    if (depStart == -1) {
        trackError("setFormInputs/missing parameter autocompheen");
        window.location.hash = '';
        return;
    }

    var depCity = urldecode(postdat.substring(depStart, depEnd));
    var retCity = urldecode(postdat.substring(retStart, retEnd));
    var depDate = postdat.substring(depDateStart, depDateEnd);
    var retDate = postdat.substring(retDateStart, retDateEnd);
    var tripType = postdat.substring(tripTypeStart, tripTypeEnd);
    numAdults = postdat.substring(numAdultsStart, numAdultsEnd);

    document.f1.adults.value = numAdults;

    // fill in form data
    if (tripType == "Retour") {
        if (document.f2 != null) {
            document.f2.r1[0].checked = "checked";
        }
    } else {
        if (document.f2 != null) {
            document.f2.r1[1].checked = "checked";
        }
        hideReturnBox();
    }

    if (verbose) {
        showMessage('halfway setFormInputs...');
    }
    
    document.getElementById('ysearchinput2').value = depCity;
    document.getElementById('ysearchinput3').value = retCity;
    // 2012/01/09  => Y:0-4, M:5-7, D:8-10
    document.dates.selDay.value = (depDate.substring(8,9) == "0")
                ? depDate.substring(9,10) : depDate.substring(8,10);
    document.dates.selMonth.value = (depDate.substring(5,6) == "0")
                ? depDate.substring(6,7) : depDate.substring(5,7);
    document.dates.selYear.value = depDate.substring(0,4);
    // return date
    document.datesT.selDayT.value = (retDate.substring(8,9) == "0")
                ? retDate.substring(9,10) : retDate.substring(8,10);
    document.datesT.selMonthT.value = (retDate.substring(5,6) == "0")
                ? retDate.substring(6,7) : retDate.substring(5,7);
    var selYear = document.getElementById("selYear");
    var selYearT = document.getElementById("selYearT");
    for (var x = 0;x < selYear.options.length;x++) {
        if (selYear.options[x].text == depDate.substring(0,4)) {
            selYear.selectedIndex = x;
            break;
        }
    }
    for (var y = 0;y < selYearT.options.length;y++) {
        if (selYearT.options[y].text == retDate.substring(0,4)) {
            selYearT.selectedIndex = y;
            break;
        }
    }
    if (verbose) {
        showMessage('setFormInputs done.');
    }
} // setFormInputs

function initMatrixDays() {
    var inDayList = "", outDayList = "";
    var year, month, dd, selected;
    var start = -1, end = 1;
    var curDate, dayName, dayNum, monthName;
    
    outDayLegend = "";
    inDayLegend = "<div id='container-top'><div id='title'>"+matrixTitle+"</div><div id='hider'>"
        + "<a href='' onclick='collapseMatrixContainer(); return false;'>&nbsp;</a></div><div id='inText'>"+inboundText+" &raquo;</div>"
        + "</div><div id='outText'>" + outboundText
        + " <img src='/images/arrows-doubledown.png' alt=''></div>";
    
    // set days for matrix (e.g., monday - friday)
    for (var day=start; day<=end; day++) {
        // calculate out-date based on day offset
        selected = (day == 0) ? " selectedOut" : "";
        curDate = new Date(depdate.getTime() + day*24*3600*1000 + 60*60*1000); // bugfix: extra minute
        dayName = getDayName(curDate.getDay());
        dayNum = curDate.getDate();
        //monthName = getMonthName(curDate.getMonth());
        outDayList += "<div id='row"+(2+day)+"' class='day outday"+selected+"'>" + dayName + ", "
            + dayNum + "-" + (curDate.getMonth()+1) + "</div>";
        // calculate in-date based on day offset
        selected = (day == 0) ? " selectedIn" : "";
        curDate = new Date(retdate.getTime() + day*24*3600*1000 + 60*60*1000); // bugfix: extra minute
        dayName = getDayName(curDate.getDay());
        dayNum = curDate.getDate();
        //monthName = getMonthName(curDate.getMonth());
        inDayList += "<div id='col"+(2+day)+"' class='day inday"+selected+"'>" + dayName + ", "
            + dayNum + "-" + (curDate.getMonth()+1) + "</div>";
    }
    outDayLegend += "<div id='outdays'>" + outDayList + "</div>";
    inDayLegend  += "<div id='indays'>" + inDayList + "</div>";
} // initMatrixDays

function collapseMatrixContainer() {
    document.getElementById('inText').style.display = 'none';
    document.getElementById('outText').style.display = 'none';
    document.getElementById('indays').style.display = 'none';
    document.getElementById('outdays').style.display = 'none';
    document.getElementById('matrix').style.display = 'none';
    document.getElementById('tip').style.display = 'none';
    document.getElementById('hider').innerHTML =
        "<a href='' onclick='expandMatrixContainer(); return false;'>&nbsp;</a></div>";
    document.getElementById('hider').style.height = '25px';
    document.getElementById('container-top').style.height = '22px';
    document.getElementById('hider').style.background = "url('/images/arrows-updown.png') no-repeat 0 -15px";
}
function expandMatrixContainer() {
    document.getElementById('inText').style.display = 'block';
    document.getElementById('outText').style.display = 'block';
    document.getElementById('indays').style.display = 'block';
    document.getElementById('outdays').style.display = 'block';
    document.getElementById('matrix').style.display = 'block';
    document.getElementById('tip').style.display = 'block';
    document.getElementById('hider').innerHTML =
        "<a href='' onclick='collapseMatrixContainer(); return false;'>&nbsp;</a></div>";
    document.getElementById('hider').style.height = '15px';
    document.getElementById('container-top').style.height = '39px';
    document.getElementById('hider').style.background = "url('/images/arrows-updown.png') no-repeat 0 2px";
}

function showMatrixContainer() {
    document.getElementById('matrixContainer').style.display = 'block';
    document.getElementById('matrixContainerBottom').style.display = 'block';
}
function hideMatrixContainer() {
    document.getElementById('matrixContainer').style.display = 'none';
    document.getElementById('matrixContainerBottom').style.display = 'none';
}

function initSession() {
    // display circle-loader
    if (document.getElementById("circle-loader") != null) {
        document.getElementById("circle-loader").style.display = "block";
    }
    // set resultpage variables
    flights = new Array();
//    filters = new Array();
    providersArray = new Array();
    frozen = false;
    currentPage = 1;
    lowestPrice = 999999999;
    matrixIsValid = false;
    sortBy = "prijs";   // sort type
    failures = 0;       // script exceptions
    countryFilters = {'NL':true, 'BE':true, 'DE':true};
    //globalSettingsInitialized = false;
    globalAirline = undefined;
    count = 0;
    setFormInputs();

    var year1, month1, day1, year2, month2, day2;
    year1 = parseInt(reqHeenDatum.substring(0,4));
    year2 = parseInt(reqTerugDatum.substring(0,4));
    month1 = reqHeenDatum.substring(4,6);
    month2 = reqTerugDatum.substring(4,6);
    day1 = reqHeenDatum.substring(6,8);
    day2 = reqTerugDatum.substring(6,8);
    // trim leading zeroes
    month1 = (month1.substring(0,1)=="0") ? month1.substring(1,2) : month1;
    month2 = (month2.substring(0,1)=="0") ? month2.substring(1,2) : month2;
    day1 = (day1.substring(0,1)=="0") ? day1.substring(1,2) : day1;
    day2 = (day2.substring(0,1)=="0") ? day2.substring(1,2) : day2;

    // global vars for requested dates, used by initMatrixDays and buildMatrix
    depdate = new Date(year1, parseInt(month1)-1, parseInt(day1));
    retdate = new Date(year2, parseInt(month2)-1, parseInt(day2));
    //alert("retdate day: " + retdate.getDate());
    initMatrixDays();
} // initSession

var loadSession = function(o) {
    var data = o.responseXML.documentElement.getElementsByTagName('d');
    var d1 = data[0];
    var hdatum = d1.getAttribute('heend');
    var tdatum = d1.getAttribute('terugd');
    reqHeenDatum = hdatum.substring(0,4)+hdatum.substring(5,7)+hdatum.substring(8,10);
    reqTerugDatum = tdatum.substring(0,4)+tdatum.substring(5,7)+tdatum.substring(8,10);
    //alert("reqTerugDatum: " + reqTerugDatum);

    initSession();
    // directly load the JSON file and show the results
    cacheRequest = true;
    allProvidersDone = true;
    matrixIsActive = true;
    getResults();
    //window.setTimeout("alert(getMatrixValidity(flexArr))",2000);
 
    // Tracker: set session ID & track event "reload results"
    _gaq.push(['_setCustomVar', 1, 'sessionID', sessionID, 2]);
    trackPageView('/reloadResults');
    prepareSdbRetrieve();
} // loadSession

function prepareSdbRetrieve() {
    var start1 = postdat.indexOf("&autocompheen") + "&autocompheen=".length;
    var end1 = postdat.indexOf("&autocompterug");
    var depString = postdat.substring(start1,end1);
    var start2 = postdat.indexOf("&autocompterug") + "&autocompterug=".length;
    var end2 = postdat.indexOf("&datumheen");
    var arrString = postdat.substring(start2,end2);
    var depAirport, arrAirport, match;

    if (depString.length == 3) {
        depAirport = depString;
    } else {
        match = depString.match(/.*?\(([^<]+)\)/);
        depAirport = match && match[1];
        if (depAirport == null) {
            depAirport = depString.substring(0,3);
        }
    }
    if (arrString.length == 3) {
        arrAirport = arrString;
    } else {
        match = arrString.match(/.*?\(([^<]+)\)/);
        arrAirport = match && match[1];
        if (arrAirport == null) {
            arrAirport = arrString.substring(0,3);
        }
    }
    //var t = setTimeout("callSdbRetrieve('"+depAirport+"','"+arrAirport+"')", 200);
} // prepareSdbRetrieve

var repeatSearch = function(o) {
    postdat = window.location.hash.substring(1);
    sessionID = getRandomString();

    setFormInputs();

    var reqData = postdat.substring(postdat.indexOf("&autocompheen"));
    // replace invalid uq with new session ID
    postdat = "uq=" + sessionID + reqData;
    formSubmitted = true;
    validate(postdat, sessionID); // resend the post data (req params)
}

function getPrefillValues() {
    if (city.length > 0) {
        document.getElementById('ysearchinput3').value=city;
    }
    if (vertrekst.length > 0) {
        vertrekst = vertrekst.replace(/%20/g, ' ');
        document.getElementById('ysearchinput2').value=vertrekst;
    }
    if (bestemst.length > 0) {
        bestemst = bestemst.replace(/%20/g, ' ');
        document.getElementById('ysearchinput3').value=bestemst;
    }
    if (aantal.length > 0) {
        document.f1.adults.value = aantal;
    }
    if (typeinv.length > 0) {
        if ((typeinv == "Enkel") || (typeinv == "enkel")) {
            document.f2.r1[1].checked = true;
            hideReturnBox();
        }
        if ((typeinv == "Retour") || (typeinv == "retour")) {document.f2.r1[0].checked = true;}
    }
//    if (nonstopinv.length > 0) {
//        if (nonstopinv == "false") {  document.reizigers.nonstop.checked=false; }
//        if (nonstopinv == "true") {  document.reizigers.nonstop.checked=true; }
//    }
    if (heend.length > 0) {
        var selDay = document.getElementById("selDay");
        var selYear = document.getElementById("selYear");
        var selMonth = document.getElementById("selMonth");
        month = heend.substr(4,2);
        day =  heend.substr(6,2);
        year =  heend.substr(0,4);
        selMonth.selectedIndex = month-1;
        selDay.selectedIndex = day-1;
        for (var y = 0;y < selYear.options.length;y++) {
           if (selYear.options[y].text == year) {
                selYear.selectedIndex = y;
                break;
            }
        }
        updateCal("false");
    }
    if (terugd.length > 0) {
        var selDayT = document.getElementById("selDayT");
        var selYearT = document.getElementById("selYearT");
        var selMonthT = document.getElementById("selMonthT");
        month = terugd.substr(4,2);
        day =  terugd.substr(6,2);
        year =  terugd.substr(0,4);
        selMonthT.selectedIndex = month-1;
        selDayT.selectedIndex = day-1;
        for (var y = 0;y < selYearT.options.length;y++) {
           if (selYearT.options[y].text == year) {
                selYearT.selectedIndex = y;
                break;
            }
        }
        updateCalT("false");
    }

    if (autosubmit == "true") {
        formSubmitHandler();
    }
}

function toTimestamp(d){
    var strDate = "";
    if (d.length == 8) {
        strDate = d.substring(0,4)+"/"+d.substring(4,6)+"/"+d.substring(6,8)+" 00:00:00";
    } else if (d.length == 10) {
        strDate = d + " 00:00:00";
    }
    var datum = Date.parse(strDate);
    return datum/1000;
}

function isLowCost(p) {
    switch(p) {
        /*case "BER":return true;break;*/
        case "EZY":return true;break;
        case "TRA":return true;break;
        case "RYR":return true;break;
        case "VLG":return true;break;
        case "WZZ":return true;break;
        default:return false;break;
    }
}

function highlight(col, row) {
    var div;
    for (var i=0; i<5; i++) {
        div = document.getElementById('col'+i);
        if (div != null && i == col) {
            div.style.fontWeight = 'bold'; // highlight this date
            div.style.color = '#666';
        } else if (div != null) {
            div.style.fontWeight = (i==2) ? 'bold' : 'normal'; // reset style
            div.style.color = (i==2) ? '#0A0' : '#666';
        }
    }
    for (var j=0; j<5; j++) {
        div = document.getElementById('row'+j);
        if (div != null && j == row) {
            div.style.fontWeight = 'bold'; // highlight this date
            div.style.color = '#666';
        } else if (div != null) {
            div.style.fontWeight = (j==2) ? 'bold' : 'normal'; // reset style
            div.style.color = (j==2) ? '#0A0' : '#666';
        }
    }
}

function init(homeURL) {
    verbose = false; //(homeURL == 'http://www.chase.nl') ? false : true;
    matrixDebugMode = false; // to test the matrix validation function
    showLowcostMask = false;
    useHashParams = true;
    cacheRequest = false; // default value, can be adjusted by loadSession()
    defaultURL = 'http://46.137.185.229:8080/Webchaser/Search?url=www.chase.nl'
                    + '&sid=';
    hash = window.location.hash;
    complete2 = true;
    complete3 = true;
    resultLayout = false; // initially the search layout is used
    ffClearActive = true; // onclick, clear departure form field => active
    formSubmitted = false;
    matrixIsActive = false;
    allInFares = false;
    labelUndefinedError = false;
    airlineFilterInitVal = true;
    runningProviders = "";// list of running providers, logged to GA on time-out
    frozen = false;
    stringLength = 20;  // used by getRandomString()
    servletURL = '';    // initialized by loadServletURL
    borderStyle = 0;
    veldleeginit = 0;
    popupKey = "";      // set by toggleProvidersBox
    showPopUp = true;
    sortPriceFlag = 1;
    sortAirlineFlag = 0;
    sortTimeFlag = 0;
    sortDurationFlag = 0;
    sortStopsFlag = 0;
    ival1 = null;
    ival2 = null;
    hstad = '';
    tstad = '';
    numAdults = 0;
    noPrice = 99999;
    msg = "";
    loggedErrors = new Array();
    nearbyAirports = new Array();
    checkedAirports = new Array();
    checkedAirports[1] = new Array();
    checkedAirports[2] = new Array();
    numSelected = new Array();
    numSelected[1] = new Array();
    numSelected[2] = new Array();

    allAirportCodes = new Array("NL","BER","BUE","DTT","HOU","LON","MIL","YMQ",
                    "MOW","NYC","OSA","PAR","ROM","SAO","SEL","STO","TYO","WAS");
    
    stopImg = "<img id='stop' alt='Stop' src='/images/closeBlack.png' border='0'/>";


    //breadcrumb = ""; // empty at start

    // Global Variables (uit oude buid-results.js)
    airlinePicturesArray = new Array("AA","DL","WN","UA","JL","NW","LH","AF",
    "NH","EL","US","CO","BA","QF","IB","KE","FR","HP","AC","SK","KL","U2","CA",
    "TG","CZ","MH","AS","SV","PC","CX","AZ","LX","LY","SQ","TW","VY","NE","7H",
    "NB","AB","HV","AY","AM","AO","AP","AT","BD","BE","CI","CJ","CL","CP","CY",
    "DE","DI","DM","DP","D9","EI","EK","FI","FJ","FL","FM","FQ","F7","F9","HF",
    "HG","H9","IG","JF","JI","JK","KA","KF","LO","LS","LT","MA","MP","MS","MT",
    "MU","NQ","OR","OS","OU","OV","PN","PY","QE","Q6","SA","SN","SU","TK","TP",
    "TS","TV","T4","VB","VG","VY","WH","WW","W6","XC","XG","ZU",
    "1I","2H","2L","2T","3L","4U","5Y","6B","8A","8O");
    maxProvidersPerFlight = 3; // max number of providers that is displayed in a compact result box
    maxFlightsPerPage = 15; // max number of flights to display on a single page
    maxTime = 80;       // number of seconds before scanning stops
    ivalLength = 2;       // waittime between scanning
    maxFailures = 5;
    maxLabelLength = 21;
    // static list of providers
    staticList = new Array('ryanair.com','tix.nl','transavia.nl',
                'vliegtickets.nl','klm.nl','ebookers.nl','vliegfabriek.nl',
                'expedia.nl','easyjet.nl','budgetair.nl');
    //origins = {};
    filters = new Array();
    filters['stops']    = new Array();
    filters['stops'][0] = new Filter("nonstop", true); // checked == true
    filters['stops'][1] = new Filter("onestop", true);
    filters['stops'][2] = new Filter("mulstop", true);
    // Initialize origin filters: all NL+ airports on
    originFilters = {'AMS':true,'EIN':true,'CRL':true,'MST':true,'RTM':true,
                     'BRU':true,'DUS':true,'NRN':true};
    
    randMax   = 99999999; // warning: altering this value is a bad idea
    highValue = 9999999;  // can be set to any big number (at least 20k)
    loadServletURL();   // AJAX request for data/nl/servleturl.xml
    //document.getElementById("circle-loader").style.display = "none";

    //document.getElementById('odForm').setAttribute( "autocomplete", "off" );
    if (language == "nl-nl") {
        document.getElementById("ysearchinput3").focus();
    } else {
        document.getElementById("ysearchinput2").focus();
    }

    YAHOO.example.ACFlatData.init();
    setDatumInitieel();
    
    YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container", {pages:2, mindate:maand+"/"+dag+"/"+jaar ,maxdate:maandT+"/"+0+"/"+jaar,title:selectDate, close:true} );
    YAHOO.example.calendar.cal1T = new YAHOO.widget.CalendarGroup("cal1T","cal1ContainerT", {pages:2, mindate:maand+"/"+dag+"/"+jaar ,maxdate:maandT+"/"+0+"/"+jaar,title:selectDate, close:true} );
    YAHOO.example.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.example.calendar.cal1, true);
    YAHOO.example.calendar.cal1T.selectEvent.subscribe(handleSelectT, YAHOO.example.calendar.cal1T, true);
    YAHOO.example.calendar.cal1.cfg.setProperty("MONTHS_LONG",[getMonthName(0),getMonthName(1),getMonthName(2),getMonthName(3),getMonthName(4),getMonthName(5),getMonthName(6),getMonthName(7),getMonthName(8),getMonthName(9),getMonthName(10),getMonthName(11)]);
    YAHOO.example.calendar.cal1.cfg.setProperty("WEEKDAYS_SHORT",[getDayName(0),getDayName(1),getDayName(2),getDayName(3),getDayName(4),getDayName(5),getDayName(6)]);
    YAHOO.example.calendar.cal1T.cfg.setProperty("MONTHS_LONG",[getMonthName(0),getMonthName(1),getMonthName(2),getMonthName(3),getMonthName(4),getMonthName(5),getMonthName(6),getMonthName(7),getMonthName(8),getMonthName(9),getMonthName(10),getMonthName(11)]);
    YAHOO.example.calendar.cal1T.cfg.setProperty("WEEKDAYS_SHORT",[getDayName(0),getDayName(1),getDayName(2),getDayName(3),getDayName(4),getDayName(5),getDayName(6)]);

//    YAHOO.util.Event.addListener("show3up", "click", YAHOO.example.calendar.cal1.show, YAHOO.example.calendar.cal1, true);
//    YAHOO.util.Event.addListener("show3upT", "click", YAHOO.example.calendar.cal1T.show, YAHOO.example.calendar.cal1T, true);

    YAHOO.example.calendar.cal1.render();
    YAHOO.example.calendar.cal1T.render();

    YAHOO.util.Event.addListener(["selMonth","selDay","selYear"], "change", updateCal);
    YAHOO.util.Event.addListener(["selMonthT","selDayT","selYearT"], "change", updateCalT);
    updateCal("true");
    updateCalT("true");

    if (useHashParams) {
        if (hash.length > 0) {
            checkHashParams(); // start new search or load results
        } else {
            getPrefillValues(); // if prefill values are set, use those values in the form
        }
    }

    ival3 = setInterval(function() {
        if (window.location.hash != hash) {
            hash = window.location.hash;
            // if back or forward button used (no form submit)
            if (formSubmitted == false || count > 0) {
                window.location.reload();
            }
        }
    }, 100);
}



