// JavaScript Document
// JavaScript Document
var Ajax1 = false;
var Ajax2 = false;
var Ajax3 = false;
//var theLoader = new loader;

var s_f1LoadText = '<div align="center" style="text-align:center; padding-top:50px;"><img src="images/ajax-loader.gif" /><br><b>Heintar dáta...</b></div>';

var s_LoadText = '<div align="center" style="padding-bottom:5px;"><input type="button" value=" Listavísing " class="button" style="width:120px;" />&nbsp;<input type="button" value=" Myndavísing " class="button" style="width:120px;" /></div><div>&nbsp;</div><table class="carList" cellpadding="2" cellspacing="0" border="0" width="100%"><tr valign=""><td height="25" width="25" style="background-image:url(images/lineStart.gif); padding:0px;">&nbsp;</td><td colspan="5" style="color:#000000; font-weight:bold"><i>Heintar dáta</i></td></tr><tr valign=""><td height="25" width="25" style="background-image:url(images/line.gif); padding:0px;">&nbsp;</td><td colspan="5" style="color:#000000; font-weight:bold" align="center"><img src="images/loading2.gif" /></td></tr></table>'

function ajaxGet(theurl,theid,showLoader,postData){
	//alert(postData);
	if(theid=='f1Content'){s_LoadText = s_f1LoadText}
	if (Ajax1==false){
		if(showLoader!=false){document.getElementById(theid).innerHTML = s_LoadText;}
		Ajax1 = true;
		AjaxGet_1(theurl,theid,postData);
	}else if (Ajax2==false){
		if(showLoader!=false){document.getElementById(theid).innerHTML = s_LoadText;}
		Ajax2 = true;
		AjaxGet_2(theurl,theid,postData);
	}else if (Ajax3==false){
		if(showLoader!=false){document.getElementById(theid).innerHTML = s_LoadText;}
		Ajax3 = true;
		AjaxGet_3(theurl,theid,postData);
	}
}

function genURL(inurl){
	if (Right(inurl,4) == ".asp")
		{inurl=inurl + "?sid=" + Math.random()}
	else
		{inurl=inurl + "&sid=" + Math.random()}
	return inurl;
}

function sendRequest(object,theurl,postData){
	//alert(postData);
	if(isDefined(postData)){
		object.open("POST", genURL(theurl) , true)
		object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
		object.send(postData)
	}else{
		object.open("GET", genURL(theurl) , true)
		object.send(null)
	}
}

function AjaxGet_1(theurl,theid,postData){
	xmlHttp = GetXmlHttpObject(Function('if(xmlHttp.readyState==4 || xmlHttp.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp.responseText;loading(false,1);Ajax1=false;}'))
	sendRequest(xmlHttp,theurl,postData)
	//xmlHttp.open("GET", genURL(theurl) , true)
	//xmlHttp.send(null)
}

function AjaxGet_2(theurl,theid,postData){
	xmlHttp2 = GetXmlHttpObject(Function('if(xmlHttp2.readyState==4 || xmlHttp2.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp2.responseText;loading(false,2);Ajax2=false;}'))
	sendRequest(xmlHttp2,theurl,postData)
	//xmlHttp2.open("GET", genURL(theurl) , true)
	//xmlHttp2.send(null)
}

function AjaxGet_3(theurl,theid,postData){
	xmlHttp3 = GetXmlHttpObject(Function('if(xmlHttp3.readyState==4 || xmlHttp3.readyState==\'complete\'){document.getElementById(\'' + theid + '\').innerHTML = xmlHttp3.responseText;loading(false,3);Ajax3=false;}'))
	sendRequest(xmlHttp3,theurl,postData)
	//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){
	if(theAction==false){
		//theLoader.hide();
	}else{
		//theLoader.show('Loading page...',theAction);
	}
}