var browser = navigator.userAgent;
if(browser.indexOf('MSIE') != -1 && browser.indexOf('Opera') == -1) var browser = "Microsoft Internet Explorer";

function getE(id)
{
    return document.getElementById(id);
}

function set_bg(oElement,over_out)
{
    var oAl = false;
    oTDs = oElement.getElementsByTagName('TD');
    for(var i = 0; i < oTDs.length; i++)
    {
        if(over_out == 'sel')
        {
            oElement.setAttribute('selected','true');
            oTDs[i].style.backgroundColor =  '#BBBBBB';
        }
        else if(oElement.getAttribute('selected') == null)
        {
            oTDs[i].style.backgroundColor = (over_out == 'over') ? '#DDDDDD' : '#EEEEEE';
        }
    }
}

function show_submenu(id)
{
    if(!document.getElementById('subspacer'))
    {
        oDiv = document.createElement('DIV');
        oDiv.id = 'subspacer';
        oDiv.style.position = 'absolute';
        oDiv.style.top = '20';
        oDiv.style.left = '0';
        oDiv.style.width = '100%';
        oDiv.style.height = '70%';
        oDiv.style.zIdex = '50';
        //oDiv.style.backgroundColor = '#ff0000';
        oDiv.onmouseover = function() {  oClear_all = setTimeout('hide_all_subs()',500); }
        oDiv.onmouseout = function() {  if(typeof oClear_all != 'undefined') clearTimeout(oClear_all); }

        document.body.appendChild(oDiv);
    }
    else document.getElementById('subspacer').style.display = '';

    clear_sub_timeout();
    var oSub = document.getElementById(id);
    if(oSub)
    {
        //oSub.style.width = oSub.parentNode.clientWidth;
        //oSub.style.display = 'block';
        //new Effect.BlindUp(oSub.id);
        //if(browser == "Microsoft Internet Explorer") oSub.style.marginLeft = -oSub.parentNode.clientWidth - 60;
        //else oSub.style.marginLeft = -60;//-oSub.parentNode.clientWidth-15 - 100;
        //new Effect.Appear(oSub, { duration: 0.4});
        oSub.style.display = '';
    }
}


function opac_ie(id)
{
    //alert(id);
    document.getElementById(id).style.filter = "alpha(opacity=90,type=2)";
}

function hide_submenu(id,oTime)
{
    if(typeof oTime == 'undefined') oTime = 1000;
    oSub = document.getElementById(id);
    if(oSub) oHideTimer = setTimeout("hide_it()",oTime);
}

function clear_sub_timeout() {     if(typeof oHideTimer != 'undefined') clearTimeout(oHideTimer);document.getElementById('subspacer').style.display = ''; }

function hide_it() {

    //oSub.style.display = 'none';
    //new Effect.Fade(oSub, { duration: 0.2});
    oSub.style.display = 'none';

}

function hide_all_subs()
{
    if(typeof oSubmenu_array != 'undefined')
    {
        for(i=0;i<oSubmenu_array.length;i++)
        {
            var oSub = document.getElementById(oSubmenu_array[i]);
            if(oSub) oSub.style.display = 'none';
        }
        if(document.getElementById('subspacer')) document.getElementById('subspacer').style.display = 'none';
    }
}


function showhide(id)
{
    t = document.getElementById(id);
    if(t.style.display == 'none') t.style.display = '';
    else t.style.display = 'none';
}

function _hide(id) { getE(id).style.display = 'none'; }

function show_parent_nodes(oSub)
{
    //oSub = oSub.parentNode;
    while(oSub.parentNode)
    {
        if(oSub) oSub.style.display = '';
        oSub = oSub.parentNode;
    }
}

function top_offset(oThis,oTarget_id,topOffset)
{
    if(!oThis.currentStyle)
    {
        oTopMargin = oThis.offsetHeight * topOffset;
        document.getElementById(oTarget_id).style.marginTop = oTopMargin;
    }
}


