function createRequestObject() 
{
var xmlhttp;
xmlhttp = false;
// native XMLHttpRequest object like firefox and safari
if(window.ActiveXObject) {
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlhttp = false;
		}
	}
} else
if(window.XMLHttpRequest)
{
	try
	{
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		xmlhttp = false;
	}
// IE/Windows ActiveX version (why do people still use this browser?)
}

if(!xmlhttp)
	alert("Error loading XMLHTTP object");
return xmlhttp;
}

var Req = createRequestObject();
var arrurl;
var arrdest;
var arrimg;

var Ajaxx =
{
	//Default Settings 
	defoptions	:
	{
		defLink			:	window.location.protocol+"//"+window.location.host+"/",
		method			:	"GET",
		async			:	true,
		onComplete		:	0,
		eval			:	"",
		rand			:	1,
		addLink			:	1,
		data			:	""
	},
	options	:{},
	working	:	0,
	reqs	:	[],	
	go		:	function(Url, options)
	{
		if(Ajaxx.working)
		{
			this.reqs.push(new Array(Url, options));
			return;
		}		
		this.setOptions(options);
		Ajaxx.working	=	1;		
		if ((Ajaxx.options.img == 1) && (Ajaxx.options.destinationImg != "")) {
			var contentDiv = document.getElementById(Ajaxx.options.destinationImg);			
		    if (contentDiv != null && contentDiv != undefined) {
				contentDiv.innerHTML = '<img src = "img/wait.gif">';
		    }
		}
		this.setLink(Url);
		this.doRequest();
	},
	
	doRequest	:	function()
	{
		try {
		    Req.open(this.options.method.toUpperCase(), this.Link, this.options.async);		
		    var SendMe	=	null;
		    if(this.options.method.toLowerCase() == "post")
		    {
			    Req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');			
			    SendMe	=	this.options.data;
		    }

		    if(this.options.onComplete.length)
		    {
			    Req.onreadystatechange	=	this.options.onComplete;
		    }
		    else
		    {
			    Req.onreadystatechange	=	function ()
			    {
				    if(Req.readyState == 4)
					    {
							    Ajaxx.working	=	0;
							    if(Ajaxx.options.eval.length)	eval(Ajaxx.options.eval);
							    
							    if ((Ajaxx.options.img == 1) && (Ajaxx.options.destinationImg != "")) {
									var contentDiv = document.getElementById(Ajaxx.options.destinationImg);
								    if (contentDiv != null && contentDiv != undefined) {
									    contentDiv.innerHTML = "";
								    }
					    		}
							    
							    delete(Req.responseText);
							    delete(Req.responseXML);
							    if(Ajaxx.reqs.length) {
								    var Temp = Ajaxx.reqs.shift();
								    Ajaxx.go(Temp[0], Temp[1]);
							    }
					    }
			    }
		    }
		    Req.send(SendMe);
		    delete(this.options.Data);
		}
	    catch (err) {
//		    alert('test'+err);
    	}
	},
	
	setLink		:	function(Url)
	{
		var	NewUrl	=	"";		
		if(this.options.addLink)	NewUrl	+=	this.options.defLink;		
		NewUrl	+=	Url;		
		if(this.options.rand)
		{
			NewUrl	+= (NewUrl.indexOf("?") >0?"&":"?")+"myRand8778="+Math.random()*3000;
		}		
		this.Link	=	NewUrl;
	},
	
	setOptions	:	function(options)
	{
		this.options	=	new clone(this.defoptions);		
		if(typeof(options) != 'undefined')
		{
			var List	=	new Array("method", "img", "destinationImg", "async", "onComplete", "eval", "rand", "defLink", "addLink", "data");
			var Total	=	List.length;			
			for(x=0; x<Total; x++)
			{
				if(typeof(options[List[x]]) != 'undefined')
					{
						this.options[List[x]]	=	options[List[x]];
					}
			}
		}
	}
}

function clone(inObj)
{
    for (i in inObj) this[i] = inObj[i];
}

function SetDetsData(dest, data) {

	contentDiv = document.getElementById(dest);
	
	if (contentDiv != null && contentDiv != undefined) { 
		contentDiv.innerHTML = data;
	}
}

function showpages(arrurl,arrdest,arrimg)
{		
	for (j=0; j<arrurl.length; j++) {
	    if (arrurl[j]) {
	       if (arrimg[j]) {
	       contentDiv = document.getElementById(arrdest[j]);
            if (contentDiv!=null && contentDiv != undefined && arrimg[j]==1) {			
			    contentDiv.innerHTML="<img src='pics/wait.gif'>";		
	        }
	       } 
	       Ajaxx.go(arrurl[j], {method:"post", eval:"SetDetsData('"+arrdest[j]+"',Req.responseText);"});	 
	    }	
	}		
}
function showpages1(arrurl,arrdest,arrimg)
{		
	for (j=0; j<arrurl.length; j++) {
	    if (arrurl[j]) {
	       if (arrimg[j]) {
	       contentDiv = document.getElementById(arrdest[j]);
            if (contentDiv!=null && contentDiv!=undefined && arrimg[j]==1) {			
			    contentDiv.innerHTML="<img src='pics/wait.gif'>";		
	        }
	       } 
	       Ajaxx.go(arrurl[j], {method:"post", eval:"SetDetsData('"+arrdest[j]+"',Req.responseText);"});	 
	    }	
	}		
}
function showpagesfunc(arrurl,arrdest,arrimg,arrfunc)
{		
	for (j=0; j<arrurl.length; j++) {
	    if (arrurl[j]) {
	       if (arrimg[j]) {
	       contentDiv = document.getElementById(arrdest[j]);
            if (contentDiv!=null && contentDiv!=undefined && arrimg[j]==1) {			
			    contentDiv.innerHTML="<img src='pics/wait.gif'>";		
	        }
	       } 
	       Ajaxx.go(arrurl[j], {method:"post", eval:"SetDetsData('"+arrdest[j]+"',Req.responseText);"+arrfunc[j]});	 
	    }	
	}		
}
function ajaxgowithimg(url,dest,data1)
{
	contentDiv = document.getElementById(dest);
    if (contentDiv!=null && contentDiv!=undefined) {			
	    contentDiv.innerHTML="<img src='/i/admin/wait.gif'>";		
    }
	Ajaxx.go(url, {method:"post", data: data1,eval:"SetDetsData('"+dest+"',Req.responseText);"});	        	
}
