var idioma;

var empreses = new Array();
var estudis = new Array();
var estudisNoReglats = new Array();

for(i=0; i<=4; i++){
	empreses[i] = false;
	estudis[i] = false;
	estudisNoReglats[i] = false;
}


//Funcions per amagar o mostrar taules del formulari de CV.
 function tblVisible(taula){
 
	document.getElementById(taula).style.display='';
}

 function tblNoVisible(taula){
 
	document.getElementById(taula).style.display="none";
}

/*Funcio que mostra un select o un altre en funcio del que s'esculli a l'apartat "com ens has conegut"*/
function Conegut(com, quinaEmpresa, quinaEmpresaTreballa)
{
	if(com == "MÀ")
	{
		tblVisible('tblEmpresaGS');
		tblNoVisible('tblReferent');
		document.getElementById('lblQuinaEmpresa').innerHTML = quinaEmpresa + ':&nbsp;';
	}
	else if (com == "CONEGUT")
	{
		tblVisible('tblEmpresaGS');
		tblVisible('tblReferent');
		document.getElementById('lblQuinaEmpresa').innerHTML = quinaEmpresaTreballa + ':&nbsp;';
	}
	else
	{
		tblNoVisible('tblEmpresaGS');
		tblNoVisible('tblReferent');
		document.getElementById('lblQuinaEmpresa').innerHTML = '&nbsp';
	}
}

/* Funcio que si en "nacionalitat" s'escull "altres" es mostra si es comunitari o no; si ho es permet introduir les dates del seu permis */
function canviaNacionalitat(nac)
{
	if(nac == "2"){
		for(i=0;i<document.cv.rdoComunitari.length;i++)
			document.cv.rdoComunitari[i].disabled=false;
		
		tblVisible('tblPaisNac');		
	}
	else
	{
		document.cv.rdoComunitari[0].checked = true;
		document.cv.rdoComunitari[1].checked = false;
		
		for(i=0;i < document.cv.rdoComunitari.length; i++)
			document.cv.rdoComunitari[i].disabled=true;
			
		tblNoVisible('tblPermis'); //Taula que mostra la data del permis de residencia i de treball.
		tblNoVisible('tblPaisNac'); //Taula que mostra el pais de la seva nacionalitat.
	}
		
}

function comprobarSubArea(val, EmpresaN)
{
	if(EmpresaN != 6){ //Si es diferent de 6 sera una empresa de "Experiencia laboral", si es 6, significa que es la subarea de "Futur treball"
		if(val == "Especificar"){
			document.getElementById("txtSubArea1Empresa" + EmpresaN).disabled = false;
			document.getElementById("divlblSubArea1Empresa" + EmpresaN).style.display = '';
			document.getElementById("divtxtSubArea1Empresa" + EmpresaN).style.display = '';
		}
		else{
			document.getElementById("txtSubArea1Empresa" + EmpresaN).disabled = true;
			document.getElementById("txtSubArea1Empresa" + EmpresaN).value = "";
			document.getElementById("divlblSubArea1Empresa" + EmpresaN).style.display = 'none';
			document.getElementById("divtxtSubArea1Empresa" + EmpresaN).style.display = 'none';
		}
	}
	else
	{
		if(val == "Especificar"){
			document.getElementById("txtAltraSubAreaDemandada1").disabled = false;
			document.getElementById("divlblAltraSubAreaDemandada1").style.display = '';
			document.getElementById("divtxtAltraSubAreaDemandada1").style.display = '';
		}
		else{
			document.getElementById("txtAltraSubAreaDemandada1").disabled = true;
			document.getElementById("txtAltraSubAreaDemandada1").value = "";
			document.getElementById("divlblAltraSubAreaDemandada1").style.display = 'none';
			document.getElementById("divtxtAltraSubAreaDemandada1").style.display = 'none';
		}
	}
}

/* Es mostra els camps per indicar la data del seu permis de residencia i/o de treball */
function Comunitari()
{ 
	if (document.cv.rdoComunitari[1].checked)
		tblVisible('tblPermis');
	else
		tblNoVisible('tblPermis');
}

/*Funcio que activa o desactiva les blocs de "Experiencia laboral" en funcio de si treballa actualment o no i si es la feina actual o no.*/
function treballActualment()
{
	if (document.cv.rdoTreballaActualment[1].checked){
		tblVisible('tblDataFiEmpresa1'); 
		tblVisible('tblMotiuFi');
	}
	else
	{
		tblNoVisible('tblDataFiEmpresa1'); 
		tblNoVisible('tblMotiuFi');
	}
}

/*
* Funcio que mostra la primera taula d'Experiencia Laboral, en el cas que es marqui l'opcio "Disposes d'alguna exp. laboral = si"
* Si es marca "NO" exp ser� = false i la taula sempre sera 1 (perque nomes es crida pel primer cop d'experiencia laboral),
* llavors les demes "experiencies" s'esborraran.
* @param exp 	De tipus boolea, si es true es mostra la primera taula d'experiencia, sino, s'amaguen totes (i es netejaran els camps).
*/
function teExperiencia(exp)
{
	if(exp){
		tblVisible('tblEmpresaRecent1');
		empreses[0] = true;
	}
	else
	{
		mesExperiencia(exp,1);
		empreses[0] = false;
	}
}

/*
* Funcio que mostra la "taula seguent" d'experiencia, en el cas "exp = true",
* sino elimina aquesta taula (i els seus valors) i les posteriors.
* En el cas que la taula sigui la 1ra o la 2na el radio button de la taula "Experiencia 1" es posara a "true" 
* ( "�s l'�nica experi�ncia laboral de la qual disposes: SI" )
* @param exp		boolea, indica si s'ha d'amagar una taula o mostrar-se
* @param empresaN 	enter, Numero de taula que s'ha d'amagar (i a partir d'aquesta les posteriors) o mostrar-se.
*/
function mesExperiencia (exp, empresaN)
{
	if(exp){
		tblVisible('tblEmpresaRecent' + empresaN);
		empreses[empresaN - 1] = true;
	}
	else
	{
		for(i=1; i<=5; i++)
		{
			if(i == empresaN || i > empresaN)
			{
				tblNoVisible('tblEmpresaRecent' + i);
				netejarCampsExpLab(i);
				empreses[i - 1] = false;
			}
		}

		if(empresaN == 1 || empresaN == 2)
		{
			document.cv.rdoUnicaExpLaboral[0].checked = true;
			document.cv.rdoUnicaExpLaboral[1].checked = false;
		}
	}
}

/*
* Funcio que neteja tots els camps d'una taula de tipus "experiencia laboral"
* @param tableExpN	Numero de taula que s'han de netejar els camps.
*/
function netejarCampsExpLab(tableExpN)
{
	document.getElementById('txtNomEmpresa' + tableExpN).value = "";
	document.getElementById('txtWebEmpresa' + tableExpN).value = "";
	document.getElementById('txtMunicipiEmpresa' + tableExpN).value = "";
	document.getElementById('txtLlocTreballEmpresa' + tableExpN).value = "";
	document.getElementById('cboCategoriaEmpresa' + tableExpN).selectedIndex = 0;
	document.getElementById('cboArea1Empresa' + tableExpN).selectedIndex = 0;
	document.getElementById('cboSubArea1Empresa' + tableExpN).selectedIndex = 0;
	document.getElementById('txtSubArea1Empresa' + tableExpN).value = "";
	document.getElementById('cboSectorEmpresa' + tableExpN).selectedIndex = 0;
	document.getElementById('txtFuncionsEmpresa' + tableExpN).value = "";
	document.getElementById('cboIniciEmpresa' + tableExpN + 'Dia').selectedIndex = 0;
	document.getElementById('cboIniciEmpresa' + tableExpN + 'Mes').selectedIndex = 0;
	document.getElementById('cboIniciEmpresa' + tableExpN + 'Any').selectedIndex = 0;
	document.getElementById('cboFiEmpresa' + tableExpN + 'Dia').selectedIndex = 0;
	document.getElementById('cboFiEmpresa' + tableExpN + 'Mes').selectedIndex = 0;
	document.getElementById('cboFiEmpresa' + tableExpN + 'Any').selectedIndex = 0;
	document.getElementById('txtMotiuFiEmpresa' + tableExpN).value = "";
	document.getElementById('cboSalariBrutAnualEmpresa' + tableExpN).selectedIndex = 0;
}

