﻿prefix='ctl00_';
var errorMsg='';
var errorTime=3000;
var loading='loading';
var numNightsID='';
var anvrNummerID='';
var isMaster = false;

if (document.layers){
  //Netscape 4 specific code
  pre = 'document.';
  preobj = 'document';
  endobj = '';
  post = '';
} else if (document.getElementById) {
  //Netscape 6 specific code
  pre = 'document.getElementById("';
  preobj = 'document.getElementById("';
  endobj = '")';
  post = '").style';
} else {
  //IE4+ specific code
  pre = 'document.all.';
  preobj = 'document.all';
  endobj = '';
  post = '.style';
}

function submitFormInstant() {
    getObj('bodyContent_action').value = 'export';
    document.forms['form1'].submit();
    getObj('bodyContent_action').value = '';
}

function submitFormPortal(action) {
    getObj('bodyContent_formAction').value = action;
    document.forms['aspnetForm'].submit();
    getObj('bodyContent_formAction').value = '';
}

function submitForm() {
    try {
        document.forms['aspnetForm'].submit();
    } catch (err) {
        kickToAjax(err.Description, 'fn:submitForm()', '0', '');
        try {
            document.aspnetForm.submit();
        } catch (err) {
            document.forms[0].submit();
        }
        
    }
}

function showMenu(anvr, img, dateMin, dateMax, divShow) {
    var showPanel = getObj(divShow);
    var foldImage = getObj(img);

    if (showPanel.style.display == 'inline') {
        showPanel.style.display = 'none';
        foldImage.src = '/App_Image/plus.png';
        foldImage.alt = 'Toon menu';
    } else {
        showPanel.style.display = 'inline';
        foldImage.src = '/App_Image/min.png';
        foldImage.alt = 'Verberg menu';
        Ajax_Code.getBoekingenByMonth(anvr, dateMin, dateMax, divShow, SucceededCallback, FailedCallback);
    }
}

function hideErrorRow() {
    getObj('ctl00_sjorsPermanentAlert').style.display = 'none';
}

function addEvent(obj, evt, fct, cap) {
    if (!cap) { cap = false; }

    if (obj.addEventListener) {
        obj.addEventListener(evt, fct, cap);
        return true;
    } else if (obj.attachEvent) {
        return obj.attachEvent("on" + evt, fct);
    } else {
        if (!obj.myEvents) obj.myEvents = {};
        if (!obj.myEvents[evt]) obj.myEvents[evt] = [];
        var evts = obj.myEvents[evt];
        evts[evts.length] = fct;

        obj['on' + evt] = function () { evtExecute(obj, evt) };
    }
}

function evtExecute(obj, evt) {
    if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
    var evts = obj.myEvents[evt];
    for (var i = 0, len = evts.length; i < len; i++) evts[i]();
}


function ANVRnummer()
{
    if (anvrNummerID!='')
    {
        if (getObj(anvrNummerID))
        {
            return getObj(anvrNummerID).value;
        }
    }
    
    return '';
}

//toegevoegde functies milan
function PopUp(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}

function ClosePopUp(){
targetWin.close()
}

function roll_over(img_name, img_src) {
    document[img_name].src = img_src;
}

function waitForItAgentNieuws(boodschap, melding, id) {
    getObj('screenOverlay').setAttribute('onclick', '');

    var html = '<div style="width: 330px; height: 265px; padding: 10px 10px 0px 10px; padding-top: 20px; background-image: url(\'/App_Image/popup_350_150.png\'); background-repeat: no-repeat">';

    if (melding.length > 40) {
        html = html + '<div style="width: 330px; height: 32px; padding-top: 4px; font-weight: bold; color: #6294CD">' + melding + '</div>';
    } else {
        html = html + '<div style="width: 330px; height: 32px; padding-top: 10px; font-weight: bold; color: #6294CD">' + melding + '</div>';
    }

    html = html + '<div style="width:200px; height: 140px; padding: 10px 10px 0px 10px; padding-left: 120px;"><a href="agentnieuws.aspx?action=delete&id=' + id + '"><img src="App_Image/Confirm.png" border="0"/></a><a href="agentnieuws.aspx"><img src="App_Image/Decline.png" border="0"/></a></div>';
    html = html + '</div>';

    showPopup(350, 275, html);
}

