var http_request;
var winname;
var winnr;
var LastAjaxCall;

function mouseY(evt) {
  if (evt.pageY) return evt.pageY;
  else if (evt.clientY)
     return evt.clientY + (document.documentElement.scrollTop ?
     document.documentElement.scrollTop :
     document.body.scrollTop);
  else return null;
}

function alertkey(e) {
    if( !e ) {
      if( window.event ) {
       //Internet Explorer
        return window.event;
      } else {
        return;
      }
    }
    
    if( typeof( e.keyCode ) == 'number'  ) {
      //DOM
        return e.keyCode;
    } else if( typeof( e.which ) == 'number' ) {
      //NS 4 compatible
        return e.which;
    } else if( typeof( e.charCode ) == 'number'  ) {
      //also NS 6+, Mozilla 0.9+
        return e.charCode;
    } else {
      //total failure, we have no way of obtaining the key code
      return null;
    }
    
  }

var searchAjax;

var aktiv;
var ajaxsearchval = "";
var ajaxsearchnewval = "";

function checkAjaxSearchVal()
{
    ajaxsearchnewval = document.getElementById('_sfor').value;    
    if (ajaxsearchval == ajaxsearchnewval)
    {   
        window.clearInterval(aktiv);
        ajaxSuche();
    }
    else    
        ajaxsearchval = ajaxsearchnewval;
}

function updateBoxSearch(ctl)
{
    window.clearInterval(aktiv);    //  Wichtig MUSS IMMER ausgeführt werden bevor man einen neuen Interval abschießt ... sonst haben wir wilde pointer durch die Landschaft schießen
    //Wenn wir VT Suche wolle, wollen wir nit warten ;-)             <== deutsch sprach, schwer sprach ^^ (Gruß ako), P.S. was ist VT?
    if (window.event == 13)
       return;

    aktiv = window.setInterval("checkAjaxSearchVal()", 250);
    //ajaxSuche();
    return false;    
}

function ajaxSuche()
{   
    var sender = document.getElementById('_sfor');                            

    var sfor = '';
    sfor = sender.value;
    if(sfor.length)
    {    
       if(sfor == "")
            document.getElementById('__SEARCH').style.display = "none";
       else
       {
        var link = searchAjax;
        if (searchAjax.indexOf('?') > -1)
            link += '&_sfor=' + encodeURI(sfor);
        else
            link += '?_sfor=' + encodeURI(sfor);

        getContent(link, '__SEARCH');
        document.getElementById('__SEARCH').style.display = "block";
       }
    }
    else{
        document.getElementById('__SEARCH').style.display = "none";
    }
}

function prepareRequest()
{
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
        if (http_request.overrideMimeType) { 
            http_request.overrideMimeType('text/xml'); 
            // zu dieser Zeile siehe weiter unten 
        } 
    } else if (window.ActiveXObject) { // IE 
        try { 
            http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try { 
                http_request = new ActiveXObject("Microsoft.XMLHTTP60"); 
                
            } catch (e) {} 
        } 
    }     
}
function handleResponse() { 
    if (http_request.readyState == 4) { 
      //alert(http_request.responseXML);; //responseText
      //document.getElementById(winname).style.cursor = "default";
    } 
} 
function httpRequest(url, querystr, method)
{
    prepareRequest();
    if (http_request)
    {
        http_request.open(method, url, true);
        http_request.onreadystatechange = handleResponse;
        if (!querystr)
        {
            http_request.send(null);
        }
        else
        {
            http_request.send(querystr);
        }
    }
}

function getContent(url, layer_id) { 
    winname = layer_id;    
    document.getElementById(layer_id).style.display = "block"; 
    document.getElementById(layer_id).style.cursor = "wait";
    http_request = false;     
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
        http_request = new XMLHttpRequest(); 
        if (http_request.overrideMimeType) { 
            http_request.overrideMimeType('text/xml'); 
            // zu dieser Zeile siehe weiter unten 
        } 
    } else if (window.ActiveXObject) { // IE 
        try { 
            http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try { 
                http_request = new ActiveXObject("Microsoft.XMLHTTP60"); 
            } catch (e) {} 
        } 
    } 

    if (!http_request) { 
        return false; 
    }     
    http_request.open('GET', url, true);     
    http_request.onreadystatechange = showContent;
    http_request.send(null);
}

function showContent() { 
    if (http_request.readyState == 4) { 
      document.getElementById(winname).innerHTML = http_request.responseText;
      document.getElementById(winname).style.cursor = "default";
    } 
} 

function getWindowSize() {
  var win = new Object();
  var wh, ww
  
  if (window.innerHeight) {
    wh = window.innerHeight;
    ww = window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientHeight)    {
    wh = document.documentElement.clientHeight;
    ww = document.documentElement.clientWidth;
  }
  else if (document.body)    {
    wh = document.body.clientHeight;
    ww = document.body.clientWidth;
  }
  
  win.Height = wh;
  win.Width = ww;
  
  return win;
}

function ShowWorkingDIV()
{
    var win = getWindowSize();
    h = win.Height;
    w = win.Width;

    if (document.getElementById("_WORKINGDIV")) {
        document.getElementById("_WORKINGDIV").style.height = document.body.offsetHeight + "px";
        document.getElementById("_WORKINGDIV").style.width = document.body.offsetWidth + "px";
        document.getElementById("_WORKINGDIV").style.visibility = "visible";
    }        
}  

