function objetoAjax(){
 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 MostrarConsulta(datos,idid,idmnu,iddivmnu){
	//datos es la peticio
	//idid es el id on el posara.
 MenuSel(idmnu,iddivmnu);
 var divResultado = document.getElementById(idid);
 ajax=objetoAjax();
 datos=datos+"&pet_ajax="+idid;
 ajax.open("GET", datos);
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divResultado.innerHTML = ajax.responseText;
  }
 }
 ajax.send(null);
}

	
function Confirma(){
	if (confirm("Vols borrar?")){
		return true;
	} else {
		alert("Cancelat");
		return false;
	}
}

function MenuSel(pId,pIdDivMnu){
	if (pIdDivMnu==""){return true;}
	var divPare = document.getElementById(pIdDivMnu);
	var as = divPare.getElementsByTagName("LI");
	for (var i=0; i<as.length; i++) {
		//alert("pId="+pId+" xx="+as[i].id);
		if (as[i].id==pId){
		//	alert("ok");
			as[i].className = 'actiu'; // negro
		} else {
			as[i].className = ''; // negro
//			as[i].style.color = '#000'; // negro
		}
	}
	return true;
}
function AnarA(menu){
	window.location.href = menu.options[menu.selectedIndex].value;
}
function Anar(pUrl,pConfirmar){
    if (pConfirmar!=""){
        if (Confirma(pConfirmar)==false){
            return "";
        }
    }
    window.location.href = pUrl;
}
function EliminaImatge(imatge){
    alert("elimina");
    document.getElementById('img_'+imatge).src='elim';
    fe=document.getElementById('fitxers_eliminar');
    if (fe.value==""){
        fe.value=imatge;
    } else {
        fe.value=fe.value+","+imatge;        
    }
}
function AnarFiltreBK(){
    var divPare = document.getElementById("taula_filtres");
    var as = divPare.getElementsByTagName("select");
    var filt="";
    params=window.location.search;
    params = params.replace(/.*\?(.*?)/,"$1");
    for (var i=0; i<as.length; i++) {
       params=CanviCadena(params,as[i].value);
    }
    novadir=window.location.pathname+"?"+params;
    window.location.href = novadir;
}

function CanviCadena(params,param){
    ig=param.indexOf("=");
    nomparam=param.substring(0,ig);
    Variables = params.split("&");
    fet=0;
    for (i = 0; i < Variables.length; i++) {
       Separ = Variables[i].split("=");
      // eval ('var '+Separ[0]+'="'+Separ[1]+'"');
      if(Separ[0]==nomparam){
          params=params.replace(Separ[0]+"="+Separ[1],param);
          fet=1;
      }
    }
    if (fet==0){params=params+"&"+param;}
    return params;
}




