window.onload = function() {
   if (!document.getElementsByTagName) return false;
   var links = document.getElementsByTagName("a");
   for (var i=0; i<links.length; i++) {
      if (links[i].getAttribute("rel") == "external") {
         links[i].onclick = function() {
            return !window.open(this.href);
         }
      }
   }
}

function canviFotoProj(idProj, num_foto, total_fotos){
	var inner = "";
	for(i=1; i<=total_fotos; i++){
		if(num_foto == i){
			document.getElementById('foto_'+idProj+'_'+i).style.display='';
			inner += '<li><span>'+i+'</span></li>';
		} else{
			document.getElementById('foto_'+idProj+'_'+i).style.display='none';
			inner += '<li><a class="link_imatges_numeret" href="javascript:canviFotoProj('+idProj+','+i+','+total_fotos+')">'+i+'</a></li>';
		}
	}
	document.getElementById('ul_'+idProj).innerHTML = inner;
}

function ValidaFormUnete(){
	var formulari=document.getElementById('form_unete');
	var mida=formulari.length;
	var control=0;
	var i=0;
	while (i<mida) {
		if(formulari[i].id=='nom'){
			if( formValidaPle(formulari[i].value)==false ) {
				control=1;
				document.getElementById("label_"+formulari[i].id).style.color="#990000";
			} else{
				document.getElementById("label_"+formulari[i].id).style.color="#999999";
			}
		} else if(formulari[i].id=='correo'){
			if( formValidaCorreu(formulari[i].value)==false ) {
				control=1;
				document.getElementById("label_"+formulari[i].id).style.color="#990000";
			} else{
				document.getElementById("label_"+formulari[i].id).style.color="#999999";
			}
		}
		i++;
	}
	if(control==0){
		document.getElementById('capa_error').style.display='none';
		return true;
	}
	else{
		// Hi ha algun error al formulari
		document.getElementById('capa_error').style.display='';
		return false;		
	}	
}

function formValidaPle(valor) {
	var j;
	for ( j = 0; j < valor.length; j++ ) {
		if ( valor.charAt(j) != " " ) {
			return true;
		}
	}
	return false;
}

function formValidaCorreu(email){
	var RegExPattern = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	if (email.match(RegExPattern)){
		return true;
	} else{
		return false;
	}
}