	function AcceptForumGuidelines ( form_id, element_id )
	{
		if ( document.forms [ form_id ].elements [ element_id ].options[document.forms [ form_id ].elements [ element_id ].selectedIndex].value  == 'No' )
		{
			alert ( "You must agree to the forum guidelines!" )
			document.forms [ form_id ].elements [ element_id ].focus ()
			return false;
		}
		return true;
	}
	
	function AcceptTerms ( form_id, element_id )
	{
		if ( document.forms [ form_id ].elements [ element_id ].options[document.forms [ form_id ].elements [ element_id ].selectedIndex].value  == 'No' )
		{
			alert ( "You must agree to the terms of use agreement in order register online!" )
			document.forms [ form_id ].elements [ element_id ].focus ()
			return false;
		}
		return true;
	}

	function AreEqual ( tempField, form_id, element_id_1, element_id_2 )
	{
		if ( document.forms [ form_id ].elements [ element_id_1 ].value != document.forms [ form_id ].elements [ element_id_2 ].value)
		{
			alert (tempField)
			document.forms [ form_id ].elements [ element_id_1 ].focus ()
			document.forms [ form_id ].elements [ element_id_1 ].style.background='#ffcccc';
			return false;
		}
		return true
	}	

	function CheckDate (tempField, form_id, element_id)
	{
		str = document.forms [ form_id ].elements [ element_id ].value;
		if (!IsBlank(str))
		{
			if (IsDate(str)==false)
			{
				alert ( "'" + tempField + "' must be a valide date" )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].select ()
				return false;
			}
		}
		return true;
	}

	function DeletionWarning()
	{
		return ( confirm ( "By clicking 'Ok', you will be deleting this record.  To abort click 'Cancel'" ) )	
	}

	function IsBlank ( s )
	{
		var len = s.length
		var i
		
		for ( i = 0; i < len; i++ )
		{
			if ( s.charAt ( i ) != " " ) 
			 	return false;
		}
		return true;
	}
	
	function IsDecimal(tempField, form_id, element_id)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
		for (i = 0; i < document.forms [ form_id ].elements [ element_id ].value.length && IsNumber == true; i++) 
		{ 
			Char = document.forms [ form_id ].elements [ element_id ].value.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				alert ( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].select ()
				IsNumber = false;
			}
		}
		return IsNumber;
	}

	function IsDecimalSpecial ( tempField, form_id, element_id )
	{
		if (!( IsBlank ( document.forms [ form_id ].elements [ element_id ].value ) ) )
		{
			if (IsDecimal ( tempField, form_id, element_id ))
				return true;
			else
				return false;
		}
		return true;
	}

	function IsNumeric(tempField, form_id, element_id)
	{
		if ( isNaN ( document.forms [ form_id ].elements [ element_id ].value ) )
		{
			alert ( tempField )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}

		var len = document.forms [ form_id ].elements [ element_id ].value.length
		var i
		
		for ( i = 0; i < len; i++ )
		{
			if ( document.forms [ form_id ].elements [ element_id ].value.charAt ( i ) == "." || document.forms [ form_id ].elements [ element_id ].value.charAt ( i ) == "-"  ) 
			{				
				alert ( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].select ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false;
			}
		}		
		return true;
	}
	
	// validates a date
	function IsDate(SelectedDate)
	{
		var dtCh= "/";
		var MinYear=1900;
		var MaxYear=2100;
		var DaysInMonth=DaysArray(12)
		var pos1=SelectedDate.indexOf(dtCh)
		var pos2=SelectedDate.indexOf(dtCh,pos1+1)
		var SelectedMonth=SelectedDate.substring(0,pos1)
		var SelectedDay=SelectedDate.substring(pos1+1,pos2)
		var SelectedYear=SelectedDate.substring(pos2+1)
		var AdjustedYear=SelectedYear

		// handles leading zeros
		if (SelectedDay.charAt(0)=="0" && SelectedDay.length>1) SelectedDay=SelectedDay.substring(1)
		if (SelectedMonth.charAt(0)=="0" && SelectedMonth.length>1) SelectedMonth=SelectedMonth.substring(1)
		for (var i = 1; i <= 3; i++) 
		{
			if (AdjustedYear.charAt(0)=="0" && AdjustedYear.length>1) AdjustedYear=AdjustedYear.substring(1)
		}

		// checks each element of the date
		var month=parseInt(SelectedMonth)
		var day=parseInt(SelectedDay)
		var year=parseInt(AdjustedYear)
		if (pos1==-1 || pos2==-1)
			return false
		if (SelectedMonth.length<1 || month<1 || month>12)
			return false
		if (SelectedDay.length<1 || day<1 || day>31 || (month==2 && day>DaysInFebruary(year)) || day > DaysInMonth[month])
			return false
		if (SelectedYear.length != 4 || year==0 || year<MinYear || year>MaxYear)
			return false
		if (SelectedDate.indexOf(dtCh,pos2+1)!=-1 || IsInteger(StripDelimeter(SelectedDate, dtCh))==false)
			return false

		// selected date is a valid date
		return true
	}	

	function ResetBackground ( start, end, form_id )
	{
		for (i = start; i <= end; i++)
			document.forms [ form_id ].elements [ i ].style.background='#ffffff';
		
	}
	
	function TabFocus (OldFormID, OldElementID, NewFormID, NewElementID, MaxLength)
	{
		if (document.forms [OldFormID].elements [OldElementID].value.length >= MaxLength)
		{
			document.forms [NewFormID].elements [NewElementID].focus ();
			document.forms [NewFormID].elements [NewElementID].select ();
		}
	}

	function Validate ( tempField, form_id, element_id )
	{
		if ( IsBlank ( document.forms [ form_id ].elements [ element_id ].value ) )
		{
			alert ( tempField )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}
		return true;
	}
	
	function ValidateDate (tempField, form_id, element_id)
	{
		str = document.forms [ form_id ].elements [ element_id ].value;
		if (IsDate(str)==false)
		{
			alert ('Date must be in the following format : mm/dd/yyyy');
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false;
		}	
		return true;
	}

	function ValidateDateSpecial ( tempField, form_id, element_id )
	{
		str = document.forms [ form_id ].elements [ element_id ].value;
		if (!( IsBlank ( str ) ) )
		{
			if ( ! ( IsDate ( str ) ) )
			{
				alert ( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				return false;
			}
		}
		return true;
	}

	function ValidateEmailAddress ( tempField, form_id, element_id )
	{
		var str=document.forms [ form_id ].elements [ element_id ].value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
		{
		   alert( tempField )
		   document.forms [ form_id ].elements [ element_id ].focus ()
		   document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert( tempField )
		   document.forms [ form_id ].elements [ element_id ].focus ()
		   document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert( tempField )
		    document.forms [ form_id ].elements [ element_id ].focus ()
		    document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    alert( tempField )
		    document.forms [ form_id ].elements [ element_id ].focus ()
		    document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    alert( tempField )
		    document.forms [ form_id ].elements [ element_id ].focus ()
		    document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    alert( tempField )
		    document.forms [ form_id ].elements [ element_id ].focus ()
		    document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    alert( tempField )
		    document.forms [ form_id ].elements [ element_id ].focus ()
		    document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
		    return false
		 }

 		 return true					
	}

	function ValidateEmailAddressSpecial ( tempField, form_id, element_id )
	{
		if ( !( IsBlank ( document.forms [ form_id ].elements [ element_id ].value ) ) )
		{
			var str=document.forms [ form_id ].elements [ element_id ].value;
			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			
			if (str.indexOf(at)==-1)
			{
			alert( tempField )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false
			}

			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
			{
			alert( tempField )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false
			}

			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
			{
				alert( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false
			}

			if (str.indexOf(at,(lat+1))!=-1)
			{
				alert( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false
			}

			if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
			{
				alert( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false
			}

			if (str.indexOf(dot,(lat+2))==-1)
			{
				alert( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false
			}
			
			if (str.indexOf(" ")!=-1)
			{
				alert( tempField )
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
				return false
			}
		 }

 		 return true					
	}
	
	function ValidatePassword ( tempField, form_id, element_id )
	{
		var passwordStr = document.forms [ form_id ].elements [ element_id ].value;

		if ( IsBlank ( passwordStr ) )
		{
			alert ( tempField )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false
		}
		
		var len = passwordStr.length
		
		if (len < 8)
		{
			alert ( "Password must be at least 8 characters long and contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter." )
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false
		}
		
		var passwordPattern = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/
		var matchArray = passwordStr.match(passwordPattern);
		if (matchArray == null) 
		{
			alert("Password must be at least 8 characters long and contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter."); 
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}
		
		return true
	}

	function ValidateRadioButton ( tempField, form_id, int_max )
	{
		var RadioSelected = false;
	
		for (i = 1; i <= int_max;i++)
			if ( eval(document.forms [ form_id ].elements [ i ].checked) == true)
				RadioSelected = true;
		
		if (RadioSelected)
			return true;
		else
		{
			alert ( tempField )
			return false;
		}
	}
	
	function ValidateTimeSpecial ( tempField, form_id, element_id )
	{
		var timeStr = document.forms [ form_id ].elements [ element_id ].value;
		
		var timePat = /^(\d{1,2}):(\d{2})?(\s?(AM|am|PM|pm))?$/;
		var matchArray = timeStr.match(timePat);
		if (matchArray == null) 
		{
			alert(tempField);
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}
		hour = matchArray[1];
		minute = matchArray[2];
		ampm = matchArray[4];

		if (ampm=="") { ampm = null }

		if (hour < 0  || hour > 12) 
		{
			alert("Hour must be between 1 and 12.");
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}
		if (minute<0 || minute > 59) 
		{
			alert ("Minute must be between 0 and 59.");
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
			document.forms [ form_id ].elements [ element_id ].style.background='#ffcccc';
			return false;
		}
		return true;
	}

	function ValidateURL(form_id, element_id)
	{
        str = document.forms [ form_id ].elements [ element_id ].value;
		if (!(validFormat(/^http:\/\/.+/, str)) && !(validFormat(/^https:\/\/.+/, str)))
       	{
        	alert("URL must contain http://' or 'https://' in the beginning of the string");
			document.forms [ form_id ].elements [ element_id ].focus ()
			document.forms [ form_id ].elements [ element_id ].select ()
	        return false;
		}
      	return true;
	}

	function ValidateURLSpecial ( form_id, element_id )
	{
		str = document.forms [ form_id ].elements [ element_id ].value;
		if (!( IsBlank ( str ) ) )
		{
			if (!(validFormat(/^http:\/\/.+/, str)) && !(validFormat(/^https:\/\/.+/, str)))
       		{
        		alert("URL must contain http://' or 'https://' in the beginning of the string");
				document.forms [ form_id ].elements [ element_id ].focus ()
				document.forms [ form_id ].elements [ element_id ].select ()
				return false;
			}
		}
		return true;
	}

	function ValidateWarning (form_id, element_id )
	{
		if (!( IsBlank ( document.forms [ form_id ].elements [ element_id ].value ) ))
		{
			return ( confirm ( "You have not saved the below prospective student information. By clicking 'Ok', you will not be saving the below prospective student information.  To abort click 'Cancel'" ) )
		}
		return true;
	}
			
	function validFormat(regex, str) 
	{
		return regex.test(str);
	}
	
	function WindowPopUp(strURL,strName, intWidth, intHeight)
	{
		window.open(strURL,strName,'fullscreen=0,resizable=1,menubar=0,scrollbars=1,status=0,location=0,toolbar=1,directories=0,width=' + intWidth + ',height=' + intHeight + ',top=0,left=0');
	}

	function WindowPopUpSpecial(strURL,strName, intWidth, intHeight)
	{
		window.open(strURL,strName,'fullscreen=0,resizable=0,menubar=0,scrollbars=1,status=0,location=0,toolbar=0,directories=0,width=' + intWidth + ',height=' + intHeight + ',top=0,left=0');
	}
