function lTrim(sStr){
    while (sStr.charAt(0) == " ")
	sStr = sStr.substr(1, sStr.length - 1);
	return sStr;
}

function rTrim(sStr){
	while (sStr.charAt(sStr.length - 1) == " ")
	sStr = sStr.substr(0, sStr.length - 1);
	return sStr;
}

function allTrim(sStr){
	return rTrim(lTrim(sStr));
}

function checkfields(idi) {

	var idiomas = new Array();	
	idiomas['CAS'] = new Array();
	idiomas['CAT'] = new Array();
	
	idiomas['CAS'][1] = 'No a aceptado la ley de protección de datos.';
	idiomas['CAS'][2] = 'Rellene los campos obligatorios del Formulario.';
	idiomas['CAS'][3] = 'Campo Teléfono no valido.';
	idiomas['CAS'][4] = 'Campo E-mail no válido.';
	
	idiomas['CAT'][1] = 'No a acceptat la llei de protecció de dades.';
	idiomas['CAT'][2] = 'Empleni els camps obligatoris del Formulari.';
	idiomas['CAT'][3] = 'Camp Telèfon no valido.';
	idiomas['CAT'][4] = 'Camp E-mail no vàlid.';  

 	var er_email = /^(.+\@.+\..+)$/
 	var er_numero = /^([0-9\s\+\-])+$/
 	 		
	v1 = allTrim(document.form.empresa.value);
	v2 = allTrim(document.form.contacto.value);
	v3 = allTrim(document.form.telefono.value);
	v4 = allTrim(document.form.email.value);
	v5 = allTrim(document.form.consulta.value);
	v6 = document.form.acepto.checked;
	
	if (!v6){
		alert(idiomas [idi][1]);
		return false;
	}
	
	if (v1.length == 0 || v2.length == 0 || v3.length == 0 || v4.length == 0 || v5.length == 0) {
		alert(idiomas [idi][2]);
		return false;
	}
	
	if(!er_numero.test(v3)) {
		alert(idiomas [idi][3]);
		return false;
   	}
	
	
	if(!er_email.test(v4)) { 
		alert(idiomas [idi][4]);
		return false;
	}	
	return true;
}