/*
* Funcio que mostra la "taula seguent" d'estudis reglats, en el cas "mes = true",
* sino elimina aquesta taula (i els seus valors) i les posteriors.
* @param mes		boolea, indica si s'ha d'amagar una taula o mostrar-se
* @param estudiN 	enter, Numero de taula que s'ha d'amagar (i a partir d'aquesta les posteriors) o mostrar-se.
*/
function mesEstudisReglats (mes, estudiN)
{
	if(mes){
		tblVisible('tblEstudisReglats' + estudiN);
		estudis[estudiN - 1] = true;
	}
	else
	{
		for(i=1; i<=5; i++)
		{
			if(i == estudiN || i > estudiN)
			{
				tblNoVisible('tblEstudisReglats' + i);
				netejarCampsEstudi(i);
				estudis[estudiN - 1] = false;
			}
		}
	}
}

function senseEstudis(val){
	if(val == 1){
		tblNoVisible('tblEstudisReglats1');
		tblNoVisible('linkMesEstudis1');
	}
	else{
		tblVisible('tblEstudisReglats1');
		tblVisible('linkMesEstudis1');
	}
}

/*
* Funcio que neteja tots els camps d'una taula de tipus "estudis reglats"
* @param tableEstudiN	Numero de taula que s'han de netejar els camps.
*/
function netejarCampsEstudi(tableEstudiN)
{
	document.getElementById('cboNivellEstudis' + tableEstudiN).selectedIndex = 0;
	document.getElementById('cboTitolEstudis' + tableEstudiN).selectedIndex = 0;
	document.getElementById('txtCentreEstudis' + tableEstudiN).value = "";
	document.getElementById('txtMunicipiEstudis' + tableEstudiN).value = "";
	document.getElementById('cboDataIniciEstudis' + tableEstudiN + 'Dia').selectedIndex = 0;
	document.getElementById('cboDataIniciEstudis' + tableEstudiN + 'Mes').selectedIndex = 0;
	document.getElementById('cboDataIniciEstudis' + tableEstudiN + 'Any').selectedIndex = 0;
	document.getElementById('cboDataFiEstudis' + tableEstudiN + 'Dia').selectedIndex = 0;
	document.getElementById('cboDataFiEstudis' + tableEstudiN + 'Mes').selectedIndex = 0;
	document.getElementById('cboDataFiEstudis' + tableEstudiN + 'Any').selectedIndex = 0;
	document.getElementById('txtNumCursosRealitzatsEstudis' + tableEstudiN).value = "";
}

/*
* Funcio que mostra la "taula seguent" de formacio no reglada, en el cas "mes = true",
* sino elimina aquesta taula (i els seus valors) i les posteriors.
* @param mes		boolea, indica si s'ha d'amagar una taula o mostrar-se
* @param estudiN 	enter, Numero de taula que s'ha d'amagar (i a partir d'aquesta les posteriors) o mostrar-se.
*/
function mesFormacioNoReglada(mes, formacioN)
{
	if(mes){
		tblVisible('tblFormacioNoReglada' + formacioN);
		estudisNoReglats[formacioN - 1] = true;
	}
	else
	{
		for(i=1; i<=5; i++)
		{
			if(i == formacioN || i > formacioN)
			{
				tblNoVisible('tblFormacioNoReglada' + i);
				netejarCampsFormacio(i);
				estudisNoReglats[formacioN - 1] = false;
			}
		}
	}
}

/*
* Funcio que neteja tots els camps d'una taula de tipus "formacio no reglada"
* @param tableFormacioN	Numero de taula que s'han de netejar els camps.
*/
function netejarCampsFormacio(tableFormacioN)
{
	document.getElementById('txtEstudiNoReglat' + tableFormacioN).value = "";
	document.getElementById('txtCentreEstudiNoReglat' + tableFormacioN).value = "";
	document.getElementById('txtMunicipiEstudiNoReglat' + tableFormacioN).value = "";
	document.getElementById('cboDataIniciEstudiNoReglat' + tableFormacioN + 'Dia').selectedIndex = 0;
	document.getElementById('cboDataIniciEstudiNoReglat' + tableFormacioN + 'Mes').selectedIndex = 0;
	document.getElementById('cboDataIniciEstudiNoReglat' + tableFormacioN + 'Any').selectedIndex = 0;
	document.getElementById('cboDataFiEstudiNoReglat' + tableFormacioN + 'Dia').selectedIndex = 0;
	document.getElementById('cboDataFiEstudiNoReglat' + tableFormacioN + 'Mes').selectedIndex = 0;
	document.getElementById('cboDataFiEstudiNoReglat' + tableFormacioN + 'Any').selectedIndex = 0;
	document.getElementById('txtNumHoresEstudiNoReglat' + tableFormacioN).value = "";
	document.getElementById('cboModalitatEstudiNoReglat' + tableFormacioN).selectedIndex = 0;

}

/***************************************************/
/*												   */
/*				VALIDACIONS DE FORMULARIS		   */
/*												   */
/***************************************************/


/***************************************************/
/*												   */
/*		  Valida el formulari de contacte		   */
/*												   */
/***************************************************/

function validar(f,id,url)
{
	idioma = id;
	
	if (EstanLlenos(f) && EsNumero(f) && ValidaEmail(f) && Condicions(f))
	{
		//Datos validados
		
		enviaForm(url, "contacte"); //URL = seccion que gestiona los datos, "FormID" = Id del formulario
	}
}

/***************************************************/
/*												   */
/*     Valida el formulari de Modificacio de CV    */
/*												   */
/***************************************************/

function validarLoginCv(f, id, url)
{
	idioma = id;
	
	if(f.txtUser.value != '' && f.txtPass.value != ''){
		/*
		if(idioma == 1)
			jQuery("#divContinguts").html('<div style="text-align:center;width:100%"><img src="/imgfiles/GrupSerhs/img/loading_ajax.gif" /><p class="text" style="text-align:center"><br />Estem validant les vostres dades...</p></div>');
		else if(idioma == 2)
			jQuery("#divContinguts").html('<div style="text-align:center;width:100%"><img src="/imgfiles/GrupSerhs/img/loading_ajax.gif" /><p class="text" style="text-align:center"><br />Estamos validando sus datos...</p></div>');
		*/
		
		enviaForm(url, "LoginCv"); //URL = seccion que gestiona los datos, "FormID" = Id del formulario
	}
	else
	{
		if(f.txtUser.value == ''){
			f.txtUser.focus();
			
			if(idioma == 1)
				alert ('*Camp obligatori.');
			else if (idioma == 2)
				alert ('*Campo obligatorio.');
		}
		else if(f.txtPass.value == '')
		{
			f.txtPass.focus();
			
			if(idioma == 1)
				alert ('*Camp obligatori.');
			else if (idioma == 2)
				alert ('*Campo obligatorio.');
		}
		
	}
	
}
	
function EstanLlenos(f)
{ 
	var i=0;
	var trobat=false;
	
	while (i<f.length-1 && !trobat)
	{
		if(	f.elements[i].value=="" && (f.elements[i].type=="text" || f.elements[i].type=="textarea") && 
			f.elements[i].name != "empresa" && f.elements[i].name != "adresa" && 
			f.elements[i].name != "cp" && f.elements[i].name != "poblacio" ) 
		{
			if(idioma == 1)
				alert ('*Camp obligatori.');
			else if (idioma == 2)
				alert ('*Campo obligatorio.');
		
			trobat=true;
			f.elements[i].focus();
		}
		i++;
	}
		
	return !trobat;
}

function EsNumero(f)
{
	var i=0;
	var trobat=false;
	while (i<f.length-1 && !trobat)
	{	
		if(f.elements[i].name == "telefon" || (f.elements[i].name == "cp" && f.elements[i].value!=""))
		{
			if(isNaN(f.elements[i].value))
			{ 
				if(idioma == 1)
					alert ('Introdueixi un n\u00famero v\u00E0lid.');
				else if (idioma == 2)
					alert ('Introduzca un n\u00famero v\u00E1lido.');
				
				trobat=true;
				f.elements[i].select();
			}
			else
			{
				if (f.elements[i].name == "telefon" && f.elements[i].value.length != 9)
				{
					if(idioma == 1)
						alert ('El n\u00famero de tel\u00E8fon ha de tenir 9 d\u00EDgits.');
					else if (idioma == 2)
						alert ('El n\u00famero tel\u00E9fono debe tener 9 digitos.');
					trobat=true;
					f.elements[i].select();
				}
					
			}
		}
		i++;
	}
	return !trobat;
}

function ValidaEmail(f)
{
	var ok=false;

	var arroba = f.email.value.indexOf('@',0);
	var punt = f.email.value.indexOf('.',arroba);
	
	if(arroba == -1 || punt == -1 || punt == f.email.value.length-1 || arroba + 1 == punt)
	{
		if(idioma == 1)
			alert ('Email incorrecte.');
		else if (idioma == 2)
			alert ('Email incorrecto.');

		f.email.select();
	}
	else
		ok=true;
		
	return ok;
}

