<!--

var error = new Array();

error['space'] = " cannot begin with spaces";
function generateValues()
{	
	var code="";
//	var start_month = document.frmBooking.start_month.options[document.frmBooking.selectedIndex].value;
		for(i = 1; i <=31; i++)
		{
			if(i < 10)
				code+='<option value="' + i + '\">' + i + '</option>\n';
			else
				code+='<option value="' + i + '\">' + i + '</option>\n';
		}
	document.write(code);
}



function isWrongEmail(arg_string)
{
	if(arg_string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return false;
	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The email field is required");
		return true;
	}
	alert("The email given is invalid");
	return true;
}

function isWrongName(arg_string, field_name)
{
	if(arg_string.search(/[\@><\*\`\\|\/]/) != -1)
	{
		alert("What are you doing with the characters \";><&*`|'/\\\" ?");
		return true;
	}
	
	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The "+field_name+" field is required");
		return true;
	}
	
	if(arg_string.search(/^[a-zA-Z\W]+$/) != -1) 
		return false;


	alert("Last and/or first name invalid");
	return true;
}

function isWrongString(arg_string, field_name)
{
	if(arg_string.search(/[;><&\*`\|]/) != -1)
	{
		alert("What are you doing with the characters \";><&*`|'\" ?");
		return true;
	}

	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The "+field_name+" field is required and"+error['space']);
		return true;
	}
	
	if(arg_string.search(/^[a-zA-Z0-9\W?]+$/) != -1) return false; //ok, is not wrong

	alert("There are errors in the " + field_name +" field !");
	return true;	//yes, is wrong!
}

function isWrongProv(arg_string)
{
	if(arg_string.search(/[;><&\*`\|]/) != -1)
	{
		alert("What are you doing with the characters \";><&*`|'\" ?");
		return true;
	}

	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The province field is required and " + error['space']);
		return true;
	}

	if(arg_string.search(/^[a-zA-Z0-9\W?]{3,}$/) != -1) return false; //ok, is not wrong
	alert("You must specify a province or state or you must write the entire name (not initials).");

	return true;	//yes, is wrong!
}

function isWrongOptional(arg_string, field_name)
{
	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The "+field_name+" field is required and" + error['space']);
		return true;
	}
	if(arg_string.search(/[;><&\*`\|]/) == -1)return false;

	alert("What are you doing with the characters \";><&*`|'\" ?");
	return true;
}

function isWrongCAP(arg_string)
{
	if(arg_string.search(/^\s+/) != -1)
	{
		alert("The postal code field is required and" + error['space']);
		return true;
	}

	if(arg_string.search(/^[a-zA-Z0-9]+$/) != -1) return false;

	alert("The postal code has spaces or invalid characters. Or simply it's missed.");
	return true;
}



function validate()
{
	if(
		isWrongName(document.frmBooking.first_name.value, 'first name') ||
		isWrongName(document.frmBooking.last_name.value, 'last name')||
		isWrongString(document.frmBooking.address.value, 'address') ||
		isWrongOptional(document.frmBooking.city.value, 'city') ||
		isWrongCAP(document.frmBooking.postal_code.value) ||
		isWrongProv(document.frmBooking.province.value) ||
		isWrongString(document.frmBooking.country.value, 'country') ||
		isWrongEmail   (document.frmBooking.email.value) ||
		isWrongString(document.frmBooking.passport_nb.value, 'passport number')
		)
	{}

	else if(document.frmBooking.start_day.options[document.frmBooking.start_day.selectedIndex].value == 					
			document.frmBooking.end_day.options[document.frmBooking.end_day.selectedIndex].value &&
		   document.frmBooking.start_month.options[document.frmBooking.start_month.selectedIndex].value == document.frmBooking.end_month.options[document.frmBooking.end_month.selectedIndex].value)
		alert("Please, select an appropriate date interval.");
	//other conditions can be added
	else document.frmBooking.submit();
}

function validateContact()
{
	if(
		isWrongName(document.frmContact.fullname.value, 'fullname') ||
		isWrongEmail(document.frmContact.email.value) ||
		isWrongString(document.frmContact.message.value, 'message')
		)
	{}

	//other conditions can be added
	else document.frmContact.submit();
}