﻿// JScript File
// If it is not IE, we assume that the browser is NS.
//var IE = document.all ? true : false;

//// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE);

//// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

//// Temporary variables to hold mouse x-y pos.s
//var mousePosX = 0;
//var mousePosY = 0;

//// Main function to retrieve mouse x-y pos.s
//function getMouseXY(e) 
//{
//    try
//    {
//        if (IE) 
//        { 
//            // grab the x-y pos.s if browser is IE
//            mousePosX = event.clientX + document.body.scrollLeft
//            mousePosY = event.clientY + document.body.scrollTop
//        } 
//        else if (event)
//        {  
//            // grab the x-y pos.s if browser is NS
//            mousePosX = e.pageX
//            mousePosY = e.pageY
//        }  

//        // catch possible negative values in NS4
//        if (mousePosX < 0) { mousePosX = 0 }
//        if (mousePosY < 0) { mousePosY = 0 }                  
//    }
//    catch (err)
//    {
//        // im iframe
//    }
//    return true;
//}

function showMap24(startStreet, targetCode)
{
    if (startStreet != '')
    {
        var link = 'http://bme.map24.com/index.php?foo=1&appid=AKZENT-HOTELS&lang=de-DE&STREET0={0}&location={1}&action=routeto';
        link = link.replace('{0}', escape(startStreet));
        link = link.replace('{1}', targetCode);
        var map24 = window.open(link, 'Map24');
    }
}

var currentWindow = null;
var showRadWindowCounter = 0;
function showRadWindow(clientID, url) {
    try
    {
        var radWindow = $find(clientID);
        hideRadWindow();
        if (url && url != '')
        {
            radWindow.setUrl(url);
        }
        radWindow.show();
        currentWindow = radWindow;
        showRadWindowCounter = 0;
    }
    catch (e) {
        // $find noch nicht verfuegbar
        showRadWindowCounter++;
        if (showRadWindowCounter < 25)
        {
            currentTimeout = window.setTimeout('showRadWindow(\'' + clientID + '\', \'' + url + '\')', 100);
        }
    }
}

function hideRadWindow()
{
    if (currentWindow)
    {
        currentWindow.hide();
        currentWindow = null;
    }
}

var TimeToFade = 400.0;
var activeElements = new Array();
// var activeFade = -1;
var currentTimeout = -1;

function hideDelayed(eid)
{
    if (currentTimeout == -1)
    {
        currentTimeout = window.setTimeout("hide('" + eid + "')", 500);
    }
}

function hide(eid)
{
    var element = document.getElementById(eid);
    
    if (element != null)
    {
        activeFade = -1;
        element.style.left = -999;
        element.style.opacity = 0;
        element.style.filter = 'alpha(opacity = ' + (0*100) + ')';        
    }   
    
    currentTimeout = -1; 
}

function cancelHideDelayed()
{
    window.clearTimeout(currentTimeout);
    currentTimeout = -1; 
}

var activeFade = -1;
function fade(eid)
{
    if (eid == activeFade)
    {
        return;
    }
    else
    {
        activeFade = eid;
    }
    
    while (activeElements.length > 0)
    {
        // aktuelle ausblenden
        var activeElement = activeElements.pop();
        activeElement.style.left = -999;
        activeElement.style.opacity = 0;
        activeElement.style.filter = 'alpha(opacity = ' + (0*100) + ')';        
    }
    
    var element = document.getElementById(eid);
    element.eid = eid;
    element.style.left = 'auto';
    element.style.opacity = 0;
    element.style.filter = 'alpha(opacity = ' + (0*100) + ')';        
    element.FadeState = 1;
    element.FadeTimeLeft = TimeToFade;
    
    activeElements.push(element);
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
}

function animateFade(lastTick, eid)
{
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var element = document.getElementById(eid);

    if (element.FadeTimeLeft <= elapsedTicks)
    {
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = ' + (element.FadeState == 1 ? '100' : '0') + ')';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        return;
    }

    element.FadeTimeLeft -= elapsedTicks;
    var newOpVal = element.FadeTimeLeft/TimeToFade;
    if (element.FadeState == 1)
        newOpVal = 1 - newOpVal;

    element.style.opacity = newOpVal;
    element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
    setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}


function DetectNEnter(e, btn) {
    var characterCode;
    if (e && e.which) {
        // NN4 specific code
        e = e;
        characterCode = e.which;
    }
    else {
        // IE specific code
        e = event
        characterCode = e.keyCode;
    }

    if (characterCode == 13) //// Enter key is 13
    {
        e.returnValue = false;
        e.cancelBubble = true;
        document.getElementById(btn).click();
    }
}