<!--
//Menu
function a() {
	document.getElementById('b1').style.display = "none";
	document.getElementById('b2').style.display = "none";
	document.getElementById('b3').style.display = "none";
	document.getElementById('b4').style.display = "none";
}
function at(tipus) {
	document.getElementById(tipus).style.display = "block";
}
function c(tipus) {
	if (document.getElementById(tipus).style.display == "none") {
		document.getElementById('b1').style.display = "none";
		document.getElementById('b2').style.display = "none";
		document.getElementById('b3').style.display = "none";
		document.getElementById('b4').style.display = "none";
		document.getElementById(tipus);
		document.getElementById(tipus).style.display = "block";
	}
	else {
	document.getElementById(tipus).style.display = "none";
	}
}
  
//Popup imatges

PositionX = 10;
PositionY = 10;
defaultWidth  = 600;
defaultHeight = 400;

var AutoClose = true;

function popImage(imageURL,imageTitle){
  var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
  if( !imgWin ) { return true; } //popup blockers should not cause errors
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
    'function resizeWinTo() {\n'+
    'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
    'var oH = document.images[0].height, oW = document.images[0].width;\n'+
    'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
    'window.doneAlready = true;\n'+ //for Safari and Opera
    'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
    'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
    'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
    'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
    'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
    'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
    'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
    'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
    'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
    'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
    '}\n'+
    '<\/script>'+
    '<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
    (document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
    '<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
    (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
  imgWin.document.close();
  if( imgWin.focus ) { imgWin.focus(); }
  return false;
}



/* @autor: Mario Martinez
 * FUNCIONS PER VERIFICAR UN FORMULARI --------------------------------------------------------------*/
function CampText(camp){
	var valid = false;
	
	var co = document.getElementById(camp);
	if (co.value.length > 0) valid = true;
	
	CambiaColor(camp,valid);
	
	return valid;
}

function CampEmail(camp){
	
	valid = VerificarEmail(camp);
	CambiaColor(camp,valid);
	
	return valid;
	
}


function VerificarEmail(e) {
   var s = document.getElementById(e).value;
   var filter=/^[A-Za-z][A-Za-z0-9\\.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
   if (s=="") return false;
   if (s.length == 0 ) return false;
   if (filter.test(s)) return true;
   else return false;
}


function CampNumeric(camp,digits){
	
	var num = document.getElementById(camp).value;
	var valid = false;
	
	if(digits == 0){
		if(num.length > 1) valid = soloNumerico(num);
	}
	else if(num.length == digits) valid = soloNumerico(num);
	
	CambiaColor(camp,valid);
	
	return valid;
}

function soloNumerico(valor) {
	return !isNaN(valor);
}

function CampCheked(camp){

	var valid = document.getElementById(camp).checked;
	CambiaColor(camp,valid);
	return valid;
}

function ValidarFormulari(camps){
	
	//FORMAT ('nom_input=tipus;nom_input2=tipus;...nom_inputX=numeric#NumMax')
	//array de camps
	var tcamps = new Array();
	var camp;
	var aux;
	var numleng = 0;
	var i_ok = 0; //conta el camps correctes. Si son = al total de camps, tot es correcte
	
	tcamps = camps.split(";");
	
	for(i=0; i < tcamps.length; i++)
	{
		numleng = 0;
		aux = tcamps[i].split("=");
		camp = aux[0];
		metode = aux[1];
		
		if(metode.match("#"))
		{//xapuza
			
			aux = metode.split("#");
			numleng = aux[1];
			metode = aux[0];
		}
		
		if(metode == "text") {
			if(CampText(camp)) i_ok++; 
		}
		else if(metode == "email") {
			if(CampEmail(camp)) i_ok++;
		}
		else if (metode == "numeric") {
			if(CampNumeric(camp, numleng)) i_ok++;
		}
		else if(metode == "check"){
			if(CampCheked(camp)) i_ok++;
		}
		
	}
	
	if(i_ok == tcamps.length) return true;
	else{
		//alert("Hi ha algun camp incorrecte!");
		return false;
	}
	
	
	//return retorn;
}

function CambiaColor(camp,valid){
	
	var e = document.getElementById(camp);
	var ok = document.getElementById(camp+"_ok");
	if(!valid) 
	{
		e.style.border = "1px solid #e51d13";
		ok.style.color = "#c80000";
	
	}
	else 
	{
		e.style.border = "1px solid #5e7885";
		ok.style.color = "inherit";
	}
}



//-->