function Condicions(f)
{
	var ok = false;
	
	if(f.chkLlei.checked == true)
		ok = true;
	else
	{
		if(idioma == 1)
			alert ('Llegeixi i accepti la Cl\u00E1usula de Compliment de la Llei Org\u00E0nica de Protecci\u00F3 de Dades de Car\u00E0cter Personal.');
		else if (idioma == 2)
			alert ('Lea y acepte la Cl\u00E1usula de Cumplimiento de la Ley Org\u00E1nica de Protecci\u00F3n de Datos de Car\u00E1cter Personal.');
			
		f.chkLlei.focus();
	}
	return ok;
}

/***************************************************/
/*												   */
/*		  Valida el formulari d'enviament		   */
/*		       d'oferta de feina				   */
/*												   */
/***************************************************/

function validaEnviaAmic(f,id,url)
{
	idioma = id;
	
	if (ValidaEmail(f))
	{
		//Datos validados
		
		enviaForm(url, "enviarAmic"); //URL = seccion que gestiona los datos, "FormID" = Id del formulario
	}
}

/***************************************************/
/*												   */
/*		  Valida el formulari de CV	   			   */
/*												   */
/***************************************************/

function validaFormCV(f, id)
{
	idioma = id;

	//jpg jpeg gif bmp png
	var extFoto = new Array(".jpg", ".jpeg", ".gif", ".bmp", ".png");
	
	var foto = true;
	
	var ok = false;
	
	if( llenosCv(f) && ValidaCp(f) && ValidaTelCv(f) && ValidaEmailCv(f) && EsNumeroCv() && CondicionsCv(f) )
	{
		ok = true;
		
		//Si els camps obligatoris estan omplerts i el cp, els telefons i el mail son correctes, i s'ha marcat el checkbox de les condicions
		//es comprova si ha adjuntat el seu cv o la seva foto.
			
		if(f.foto.value != "")
			foto = comprueba_extension(f.foto.value, extFoto);
			
		if(!foto)
			ok = false;
		
	}
		//alert("envio el formulari");
		//f.submit();
	return ok;
}


function EsNumeroCv()
{
	var ok = true;
	var i = 1;
	
	while (i <= 5 && ok)
	{
		var hores = document.getElementById('txtNumHoresEstudiNoReglat' + i).value;
		if(hores != null || hores != "")
		{
			if(isNaN(hores))
			{
				document.getElementById('txtNumHoresEstudiNoReglat' + i).focus();
				
				if(idioma == 1)
					alert ('Introdueixi un n\u00famero v\u00E0lid.');
				else if (idioma == 2)
					alert ('Introduzca un n\u00famero v\u00E1lido.');
					
				ok = false;
			}
		}
		i++;
	}
	
	return ok;
}