function checkField(melding) {
    showSjors(melding, 5000)
    }
//


function Browser() {
    var myagent, s, i;

    this.isIE9 = false;
    this.isIE    = false;
    this.isNS    = false;
    this.version = null;

    myagent = navigator.userAgent;

    if ( ((i = myagent.indexOf("MSIE")) >= 0) || ((i = myagent.indexOf("Opera")) >= 0)) {
        this.isIE = true;
        this.version = parseFloat(myagent.substr(i + 4));

        if (this.version > 8) {
            this.isIE = false;
            this.isIE9 = true;
        }

        return;
    } else if ((i = myagent.indexOf("Netscape6/")) >= 0) {
        this.isNS = true;
        this.version = parseFloat(myagent.substr(i + 10));
        return;
    } else if ((i = myagent.indexOf("Gecko")) >= 0) {
        this.isNS = true;
        this.version = 6.1;
    }
    return;
}

var browser = new Browser();
	
function getObj(objname)
{
    myObj = eval(preobj+objname+endobj);

    if (!myObj)
    {
        myObj = eval(preobj+prefix+objname+endobj);  
    }

    return myObj;
}

function getStyle(objname)
{
    try 
    {
        myObj = eval(preobj+objname+post);
    } catch(err) {
        try
        {
            myObj = eval(preobj+prefix+objname+post);   
        } catch(err) {
            alert(objname+': '+err);
        }
    }
        
    return myObj;
}

function PageScrollY() 
{
    if (window.pageYOffset) {
        return window.pageYOffset;
    }
    else {
        if (document.documentElement && document.documentElement.scrollTop) {
            return document.documentElement.scrollTop;
        }
        else if (document.body) {
            return document.body.scrollTop;
        }
    }
    return 0;
}

function PageScrollHeight() 
{
    if (window.innerHeight && window.scrollMaxY) {
        // Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ 
        // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
    } else if (document.documentElement) {
        yWithScroll = document.documentElement.scrollHeight;
    } else {
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
    }
    
    return yWithScroll; 
}

function PageScrollWidth() 
{
    if (window.innerWidth && window.scrollMaxX) {
        // Firefox
        yWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollWidth > document.body.offsetWidth){ 
        // all but Explorer Mac
        yWithScroll = document.body.scrollWidth;
    } else { 
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetWidth;
    }
    
    return yWithScroll; 
}

function BrowserHeight() 
{
    if (window.innerHeight) {
        return window.innerHeight;
    }
    
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            return document.documentElement.clientHeight;
        }
        else if (document.body) {
            return document.body.clientHeight;
        }
    }
}

function BrowserWidth() 
{
    if (window.innerWidth) {
        return window.innerWidth - 17;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            return document.documentElement.clientWidth;
        }
        else if (document.body) {
            return document.body.clientWidth;
        }
    }
    return 0;
}


var persistent = new Array();

function hidePersistent() {
    if (typeof sIFR == "function") {
        sIFR.rollback();
    }
    
    var myCol = document.getElementsByTagName("object");
    
    for (i=0; i<myCol.length; i++) {

        //var myStyle = getStyle(myCol[i].id);

        if (myCol[i].id != '') {
            myStyle = myCol[i].style;
            //myStyle.display = 'none';
        }

        //myStyle.visibility='hidden';
    }
    
    return true;
}

