// Laenderdropdown ein- und ausblenden
var countrylayerwidth=0;
function countryselect(mode)
 {   
   var layer=get('countryselect');
   if (mode)
    {
      var x=get('countrydisplay').getX()-3;
      var maxwidth=Acolyte.getVisibleWidth();
      if (!countrylayerwidth) countrylayerwidth=layer.getWidth(); // Breite nur einmal messen da Wert spaeter nicht mehr stimmt
      if (x+countrylayerwidth>maxwidth) x+=maxwidth-countrylayerwidth-x; // Layer weiter nach links wenn Aufloesung zu niedrig
      layer.setX(x);
      layer.show();
    }
   if (!mode) layer.hide();
 }
/*
    caching fuer ajax anfragen
*/
aAjaxConsultantCache = new Array();
/*

*/
var jump=0; var opened=0;
function openjump () {
  if (jump==0) {
    document.getElementById('jumpoptions').style.display='block';
    jump=1;
    opened=1;
  }
  else closejump();
}
function closejump () {
  if (opened==0) {
    document.getElementById('jumpoptions').style.display='none';
    jump=0;
  }
  else opened=0;
}
function linklayer (el) {
  var text=el.parentNode.lastChild;
  if (text.style.display=='block') text.style.display='none';
  else text.style.display='block';
}
function clayer (el, consultant, channel) {
  var content;
  var layer=document.getElementById('clayer');
  var scroll,height,relposition,newtop,newleft,diff;
  layer.style.display="block";

  if (aAjaxConsultantCache[consultant]) {
    document.getElementById('clayercontent').innerHTML = aAjaxConsultantCache[consultant];
  }
  else {
    // änderungen um asynchron den server abzufragen
    var xmlhttp = false;
/*    var request = '/ajax/consultant.php?consultant='+consultant+'&channel='+channel;*/
    var request = ('/ajax/'+consultant+'.txt'); 
    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 && xmlhttp.status == 200) {
          var content = xmlhttp.responseText;
          // caching
          aAjaxConsultantCache[consultant] = content;
          document.getElementById('clayercontent').innerHTML = aAjaxConsultantCache[consultant];
        }
      }
      xmlhttp.send(null);
    }
  }

  if (window.pageYOffset) scroll=window.pageYOffset;
  else if (document.body.scrollTop) scroll=document.body.scrollTop;
  else if (document.documentElement.scrollTop) scroll=document.documentElement.scrollTop;
  else scroll=0;
  if (document.body && self.innerHeight) height=Math.min(document.body.clientHeight,self.innerHeight);
  else if (document.documentElement && document.documentElement.clientHeight) { height=document.documentElement.clientHeight; extra=1; }
  else if (document.body) height=document.body.clientHeight;

  var parent=el;
  var cposition=0;
  while (parent) {
    cposition+=parent.offsetTop;
    parent=parent.offsetParent;
  }
  cposition=cposition+9;

  var lheight=layer.firstChild.offsetHeight;
  if (cposition-scroll > height-lheight) {
    newtop=height+scroll-lheight;
    newleft=cposition-newtop;
    if (newleft+120 > lheight) {
      diff=lheight-120-newleft;
      newleft=newleft+diff;
      newtop=newtop-diff;
    }
  }
  else {
    newtop=cposition;
    newleft=0;
  }
  layer.style.top=newtop+'px';
  document.getElementById('clayerleft').style.top=newleft+'px';
}

function closeclayer () {
  document.getElementById('clayer').style.display="none";
}

function keepclayer () {
  document.getElementById('clayer').style.display="block";
}

function getConsultantData(consultant, channel)
{
    var content;

    if(aAjaxConsultantCache[consultant]){
        return aAjaxConsultantCache[consultant];
    }else{
        // änderungen um asynchron den server abzufragen
        var xmlhttp = false;
        var request = '/ajax/consultant.php?consultant='+consultant+'&channel='+channel;
        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 && xmlhttp.status == 200) {
                  var content = xmlhttp.responseText;
                  // caching
                 aAjaxConsultantCache[consultant] = content;
                 return content;
              }
          }
              xmlhttp.send(null);
        }
    }
}

function navclasses (id,cl) {
  document.getElementById('navtop'+id).className=cl;
  document.getElementById('nav'+id).className=cl;
  document.getElementById('navbottom'+id).className=cl;
}
function navswitch (on,off) {
  var lefton=on-1;
  var leftoff=off-1;
  navclasses(on,'active');
  navclasses(off,'');
  if (lefton>0) navclasses(lefton,'leftofactive');
  if (off-on!=1 && leftoff>0) navclasses(leftoff,'');
}

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
    if(!document.forms[FormName])
        return;
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    if(!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    if(!countCheckBoxes)
        objCheckBoxes.checked = CheckValue;
    else
        // set the check value for all check boxes
        for(var i = 0; i < countCheckBoxes; i++)
            objCheckBoxes[i].checked = CheckValue;
}
