/*********************************************************************************************
**
* 					C L A S S  A J A X
**
*********************************************************************************************/
function CAJAX() {
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Private vars
	///////////////////////////////////////////////////////////////////////////////////////////////
	this.m_oXMLHttp = null;
	this.m_sPostRequestString = null;
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return object XMLHttpRequest
	* @param void
	* @desc Returns the XMLHttpRequest object
	*/
	this.get = function() {
		return this.m_oXMLHttp;
	}
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return void
	* @param string sMethod
	* @param string sURL
	* @param bool bAsynchronous
	* @desc Opens the given url
	*/
	this.OpenURL = function(sMethod, sURL, bAsynchronous) {
		this.m_oXMLHttp.open(sMethod, sURL, bAsynchronous);
	}
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return void
	* @param string sRequest (optional)
	* @desc Sends the request to the server
	*/
	this.SendRequest = function(sRequest) {
		if (typeof(sRequest) == "undefined") sRequest = null;
		this.m_oXMLHttp.send(sRequest);
	}
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return void
	* @param string sRequest (optional)
	* @desc Sends the request to the server
	*/
	this.SendPostRequest = function(sRequest) {
		if (typeof(sRequest) == "undefined") sRequest = this.m_sPostRequestString;
		this.m_oXMLHttp.send(sRequest);
	}
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return string
	* @param string/object oForm
	* @param bool bGetDisabled
	* @param string sPrefix
	* @desc Builds a query string from the elements of a form object
	*/
	this.GetFormValues = function(oForm, bGetDisabled, sPrefix) {
		arParams = new Array();
		if (typeof(oForm) == "string") oForm = document.getElementById(oForm);
		if (typeof(bGetDisabled) == "undefined") bGetDisabled = false;
		if (typeof(sPrefix) == "undefined") sPrefix = "";
		if (oForm && oForm.tagName == 'FORM') {
			var arFormElements = oForm.elements;
			for(i=0; i < arFormElements.length; i++) {
				if (!arFormElements[i].name) continue;
				if (arFormElements[i].name.substring(0, sPrefix.length) != sPrefix) continue;
				if (arFormElements[i].type && (arFormElements[i].type == 'radio' || arFormElements[i].type == 'checkbox') && arFormElements[i].checked == false) continue;
				if (arFormElements[i].disabled && arFormElements[i].disabled == true && bGetDisabled == false) continue;
				sName = arFormElements[i].name;
				if (sName) {
					var sParam = encodeURIComponent(sName);
					if(arFormElements[i].type=='select-multiple') {
						for (j = 0; j < arFormElements[i].length; j++) {
							if (arFormElements[i].options[j].selected == true)
								sParam += "=";
								sParam += encodeURIComponent(arFormElements[i].options[j].value);
						}
					} else {
						sParam += "=";
						sParam += encodeURIComponent(arFormElements[i].value);
					}
					arParams.push(sParam);
				}

			}
		}
		return arParams.join("&");
	}
	//////////////////////////////////////////////////////////////////////////////////
	/**
	* @return void
	* @param string sFileName
	* @desc Dinamically includes JavaScript file
	*/
	this.Include = function(sFileName) {
		var oHead = document.getElementsByTagName('head');
		var oScript = document.createElement('script');
		oScript.type = 'text/javascript';
		oScript.src = sFileName;
		oHead[0].appendChild(objScript);
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	if (typeof XMLHttpRequest != "undefined") {
		this.m_oXMLHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		var arVersions = 	["MSXML2.XMLHttp.5.0",
					"MSXML2.XMLHttp.4.0",
					"MSXML2.XMLHttp.3.0",
					"MSXML2.XMLHttp",
					"Microsoft.XMLHttp"
					];
				for (var i = 0; i < arVersions.length; i++) {
					try {
						this.m_oXMLHttp = new ActiveXObject(arVersions[i]);
					} catch (oError) {
					//Do nothing
					}
				}
	}
}