function showPersistent()
{
    //sIFR.rollback();
    if(typeof sIFR == "function"){
        sIFR.replaceElement(named({ sSelector: "h2.sectionTitle", sFlashSrc: "/flash/caecilia_bold.swf", sColor: "#FFFFFF", sBgColor: "#6294CD", sWmode: "transparent" }));
        sIFR.replaceElement(named({ sSelector: "h2.itemAdjust", sFlashSrc: "/flash/caecilia_bold.swf", sColor: "#6294CD", sBgColor: "#FFFFFF", sWmode: "transparent" }));
        sIFR.replaceElement(named({ sSelector: "h2.agTitle", sFlashSrc: "/flash/caecilia_bold.swf", sColor: "#6294CD", sBgColor: "#d6e9ff", sWmode: "transparent" }));
        //sIFR.replaceElement(named({sSelector:"h3.tabTitle", sFlashSrc:"/flash/eurostile_bold.swf", sColor:"#000000", sBgColor:"#FFFFFF"}));
    };
}

function toggleOverlay(show)
{
    var overObj = getStyle('screenOverlay');

    if (show) {
        overObj.width=PageScrollWidth()+'px';

        var olayhgt = PageScrollHeight() + PageScrollY();

        if (olayhgt < BrowserHeight())
        {
            overObj.height = BrowserHeight().toString() + 'px';
        } else {
            overObj.height=olayhgt.toString() + 'px';
        }

        overObj.display='inline';

        hidePersistent();
    } else {
        overObj.display='none';

        showPersistent();
    }    
}

function showPopup(width, height, HTML) {
    toggleOverlay(true);

    var myPanel=getObj('showPanel');
    var myStyle=getStyle('showPanel');
    
    myStyle.width=width.toString()+'px';
    myStyle.height=height.toString()+'px';
    myStyle.left=((parseInt(BrowserWidth()) / 2)-(width/2)).toString()+'px';
    myStyle.top=((parseInt(BrowserHeight()) / 2)-(height/2)+parseInt(PageScrollY())).toString()+'px';
    myStyle.display='inline';
        
    myPanel.innerHTML = HTML;
}

function hidePopup()
{
    toggleOverlay(false);
    hideSjors();

    getStyle('showPanel').display='none';
}

function waitForIt(boodschap, melding) {
    try {
        getObj('screenOverlay').setAttribute('onclick', '');

        var html = '<div id="waitforme" style="width: 330px; height: 265px; padding: 10px 10px 0px 10px; border: solid 0px #FFFFFF; background-image: url(\'/App_Image/popup_350_275.png\'); background-repeat: no-repeat">';
        html = html + '<div style="width: 323px; height: 148px; padding-top: 80px; padding-left: 7px"><object id="busyContainerObj" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="width: 305px; height: 66px"><param name="movie" value="/flash/busy.swf" /><param name="wmode" value="transparent" /><!-- [if !IE]> --><embed src="/flash/busy.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="305px" height="66px" name="prijs_tag" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object></div>';

        if (melding.length > 40) {
            html = html + '<div style="width: 330px; height: 32px; padding-top: 4px; font-weight: bold; color: #FFFFFF">' + melding + '</div>';
        } else {
            html = html + '<div style="width: 330px; height: 32px; padding-top: 10px; font-weight: bold; color: #FFFFFF">' + melding + '</div>';
        }

        html = html + '</div>';

        showPopup(350, 275, html);
    }
    catch (err) {
        kickToAjax(err.Description, 'fn:waitForIt()', '0', '');
    }
}

window.onbeforeunload = function () {
    var myPanel = getObj('waitforme');
    if (myPanel) { myPanel.style.backgroundImage = "url('/App_Image/popup_350_275.png')"; }
}


function shadeHeader(objID, tsonts)
{
    var myobj=getObj(objID);
    
    if (tsonts)
    {
        myobj.style.display='none';
    } else {
        myobj.style.display='inline';
    }
}

function waitForType()
{
    switch(selectedTransport())
    {
        case 11:
            waitForIt('', 'Accommodaties en beschikbaarheid worden opgevraagd  ');     
        break;
        
        default:
            waitForIt('', 'Transport wordt opgevraagd  '); 
        break;
    }
}

