function check(f){
	if (document.getElementById('arrivalDateD').value==0) {
		err_pass("arrivalDateD");
		return false;
	}
	if (document.getElementById('arrivalDateM').value==0) {
		err_pass("arrivalDateM");
		return false;
	}
	if (document.getElementById('arrivalDateY').value==0) {
		err_pass("arrivalDateY");
		return false;
	}	
	if (document.getElementById('departureDateD').value==0) {
		err_pass("departureDateD");
		return false;
	}
	if (document.getElementById('departureDateM').value==0) {
		err_pass("departureDateM");
		return false;
	}
	if (document.getElementById('departureDateY').value==0) {
		err_pass("departureDateY");
		return false;
	}		
	if (document.getElementById('mlfirstName').value=='') {
		err_pass("firstName");
		document.getElementById('mlfirstName').focus();
		document.getElementById('mlfirstName').select();
		return false;
	}
	if (document.getElementById('mllastName').value=='') {
		err_pass("lastName");
		document.getElementById('mllastName').focus();
		document.getElementById('mllastName').select();
		return false;
	}
	
	if (document.getElementById('email').value=='') {
		err_pass("email");
		document.getElementById('email').focus();
		document.getElementById('email').select();
		return false;
	}
	if (document.getElementById('confirmEmail').value=='') {
		err_pass("confirmEmail");
		document.getElementById('confirmEmail').focus();
		document.getElementById('confirmEmail').select();
		return false;
	}
	
	if (document.getElementById('email').value != 
			document.getElementById('confirmEmail').value) {
		err_pass("error");
		return false;
	}		
	
	if (document.getElementById('card').value=='' && document.getElementById('cardType').value!='None') {
		err_pass("card");
		document.getElementById('card').focus();
		document.getElementById('card').select();
		return false;
	}		
	
	if(emailCheck(document.getElementById('email').value) &&
			emailCheck(document.getElementById('confirmEmail').value)) {
//		lsubmit(f);	
	}	
	
	return true;
}
function err_pass(key){
	var arrivalDateD = "Select the day of arrival";
	var arrivalDateM = "Select the month of arrival";
	var arrivalDateY = "Select the year of arrival";
	
	var departureDateD = "Select the day of departure";
	var departureDateM = "Select the month of departure";
	var departureDateY = "Select the year of departure";	
	
	var firstName = "Select the first name";
	var lastName  = "Select the last name";
	var email     = "Input the email address";
	var confirmEmail     = "Confirm the email address";
	var card     = "Input the card number";
	var error = "The email and confirmation must be the same";

	switch (key){
		case "arrivalDateD"     : alert(arrivalDateD); break;
		case "arrivalDateM"     : alert(arrivalDateM); break;
		case "arrivalDateY"     : alert(arrivalDateY); break;		
		case "departureDateD"   : alert(departureDateD); break;
		case "departureDateM"   : alert(departureDateM); break;
		case "departureDateY"   : alert(departureDateY); break;
		case "firstName" : alert(firstName); break;
		case "lastName"  : alert(lastName); break;
		case "email"     : alert(email); break;
		case "confirmEmail"     : alert(confirmEmail); break;
		case "card"     : alert(card); break;
		case "error"     : alert(error); break;
		
	}
}
function emailCheck(emailStr){
	var emailPat = /^(.+)@(.+)$/
	var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars = "\[^\\s" + specialChars + "\]"
	var quotedUser = "(\"[^\"]*\")"
	var ipDomainPat= /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom = validChars + '+'
	var word = "(" + atom + "|" + quotedUser + ")"
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)

	if (matchArray == null){alert("The email or confirmation is incorrect."); return false;}
	var user = matchArray[1]
	var domain = matchArray[2]
	if (user.match(userPat) == null){alert("The email or confirmation is incorrect."); return false;}
	var IPArray = domain.match(ipDomainPat)
	if (IPArray!=null){
		for (var i=1;i<=4;i++){
			if (IPArray[i]>255){alert("The email or confirmation is incorrect."); return false;}
		}
    	return true;
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null){alert("The email or confirmation is incorrect."); return false;}
	var atomPat = new RegExp(atom,"g")
	var domArr = domain.match(atomPat)
	var len = domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3){
	   alert("The email or confirmation is incorrect.")
	   return false
	}
	if (len<2){alert("The email or confirmation is incorrect."); return false;}
	return true;
}
function queVilla() {
	
	var id_villa = document.getElementById("villa");
	var villaTitle = document.getElementById("villaTitle");
	var option = document.getElementById("op"+id_villa.value);

	villaTitle.innerHTML = option.innerHTML;
	option.selected=true;
	document.getElementById("villa_hidden").value = id_villa.value;
}
