// JavaScript Document// JavaScript Document// JavaScript Document
function FrontPage_Form1_Validator(theForm)
{ 
	//The First Three Fields Are Required for almost all Admin Forms
	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.Mailbox_Number)//Is there a required mailbox number field?
	{
  		if (theForm.Mailbox_Number.value == "")
  		{
	    	alert ("Please provide the mailbox number. It is the last 4 digits of your phone number or your extension")
			theForm.Mailbox_Number.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.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.email)//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)$/
				//filter3 allows @? email addresses
				var filter3=/^([\w-]+(?:\.[\w-]+)*)@(basc1.org)$/
				if (!filter3.test(str))
				{
					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;
				}
				else 
					return true;
		}
		if(!checkemail())
			return false;
	}
	if(
	theForm.summary.value == "Admin Computer Line Move" 
	|| theForm.summary.value == "Audio Conferencing Bridge" 
	|| theForm.summary.value == "Admin Voice Mailbox" 
	|| theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)"
	|| theForm.Work_Type.value == "106 - Telephone Line Disconnect"  
	|| theForm.Work_Type.value == "110 - Telephone Line Programming Change" 
	|| theForm.Work_Type.value == "115 - ACD Telephone Programming Change" 
	|| theForm.Work_Type.value == "130 - Telephone Line Name Change" 
	|| theForm.Work_Type.value == "201 - Add Voice Mailbox" 
	|| theForm.Work_Type.value == "203 - Voicemail Password Reset/Re-enable" 
	|| theForm.Work_Type.value == "210 - Speech Recognition Changes" 
	|| theForm.Work_Type.value == "225 - Design/Build New ACD Queue" 
	|| theForm.Work_Type.value == "226 - Reprogram ACD Queue" 
	|| theForm.Work_Type.value == "230 - ACD Real Time Display/Reporting" 
	|| theForm.Work_Type.value == "240 - Design/Build Menu" 
	|| theForm.Work_Type.value == "241 - Change Existing Menu" 
	|| theForm.Work_Type.value == "300 - Data Install (Cable Needed)" 
	|| theForm.Work_Type.value == "500 - Cable Cleanup" 
	|| theForm.Work_Type.value == "615 - Data Line Repair" 
	|| theForm.Work_Type.value == "620 - Cable TV Repair"
	|| theForm.Work_Type.value == "Equipment Order" 
	|| theForm.Work_Type.value == "Other" 
	|| theForm.Work_Type.value == "PBN Application" 
	)
	{
		if (theForm.Account_Billed)//Is there a Account Billed?
		{
				if (theForm.Account_Billed.selectedIndex == 0)
				{
					alert ("Please provide the account under billing information.")
					theForm.Account_Billed.focus();
					return false;
				}
				else if (theForm.Account_Billed.selectedIndex == 1 && theForm.Account_Not_Listed.value == "")
				{
					alert("Please specify the other account to be billed.");
					theForm.Account_Not_Listed.focus();
					return false;
				}
				else if(theForm.Account_Billed.selectedIndex > 1 && theForm.department)
				{
					theForm.department.value = theForm.Account_Billed.options[theForm.Account_Billed.selectedIndex].text;
				}
		}
	}
	if(theForm.Work_Type.value == "110 - Telephone Line Programming Change")
	{
		if(theForm.Purchase_Phone.selectedIndex == 0)
		{
			alert("Please select yes or no.");
			theForm.Purchase_Phone.focus();
			return false;	
		}
		else if(theForm.Purchase_Phone.selectedIndex == 1 && theForm.Equipment.selectedIndex == 0)
		{
			alert("Please select the phone you wish to purchase.");
			theForm.Equipment.focus();
			return false;	
		}
		else if(theForm.Purchase_Phone.selectedIndex == 1 & theForm.Quantity.value == "")
		{
			alert("Please select quantity of the selected phone you wish to purchase.");
			theForm.Quantity.focus();
			return false;	
		}
	}
	if(	theForm.Work_Type.value == "115 - ACD Telephone Programming Change" ||  
		theForm.Work_Type.value == "620 - Cable TV Repair" || 
		theForm.Work_Type.value == "300 - Data Install (Cable Needed)" || 
		theForm.Work_Type.value == "106 - Telephone Line Disconnect" || 
		theForm.Work_Type.value == "615 - Data Line Repair" || 
		theForm.Work_Type.value == "110 - Telephone Line Programming Change" || 
		theForm.Work_Type.value == "102 - Telephone Line Install (Cable Needed)" || 
		theForm.Work_Type.value == "240 - Design/Build Menu" || 
		theForm.Work_Type.value ==  "130 - Telephone Line Name Change" || 
		theForm.Work_Type.value == "Other" || 
		theForm.Work_Type.value == "225 - Design/Build New ACD Queue" || 
		theForm.Work_Type.value == "PBN Application" || 
		theForm.Work_Type.value == "623 - Emergency Notification Speaker Repair")
	{
		if (theForm.Building_Name)//Is there a Building Field?
		{
			if (theForm.Building_Name.selectedIndex == 0)
			{
				alert("Please select your Building.");
				theForm.Building_Name.focus();
				return false;
			}
			else if (theForm.Building_Name.selectedIndex == 1 && theForm.Other_Location.value == "")
			{
				alert("Please specify the other location.");
				theForm.Other_Location.focus();
				return false;
			}
			else if(theForm.Building_Name.selectedIndex > 1 && theForm.building)
			{
				theForm.building.value = theForm.Building_Name.options[theForm.Building_Name.selectedIndex].text;
			}
		}
	}
	if( theForm.Work_Type.value == "102 - Telephone Line Install (Cable Needed)" || 
		theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)" || 
		theForm.Work_Type.value == "106 - Telephone Line Disconnect"  || 
		theForm.Work_Type.value == "110 - Telephone Line Programming Change" || 
		theForm.Work_Type.value == "112 - Admin Call Forward" || 
		theForm.Work_Type.value == "115 - ACD Telephone Programming Change" || 
		theForm.Work_Type.value ==  "130 - Telephone Line Name Change" || 
		theForm.Work_Type.value=="204 - Admin Remote Voicemail Notification "|| 
		theForm.Work_Type.value == "225 - Design/Build New ACD Queue" || 
		theForm.Work_Type.value == "240 - Design/Build Menu"  || 
		theForm.Work_Type.value == "300 - Data Install (Cable Needed)" ||  
		theForm.Work_Type.value == "600 - Telephone Line Repair" || 
		theForm.Work_Type.value == "615 - Data Line Repair" || 
		theForm.Work_Type.value == "620 - Cable TV Repair" || 
		theForm.Work_Type.value == "PBN Application"  ||
		theForm.Work_Type.value == "Other"
		)
	{
		if (theForm.Room)//Is there a Room Field?
		{
			if (theForm.Room.value == "")
			{
				alert ("Please provide the room number.")
				theForm.Room.focus();
				return false;
			}
		}
	}
	if(theForm.Work_Type.value == "115 - ACD Telephone Programming Change" 
		|| theForm.Work_Type.value == "110 - Telephone Line Programming Change")
	{
		if(theForm.Changes_To_Telephone)//Id=s the Changes to telephone
		{
				if(theForm.Changes_To_Telephone.value == "")
				{
					alert("Please enter the extension to make changes too.");
					theForm.Changes_To_Telephone.focus();
					return false;
				}
		}
	}
	if(theForm.Work_Type.value == "115 - ACD Telephone Programming Change" 
	|| theForm.Work_Type.value == "110 - Telephone Line Programming Change")
	{
		if(theForm.Caller_ID_Display_Name)//Is there a Display Name
		{
				if(theForm.Caller_ID_Display_Name.value == "")
				{
					alert("Please enter the caller ID display name.");
					theForm.Caller_ID_Display_Name.focus();
					return false;
				}
		}
	}
	if(theForm.summary.value == "Admin Voice Mailbox")
	{
		if(theForm.Change)//Is there a Display Name
		{
				if(theForm.Change.selectedIndex == 0)
				{
					alert("Please select a service.");
					theForm.Change.focus();
					return false;
				}
		}
	}
	if(theForm.summary.value == "Admin Voice Mailbox")
	{
		if(theForm.Voice_Mail_On)//Is there a Display Name
		{
				if(theForm.Voice_Mail_On.value == "")
				{
					alert("Please enter the extension of the changed +voicemail.");
					theForm.Voice_Mail_On.focus();
					return false;
				}
		}
	}
	if(theForm.summary.value == "Admin Voice Mailbox")
	{//This is the part of the Admin voicemail form that is for add new voicemail box only  
		if(theForm.Change.selectedIndex == 1)
		{
			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;
				}
				else if (theForm.Building_Name.selectedIndex == 1 && theForm.Other_Location.value == "")
				{
					alert("Please specify the other location.");
					theForm.Other_Location.focus();
					return false;
				}
			}
			if (theForm.Room)//Is there a Room Field?
			{
				if (theForm.Room.value == "")
				{
					alert ("Please provide the room number.")
					theForm.Room.focus();
					return false;
				}
			}
			if(theForm.Voice_Mailbox_Assigned_To.disabled == false)
			{
				if (theForm.Voice_Mailbox_Assigned_To.value == "")
				{
					alert ("Please provide the name assigned to the mailbox.")
					theForm.Voice_Mailbox_Assigned_To.focus();
					return false;
				}
			}
			if (theForm.To_Voice_Mail_When_Busy.disbaled == false)
			{
				if (theForm.To_Voice_Mail_When_Busy.selectedIndex == 0)
				{
					alert("Please choose yes or no.");
					theForm.To_Voice_Mail_When_Busy.focus();
					return false;
				}
			}
			if (theForm.To_Voice_Mail_When_Not_Answered.disbaled == false)
			{
				if (theForm.To_Voice_Mail_When_Not_Answered.selectedIndex == 0)
				{
					alert("Please choose yes or no.");
					theForm.To_Voice_Mail_When_Not_Answered.focus();
					return false;
				}
			}
		}
	}
	if(theForm.Work_Type.value == "620 - Cable TV Repair" 
	|| theForm.Work_Type.value == "615 - Data Line Repair")
	{
		if(theForm.Time_Problem_Started.selectedIndex == 0)
		{
				alert("Please select the time the problem started.");
				theForm.Time_Problem_Started.focus();
				return false;
		}
	}
	if(theForm.Work_Type.value == "300 - Data Install (Cable Needed)")
	{
		if(theForm.Number_Of_Drops.value == "")
		{
				alert("Please enter the number of connections.");
				theForm.Number_Of_Drops.focus();
				return false;
		}
	}
	if(theForm.Work_Type.value == "106 - Telephone Line Disconnect")
	{
		if(theForm.Disconnect_Telephone.value == "")
		{
			alert("Please enter the telephone number to be disconnected.");
			theForm.Disconnect_Telephone.focus();
			return false;
		}
		if(theForm.Line_Has_Voice_Mail.selectedIndex == 0)
		{
			alert("Please select yes or no.");
			theForm.Line_Has_Voice_Mail.focus();
			return false;
		}
	}
	if(theForm.Work_Type.value == "600 - Telephone Line Repair" )
	{
		if(theForm.summary.value == "Admin Telephone/Telephone Line Repair Request")
		{
			if(theForm.Payphone_In_Trouble.selectedIndex == 0 && theForm.Telephone_In_Trouble.value == "")
			{
				alert("Please select or enter the telephone in trouble.");
				theForm.Telephone_In_Trouble.focus();
				return false;
			}
			else if(theForm.Telephone_In_Trouble.value != "")
			{
					if (theForm.Room.value == "")
					{
						alert ("Please provide the room number.")
						theForm.Room.focus();
						return false;
					}
			}
			
		}
		else
		{
			if(theForm.Telephone_In_Trouble.selectedIndex == 0)
			{
					alert("Please select the telephone in trouble.");
					theForm.Telephone_In_Trouble.focus();
					return false;
			}
			else if(theForm.Telephone_In_Trouble.selectedIndex == 1 || 
			theForm.Telephone_In_Trouble.selectedIndex == 2 || 
			theForm.Telephone_In_Trouble.selectedIndex == 43 || 
			theForm.Telephone_In_Trouble.selectedIndex == 44 || 
			theForm.Telephone_In_Trouble.selectedIndex == 45 || 
			theForm.Telephone_In_Trouble.selectedIndex == 78 || 
			theForm.Telephone_In_Trouble.selectedIndex == 79 || 
			theForm.Telephone_In_Trouble.selectedIndex == 80)
			{
					alert("You have selected a heading field from the drop down list, Please Select a phone location from the drop down list.");
					theForm.Telephone_In_Trouble.focus();
					return false;
			}
		}
	}
	if(theForm.Work_Type.value == "Equipment Order")
	{
		if(theForm.Equipment.selectedIndex == 0)
		{
			alert("Please select the accessory you wish to purchase.");
			theForm.Equipment.focus();
			return false;
		}
	}
	if(theForm.Work_Type.value == "Equipment Order")
	{
		if(theForm.Quantity.value == 0)
		{
			alert("Please enter the amount of the selected accessory you wish to purchase.");
			theForm.Quantity.focus();
			return false;
		}
		if(theForm.Extension.value == "")
		{
			alert("Please enter extension where the accessory will be used.");
			theForm.Extension.focus();
			return false;
		}
	}
	if(theForm.Work_Type.value == "102 - Telephone Line Install (Cable Needed)")
	{
		if(document.FrontPage_Form1.Account_Billed_Monthly.selectedIndex == 0)
		{
			alert("Please select an account to be billed .");
			theForm.Account_Billed_Monthly.focus();
			return false;
		}
		else if(document.FrontPage_Form1.Account_Billed_Monthly.selectedIndex == 1 
		&& document.FrontPage_Form1.Monthly_Account_Not_Listed.value == "")
		{
			alert("Please specify the other account.");
			theForm.Monthly_Account_Not_Listed.focus();
			return false;
		}
		if(document.FrontPage_Form1.Account_Billed_Install.selectedIndex == 1)
		{
			if(document.FrontPage_Form1.Install_Account_Not_Listed.value == "")
			{
				alert("Please specify the other account.");
				theForm.Install_Account_Not_Listed.focus();
				return false;		
			}
		}
		if(theForm.Line_Type.selectedIndex == 0)
		{
			alert("Please select the type of telephone line you want to install.");
			theForm.Line_Type.focus();
			return false;
		}
		if(theForm.Purchase_Telephone.selectedIndex == 0)
		{
			alert("Please select yes or no.");
			theForm.Purchase_Telephone.focus();
			return false;
		}
		if(theForm.Telephone_Model.selectedIndex == 0)
		{
			alert("Please select the telephone model you will use for this line.");
			theForm.Telephone_Model.focus();
			return false;
		}
		if(theForm.Add_Voice_Mail.selectedIndex == 0)
		{
			alert("Please select yes or no.");
			theForm.Add_Voice_Mail.focus();
			return false;
		}
	}
	if(theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)" 
		&& theForm.summary.value != "Admin Computer Line Move")
	{
				if(theForm.Move_Telephone.value == "" 
					&& theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)")
			{
					alert("Please enter the number to be moved.");
					theForm.Move_Telephone.focus();
					return false;
			}
			if(theForm.Caller_ID_Display_Name.value == "" 
				&& theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)")
			{
					alert("Please enter the name to appear on caller ID.");
					theForm.Caller_ID_Display_Name.focus();
					return false;
			}	
		
	}
	if(theForm.Work_Type.value == "104 - Telephone Line Move (Cable Needed)")
	{
			if(theForm.Current_Building_Name.selectedIndex == 0)
			{
					alert("Please enter select the current building location.");
					theForm.Current_Building_Name.focus();
					return false;
			}
			else if(theForm.Current_Building_Name.selectedIndex == 1 & theForm.Current_Other_Location.value == "")
			{
					alert("Please specify the other location.");
					theForm.Current_Other_Location.focus();
					return false;
			}
			if(theForm.Current_Room.value == "")
			{
					alert("Please enter the current room location.");
					theForm.Current_Building_Name.focus();
					return false;
			}
			
			if(theForm.New_Building_Name.selectedIndex == 0)
			{
					alert("Please enter select the new building location.");
					theForm.New_Building_Name.focus();
					return false;
			}
			else if(theForm.New_Building_Name.selectedIndex == 1 & theForm.New_Other_Location.value == "")
			{
					alert("Please specify the other location.");
					theForm.New_Other_Location.focus();
					return false;
			}
			if(theForm.New_Room.value == "")
			{
					alert("Please enter the new room location.");
					theForm.New_Building_Name.focus();
					return false;
			}
	}
	if(theForm.Work_Type.value ==  "130 - Telephone Line Name Change")
	{
		if(theForm.Name_of_Person_Assigned_to_Phone_Line.value == "")
		{
			alert("Please enter the name of the person or department assigned to the phone.");
			theForm.Name_of_Person_Assigned_to_Phone_Line.focus();
			return false;
		}
		if(theForm.Change_Name_On_Telephone_Line.value == "")
		{
			alert("Please enter the phone number for the name change.");
			theForm.Change_Name_On_Telephone_Line.focus();
			return false;
		}
	}
	if(theForm.Work_Type.value == "PBN Application" && theForm.summary.value != "Audio Conferencing Bridge")
	{
		if(theForm.Date_of_Birth.value == "")
		{
			alert("Please enter your date of birth.");
			theForm.Date_of_Birth.focus();
			return false;
		}
		if(theForm.BannerID.value == "")
		{
			alert("Please enter your BannerID.");
			theForm.BannerID.focus();
			return false;
		}
		if(theForm.agreecheck.checked == false)
		{
			alert("Please read the terms and conditions. Then indicate that you have by checking the box.");
			theForm.agreecheck.focus();
			return false;
		}
	}
	
	if(theForm.Work_Type.value == "600 - Telephone Line Repair")
	{
		if(theForm.Time_Problem_Started.selectedIndex == 0)
		{
			alert("Please select the time the problem started.");
			theForm.Time_Problem_Started.focus();
			return false;
			
		}
	}
	
  	return (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 == "hidden")
				if (document.FrontPage_Form1.elements[i].value == "")
					document.FrontPage_Form1.elements[i].disabled = true;
			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 ResetForm()
{
	num = document.FrontPage_Form1.elements.length;
	//Loop Through form elements enabling all of them
	for(i = 0 ;i < num; i++)
	{
		document.FrontPage_Form1.elements[i].disabled = false;
		if(document.FrontPage_Form1.elements[i].name == "Account_Not_Listed" 
		&& document.FrontPage_Form1.Account_Billed.selectedIndex != 1)
		{
			document.FrontPage_Form1.elements[i].disabled = true;
		}
		if(document.FrontPage_Form1.elements[i].name == "Other_Location" 
		&& document.FrontPage_Form1.Building_Name.selectedIndex != 1)
		{
		
			document.FrontPage_Form1.elements[i].disabled = true;
		}
		
	}
	if(document.FrontPage_Form1.Purchase_Phone)
	{
		document.FrontPage_Form1.Purchase_Phone.selectedIndex = 0;
	}
	
}
function otherLocation()
{
	if(document.FrontPage_Form1.Building_Name.selectedIndex == 1)
		document.FrontPage_Form1.Other_Location.disabled = false;
	else
		document.FrontPage_Form1.Other_Location.disabled = true;
		
}
function otherLocations()
{
	if(document.FrontPage_Form1.Current_Building_Name.selectedIndex == 1)
		document.FrontPage_Form1.Current_Other_Location.disabled = false;
	else
		document.FrontPage_Form1.Current_Other_Location.disabled = true;

if(document.FrontPage_Form1.New_Building_Name.selectedIndex == 1)
		document.FrontPage_Form1.New_Other_Location.disabled = false;
	else
		document.FrontPage_Form1.New_Other_Location.disabled = true;

		
}
function otherAccount()
{
	if(document.FrontPage_Form1.Account_Billed.selectedIndex == 1)
		document.FrontPage_Form1.Account_Not_Listed.disabled = false;
	else
		document.FrontPage_Form1.Account_Not_Listed.disabled = true;
		
}
function otherAccounts()
{
	if(document.FrontPage_Form1.Account_Billed_Monthly.selectedIndex == 1)
		document.FrontPage_Form1.Monthly_Account_Not_Listed.disabled = false;
	else
		document.FrontPage_Form1.Monthly_Account_Not_Listed.disabled = true;
	
	if(document.FrontPage_Form1.Account_Billed_Install.selectedIndex == 1)
		document.FrontPage_Form1.Install_Account_Not_Listed.disabled = false;
	else
		document.FrontPage_Form1.Install_Account_Not_Listed.disabled = true;
		
}

