		// ---------------- VALIDACIO DOMINI ----------------
		var msg;
		
		function validarDomini()
		{
			msg = "";
			document.getElementById("existeix").innerHTML = "";
			var extensio = document.getElementById('extensio').value;
			var nom = $('input[@name=nom]').val();
			if (nom == null || nom == '')
			{
				msg += "\n\tFalta el nom del domini";
			} else {
				if ( ! esValidDomini(nom) ) { msg += "\n\tEl nom del domini no és vàlid"; }
			}
			if ( msg == "" )
			{	
				document.getElementById("loading").innerHTML = "<img src=\"medias/img/loading.gif\">";
				$.post("existeixJS.php",  { nom: nom , extensio:extensio }, function(data){
					if ( data != "" || data != null )
					{
						document.getElementById("existeix").innerHTML = data;
						validaDominiFinal();
					}
				});
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validaDominiFinal()
		{
			if ( msg == "" )
			{
				if ( document.getElementById("existeix").innerHTML == "" )
					{
						document.getElementById("loading").innerHTML = "";
						$('#domini').submit();
					} else {
						document.getElementById("loading").innerHTML = "";
						alert("Errors trobats:\n" + document.getElementById("existeix").innerHTML);
						return false;
					}
			}else{
				document.getElementById("loading").innerHTML = "";
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO DOMINI ----------------
		
		
		// ---------------- VALIDACIO CORREU ----------------
		
		function validarCorreu()
		{
			var msg = "";
			var user = $('input[@name=user]').val();
			user = trim(user);
			var password1 = $('input[@name=password1]').val();
			var password2 = $('input[@name=password2]').val();
			
			if (user == null || user == '') { msg += "\n\tFalta nom de la bústia"; }
			else {
				if ( ! esValidUser2(user) )		{ msg += "\n\tEl nom de la bústia no és vàlid"; }
			}
			if ( password1 == null || password1 == '' ) { msg += "\n\tFalta la clau"; }
			else {
				if ( password1.length < 6 )		{ msg += "\n\tLa clau ha de tenir mínim 6 caràcters"; }
				if ( password2.length < 6 )		{ msg += "\n\tLa repetició de la clau ha de tenir mínim 6 caràcters"; }
			}
			if ( msg == "" && password1 != password2 )	{ msg += "\n\tLes claus són diferents"; }
			
			if ( msg == "" )
			{
				$("#mail").submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validarModifCorreu()
		{
			var envia1, envia2;
			var password1 = $('input[@name=password1]').val();
			var password2 = $('input[@name=password2]').val();
			if ( (password1.length < 6) )
			{
				document.getElementById('error2a').innerHTML = "<img src=medias/img/ico_delete2.gif>La clau de verificació ha de tenir 6 caràcters com a mínim.";
				document.getElementById('error2a').style.display='inline';
				envia1 = 0;
				document.getElementById('password1').focus();
			} else {
				document.getElementById('error2a').innerHTML = "";
				document.getElementById('error2a').style.display='none';
				envia1 = 1;
			}
			if ( ( envia1 == 1 ) && (password2.length < 6) )
			{
				document.getElementById('error2b').innerHTML = "<img src=medias/img/ico_delete2.gif>La clau de verificació ha de tenir 6 caràcters com a mínim.";
				document.getElementById('error2b').style.display='inline';
				envia2 = 0;
				document.getElementById('password2').focus();
			} else {
				document.getElementById('error2b').innerHTML = "";
				document.getElementById('error2b').style.display='none';
				envia2 = 1;
			}
			if ( ( envia1 == 1 ) && ( envia2 == 1 ) )
			{
				if ( password1 == password2 )
				{
					$('#mail').submit();
				} else {
					document.getElementById('error2b').innerHTML = "<img src=medias/img/ico_delete2.gif>Les dues claus no coincideixen, repassa-les i torna-ho a intentar.";
					document.getElementById('error2b').style.display='inline';
					envia2 = 0;
					document.getElementById('password2').focus();
					return false;
				}
			} else {
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO CORREU ----------------
		
		

		
		// ---------------- VALIDACIO ARTICLE ----------------
		
		function validarArticle()
		{
			tinyMCE.triggerSave(true, true);
			var msg = "";
			var titol = document.getElementById("titol2").value;
			var cos = document.getElementById("cos").value;
			if (titol == null || titol == '' ) { msg += "\n\tFalta el títol de l'article"; }
			if (cos == null || cos == '' || cos == "<br>") { msg += "\n\tFalta el cos de l'article"; }
			if ( msg == "")
			{
				$('#llhabilitats option').each(function(i) { $(this).attr("selected", "selected"); });
				$('#article').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO ARTICLE ----------------
		
		// ---------------- VALIDACIO ALBUM FOTOGRAFIES ----------------
		
		function validarAlbum()
		{
			var msg = "";
			tinyMCE.triggerSave(true, true);
			var titol = $('input[@name=titol2]').val();
			if (titol == null || titol == '') { msg += "\n\tFalta títol"; }
			if ( msg == "" )
			{
				$('#llhabilitats option').each(function(i) { $(this).attr("selected", "selected"); });
				$('#album').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO ALBUM FOTOGRAFIES ----------------
		
		// ---------------- VALIDACIO ARXIUS ----------------
		
		function validarCarpeta()
		{
			var msg = "";
			var titol = $('input[@name=nom]').val();
			if (titol == null || titol == ''){ msg = "\n\tFalta títol"; }
			if ( msg == "" )
			{
				$('#llhabilitats option').each(function(i) { $(this).attr("selected", "selected"); });
				$('#carpeta').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function veureCarpetes(opcio)
		{
			if ( opcio == "si" )
			{
				document.getElementById('llistaCarpetes').style.display='inline';
			} else {	
				document.getElementById('llistaCarpetes').style.display='none';
			}
		}
		
		// ---------------- FI VALIDACIO ARXIUS ----------------
		
		// ---------------- VALIDACIO AMICS ----------------
		
		function validarAmic()
		{
			var msg = "";
			var nom = $('input[@name=nom]').val();
			var email = $('input[@name=email]').val();
			var contrasenya = $('input[@name=contrasenya]').val();
			if (nom == null || nom == '') { msg += "\n\tFalta nom"; }
			if (email == null || email == '') { msg += "\n\tFalta e-mail"; }
			else
			{ if ( ! validarEmail(email) ) { msg += "\n\tE-mail no vàlid"; } }
			if (contrasenya == null || contrasenya == '') { msg += "\n\tFalta clau"; }
			
			if ( msg == "" )
			{
				$('#amic').submit();
			} else {
				alert(msg);
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO AMICS ----------------
		
		// ---------------- VALIDACIO RECEPTES ----------------
		
		function validarCategoria()
		{
			var msg = "";
			var nom = $('input[@name=nom]').val();
			if (nom == null || nom == '') { msg += "\n\tFalta el nom de la categoria"; }
			if ( msg == "" )
			{
				$('#categoria').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validarRecepta()
		{
			var msg = "";
			var titol = $('input[@name=titol2]').val();
			if (titol == null || titol == '') { msg += "\n\tFalta el nom de la recepta"; }
			if ( msg == "" )
			{
				$('#llhabilitats option').each(function(i) { $(this).attr("selected", "selected"); });
				$('#recepta').submit();
			} else {
				alert("Errors trobats:\n"+msg);
				return false;
			}
		}
		
		function validarPas()
		{
			tinyMCE.triggerSave(true, true);
			var msg = "";
			var temps = $('input[@name=temps]').val();
			var descripcio = document.getElementById("descripcio").value;
			if (temps == null || temps == '') { msg += "\n\tFalta temps"; }
			if (descripcio == null || descripcio == '' || descripcio == "<br>") { msg += "\n\tFalta descripció"; }
			if ( msg == "" )
			{
				$('#pas').submit();
			} else {
				alert("Errors trobats:\n"+msg);
				return false;
			}
		}
		
		// ---------------- FI VALIDACIO RECEPTES ----------------
		
		// ---------------- VALIDACIO ACTIVITATS ----------------
		
		function validarActivitat()
		{
			//tinyMCE.triggerSave(true, true);
			/*
			var nom = $('input[@name=nom]').val();
			var descripcio = $('input[@name=descripcio]').val();
			
			if (temps == null || temps == '')
			{
				document.getElementById('error1').innerHTML = "<img src=medias/img/ico_delete2.gif>Aquest camp és obligatori.";
				document.getElementById('error1').style.display='inline';
				envia = 0;
				document.getElementById('temps').focus();
			}
			else
			{
				document.getElementById('error1').innerHTML = "";
				document.getElementById('error1').style.display='none';
				envia = 1;
			}
			if (envia == 1)
			{
				if (descripcioPas == null || descripcioPas == '')
				{
					document.getElementById('error1').innerHTML = "<img src=medias/img/ico_delete2.gif>Aquest camp és obligatori.";
					document.getElementById('error1').style.display='inline';
					envia = 0;
					document.getElementById('descripcioPas').focus();
				}
				else
				{
					document.getElementById('error1').innerHTML = "";
					document.getElementById('error1').style.display='none';
					envia = 1;
				}
			}
			if ( envia == 1 )
			{
				$('#llhabilitats option').each(function(i) { $(this).attr("selected", "selected"); });
				$('#pas').submit();
			} else {
				return false;
			}
			*/
			$('#activitat').submit();
		}
		
		// ---------------- FI VALIDACIO ACTIVITATS ----------------
		
		// ---------------- FUNCIONS GENERALS ----------------
		
		function checkEnter(e,option)
		{	//e is event object passed from function invocation
			var characterCode // literal character code will be stored in this variable
			if(e && e.which) {
				//if which property of event object is supported (NN4)
				//character code is contained in NN4's which property
				e = e
				characterCode = e.which
			} else {
				//character code is contained in IE's keyCode property
				characterCode = e.keyCode
			}
			
			if(characterCode == 13) {
				//if generated character code is equal to ascii 13 (if enter key)
				validarUsuari();
				return false
			} else {
				return true
			}

		}
		
		function checkEnterVC(e,option)
		{	//e is event object passed from function invocation
			var characterCode // literal character code will be stored in this variable
			if(e && e.which) {
				//if which property of event object is supported (NN4)
				//character code is contained in NN4's which property
				e = e
				characterCode = e.which
			} else {
				//character code is contained in IE's keyCode property
				characterCode = e.keyCode
			}
			
			if(characterCode == 13) {
				//if generated character code is equal to ascii 13 (if enter key)
				validarRC3()();
				return false
			} else {
				return true
			}

		}
		
		function validarUsuari()
		{
			var msg = "";
			var usuariLogin = $('input[@name=usuariLogin]').val();
			var clauLogin = $('input[@name=clauLogin]').val();
			
			if (usuariLogin == null || usuariLogin == '') { msg += "\n\tFalta usuari"; }
			if (clauLogin == null || clauLogin == '') 	{ msg += "\n\tFalta clau"; }
			
			if ( msg == "" )
			{
				$('#autentificar').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function treureError()
		{
			document.getElementById('error').style.display='none';
			document.getElementById('autentificacio').style.display='inline';
		}
		
		function maxim(camp,limit)
		{
			if(camp.value.length>=limit)
			{
				camp.value = camp.value.substring(0,limit);
			}
		}
		
		
		function validarSuport()
		{
			var autentificacio = "";
			
			var nom = $('input[@name=nom]').val();
			var email = $('input[@name=email]').val();
			var desc = $('textarea[@name=desc]').val();
			
			if (nom == null || nom == '') 				{ autentificacio +=  "\n\tFalta nom"; }
			if (email == null || email == '')			{ autentificacio += "\n\tFalta e-mail";}
			if ( ! validarEmail(email) )				{ autentificacio += "\n\tE-mail erroni";}
			if (desc == null || desc == '')				{ autentificacio += "\n\tFalta la descripció del problema";}
			
			if ( autentificacio == "" )
			{
				$('#suport').submit();
			} else {
				alert("Errors trobats:\n" + autentificacio);
				return false;
			}
		}
		
		function esNumero(aValidar, long)
		{
			return /^[0-9]$/.test(aValidar);
		}
		
		function validaCP(aValidar)
		{
			return /^[0-9]{5}$/.test(aValidar);
		}
		
		function validarDNI(dni)
		{
			if ( esNumero( dni.substr(0,1) ) )
			{	// Ã‰s DNI
				var numero = dni.substr(0,8);
				var expreg = /^([0-9]{8})([T,R,W,A,G,M,Y,F,P,D,X,B,N,J,Z,S,Q,V,H,L,C,K,E,t,r,w,a,g,m,y,f,p,d,x,b,n,j,z,s,q,v,h,l,c,k,e]{1})$/;
			} else {
				// Ã‰s NIE
				var numero = dni.substr(1,7);
				var expreg = /^([K,L,M,X,k,l,m,x]{1})([0-9]{7})([T,R,W,A,G,M,Y,F,P,D,X,B,N,J,Z,S,Q,V,H,L,C,K,E,t,r,w,a,g,m,y,f,p,d,x,b,n,j,z,s,q,v,h,l,c,k,e]{1})$/;
			}
			var lletraFi 	= dni.substr(8,8);
			lletraFi 		= lletraFi.toUpperCase();
			var lletres		= 'TRWAGMYFPDXBNJZSQVHLCKET';
			var lletra 		= lletres.substring(numero%23,(numero%23)+1);
			if ( expreg.test(dni) && lletraFi == lletra ){ return true; } else { return false; }
		}
		
		function validarEmail(email)
		{
			re = /^[a-zA-Z0-9_\-\.]+(\+[a-zA-Z0-9_\-\.]+)*@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,4}$/;
			if( ! re.exec(email) )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function esValidUser(usuari)
		{
			re = /^[a-zA-Z0-9]{5,25}$/;
			if( ! re.exec(usuari) )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function esValidUser2(usuari)
		{
			// Per als mails d'usuaris avanÃ§ats, long minima 2.
			re = /^(([0-9a-zA-Z]+[-._])*[0-9a-zA-Z]+){2,25}$/;
			if( ! re.exec(usuari) )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function esValidDomini(domini)
		{
			re = /^([a-zA-Z0-9]+([\-]{0,1}[a-zA-Z0-9]+)){3,62}$/;
			if( ! re.exec(domini) )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function validarTelefon(tel)
		{
			tel = tel.split(" ").join("");
			tel = tel.split("-").join("");
			tel = tel.split(".").join("");
			
			re = /^(\+34)?(34)?([6,7,8,9]{1})([0-9]{8})$/;
			if( ! re.exec(tel) )
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		
		function validarEnviaFile()
		{
			var msg = "";
			var file = $('input[@name=userfile]').val();
			if (file == null || file == '') { msg += "\n\tFalta seleccionar l'arxiu"; }
			if ( msg == "" )
			{
				$('#file').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validarRC()
		{
			var msg = "";
			var usuari = $('input[@name=usuari]').val();
			var email = $('input[@name=email]').val();
			if (usuari == null || usuari == '') { msg += "\n\tFalta usuari"; }
			if (email == null || email == '') 	{ msg += "\n\tFalta e-mail"; }
			if ( ! validarEmail(email) ) 		{ msg += "\n\tE-mail no vàlid"; }
			
			if ( msg == "" )
			{
				$('#clau').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validarRC2()
		{
			var msg = "";
			var usuari = $('input[@name=usuari]').val();
			var email = $('input[@name=email]').val();
			var clau1 = $('input[@name=clau1]').val();
			var clau2 = $('input[@name=clau2]').val();
			var random = $('input[@name=random]').val();
			
			if ( usuari == null || usuari == '' ) 	{ msg += "\n\tFalta usuari"; }
			if ( email == null || email == '' ) 	{ msg += "\n\tFalta e-mail"; }
			if ( random == null || random == '' ) 	{ msg += "\n\tFalta la clau aleatòria"; }
			if ( ! validarEmail(email) ) 			{ msg += "\n\tE-mail no vàlid"; }
			if ( clau1 == null || clau1 == '' ) 	{ msg += "\n\tFalta clau nova"; }
			if ( clau2 == null || clau2 == '' ) 	{ msg += "\n\tFalta repetir clau nova"; }
			if ( clau1 != clau2 ) 					{ msg += "\n\tClaus diferents"; }
			
			if ( msg == "" )
			{
				$('#clau').submit();
			} else {
				alert("Errors trobats:\n" + msg);
				return false;
			}
		}
		
		function validarRC3()
		{
			
			var idClient = $('input[@name=idClient]').val();
			var clauv = $('input[@name=clauv]').val();
			
			if ( clauv == null || clauv == '' ) 	{ alert("Errors trobats: \n\tFalta entrar la clau actual."); }
			else {
				clauv2 = hex_md5(clauv);
				$.post("existeixJS.php",  { idClient: idClient, clauv: clauv2 }, function(data){
					if ( data != "" || data != null )
					{
						document.getElementById("existeix").innerHTML = data;
						validaRC3Final();
					}
				});
			}
		}
		
		function validaRC3Final()
		{
			var msg = "";
			var usuari = $('input[@name=usuari]').val();
			var clau1 = $('input[@name=clau1]').val();
			var clau2 = $('input[@name=clau2]').val();
			
			if ( clau1 == null || clau1 == '' ) 	{ msg += "\n\tFalta clau nova"; }
			if ( clau2 == null || clau2 == '' ) 	{ msg += "\n\tFalta repetir clau nova"; }
			else {
				if ( clau1.length < 6 ) 							{ msg += "\n\tLa clau ha de tenir un mínim de 6 caràcters"; }
				else {
					if (clau2.length < 6) 							{ msg += "\n\tLa repetició de la clau també ha de tenir un mínim de 6 caràcters"; }
				}
				if ( clau1 != clau2 ) 					{ msg += "\n\tClaus diferents"; }
				else {
					if ( usuari == clau1 ) 							{ msg += "\n\tEl nom d'usuari ha de ser diferent de la clau"; }
				}
			}
			if ( msg == "" )
			{
				if ( document.getElementById("existeix").innerHTML == "" )
				{
					$('#clau').submit();
				} else {
					alert("Errors trobats: \n" + document.getElementById("existeix").innerHTML);
					return false;
				}
			}else{
				alert("Errors trobats: \n" + msg);
				return false;
			}
		}
		
		
		function trim(cadena)
		{
			return cadena.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
		}