// JavaScript Document

// textos por idiomas:
switch (jIdioma){
	case "cat":
		t_nombre = " · Nom\n";
		t_apellidos1 = " · 1r Cognom\n";
		t_apellidos2 = " · 2n Cognom\n";
		t_direccion = " · Carrer / plaça\n"
		t_poblacion = " · Municipi\n";
		t_cp = " · Codi postal\n";
		t_email = " · Adreça electrònica\n";
		t_telefono_m = " · Telèfon mòbil\n";
		t_telefono_f = " · Telèfon fix\n";
		t_curriculum = " · Currículum\n";
		t_condicions = "Ha d'acceptar les condicions de protecció de dades.\n";
		t_errordp = "Els següents camps han d´estar complets:\n";
		t_errorv = "Els següents camps han de ser vàlids:\n";
		t_confirm = "Estas segur que vols enviar?";
		break;
		
	case "esp":
		t_nombre = " · Nombre\n";
		t_apellidos1 = " · 1er Apellido\n";
		t_apellidos2 = " · 2o Apellido\n";
		t_direccion = " · Calle / plaza\n"
		t_poblacion = " · Municipio\n";
		t_cp = " · Código postal\n";
		t_email = " · Correo electrónico\n";
		t_telefono_m = " · Teléfono móvil\n";
		t_telefono_f = " · Teléfono fijo\n";
		t_curriculum = " · Currículum\n";
		t_condicions = "Debe aceptar las condiciones de protección de datos.\n";
		t_errordp = "Los siguientes campos deben estar completos:\n";
		t_errorv = "Los campos siguientes deben ser válidos:\n";
		t_confirm = "¿Estás seguro que quieres enviar?";
		break;
		
	case "eng":
		t_nombre = " · Name\n";
		t_apellidos = " · Surname\n";
		t_direccion = " · Address\n"
		t_poblacion = " · Town\n";
		t_cp = " · Post Code\n";
		t_email = " · E-mail\n";
		t_telefono_m = " · Telephone\n";
		t_telefono_f = " · Teléfono Fijo\n";
		t_curriculum = " · Currículum\n";
		t_errordp = "The following fields must be filled in:\n";
		t_errorv = "The following fields must be valid:\n";
		t_confirm = "Are you sure you want to send?";
		break;
}

// VALIDACIO FORMULARI
function validaFormDades(f){
	
	//mirar si los campos estan vacios
	var er_email = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;  
	var er_telf = /(^([0-9\s\+\-]+)|^)$/;   
	var er_num = /^(?:\+|-)?\d+$/;
	var er_cp = /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/;
	var er_data = /^(0[1-9]|[12][0-9]|3[01])(\/|-)(0[1-9]|1[012])\2(\d{4})$/;
	var er_dni = /^\w{5,20}$/;
	
	//mirar si los campos estan vacios
	if(f.nom.value.length < 2)		errordp += t_nombre;
	if(f.cognom1.value.length < 2)	errordp += t_apellidos1;
	if(f.cognom2.value.length < 2)	errordp += t_apellidos2;
	if(f.cp.value.length > 2 && !er_cp.test(f.cp.value))					errorv += t_cp;
	if(f.telefon_f.value.length > 2 && !er_telf.test(f.telefon_f.value))	errorv += t_telefono_f;
	if(f.telefon_m.value.length < 2 || !er_telf.test(f.telefon_m.value))	errorv += t_telefono_m;
	if(f.email.value.length < 2 || !er_email.test(f.email.value))			errorv += t_email;	
	if(f.curriculum.value == "")	errordp += t_curriculum;
	if(!f.condicions.checked)		errorp += t_condicions;	
}

//funcio per validar formulari
function validaForm(){
	var f = document.formulario;
	errordp = "";
	errorv = "";
	errorp = "";
	error = "";
	
	validaFormDades(f);
	
	if(errordp.length > 2 || errorv.length > 2 || errorp.length > 2) {  
		if (errordp.length > 2)	error += t_errordp+errordp+"\n";
		if (errorv.length > 2)	error += t_errorv+errorv+"\n";
		if (errorp.length > 2)	error += errorp+"\n";
		alert(error);
		return false;
	}else{
		//if(confirm(t_confirm)){
			f.action = "treballar_fgc.asp";
			f.submit();	
		//}		
	}
	return false;
}