function llenosCv(f) //Estan llenos
{
	var i=0;
	var trobat=false;
	var estilDefecte = document.getElementById('txtNom').style;
	
	/*Afegit 27/07/2010*/
	//Variable per guardar el valor de retorn de la funcio validaLocalitzacio()
	//Retorna l'index de l'element en el formulari.
	var localitzacio = 0;
	
	while (i<f.length-1 && !trobat)
	{
		if(f.elements[i].value == "" && f.elements[i].type=="text"){
			
			//Camps de text
			if(f.elements[i].name == "txtNom" || f.elements[i].name == "txtCognom1" || f.elements[i].name == "txtCognom2" || f.elements[i].name == "txtNumeroDocument" || f.elements[i].name == "txtNomVia" ||
				f.elements[i].name == "txtNumero" || f.elements[i].name == "txtCP" || f.elements[i].name == "txtTelefonMobil" || f.elements[i].name == "txtTelefonFix" || f.elements[i].name == "txtEmail" ||
				(f.cboNivellEstudis1.selectedIndex > 1 && (f.elements[i].name == "txtCentreEstudis1" || f.elements[i].name=="txtMunicipiEstudis1")) || 
				f.elements[i].name=="txtLlocFeinaInteressat" || (f.elements[i].name == "txtAltraSubAreaDemandada1" && f.elements[i].disabled == false) ||
				(f.elements[i].name == "txtAltreCarnetConduir" && f.elements[i].disabled == false) || (f.elements[i].name == "txtAltreVehicle" && f.elements[i].disabled == false)
			)
			{
					trobat = error(f, i);
			}
		}
		else if(f.elements[i].value != "" && f.elements[i].type=="text")
			estilBox(f.elements[i].id);
		
		if(f.elements[i].type == "select-one"){
			//Combo Box
			if((f.elements[i].name == "cboConegut" || f.elements[i].name == "cboTipusDocument" || f.elements[i].name == "cboNaiDia" || f.elements[i].name == "cboNaiMes" || f.elements[i].name == "cboNaiAny" ||
				f.elements[i].name == "cboSexe" || f.elements[i].name == "cboNacionalitat" || f.elements[i].name == "cboPais" ||
				f.elements[i].name == "cboNivellEstudis1" || (f.cboNivellEstudis1.selectedIndex > 1 && (f.elements[i].name == "cboTitolEstudis1" ||
				f.elements[i].name == "cboDataIniciEstudis1Dia" || f.elements[i].name == "cboDataIniciEstudis1Mes" || f.elements[i].name == "cboDataIniciEstudis1Any" || 
				f.elements[i].name == "cboDataFiEstudis1Dia" || f.elements[i].name == "cboDataFiEstudis1Mes" || f.elements[i].name == "cboDataFiEstudis1Any")) ||
				f.elements[i].name == "cboIdiomaCatala" || f.elements[i].name == "cboIdiomaCastella" || f.elements[i].name == "cboIdiomaAngles" || 
				f.elements[i].name == "cboWord" || f.elements[i].name == "cboExcel" || f.elements[i].name == "cboAreaDemandada1" || f.elements[i].name == "cboSubAreaDemandada1" || f.elements[i].name == "cboCategoriaDemandada" || 
				f.elements[i].name == "cboSalariMinim" || f.elements[i].name == "cboSalariDesitjat" || f.elements[i].name == "cboTipusContracte" || f.elements[i].name == "cboJornada" || 
				f.elements[i].name == "cboDispViatjar" || f.elements[i].name == "cboDispCanviRes") && f.elements[i].selectedIndex == 0)
			{
				trobat = error(f, i);
			}
			else if( f.elements[i].name == "cboPaisNacionalitat" && document.getElementById('cboNacionalitat').selectedIndex == 2 && f.elements[i].selectedIndex == 0){
				trobat = error(f, i);
			}
			else if ((f.elements[i].name == "cboPerResDia" || f.elements[i].name == "cboPerResMes" || f.elements[i].name == "cboPerResAny") && f.elements[i].selectedIndex == 0 &&
					f.rdoComunitari[1].checked == true && f.rdoPerRes[0].checked == true ){
				trobat = error(f, i);
			}
			else if (f.elements[i].name == "cboPais"  && f.elements[i].value == '011')
			{
				localitzacio = validaLocalitzacio();
				if(localitzacio > 0)
					trobat = error(f,localitzacio);
			}
			else
				f.elements[i].style.border='1px solid #cccccc';
		}
		
		//Experiencia laboral //Validar empresa 1
		if( f.rdoExperiencia[0].checked == true )
		{	
			if((f.elements[i].type=="text" || f.elements[i].type=="textarea") && f.elements[i].value == "" ){
				//Camps de text
				if(f.elements[i].name == "txtNomEmpresa1" || f.elements[i].name == "txtLlocTreballEmpresa1" ||
					(f.cboSubArea1Empresa1.options[f.cboSubArea1Empresa1.selectedIndex].value=="Especificar" && f.elements[i].name == "txtSubArea1Empresa1" && f.txtSubArea1Empresa1.value=="") || 
					f.elements[i].name == "txtFuncionsEmpresa1")
				{
					trobat = error(f, i);
				}
				
			}
			else if(f.elements[i].value != "" && f.elements[i].type=="text")
				estilBox(f.elements[i].id);
			else if(f.elements[i].value != "" && f.elements[i].type=="textarea")
				document.getElementById(f.elements[i].id).style.border='1px solid #cccccc';
				
			if(f.elements[i].type == "select-one"){
				//Combo Box
				if((f.elements[i].name == "cboCategoriaEmpresa1" || f.elements[i].name == "cboArea1Empresa1" || f.elements[i].name == "cboSubArea1Empresa1" || 
					f.elements[i].name == "cboSectorEmpresa1" || f.elements[i].name == "cboIniciEmpresa1Dia" || f.elements[i].name == "cboIniciEmpresa1Mes" || 
					f.elements[i].name == "cboIniciEmpresa1Any" || f.elements[i].name == "cboSalariBrutAnualEmpresa1")  && f.elements[i].selectedIndex == 0)
				{
					trobat = error(f, i);
				}
				else
					f.elements[i].style.border='1px solid #cccccc';
			}
			
			//Validar data de fi de Empresa 1
			if (f.rdoTreballaActualment[1].checked == true)
			{
				if(f.elements[i].type == "select-one" ){
					if((f.elements[i].name == "cboFiEmpresa1Dia" || f.elements[i].name == "cboFiEmpresa1Mes" || f.elements[i].name == "cboFiEmpresa1Any") && f.elements[i].selectedIndex == 0)
					{
						trobat = error(f, i);
					}
					else
						f.elements[i].style.border='1px solid #cccccc';
				}
			}
			
			//Validar empresa 2 .. 5
			if( f.elements[i].name == "rdoUnicaExpLaboral" && f.rdoUnicaExpLaboral[1].checked == true)
			{
				var hihaEmpreses;

				var k = 0;
				var j = 0;
				var max = 0;
				
				for(x = 0; x < empreses.length; x++ )
				{
					if(empreses[x])
						k++;
				}

				for(inici = 1; inici < k; inici++)
				{
					j = inici+1;
					
					//90 = Num  del primer camp obligatori de la segona empresa, 
					//cada empresa te 18 camps obligatoris, per tant anira fins 18 * (inici -1)
					//(que inici pren el valor de la empresa actual la qual s'esta validant)

					max = 92 + (18 * (inici - 1)); //Max diu fins on arriba l'ultim camp obligatori de l'ultima empresa "desplegada"
					
					
					while(i <=  max && !trobat ) 
					{
						if((f.elements[i].type=="text" || f.elements[i].type=="textarea") && f.elements[i].value == "" ){
							//Camps de text
							if(f.elements[i].name == "txtNomEmpresa" + j || f.elements[i].name == "txtLlocTreballEmpresa" + j ||
								(f.elements[i].name == "txtSubArea1Empresa" + j && f.elements[i].disabled == false) ||
								f.elements[i].name == "txtFuncionsEmpresa" + j || f.elements[i].name == "txtMotiuFiEmpresa" + j)
							{
								trobat = error(f, i);
							}
							
						}
						else if(f.elements[i].value != "" && f.elements[i].type=="text")
							estilBox(f.elements[i].id);
						else if(f.elements[i].value != "" && f.elements[i].type=="textarea")
							document.getElementById(f.elements[i].id).style.border='1px solid #cccccc';
						
						if(f.elements[i].type == "select-one"){
							//Combo Box
							if((f.elements[i].name == "cboCategoriaEmpresa" + j || f.elements[i].name == "cboArea1Empresa" + j || f.elements[i].name == "cboSubArea1Empresa" + j || 
								f.elements[i].name == "cboSectorEmpresa" + j || f.elements[i].name == "cboIniciEmpresa" + j + "Dia" || f.elements[i].name == "cboIniciEmpresa" + j + "Mes" || 
								f.elements[i].name == "cboIniciEmpresa" + j + "Any" || f.elements[i].name == "cboFiEmpresa" + j + "Dia" || f.elements[i].name == "cboFiEmpresa" + j + "Mes" || 
								f.elements[i].name == "cboFiEmpresa" + j + "Any" || f.elements[i].name == "cboSalariBrutAnualEmpresa" + j) && f.elements[i].selectedIndex == 0)
							{
								trobat = error(f, i);
							}
							else
								f.elements[i].style.border='1px solid #cccccc';
						}
						
						i++;
					}
					
					//Si s'han emplenat totes les empreses cal decrementar la i perque despr�s es torna a incrementar, 
					//si aix� no es posa es salta el primer camp d'estudis
					//(quan s'han emplenat 5 empreses d'experiencia laboral.)
					
					if(k == 5) 
						i--;
				}
				
			}
		}	
		
		//Situacio laboral actual, Incorporacio, Caps de setmana, Torns rotatius i desplacament al lloc de treball 
		if(f.elements[i].type == "radio")
		{
			if( (f.elements[i].name == "rdoSitLabAct" && !f.rdoSitLabAct[0].checked && !f.rdoSitLabAct[1].checked && !f.rdoSitLabAct[2].checked ) ||
				(f.elements[i].name == "rdoIncorporacio" && !f.rdoIncorporacio[0].checked && !f.rdoIncorporacio[1].checked && !f.rdoIncorporacio[2].checked) ||
				(f.elements[i].name == "rdoCapsSetmana" && !f.rdoCapsSetmana[0].checked && !f.rdoCapsSetmana[1].checked) ||
				(f.elements[i].name == "rdoTornsRotatius" && !f.rdoTornsRotatius[0].checked && !f.rdoTornsRotatius[1].checked) ||
				(f.elements[i].name == "rdoDesplacament" && !f.rdoDesplacament[0].checked && !f.rdoDesplacament[1].checked && !f.rdoDesplacament[2].checked)
			)
				trobat = error(f, i);
		}
		
		//Vehicle propi
		if(f.elements[i].type == "checkbox"){
		
			if( (f.elements[i].name=="chkVehiclePropiNo" || f.elements[i].name=="chkVehiclePropiCotxe" ||
				f.elements[i].name=="chkVehiclePropiMoto" || f.elements[i].name=="chkVehiclePropiAltres") && 
				(!f.chkVehiclePropiNo.checked && !f.chkVehiclePropiCotxe.checked &&
				!f.chkVehiclePropiMoto.checked && !f.chkVehiclePropiAltres.checked))

				trobat = error(f, i);
		}
		
		//Curriculum
		if(f.elements[i].type == "file" && f.elements[i].name == "curriculum")
		{
			//pdf doc docx rtf odt
			var extCV = new Array(".pdf", ".doc", ".docx", ".rtf", ".odt",".txt");
	
			if (f.elements[i].value != "")
				trobat = !comprueba_extension(f.elements[i].value, extCV);
			else
				trobat = error(f,i);
		}
			
		i++;
	}
	
	return !trobat;
}

function ValidaCp(f)
{
	var ok = true;
	if(isNaN(f.txtCP.value) || f.txtCP.value.length < 5)
	{
		f.txtCP.focus();
		
		if(idioma == 1)
			alert ('El codi postal no \u00E9s v\u00E0lid.');
		else if (idioma == 2)
			alert ('El codigo postal no es v\u00E1lido.');
		
		ok = false;
	}
	
	return ok;
}

function ValidaEmailCv(f)
{
	var ok=true;

	var arroba = f.txtEmail.value.indexOf('@',0);
	var punt = f.txtEmail.value.indexOf('.',arroba);
	
	
	if(arroba == -1 || punt == -1 || punt == f.txtEmail.value.length-1 || arroba + 1 == punt)
	{
		f.txtEmail.focus();
		
		if(idioma == 1)
			alert ('Email incorrecte.');
		else if (idioma == 2)
			alert ('Email incorrecto.');
			
		ok = false;
	}
		

	return ok;
}

function ValidaTelCv(f)
{
	var ok = true;
	
	if(isNaN(f.txtTelefonMobil.value) || isNaN(f.txtTelefonFix.value))
	{
		if(isNaN(f.txtTelefonMobil.value))
			f.txtTelefonMobil.focus();
		else
			f.txtTelefonFix.focus();
		
		if(idioma == 1)
			alert ('Introdueixi un n\u00famero v\u00E0lid.');
		else if (idioma == 2)
			alert ('Introduzca un n\u00famero v\u00E1lido.');
		
		ok = false;
	}
	else if(f.txtTelefonMobil.value.length < 9 || f.txtTelefonFix.value.length < 9)
	{
		if(f.txtTelefonMobil.value.length < 9)
			f.txtTelefonMobil.focus();
		else
			f.txtTelefonFix.focus();
		
		if(idioma == 1)
			alert ('El n\u00famero de tel\u00E8fon ha de tenir 9 d\u00EDgits com a minim.');
		else if (idioma == 2)
			alert ('El n\u00famero tel\u00E9fono debe tener 9 digitos como minimo.');
		
		ok = false;
	}
	
	return ok;
}

