function runScripts(scripts) 
{
	if (!scripts) return false;
	for (var i = 0; i < scripts.length; i++) 
	{
		var thisScript = scripts[i];   
		var text; 
		if (thisScript.src) 
		{
			var newScript = document.createElement("script");
			newScript.type = thisScript.type;       
			newScript.language = thisScript.language;
			newScript.src = thisScript.src;             
			document.body.appendChild(newScript);   
		} 
		else if (text = (thisScript.text || thisScript.innerHTML)) 
		{
			var text = (""+text).replace(/^\s*<!\-\-/, '').replace(/\-\->\s*$/, '');
            eval(text);
		}
	}
}
	
function GetContent(httpRequest,resultId)
{
	if (httpRequest.readyState == 4) 
	{
		if (httpRequest.status == 200)
		{
			document.getElementById(resultId).innerHTML = httpRequest.responseText;
			runScripts(document.getElementById(resultId).getElementsByTagName('script'));
		}
	}
}

function GetElVal(_objId)
{
	var str = "";
	var obj=document.getElementById(_objId);
	for (i=0; i<obj.childNodes.length; i++) 
	{
		if (obj.childNodes[i].tagName == "INPUT") 
		{
			if (obj.childNodes[i].type == "text") 
				str += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
			if (obj.childNodes[i].type == "checkbox") 
			{
				if (obj.childNodes[i].checked)
					str += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
				else 
					str += obj.childNodes[i].name + "=&";
			}
			if (obj.childNodes[i].type == "radio") 
				if (obj.childNodes[i].checked)
					str += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
		}   
		if (obj.childNodes[i].tagName == "SELECT") 
		{
			var sel = obj.childNodes[i];
			str += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		}
		if (obj.childNodes[i].tagName == "TEXTAREA") 
		{
			var sel = obj.childNodes[i];
			str += sel.name + "=" + sel.value + "&";
		}
	}
	return str;
}
	
function CreateHttpRequest()
{
	var httpRequest;
	if (window.XMLHttpRequest) 
	{
		httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) 
			httpRequest.overrideMimeType('text/xml');
	} 
	else if (window.ActiveXObject) 
	{
		try {httpRequest = new ActiveXObject("Msxml2.XMLHTTP");} 
		catch (e) 
			{
			try{httpRequest = new ActiveXObject("Microsoft.XMLHTTP");} 
			catch (e) {}
			}
	}
	return httpRequest;
}

function Ajax()
{
	this.Get=function(_file, _resultId, _caption)
	{
		var httpRequest = CreateHttpRequest();

		if(!_resultId) _resultId='result_form';
		var c_ldng='<table class=ajax_loading><tr><td>';
		!_caption ? caption='Загрузка...' : caption=_caption;
		c_ldng+=caption+'&nbsp;</td></tr></table>';
		document.getElementById(_resultId).innerHTML = c_ldng;
		
		httpRequest.open('GET', sw_url+'get.php?'+_file,true);
		httpRequest.onreadystatechange = function(){GetContent(httpRequest,_resultId);};
		httpRequest.send('');
	}
	
	this.Post=function(_file,_resultId,_d)
	{
		var httpRequest = CreateHttpRequest();
		httpRequest.open("POST", _file, true);
		httpRequest.onreadystatechange = function(){GetContent(httpRequest,_resultId);};
		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpRequest.send(_d);
	}
}

function SendR(_file, _resultId, _caption) 
{
var req=new Ajax();
req.Get(_file, _resultId, _caption);
}

function PostR(_file,_resultId,_d) 
{
var req=new Ajax();
req.Post(_file,_resultId,_d);
}