function submitForm(formRef, url)
{
	var submitForm = new formSubmit();
	submitForm.setFormRef(formRef);
	submitForm.setUrl(url);
	return submitForm.submit();
}


/**
* @constructor
*/

formSubmit = function()
{
	var formRef;
	var url;
	var send;
	
	this.url = '';
	this.formRef = null;
	this.send = '';

}

formSubmit.prototype = {
	// {{{ setFormRef(formRef)
    /**
     *	Set the reference to the form
     * 	
     *
     * @public	
     */		
	setFormRef : function(formRef)
	{
		this.formRef = formRef;
		
	}
	// }}}	
	,
	// {{{ setUrl(url)
    /**
     *	Set the url where to post the data
     * 	
     *
     * @public	
     */		
	setUrl : function(url)
	{
		this.url = url;
		
	}
	// }}}	
	,
	// {{{ submit()
    /**
     *	Submit the form
     * 	
     *
     * @public	
     */		
	submit : function()
	{
			if (typeof this.formRef == "string")
			{
				this.send = this.formRef;
			}
			else
			{
				var els = this.__getValuesAsArray();
				for(var prop in els)
				{
					if(this.send != '') this.send += '&';
					if(this.__isArray(els[prop]))
					{
						for(var no = 0; no < els[prop].length; no++)
						{
							var name = prop + '[' + no + ']';
							if(prop.indexOf('[') >= 0)
							{ // The name of the form field is already indicating an array
								name = prop.replace('[','[' + no);
							}
							this.send += name + "=" + els[prop][no];
						}
					}
					else
					{
						this.send += prop + "=" + els[prop];
					}
				}
			}
			var objHTTP = this.__createAJAX();
			var strResult = null;
			if(objHTTP)
			{
				objHTTP.open('POST',this.url,false);
				objHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
				//.setRequestHeader("Content-Type", "text/plain");
				objHTTP.send(this.send + "&submitRndval=" + this.__getRandom());
				strResult = this.__IE_response(objHTTP.responseText);
				//strResult = strResult.replace(/[^a-zA-ZäüöÄÖÜß 0-9_-]+/g,'').basicTrim();
			}
			return strResult;

	}
	// }}}		
	,
	// {{{ __getValuesAsArray()
    /**
     *	Get the values of the form as an array
     * 	
     *
     * @private	
     */		
	__getValuesAsArray : function()
	{
			var retArray = new Object();
			var formRef = this.formRef;
			var els = formRef.elements;
			for(var no = 0; no < els.length; no++)
			{
				if(els[no].disabled) continue;
				var tag = els[no].tagName.toLowerCase();
				switch(tag)
				{
					case "input":
						var type = els[no].type.toLowerCase();
						if(!type) type='text';
						switch(type)
						{
							case "text":
							case "image":
							case "hidden":
							case "password":
								retArray[els[no].name] = els[no].value;
								break;
							case "checkbox":
								var boxes = this.__getFamily(els[no]);
								if(boxes.length > 1)
								{
									retArray[els[no].name] = new Array();
									for(var no2 = 0; no2 < boxes.length; no2++)
									{
										if(boxes[no2].checked)
										{
											var index = retArray[els[no].name].length;
											retArray[els[no].name][index] = boxes[no2].value;
										}
									}
								}
								else
								{
									if(els[no].checked)retArray[els[no].name] = els[no].value;
								}
								break;
							case "radio":
								if(els[no].checked) retArray[els[no].name] = els[no].value;
								break;
						}
						break;
					case "select":
						var string = '';
						var mult = els[no].getAttribute('multiple');
						if(mult || mult==='')
						{
							retArray[els[no].name] = new Array();
							for(var no2 = 0; no2 < els[no].options.length; no2++)
							{
								var index = retArray[els[no].name].length;
								if(els[no].options[no2].selected)retArray[els[no].name][index] = els[no].options[no2].value;
							}
						}
						else
						{
							retArray[els[no].name] = els[no].options[els[no].selectedIndex].value;
						}
						break;
					case "textarea":
						retArray[els[no].name] = els[no].value;
						break;
				}
			}
			return retArray;
	}
	// }}}
	,
	// {{{ __isArray(element)
    /**
     *	Tell if element is array or not
     * 	
     *
     * @private	
     */		
	__isArray : function(element)
	{
			if(element.constructor.toString().indexOf("Array") != -1) return true;
			return false;

	}
	// }}}
	,
	// {{{ __getFamily(element)
    /**
     *	Return the family of element
     * 	
     *
     * @private	
     */		
	__getFamily : function(element)
	{
			var formRef = this.formRef;
			var els = formRef.elements;
			var retArray = new Array();
			for(var no = 0; no < els.length; no++)
			{
				if(els[no].name == element.name) retArray[retArray.length] = els[no];
			}
			return retArray;

	}
	// }}}
	,
	// {{{ __createAJAX()
    /**
     *	Create an AJAX reference
     * 	
     *
     * @private	
     */		
	__createAJAX : function()
	{
			var xmlhttp;
			try
			{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e1)
			{
				try
				{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e2)
				{
					xmlhttp = null;
				}
			}
			if(!xmlhttp)
			{
				if (typeof XMLHttpRequest != "undefined")
				{
					xmlhttp = new XMLHttpRequest();
				}
			}

			return xmlhttp;

	}
	// }}}
	,
	// {{{ __IE_response(responseText)
    /**
     *	Removes the first two characters if IE is used
     * 	
     *
     * @private	
     */		
	__IE_response : function(responseText)
	{
			if(responseText.charCodeAt(0) == 65279 && responseText.charCodeAt(1) == 65279) responseText = responseText.slice(2);
			return responseText;

	}
	// }}}
	,
	// {{{ __insertContent()
    /**
     *	Insert content into the content div
     * 	
     *
     * @private	
     */	
    __getRandom : function()
    {
			var min = 10000;
			var max = 99999;
			var r = parseInt( Math.random() * ( max + 1 ) );
			return( r + min <= max ? r + min : r );
    }		
}
