function createRequestObject() 
{
var xmlhttp;
xmlhttp = false;
// native XMLHttpRequest object like firefox and safari
if(window.XMLHttpRequest)
{
	try
	{
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		xmlhttp = false;
	}
// IE/Windows ActiveX version (why do people still use this browser?)
}
else if(window.ActiveXObject)
{
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlhttp = false;
		}
	}
}
if(!xmlhttp)
	alert("Error loading XMLHTTP object");
return xmlhttp;
}

var Req = createRequestObject();
var arrurl;
var arrdest;
var arrimg;

var myAjax =
{
	//Default Settings 
	defoptions	:
	{
		//���� �� ����, ���� ������ ������. (����������� ��������� ���� �����)
		defLink			:	window.location.protocol+"//"+window.location.host+"/",
		//����� POST/GET
		method			:	"GET",
		//��� ������� : true/false
		async			:	true,
		//������� ������� ����� ���������� ����� ���������� ������� (�� ������������ ����)
		onComplete		:	0,
		//��� ������� ����� �������� ����� ���������� ������� (eval("alert('123')")).
		eval			:	"",
		//��������� �� � ����� ����� ��������� ���������� � ��������� ������ (������������ ��� ���� ���� �� ���� ���� ��������)
		rand			:	1,
		//�������� �� ���� defLink � �������
		addLink			:	1,
		//� ������ POST ������� - ������ ������� ���� ��������!
		data			:	""
	},
	//���������� ������� �������� � ���� ��������� ������� �������
	options	:{},
	// ������ , ������ ��������� � ���������� 1/0
	working	:	0,
	//������� ��������.
	reqs	:	[],	
	go		:	function(Url, options)
	{
		if(myAjax.working)
		{
			this.reqs.push(new Array(Url, options));
			return;
		}		
		myAjax.working	=	1;
		this.setOptions(options);
		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)
					    {
							    myAjax.working	=	0;
							    if(myAjax.options.eval.length)	eval(myAjax.options.eval);
							    delete(Req.responseText);
							    delete(Req.responseXML);							
							    if(myAjax.reqs.length)
							    {
								    var Temp = myAjax.reqs.shift();
								    myAjax.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", "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;

if (dest=='frame1_body') {  					
	updateInfoForModule(1);    
}
	
if (dest=='frame2_body') {
	updateInfoForModule(2);		
}
}
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'>";		
	        }
	       } 
	       myAjax.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'>";		
	        }
	       } 
	       myAjax.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'>";		
	        }
	       } 
	       myAjax.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 style='left: 50%; margin-left: -28px; margin-top: -3px; top: 50%; position: relative;' src='/i/admin/wait.gif'>";
  }
  myAjax.go(url, {method:"post", data: data1,eval:"SetDetsData('"+dest+"',Req.responseText);"});
}
