sendFormAjax = function(){
	this.ActionUrl 		= "";
	this.ActionMethod	= "POST";
	this.ActionForm 	= null;
	this.FormBody		= "";
	this.XmlHttp		= null;
	this.userData		= new Object();
	this.fEventHandle	= null;
	this.oEventHandle	= null;
	return this;
}

sendFormAjax.prototype = {
	createXmlHttp : function(){
		var aObjAjax = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLH TTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
		for(var i=0; this.XmlHttp == null && i<aObjAjax.length ; i++){
			try{ this.XmlHttp = new ActiveXObject(aObjAjax[i]); }
			catch(e) { this.XmlHttp = null; }
		}
	
		if(this.XmlHttp == null && typeof XMLHttpRequest!='undefined') {
			this.XmlHttp = new XMLHttpRequest();
		}
		return this.XmlHttp;
	},  //createXmlHttp()	
	
	FormSubmitToAjax : function(){
		if (this.XmlHttp == null) { this.createXmlHttp(); }
		if(this.XmlHttp == null){ return false; }

		this.XmlHttp.open(this.ActionMethod, (this.ActionUrl != "" ? this.ActionUrl : this.getPagePhpName()), true);
		this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		if (this.ActionForm != null) { this.FormBody +=this.formData2QueryString() }
		
		if(sendFormAjax.persistentParams){
			this.FormBody += '&' + sendFormAjax.persistentParams.join('&')
		}
		
		this.XmlHttp.send(this.FormBody);
		
		if (this.oEventHandle != null) {
			this.XmlHttp.onreadystatechange = this.oEventHandle[this.fEventHandle](this);
		}
		else {
			this.XmlHttp.onreadystatechange = this.fEventHandle(this);
		}
		
	},  //FormSubmit

	setActionUrl : function(ActionUrl) { this.ActionUrl = ActionUrl; },	
	getActionUrl : function() { return this.ActionUrl; },	
	setActionMethod : function(ActionMethod){ this.ActionMethod = ActionMethod; },
	getActionMethod : function(){ return this.ActionMethod; },	
	setActionForm : function(ActionForm){ this.ActionForm = ActionForm; },	
	getActionForm : function(){ return this.ActionForm; },	
	setFormBody : function(FormBody){ this.FormBody = FormBody; },	
	getFormBody : function(){ return this.FormBody; },
	setPersistentParam : function(param,value){
		if(!sendFormAjax.persistentParams) sendFormAjax.persistentParams = [];
		sendFormAjax.persistentParams.push(param + '=' + value);
	},
	
	formData2QueryString : function() {
		if (this.ActionForm == null) { return ""; }
		var strSubmitContent = '';
		var formElem;
		var strLastElemName = '';
		
		for (var i = 0; i < this.ActionForm.elements.length; i++) {		
			formElem = this.ActionForm.elements[i];
			if (formElem.disabled != true) {
				switch (formElem.type) {			
					case 'text': // Text fields, hidden form elements
					case 'hidden':
					case 'password':
					case 'textarea':
					case 'select-one':
						strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
						break;
					case 'select-multiple': 
						for (var count = 0; count < formElem.length; count++) { 
							if ( formElem[count].selected ) { 
								strSubmitContent += formElem.name + '=' + encodeURIComponent(formElem[count].value) + '&'; 
							} 
						}
					case 'radio': // Radio buttons
						if (formElem.checked) {
							strSubmitContent += formElem.name + '=' + escape(formElem.value) + '&'
						}
						break;			
					case 'checkbox': // Checkboxes
						if (formElem.checked) {
							// Continuing multiple, same-name checkboxes
							if (formElem.name == strLastElemName) {
								// Strip of end ampersand if there is one
								if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
									strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
								}
								// Append value as comma-delimited string
								strSubmitContent += ',' + escape(formElem.value);
							}
							else {
								strSubmitContent += formElem.name + '=' + escape(formElem.value);
							}
							strSubmitContent += '&';
							strLastElemName = formElem.name;
						}
						break;				
				}
			}
		}
		// Remove trailing separator
		strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
		return strSubmitContent;
	},  //formData2QueryString

	isInputFile : function(thisForm){		
		for (var i = 0; i < thisForm.elements.length; i++) {		
			formElem = thisForm.elements[i];
			if  (formElem.type == "file") {
				return true;
			}			
		}
		return false;
	},  //isInputFile
	
	getPagePhpName : function(){
		aPage 		= document.location.href.split("/");
		aPageTmp 	= aPage[aPage.length-1].split(".");
		return aPageTmp[0] + "." + aPageTmp[1].substr(0, 3);
	}
}