var xmlHttp;
var dstAjax;
var AjaxDoneFunction = new Function("");


var UpdateAjaxTimerID=null;

function AjaxStart(AjaxUrl,AjaxDst) {
	if(UpdateAjaxTimerID!=null) {
		clearTimeout(UpdateAjaxTimerID);
		}
	UpdateAjaxTimerID=setTimeout("DelayAjaxStart('" + AjaxUrl + "','" + AjaxDst + "');", 500 );
	AjaxDoneFunction = new Function("");
	}

function DelayAjaxStart(AjaxUrl,AjaxDst) {
	UpdateAjaxTimerID=null;
//alert("AjaxStart(" + AjaxUrl + "," + AjaxDst + ")");
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request");
return;
}

xmlHttp.onreadystatechange=AjaxstateChanged;
dstAjax=document.getElementById(AjaxDst);
xmlHttp.open("GET",AjaxUrl,true);
xmlHttp.send(null);

//dstAjax.innerHTML = "<p>Kontakta servern för lösningen</p>";
MyInnerHTML(dstAjax, "<p>Contacting server</p>");
}

function GetXmlHttpObject() {
//alert("GetXmlHttpObject()");
var objXMLHttp=null;
if (window.XMLHttpRequest) {
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject) {
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}

function AjaxstateChanged() {
//alert("AjaxstateChanged()");
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//dstAjax.innerHTML=xmlHttp.responseText;
MyInnerHTML(dstAjax, xmlHttp.responseText);
AjaxDoneFunction();
}
else {
//dstAjax.innerHTML = "<p>Kontakta servern</p>";
MyInnerHTML(dstAjax, "<p>Contacting server</p>");
}
}

function MyInnerHTML(dstid,htmlcode){
//alert("MyInnerHTML(" + dstid + "," + htmlcode + ")");
if (document.createRange) {
myrange = document.createRange();
myrange.setStartBefore(dstid);
myhtmlcode = myrange.createContextualFragment(htmlcode);
while (dstid.hasChildNodes()) dstid.removeChild(dstid.lastChild);
dstid.appendChild(myhtmlcode);
}
else {
	dstid.innerHTML=htmlcode;
}
}
function showelement(idnamne) {
document.getElementById(idnamne).style.visibility="visible";
}
function hideelement(idnamne) {
document.getElementById(idnamne).style.visibility="hidden";
}