var aktKey="";
var chgActive=true;
var clickActive=true;
function getStrKeyCode(e) {
  var keynum;
  var keychar;
  var numcheck;
  if(window.event) // IE
    return window.event.keyCode
  else if(e.which) // Netscape/Firefox/Opera
    return e.which
}
/*
var http_request = false;
var fctDefault="DEFAULT";
function makePOSTRequest(url, parameters, status) {
  fctDefault=(status?status:"DEFAULT");
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  }
  else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {}
    }
  }
  if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }

  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
  return false;
}
function alertContents() {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      var result = http_request.responseText;
      switch (fctDefault) {
        case "EVAL":
          eval(result);
        break;
        //default: alert(result);
      }
    }
    else {
      alert('There was a problem with the request.');
    }
  }
  return false;
}
*/
function getKey(e) {
  keychar = String.fromCharCode(getStrKeyCode(e));
  return keychar;
}
function goToNeares(searchText, cbCtr) {
  for(i=0; i<document.getElementById(cbCtr).length; i++) {
    if (document.getElementById(cbCtr).options[i].text.toUpperCase().indexOf(searchText.toUpperCase()) == 0) {
      document.getElementById(cbCtr).selectedIndex=i;
      break;
    }
  }
}
function loadNewOptions(aKey,cbCtr,type) {
  if (tbl) {
    clearCtr(document.getElementById(cbCtr),type);
    makePOSTRequest("AdrStr.php","TABLE="+cbCtr+"&ORT="+tbl+"&CONTROL="+cbCtr+"&NODE="+aKey,"EVAL");
  }
}
function loadNaviOptions(cbCtr,param,type) {
  clearCtr(document.getElementById(cbCtr),type);
  makePOSTRequest("AdrFilter.php","TABLE=orte"+param,"EVAL");
}
var oldLink=null;
function setLinkDecoration(aLink) {
  if (oldLink) oldLink.className="";
  aLink.className="clicked";
  oldLink=aLink;
}
function hideStrSelect(lost) {
  if (!lost || (lost && !document.getElementById("str").hasFocus())) {
    window.focus();
    document.getElementById("strSelect").style.display="none";
  }
}
function loadHnr(aCtrSl,txtCtr) {
  globalHNR=0;
  document.getElementById(txtCtr).value="";
  if (chgActive) {
    if (aCtrSl.selectedIndex>=0) {
      hideStrSelect(); 
      document.getElementById(txtCtr).value=aCtrSl.options[aCtrSl.selectedIndex].text;
      setExtent(aCtrSl.options[aCtrSl.selectedIndex].value);
      loadNewOptions(escape(aCtrSl.options[aCtrSl.selectedIndex].text),"hnr_","DIV"); 
    }
  }
}
function execute(txtCtr,cbCtr) {
  chgActive=true;
  clickActive=false;
  loadHnr(document.getElementById(cbCtr),"strEdit");
}
function clearCtr(aCtr,type){
  if (aCtr) {  
    if (type=="SELECT") {
      for(var i=(aCtr.length-1);i>=0; i--)
        aCtr.remove(i);
    }
    else if (type=="DIV") aCtr.innerHTML="";
  }
}
var inSL=false;
function findNeares(e,ctrIdx, txtCtr, cbCtr) {
  if (getStrKeyCode(e) == 13) {
    execute(txtCtr, cbCtr);
    //document.getElementById(txtCtr).value="";
    inSL=false;
    return;
  }
  if (ctrIdx===0) {
    if (!inSL) {
      inSL=true;
      document.getElementById(txtCtr).value="";
    }
    document.getElementById(txtCtr).value+=getKey(e);
  }
  else inSL=false;
  if (document.getElementById(txtCtr).value.length>=3) {
    document.getElementById("strSelect").style.display="block";
    chgActive=false;
    clickActive=false;
    //if (aktKey==document.getElementById(txtCtr).value.toUpperCase()) {
    if (aktKey.length>0 && (aktKey.indexOf(document.getElementById(txtCtr).value.toUpperCase())===0 || document.getElementById(txtCtr).value.toUpperCase().indexOf(aktKey)===0)) {    
      document.getElementById(cbCtr).selectedIndex=-1;
      if (document.getElementById(cbCtr).selectedIndex<0)
        clearCtr(document.getElementById("hnr_"),"DIV");
      goToNeares(document.getElementById(txtCtr).value,cbCtr);
      document.getElementById(cbCtr).style.display='block';
    }
    else {
      aktKey=document.getElementById(txtCtr).value.toUpperCase();
      clearCtr(document.getElementById("hnr_"),"DIV");
      loadNewOptions(aktKey,cbCtr,"SELECT");
    }
  }
  else {
    goToNeares(document.getElementById(txtCtr).value,cbCtr);
  }
}
function loadLayers(ort,ecwView,panel) {
  var date=new Date();
  makePOSTRequest("layers.php","CLIENT="+client+"&ORT="+ort+"&ECWVIEW="+ecwView+"&PANEL="+panel+"&timestamp="+date.getTime(),"EVAL");
}

