//***********************************//
// www.villaxarahiz.com              //
// master javascript functions file  //
// Copyright 2002 - extrenet.com     //
//***********************************//

function submitIt(webform) {
	// fill date_in & date_out fields
	webform.date_in.value = webform.day_in.value + '-' + webform.month_in.value + '-' + webform.year_in.value;
	webform.date_out.value = webform.day_out.value + '-' + webform.month_out.value + '-' + webform.year_out.value;
	// check Name_Surname field
	if (webform.name_surname.value == ""){
	  alert('Introduzca su Nombre y Apellidos');
	  webform.name_surname.focus();
	  webform.name_surname.select();
	  return false;	
	}
	// check to see if the phone number is valid
	if (!validPhone(webform.phone.value)) {
		alert('Su nº de teléfono es incorrecto');
		webform.phone.focus();
		webform.phone.select();
		return false;
	}
	// check to see if the email's valid
	if (!validEmail(webform.email.value)) {
		alert('Su dirección de email es inválida.');
		webform.email.focus();
		webform.email.select();
		return false;
	}
	//  check message field
	if (webform.message.value == ""){
	  alert('Introduzca el tipo de habitación que desea');
	  webform.message.focus();
	  webform.message.select();
	  return false;	
	}
	// If we made it to here, everything's valid, so return true
	return true;
}

function validEmail(Email) {
	invalidChars = " /:,;"
	if (Email == "") {						// cannot be empty
		return false;
	}
	for (i=0; i<Email.length; i++) {	// does it contain any invalid characters?
		badChar = Email.charAt(i)
		if (invalidChars.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = Email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false;
	}
	if (Email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false;
	}
	periodPos = Email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false;
	}
	if (periodPos+3 > Email.length)	{		// must be at least 2 characters after the "."
		return false;
	}
	return true;
}

function validPhone(Phone) {
	validChars = " +0123456789";
	if (Phone == "") {						// cannot be empty
		return false;
	}
	for (i=0; i<Phone.length; i++) {	// does it contain any invalid characters?
		Char = Phone.charAt(i);
		//alert('char: '+Char);
		//alert('result:' + validChars.indexOf(Char,0) + 'bucle:' + i);
		if (validChars.indexOf(Char,0) <= -1) {
			return false;
		}
	}
	return true;
}
