/* XmlHttpRequest library */
    /* Version 0.9.2.2, 6 May 2005, Adamv.com */
    function _getXmlHttp()
    {
        /*@cc_on @*/
        /*@if (@_jscript_version >= 5)
                var progids=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
                for (i in progids) {
                        try { return new ActiveXObject(progids[i]) }
                        catch (e) {}
                }
        @end @*/
        try { return new XMLHttpRequest();}
        catch (e2) {return null; }
    }

    function CachedResponse(response) {
        this.readyState = ReadyState.Complete
        this.status = HttpStatus.OK
        this.responseText = response
    }

    ReadyState = {
        Uninitialized: 0,
        Loading: 1,
        Loaded:2,
        Interactive:3,
        Complete: 4
    }

    HttpStatus = {
        OK: 200,
        NotFound: 404
    }

    function Request_from_cache(url, f_change) {
        var result = this._cache[url];

        if (result != null) {
            var response = new CachedResponse(result)
            f_change(response)
            return true
        }
        else
            return false
    }

    function Request_cached_get(url, f_change) {
        if (!this.FromCache(url, f_change)){
            var request = this
            this.Get(url,
            /* Cache results if request completed */
            function(x){
                if ((x.readyState==ReadyState.Complete)&&(x.status==HttpStatus.OK))
                {request._cache[url]=x.responseText}
                f_change(x)
            },
            "GET")
        }
    }

    function Request_get(url, f_change, method) {
        if (!this._get) return;

        if (method == null) method="GET"
        if (this._get.readyState != ReadyState.Uninitialized)
            this._get.abort()

        this._get.open(method, url, true);

        if (f_change != null) {
            var _get = this._get;
            this._get.onreadystatechange = function(){f_change(_get);}
        }
        this._get.send(null);
    }

    function Request_get_no_cache(url, f_change, method){
        var sep = (-1 < url.indexOf("?")) ? "&" : "?"
        var newurl = url + sep + "__=" + encodeURIComponent((new Date()).toString());
        return this.Get(newurl, f_change, method);
    }

    function Request() {
        this.Get = Request_get
        this.GetNoCache = Request_get_no_cache
        this.CachedGet = Request_cached_get
        this.FromCache = Request_from_cache

        this.Use = function(){return this._get!=null}
        this.Cancel = function(){if (this._get) this._get.abort();}
        this._cache = new Object();
        this._get = _getXmlHttp();
        if (this._get == null)
        {
            //if there is a "notSupported function, call it, else do nothing
            if( typeof(NotSupported) == 'function' )
                NotSupported();
            else
                return;
        }
    }

    function GetRegions()
    {
        var countryID = document.getElementById(lstCountryID).options[document.getElementById(lstCountryID).selectedIndex].value;
        if( countryID == '' )
        {
            var e    = document.getElementById(lstRegionID)
            e[0]     = new Option(document.getElementById(hfRegionID).value, "");
            e.length = 1;
        }

        var url = "<?= $code ?>Regions.aspx?CountryID=" + countryID;

        var req = new Request();
        req.GetNoCache(url, GetRegionsResult);
    }

    function GetRegionsResult(result)
    {
        if (result.readyState!=ReadyState.Complete) return;
        if (result.status==HttpStatus.OK && result.responseText != "")
        {
            if( result.responseText != "Nothing" )
            {
                var e   = document.getElementById(lstRegionID);
                var all = document.getElementById(hfRegionAllID).value;

                e[0] = new Option(all ,"");
                eval( result.responseText );

                //Added by JvL on 20090930: check if only 1 item is in dropdownlist
                //Select item if only 1 item is available
                if (e.length==2)
                    e.options[1].selected = true;

                GetPlaces();
            }
        }
        else
        {
            //alert( result.status );
            //alert( result.responseText );
        }
    }

    function GetPlaces()
    {
        var regionID = document.getElementById(lstRegionID).options[document.getElementById(lstRegionID).selectedIndex].value;
        var countryID = document.getElementById(lstCountryID).options[document.getElementById(lstCountryID).selectedIndex].value;
        /*if( regionID == '' )
        {
                var e    = document.getElementById(lstPlaceID)
                e[0]     = new Option(document.getElementById(hfPlaceID).value, "");
                e.length = 1;
        }*/

        var url = "<?= $code ?>Places.aspx?CountryID=" + countryID + "&RegionID=" + regionID;

        var req = new Request();
        req.GetNoCache(url, GetPlacesResult);
    }

    function GetPlacesResult(result)
    {
        if (result.readyState!=ReadyState.Complete) return;
        if (result.status==HttpStatus.OK && result.responseText != "")
        {
            if( result.responseText != "Nothing" )
            {
                var e   = document.getElementById(lstPlaceID);
                var all = document.getElementById(hfPlaceAllID).value;

                e[0] = new Option(all ,"");
                eval( result.responseText );

                //Added by JvL on 20090930: check if only 1 item is in dropdownlist
                //Select item if only 1 item is available
                if (e.length==2)
                    e.options[1].selected = true;
            }
        }
        else
        {
            alert( result.status );
            alert( result.responseText );
        }
    }

    function GetAccommodations()
    {
        //if( Page_ClientValidate("") == true )
        //{
        var pos       = 0;
        var winHeight = 0;
        var wt        = document.getElementById('Wait');
        var wtcnt     = document.getElementById('WaitContent');
        var bd        = document.getElementsByTagName('BODY')[0];

        if (window.innerHeight)
        {
            pos = window.pageYOffset
            winHeight = window.innerHeight;
        }
        else if (document.documentElement)
        {
            pos = document.documentElement.scrollTop
            winHeight = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
            pos = document.body.scrollTop
            winHeight = document.body.clientHeight;
        }

        wt.top            = '0px;'
        wt.style.width    = bd.offsetWidth + 'px';
        wt.style.height   = winHeight + 'px';
        wt.style.display  = 'block';
        wtcnt.style.left  = ((bd.offsetWidth - 250)/2) + 'px';
        wtcnt.style.top   = ((winHeight-100)/2) + 'px';

        var url = "<?= $code ?>Step2_Search.aspx"
        url    += "?co=" + document.getElementById(lstCountryID).value;
        url    += "&dt=" + document.getElementById(lstDateID).value;
        url    += "&du=" + document.getElementById(lstDurationID).value;
        url    += "&aa=" + document.getElementById(lstAdultsID).value;
        url    += "&ac=" + document.getElementById(lstChildrenID).value;
        url    += "&ab=" + document.getElementById(lstBabiesID).value;
        url    += "&at=" + document.getElementById(lstAccoTypeID).value;
        url    += "&tt=" + document.getElementById(lstTransportID).value;
        url    += "&rg=" + document.getElementById(lstRegionID).value;
        url    += "&pl=" + document.getElementById(lstPlaceID).value;
        url    += "&dp=" + document.getElementById(lstDepartID).value;
        //url    += "&bu=" + document.getElementById(lstBudgetID).value;
        url    += "&bu=";
        url    += "&bo=" + document.getElementById(lstBoardID).value;

        var req = new Request();
        req.GetNoCache(url, GetAccommodationsResult);
        //}
    }

    function GetAccommodationsResult(result)
    {
        if (result.readyState!=ReadyState.Complete) return;
        if (result.status==HttpStatus.OK)
        {
            location.href = '<?= $code ?>Step2.aspx?Search=false';
        }
        else
        {
            //alert( result.responseText );
            alert("Door grote drukte kan het voorkomen dat u tijdelijk niet kunt sorteren op prijs.");
            document.getElementById('Wait').style.display = 'none';
            document.getElementById(chkSortOnPriceID).checked = false;
        }
    }

    function CheckOtherDate(direction, period)
    {
        var url = "<?= $code ?>Step2_CheckDate.aspx?type=" + direction + "&Period=" + period;

        var req = new Request();
        req.GetNoCache(url, GetCheckOtherDateResult);
    }

    function GetCheckOtherDateResult(result)
    {
        if (result.readyState!=ReadyState.Complete) return;
        if (result.status==HttpStatus.OK && result.responseText != "")
        {
            eval(result.responseText);
        }
        else
        {
            alert("Er zijn geen alternatieve data gevonden");
        }
    }

    function ShowAccoInformation(accoID)
    {
        ShowAccoInformation(0, 0, 0,  accoID);
    }

    function ShowAccoInformation(countryID, regionID, placeID, accoID, date)
    {
        ShowAccoInformation(countryID, regionID, placeID, accoID, date, "A")
    }

    function ShowAccoInformation(countryID, regionID, placeID, accoID, date, type)
    {
        url  = "<?= $code ?>Information.aspx?co=" + countryID;
        url += "&rg=" + regionID;
        url += "&pl=" + placeID;
        url += "&ac=" + accoID;
        url += "&dt=" + date;
        url += "&tp=" + type;

        var theInfo = window.open(url, "AccoInformation", "top=0, left=0, height=600, width=820, scrollbars=yes, resizable=yes, status=no, location=no, toolbar=no");
        theInfo.focus();
    }

    function setOpenState() {
        var link = document.getElementById(hlExtSearchID);
        var border = document.getElementById('border');
        //link.className = 'bulletlinkup';
        border.style.display = 'block';
        //Update links
        document.getElementById(hlExtSearchID).style.display = 'none'
        document.getElementById(hlExtSearch2ID).style.display = ''
    }

    function setClosedState() {
        var link = document.getElementById(hlExtSearchID);
        var border = document.getElementById('border');
        border.style.display = 'none';
        //Update links
        document.getElementById(hlExtSearchID).style.display = ''
        document.getElementById(hlExtSearch2ID).style.display = 'none'
    }

    function Revealer(obj, startY, visibleHeight) {
        this.div = document.getElementById(obj);
        this.visibleHeight = visibleHeight;
        this.startY = startY;
        this.height = this.div.offsetHeight;
        this.yClip = this.height - visibleHeight;
        this.yPos = (startY - this.height) + visibleHeight;
        this.animating = -1;
        this.div.style.top = this.yPos + "px";
        this.div.style.clip = "rect(" + this.yClip + "px auto auto auto)";
    }

    Revealer.prototype.pixelDown = function (amount) {
        this.yPos += amount;
        this.yClip -= amount;
        if (this.yPos > this.startY) {
            this.yPos = this.startY;
            this.yClip = 0;
            clearInterval(animating);
        }
        this.div.style.clip = "rect(" + (this.yClip) + "px auto auto auto)";
        this.div.style.top = this.yPos + "px";
    }

    Revealer.prototype.pixelUp = function (amount) {
        this.yPos -= amount;
        this.yClip += amount;
        if (this.yPos < (this.startY - this.height) + this.visibleHeight) {
            this.yPos = this.startY - this.height + this.visibleHeight;
            this.yClip = this.height - this.visibleHeight;
            clearInterval(animating);
        }
        this.div.style.top = this.yPos + "px";
        this.div.style.clip = "rect(" + (this.yClip) + "px auto auto auto)";
    }

    function Animator(obj, startY, visibleHeight) {
        animator = new Revealer(obj, startY, visibleHeight);
        this.open = function() {animating = setInterval("animator.pixelDown(10)", 10)};
        this.close = function() {animating = setInterval("animator.pixelUp(10)", 10)};
    }

    function attachAction(open) {


        if (open)
        {
            var searchBut = document.getElementById(hlExtSearchID);
            searchBut.onclick = function () {extSearch.open();attachAction(0);setOpenState();}
        }
        else
        {
            var searchBut = document.getElementById(hlExtSearch2ID);
            searchBut.onclick = function () {extSearch.close();attachAction(1);setClosedState();}
        }
        document.getElementById('extendedSearch').style.visibility = 'visible';
    }

    function StartUp()
    {
        extSearch = new Animator('extendedSearch', document.getElementById('extendedSearch').offsetTop, document.getElementById('btnSearchDiv').offsetHeight);
        attachAction(open);
    }

    function ShowWindow(show)
    {
        if (document.getElementById("ShowWindow"))
        {
            switch (show)
            {
                case true : document.getElementById("ShowWindow").style.visibility = "visible"; break;
                case false : document.getElementById("ShowWindow").style.visibility = "hidden"; break;
            }
        }
    }

    /***********************************************
     * Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
     * This notice MUST stay intact for legal use
     * Visit http://www.dynamicdrive.com/ for full source code
     ***********************************************/
    var tipwidth='150px' //default tooltip width
    var tipbgcolor='lightyellow'  //tooltip bgcolor
    var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
    var vertical_offset="0px" //horizontal offset of tooltip from anchor link
    var horizontal_offset="-3px" //horizontal offset of tooltip from anchor link

    /////No further editting needed

    var ie4=document.all
    var ns6=document.getElementById&&!document.all

    if (ie4||ns6)
        document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';" class="ToolTip"></div>')

    function getposOffset(what, offsettype){
        var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
        var parentEl=what.offsetParent;
        while (parentEl!=null){
            totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
            parentEl=parentEl.offsetParent;
        }
        return totaloffset;
    }


    function showhide(obj, e, visible, hidden, tipwidth){
        if (ie4||ns6)
            dropmenuobj.style.left=dropmenuobj.style.top=-500
        if (tipwidth!=""){
            dropmenuobj.widthobj=dropmenuobj.style
            //dropmenuobj.widthobj.width=tipwidth
        }
        if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
            obj.visibility=visible
        else if (e.type=="click")
            obj.visibility=hidden
    }

    function iecompattest(){
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }

    function clearbrowseredge(obj, whichedge){
        var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
        if (whichedge=="rightedge"){
            var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
            dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
            if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
                edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
        }
        else{
            var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
            dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
            if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
                edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
        }
        return edgeoffset
    }

    function fixedtooltip(menucontents, obj, e, tipwidth){
        if (window.event) event.cancelBubble=true
        else if (e.stopPropagation) e.stopPropagation()
        clearhidetip()
        dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
        dropmenuobj.innerHTML=menucontents

        if (ie4||ns6){
            showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
            dropmenuobj.x=getposOffset(obj, "left")+20
            dropmenuobj.y=getposOffset(obj, "top")
            dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
            dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
        }
    }

    function hidetip(e){
        if (typeof dropmenuobj!="undefined"){
            if (ie4||ns6)
                dropmenuobj.style.visibility="hidden"
        }
    }

    function delayhidetip(){
        if (ie4||ns6)
            delayhide=setTimeout("hidetip()",disappeardelay)
    }

    function clearhidetip(){
        if (typeof delayhide!="undefined")
            clearTimeout(delayhide)
    }



    function WebForm_DoPostBackWithOptions() {
        var theForm = document.forms['aspnetForm'];
        if (!theForm) {
            theForm = document.aspnetForm;
        }
        theForm.__EVENTTARGET.value = 'ctl00$ContentPlaceHolder_Body$btnSearch';
        theForm.__EVENTARGUMENT.value = '';
        theForm.submit();
    }

    function WebForm_PostBackOptions() {

    }
