
document.nbEnfantsMax=7;
	
function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

	
	
function displayCityList(strVilles)
{

	strVilles = unescape(strVilles);
	posEnd=strVilles.indexOf("~!~");
	strVilles=strVilles.substring(posEnd+4);
	strVilles = trim(strVilles);
	arrVilles=strVilles.split(";");
	document.getElementById("ville").options.length=arrVilles.length;
	if(strVilles!=""){
		for(i=0;i<arrVilles.length;i++){	
			arrIdVilles=arrVilles[i].split(":");
			cityName=unescape(arrIdVilles[1]);
			if (cityName != "undefined") { 
			while(cityName.indexOf("+")>-1)
			{
				cityName=cityName.replace("+"," ");
			}
			document.getElementById("ville").options[i].text=cityName;
			document.getElementById("ville").options[i].value=arrIdVilles[0];
			//document.getElementById("ville").options[i].value=cityName; 
			}	
		}
	}
	else{
	//document.getElementById("divVille").style.display="none";
	}
}

function getCityName(cpval)
{	

	cpvalall=""+cpval;
	if(cpvalall.length==5){
		arrParamsKeys=new Array("getCityList","cpval");
		arrParamsValues=new Array("",cpvalall);
		
		//envoieRequete("incs/functsAjax.php","",arrParamsKeys,arrParamsValues,displayCityList,"");
		//envoieRequete("http://www.santiane.fr/forms/interface_villes.php","",arrParamsKeys,arrParamsValues,displayCityList,"");
		;
		request_send("",displayCityList );
		//request_receive('OK...');
	
	}
	else if(cpval!=""){
		alert("Le code postal saisi n'est pas correct");	
	}
}


function request_send(send, callback)
{
    request_callback = callback;
    request_script = document.createElement("script");
    request_script.src = "http://www.santiane.fr/forms/interface_villes.php?cpval="+cpvalall+"&getCityList&test";
    document.getElementsByTagName("head")
        [0].appendChild(request_script);
}

function request_receive(data)
{
    document.getElementsByTagName("head")
        [0].removeChild(request_script);
    request_callback(data);
}

function getProperties(/*Object*/ obj){
    var msg = "";
    for (prop in obj){
        msg += "property : " + prop + "\t\t value : " + obj[prop] + "\n";
    }
    alert(msg);
}

function setClassToFields(arrFields,classtoapply)
{
	for(i=0;i<arrFields.length;i++)
	{
			document.formMain[arrFields[i]].className=classtoapply;
	}
}

//]]>
