/* Validate all user booking information */

/*function validateQuickSearch() {

}*/

function validEmail(email) {
 var regex=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (regex.test(email)) {
		return true;
	} else {
		return false;
	}
}

var normalBackground = "white";
var invalidBackground = "#EEDC82";

function validate() {
	/* Booking details */
       var checkIn = document.getElementById("check_in");
       var checkOut = document.getElementById("check_out");
       var noRooms = document.getElementById("no_rooms");
       var roomType = document.getElementById("room_type");
       var noAdults = document.getElementById("no_adults");
       var noChildren = document.getElementById("no_children");
       var twoUnder = document.getElementById("two_under");
       var threeThirteen = document.getElementById("three_thirteen");
       
       /* Personal Information */
       var Name = document.getElementById("fullname");
       //var secondName= document.getElementById("surname");
       var email = document.getElementById("email");
       var address = document.getElementById("address");
       /*var town = document.getElementById("town");
       var city = document.getElementById("city");
       var county = document.getElementById("county");*/
       var postcode = document.getElementById("postcode");
       var telephone = document.getElementById("telephone");
       var mobile = document.getElementById("mobile");

       var processError = false;
       var error = "";
       
       /* Booking information validation */
       if(checkIn.value.length < 5) {
               error += "Please enter a check in date\n";
               checkIn.style.background = invalidBackground;
               processError = true;
       }
       
       if(checkOut.value.length < 5) {
               error += "Please enter a check out date\n";
               checkOut.style.background = invalidBackground;
               processError = true;
       }
       
       /*if(noChildren.value > 0 && twoUnder.value != "two_under" || threeThirteen.value != "three_thirteen"  thirteenOver.value != "thirteen_over") {
               error += "Please enter the age of your children\n";
               processError = true;
       }*/
       
       /*if(noRooms.value == 1 && noChildren.value > 0 && twoUnder.checked == true && threeThirteen.checked == true &&  thirteenOver.checked== true) {
               error += "There is a limit of 2 children in any room\n";
               processError = true;
       }*/
       
       /*if(roomType.options.selectedIndex != "standard_double" && dog.value == "yes") {
		error += "Dogs are only allowed in standard double rooms\n";
                processError = true;
	}*/
	
	/*if(roomType.value != "standard_family" && twoUnder.checked == "two_under") {
		error += "This room is not available to families with children two and under\n";
                processError = true;
	}*/
	
       /* Personal information validation */
       if(Name.value.length < 3) {
               error += "Please enter your name\n";
               Name.style.background = invalidBackground;
               processError = true;
       }
       
       if(address.value.length < 5) {
               error += "Please enter your address\n";
               address.style.background = invalidBackground;
               processError = true;
       }
       
       if(postcode.value.length < 5) {
               error += "Please enter your postcode\n";
               postcode.style.background = invalidBackground;
               processError = true;
       }

       if(email.value.length > 0 && !validEmail(email.value)) {
               error += "Please enter a VALID email address\n";
               email.style.background = invalidBackground;
               processError = true;
       }

       if(email.value.length == 0 && telephone.value.length == 0) {
               error += "Please enter your email or telephone number\n";
               email.style.background = invalidBackground;
               telephone.style.background = invalidBackground;
               processError = true;
       }

       if( processError ) alert ( error );
       return ! processError;
}