// JavaScript Document

function validateForm(who) {
	var name = who.Nome.value;
	var firstname = who.Cognome.value
	var email = who.Email.value;
	var easyRoom = who.Easy_Room.value;
	var circleRoom = who.Circle_Room.value;
	var executiveRoom = who.Executive_Room.value;
	var suite = who.Suite.value;
	var checkinYear =  who.Checkin_Year.options[who.Checkin_Year.selectedIndex].value;
	var checkoutYear = who.Checkout_Year.options[who.Checkout_Year.selectedIndex].value;
	var checkinMonth = who.Checkin_Month.options[who.Checkin_Month.selectedIndex].value;
	var checkoutMonth = who.Checkout_Month.options[who.Checkout_Month.selectedIndex].value;
	var checkinDay = who.Checkin_Day.options[who.Checkin_Day.selectedIndex].value;
	var checkoutDay = who.Checkout_Day.options[who.Checkout_Day.selectedIndex].value;

	var langsetup = "it";
	var url = document.URL;
	if (url.lastIndexOf("eng") != -1) 
		langsetup = "eng";

	if (name == "" ||
		firstname == "" ||
		email == "") {
			if (langsetup == "it")
				alert ("Si prega di compilare il modulo facendo attenzione ai campi obbligatori (..ai campi contrassegnati dall'asterisco)");
			else
				alert ("Please enter all of the required fields.");
		return false;
	} 

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		if (langsetup == "it")
	   		alert("Scrivete una Email valida.");
		else
			alert("Please fill in a valid email address.");
	   return false;
	}

	if (checkoutYear < checkinYear) {
		if (langsetup == "it")
			alert ("La data del check-out non puņ precedere la data del check-in.");
		else
			alert ("The checkout date cannot be earlier than the checkin date.");
		return false;
	} else if (checkoutYear == checkinYear) {
		if (checkoutMonth < checkinMonth) {
			if (langsetup == "it")
				alert ("La data del check-out non puņ precedere la data del check-in.");
			else
				alert ("The checkout date cannot be earlier than the checkin date.");
			return false;
		} else if (checkoutMonth == checkinMonth) {
			if (checkoutDay == checkinDay || checkoutDay < checkinDay ) {
				if (langsetup == "it")
					alert ("La data del check-out non puņ essere uguale o precedere la data del check-in.");
				else
					alert ("The checkout date cannot be the same or earlier than the checkin date.");
				return false;
			}
		}
	}

	if (easyRoom == "0" && circleRoom == "0" && executiveRoom == "0" && suite == "0") {
		if (langsetup == "it")
			alert ("Si prega di compilare il modulo facendo attenzione ai campi obbligatori (..ai campi contrassegnati dall'asterisco)");
		else
			alert ("Please select at least one type of room.");
		return false;
	} 

	return true;

}

	function validateRequiredFields() {
		if (document.forms[0].nuitaction[0].checked) { // insert
			if (document.getElementById('head').value == "")  {
				alert("Please make sure the Headline field is not Empty!")
				return false;
			}
		}
		if (document.forms[0].nuitaction[1].checked) { // select/update
				if (document.getElementById('id').length == 1)  {
						alert("There are no Concerts to be updated!");
						return false;
				} else 	if (document.getElementById('id').value == "")  {
						alert("Please make sure a Concert is selected from the pulldown!")
						return false;
				}
		}
		if (document.forms[0].nuitaction[2].checked) { // delete
				if (document.getElementById('id').length == 1)  {
						alert("There are no Concerts to be deleted!");
						return false;
				} else 	if (document.getElementById('id').value == "")  {
						alert("Please make sure a Concert is selected from the pulldown!")
						return false;
				}
				var agree=confirm("Are you sure you want to delete this concert?");
				if (agree)
					return true;
				else
					return false;
		}
		if (document.forms[0].nuitaction[3].checked) { // delete all
				if (document.getElementById('id').length == 1)  {
						alert("There are no Concerts to be deleted!");
						return false;
				} 
				var agree=confirm("Are you sure you want to delete all concerts?");
				if (agree)
					return true ;
				else
					return false;
		}
		return true;
	}

	function validateRequiredTxTFields() {
		var emptyList = new Array();
		if (document.forms[0].bioaction[0].checked && document.getElementById('txtbody').value == "") {
				emptyList.push("Text\n");
		} 

		if (emptyList.length < 1) {
			return true;
		}
		
		alert("Please make sure the Textfield is not empty.");
		return false;

	}


	function setElementInactive(formElement, setValue)  {
			document.getElementById(formElement).disabled = setValue; 
	}

	function set2ElementsInactive(formElement, formElement2, setValue)  {
			document.getElementById(formElement).disabled = setValue; 
			document.getElementById(formElement2).disabled = setValue; 
	}

	function set3ElementsInactive(formElement, formElement2, formElement3, setValue )  {
			document.getElementById(formElement).disabled = setValue;  
			document.getElementById(formElement2).disabled = setValue;  
			document.getElementById(formElement3).disabled = setValue;  
	}

	function set4ElementsInactive(formElement, formElement2, formElement3, formElement4, setValue )  {
			document.getElementById(formElement).disabled = setValue;  
			document.getElementById(formElement2).disabled = setValue;  
			document.getElementById(formElement3).disabled = setValue;  
			document.getElementById(formElement4).disabled = setValue;  
	}

	function setInactiveCDTitles(formElement, formElement2, formElement3, setValue )  {
			set3ElementsInactive(formElement, formElement2, formElement3, setValue );
			for (idx = 0; idx < 18; idx++) {
				var txtBoxName = "title" + idx;
				document.getElementById(txtBoxName).disabled = setValue; 
			}
	}

    function setClearFlag(flag) {
		document.getElementById("flag").value = flag; 
	}