function actionHeader(actie)
{
    var actionmsg='Gegevens worden opgevraagd.';
    var confirmGo=false;
    
    switch(actie.toLowerCase())
    {
        case 'accommodatie':
            actionmsg='Accommodaties worden opgevraagd.';
        break;
        
        case 'transport':
            actionmsg='Transportgegevens worden opgevraagd.';
        break;
        
        case 'reisplan':
            confirmGo=false;
        break;
    }

    getObj(headerActionID).value=actie;
    
    if (confirmGo)
    {
        var html='<div style="width: 230px; height: 140px; padding: 10px 10px 0px 10px; background-image: url(\'/App_Image/popup_250_150.png\'); background-repeat: no-repeat">';
        html=html+'</div>';
        
        showPopup(250, 150, html);            
    } else {
        waitForIt('', actionmsg);
        var tempTO = setTimeout(submitForm, 500);
    }
}

var stedenCache='';

function showCities()
{
    if (stedenCache=='') 
    {
        Ajax_Code.toonSteden(SucceededCallback, FailedCallback); 
    } else {
        showCityPanel(stedenCache)
    }
}

function showCityPanel(myhtml)
{
    var html='<div style="width: 500px; height: 460px; padding: 10px 10px 0px 10px; background-image: url(\'/App_Image/popup_520_470.png\'); background-repeat: no-repeat">';
    html=html+'<div style="width: 500px; height: 32px; padding-top: 8px; font-weight: bold; font-size: 14px">Stedenoverzicht</div>';            
    html=html+'<div style="width: 500px; height: 380px">'+myhtml+'</div>';            
    html=html+'<div style="width: 500px; height: 40px; text-align: right"><img style="margin-right: 8px; margin-bottom: 8px; cursor: pointer" onclick="javascript:hidePopup(); " onmouseover="javascript:this.src=\'/App_Image/close_over.png\'; " onmouseout="javascript:this.src=\'/App_Image/close.png\'; " src="/App_Image/close.png" alt="Sluit venster" /></div></div>';            
    showPopup(520, 470, html);
}

window.onresize = function () {
    if (getObj('screenOverlay'))
    {
        if (getObj('screenOverlay').style.display == 'inline') {
            toggleOverlay(true);

            var myStyle = getStyle('showPanel');

            var width = parseInt(myStyle.width);
            var height = parseInt(myStyle.height);

            myStyle.left = ((parseInt(BrowserWidth()) / 2) - (width / 2)).toString() + 'px';
            myStyle.top = ((parseInt(BrowserHeight()) / 2) - (height / 2) + parseInt(PageScrollY())).toString() + 'px';
        }

    }
}

var sjTrain;
var sjPopup;
var sjLeft = -850;
var trainTO;
var sjSW = BrowserWidth() + 10;
var sjMiddle = (BrowserWidth() / 2) -110;
var sjSpeed = 4;

function moveTrain() {
    if (sjTrain) {
        if (sjLeft > sjSW) {
            //sjLeft = -850;
            //sjSpeed = sjSpeed + Math.floor(Math.random() * 100)
        } else {
            sjLeft = sjLeft + sjSpeed;
        }

        if (sjLeft < sjMiddle) { sjPopup.style.left = (sjLeft + 10).toString() + 'px'; }
        sjTrain.style.left = sjLeft.toString() + 'px';
    } else {
        sjTrain = getObj('sjorstrain');
        sjPopup = getObj('sjorspopup');
    }

    if (sjLeft <= sjSW) {
        trainTO = setTimeout(moveTrain, 25);
    }
}

function hideHint() {
    getObj('sjorsHint').style.display = 'none';
    setCookie("sjorshint", "1", 1);
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + "; path=/";
    document.cookie = c_name + "=" + c_value;
}