function HideWorkingDIV()
{
    if (document.getElementById("_WORKINGDIV")) {
        document.getElementById("_WORKINGDIV").style.visibility = "hidden";
    }        
}

function getPosition(element)
{
    var elem=element,tagname="",x=0,y=0;
    y = elem.offsetHeight;
    x = 20;

    while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
    {
      y+=elem.offsetTop;
      x+=elem.offsetLeft;
      tagname=elem.tagName.toUpperCase();

      if ((tagname=="HTML") || (tagname=="BODY"))
      {
        elem=0;
        } 

      if (typeof(elem)=="object")
        if (typeof(elem.offsetParent)=="object")
          elem=elem.offsetParent;
    }
    position=new Object();
    position.x=x;
    position.y=y;

    if (element.offsetWidth && element.offsetHeight) {
        position.width = element.offsetWidth;
        position.height = element.offsetHeight;
    }
    else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
        position.width = elem.style.pixelWidth;
        position.height = elem.style.pixelHeight;
    }

    return position;
}



/*************  EXPRESSABO  ***********/
var req;
var zeitschriftenCatId = "";
var zeitschriftenId = "";
var incentiveCatId = "";
var aboArtId = "";
var incentiveId = "";
var responseUrl = "";
function ExpressaboHandler(script, _zeitschriftenCatId, _zeitschriftenId, zStartIndex, _aboArtId, _incentiveCatId, iStartIndex, _incentiveId, _responseUrl)
{

    zeitschriftenCatId =_zeitschriftenCatId;
    zeitschriftenId = _zeitschriftenId;
    incentiveCatId = _incentiveCatId;
    aboArtId = _aboArtId;
    incentiveId = _incentiveId;
    responseUrl = _responseUrl;
    //alert(script + " => " + zeitschriftenCatId + " => " + zeitschriftenId + " => " + zStartIndex + " => " + aboArtId + " => " + incentiveCatId + " => " + iStartIndex + " => " + incentiveId);

    document.getElementById('abocontainerTrans').style.display = "block"; 
    document.getElementById('__EXPRESSABO').style.display = "block"; 
    document.getElementById('__EXPRESSABO').style.cursor = "wait";
    req = false;     
    if (window.XMLHttpRequest) { // Mozilla, Safari,... 
        req = new XMLHttpRequest(); 
        if (req.overrideMimeType) { 
            req.overrideMimeType('text/xml'); 
            // zu dieser Zeile siehe weiter unten 
        } 
    } else if (window.ActiveXObject) { // IE 
        try { 
            req = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try { 
                req = new ActiveXObject("Microsoft.XMLHTTP60"); 
            } catch (e) {} 
        } 
    } 

    if (!req) { 
        return false; 
    }     

    var url = script;
    url = url + '&zeitschriftenCatId=' + zeitschriftenCatId;
    url = url + '&zStartIndex=' + zStartIndex;
    url = url + '&zeitschriftenId=' + zeitschriftenId;
    url = url + '&aboArtId=' + aboArtId;
    url = url + '&incentiveCatId=' + incentiveCatId;
    url = url + '&iStartIndex=' + iStartIndex;
    url = url + '&incentiveId=' + incentiveId;
    url = url + '&rand=' + Math.random();//Math.floor(Math.random()*11);

    req.open('GET', url, true);     
    req.onreadystatechange = ExpressaboResponse;
    req.send(null);
}

function ExpressaboResponse()
{
    if (req.readyState == 4)   { 
        document.getElementById('__EXPRESSABO').innerHTML = req.responseText;
        document.getElementById('__EXPRESSABO').style.cursor = "default";

        var EAZeitschriftDetail = document.getElementById('EAZeitschriftDetail');
        var EAIncentiveMenu = document.getElementById('EAIncentiveMenu');
        var EAIncentiveDetail = document.getElementById('EAIncentiveDetail');

        if (EAZeitschriftDetail)
            EAZeitschriftDetail.style.display = (zeitschriftenCatId != "")  ? "block": "none";
        if (EAIncentiveMenu)
            EAIncentiveMenu.style.display = (zeitschriftenId != "") ? "block" : "none";
            //EAIncentiveMenu.style.display = (zeitschriftenId != "" && aboArtId == "1") ? "block" : "none";
        if (EAIncentiveDetail)
            EAIncentiveDetail.style.display = (incentiveCatId != "")    ? "block" : "none";
            //  So schauts aus wenn die Geschenke nicht nach links aufgerückt werden sollen ... MIT Geschenke-Kategorien-Menü
            //EAIncentiveDetail.style.display = (incentiveCatId != "" || aboArtId == "2" || aboArtId == "3" || aboArtId == "4")    ? "block" : "none";
        
        if (incentiveId != "" && responseUrl)
        {
            document.getElementById('__EXPRESSABO').style.display = 'none';
            window.location.href = responseUrl;
        }
    } 
}

function ExpressaboTableColor(ich)
{
    var lauf = 0;
    if (ich != "")
    {
        lauf = parseInt(ich);
    
        for (i=0; i<3; i++)
        {
            if (i == lauf)
                if (document.getElementById('EAtable_' + i))
                    document.getElementById('EAtable_' + i).style.border = "4px solid #AE0E1B";
            else
                if (document.getElementById('EAtable_' + i))
                    document.getElementById('EAtable_' + i).style.border = "0px solid";
        }
    }
}
/****** EXPRESSABO - ENDE ***********/