// JavaScript Document

/**
*Checks for alphabetic characters
*/
function isLetter(c)
{
	//if the character passes the evaluation, it isn't a letter
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for alphabetic characters, hyphens and spaces
*/
function isAlpha(c)
{
	//if the character passes the evaluation, it is not a letter, hyphen or space
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && ((c != "-") && (c != " ")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for numeric characters
*/
function isNumber(c)
{
	//if the character passes the evaluation it isn't a number
	if((c < "0") || (c > "9"))
	{
		return false;
	}//end if
	return true;
}//end isNumber

/**
*Checks for alphanumeric characters, spaces, hyphens, periods and pound
*/
function isAlphaNum(c)
{
	//if the character passes the evaluation, then it isn't an alphanumeric character, space, period or number sign
	if(((c < "0") || (c > "9")) && (((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && (c != " ") && (c != "-") && (c != ".") && (c != "#")))
	{
		return false;
	}//end if
	return true;
}//end isAlphaNum()

//***START***

//function checkFirstName
function checkFirstName()
{
	var fname = document.form.fname.value;
	
	if(fname == null || fname == "" )
	{
		document.form.fname.style.color = "FFFFFF";
		document.form.fname.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
		for(var i = 0; i < fname.length; i+= 1)
		{
			var isGood = isAlpha(fname.charAt(i));
			
			if(!isGood)
			{
				document.form.fname.style.color = "FFFFFF";
				document.form.fname.style.backgroundColor = "FFFFCC";;
				return false;
			}//end if
	     }//end for
	
	return true;
	
}//end function checkFirstName()


//function checkLastName
function checkLastName()
{
	var lname = document.form.lname.value;
	
	if(lname == null || lname == "" )
	{
		document.form.lname.style.color = "FFFFFF";
		document.form.lname.style.backgroundColor = "FFFFCC";;
		return false;
	}//end if
		for(var i = 0; i < lname.length; i+= 1)
		{
			var isGood = isAlpha(lname.charAt(i));
			
			if(!isGood)
			{
				document.form.lname.style.color = "FFFFFF";
				document.form.lname.style.backgroundColor = "FFFFCC";;
				return false;
			}//end if
	     }//end for
	
	return true;
	
}//end function checkLastName()

//function checkPhoneNumber
function checkPhoneNumber()
{
	var phone1 = document.form.phone1.value;
	var phone2 = document.form.phone2.value;
	var phone3 = document.form.phone3.value;
	
	if((phone1 == null || phone1 == "") || phone1.length < 3)
	{
		document.form.phone1.style.color = "FFFFFF";
		document.form.phone1.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if((phone2 == null || phone2 == "") || phone2.length < 3)
	{
		document.form.phone2.style.color = "FFFFFF";
		document.form.phone2.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if((phone3 == null || phone3 == "") || phone3.length < 4)
	{
		document.form.phone3.style.color = "FFFFFF";
		document.form.phone3.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	
	for(var i = 0; i < phone1.length; i+= 1)
	{
		var isGood = isNumber(phone1.charAt(i));
		
		if(!isGood)
		{
			document.form.phone1.style.color = "FFFFFF";
			document.form.phone1.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	
	for(var i = 0; i < phone2.length; i+= 1)
	{
		var isGood = isNumber(phone2.charAt(i));
		
		if(!isGood)
		{
			document.form.phone2.style.color = "FFFFFF";
			document.form.phone2.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	
	for(var i = 0; i < phone3.length; i+= 1)
	{
		var isGood = isNumber(phone3.charAt(i));
		
		if(!isGood)
		{
			document.form.phone3.style.color = "FFFFFF";
			document.form.phone3.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	
	return true;
}//end function checkPhoneNumber()

//function checkEmail
function checkEmail()
{
	//obtain the value of the email field and use a regular expression to make sure the address is valid
	var email = document.form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.ca)|(\..{2,2}))$)\b/gi);
	
	//if the address is valid, return true
	if (!email)
	{
		//set the text color to white and the background color to turquoise and return false
	   document.form.email.style.color = "FFFFFF";
	   document.form.email.style.backgroundColor = "FFFFCC";
	   return false;
	}//end else
	return true;
}//end function checkEmail()

//function checkArrivalDate
function checkArrivalDate()
{
	var arr_day = document.form.arr_day.value;
	var arr_month = document.form.arr_month.value;
	var arr_year = document.form.arr_year.value;
	
	var dep_day = document.form.dep_day.value;
	var dep_month = document.form.dep_month.value;
	var dep_year = document.form.dep_year.value;
	
	
	var date = new Date();
	var this_year = date.getYear();
	var this_month = date.getMonth() + 1;
	var today = date.getDate();
	
	if(arr_day == 0)
	{
		document.form.arr_day.style.color = "FFFFFF";
		document.form.arr_day.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if(arr_month == 0)
	{
		document.form.arr_month.style.color = "FFFFFF";
		document.form.arr_month.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if(arr_year == 0)
	{
		document.form.arr_year.style.color = "FFFFFF";
		document.form.arr_year.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	

	if(arr_year == this_year)
	{
		if(arr_month < this_month)
		{
			document.form.arr_month.style.color = "FFFFFF";
			document.form.arr_month.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
		else if(arr_month == this_month)
		{
			if(arr_day <= today)
			{
				document.form.arr_day.style.color = "FFFFFF";
				document.form.arr_day.style.backgroundColor = "FFFFCC";
				return false;
			}//end if
		}//end else
	}//end if
	if(dep_year == arr_year)
	{
		if(dep_month == arr_month)
		{
			if(dep_day <= arr_day)
			{
				document.form.arr_day.style.color = "FFFFFF";
				document.form.arr_day.style.backgroundColor = "FFFFCC";
				return false;
			}//end if
		}//end if
	}//end if
	
	return true;
}//end checkArrivalDate()

//function checkDepartureDate
function checkDepartureDate()
{
	var dep_day = document.form.dep_day.value;
	var dep_month = document.form.dep_month.value;
	var dep_year = document.form.dep_year.value;
	
	var arr_day = document.form.arr_day.value;
	var arr_month = document.form.arr_month.value;
	var arr_year = document.form.arr_year.value;
	
	var date = new Date();
	var this_year = date.getYear();
	var this_month = date.getMonth() + 1;
	var today = date.getDate();
	
	if(dep_day == 0)
	{
		document.form.dep_day.style.color = "FFFFFF";
		document.form.dep_day.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if(dep_month == 0)
	{
		document.form.dep_month.style.color = "FFFFFF";
		document.form.dep_month.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if(dep_year == 0)
	{
		document.form.dep_year.style.color = "FFFFFF";
		document.form.dep_year.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	
	if(dep_year == this_year)
	{
		if(dep_month < this_month)
		{
			document.form.dep_month.style.color = "FFFFFF";
			document.form.dep_month.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
		else if(dep_month == this_month)
		{
			if(dep_day <= today)
			{
				document.form.dep_day.style.color = "FFFFFF";
				document.form.dep_day.style.backgroundColor = "FFFFCC";
				return false;
			}//end if
		}//end else
	}//end if	
	
	return true;
}//end function checkDepartureDate()

//function checkNumberPeople
function checkNumberPeople()
{
	var total_people = document.form.total_people.value;
	
	if(total_people == null || total_people == "")
	{
		document.form.total_people.style.color = "FFFFFF";
		document.form.total_people.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	else if(total_people == "0")
	{
		document.form.total_people.style.color = "FFFFFF";
		document.form.total_people.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	
	for(var i = 0; i < total_people.length; i += 1)
	{
		var isGood = isNumber(total_people.charAt(i));
		
		if(!isGood)
		{
			document.form.total_people.style.color = "FFFFFF";
			document.form.total_people.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	
	return true;
}//end function checkNumberPeople()

function do_theCheck(){
	
	
	if(document.form.continental_breakfast_sameroom.checked == true)
	{		
		document.form.continental_breakfast_sameroom2.value = 'YES';
	}//end if
	else
	{
		document.form.continental_breakfast_sameroom2.value = 'NO';
	}//end else
	if(document.form.continental_breakfast_restaurant.checked == true)
	{		
		document.form.continental_breakfast_restaurant2.value = 'YES';
	}//end if
	else
	{
		document.form.continental_breakfast_restaurant2.value = 'NO';
	}//end else	
	if(document.form.morning_break.checked == true)
	{		
		document.form.morning_break2.value = 'YES';
	}//end if
	else
	{
		document.form.morning_break2.value = 'NO';
	}//end else	
	if(document.form.lunch_sameroom.checked == true)
	{		
		document.form.lunch_sameroom2.value = 'YES';
	}//end if
	else
	{
		document.form.lunch_sameroom2.value = 'NO';
	}//end else	
	if(document.form.lunch_restaurant.checked == true)
	{
		document.form.lunch_restaurant2.value = 'YES';
	}//end if
	else
	{
		document.form.lunch_restaurant2.value = 'NO';
	}//end else	
	if(document.form.afternoon_break.checked == true)
	{
		document.form.afternoon_break2.value = 'YES';
	}//end if
	else
	{
		document.form.afternoon_break2.value = 'NO';
	}//end else	
	if(document.form.diner.checked == true)
	{
		document.form.diner2.value = 'YES';
	}//end if
	else
	{
		document.form.diner2.value = 'NO';
	}//end else	
	if(document.form.reception_banquet.checked == true)
	{
		document.form.reception_banquet2.value = 'YES';
	}//end if
	else
	{
		document.form.reception_banquet2.value = 'NO';
	}//end else	
	if(document.form.overhead_projector.checked == true)
	{
		document.form.overhead_projector2.value = 'YES';
	}//end if
	else
	{
		document.form.overhead_projector2.value = 'NO';
	}//end else	
	if(document.form.tv.checked == true)
	{
		document.form.tv2.value = 'YES';
	}//end if
	else
	{
		document.form.tv2.value = 'NO';
	}//end else	
	if(document.form.vhs.checked == true)
	{
		document.form.vhs2.value = 'YES';
	}//end if
	else
	{
		document.form.vhs2.value = 'NO';
	}//end else	
	if(document.form.ecran.checked == true)
	{	
		document.form.ecran2.value = 'YES';
	}//end if
	else
	{
		document.form.ecran2.value = 'NO';
	}//end else	
	if(document.form.flipchart.checked == true)
	{
		document.form.flipchart2.value = 'YES';
	}//end if	
	else
	{
		document.form.flipchart2.value = 'NO';
	}//end else	
	
}//end function do_theCheck()



//** This will validate the whole form
function validate()
{
	var fname = checkFirstName();
	var lname = checkLastName();
	var phone = checkPhoneNumber();
	var email = checkEmail();
	var arrival = checkArrivalDate();
	var departure = checkDepartureDate();
	var people = checkNumberPeople();
	//var check = do_theCheck();
	
	if(!fname)
	{
		alert('Error! Please enter your first name ');
		return false;
	}//else if
	if(!lname)
	{
		alert('Error! Please enter your last name ');
		return false;
	}//else if
	if(!phone)
	{
		alert('Error! Please enter your telephone number ');
		return false;
	}//else if
	if(!email)
	{
		alert('Error! Please enter your email address ');
		return false;
	}//else if
	if(!arrival)
	{
		alert('Error! Please enter the arrival date ');
		return false;
	}//else if
	if(!departure)
	{
		alert('Error! Please enter your departure date ');
		return false;
	}//end if	
	if(!people)
	{
		alert('Error! Please enter the number of people that will be attending the event ');
		return false;
	}//end if
	
	
	return true;	
}



function changeColor(c)
{
	c.style.color = "000000";
	c.style.backgroundColor = "FFFFFF";
}//end changeColor()






