/* ajax function */

function postRequest(strURL,id,action) {
  var xmlHttp;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    var xmlHttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { // IE
    var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlHttp.open('POST', strURL, true);
  xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=ISO-8859-1');
  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
      updatepage(xmlHttp.responseText,id,action);
    }
  }
  xmlHttp.send('strURL' + encodeURIComponent('ä'));
}
function updatepage(str,id,action){
 	if (action == "add"){
    document.getElementById(id).innerHTML +=str;
 	}
 	else if (action == "replace"){
 		document.getElementById(id).innerHTML =str;
 	}
}
function eventfetch(url,id,action){
 	postRequest(url,id,action);
}
function timefetch(url,id,action,milliseconds) {
 	eventfetch(url,id,action)
  setTimeout(function () { timefetch(url,id,action,milliseconds); },milliseconds);
}
//generic fetch function, accepts 5 parameters (first 4 mandatory).
//url = script to access on the server
//id = html id (for example of a div, a form field etc.., works with all tags which accept an id)
//action = add or replace, add adds up content at the end of the original content in the id element, replace replaces the complete content in the id element
//base = time or event, time based means script will autoexecute itself every amount of milliseconds specified via the 5th (millisecdons) parameter, event based means you are calling the funtion with something like onclick, onchange, onmouseover etc....
//milliseconds = time in milliseconds till the script should autoexecute itself again (only needed when base==time)
function fetch(url,id,action,base,milliseconds){
 	if(base == "event"){
 		eventfetch(url,id,action);
 	}
 	else if(base == "time"){
 		timefetch(url,id,action,milliseconds);
 	}
}
//search & overlay functions
function search(table,column,identifier,search,searchtemp,id,action){
  searchrequest="../asearch.php?table="+table+"&column="+column+"&identifier="+identifier+"&search="+search+"&searchtemp="+searchtemp+"&div="+id;
  eventfetch(searchrequest,id,action);
}
function getposOffset(overlay, offsettype){
  var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
  var parentEl=overlay.offsetParent;
  while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}
function overlay(curobj, subobjstr, opt_position){
  if (document.getElementById){
    var subobj=document.getElementById(subobjstr)
    subobj.style.display="block"
    var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0)
    var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
    subobj.style.left=xpos+"px"
    subobj.style.top=(ypos+15)+"px"
    return false
  }
  else
    return true
}
function overlayclose(subobj){
	document.getElementById(subobj).style.display="none"
}