// JavaScript Document
var Ajax1 = false;
var Ajax2 = false;
var Ajax3 = false;

function ajaxGet(theurl,theid){
	if (Ajax1==false){
		loading(theid,'1');
		Ajax1 = true;
		AjaxGet_1(theurl,theid);
	}else if (Ajax2==false){
		loading(theid,'2');
		Ajax2 = true;
		AjaxGet_2(theurl,theid);
	}else if (Ajax3==false){
		loading(theid,'3');
		Ajax3 = true;
		AjaxGet_3(theurl,theid);
	}
}
function test(testText){
	alert(testText);	
}
function genURL(inurl){
	if (Right(inurl,4) == ".asp")
		{inurl=inurl + "?sid=" + Math.random()}
	else
		{inurl=inurl + "&sid=" + Math.random()}
	return inurl;
}


function AjaxGet_1(theurl,theid){
	xmlHttp = GetXmlHttpObject(Function('if(xmlHttp.readyState==4 || xmlHttp.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp.responseText;loading(false,1);Ajax1=false;}'))
	xmlHttp.open("GET", genURL(theurl) , true)
	xmlHttp.send(null)
}

function AjaxGet_2(theurl,theid){
	xmlHttp2 = GetXmlHttpObject(Function('if(xmlHttp2.readyState==4 || xmlHttp2.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp2.responseText;loading(false,2);Ajax2=false;}'))
	xmlHttp2.open("GET", genURL(theurl) , true)
	xmlHttp2.send(null)
}

function AjaxGet_3(theurl,theid){
	xmlHttp3 = GetXmlHttpObject(Function('if(xmlHttp3.readyState==4 || xmlHttp3.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp3.responseText;loading(false,3);Ajax3=false;}'))
	xmlHttp3.open("GET", genURL(theurl) , true)
	xmlHttp3.send(null)
}

function GetXmlHttpObject(handler)
{
	var objXmlHttp = null
	if (navigator.userAgent.indexOf("Opera")>=0)
	{
		alert("Funktionalitetur ikki virkin.\n\nVirkar bert í Internet Explorer og Firefox") 
		return; 
		}
	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP"
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP"
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName)
			objXmlHttp.onreadystatechange=handler 
			return objXmlHttp
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled") 
			return 
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest()
		objXmlHttp.onload=handler
		objXmlHttp.onerror=handler 
		return objXmlHttp
	}
}
function loading(theAction,NR){
	/*
	var loader = document.getElementById('loader_' + NR);
	
	if (theAction==false){
		loader.style.display = 'none';
		
	}else{
		theID = document.getElementById(theAction);
		loader.style.left = findPosX(theID) + 'px';
		loader.style.top = findPosY(theID) + 'px';
		loader.style.width = theID.offsetWidth + 'px';
		loader.style.height = theID.offsetHeight + 'px';
		loader.style.display = 'block';
	}
	*/
}


function xmlhttpPost(strURL,theid) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,theid);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}


function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
