function Checkform(f,lang) {
	var msg = "";
	if (lang=="ca") {
		msg = "Si us plau, comprova els camps obligatoris";
	} else if (lang=="es") {
		msg = "Por favor, comprueba los campos obligatorios";
	} else if (lang=="en") {
		msg = "Please, check compulsory fields";
	}
	
	if (f.nombre.value=="") {
		f.nombre.focus();
		alert(msg);
		return false;
	}

	if (f.correo.value=="") {
		f.correo.focus();
		alert(msg);
		return false;
	}

	return true;
}


function Validate(f,lang){
	if (Checkform(f,lang))
		ajaxCheckCaptcha(f,lang);
}

function ajaxCheckCaptcha(f,lang) {
	var captcha = f.captcha.value;
	var msg = '';
	if (lang=="ca") {
		msg = "El codi de seguretat no coincideix";
	} else if (lang=="es") {
		msg = "El código de seguridad no coincide";
	} else if (lang=="en") {
		msg = "security code mismatch";
	}
	
	$.ajax({
		type: "GET",
		url: "/contacte/json_check_captcha.php",
		data: 'captcha='+captcha,
		dataType: "json",
		error: function(){ alert('Error AJAX'); }, 
		success: function(data){
			if (data.captcha_ok) f.submit(); 
			else { alert(msg); f.captcha.focus(); }
		}
	});

}