/*
    caching fuer ajax suchanfragen
*/
aAjaxSearchCache = new Array();
aAjaxGlossarCache = new Array();
divs=new Array();

function getObject(name) {
  if(document.getElementById) return document.getElementById(name);
  else if(document.all) return document.all[name];
  else if(document.layers) return document.layers[name];
}

function resetIndiziesHeader(anzahl, act) {
    for(i=1;i<=anzahl;i++){
        document.getElementById('ihl_'+i).style.fontWeight='normal';
    }
    document.getElementById('ihl_'+act).style.fontWeight='bold';
}

function DisplayTime()
{

 var SysDate = new Date();
 var Day = SysDate.getDate();
 var MonthNow = SysDate.getMonth() + 1;
 var YearNow = SysDate.getFullYear();
 var HoursNow = SysDate.getHours();
 var MinuteNow = SysDate.getMinutes();
 var Seconds = SysDate.getSeconds();
 var DOW = SysDate.getDay();

 // erste Stelle fï¿½r zweistellige Anzeige bei einstelligem Ergebnis
 var firstDay  = ((Day < 10) ? "0" : "");
 var firstMonth  = ((MonthNow < 10) ? ".0" : ".");
 var firstHour  = ((HoursNow < 10) ? "0" : "");
 var firstMinute  = ((MinuteNow < 10) ? ":0" : ":");
 var firstSecond  = ((Seconds < 10) ? ":0" : ":");

 // aktuelles Datum
 var DateNow = firstDay + Day + firstMonth + MonthNow  + "." + YearNow;

 // aktuelle Zeit
 var TimeNow = firstHour + HoursNow + firstMinute + MinuteNow + firstSecond + Seconds + " Uhr";

 // Wochentag Datum Zeit
 var DispString = DateNow + " &nbsp;" + TimeNow;



if (document.layers) {
document.layers.uhr.document.write(DispString);
document.layers.uhr.document.close();
}
else
if (document.all || document.getElementById)document.getElementById('uhr').innerHTML = DispString;
setTimeout("DisplayTime()", 1000);
}

      var jsmenuCurrent=0, jsmenuDelay=0;
      function jsmenuOpen(key)
       {
         if ((jsmenuDelay) && (jsmenuDelay!=key)) document.getElementById('jsmenu'+jsmenuDelay).style.display='none';
         if (key) document.getElementById('jsmenu'+key).style.display='block';
         jsmenuCurrent=key;
       }
      function jsmenuClose(key)
       {
         jsmenuCurrent=0; jsmenuDelay=key;
         setTimeout("if (jsmenuCurrent!='"+key+"') { document.getElementById('jsmenu"+key+"').style.display='none'; if (jsmenuDelay=='"+key+"') jsmenuDelay=0; }",750);
       }
      function zpopup(url,width,height)
       {
         now=new Date(); fname='thefocus'+now.getMilliseconds();
         var handle=window.open(url,fname,"width="+width+",height="+height+",resizable=no,location=no,menubar=no,status=no,top=1,scrollbars=yes")
         handle.focus();
       }

// Ajax-Request
function ajaxLoad(request)
 {
   // Mozilla, Opera, Safari, Internet Explorer 7
   var xmlhttp=false;
   if (typeof(XMLHttpRequest)!='undefined') xmlhttp=new XMLHttpRequest();
   // Internet Explorer 6 und aelter
   if (!xmlhttp) try { xmlhttp=new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { xmlhttp=false; } }
   // Anfrage abschicken
   if (xmlhttp)
    {
      xmlhttp.open('GET',request,false);
      xmlhttp.send(null);
    }
   return xmlhttp.responseText;
}

function doSearch(value)
{
    var content;
    if(value.length<3){
        getObject("search_content").style.display="none";
        return;
    }

    getObject("search_content").style.display="inline";
    if(aAjaxSearchCache[value]){
        getObject("search_content").innerHTML=aAjaxSearchCache[value];
    }else{
        content = ajaxLoad('/ajax_arivasearch.php?searchword='+value);
        // änderungen um asynchron den server abzufragen
        var xmlhttp = false;
        var request = '/ajax_arivasearch.php?searchword='+value;
        if (typeof(XMLHttpRequest)!='undefined') xmlhttp=new XMLHttpRequest();
        // Internet Explorer 6 und aelter
           if (!xmlhttp) try { xmlhttp=new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { xmlhttp=false; } }
        // Anfrage abschicken
           if (xmlhttp)
        {
              xmlhttp.open('GET',request,true);
              xmlhttp.onreadystatechange=function() {
              if (xmlhttp.readyState==4) {
                  var content = xmlhttp.responseText;
                  getObject("search_content").innerHTML=content;
              }
          }
              xmlhttp.send(null);
        }
        // caching
        aAjaxSearchCache[value] = content;
    }
}

