var trap = 0;

function doAjax()
{
	if (trap == 0)
	{
		trap=1;
		ajaxHandler.addRequest();
	}	
}

var ajaxHandler =
{
	
	url : "ERAS_CreateUser_formPartner.jsp",
	calls : new Array(),
		
	addRequest: function()
	{
		if (this.calls.length > 0)
		{
			if (this.calls[0].readyState != 4)
			{}
			else
			{
				//document.getElementById("plswaitBox").style.display="";
				this.calls[0] = this.callAjaxRequest();
			}
			
		}
		else
		{	
			//document.getElementById("plswaitBox").style.display="";
			
			this.calls[0] = this.callAjaxRequest();
		}
		
		
	},
	
	GetXmlHttpObject: function (handler)
	{ 
		var objXmlHttp=null;
		
		if (navigator.userAgent.indexOf("Opera")>=0)
		{
			alert("This example doesn't work in Opera") ;
			return ;
		}
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP";
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP";
			} 
			try
			{ 
				objXmlHttp=new ActiveXObject(strName);
				objXmlHttp.onreadystatechange=handler;
				
				return objXmlHttp;
			} 
			catch(e)
			{ 
				alert("Error. Scripting for ActiveX might be disabled") 
				return 
			} 
		} 
		if (navigator.userAgent.indexOf("Mozilla")>=0)
		{
			objXmlHttp=new XMLHttpRequest();
			objXmlHttp.onload=handler;
			objXmlHttp.onerror=handler;
			return objXmlHttp;
		}
	},
	 
	stateChanged: function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			var div_wait = document.getElementById('wait_adresse_partenaire');
			if (div_wait) {
				div_wait.style.display = 'none';
			}
			var scqobj = document.getElementById("adresse_partenaire");
			scqobj.innerHTML=xmlHttp.responseText;
			scqobj.style.display = 'block';
			trap=0;
			flagModify=0;
			document.body.style.cursor = 'default';
			document.onclick = null;
			document.getElementById('siret_link_upd').style.display = 'inline';
			if (document.getElementById('gold_link')) document.getElementById('gold_link').style.display = 'block';
		}
	},
	
	callAjaxRequest: function()
	{
		var data = "";
		
		 for(i=0; i<document.updateUserForm.elements.length; i++)
		 {
		 	theElm = document.updateUserForm.elements[i];
		 	theName = document.updateUserForm.elements[i].name;
		 	elmType = document.updateUserForm.elements[i].type;
		 	if (elmType == "radio" || elmType == "checkbox")
		 	{
				if (!theElm.checked)
					continue;
				theValue = theElm.value;
			}
			else if ( elmType == "select-multiple") 
			{
				for (opts = 0; opts < theElm.options.length; opts++)
				{
					if (theElm.options[opts].selected)
					{
						if (data == "")   		
		   					data = theName + "=" + theElm.options[opts].value;   
		   				else
		   					data += "&" + theName + "=" + theElm.options[opts].value;		   			 
					}	
				}
				continue;
			}
			
			else
			{
	   			theValue = theElm.value;
	   			
	   		}
			if (theValue != null)
			{
				if (data == "")   		
		   			data = theName + "=" + theValue;   
		   		else
		   			data += "&" + theName + "=" + theValue; 	
		   	}		
	   	 }
	   	 
		xmlHttp=this.GetXmlHttpObject(this.stateChanged);
		xmlHttp.open("POST", this.url , true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"); 
		xmlHttp.send(data);	
		
		return xmlHttp;
			
	}

};
