
function validar_frm_comentari(){
	var error="";
	var nom=document.getElementById("comentari_nomautor").value;   
	var comentari=document.getElementById("comentari_descripcio").value;   
	if(nom=="")
		error="Cal introduir el nom\n";
	if(comentari=="")
		error=error+"Cal introduir el comentari";
	if(error!=""){
		alert(error);
		return false;
	}
	else	
		return true;
}
function comprovar_usuari(f){
	var contrasenya=f.pwd.value;
	var usuari=f.uid.value;
	var error;
	error="";
	if(usuari=="")
		error="Falta l'usuari.\n";
	if(contrasenya=="")
		error=error+"Falta la contrasenya.";
	
	if(error!="")
	{
		alert(error);
		return false;
	}
	else
		return true;
		
}
function confirmar_esborrar(frase){
	return confirm(frase);
}


function mantenir_email(titol,descripcio){
	var t=document.f_email.titol_missatge.value;
	var d=document.f_email.descripcio.value;
	titol.value=t;
	descripcio.value=d;
	return true;
}
function comprovar_destinataris(missatge){
	// evitar l'enviament d'un missatge sense destinataris i, de passada, forçar-ne l'entrada
	// enviant l'usuari al formulari d'adreces
	var i=document.f_email.total_destinataris.value;
	if(i==0){
		alert(missatge);
		mantenir_email(document.adreces.titol_missatge,document.adreces.descripcio);
		document.adreces.submit();
		return false;
	}
	else
		return true;
}
function print_f(s,i){
	s=s.split("%d").join(i);
	return s;
}
function isInt(n){
	var i=0;
	for(i=0;i<n.length;i++)
		if(n.charAt(i)<0||n.charAt(i)>9)	return false;
	return true;
}



