function SupprimeAccent(sChaine){
      temp = sChaine.replace(/[àâä]/gi,"a");
      temp = temp.replace(/[éèêë]/gi,"e");
      temp = temp.replace(/[îï]/gi,"i");
      temp = temp.replace(/[ôö]/gi,"o");
      temp = temp.replace(/[ùûü]/gi,"u");
      return temp;
}
function RemplaceSpecialCarParEtoile(sChaine){
     temp = sChaine.replace(/[àâäéèêëîïôöùûü-]/gi,"*");

	var reg = new RegExp("[\\s]", "ig");
	temp = temp.replace(reg, "*");


	 return temp;
}
function VerifCP(idFldCp, idFldLoc, idFldPays, idDivVille){
	sSizeInput = "size=\"50\"";
	sSizeSelect = "style=\"width:270px\"";
	if (idFldCp == "tlcpent"){
		sSizeInput = "size=\"22\"";
		sSizeSelect =  "style=\"width:137px\"";
	}
	if (idFldCp == "postalcode"){
		sSizeInput = "class=\"size3\"";
		sSizeSelect =  "style=\"width:130px\"";
	}

	var oCp = document.getElementById(idFldCp);
	var oPays = document.getElementById(idFldPays);
	
	//On lance le contrôle si le code postal est non vide et si rien ou France est sélectionné dans le référentiel Pays
	if (oCp.value != "" && (oPays.value=='' || oPays.value=='FR') ){
		sSend = "action=controleCP&cp="+oCp.value
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
			xhr_object = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xhr_object.open("POST", "/a2i_annuaire/referentiels/a2i_ajax_referentiels.php", false);
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(sSend);
		if(xhr_object.readyState == 4){
			if(xhr_object.responseText != "0"){
				//DEBUG : alert(xhr_object.responseText);
				//Si 1 seule ville, on l'affiche dans le champ Ville
				if (xhr_object.responseText.indexOf("|")<0){
					document.getElementById(idDivVille).innerHTML = "<input type=\"text\" class=\"input\" name=\""+idFldLoc+"\" id=\""+idFldLoc+"\" value=\"" + xhr_object.responseText + "\" "+sSizeInput+" readonly=true/>";
				}
				//Si plusieurs villes construction de la liste déroulante avec les valeurs
				else {
					var tLoc = xhr_object.responseText.split("|");
					sTemp = "<SELECT class=\"input select\" name=\""+idFldLoc+"\" id=\""+idFldLoc+"\" "+sSizeSelect+">";
					sTemp += "<option value=''>Sélectionner ...</option>";
					for (i=0;i<=tLoc.length; i++ ){
						if (tLoc[i]){
							sTemp += "<option value='"+tLoc[i]+"'>"+tLoc[i]+"</option>";
						}
					}
					sTemp += "</SELECT>";
					if (window.ActiveXObject){
						sTemp += "<div class='spacer' style='height:3px'></div>";
					}
					document.getElementById(idDivVille).innerHTML = sTemp;
				}
				oPays.value='FR';
				oPays.disabled=true;
			}else{
				document.getElementById(idDivVille).innerHTML = "<input type=\"text\" class=\"input\" name=\""+idFldLoc+"\" id=\""+idFldLoc+"\" value=\"\" "+sSizeInput+"/>";
				oPays.value='';
				oPays.disabled=false;
			}
		}
	}else{
		document.getElementById(idDivVille).innerHTML = "<input type=\"text\" class=\"input\" name=\""+idFldLoc+"\" id=\""+idFldLoc+"\" value=\"\" "+sSizeInput+"/>";
		oPays.disabled=false;
	}

}

function CalculGR(idFldCp, idFldPays, idFldGr){
	var oGr = document.getElementById(idFldGr);
	var oCp = document.getElementById(idFldCp);
	var oPays = document.getElementById(idFldPays);
	
	if (oCp.value!=''){
		sValCp=oCp.value;
	}else{
		sValCp='-1';
	}

	sSend = "action=getGR&cp="+sValCp+'&pays='+oPays.value;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		xhr_object = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhr_object.open("POST", "/a2i_annuaire/referentiels/a2i_ajax_referentiels.php", false);
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr_object.send(sSend);
	if(xhr_object.readyState == 4){
		oGr.value = xhr_object.responseText;
	}
}

function openPopup(href, id, width, height)
{
	if (href != "") {
		var top = (screen.height - height)/2;
		var left = (screen.width - width)/2;
		pagePopupWin = window.open(href, 'CMS_page_'+id, 'width='+width+',height='+height+',resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=no,left='+left+',top='+top);
	}
}
