



function acceptar(){
    if(document.nou_usuari.accept.checked){
        document.nou_usuari.accept.checked = false;
        document.nou_usuari.submit();
    } else {
        alert("Debe aceptar el aviso legal");
    }
}

/// Funcions d'imatges ///


/**
   Carrega un conjunt d'imatges a un array, per cada imatge guarda la ruta.
   Rep per parï¿½metre un o mï¿½s literals, cada literal ï¿½s el valor del camp id 
   de la imatge que volem carregar.
*/
function carrega_imatge() {
    var d = document;
    if (d.images) {
    	if (!d.imatges)
    		d.imatges = new Array();
    	var i = d.imatges.length;
    	var a = carrega_imatge.arguments;
    	var img = '';
    	for (i = 0; i<a.length; i++) {
    		if (a[i].indexOf("#") != 0) {
    			img = d.getElementById(a[i]);
    			if (img != undefined) {
    				d.imatges[img.id] = new Image;
    				d.imatges[img.id].src = img.src;
    			}
    		}
    	}
    }
}
    
/**
	Canvia el valor (ruta) d'una imatge (imatge_old) per una nova (imatge_new).
 	@param imatge_old es un literal que indica el id de la imatge original.
 	@param imatge_new es un literal que indica el id de la nova imatge.
*/
function canvia_imatge(imatge_old, imatge_new) {
   	var o = document.getElementById(imatge_old);
   	var n = document.getElementById(imatge_new);
   	if ((o != undefined) && (n != undefined)) {
   		 if (o.src != n.src)
   		 	o.src = n.src;
	}
}

/**
	Restableix el valor (ruta) d'una imatge pel seu original. 
	@param imatge_old es un literal que indica el id de la imatge que volem<b>
	recuperar el seu valor (ruta) original. 
*/    
function restableix_imatge(imatge_old) {
   	var d = document;
  	if (d.imatges) {
   		var o = d.getElementById(imatge_old);
   		if (o != undefined)
   			o.src = d.imatges[imatge_old].src;
  			
   	}
}

function validaData(){
    if ((document.insertusua.password.value != '') && (document.insertusua.confirm.value != '') && (document.insertusua.nom.value != '') && (document.insertusua.llinatges.value != '') && (document.insertusua.mail.value != '') && (document.insertusua.usu_idioma.value != '')) {
      if(document.insertusua.password.value.length >= 6){
        if(document.insertusua.password.value == document.insertusua.confirm.value){
            if(echeck(document.insertusua.mail.value)){
                document.insertusua.submit();
           } else {
                alert('E-mail incorrecto');
            }
        } else {
            alert('El valor del Password y el Confirmar password deben coincidir.');
        }
      } else {
        alert('El campo password debe tener 6 carácters com a mínimo.');
      }
    } else {
      alert('Debe rellenar todos los campos con asterisco.');
    }
}

/**
 * Valida un e-mail
 */

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }

		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;
	}


function destriar(numero){
      if (numero == 1){
        document.llista.forma.value = "mod";
        document.llista.submit();
      }
      if (numero == 2){
        document.llista.forma.value = "del";
        document.llista.submit();
      }
}

function validaSend() {
    if ((document.email.direccio_desti.value != '') && (document.email.direccio_origen.value != '') && (echeck(document.email.direccio_origen.value)) && (echeck(document.email.direccio_desti.value))) {
        document.email.submit();
    } else {
      alert("Debe introducir las direcciones origen y destino");
    }
}

