Function.prototype.callBack=function(){
      var __method = this, args = Array.prototype.slice.call(arguments,0);
      return function() {
           return __method.apply(this, args);
      }
}

function aX(method, filecon, type) {
	this.data=null;
	this.mO=method;
	this.fC=filecon;
	this.tP=type;
	try { this.xhr=new XMLHttpRequest(); }
	catch(e) { this.xhr=new ActiveXObject("Microsoft.XMLHTTP"); }
	}	
aX.prototype.send=function() {
	this.xhr.open(this.mO, this.fC, this.tP);
	this.xhr.onreadystatechange = this.wait.callBack(this.asker, this.xhr);
   	this.xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	this.xhr.send(this.data);
}
aX.prototype.ask=function(dis) {
	this.asker=dis;
	this.data=this.asker.name+"="+this.asker.value;
	this.pag=this.lediv;
	if(this.asker.value.length>1) {
		this.send();	
	}	
}
aX.prototype.wait=function(asker, xr) {
	if(asker==document.getElementById("cp") || asker==document.getElementById("dpt")) {
		cachin();
		if(xr.readyState == 4) {
			optionin(xr.responseText);
			}
		}	
	if(asker==document.getElementById("ajaxSel")) {
		disable();
		if(xr.readyState == 4) {
			cp(xr.responseText);
			}
		}	
	}
	
function optionin(arstr) {
	var gim=new Array();
	b=0;
	as=document.getElementById("ajaxSel");
	for(k=0; k<as.getElementsByTagName("option").length; k++) {
		gim.push(as.getElementsByTagName("option")[k]);
	}
	for(j=0; j<gim.length; j++) {
		gim[j].parentNode.removeChild(gim[j]);
	}
	b=arstr.split("::");
	if(b.length>1) {
		if(document.getElementById("alert")) { document.getElementById("alert").style.display="none"; }
		if(document.getElementById("labVille")) { document.getElementById("labVille").style.display="inline"; }
		document.getElementById("loadin").style.display="none";
		document.getElementById("ajaxSel").style.display="inline";
		opt=document.createElement("option");
		inopt=document.createTextNode("Sélectionnez");
		opt.appendChild(inopt);
		as.appendChild(opt);
		for(i=0; i<b.length-1; i++) {
			opt=document.createElement("option");
			inopt=document.createTextNode(b[i]);
			opt.appendChild(inopt);
			opt.value=b[i];
			as.appendChild(opt);
			}
		}
	else {
		if(arstr.length>0) {
			document.getElementById("alert").style.display="block";
			rip=document.getElementById("cp").value;
			document.getElementById("cp").value=rip.substr(0,2);
			}		
		}
	}
	
function cachin() {
	if(document.getElementById("labVille")) { document.getElementById("labVille").style.display="none"; }
	document.getElementById("ajaxSel").style.display="none";
	document.getElementById("loadin").style.display="inline";
	}
	
function disable() {
	document.getElementById("cp").disabled=true;
	}
function cp(astr) {
	document.getElementById("cp").value="patience...";
	if(document.getElementsByTagName) {
		document.getElementById("cp").disabled=false;
		document.getElementById("cp").value=astr;
		}
	}