function validaLocalitzacio()
{
	var ok = false;
	//sera el valor de retorn
	//On coincidira amb l'index de la seva posicio en el formulari.
	var localitzacio = 0;
	
	var comunitat;
	var provincia;
	var comarca;
	
	var comunitatI;
	var provinciaI;
	var comarcaI;
	
	comunitat = document.getElementById('cboComunitat').value;
	provincia = document.getElementById('cboProvincia').value;
	comarca = document.getElementById('cboComarca').value;
	
	
	comunitatI = document.getElementById('cboComunitat').selectedIndex;
	provinciaI = document.getElementById('cboProvincia').selectedIndex;
	comarcaI = document.getElementById('cboComarca').selectedIndex;
	
	if(comunitatI > 0)
	{
		if(comunitat == '09'){
			if(comarcaI == 0){
				//ok = true;
				localitzacio = 42;
				document.getElementById('cboComarca').focus();
				document.getElementById('cboComarca').style.border='1px solid red';
			}
			else
				document.getElementById('cboComarca').style.border='1px solid #cccccc';
		}
		
		if (!ok){
			if(provinciaI == 0){
				//ok = true;
				localitzacio = 41;
				document.getElementById('cboProvincia').focus();
				document.getElementById('cboProvincia').style.border='1px solid red';
			}
			else
				document.getElementById('cboProvincia').style.border='1px solid #cccccc';
		}
		
		document.getElementById('cboComunitat').style.border='1px solid #cccccc';
	}
	else
	{
		//ok = true;
		localitzacio = 40;
		document.getElementById('cboComunitat').focus();
		document.getElementById('cboComunitat').style.border='1px solid red';
	}
	
	/*
	if(ok){
		if(idioma == 1)
			alert ('*Camp obligatori.');
		else if (idioma == 2)
			alert ('*Campo obligatorio.');
	}*/
	
	document.getElementById('cboPais').style.border='1px solid #cccccc';
	
	//return ok;
	return localitzacio;;
}

function CondicionsCv(f)
{
	var ok = true;
	
	if(!f.chkCondicions.checked)
	{
		f.chkCondicions.focus();
		
		if(idioma == 1)
			alert ('Si us plau, llegeixi i accepti les condicions.');
		else if (idioma == 2)
			alert ('Por favor, lea y acepte las condiciones.');
		
		ok = false;
	}
	
	return ok;
}

function comprueba_extension(arxiu, ext) {
		
		//pdf doc docx rtf odt
		
		//jpg jpeg gif bmp png
		
		if(ext[0] == ".pdf")
			error = "Error al adjuntar curriculum.\n\n";
		else if(ext[0] == ".jpg")
			error = "Error al adjuntar la foto.\n\n";
		
		//recupero l'extensi� d'aquest nom d'arxiu
		extensio = (arxiu.substring(arxiu.lastIndexOf("."))).toLowerCase();
		
		//Comprobo si l'extensi� es troba entre les permeses
		permesa = false;
		for (var i = 0; i < ext.length; i++) {
			if (ext[i] == extensio) { 
				permesa = true;
				break;
			}
		}
		
		if (!permesa) {
		
			if(idioma == 1)
				error += "Nom\u00E9s estan permesos arxius amb extensi\u00F3: \n\n    " + ext.join();
			else if (idioma == 2)
				error += "Solo estan permitidos archivos con extensi\u00F3n: \n\n    " + ext.join();
		}else{
			return true;
		}
		
		//Hi ha hagut un error
		alert (error);
		return false;
}

function estilBox(id)
{
	document.getElementById(id).style.borderTopStyle='none';
	document.getElementById(id).style.borderRightStyle='none';
	document.getElementById(id).style.borderBottomStyle='solid';
	document.getElementById(id).style.borderBottomColor='#cccccc';
	document.getElementById(id).style.borderBottomWidth='1px';
	document.getElementById(id).style.borderLeftStyle='none';
}

