var gaPositions= new Array;

function formToQueryString(xId){
	if ((typeof(xId) != 'object'))
		xId=document.getElementById(xId);
	if (xId && ('elements' in xId)){
		var sCGI='parsedByFTQS=1';
		for (i=0;i<xId.elements.length;i++){
			var oElement=xId.elements[i];
			if (oElement.type=="text")
				sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.value);
			if ((oElement.type=="checkbox")&&(oElement.checked))
				sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.value);
			if (oElement.type=="password")
				sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.value);
			if (oElement.type=="hidden")
				sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.value);
			if (oElement.type=="textarea")
				sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.value);
			if (oElement.options){
				if (oElement.selectedIndex >-1){
					sCGI+='&'+encodeURIComponent(oElement.name)+'='+encodeURIComponent(oElement.options[oElement.selectedIndex].value);
				}
			}
		}
		return sCGI;
	}
	return '';
}

function ajaxRequest(sUrl,sCGI,oCallBack){
	
	var oHttpRequest = null;
	var i=1;
	while ((i in gaPositions) && (false!=gaPositions[i]))
		i++;
	
	
	if (window.XMLHttpRequest){
		// W3C
		oHttpRequest = new XMLHttpRequest();
		if (oHttpRequest.overrideMimeType)
			oHttpRequest.overrideMimeType('text/xml');
	}else if (window.ActiveXObject){
		// IE
		try{
			oHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				oHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			}
		}
	}
	
	if (!oHttpRequest)
		return false;
		
	gaPositions[i]={oCallBackFunc:oCallBack,oRequest:oHttpRequest};
		
	oHttpRequest.onreadystatechange = new Function ("return ajaxResponse("+String(i)+")");
	oHttpRequest.open('POST', sUrl, true);
	oHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	oHttpRequest.send(sCGI);
	
}

function ajaxResponse(i,bLastStep) {

		if (!(i in gaPositions) || (false==gaPositions[i]))
			return false;
	
		var oHttpRequest=gaPositions[i].oRequest;
	
		if (!document.getElementById('ajaxStatus'+String(i))){
			oAjaxStatus=document.createElement('div');
			oAjaxStatus.setAttribute('id','ajaxStatus'+String(i));
			oAjaxStatus.style.height='14px';
			oAjaxStatus.style.width='260px';
			oAjaxStatus.style.padding='1px';
			oAjaxStatus.style.background='transparent';
			oAjaxStatus.style.fontFamily='"Lucida Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, Arial, Helvetica';
			oAjaxStatus.style.fontSize='10px';
			oAjaxStatus.style.position='absolute';
			oAjaxStatus.style.border='1px solid black';
			oAjaxStatus.style.color='black';
			oAjaxStatus.style.filter="alpha(opacity=60)";
			oAjaxStatus.style.opacity=0.6;
			oAjaxStatus.style.MozOpacity=0.6;
			oAjaxStatus.style.KHTMLOpacity=0.6;
			var oOff=getPageOffset();
			oAjaxStatus.style.left=(20+oOff.x)+'px';
			oAjaxStatus.style.top=(15*i+oOff.y)+'px';
			oAjaxStatus.style.zIndex='100';
			window.document.body.appendChild(oAjaxStatus);
		}
		sDivString=Number(oHttpRequest.readyState);
		switch (sDivString){
			case 0: sDivString='preparing'; break;
			case 1: sDivString='loading'; break;
			case 2: sDivString='loaded'; break;
			case 3: sDivString='interactive'; break;
			case 4: sDivString='completed'; break;
			default: sDivString='state '.oHttpRequest.readyState; break;
		}
		oAjaxStatus=document.getElementById('ajaxStatus'+String(i));
		oAjaxStatus.style.background='#ffffff';
		oAjaxStatus.style.backgroundImage='url("./../images.system/processing.gif")';
		oAjaxStatus.innerHTML=sDivString;
		if (bLastStep){
			
			window.document.body.removeChild(document.getElementById("ajaxStatus"+String(i)));
			gaPositions[i]=false;
			
		}else if ((oHttpRequest.readyState == 4) && (oHttpRequest.status == 200)){
		
			var oXMLDoc=null;
			if (!sW3C){
			
				var oXMLDoc = new ActiveXObject("Msxml2.DOMDocument");
				oXMLDoc.resolveExternals=false;
				oXMLDoc.validateOnParse=false;
				oXMLDoc.async=false;
				if (oXMLDoc.loadXML(oHttpRequest.responseText)){
					sDivString=oXMLDoc.selectSingleNode('response/status').firstChild.nodeValue;
				}
			}else{
					
				sDivString=oHttpRequest.responseXML.getElementsByTagName('status')[0].firstChild.nodeValue;
				oXMLDoc=oHttpRequest.responseXML;
			}

			oAjaxStatus.innerHTML=sDivString.substring(0,40);
			oAjaxStatus.style.backgroundImage='';
			oAjaxStatus.style.background='#aac2da';
			oAjaxStatus.style.border='1px solid #453545';
			
			if ((typeof gaPositions[i].oCallBackFunc) == 'function')
				gaPositions[i].oCallBackFunc(oXMLDoc);
				
			window.setTimeout('ajaxResponse('+String(i)+',true);',4000);

		}
	};
	