if(typeof oActive_insert == 'undefined') oActive_insert     = new Object();
oActive_insert     = function (src,type,width,height,params)
{
    this.oSrc         = src;
    this.oType        = type;
    this.oWidth        = width;
    this.oHeight        = height;
    this.oParams        = params;

    if(this.oParams == '' || this.oParams == undefined) this.oParams = ' wmode="transparent" ';
    //if(this.oParams == '' || this.oParams == undefined) this.oParams = ' wmode="normal" ';

    this.init        = function()
    {
        this.oHTML         = ''; // reset the html
        if(this.oParams == '' || typeof(this.oParams) == 'undefined')     this.oParams = 'autoplay=\"0\" autostart=\"0\"';
        if(this.oType == 'swf') this.getswf();
        if(this.oType == 'mov') this.getmov();
        if(this.oType == 'avi') this.getmov();
        if(this.oType == 'dcr') this.getdcr();
        if(this.oType == 'mpeg' || this.oType == 'mpg') this.getmpeg();
        if(this.oType == 'wmv') this.getwmv();
        document.write(this.oHTML);
    }

    this.getswf = function()
    {
        this.oHTML         = '<embed src="'+this.oSrc+'" '+ this.oParams +' pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+this.oWidth+'" height="'+this.oHeight+'" />';    }

    this.getmov = function()
    {
        this.oHTML         = '  <embed src="'+this.oSrc+'" '+ this.oParams +' pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" width="'+this.oWidth+'" height="'+this.oHeight+'" />';
    }

    this.getmpeg = function()
    {
        this.oHTML         = '  <embed src="'+this.oSrc+'" '+ this.oParams +' width="'+this.oWidth+'" height="'+this.oHeight+'" />'; // pluginspage="http://www.microsoft.com/mac/otherproducts/otherproducts.aspx?pid=windowsmedia" type="video/quicktime"
    }

    this.getwmv = function()
    {
        this.oSrc = this.oSrc.replace("../../userfiles/",oAbspath+"userfiles/"); // op de een of andere manier werkt wmv alleen met absoluut pad
        this.oHTML         = '  <embed src="'+this.oSrc+'" '+ this.oParams +' width="'+this.oWidth+'" height="'+this.oHeight+'" />';
    }

    this.getdcr = function()
    {
        this.oSrc = this.oSrc.replace("../../userfiles/",oAbspath+"userfiles/"); // op de een of andere manier werkt wmv alleen met absoluut pad
        this.oHTML         = '  <embed '+ this.oParams +' src="'+this.oSrc+'" '+ this.oParams +' width="'+this.oWidth+'" height="'+this.oHeight+'" />';
        this.oHTML         = '    <OBJECT CLASSID="clsid:166B1BCA-3F9C-11CF-8075-444553540000"  CODEBASE="http://active.macromedia.com/director/cabs/sw.cab" WIDTH="'+this.oWidth+'" HEIGHT="'+this.oHeight+'" > <PARAM NAME="SRC" VALUE="'+this.oSrc+'"><embed src="'+this.oSrc+'" width="'+this.oWidth+'"  height="'+this.oHeight+'" '+ this.oParams +'> </OBJECT>';
    }

    this.init();
}

function backlink()
{
    oBl = document.getElementById('backlink');
    if(oBl)
    {
        if(window.history.length > 1)
        {
            oBl.style.display = '';
        }
    }

}

window.setTimeout('backlink()',400);

function getWindowWidth() {
    var windowWidth = 0;
    if (typeof(window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}


function getWindowHeight() {
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}



function _show_arrangement(id,title)
{
	if(getE('show_regio')) getE('show_regio').style.display = 'none';
	getE('iarrangementen').src = 'http://89.234.9.62/templates/bookings/1/arrangementen.php?info&id='+id+'&bg=90C831&bkuri=www.hotelsarnhem.nl';
	getE('arrangement_title').innerHTML = title;
	//new Effect.Appear(getE('arrangementendiv'),300);
    getE('arrangementendiv').style.display = '';
}

function _showmap(id,title)
{
	if(getE('show_regio')) getE('show_regio').style.display = 'none';
    //getE('iarrangementen').src = 'http://89.234.9.62/templates/hotelsarnhem/1/classes/google.maps.php?pid='+id+'&bg=90C831&bkuri=www.hotelsarnhem.nl&standalone=1';
    getE('iarrangementen').src = 'classes/google.maps.php?pid='+id+'&bg=90C831&bkuri=www.hotelsarnhem.nl&standalone=1';
	//getE('iarrangementen').src = 'http://89.234.9.62/templates/bookings/1/arrangementen.php?map&id='+id+'&bg=90C831&bkuri=www.hotelsarnhem.nl';
	//getE('iarrangementen').src = 'classes/google.maps.php?pid='+id+'&bg=90C831';
	getE('arrangement_title').innerHTML = title;
    //new Effect.Appear(getE('arrangementendiv'),300);
	getE('arrangementendiv').style.display = '';
}






_events = function()
{
    this.browser = navigator.userAgent;
    this.day;
    this.month;
    this.year;
    this.regio_id;

    if(this.browser.indexOf('MSIE') != -1 && this.browser.indexOf('Opera') == -1) this.browser = "Microsoft Internet Explorer";


    this.conn = function()
    {
        if ( this.browser == 'Microsoft Internet Explorer' ) return new ActiveXObject("Microsoft.XMLHTTP");
        else return new XMLHttpRequest();
    }

    this.getE = function(id) { return document.getElementById(id); }

    this.loadsplash_regio = function(id)
    {
        ht_splash     = this.conn();
        ht_splash.open('GET', oAbspath + 'classes/rbt/ajax.class.php?action=load_splash_regio&id='+id,true);
        ht_splash.onreadystatechange = this.show_splash_txt;
        ht_splash.send('');
    }

    this.show_splash_txt = function()
    {
        if ( ht_splash.readyState == 4 )
        {
            var response     = ht_splash.responseText;
            _events.getE('splash_txt').innerHTML = response;
        }
    }

    this.switch_regio = function(regio_id)
    {
        this.load_event_sum(this.day,this.month,this.year,regio_id,'month');
        getE('events_titlebar').style.backgroundColor             = regio_conf[regio_id][0];
    }
    this.load_event_sum = function(day,month,year,regio_id,type)
    {
        this.day         = day;
        this.month         = month;
        this.year         = year;
        this.regio_id     = regio_id;

        espans = this.getE('events_menu').getElementsByTagName('span');
        for( var i = 0 ; i < espans.length; i++)
        {
            espans[i].style.textDecoration = 'none';
        }
        month = (month < 10) ? '0'+month : month;
        this.getE('events_month_'+month).style.textDecoration = 'underline';
        this.getE('event_sum').innerHTML = 'loading...';
        //new Effect.Appear(this.getE('eventsdiv'),200);
        this.getE('eventsdiv').style.display = '';
        // #### IE
        setTimeout('_events.hide_selectboxes()', 500);


        ht_event_sum     = this.conn();
        ht_event_sum.open('GET', oAbspath + 'classes/rbt/ajax.class.php?action=loadevents&maand='+month+'&dag='+day+'&jaar='+year+'&regio_id='+regio_id+'&type='+type+'&hidemenu=true',true);
        ht_event_sum.onreadystatechange = this.show_event_sum;
        ht_event_sum.send('');
    }

    this.hide_selectboxes = function()
    {
        if(getE('events_select_month')) getE('events_select_month').style.display     = 'none';
        if(getE('events_select_year')) getE('events_select_year').style.display     = 'none';
    }

    this.show_event_sum = function()
    {
        if ( ht_event_sum.readyState == 4 )
        {
                var response     = ht_event_sum.responseText;
                _events.getE('event_sum').innerHTML = response;
        }
    }

    this.load_calendar = function(day,month,year,regio_id)
    {
        ht_calendar     = this.conn();
        ht_calendar.open('GET', oAbspath + 'classes/domain_classes/hotelsarnhem.class.php?action=loadcalendar&maand='+month+'&dag='+day+'&jaar='+year+'&regio_id='+regio_id,true);
        ht_calendar.onreadystatechange = this.show_calendar;
        ht_calendar.send('');
    }

    this.show_calendar = function()
    {
        if ( ht_calendar.readyState == 4 )
        {
                var response     = ht_calendar.responseText;
                _events.getE('calendar').innerHTML = "<center>" + response + "</center>";
        }
    }

    this.load_info = function(id,day,month,year,regio_id)
    {
        //new Effect.Appear('eventsdiv');
        getE('eventsdiv').style.display = '';
        ht_info     = this.conn();
        ht_info.open('GET', oAbspath + 'classes/rbt/ajax.class.php?action=load_event_info&id='+id+'&maand='+month+'&dag='+day+'&jaar='+year+'&regio_id='+regio_id,true);
        ht_info.onreadystatechange = this.show_info;
        ht_info.send('');
    }

    this.show_info = function()
    {
        if ( ht_info.readyState == 4 )
        {
                var response     = ht_info.responseText;
                _events.getE('event_sum').innerHTML = response;
        }
    }

    this.load_tip = function(id)
    {
        this.getE('tip_content').innerHTML = 'Tip van de maand wordt geladen...';
        // #### IE
        if(getE('events_select_month')) getE('events_select_month').style.display     = 'none';
        if(getE('events_select_year')) getE('events_select_year').style.display     = 'none';
        //new Effect.Appear(this.getE('tipdiv'),200);
        this.getE('tipdiv').style.display = '';
        ht_tip     = this.conn();
        ht_tip.open('GET', oAbspath + 'classes/rbt/ajax.class.php?action=loadtip&id='+id,true);
        ht_tip.onreadystatechange = this.show_tip;
        ht_tip.send('');
    }

    this.show_tip = function()
    {
        if ( ht_tip.readyState == 4 )
        {
                var response     = ht_tip.responseText;
                _events.getE('tip_content').innerHTML = response;
        }
    }

    this.subscribe = function(id)
    {
        var oName     = getE('subname').value;
        var oEmail     = getE('subemail').value;
        ht_subscribe     = this.conn();
        ht_subscribe.open('GET', oAbspath + 'classes/rbt/ajax.class.php?action=subscribe&name='+oName+'&email='+oEmail,true);
        ht_subscribe.onreadystatechange = this.show_subscribe;
        ht_subscribe.send('');
    }

    this.show_subscribe = function()
    {
        if ( ht_subscribe.readyState == 4 )
        {
                var response     = ht_subscribe.responseText;
                if(response != '') alert(response);
                else
                {
                    getE('substatus').innerHTML = 'Bedankt voor uw interesse';
                    getE('subtable').style.display = 'none';
                    setTimeout('_events._close_window("subscribediv")',1500);

                }

        }
    }

    this._close_window = function(id)
    {
        // #### IE
        if(getE('events_select_month')) getE('events_select_month').style.display     = '';
        if(getE('events_select_year')) getE('events_select_year').style.display     = '';
        //new Effect.Fade(getE(id),300);
        getE(id).style.display = 'none';
    }
}
_events = new _events();