function error(f, i)
{

	/*for(h = 0; h<f.length-1;h++)
	{
		document.write('elemento ' + h +': ' + f.elements[h].name + '<br/>');
	}*/

	f.elements[i].focus();
	
	f.elements[i].style.border='1px solid red';
	
	//Array amb els noms dels camps obligatoris del formulari del curriculum
	//campsCat: Nom de l'array per als camps en catala
	
	/*
		Son parelles de dades:
			- El primer valor correspon a la posicio de l'element en el formulari.
			- El segon valor correspon al nom del camp de forma entenedora per a l'usuari
	*/
	
	
	if (f.name == "cv" && idioma == 1)
	{
		var campsCat = new Array();

		campsCat[0]=9;
		campsCat[1]="Com ens has conegut";

		campsCat[2]=10;
		campsCat[3]="Treballador referent";

		campsCat[4]=12;
		campsCat[5]="Dades personals: Nom";

		campsCat[6]=13;
		campsCat[7]="Dades personals: Primer cognom";

		campsCat[8]=14;
		campsCat[9]="Dades personals: Segon cognom";

		campsCat[10]=15;
		campsCat[11]="Dades personals: Tipus de document d´Identitat";

		campsCat[12]=16;
		campsCat[13]="Dades personals: Número de document d´Identitat";

		campsCat[14]=17;
		campsCat[15]="Dades personals: Dia de naixement";

		campsCat[16]=18;
		campsCat[17]="Dades personals: Mes de naixement";

		campsCat[18]=19;
		campsCat[19]="Dades personals: Any de naixement";

		campsCat[20]=20;
		campsCat[21]="Dades personals: Sexe";

		campsCat[22]=22;
		campsCat[23]="Dades personals: Nacionalitat";

		campsCat[24]=23;
		campsCat[25]="Dades personals: País de nacionalitat";

		campsCat[26]=28;
		campsCat[27]="Dades personals: Dia de permis de residència";

		campsCat[28]=29;
		campsCat[29]="Dades personals: Mes de permis de residència";

		campsCat[30]=30;
		campsCat[31]="Dades personals: Any de permis de residència";

		
		//A partir d´aqui els 3 camps seguents s´han eliminat
		//Per tant a partir del 37(nom de la via) s´ha de modificar les posicions com calgui.
		
		/*campsCat[32]=33;
		campsCat[33]="Dia: permis de treball";

		campsCat[34]=34;
		campsCat[35]="Mes: permis de treball";

		campsCat[36]=35;
		campsCat[37]="Any: permis de treball";*/

		//Per exemple, a partir d´aqui nom de la via hauria de ser 32.
		
		campsCat[38]=32;
		campsCat[39]="Domicili: Nom de la via";

		campsCat[40]=33;
		campsCat[41]="Domicili: Número de la via";

		campsCat[42]=37;
		campsCat[43]="Domicili: Codi postal";

		campsCat[44]=39;
		campsCat[45]="Domicili: País";

		campsCat[46]=40;
		campsCat[47]="Domicili: Comunitat Autònoma";

		campsCat[48]=41;
		campsCat[49]="Domicili: Província";

		campsCat[50]=42;
		campsCat[51]="Domicili: Comarca";

		campsCat[52]=43;
		campsCat[53]="Dades de contacte: Telèfon mòbil";

		campsCat[54]=44;
		campsCat[55]="Dades de contacte: Telèfon fix";

		campsCat[56]=45;
		campsCat[57]="Dades de contacte: E-mail";

		campsCat[58]=48;
		campsCat[59]="Empresa actual o més recent: Nom empresa";

		campsCat[60]=51;
		campsCat[61]="Empresa actual o més recent: Lloc de treball";

		campsCat[62]=52;
		campsCat[63]="Empresa actual o més recent: Categoria";

		campsCat[64]=53;
		campsCat[65]="Empresa actual o més recent: Àrea";

		campsCat[66]=54;
		campsCat[67]="Empresa actual o més recent: Subàrea";

		campsCat[68]=55;
		campsCat[69]="Empresa actual o més recent: Especificar subàrea";

		campsCat[70]=56;
		campsCat[71]="Empresa actual o més recent: Sector";

		campsCat[72]=57;
		campsCat[73]="Empresa actual o més recent: Funcions";

		campsCat[74]=58;
		campsCat[75]="Empresa actual o més recent: Dia d´inici";

		campsCat[76]=59;
		campsCat[77]="Empresa actual o més recent: Mes d´inici";

		campsCat[78]=60;
		campsCat[79]="Empresa actual o més recent: Any d´inici";

		campsCat[80]=63;
		campsCat[81]="Empresa actual o més recent: Dia de finalització";

		campsCat[82]=64;
		campsCat[83]="Empresa actual o més recent: Mes de finalització";

		campsCat[84]=65;
		campsCat[85]="Empresa actual o més recent: Any de finalització";

		campsCat[86]=67;
		campsCat[87]="Empresa actual o més recent: Salari brut anual";

		campsCat[88]=70;
		campsCat[89]="Empresa anterior (1): Nom empresa";

		campsCat[90]=73;
		campsCat[91]="Empresa anterior (1): Lloc de treball";

		campsCat[92]=74;
		campsCat[93]="Empresa anterior (1): Categoria";

		campsCat[94]=75;
		campsCat[95]="Empresa anterior (1): Àrea";

		campsCat[96]=76;
		campsCat[97]="Empresa anterior (1): Subàrea";

		campsCat[98]=77;
		campsCat[99]="Empresa anterior (1): Especificar subàrea";

		campsCat[100]=78;
		campsCat[101]="Empresa anterior (1): Sector";

		campsCat[102]=79;
		campsCat[103]="Empresa anterior (1): Funcions";

		campsCat[104]=80;
		campsCat[105]="Empresa anterior (1): Dia d´inici";

		campsCat[106]=81;
		campsCat[107]="Empresa anterior (1): Mes d´inici";

		campsCat[108]=82;
		campsCat[109]="Empresa anterior (1): Any d´inici";

		campsCat[110]=83;
		campsCat[111]="Empresa anterior (1): Dia de finalització";

		campsCat[112]=84;
		campsCat[113]="Empresa anterior (1): Mes de finalització";

		campsCat[114]=85;
		campsCat[115]="Empresa anterior (1): Any de finalització";

		campsCat[116]=86;
		campsCat[117]="Empresa anterior (1): Motiu de finalització";

		campsCat[118]=87;
		campsCat[119]="Empresa anterior (1): Salari brut anual";

		campsCat[120]=88;
		campsCat[121]="Empresa anterior (2): Nom empresa";

		campsCat[122]=91;
		campsCat[123]="Empresa anterior (2): Lloc de treball";

		campsCat[124]=92;
		campsCat[125]="Empresa anterior (2): Categoria";

		campsCat[126]=93;
		campsCat[127]="Empresa anterior (2): Àrea";

		campsCat[128]=94;
		campsCat[129]="Empresa anterior (2): Subàrea";

		campsCat[130]=95;
		campsCat[131]="Empresa anterior (2): Especificar subàrea";

		campsCat[132]=96;
		campsCat[133]="Empresa anterior (2): Sector";

		campsCat[134]=97;
		campsCat[135]="Empresa anterior (2): Funcions";

		campsCat[136]=98;
		campsCat[137]="Empresa anterior (2): Dia d´inici";

		campsCat[138]=99;
		campsCat[139]="Empresa anterior (2): Mes d´inici";

		campsCat[140]=100;
		campsCat[141]="Empresa anterior (2): Any d´inici";

		campsCat[142]=101;
		campsCat[143]="Empresa anterior (2): Dia de finalització";

		campsCat[144]=102;
		campsCat[145]="Empresa anterior (2): Mes de finalització";

		campsCat[146]=103;
		campsCat[147]="Empresa anterior (2): Any de finalització";

		campsCat[148]=104;
		campsCat[149]="Empresa anterior (2): Motiu de finalització";

		campsCat[150]=105;
		campsCat[151]="Empresa anterior (2): Salari brut anual";

		campsCat[152]=106;
		campsCat[153]="Empresa anterior (3): Nom empresa";

		campsCat[154]=109;
		campsCat[155]="Empresa anterior (3): Lloc de treball";

		campsCat[156]=110;
		campsCat[157]="Empresa anterior (3): Categoria";

		campsCat[158]=111;
		campsCat[159]="Empresa anterior (3): Àrea";

		campsCat[160]=112;
		campsCat[161]="Empresa anterior (3): Subàrea";

		campsCat[162]=113;
		campsCat[163]="Empresa anterior (3): Especificar subàrea";

		campsCat[164]=114;
		campsCat[165]="Empresa anterior (3): Sector";

		campsCat[166]=115;
		campsCat[167]="Empresa anterior (3): Funcions";

		campsCat[168]=116;
		campsCat[169]="Empresa anterior (3): Dia d´inici";

		campsCat[170]=117;
		campsCat[171]="Empresa anterior (3): Mes d´inici";

		campsCat[172]=118;
		campsCat[173]="Empresa anterior (3): Any d´inici";

		campsCat[174]=119;
		campsCat[175]="Empresa anterior (3): Dia de finalització";

		campsCat[176]=120;
		campsCat[177]="Empresa anterior (3): Mes de finalització";

		campsCat[178]=121;
		campsCat[179]="Empresa anterior (3): Any de finalització";

		campsCat[180]=122;
		campsCat[181]="Empresa anterior (3): Motiu de finalització";

		campsCat[182]=123;
		campsCat[183]="Empresa anterior (3): Salari brut anual";

		campsCat[184]=124;
		campsCat[185]="Empresa anterior (4): Nom empresa";

		campsCat[186]=127;
		campsCat[187]="Empresa anterior (4): Lloc de treball";

		campsCat[188]=128;
		campsCat[189]="Empresa anterior (4): Categoria";

		campsCat[190]=129;
		campsCat[191]="Empresa anterior (4): Àrea";

		campsCat[192]=130;
		campsCat[193]="Empresa anterior (4): Subàrea";

		campsCat[194]=131;
		campsCat[195]="Empresa anterior (4): Especificar subàrea";

		campsCat[196]=132;
		campsCat[197]="Empresa anterior (4): Sector";

		campsCat[198]=133;
		campsCat[199]="Empresa anterior (4): Funcions";

		campsCat[200]=134;
		campsCat[201]="Empresa anterior (4): Dia d´inici";

		campsCat[202]=135;
		campsCat[203]="Empresa anterior (4): Mes d´inici";

		campsCat[204]=136;
		campsCat[205]="Empresa anterior (4): Any d´inici";

		campsCat[206]=137;
		campsCat[207]="Empresa anterior (4): Dia de finalització";

		campsCat[208]=138;
		campsCat[209]="Empresa anterior (4): Mes de finalització";

		campsCat[210]=139;
		campsCat[211]="Empresa anterior (4): Any de finalització";

		campsCat[212]=140;
		campsCat[213]="Empresa anterior (4): Motiu de finalització";

		campsCat[214]=141;
		campsCat[215]="Empresa anterior (4): Salari brut anual";

		campsCat[216]=142;
		campsCat[217]="Estudis reglats: Nivell estudis";

		campsCat[218]=143;
		campsCat[219]="Estudis reglats: Titol / Estudi";

		campsCat[220]=144;
		campsCat[221]="Estudis reglats: Centre";

		campsCat[222]=145;
		campsCat[223]="Estudis reglats: Municipi";

		campsCat[224]=146;
		campsCat[225]="Estudis reglats: Dia d´inici";

		campsCat[226]=147;
		campsCat[227]="Estudis reglats: Mes d´inici";

		campsCat[228]=148;
		campsCat[229]="Estudis reglats: Any d´inici";

		campsCat[230]=149;
		campsCat[231]="Estudis reglats: Dia de finalització";

		campsCat[232]=150;
		campsCat[233]="Estudis reglats: Mes de finalització";

		campsCat[234]=151;
		campsCat[235]="Estudis reglats: Any de finalització";

		campsCat[236]=251;
		campsCat[237]="Idiomes: Català";

		campsCat[238]=252;
		campsCat[239]="Idiomes: Castellà";

		campsCat[240]=253;
		campsCat[241]="Idiomes: Anglès";

		campsCat[242]=268;
		campsCat[243]="Coneixements informàtics: Word";

		campsCat[244]=269;
		campsCat[245]="Coneixements informàtics: Excel";

		campsCat[246]=285;
		campsCat[247]="Futur treball: Situació laboral actual";

		campsCat[248]=288;
		campsCat[249]="Futur treball: Lloc de feina";

		campsCat[250]=289;
		campsCat[251]="Futur treball: Àrea o departament";

		campsCat[252]=290;
		campsCat[253]="Futur treball: Subàrea";

		campsCat[254]=291;
		campsCat[255]="Futur treball: Especificar subàrea";

		campsCat[256]=292;
		campsCat[257]="Futur treball: Categoria";

		campsCat[258]=293;
		campsCat[259]="Futur treball: Salari mínim requerit";

		campsCat[260]=294;
		campsCat[261]="Futur treball: Salari desitjat";

		campsCat[262]=295;
		campsCat[263]="Futur treball: Incorporació";

		campsCat[264]=298;
		campsCat[265]="Futur treball: Tipus de contracte preferit";

		campsCat[266]=299;
		campsCat[267]="Disponibilitat: Jornada";

		campsCat[268]=300;
		campsCat[269]="Disponibilitat: Caps de setmana";

		campsCat[270]=302;
		campsCat[271]="Disponibilitat: Torns rotatius";

		campsCat[272]=304;
		campsCat[273]="Disponibilitat: Desplaçament al lloc de treball";

		campsCat[274]=307;
		campsCat[275]="Disponibilitat: Disponibilitat per a viatjar";

		campsCat[276]=308;
		campsCat[277]="Disponibilitat: Disponibilitat canvi de residencia";

		campsCat[278]=318;
		campsCat[279]="Disponibilitat: Vehicle propi";

		campsCat[280]=319;
		campsCat[281]="Disponibilitat: Vehicle propi";

		campsCat[282]=320;
		campsCat[283]="Disponibilitat: Vehicle propi";

		campsCat[284]=321;
		campsCat[285]="Disponibilitat: Vehicle propi";

		campsCat[286]=322;
		campsCat[287]="Disponibilitat: Especificar vehicle propi";
		
		campsCat[288]=323;
		campsCat[289]="Curriculum: Es obligatori adjuntar el Curriculum Vitae.";
		
		var posErr = 0, j = 0;
		var trobat = false;
		
		while(j < campsCat.length && trobat == false)
		{
			if(campsCat[j] == i){
				trobat = true;
				posErr = j + 1;
			}
			
			j++;
		}
		
		//if(trobat)
		//	alert(campsCat[posErr]);
			
		
		
	}
	//En castella
	else if (f.name == "cv" && idioma == 2)
	{
		var campsEsp = new Array();

		campsEsp[0]=9;
		campsEsp[1]="Cómo nos has conocido";

		campsEsp[2]=10;
		campsEsp[3]="Referente a Grup Serhs";

		campsEsp[4]=12;
		campsEsp[5]="Datos personales: Nombre";

		campsEsp[6]=13;
		campsEsp[7]="Datos personales: Primer apellido";

		campsEsp[8]=14;
		campsEsp[9]="Datos personales: Segundo apellido";

		campsEsp[10]=15;
		campsEsp[11]="Datos personales: Tipo de documento de identidad";

		campsEsp[12]=16;
		campsEsp[13]="Datos personales: Número de documento de identidad";

		campsEsp[14]=17;
		campsEsp[15]="Datos personales: Dia de nacimiento";

		campsEsp[16]=18;
		campsEsp[17]="Datos personales: Mes de nacimiento";

		campsEsp[18]=19;
		campsEsp[19]="Datos personales: Año de nacimiento";

		campsEsp[20]=20;
		campsEsp[21]="Datos personales: Sexo";

		campsEsp[22]=22;
		campsEsp[23]="Datos personales: Nacionalidad";

		campsEsp[24]=23;
		campsEsp[25]="Datos personales: País de nacionalidad";

		campsEsp[26]=28;
		campsEsp[27]="Datos personales: Dia de permiso de residencia";

		campsEsp[28]=29;
		campsEsp[29]="Datos personales: Mes de permiso de residencia";

		campsEsp[30]=30;
		campsEsp[31]="Datos personales: Año de permiso de residencia";

		
		//A partir d'aqui els 3 camps seguents s'han eliminat
		//Per tant a partir del 37(nom de la via) s'ha de modificar les posicions com calgui.
		
		/*campsEsp[32]=33;
		campsEsp[33]="Dia: permis de treball";

		campsEsp[34]=34;
		campsEsp[35]="Mes: permis de treball";

		campsEsp[36]=35;
		campsEsp[37]="Any: permis de treball";*/

		//Per exemple, a partir d'aqui nom de la via hauria de ser 32.
		
		campsEsp[38]=32;
		campsEsp[39]="Domicilio: Nombre de la vía";

		campsEsp[40]=33;
		campsEsp[41]="Domicilio: Número de la vía";

		campsEsp[42]=37;
		campsEsp[43]="Domicilio: Código postal";

		campsEsp[44]=39;
		campsEsp[45]="Domicilio: País";

		campsEsp[46]=40;
		campsEsp[47]="Domicilio: Comunidad Autónoma";

		campsEsp[48]=41;
		campsEsp[49]="Domicilio: Provincia";

		campsEsp[50]=42;
		campsEsp[51]="Domicilio: Comarca";

		campsEsp[52]=43;
		campsEsp[53]="Datos de contacto: Teléfon móvil";

		campsEsp[54]=44;
		campsEsp[55]="Datos de contacto: Teléfon fijo";

		campsEsp[56]=45;
		campsEsp[57]="Datos de contacto: E-mail";

		campsEsp[58]=48;
		campsEsp[59]="Empresa actual o más reciente: Nombre empresa";

		campsEsp[60]=51;
		campsEsp[61]="Empresa actual o más reciente: Lugar de trabajo";

		campsEsp[62]=52;
		campsEsp[63]="Empresa actual o más reciente: Categoría";

		campsEsp[64]=53;
		campsEsp[65]="Empresa actual o más reciente: Área";

		campsEsp[66]=54;
		campsEsp[67]="Empresa actual o más reciente: Subárea";

		campsEsp[68]=55;
		campsEsp[69]="Empresa actual o más reciente: Especificar subárea";

		campsEsp[70]=56;
		campsEsp[71]="Empresa actual o más reciente: Sector";

		campsEsp[72]=57;
		campsEsp[73]="Empresa actual o más reciente: Funciones";

		campsEsp[74]=58;
		campsEsp[75]="Empresa actual o más reciente: Dia de inicio";

		campsEsp[76]=59;
		campsEsp[77]="Empresa actual o más reciente: Mes de inicio";

		campsEsp[78]=60;
		campsEsp[79]="Empresa actual o más reciente: Año de inicio";

		campsEsp[80]=63;
		campsEsp[81]="Empresa actual o más reciente: Dia de finalización";

		campsEsp[82]=64;
		campsEsp[83]="Empresa actual o más reciente: Mes de finalización";

		campsEsp[84]=65;
		campsEsp[85]="Empresa actual o más reciente: Año de finalización";

		campsEsp[86]=67;
		campsEsp[87]="Empresa actual o más reciente: Salario bruto anual";

		campsEsp[88]=70;
		campsEsp[89]="Empresa anterior (1): Nombre empresa";

		campsEsp[90]=73;
		campsEsp[91]="Empresa anterior (1): Lugar de trabajo";

		campsEsp[92]=74;
		campsEsp[93]="Empresa anterior (1): Categoría";

		campsEsp[94]=75;
		campsEsp[95]="Empresa anterior (1): Área";

		campsEsp[96]=76;
		campsEsp[97]="Empresa anterior (1): Subárea";

		campsEsp[98]=77;
		campsEsp[99]="Empresa anterior (1): Especificar subárea";

		campsEsp[100]=78;
		campsEsp[101]="Empresa anterior (1): Sector";

		campsEsp[102]=79;
		campsEsp[103]="Empresa anterior (1): Funciones";

		campsEsp[104]=80;
		campsEsp[105]="Empresa anterior (1): Dia de inicio";

		campsEsp[106]=81;
		campsEsp[107]="Empresa anterior (1): Mes de inicio";

		campsEsp[108]=82;
		campsEsp[109]="Empresa anterior (1): Año de inicio";

		campsEsp[110]=83;
		campsEsp[111]="Empresa anterior (1): Dia de finalización";

		campsEsp[112]=84;
		campsEsp[113]="Empresa anterior (1): Mes de finalización";

		campsEsp[114]=85;
		campsEsp[115]="Empresa anterior (1): Año de finalización";

		campsEsp[116]=86;
		campsEsp[117]="Empresa anterior (1): Motiu de finalización";

		campsEsp[118]=87;
		campsEsp[119]="Empresa anterior (1): Salario bruto anual";

		campsEsp[120]=88;
		campsEsp[121]="Empresa anterior (2): Nombre empresa";

		campsEsp[122]=91;
		campsEsp[123]="Empresa anterior (2): Lugar de trabajo";

		campsEsp[124]=92;
		campsEsp[125]="Empresa anterior (2): Categoría";

		campsEsp[126]=93;
		campsEsp[127]="Empresa anterior (2): Área";

		campsEsp[128]=94;
		campsEsp[129]="Empresa anterior (2): Subárea";

		campsEsp[130]=95;
		campsEsp[131]="Empresa anterior (2): Especificar subárea";

		campsEsp[132]=96;
		campsEsp[133]="Empresa anterior (2): Sector";

		campsEsp[134]=97;
		campsEsp[135]="Empresa anterior (2): Funciones";

		campsEsp[136]=98;
		campsEsp[137]="Empresa anterior (2): Dia de inicio";

		campsEsp[138]=99;
		campsEsp[139]="Empresa anterior (2): Mes de inicio";

		campsEsp[140]=100;
		campsEsp[141]="Empresa anterior (2): Año de inicio";

		campsEsp[142]=101;
		campsEsp[143]="Empresa anterior (2): Dia de finalización";

		campsEsp[144]=102;
		campsEsp[145]="Empresa anterior (2): Mes de finalización";

		campsEsp[146]=103;
		campsEsp[147]="Empresa anterior (2): Año de finalización";

		campsEsp[148]=104;
		campsEsp[149]="Empresa anterior (2): Motiu de finalización";

		campsEsp[150]=105;
		campsEsp[151]="Empresa anterior (2): Salario bruto anual";

		campsEsp[152]=106;
		campsEsp[153]="Empresa anterior (3): Nombre empresa";

		campsEsp[154]=109;
		campsEsp[155]="Empresa anterior (3): Lugar de trabajo";

		campsEsp[156]=110;
		campsEsp[157]="Empresa anterior (3): Categoría";

		campsEsp[158]=111;
		campsEsp[159]="Empresa anterior (3): Área";

		campsEsp[160]=112;
		campsEsp[161]="Empresa anterior (3): Subárea";

		campsEsp[162]=113;
		campsEsp[163]="Empresa anterior (3): Especificar subárea";

		campsEsp[164]=114;
		campsEsp[165]="Empresa anterior (3): Sector";

		campsEsp[166]=115;
		campsEsp[167]="Empresa anterior (3): Funciones";

		campsEsp[168]=116;
		campsEsp[169]="Empresa anterior (3): Dia de inicio";

		campsEsp[170]=117;
		campsEsp[171]="Empresa anterior (3): Mes de inicio";

		campsEsp[172]=118;
		campsEsp[173]="Empresa anterior (3): Año de inicio";

		campsEsp[174]=119;
		campsEsp[175]="Empresa anterior (3): Dia de finalización";

		campsEsp[176]=120;
		campsEsp[177]="Empresa anterior (3): Mes de finalización";

		campsEsp[178]=121;
		campsEsp[179]="Empresa anterior (3): Año de finalización";

		campsEsp[180]=122;
		campsEsp[181]="Empresa anterior (3): Motiu de finalización";

		campsEsp[182]=123;
		campsEsp[183]="Empresa anterior (3): Salario bruto anual";

		campsEsp[184]=124;
		campsEsp[185]="Empresa anterior (4): Nombre empresa";

		campsEsp[186]=127;
		campsEsp[187]="Empresa anterior (4): Lugar de trabajo";

		campsEsp[188]=128;
		campsEsp[189]="Empresa anterior (4): Categoría";

		campsEsp[190]=129;
		campsEsp[191]="Empresa anterior (4): Área";

		campsEsp[192]=130;
		campsEsp[193]="Empresa anterior (4): Subárea";

		campsEsp[194]=131;
		campsEsp[195]="Empresa anterior (4): Especificar subárea";

		campsEsp[196]=132;
		campsEsp[197]="Empresa anterior (4): Sector";

		campsEsp[198]=133;
		campsEsp[199]="Empresa anterior (4): Funciones";

		campsEsp[200]=134;
		campsEsp[201]="Empresa anterior (4): Dia de inicio";

		campsEsp[202]=135;
		campsEsp[203]="Empresa anterior (4): Mes de inicio";

		campsEsp[204]=136;
		campsEsp[205]="Empresa anterior (4): Año de inicio";

		campsEsp[206]=137;
		campsEsp[207]="Empresa anterior (4): Dia de finalización";

		campsEsp[208]=138;
		campsEsp[209]="Empresa anterior (4): Mes de finalización";

		campsEsp[210]=139;
		campsEsp[211]="Empresa anterior (4): Año de finalización";

		campsEsp[212]=140;
		campsEsp[213]="Empresa anterior (4): Motiu de finalización";

		campsEsp[214]=141;
		campsEsp[215]="Empresa anterior (4): Salario bruto anual";

		campsEsp[216]=142;
		campsEsp[217]="Estudios reglados: Nivel de estudios";

		campsEsp[218]=143;
		campsEsp[219]="Estudios reglados: Título / Estudio";

		campsEsp[220]=144;
		campsEsp[221]="Estudios reglados: Centro";

		campsEsp[222]=145;
		campsEsp[223]="Estudios reglados: Municipio";

		campsEsp[224]=146;
		campsEsp[225]="Estudios reglados: Dia de inicio";

		campsEsp[226]=147;
		campsEsp[227]="Estudios reglados: Mes de inicio";

		campsEsp[228]=148;
		campsEsp[229]="Estudios reglados: Año de inicio";

		campsEsp[230]=149;
		campsEsp[231]="Estudios reglados: Dia de finalización";

		campsEsp[232]=150;
		campsEsp[233]="Estudios reglados: Mes de finalización";

		campsEsp[234]=151;
		campsEsp[235]="Estudios reglados: Año de finalización";

		campsEsp[236]=251;
		campsEsp[237]="Idiomas: Catalán";

		campsEsp[238]=252;
		campsEsp[239]="Idiomas: Castellano";

		campsEsp[240]=253;
		campsEsp[241]="Idiomas: Ingles";

		campsEsp[242]=268;
		campsEsp[243]="Conocimientos informáticos: Word";

		campsEsp[244]=269;
		campsEsp[245]="Conocimientos informáticos: Excel";

		campsEsp[246]=285;
		campsEsp[247]="Futuro trabajo: Situació laboral actual";

		campsEsp[248]=288;
		campsEsp[249]="Futuro trabajo: Lugar de trabajo";

		campsEsp[250]=289;
		campsEsp[251]="Futuro trabajo: Área o departamento";

		campsEsp[252]=290;
		campsEsp[253]="Futuro trabajo: Subárea";

		campsEsp[254]=291;
		campsEsp[255]="Futuro trabajo: Especificar Subárea";

		campsEsp[256]=292;
		campsEsp[257]="Futuro trabajo: Categoría";

		campsEsp[258]=293;
		campsEsp[259]="Futuro trabajo: Salario mínimo requerido";

		campsEsp[260]=294;
		campsEsp[261]="Futuro trabajo: Salario deseado";

		campsEsp[262]=295;
		campsEsp[263]="Futuro trabajo: Incorporación";

		campsEsp[264]=298;
		campsEsp[265]="Futuro trabajo: Tipo de contrato preferido";

		campsEsp[266]=299;
		campsEsp[267]="Disponibilidad: Jornada";

		campsEsp[268]=300;
		campsEsp[269]="Disponibilidad: Fines de semana";

		campsEsp[270]=302;
		campsEsp[271]="Disponibilidad: Turnos rotativos";

		campsEsp[272]=304;
		campsEsp[273]="Disponibilidad: Desplazamiento al lugar de trabajo";

		campsEsp[274]=307;
		campsEsp[275]="Disponibilidad: Disponibilidad para viajar";

		campsEsp[276]=308;
		campsEsp[277]="Disponibilidad: Disponibilidad cambio de residencia";

		campsEsp[278]=318;
		campsEsp[279]="Disponibilidad: Vehículo propio";

		campsEsp[280]=319;
		campsEsp[281]="Disponibilidad: Vehículo propio";

		campsEsp[282]=320;
		campsEsp[283]="Disponibilidad: Vehículo propio";

		campsEsp[284]=321;
		campsEsp[285]="Disponibilidad: Vehículo propio";

		campsEsp[286]=322;
		campsEsp[287]="Disponibilidad: Especificar vehículo propio";
		
		campsEsp[288]=323;
		campsEsp[289]="Curriculum: Es obligatorio adjuntar el Curriculum Vitae.";
		
		var posErr = 0, j = 0;
		var trobat = false;
		
		while(j < campsEsp.length && trobat == false)
		{
			if(campsEsp[j] == i){
				trobat = true;
				posErr = j + 1;
			}
			
			j++;
		}
	}
	
	
	if(idioma == 1 && trobat){
		alert ('*Camp obligatori.\n\n' + campsCat[posErr]);
	}
	else if (idioma == 2 && trobat){
		alert ('*Campo obligatorio.\n\n' + campsEsp[posErr]);
	}
	

	return trobat;

}

function esborrarForm(f, id)
{
	idioma = id;

	if(idioma == 1)
	{
		if(confirm("Segur que vol eliminar les dades? \n\nUn cop eliminades no es poden recuperar.")) {
			f.reset();
		}
	}
	else if (idioma == 2)
	{
		if(confirm("Seguro que desea eliminar los datos? \n\nUna vez eliminadas no se pueden recuperar.")) {
			f.reset();
		}
	}

}

function enviaForm(url,FormID){
	var str = $("#" + FormID).serialize();
	url = url + "&" + str;
	eBDSection.show(url,retornoDetalle);
}