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 PeticioAjax(datos,idid){
    //datos es la peticio
    //idid es el id on el posara.
 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 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,pNou){
    //alert("cuac!");
    if (pConfirmar!=null & pConfirmar!=""){
        if (Confirma(pConfirmar)==false){
            return "";
        }
    }
    if (pNou==null){
        window.location.href =pUrl; 
    } else {
        open(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;
}

function CanviaFotoiTexte(num){
    document.images["igran"].src=document.images["idescripcio"+num].src;
    document.getElementById("textep").innerHTML=document.getElementById("descripcio"+num).value;
}
function CanviaFoto(origen,desti){
    document.images[desti].src=document.images[origen].src;
}



function CreaDivFitxer(contenidor,pnomfitxer,boto){

    if(vf[pnomfitxer]['pendents']==0){return "";}

    vf[pnomfitxer]['pendents']=vf[pnomfitxer]['pendents']-1;
    if(vf[pnomfitxer]['pendents']==0){boto.setAttribute("type","hidden");}

    
    vf[pnomfitxer]['ultnum']++;
    nomfitxer=pnomfitxer+vf[pnomfitxer]['ultnum'];
    
    divfit= document.getElementById(contenidor);

     divrfp= document.createElement('div');
     divrfp.setAttribute("class", "form-row_principal");

     divuplp= document.createElement('div');
     divuplp.setAttribute("class", "uploads_p");


     divupl= document.createElement('div');
     divupl.setAttribute("class", "upload");

     divimg= document.createElement('div');
     divimg.setAttribute("class", "image-cont");
     
     img=document.createElement('img');
     img.id="img_"+nomfitxer;
     img.setAttribute("name", "img_"+nomfitxer);
          
     divtit=document.createElement('div');
     divtit.setAttribute("class", "titulo");
         
     texttit = document.createTextNode(pnomfitxer);
     
     divbot=document.createElement('div');
     divbot.setAttribute("class", "buttons");
     
     inpfit=document.createElement('input');
     inpfit.setAttribute("class", "file");
     inpfit.setAttribute("type","file");
     inpfit.setAttribute("name", nomfitxer);
     inpfit.id=nomfitxer;
         
     inpdel=document.createElement('input');
     inpdel.setAttribute("class", "remove");
     inpdel.setAttribute("type", "button");
     inpdel.setAttribute("onclick","EliminaImatge('"+nomfitxer+"')");
    
     divimg.appendChild(img);
     
     divtit.appendChild(texttit);
     
     divbot.appendChild(inpfit);
     divbot.appendChild(inpdel);
     
     divupl.appendChild(divimg);
     divupl.appendChild(divtit);
     divupl.appendChild(divbot);
     
     divuplp.appendChild(divupl);
     divrfp.appendChild(divuplp);
     divfit.appendChild(divrfp);
     kk="#"+nomfitxer;
     $(kk).si();
}

