// Validador del formulario de contacto

function checkFormQuiz(quizform) {
	var why = "";
	why += checkEmail(quizform.EMAIL.value);
	if (why != "") {
		alert(why);
		return false;
	}
	return true;
}


function clear(contactform) {
	contactform.DiaSortida.value="";
	contactform.MesSortida.value="";
	contactform.AnySortida.value="";
	contactform.HoraSortida.value="";
	contactform.MinutsSortida.value="";
	contactform.HoraArribada.value="";
	contactform.MinutsArribada.value="";
	contactform.NumPassatgers.value="";
	contactform.ITINERARI.value="";
	contactform.NOM.value="";
	contactform.EMPRESA.value="";
	contactform.NIF.value="";
	contactform.EMAIL.value="";
	contactform.TELEFON.value="";
	contactform.FAX.value="";
	contactform.DIRECCIO.value="";
	contactform.POBLACIO.value="";
	contactform.CODIPOSTAL.value="";
	contactform.MAIL.value="";
}


function checkForm(contactform) {
	var why = "";
	why += checkDiaServei(contactform.DiaSortida.value);
	why += checkMesServei(contactform.MesSortida.value);
	why += checkAnyServei(contactform.AnySortida.value)
	why += checkHoraSortida(contactform.HoraSortida.value);
	why += checkMinutsSortida(contactform.MinutsSortida.value);
	why += checkHoraArribada(contactform.HoraArribada.value);
	why += checkMinutsArribada(contactform.MinutsArribada.value);
	why += checkNumPassatgers(contactform.NumPassatgers.value);
	why += checkItinerari(contactform.ITINERARI.value);
	why += checkNom(contactform.NOM.value);
	why += checkEmail(contactform.EMAIL.value);
	why += checkPhone(contactform.TELEFON.value);
	if (why != "") {
		alert(why);
		return false;
	}
	return true;
}


// Data del servei

function checkDiaServei(strng) {
	var error="";
	if (strng == "Dia") {
		error = "Si us plau, introdueixi el dia de servei.\n";
	}
	return error;
}
function checkMesServei(strng) {
	var error="";
	if (strng == "Mes") {
		error = "Si us plau, introdueixi el mes de servei.\n";
	}
	return error;
}
function checkAnyServei(strng) {
	var error="";
	if (strng == "Any") {
		error = "Si us plau, introdueixi l'any de servei.\n";
	}
	return error;
}


// Hora sortida

function checkHoraSortida(strng) {
	var error="";
	if (strng == "Hora") {
		error = "Si us plau, introdueixi l'hora de sortida.\n";
	}
	return error;
}
function checkMinutsSortida(strng) {
	var error="";
	if (strng == "Minuts") {
		error = "Si us plau, introdueixi els minuts a la hora de sortida.\n";
	}
	return error;
}


// Hora arribada

function checkHoraArribada(strng) {
	var error="";
	if (strng == "Hora") {
		error = "Si us plau, introdueixi l'hora de arribada.\n";
	}
	return error;
}
function checkMinutsArribada(strng) {
	var error="";
	if (strng == "Minuts") {
		error = "Si us plau, introdueixi els minuts a l'hora de arribada.\n";
	}
	return error;
}

// Num Passatgers

function checkNumPassatgers(strng) {
	var error="";
	if (strng == "") {
		error = "Si us plau, introdueixi el numero de passatgers.\n";
	}
	return error;
}


// Itinerari

function checkItinerari(strng) {
	var error="";
	if (strng == "") {
		error = "Si us plau, introdueixi el itinerari.\n";
	}
	return error;
}

// Nom

function checkNom(strng) {
	var error="";
	if (strng == "") {
		error = "Si us plau, introdueixi el seu nom.\n";
	}
	return error;
}


// email

function checkEmail (strng) {
	var error="";
	if (strng == "") {
		error = "Introdueixi el seu correo electronic.\n";
	}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Introdueixi una direccio de correu electronic correcte.\n";
	} else {
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
		if (strng.match(illegalChars)) {
			error = "La direccio de correu electronic conte caracters no valids.\n";
		}
	}
	return error;    
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
	var error = "";
	if (strng == "") {
		error = "Si us plau, introdueixi el seu telefon.\n";
	}
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		error = "El seu telefon conte caracters no valids.";
	}
	if (!(stripped.length == 9)) {
		error = "El telefon ha de tindre 9 digits.\n";
	} 
	return error;
}