function ContarCP(valor,url) {
	if (valor.value.length > 1){
		var url=url+"?CP="+valor.value;
		var x=0;
	ajax(valor,url,x)
	}
}
function ContarPR(valor,url) {
	if (valor.value.length > 1){
		var url=url+"&PR="+valor.value;
		var x=1;
	ajax(valor,url,x);
	}
}
function ContarDir(valor,url) {
	if (valor.value.length >3 && valor.value.length <50){
		var url=url+"?Dir="+valor.value;
		var x=2;
	ajax(valor,url,x)
	}
}
function ajax(valor,url,x){
var url_1 = false;
if (window.XMLHttpRequest) {
url_1 = new XMLHttpRequest();
} else if (window.ActiveXObject){ // pero si es IE
try {
url_1 = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e){ // en caso que sea una versión antigua
try{
url_1 = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){}
}
}
else
return false;
url_1.onreadystatechange=function(){ // función de respuesta
carregar(valor,url_1,x,url);
}
url_1.open('GET',url,true) // asignamos los métodos open y send
url_1.send(null);
}
function carregar (valor,url_1,x,url){    
	if (url_1.readyState == 4 && (url_1.status == 200 || window.location.href.indexOf ("http") == - 1))
	if(x==0){
	Alta.Provincia.value=url_1.responseText;
	Alta.poblacio.value="";
	valor=Alta.Provincia;
	ContarPR(valor,url);
	}else if(x==1){
	url_2=escape(url_1.responseText);
	for (i = 0; i < url_2.length; i++){
		url_2=url_2.replace('%uFFFFe','ç');
		url_2=url_2.replace('%20',' ');
	}
	document.Alta.poblacio.value=url_2;
	}else{
		if(url_1.responseText!=""){
		var txtbx="";
		var Len1="";
		Len1=valor.value.length;
		document.Alta.adreca.value=url_1.responseText;
		txtbx=document.Alta.adreca.createTextRange();
		txtbx.moveStart("character",Len1);
		txtbx.moveEnd("character", 100);
		txtbx.select();
		}
	}
}