function getObj(id)
{
	return document.getElementById(id);
}

function pasteContent(id, content)
{
	if (content == undefined) content = ""; 
	document.getElementById(id).innerHTML = content;
}

function createXMLHttp(){
	if(window.XMLHttpRequest){
		try{
			return new XMLHttpRequest();
		}catch(e){}
	}else
	if(window.ActiveXObject){
		try{
			return new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e){}
		try{
			return new ActiveXObject('Microsoft.XMLHTTP');
		}catch(e){}
	}
	return null;
}

function getRequestBodyBind(oForm){
	var aParams = new Array();
	for(var i=0;i<oForm.elements.length;i++){
		//var sParam = encodeURIComponent(oForm.elements[i].name);
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";
		//sParam += encodeURIComponent(oForm.elements[i].value);
		sParam += encodeURIComponent(oForm.elements[i].value);
		aParams.push(sParam);
	}
	return aParams.join("&");
}

var FCKeditorAPI_view;
function getRequestBody(oForm)
{
	
	var aParams = new Array();
	//getMceContentsSubmitAjax();
	for(var i=0;i<oForm.elements.length;i++){

		var sParam = encodeURIComponent(oForm.elements[i].name);
		//var sParam = oForm.elements[i].name;
		
		if(oForm.elements[i].type == "checkbox"){
			if(oForm.elements[i].checked == true){
				sParam += "=";
				sParam += encodeURIComponent(oForm.elements[i].value);
			}
		}else{
			if(oForm.elements[i].type == "radio"){
				if(oForm.elements[i].checked == true){
					sParam += "=";
					sParam += encodeURIComponent(oForm.elements[i].value);
				}
			}else{
				if(oForm.elements[i].type == "textarea"){

					var idtextarea = oForm.elements[i].id;
					var FCKeditorAPI_view;
					
					if (oForm.elements[i].className == "FCKEditor") {
					var valuetextarea = getFCKContent(idtextarea);
					if (valuetextarea == false) valuetextarea = getContent(idtextarea);
					} else {
						valuetextarea = oForm.elements[i].value;
					}
					//var valuetextarea = getMceContentsSubmitAjax(idtextarea);
						sParam += "=";
						//sParam += encodeURIComponent(oForm.elements[i].value);
						sParam += encodeURIComponent(valuetextarea);
				}else{
					if(oForm.elements[i].type == "select-one"){
						var select = _getSelect(oForm.elements[i]);

						//var valuetextarea = getMceContentsSubmitAjax(idtextarea);
							sParam += "=";
							//sParam += encodeURIComponent(oForm.elements[i].value);
							sParam += encodeURIComponent(select);
					} else {
						sParam += "=";
						sParam += encodeURIComponent(oForm.elements[i].value);
					}
				}
			}
		}
		aParams.push(sParam);
	}
	return aParams.join("&");
}

function testS(a)
{
	if(a == undefined) return false;
	else return true; 
}

function sendRequest(name, type){
	var oForm = document.getElementById(name);
	var sBody = getRequestBody(oForm);
	var oXmlHttp = createXMLHttp();

	if (!type) type = "POST";  

	oXmlHttp.open(type, oForm.action ,true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.setRequestHeader("Charset", "UTF-8");
	
	oXmlHttp.onreadystatechange = function(){
		if(oXmlHttp.readyState == 4){
			if(oXmlHttp.status == 200){
				saveResult(oXmlHttp.responseText, oXmlHttp.responseXML);
			}else{
				saveResult("error"+oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);
}

function saveResult(sText, sXml){
	return loadFunction(sText, sXml);
}

var Texts = "";
var RequestXml;
var Requiests;
var loadF = "";
function loadFunction(Text, Xml)
{
	Texts = Text;
	RequestXml = Xml;
	var actions = "var act = {metod: function() {" + loadF + "(Text)}};";
	eval(actions);
	
	act["metod"]();
}

var loadF = "";
function submitForm_ajax(nameForm, nameFunction, type)
{
	loadF = nameFunction;
	sendRequest(nameForm, type);
}

function getVar(name)
{
	document.getElementById("getAjax").innerHTML = Texts;
	if(document.getElementById(name)) return document.getElementById(name).innerHTML;
	else return "";
}



function sendRequestBind(name){
	var oFormBind = document.getElementById(name);
	var sBody = getRequestBody(oFormBind);
	var oXmlHttp = createXMLHttp();

	oXmlHttp.open("POST", oFormBind.action ,true);
	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset UTF-8");
	//oXmlHttp.setRequestHeader("Charset", "UTF-8");
	
	oXmlHttp.onreadystatechange = function(){
		if(oXmlHttp.readyState == 4){
			if(oXmlHttp.status == 200){
				 Requiests = oXmlHttp;
				saveResultBind(oXmlHttp.responseText, oXmlHttp.responseXML);
			}else{
				saveResultBind(oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);
}

function saveResultBind(sText, Xml){
	RequestXml = Xml;
	return loadFunctionBind(sText);
}

var TextsBind = "";
var loadFBind = "";
function loadFunctionBind(Text)
{
	TextsBind = Text;
	var actions = "var act = {metod: function() {" + loadFBind + "(Text)}};";
	eval(actions);
	
	act["metod"]();
}

function submitFormBind_ajax(nameForm, nameFunction)
{
	loadFBind = nameFunction;
	sendRequestBind(nameForm);
}