/*
function ObrePopUp(e, origen,width,height){
	// Obre una nova finestra al mig de la pantalla
	if(!document.captureEvents)	e=window.event;
	var boto = (e.which?e.which:e.button);
	var passa = false;
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	if(e.type=="click" && (boto==0 || boto==1)) passa = true;
	if(e.type=="keypress" && e.keyCode==13) passa=true;
	if(passa){
		window.open(origen.href, 'popup' + new Date().getTime(), 'width='+width+',height='+height+',toolbar=0,resizable=1,directories=1,menubar=0,location=1,scrollbars=1,status=1,rezisable,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
		return false;
	}
}
*/
function ObrePopUp(e, origen,width,height){
	// Obre una nova finestra al mig de la pantalla
	if(!document.captureEvents)	e=window.event;
	var boto = (e.which?e.which:e.button);
	var passa = false;
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	if(e.type=="click" && (boto==0 || boto==1)) passa = true;
	if(e.type=="keypress" && e.keyCode==13) passa=true;
	if(passa){
		windowReference = window.open(origen.href, 'popup' + new Date().getTime(),
		'width='+width+',height='+height+',toolbar=1,resizable=1,directories=1,menubar=1,location=1,scrollbars=1,status=1,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
		if (!windowReference.opener)
			windowReference.opener = self;
		return false;
	}
}
function ObrePopUpImg(e, origen,width,height){
	// Obre una nova finestra al mig de la pantalla
	if(!document.captureEvents)	e=window.event;
	var boto = (e.which?e.which:e.button);
	var passa = false;
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	if(e.type=="click" && (boto==0 || boto==1)) passa = true;
	if(e.type=="keypress" && e.keyCode==13) passa=true;
	if(passa){
		windowReference = window.open(origen.href, 'popup' + new Date().getTime(),
		'width='+width+',height='+height+',toolbar=0,resizable=0,directories=0,menubar=0,location=0,scrollbars=1,status=0,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
		if (!windowReference.opener)
			windowReference.opener = self;
		return false;
	}
}
function ObrePopUpForm(adreca,width,height){
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	windowReference = window.open(adreca, 'popup' + new Date().getTime(),
	'width='+width+',height='+height+',toolbar=0,resizable=0,directories=0,menubar=0,location=0,scrollbars=1,status=0,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
	if (!windowReference.opener)
		windowReference.opener = self;
	return false;
}

function ObrePopUpDicc(adreca,idselect,width,height){
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	var select=document.getElementById(idselect);
	var index=select.options[select.selectedIndex].value;

	adreca+="&index="+index;
	windowReference = window.open(adreca, 'popup' + new Date().getTime(),
	'width='+width+',height='+height+',toolbar=0,resizable=0,directories=0,menubar=0,location=0,scrollbars=1,status=0,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
	if (!windowReference.opener)
		windowReference.opener = self;
	return false;
}
function ObrePopUpDicc_vp(adreca,idinput,width,height){
	var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
	//alert(222);
	
	var s=document.getElementById(idinput);
	var index=s.value;

	adreca+="&index="+index;
	windowReference = window.open(adreca, 'popup' + new Date().getTime(),
	'width='+width+',height='+height+',toolbar=0,resizable=0,directories=0,menubar=0,location=0,scrollbars=1,status=0,left=' + left + ",top=" + top + "screenX=" + left + ",screenY=" + top);
	if (!windowReference.opener)
		windowReference.opener = self;
	return false;
	
}


function bloca_pagina(accio){
	var s="";
	if(accio === undefined)
		accio="temes.php";
	s="<form name='form_bloca_pagina' action='"+accio+"'><input type='hidden' name='opcio' value='r' /></form>";
	if(confirm("ATENCIÓ!\n\nAquesta operació permet actualitzar el menú i el fil d\'ariadna a totes les seccions del web.\nMentre dura el procés, no tanquis ni refresquis el navegador.\n\nAquesta operació pot durar uns minuts. \nSegur que vols continuar?")){
		
		if(accio == "admin/temes.php")
			document.body.innerHTML += s;
			//document.body.innerHTML = s+"<div style='width: 100%; height: 100%; position: absolute; display:block;  background-color: #fff; opacity:0.5; z-index: 100;'></div>";
		else
			document.body.innerHTML += s;
		deshabilita_boto(document.getElementById("bto_ref"));	
		document.form_bloca_pagina.submit();
		
	}
	return false;
}
function bloca_pagina_menu(f){
	bloca_pagina("admin/temes.php");
/*
	var titol="<p>Actualitzant dades...</p>";
	var s="<form name='form3' action='admin/temes.php'><input type='hidden' name='opcio' value='r' /></form>";
	s+="<img src='admin/images/ico/progressbar.gif' style='margin-top: 10px;' />"; //."images/ico/progressbar.gif";
	if(confirm("ATENCIÓ!\n\nAquesta operació permet actualitzar el menú i el fil d\'ariadna a totes les seccions del web.\nMentre dura el procés, no tanquis ni refresquis el navegador.\n\nAquesta operació pot durar uns minuts. \nSegur que vols continuar?")){
		document.body.innerHTML = "<div style='text-align: center; padding-top: 20%; width: 100%; height: 100%; position: absolute;  background-color: #fff; font-size: 12px;'>"+titol+s+"</div>";
		document.form3.submit();
	}
	return false;
*/
}





/*
function aguanta_panell(idspan){
	var a=document.getElementById(idspan);
	if(a.style.visibility != "visible"){
		a.style.display="block";
		a.style.visibility="visible";
	}
	//alert(a.style.visibility);
}

function in_panell(idspan, e){
	var a=document.getElementById(idspan);
	var b=document.getElementById("a_"+idspan);
	var IE = document.all?true:false;
	
	var tempX=0;
	var tempY=0;
	if (!IE) document.captureEvents(Event.MOUSEMOVE);

	if (IE) { // grab the x-y pos.s if browser is IE
	tempX = e.clientX;// + document.body.scrollLeft;
	tempY = e.clientY;// + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
	tempX = e.pageX;
	tempY = e.pageY;
	}  

	//alert(tempX);

	a.style.left=tempX-20;
	a.style.top=tempY-20;	
	
	if(a.style.visibility!="visible"){
		a.style.display="block";	
		//a.style.position="fixed";
		a.style.visibility="visible";
	}
	//alert(a.style.visibility);
	return true;
}
function out_panell(idspan){
	var a=document.getElementById(idspan);
	//alert("out");
	a.style.visibility="hidden";
}

*/

/*  FUNCIONS REVISIÓ DE DADES  */

function es_ascii2(s){	
	var i;
	var strobats="";
	for(i=0;i<s.length;i++){
		if(s.charCodeAt(i)>127){
			strobats+=s.charAt(i)+" ";
		}
	}
	//alert(strobats);
	return strobats;
}
function left(str, n){
   if (n <= 0) 
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function es_email(s){
	var i;
	var punt=0;
	var arroba=0;
	
	for(i=0;i<=s.length-1;i++){
		//alert(s.charAt(i));
		switch (s.charAt(i)){
			case '@':
				arroba=i;
				break;
			case '.':
				punt=i;
		}
	}
	if(arroba==0 || punt==0 || punt<arroba+2 || arroba==s.length-1 || punt==s.length-1)
		return false;
	else
		return true;
}

function GlobusObert(){
	//alert(222);
	var globus=document.getElementById("globus_tancar_vp");
	globus.style.height="500px";
}
function GlobusTancat(){
	//alert(222);
	var globus=document.getElementById("globus_tancar_vp");
	globus.style.height="18px";
}
function botonets(obrir,tipus,id,alt){
	var boleta=document.getElementById(id);
	var imatge=document.getElementById("img_"+id);
	var gris=document.getElementById("capa_gris_vp");
	//document.body.height+=800;
	//alert(screen.availWidth);
	/*
	switch(tipus){
		case "art":
			alt="220px";
			break;
		case "tem":
			alt="230px";
			break;
		case "ban":
			alt="200px";
			break;
		case "lli":
			alt="180px";
			break;
		case "reg":
			alt="210px";
			break;
		case "dis":
			alt="110px";
			break;
		case "cal":
			alt="140px";
			break;			
		case "rel":
			alt="100px";
			break;		
		case "reli": // RELACIONATS > IMATGES
			alt="140px";
			break;
		default:
			alt="250px";
			break;
			
	}
	*/
	
	if(!alt)
		alt=250;
	if(obrir){
		//alert(parseInt((screen.availWidth)));
		
	//alert(boleta.offsetLeft);
	//alert(boleta.clientHeight);
	//alert(boleta.scrollLeft);
		boleta.style.height=alt+"px";
		boleta.style.width="150px";
		boleta.style.zIndex="1000";
		boleta.style.borderWidth="2px";
		//boleta.style.left="-50px";
		
		
		//boleta.style.borderColor="#444";
		//boleta.style.position="absolute";
		boleta.style.padding="2px";
		
		imatge.style.height="0px";
		gris.style.display="block";
		gris.visibility="visible";
	}
	else{
		boleta.style.height="10px";
		boleta.style.width="20px";
		boleta.style.zIndex="500";
		boleta.style.borderWidth="1px";
		//boleta.style.borderColor="#f00";
		boleta.style.padding="0px";
		//boleta.style.position="relative";
		
		imatge.style.height="10px";
		gris.style.display="none";
		gris.visibility="hidden";
	}
}
function SetFocus(id){
	//alert(1);
	//ocument.f.elements[0].focus();
	if(document.getElementById(id) != null)
		document.getElementById(id).focus();
	//alert(2);
}
function mostrar_espera(){
	var miss=document.getElementById("miss_espera");
	miss.style.display="block";
	miss.visibility="visible";	
}
function deshabilita_boto(boto){
	//boto.disabled=true;
	boto.style.color="#aaaaaa";
	mostrar_espera();	
	return true;
}
function amagar(element){
	//alert("amagar");
	element.innerHTML=""; element.visibility="hidden"; element.style.display="none";
}
function mostrar(element){
	//alert("mostrar");
	if(element.style.display=="none" && element.innerHTML != "") {element.style.display="block"; element.visibility="visible";}
}


function tanca_finestra(codi){
	if(codi==27) 
		window.close();
}	
