// JavaScript Document

/** Variables globals */
var color_error_fons = "#FFEBEB";
var color_error_borde = "#D36164";
var color_ok_fons = "#FFFFFF";
var color_ok_borde = "#AAAAAA";

var missatge_error = "Por favor, rellena correctamente los campos en los que se han detectado errores";

var patro_base = /(\[)|(\])|(\()|(\))|(\<)|(\>)|(\')|(\")|(\?)|(\ż)|(\!)|(\ˇ)/;
var patro_mail = new RegExp("^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$","g");
var patro_llista_mails = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/;
var patro_link = new RegExp("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*$","g");
var patro_numeric = new RegExp("^[-+]?[0-9]+(\.[0-9]+)?$","g");
/*
function redirigeix(var url, var id){
	location.href = url+"?id="+id;	
}
*/
function focus_camp(camp){
	if (camp == 'nombre'){
		document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
	} else if (camp == 'username'){
		document.getElementById('tf_username').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_username').style.borderColor=color_ok_borde;
	} else if (camp == 'email'){		
		document.getElementById('tf_email').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_email').style.borderColor=color_ok_borde;
	} else if (camp == 'password'){
		document.getElementById('tf_password').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_password').style.borderColor=color_ok_borde;
	} else if (camp == 'link'){
		document.getElementById('tf_link').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_link').style.borderColor=color_ok_borde;
	} else if (camp == 'imagen'){
		document.getElementById('tf_imagen').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_imagen').style.borderColor=color_ok_borde;
	}  
	
}

function provaCompr(){
	/** Definició de patrons */
	
	var patroLink = new RegExp("^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*$","g");
	var patroBase =/(\[)|(\])|(\()|(\))|(\<)|(\>)|(\')|(\")|(\?)|(\ż)|(\!)|(\ˇ)/;
	
	/** Comprovació dels camps obligatoris */
	var nom = document.getElementById('tf_nombre').value;
	var username = document.getElementById('tf_username').value;
	var mail = document.getElementById('tf_email').value;
	var password = document.getElementById('tf_password').value;
	
	/** Comprovació caracters prohibits en camps generals */
	var t_nom = nom.match(patroBase); 	
	var t_username = username.match(patroBase);	
	
	/** Comprovació format correcte de camps especials */
	var res_mail = document.getElementById('tf_email').value.match(patroMail);	
	var linc = document.getElementById('tf_link').value;
	var res_linc = document.getElementById('tf_link').value.match(patroLink);
	//var imagen = document.getElementById('tf_imagen').value;
	//var res_imagen = document.getElementById('tf_imagen').value.match(patroLink);
	
	if (nom == "" || username == "" || mail == "" || password == "" || res_mail == null || t_nom !=null || t_username != null || (linc != "" && res_linc == null)/* || (imagen != "" && res_imagen == null)*/){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (nom == "" || t_nom != null){
			document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre').style.borderColor=color_error_borde;
		}
		if (username == "" || t_username != null){
			document.getElementById('tf_username').style.backgroundColor=color_error_fons;
			document.getElementById('tf_username').style.borderColor=color_error_borde;
		}
		if (mail == "" || res_mail == null){
			document.getElementById('tf_email').style.backgroundColor=color_error_fons;
			document.getElementById('tf_email').style.borderColor=color_error_borde;
		}
		if (password == ""){
			document.getElementById('tf_password').style.backgroundColor=color_error_fons;
			document.getElementById('tf_password').style.borderColor=color_error_borde;
		}
		if (linc != "" && res_linc == null){
			document.getElementById('tf_link').style.backgroundColor=color_error_fons;
			document.getElementById('tf_link').style.borderColor=color_error_borde;
		}
		/*
		if (imagen != "" && res_imagen == null){
			document.getElementById('tf_imagen').style.backgroundColor=color_error_fons;
			document.getElementById('tf_imagen').style.borderColor=color_error_borde;
		}
		*/
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		alert("Tot correcte");
	}
}

function mostra(){	
	document.getElementById('missatge-error').style.display = "block";
}
function modifica(){
	if (document.getElementById('missatge-error').value=="Missatge de la caixa modificat"){
		document.getElementById('missatge-error').value="Missatge2";		
	} else {
		document.getElementById('missatge-error').value="Missatge de la caixa modificat";		
	}
}

function elimina(){
	document.getElementById('missatge-error').value="Missatge de la caixa modificat";		
	document.getElementById('missatge-error').style.display = "none";
}

/************************************************
 * COMPROVACIÓ DE FORMULARIS
 */

/** FORMULARI D'IDENTIFICACIO */
function compFormIdentificacio(){	
	/** Comprovació dels camps obligatoris */		
	var username = document.getElementById('tf_username').value;	
	var password = document.getElementById('tf_password').value;
	
	/** Comprovació caracters prohibits en camps generals */	
	var t_username = username.match(patro_base);	
	var t_password = password.match(patro_base)
	
	if (username == "" || t_username != null || password == "" || t_password != null){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (username == "" || t_username != null){
			document.getElementById('tf_username').style.backgroundColor=color_error_fons;
			document.getElementById('tf_username').style.borderColor=color_error_borde;
		}
		if (password == "" || t_password != null){
			document.getElementById('tf_password').style.backgroundColor=color_error_fons;
			document.getElementById('tf_password').style.borderColor=color_error_borde;
		}
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}
}

function campsIdentificacio(camp){
	if (camp == 'username'){
		document.getElementById('tf_username').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_username').style.borderColor=color_ok_borde;
	} else if (camp == 'password'){
		document.getElementById('tf_password').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_password').style.borderColor=color_ok_borde;
	}
}

/** FORMULARI NOU USUARI */
function compFormRegistre(){	
	/** Comprovació dels camps obligatoris */		
	var nombre = document.getElementById('tf_nombre').value;
	var username = document.getElementById('tf_username').value;	
	var email = document.getElementById('tf_email').value;
	var password = document.getElementById('tf_password').value;
	
	/** Comprovació caracters prohibits en camps generals */	
	var t_nombre = nombre.match(patro_base);
	var t_username = username.match(patro_base);	
	var t_mail = email.match(patro_mail);
	var t_password = password.match(patro_base);
	
	if (nombre == "" || t_nombre != null || username == "" || t_username != null || email == "" || t_mail == null || password == "" || t_password != null){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (nombre == "" || t_nombre != null){
			document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre').style.borderColor=color_error_borde;
		}
		if (username == "" || t_username != null){
			document.getElementById('tf_username').style.backgroundColor=color_error_fons;
			document.getElementById('tf_username').style.borderColor=color_error_borde;
		}
		if (email == "" || t_mail == null){
			document.getElementById('tf_email').style.backgroundColor=color_error_fons;
			document.getElementById('tf_email').style.borderColor=color_error_borde;
		}
		if (password == "" || t_password != null){
			document.getElementById('tf_password').style.backgroundColor=color_error_fons;
			document.getElementById('tf_password').style.borderColor=color_error_borde;
		}
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}
}

function campsNouUsuari(camp){
	if (camp == 'username'){
		document.getElementById('tf_username').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_username').style.borderColor=color_ok_borde;
	} else if (camp == 'password'){
		document.getElementById('tf_password').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_password').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre'){
		document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
	} else if (camp == 'mail'){
		document.getElementById('tf_email').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_email').style.borderColor=color_ok_borde;
	}
}


/** FORMULARI NOVA LLISTA */
function compFormNovaLlista(){	
	/** Comprovació dels camps obligatoris */		
	var nombre = document.getElementById('tf_nombre').value;
	
	/** Comprovació caracters prohibits en camps generals */	
	var t_nombre = nombre.match(patro_base);
	
	if (nombre == "" || t_nombre != null){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
		document.getElementById('tf_nombre').style.borderColor=color_error_borde;
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}
}

function campsNovaLlista(){
	document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
	document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
}

 
function comprovaFormulariInvitacions(){
	
}

/** FORMULARI NOU ARTICLE */
function comprovaFormNouArticle(){
	/** Comprovació dels camps obligatoris */
	var nom = document.getElementById('tf_nombre').value;
		
	/** Comprovació caracters prohibits en camps generals */
	var t_nom = nom.match(patro_base); 	
	
	/** Comprovació format correcte de camps especials */
	var descripcio = document.getElementById('tf_descripcion').value;;
	var t_descripcio = descripcio.match(patro_base);
	var preu = document.getElementById('tf_precio').value;;
	var t_preu = preu.match(patro_numeric);	
	var linc = document.getElementById('tf_link').value;
	var res_linc = document.getElementById('tf_link').value.match(patro_link);
	//var imagen = document.getElementById('tf_imagen').value;
	//var res_imagen = document.getElementById('tf_imagen').value.match(patro_link);
	
	if (nom == "" || t_nom !=null || (descripcio != "" && t_descripcio != null) || (preu != "" && t_preu == null) || (linc != "" && linc != "http://" && res_linc == null)/* || (imagen != "" && res_imagen == null)*/){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (nom == "" || t_nom != null){
			document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre').style.borderColor=color_error_borde;
		}
		if (descripcio != "" && t_descripcio != null){
			document.getElementById('tf_descripcion').style.backgroundColor=color_error_fons;
			document.getElementById('tf_descripcion').style.borderColor=color_error_borde;
		}
		if (preu != "" && t_preu == null){
			document.getElementById('tf_precio').style.backgroundColor=color_error_fons;
			document.getElementById('tf_precio').style.borderColor=color_error_borde;
		}
		if (linc != "" && linc != "http://" && res_linc == null){
			document.getElementById('tf_link').style.backgroundColor=color_error_fons;
			document.getElementById('tf_link').style.borderColor=color_error_borde;
		}	
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();	
	}
}
 
function campsNouArticle(camp){
	if (camp == 'nombre'){
		document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
	} else if (camp == 'descripcion'){
		document.getElementById('tf_descripcion').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_descripcion').style.borderColor=color_ok_borde;
	} else if (camp == 'precio'){		
		document.getElementById('tf_precio').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_precio').style.borderColor=color_ok_borde;
	} else if (camp == 'link'){
		document.getElementById('tf_link').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_link').style.borderColor=color_ok_borde;
	}
}


/** FORMULARI NOU ARTICLE */
function comprovaFormCuentalo(){
	/** Comprovació dels camps obligatoris */
	var nom1 = document.getElementById('tf_nombre1').value;
	var mail1 = document.getElementById('tf_mail1').value;			
	var t_nom1 = nom1.match(patro_base); 	
	var t_mail1 = mail1.match(patro_mail);
	
	var nom2 = document.getElementById('tf_nombre2').value;
	var mail2 = document.getElementById('tf_mail2').value;			
	var t_nom2 = nom2.match(patro_base); 	
	var t_mail2 = mail2.match(patro_mail);
	
	var nom3 = document.getElementById('tf_nombre3').value;
	var mail3 = document.getElementById('tf_mail3').value;			
	var t_nom3 = nom3.match(patro_base); 	
	var t_mail3 = mail3.match(patro_mail);
	
	var nom4 = document.getElementById('tf_nombre4').value;
	var mail4 = document.getElementById('tf_mail4').value;			
	var t_nom4 = nom4.match(patro_base); 	
	var t_mail4 = mail4.match(patro_mail);
	
	var nom5 = document.getElementById('tf_nombre5').value;
	var mail5 = document.getElementById('tf_mail5').value;			
	var t_nom5 = nom5.match(patro_base); 	
	var t_mail5 = mail5.match(patro_mail);
	
	if (nom1 == "" || t_nom1 != null || mail1 == "" || t_mail1 == null || 
		(nom2 != "" && t_nom2 != null) || (mail2 != "" && t_mail2 == null) ||
		(nom3 != "" && t_nom3 != null) || (mail3 != "" && t_mail3 == null) ||
		(nom4 != "" && t_nom4 != null) || (mail4 != "" && t_mail4 == null) ||
		(nom5 != "" && t_nom5 != null) || (mail5 != "" && t_mail5 == null)	
	   ){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		/* amic 1 */
		if (nom1 == "" || t_nom1 != null){
			document.getElementById('tf_nombre1').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre1').style.borderColor=color_error_borde;
		}
		if (mail1 == "" || t_mail1 == null){
			document.getElementById('tf_mail1').style.backgroundColor=color_error_fons;
			document.getElementById('tf_mail1').style.borderColor=color_error_borde;
		}
		/* amic 2 */
		if (nom2 != "" && t_nom2 != null){
			document.getElementById('tf_nombre2').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre2').style.borderColor=color_error_borde;
		}
		if (mail2 != "" && t_mail2 == null){
			document.getElementById('tf_mail2').style.backgroundColor=color_error_fons;
			document.getElementById('tf_mail2').style.borderColor=color_error_borde;
		}
		/* amic 3 */
		if (nom3 != "" && t_nom3 != null){
			document.getElementById('tf_nombre3').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre3').style.borderColor=color_error_borde;
		}
		if (mail3 != "" && t_mail3 == null){
			document.getElementById('tf_mail3').style.backgroundColor=color_error_fons;
			document.getElementById('tf_mail3').style.borderColor=color_error_borde;
		}
		/* amic 4 */
		if (nom4 != "" && t_nom4 != null){
			document.getElementById('tf_nombre4').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre4').style.borderColor=color_error_borde;
		}
		if (mail4 != "" && t_mail4 == null){
			document.getElementById('tf_mail4').style.backgroundColor=color_error_fons;
			document.getElementById('tf_mail4').style.borderColor=color_error_borde;
		}
		/* amic 5 */
		if (nom5 != "" && t_nom5 != null){
			document.getElementById('tf_nombre5').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre5').style.borderColor=color_error_borde;
		}
		if (mail5 != "" && t_mail5 == null){
			document.getElementById('tf_mail5').style.backgroundColor=color_error_fons;
			document.getElementById('tf_mail5').style.borderColor=color_error_borde;
		}		
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();	
	}
}
 
function campsCuentalo(camp){
	if (camp == 'nombre1'){
		document.getElementById('tf_nombre1').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre1').style.borderColor=color_ok_borde;
	} else if (camp == 'mail1'){
		document.getElementById('tf_mail1').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_mail1').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre2'){
		document.getElementById('tf_nombre2').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre2').style.borderColor=color_ok_borde;
	} else if (camp == 'mail2'){
		document.getElementById('tf_mail2').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_mail2').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre3'){
		document.getElementById('tf_nombre3').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre3').style.borderColor=color_ok_borde;
	} else if (camp == 'mail3'){
		document.getElementById('tf_mail3').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_mail3').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre4'){
		document.getElementById('tf_nombre4').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre4').style.borderColor=color_ok_borde;
	} else if (camp == 'mail4'){
		document.getElementById('tf_mail4').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_mail4').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre5'){
		document.getElementById('tf_nombre5').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre5').style.borderColor=color_ok_borde;
	} else if (camp == 'mail5'){
		document.getElementById('tf_mail5').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_mail5').style.borderColor=color_ok_borde;
	} 
}

/** FORMULARI CANVI DADES USUARI */
function compFormDatos(){	
	/** Comprovació dels camps obligatoris */		
	
	var nombre = document.getElementById('tf_nombre').value;
	var username = document.getElementById('tf_username').value;	
	var email = document.getElementById('tf_email').value;
	
	if (document.getElementById('tf_antic_password') != null){		
		var old_password = document.getElementById('tf_antic_password').value;
		var new_password = document.getElementById('tf_nou_password').value;
		var new_password2 = document.getElementById('tf_nou_password2').value;
	}
	
	/** Comprovació caracters prohibits en camps generals */	
	var t_nombre = nombre.match(patro_base);
	var t_username = username.match(patro_base);	
	var t_mail = email.match(patro_mail);
	
	if (document.getElementById('tf_antic_password') != null){		
		var t_old_password = old_password.match(patro_base);
		var t_new_password = new_password.match(patro_base);
		var t_new_password2 = new_password2.match(patro_base);
	}
		
	if (nombre == "" || t_nombre != null || username == "" || t_username != null || email == "" || t_mail == null ||
		(document.getElementById('tf_antic_password') != null && (old_password == "" || t_old_password != null || new_password == "" || t_new_password != null || new_password2 == "" || t_new_password2 != null)) ||
		(document.getElementById('tf_antic_password') != null && (new_password != new_password2))
		){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (nombre == "" || t_nombre != null){
			document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre').style.borderColor=color_error_borde;
		}
		if (username == "" || t_username != null){
			document.getElementById('tf_username').style.backgroundColor=color_error_fons;
			document.getElementById('tf_username').style.borderColor=color_error_borde;
		}
		if (email == "" || t_mail == null){
			document.getElementById('tf_email').style.backgroundColor=color_error_fons;
			document.getElementById('tf_email').style.borderColor=color_error_borde;
		}
		if (document.getElementById('tf_antic_password') != null){
			if (old_password == "" || t_old_password != null){
				document.getElementById('tf_antic_password').style.backgroundColor=color_error_fons;
				document.getElementById('tf_antic_password').style.borderColor=color_error_borde;
			}
			if (new_password == "" || t_new_password != null || new_password != new_password2){
				document.getElementById('tf_nou_password').style.backgroundColor=color_error_fons;
				document.getElementById('tf_nou_password').style.borderColor=color_error_borde;
			}
			if (new_password2 == "" || t_new_password2 != null || new_password != new_password2){
				document.getElementById('tf_nou_password2').style.backgroundColor=color_error_fons;
				document.getElementById('tf_nou_password2').style.borderColor=color_error_borde;
			}
		}
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}
}

function campsDatos(camp){
	if (camp == 'username'){
		document.getElementById('tf_username').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_username').style.borderColor=color_ok_borde;
	} else if (camp == 'nombre'){
		document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
	} else if (camp == 'mail'){
		document.getElementById('tf_email').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_email').style.borderColor=color_ok_borde;
	} else if (camp == 'old_password'){
		document.getElementById('tf_antic_password').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_antic_password').style.borderColor=color_ok_borde;
	} else if (camp == 'new_password1'){
		document.getElementById('tf_nou_password').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nou_password').style.borderColor=color_ok_borde;
	} else if (camp == 'new_password2'){
		document.getElementById('tf_nou_password2').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nou_password2').style.borderColor=color_ok_borde;
	}
}


/** FORMULARI INVITACIÓ A LLISTA */
function compFormInvitados(){	
	/** Comprovació dels camps obligatoris */		
	
	var llista_mails = document.getElementById('tf_invitados').value;
	
	if (llista_mails != ""){
		var t_llista_mails = llista_mails.match(patro_llista_mails);
		if (t_llista_mails == null){			
			/* {error detectat} --> es mostra el missatge d'error */
			document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
			document.getElementById('missatge-error').style.display = "block";
			/* es marca el camp de text dels emails */
			document.getElementById('tf_invitados').style.backgroundColor=color_error_fons;
			document.getElementById('tf_invitados').style.borderColor=color_error_borde;
		} else {
			/* {no s'han detectat errors} --> s'envia el formulari */
			document.getElementById('missatge-error').style.display = "none";
			document.forms['form1'].submit();
		}		
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}	
}

function campsInvitados(){
	document.getElementById('tf_invitados').style.backgroundColor=color_ok_fons;
	document.getElementById('tf_invitados').style.borderColor=color_ok_borde;
}



/** FORMULARI CONTACTE */
function compFormContacto(){	
	/** Comprovació dels camps obligatoris */			
	var nombre = document.getElementById('tf_nombre').value;
	var email = document.getElementById('tf_email').value;
	var text = document.getElementById('ta_texto').value;
		
	/** Comprovació caracters prohibits en camps generals */	
	var t_nombre = nombre.match(patro_base);	
	var t_mail = email.match(patro_mail);	
	
	if (nombre == "" || t_nombre != null || email == "" || t_mail == null || text == ""){
		/* {error detectat} --> es mostra el missatge d'error */
		document.getElementById('missatge-error').value="Por favor, rellena correctamente los campos en los que se han detectado errores";
		document.getElementById('missatge-error').style.display = "block";
		
		/* marquem els camps on s'han detectat errors */		
		if (nombre == "" || t_nombre != null){
			document.getElementById('tf_nombre').style.backgroundColor=color_error_fons;
			document.getElementById('tf_nombre').style.borderColor=color_error_borde;
		}
		if (email == "" || t_mail == null){
			document.getElementById('tf_email').style.backgroundColor=color_error_fons;
			document.getElementById('tf_email').style.borderColor=color_error_borde;
		}
		if (text == ""){
			document.getElementById('ta_texto').style.backgroundColor=color_error_fons;
			document.getElementById('ta_texto').style.borderColor=color_error_borde;
		}
	} else {
		/* {no s'han detectat errors} --> s'envia el formulari */
		document.getElementById('missatge-error').style.display = "none";
		document.forms['form1'].submit();
	}
}

function campsContacto(camp){
	if (camp == 'nombre'){
		document.getElementById('tf_nombre').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_nombre').style.borderColor=color_ok_borde;
	}else if (camp == 'mail'){
		document.getElementById('tf_email').style.backgroundColor=color_ok_fons;
		document.getElementById('tf_email').style.borderColor=color_ok_borde;
	} else if (camp == 'texto'){
		document.getElementById('ta_texto').style.backgroundColor=color_ok_fons;
		document.getElementById('ta_texto').style.borderColor=color_ok_borde;
	}
}
