	/*
	1.1: Möglichkeit Files upzuloaden und danach mittels der Index.php Datei ein _FILES Objekt bereitzustellen.
	1.2: Umstellung auf eine KLasse
	*/
	
var oAjax = new qxcAjax ();
oAjax.index();
//<+1.2: Rückwärtskompatibel
function qxcAjaxSet(dataSource,retFunc,methode,oForm)
{
	
	oAjax.set(dataSource,retFunc,methode,oForm);
}
//+>

//<+1.2
function qxcAjax () 
{		
	
	this.index = function ()
	{
		this.XMLHttpRequestObject = false;
		
		if(window.XMLHttpRequest)
		{
			this.XMLHttpRequestObject = new XMLHttpRequest();
		} 
		else if(window.ActiveXObject)
		{
			this.XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	this.onreadystatechange = function()
	{
		
		if(oAjax.XMLHttpRequestObject.readyState == 4)
		{
			if(oAjax.XMLHttpRequestObject.status == 200)
			{
				
				
				eval(oAjax.retFunc+"(oAjax.XMLHttpRequestObject.responseText)");
			}
			else
			{
				alert(oAjax.XMLHttpRequestObject.status);
				
			}
		}
	}

	
	this.set = function (dataSource,retFunc,methode,oForm)
	{
	
		this.retFunc=retFunc;
		if (typeof methode == "undefined") 
		{
			methode = "GET";
		}
     

		
		if(this.XMLHttpRequestObject)
		{
			
			this.XMLHttpRequestObject.open(methode, dataSource);
			
			this.XMLHttpRequestObject.onreadystatechange = this.onreadystatechange;
			
			if(methode=="GET")
			{
				this.XMLHttpRequestObject.send(null);
			}
			else
			{
				
				//POST Parameter
				
				//<+1.1
				var isFileUpload=false;
				//+>
				this.postarg="";
				
				for(i=0;i<oForm.elements.length;i++)
				{
					if((oForm.elements[i].type!="radio" && oForm.elements[i].type!="checkbox") || oForm.elements[i].checked)
					{						
						this.postarg+=oForm.elements[i].name+"="+oForm.elements[i].value+"&";
					}
					
					//<+1.1
					if(oForm.elements[i].type=="file")
					{
						isFileUpload=true;
					}
					//+>

				}
				
				//<+1.1
				if(isFileUpload)
				{
					
					
					//IFrame erzeugen
					/*var oIFrame = document.createElement("iFrame");
					oIFrame.src="";
					//oIFrame.style.visibility="hidden";
					oIFrame.name="qxcAjaxFileUploadArea";
					oIFrame.id="qxcAjaxFileUploadArea";
					oIFrame.style.width="500px";
					oIFrame.style.height="500px";
					oIFrame.style.border="1px solid #ff0000";
					
					//IFrame einhängen
					document.getElementsByTagName("body")[0].appendChild(oIFrame);
					*/
					
					
					
					
					//Formular action anpassen
					var sAction=oForm.action;
					oForm.action="fileUpload.php";
					
					//Formular enctype anpassen
					var sEncType=oForm.enctype;
					oForm.enctype="multipart/form-data";
					
					//Formular target anpassen
					var sTarget=oForm.target;
					oForm.target="qxcAjaxFileUploadArea";
					
					
					
					//Formular abschicken
					
					oForm.submit();
					
					
					
					//Formular wieder zurücksetzen
					oForm.action=sAction;
					oForm.enctype=sEncType;
					oForm.target=sTarget;
					
					
				}
				//+>
				else
				{
					this.goPost(false)
				}
				
			}
		}
		
	}	
	this.goPost = function(file)
	{
		if(!file==false)
		{
			//Element POST["_FILES"] schreiben.
			for(i=0;i<file.length;i++)
			{
				this.postarg+="_FILES["+file[i]['key']+"][name]="+file[i]['name']+"&";
				this.postarg+="_FILES["+file[i]['key']+"][type]="+file[i]['type']+"&";
				this.postarg+="_FILES["+file[i]['key']+"][tmp_name]="+file[i]['tmp_name']+"&";
				this.postarg+="_FILES["+file[i]['key']+"][error]="+file[i]['error']+"&";
				this.postarg+="_FILES["+file[i]['key']+"][size]="+file[i]['size']+"&";
			}
			
			
			
			//IFrame löschen
			var oIFrame=document.getElementById("qxcAjaxFileUploadArea");
			document.getElementsByTagName("body")[0].removeChild(oIFrame);
		}
		
		
		//Send the proper header information along with the request
		this.XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.XMLHttpRequestObject.setRequestHeader("Content-length", this.postarg.length);
		this.XMLHttpRequestObject.setRequestHeader("Connection", "close");
		this.XMLHttpRequestObject.send(this.postarg);
		
	}
	
}
//+>
