// JavaScript Document// JavaScript Document
function FrontPage_Form1_Validator(theForm)
{
	if(theForm.Change)//Is there a change Field?
  	{  
  		if (theForm.Change.selectedIndex == 0)
  		{
    		alert("Please select the Service needed.");
    		theForm.Change.focus();
    		return false;
  		}
  	}
	
	if (theForm.Mailbox_Number)//Is there a Extension Field?
	{
		if (theForm.Mailbox_Number.value == "")
		{
			alert ("Please provide the mailbox number.")
			theForm.Mailbox_Number.focus();
			return false;
		}
	}
	
	if(theForm.Time_Problem_Started)//Is there a time porblem started Field?
  	{  
  		if (theForm.Time_Problem_Started.selectedIndex == 0)
  		{
    		alert("Please select the time that the problem started.");
    		theForm.Time_Problem_Started.focus();
    		return false;
  		}
  	}
  	if(theForm.Time_Available)//is there a time availabe field?
	{
			if(theForm.Time_Available.value == "")
			{
				alert("Please enter the time you will be available.");
				theForm.Time_Available.focus();
				return false
			}
	}
	if(theForm.Date_of_Birth)//is there a date of birth field?
	{
			if(theForm.Date_of_Birth.value == "")
			{
				alert("Please enter your date of birth.");
				theForm.Date_of_Birth.focus();
				return false
			}
	}
	if(theForm.BannerID)//is there a bannerid field?
	{
			if(theForm.BannerID.value == "")
			{
				alert("Please enter your BannerID Number.");
				theForm.BannerID.focus();
				return false;
			}
	}
	
	if (theForm.Building_Name)//Is there a Building Field?
  	{
		if (theForm.Building_Name.selectedIndex == 0)
	  	{
			alert("Please select your Dorm Building.");
			theForm.Building_Name.focus();
			return false;
	  	}
  	}
  	if (theForm.Room)//Is there a Room Field?
  	{
	 	if (theForm.Room.value == "")
	  	{
			alert ("YAYAYAYAYA!!!.")
			theForm.Room.focus();
			return false;
	  	}
  	}
  
  
    if (theForm.Full_Name)//Is there a Name Field?
	{
  		if (theForm.Full_Name.value == "")
  		{
	    	alert ("Please provide the contact name.")
			theForm.Full_Name.focus();
			return false;
  		}
	}
	
	 if(theForm.I_Agree)//is there a i agree checkbox?
	{
			if(theForm.I_Agree.checked == false)
			{
				alert("You must agree to the terms to continue.");
				theForm.I_Agree.focus();
				return false;
			}
	}
		
	if (theForm.phone)//Is there a Extension Field?
	{
		if (theForm.phone.value == "")
		{
			alert ("Please provide the contact telephone number.")
			theForm.phone.focus();
			return false;
		}
	}
	if(theForm.summary.value == "Site Survey Form" && theForm.email.value == "")
	{
		alert("Please input your email address!")
		theForm.email.focus()
		return false;
		
	}
	if(theForm.email && theForm.summary.value != "Site Survey Form")//Is there a email?
	{
		function checkemail()
		{
				var str=theForm.email.value
				//filter allows @dasny.org emails
				var filter=/^([\w-]+(?:\.[\w-]+)*)@(dasny.org)$/
				//filter2 allows @brockport.edu emails			
				var filter2=/^([\w-]+(?:\.[\w-]+)*)@(brockport.edu)$/
				if (!filter2.test(str))
				{
					if (!filter.test(str))
					{
						alert("Please input your BROCKPORT email address!")
						theForm.email.focus()
						return false;
					}
					else 
					 	return true; 
				}
				else 
					return true;	
		}
		if(!checkemail())
			return false;
	}
	if(theForm.summary.value == "Site Survey Form")
	{
		if(theForm.Account_Billed.selectedIndex == 0 && (theForm.Account_Not_Listed.value == "" || theForm.Company_Name.value == 0 ))
		{
			alert ("Please select a department or enter a company name.");
			theForm.Account_Billed.focus();
			return false;
		}
		else if(theForm.Account_Billed.selectedIndex == 1 && theForm.Account_Not_Listed.value == "")
		{
			alert ("Please specify the other department.");
			theForm.Account_Not_Listed.focus();
			return false;
		}
	}
	
	return (true);
}

function ResetForm()
{
	num = document.FrontPage_Form1.elements.length;
	//Loop Through form elements enabling all of them
	for(i = 0 ;i < num; i++)
	{
		if(document.FrontPage_Form1.elements[i].name != "Submit")
			document.FrontPage_Form1.elements[i].disabled = false;
		if(document.FrontPage_Form1.elements[i].name == "Available_Times")
			document.FrontPage_Form1.elements[i].disabled = true;
		
		
		
	}
}
function Validate()
{
	if(FrontPage_Form1_Validator(document.FrontPage_Form1))
	{
		num = document.FrontPage_Form1.elements.length;
		//Loop Through form elements diabling any that are not filled out
		for(i = 0 ;i < num; i++)
		{
			if (document.FrontPage_Form1.elements[i].type == "text")
				if (document.FrontPage_Form1.elements[i].value == "")
					document.FrontPage_Form1.elements[i].disabled = true;
			if (document.FrontPage_Form1.elements[i].selectedIndex == 0)
				document.FrontPage_Form1.elements[i].disabled = true;
			
				
		
			if(document.FrontPage_Form1.elements[i].value == "on")
				document.FrontPage_Form1.elements[i].value = "";
		}
	
	if(document.FrontPage_Form1.Date_Month)
			document.FrontPage_Form1.Date_Month.disabled=true;
		document.FrontPage_Form1.submit();
	}
	
	
}
function phonePickup()
{
	if(document.FrontPage_Form1.Phone_Delivery.selectedIndex == 1)
		document.FrontPage_Form1.Available_Times.disabled = false;
	else
		document.FrontPage_Form1.Available_Times.disabled = true;
		
}
