
function validaMail(str) {
	
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var not_correct= new Array('º','ª','\',','·','#','$','%','&','€','|','~','¬','/','(',')','=','?','¿','¡','!','^','`','´','[','+','*',']','{','ç','Ç','ñ','Ñ','}',',',';',':','"','\'','Á','À','Â','Ä','á','à','â','ä','É','È','Ê','Ë','é','è','ê','ë','Í','Ì','Î','Ï','í','ì','î','ï','Ó','Ò','Ô','Ö','ó','ò','ô','ö','Ú','Ù','Û','Ü','ú','ù','û','ü');
		
	for(i=0;i<not_correct.length;i++){
		if (str.indexOf(not_correct[i])!=-1){
			alert("Formato de E-mail incorrecto");
			return false;
		}
	}
	
	if (str.indexOf(at)==-1){
	   alert("Formato de E-mail incorrecto");
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Formato de E-mail incorrecto");
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Formato de E-mail incorrecto");
	    return false;
	}
	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Formato de E-mail incorrecto");
	    return false;
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   alert("Formato de E-mail incorrecto");
	    return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
	   alert("Formato de E-mail incorrecto");
	    return false;
	 }
	 if (str.indexOf(" ")!=-1){
	    alert("Formato de E-mail incorrecto");
	    return false;
	 }
	 return true;			
}


send = function(){
	formu2 = document.getElementById("form2");
	
	if (formu2.nombre.value == ''){
		alert("El campo nombre es obligatorio");
		formu2.nombre.focus();
		return;
	}else if (formu2.apellidos.value == ''){
		alert("El campo apellidos es obligatorio");
		formu2.apellidos.focus();
		return;
	}else if (formu2.email.value == ''){
		alert("El campo e-mail es obligatorio");
		formu2.email.focus();
		return;
	}else if (validaMail(formu2.email.value) == false){
		formu2.email.value = "";
		formu2.email.focus();
		return;	
	}else if (formu2.fileUpload.value == ''){
		alert("Es obligatorio adjuntar el CV");
		formu2.apellidos.focus();
		return;
	}else if(!formu2.checkcond.checked){
		alert("Debe aceptar la politica de proteccion de datos");
		formu2.checkcond.focus();
		return;		
	}else{
		document.getElementById('pujant').innerHTML = "<img src='../img/contacto/es_enviant.gif' />";

		formu2.submit();
	}
}

initform = function(){
	document.getElementById("form2").nombre.focus();
	formulari_sencer = document.getElementById("contingut_contact").innerHTML;
}

reinit = function(){
	document.getElementById("contingut_contact").innerHTML = formulari_sencer;
	document.getElementById("form2").nombre.focus();
}

privacitat = function() {
	javascript:window.open('privacidad.html','leg1','width=500,height=190,top='+((screen.height/2)-(265))+',left='+((screen.width/2)-(250))+',toolbar=no,scrollbars=yes,resizable=no,menubar=no,status=no,directories=no,location=no');
}


torna = function(){
	formu2 = document.getElementById("form2");
	document.getElementById('pujant').innerHTML = "<a href=\"javascript:send();\" onMouseOver=\"document.images[\'bt_send\'].src=bt_send_on.src;return true;\" onMouseOut=\"document.images[\'bt_send\'].src=bt_send_off.src;return true;\"><img id=\"bt_send\" src=\"../img/contacto/es_bt_enviar_off.gif\" border=\"0\" /></a>";
}

function resultatUpload(estat) {
 
	if (estat == 0){
		var mensaje = 'El CV se ha enviado correctamente';
		setTimeout("reinit()",2000);
	}
	if (estat == 1){
		var mensaje = 'Error en el envío, por favor int&eacute;ntelo de nuevo';
		setTimeout("torna()",500);
	}
	if (estat == 2){
		var mensaje = 'Error, el CV debe ser en formato pdf, doc, docx o txt';
		setTimeout("torna()",500);
	}
	if (estat == 3){
		var mensaje = 'Error, el CV debe tener un peso m&aacute;ximo de 1MB';
		setTimeout("torna()",500);
	}


	document.getElementById('respUpload').innerHTML=mensaje;
}