function doGlossar(value)
{
    var content;

    getObject("ajax_glossar").style.visibility='visible';
    getObject("content").style.visibility='hidden';
    window.scrollTo(0,0);
    if(aAjaxGlossarCache[value]){
        getObject("ajax_glossar").innerHTML=aAjaxGlossarCache[value];
    }else{
        content = ajaxLoad('/ajax_glossar.php?word='+value);
        getObject("ajax_glossar").innerHTML=content;
        // caching
        aAjaxGlossarCache[value] = content;
    }
}

function closeSearch()
{
    getObject('search_content').style.display='none';
}

function showGoogleMap(x, y, z)
{
    var map = new GMap2(document.getElementById('map'));
    var point = new GLatLng(x,y);
    map.setCenter(point, z);
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    map.addOverlay(new GMarker(point, icon));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
}

function evalKeyForSubmit(event) {
   if (event && event.which == 13 || event.keyCode==13){
           return true;
   }
}

function hidebox(elem){
    var crossobj1=document.getElementById(elem)
    crossobj1.style.visibility="hidden"
    document.getElementById('content').style.visibility='visible';
}
function showbox(elem){
    var crossobj1=document.getElementById(elem)
    crossobj1.style.visibility="visible"
}

function topnavInit()
 {
   var i,n=document.getElementById('topnav').childNodes;
   for (i=0;i<n.length;i++)
    {
      divs[i]=n[i].firstChild.nextSibling;
      if (divs[i])
       {
         divs[i].motion=false;
         if (n[i].className.indexOf('active')>=0) divs[i].isActive=true;
         n[i].i=i;
         divs[i].origY=divs[i].offsetHeight;
         divs[i].style.height="0px";
         n[i].onmouseover=function() { divs[this.i].parentNode.className='nav_container active_0'; divs[this.i].style.visibility='visible'; slide(this.i, 1); }
         n[i].onmouseout=function() { slide(this.i, -1); }
       }
    }
 }

function slide(num, flag)
 {
   obj=divs[num];
   osize=0;
   usize=obj.origY;
   window.clearTimeout(obj.motion);
   var step=60;
   oht = obj.style.height;
   oht = oht.substring(0, oht.indexOf('px'));
   oht = parseInt(oht);
   uht=usize;
   if (flag>0) step*=(1-oht/uht);
   else step*=(oht/uht);
   step = Math.ceil(step);
   while ((step-1) > (uht-oht)) step=step-.5;
   if (flag>0)
    {
      oht+=step;
      if (oht>usize) oht=usize;
    }
   else
    {
      oht-=step;
      if (oht<osize) oht=osize;
    }
   obj.style.height=oht+'px';
   if (flag>0)
    {
      if(oht!=uht) obj.motion=window.setTimeout("slide("+num+","+flag+")", 5000/usize);
      else window.clearTimeout(obj.motion);
    }
   else
    {
      if(oht>0) obj.motion = window.setTimeout("slide("+num+","+flag+")", 33);
      else
       {
         window.clearTimeout(obj.motion);
         obj.style.visibility='hidden';
         if (!obj.isActive) obj.parentNode.className='nav_container';
       }
    }
  }

function checkLogin()
 {
   if (document.forms.login_form.login_name.value)
    {
      clearLogin();
    }
  }

function clearLogin()
 {
   document.getElementById('login_nametext').style.display='none';
   document.getElementById('login_passwordtext').style.display='none';
 }

// Zusätze fürs Gewinnspiel "10 Jahre Quality Trading"
// Popupdemo:
function openPopup(target)
{
    if (target == "gewinnspiel")
    {
        Fenster1 = window.open("/lottery?popup=1", "Gewinnspiel", "width=900,height=615,left=100,top=50,resizable=no");
        Fenster1.focus();
    }
}