function substitueix(aixo, per, text){
	busca = eval("/" + aixo + "/gi");
	res = text.replace(busca, per);
	
	return res;
}

function encodeEspecials(text){
	//text = substitueix('é', "\u00E9", text);
	text = substitueix("è", "&egrave;", text);
	text = substitueix("`", "&lsquo;", text);
	text = substitueix("´", "&rsquo;", text);
	text = substitueix("”", "&rdquo;", text);
	return text;
}

function decodeEspecials(text){
	//text = substitueix("\u00E9", "é", text);
	text = substitueix("&egrave;", "è", text);
	text = substitueix("&lsquo;", "`", text);
	text = substitueix("&rsquo;", "´", text);
	text = substitueix("&ldquo;", "“", text);
	text = substitueix("&rdquo;", "”", text);
	return text;
}

function nouAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function consultaAjax(str_valors, capa_resposta, img, pagina){
	
	if(img){imatge = img;}else{imatge = 'img/ajax-carregant2.gif';}
	if(pagina){pagina = pagina;}else{pagina = 'include/consultesAjax.php';}	
	
	capa = document.getElementById(capa_resposta);
	ajax=nouAjax();
	ajax.open("POST", pagina, true);
	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
            capa.innerHTML = "<div class='a_centre' style='padding-top:20px;'><img src='" + imatge + "'></div>" +
			"<div class='a_centre x_per_sobre blanc'>Carregant...</div>";
        }else if (ajax.readyState==4) {
			capa.innerHTML = ajax.responseText;
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1;");
	ajax.send(str_valors);
}
