// http://kokeshnet.com/wordpress/?p=186

// here we define global variable
var ajaxdestination="";

function getdata(what,where)
 { // get data from source (what)
  try
   {
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  	new ActiveXObject("Microsoft.XMLHTTP");
   }
  catch (e)
   {
   	// do nothing
   }
  //document.getElementById(where).innerHTML ="<center><img src='/grafikk/loading_32x32.gif'></center>";
  // we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
 	ajaxdestination=where;
 	xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
 	xmlhttp.open("GET", what);
 	xmlhttp.send(null);
  return false;
 }

function triggered()
 { // put data returned by requested URL to selected DIV
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) 
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
 }



function postdata(url,params,destination)
 {
  try
   {
    http = window.XMLHttpRequest?new XMLHttpRequest():
  	new ActiveXObject("Microsoft.XMLHTTP");
   }
  catch (e)
   {
   	// do nothing
   }
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function()
	 {
		if(http.readyState == 4 && http.status == 200)
		 {
			document.getElementById(destination).innerHTML = http.responseText;
		}
	 }
	http.send(params);
 }
