// JavaScript Documentvar xmlHttp
function showInfoPays(page,str,divid,minimum) {	
	
	divname_pays=divid;	
	xmlHttp_pays=GetXmlHttpObject()
	if (xmlHttp_pays==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	// appel pas la page si la chaine est trop petite

	if (str.length >= minimum) {
		var url=page;
		
		url = url + "?" + str;
		
		url = url + "&sid=" + Math.random();
		xmlHttp_pays.onreadystatechange=stateChanged_pays;
		xmlHttp_pays.open("GET",url,true);
		xmlHttp_pays.send(null);
	}
} 

function showHint(page,str,divid,minimum) {	
	divnameX=divid;

	
	xmlHttpX=GetXmlHttpObject()
	if (xmlHttpX==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (str.length >= minimum) {
		
		var url=page;
		str=str + "&sid=" + Math.random();
		xmlHttpX.onreadystatechange=stateChangedshowHint;
		// si je met le parametre assychrone a false
		// ca ne fonctionne pas avec FFox
		str = str.replace(/ /g,"(space)")
		str = str.replace(/\n/g,"(retour)")
		xmlHttpX.open("POST",url,true);
	
		//xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xmlHttpX.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttpX.setRequestHeader("Content-length",str.length);
		xmlHttpX.send(str);
	}
} 
function showHintOLD(page,str,divid,minimum) {
	
	
	divname=divid;
	if (str.length==0) { 
		document.getElementById(divname).innerHTML="";
		return;
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (str.length >= minimum) {
		obj = document.getElementById(divname)
		obj.style.display="";
		var url=page;
		//str= str.replace(/&/g,"XXXX")
		//str= str.replace(/=/g,"YYYY")

		//str = escape(str)
		
		//str= str.replace(/XXXX/g,"&")
		//str= str.replace(/YYYY/g,"=")
		url=url + "?" + str;
		//url=url + "?" + escape(str);
		url=url + "&sid=" + Math.random();
		
		xmlHttp.onreadystatechange=stateChanged;
		
		
		//xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.open("GET", url,true);
		xmlHttp.send(null);



	}
} 

/****************************
fonctionne bien mais enleve tous les espace
----------
*/
function ajaxSpace(page,str,divid,minimum) {
	
	divname=divid;
	if (str.length==0) { 
		document.getElementById(divname).innerHTML="";
		return;
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (str.length >= minimum) {
		
		// verifie si existe avant
		if (document.getElementById(divname)){
			obj = document.getElementById(divname)
			obj.style.display="";
		}
		var url=page;
		str=str + "&sid=" + Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		// si je met le parametre assychrone a false
		// ca ne fonctionne pas avec FFox
		str = str.replace(/ /g,"(space)")
		str = str.replace(/\n/g,"(retour)")
		xmlHttp.open("POST",url,true);
	
		//xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.setRequestHeader("Content-length",str.length);
		xmlHttp.send(str);

	}
} 

function ajaxHTTP(page,str,divid,minimum) {
	
	divname=divid;
	if (str.length==0) { 
		document.getElementById(divname).innerHTML="";
		return;
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (str.length >= minimum) {
		
		// verifie si existe avant
		if (document.getElementById(divname)){
			obj = document.getElementById(divname)
			obj.style.display="";
		}
		var url=page;
		str=str + "&sid=" + Math.random();
		
		xmlHttp.onreadystatechange=stateChangedHTTP;
		
		// si je met le parametre assychrone a false
		// ca ne fonctionne pas avec FFox
		str = str.replace(/ /g,"(space)")
		str = str.replace(/\n/g,"(retour)")
		xmlHttp.open("POST",url,true);
	
		//xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.setRequestHeader("Content-length",str.length);
		xmlHttp.send(str);
	

	}
} 
function stateChangedHTTP() {
	
	if (xmlHttp.readyState==4) {
		//alert("OKOKOK")
	}
}

function stateChangedshowHint() {
	
	if (xmlHttpX.readyState==4) {
		var reponseX = xmlHttpX.responseText
	
		if (reponseX=="FERMER-SESSION") {
				// 2010-09-29 enlever www.carrefour-capital.com
				window.location="/";
		}
		if (reponseX=="REFRESH") {
				window.location.reload();
		}		
		document.getElementById(divnameX).innerHTML=reponseX
	}
}

function stateChanged() {
	
	if (xmlHttp.readyState==4) {
		var reponse = xmlHttp.responseText
		// si le nom div est recharger_cette_page
		// la page doit être refraichie
		if (divname=="recharger_cette_page") {
			window.location.reload();
			}
		else
			{
			if (xmlHttp.responseText=="REFRESH") {
				window.location.reload();
			}
			else if (xmlHttp.responseText=="FERMER SESSION") {
				// 2010-09-29 enlever www.carrefour-capital.com
				window.location="/";
			}
			else if ( reponse.indexOf("ACCUEIL")>=0 )
			{
				// cherche le carrefour
				cc = reponse.replace("ACCUEIL;","");
				// 2010-09-29 enlever www.carrefour-capital.com
				window.location="/" + cc;
	
			}
			else
			{
				// verifie si existe avant
			
				if (document.getElementById(divname)){
					document.getElementById(divname).innerHTML=xmlHttp.responseText;	}
			}
		}
	}	
}

function ajaxSpaceValid(page,str,divid,minimum) {
	
	divname=divid;
	if (str.length==0) { 
		document.getElementById(divname).innerHTML="";
		return;
	}
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (str.length >= minimum) {
		
		// verifie si existe avant
		if (document.getElementById(divname)){
			obj = document.getElementById(divname)
			obj.style.display="";
		}
		var url=page;
		str=str + "&sid=" + Math.random();
		xmlHttp.onreadystatechange=stateChangedValid;
		// si je met le parametre assychrone a false
		// ca ne fonctionne pas avec FFox
		str = str.replace(/ /g,"(space)")
		str = str.replace(/\n/g,"(retour)")
		xmlHttp.open("POST",url,true);
	
		//xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
		xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
		xmlHttp.setRequestHeader("Content-length",str.length);
		xmlHttp.send(str);

	}
} 

function stateChangedValid() {
	
	if (xmlHttp.readyState==4) {
		
		var reponse = xmlHttp.responseText
		// si le nom div est recharger_cette_page
		// la page doit être refraichie
		if (divname=="recharger_cette_page") {
			window.location.reload();
			}
		else
			{
			if (xmlHttp.responseText=="REFRESH") {
				window.location.reload();
			}
			else if ( reponse.indexOf("ACCUEIL")>=0 )
			{
				// cherche le carrefour
				cc = reponse.replace("ACCUEIL;","");
				// 2010-09-29 enlever www.carrefour-capital.com
				window.location="/" + cc;
	
			}
			else
			{
				// verifie si existe avant
				//if (document.getElementById(divname))
				//{
					inlineMsg(divname,xmlHttp.responseText);
					//alert("dedans");
				//}
			}
		}
	}	
}

function stateChanged_pays() {
	/**********************************
	* appeller dans la page form_inscr_inv_step2
	* pour régler problème d'affichage
	*************************************/
	if (xmlHttp_pays.readyState==4) {
		
		var reponse = xmlHttp_pays.responseText
			// verifie si existe avant
			if (document.getElementById(divname_pays))
			{
				document.getElementById(divname_pays).innerHTML=xmlHttp_pays.responseText;
				if ((divname_pays == "div_province") || (divname_pays == "div_division") )
				{
					// je call pour mettre a jour la zone div_province
					majDiv();
				}
			}
		}
		
}


function GetXmlHttpObject() {

	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	
	catch (e) {
	  // Internet Explorer
		try {
	
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	return xmlHttp;
}


function loadCC(txt)
{
	window.location.href= txt 
	
}

function loadPays(txt)
{
	document.getElementById('id_pays').value=txt
	hideshow(document.getElementById('search_suggest'))	
}


function changeValeurInput(txt,divname)
{

	divTextName="texte_" + divname
	document.getElementById(divTextName).value = txt;
	// je fais disparaitre la liste des options
	hideshow(document.getElementById(divname));
	
}


function changeValue2(txt)
{
	document.getElementById('id_txtSearch').value=txt
	// je fais disparaitre la liste des options
	hideshow(document.getElementById('search_suggest'))
	hideshow(document.getElementById('generale'))
}

function hideshow(obj) 
{ 
		if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) 
		{
			if (obj.style.display=="none") 
             obj.style.display="";
        	else
             obj.style.display="none";
		}
}

/* 
	changer l'état de la boite de texte 

*/
etatRecherche=0
function changeEtat(objField) {

    changeColor(objField);
    if (etatRecherche == 0) {
	objField.value = "";
	etatRecherche = 1;
    }
}

function changeColor(objField) {
    objField.style.color='#000';
}

function cacheDiv(div_nom) { 
		if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) 
		{
	       document.getElementById(div_nom).style.display="none";
		}
}
 
function montreDiv(div_nom) { 
	if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) 
		{
	        document.getElementById(div_nom).style.display="";
		}

} 
function montre_cacheDiv(div_nom) 
{ 
		if (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1) 
		{
			if (document.getElementById(div_nom).style.display=="none") 
             document.getElementById(div_nom).style.display="";
        	else
             document.getElementById(div_nom).style.display="none";
		}
}
