// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validation Functions
// ====================
// Version 2.1 [9.29.00] 
//
// This file includes several javascript functions that facilitate client side validation.
// Includes date functions, password verification and string compare.
//
// Copyright SVMedia 2000. All rights reserved
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function closeWindow(){
	if(window.opener){
			window.opener.location = window.opener.location;
			window.opener.focus();
		}	
		window.close();
	}
    

function openServiceWindow(serviceURL) 
	{
	serviceWindow = window.open(serviceURL, "", "scrollbars,resizable,height=360,width=700")
	}

function BBLogin() 
	{
	BBWindow = window.open("", "BBWindow", "scrollbars,resizable,height=360,width=620");
	}

function openBBWindow(serviceURL) 
	{
	BBwindow = window.open(serviceURL, "", "scrollbars,resizable,height=360,width=620")
	}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CheckField Function
// ===================
// Author:
//		Jim Coll
//  
// Purpose:
//		The purpose of the function is to determine whether a string submitted contains only
//		elements of the valid set as well as whether or not it is greater than the minimum 
//		permited length
//
// Variables required:
//		ValidString = a string variable which contains all valid elements used in the check
//		FieldName   = the string to be checked
//      FailMessage = a string variable containing the message to be used in case the entered 
//					  string is not valid
//		MinAvail    = the minimum number of elements that will be permitted in the passed string
//		MinMessage  = a string variable containing the message to be used in case the string is 
//                    shorter than the required length (this can be used to check if the string 
//					  empty by setting the minimum length to '0')   
//
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function CheckField( ValidString, FieldName, FailMessage, MinAvail, MinMessage ) {
 
    var allValid;
	
	allValid = true

	if ( FieldName.value.length < MinAvail ) {
			alert( MinMessage );
			FieldName.focus();
			return( false );
			}
	

//now check for valid characters in the field
  for ( i = 0;  i < FieldName.value.length;  i++ ) {
    ch = FieldName.value.charAt(i);
		for ( j = 0;  j < ValidString.length;  j++ ) {
      if ( ch == ValidString.charAt(j) ) {
				break;
      }
			if ( j == (ValidString.length - 1 ) ) {
        allValid = false;
        break;
			}
		}
	}	
	if ( !allValid ) {
	                      alert( FailMessage );
	                      FieldName.focus();
		                  return ( false );
		             }
                          else {return( true );	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//CheckField Function End -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CheckEmail Function
// ===================
// Author: 
//		Jim Coll
//
// Purpose:
//		The purpose of the function is to check the validity of a string submitted as an e-mail.
//		It checks for the 'myname@myplace.com' format, including no spaces, use of '@' and a 
//      .*** suffix
//      
// Variables required:
//		EmailFieldValue = a string variable containing the email to validate
//
// Modified:
// 		Jan 30 2002 by Stephen Rojas
//		Function now takes an optional field, EmailFieldName, which is used to give back more descriptive
//		alert messages.
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function CheckEmail( EmailFieldValue, EmailFieldName ) {
  if ( ( EmailFieldValue == '' ) || ( EmailFieldValue == ' ' ) ) {
		if (( EmailFieldName == '' ) || ( EmailFieldName == ' ' ) || !EmailFieldName ) {
			alert( "E-mail address is a required field." );			
		}else{
			alert( EmailFieldName + " is a required field." );
		}
		return( false );
	}

	var a=0
	var NewLen = EmailFieldValue.length;
	var strFieldName 
	
//check for spaces in email addresses

for ( a = 0;  a < NewLen;  a++ ) {
   ch = EmailFieldValue.charAt(a);
	if ( ch == " " ) {
		alert("E-mail addresses shouldn't have any spaces in them. \nTry it like this: myname@myplace.com" );
		return ( false );
	}
}	

   a=0;


	while ( ( a < NewLen ) && ( EmailFieldValue.charAt(a) != "@" ) ) {
		a++
	}
	if ( ( a >= NewLen ) || ( EmailFieldValue.charAt(a) != "@" ) ) {
		if (( EmailFieldName == '' ) || ( EmailFieldName == ' ' ) || !EmailFieldName ) {
			alert("Invalid E-mail address, please reenter.");		
		}else{
			alert("The e-mail entered for field " + EmailFieldName + " is invalid, please re-enter." );
		}
		return( false );	
	}
	else {
		a=a+2
	}
	while ( ( NewLen > a ) && ( EmailFieldValue.charAt(a) != "." ) ) {
		if ( EmailFieldValue.charAt(a) == "@" ) {
		if (( EmailFieldName == '' ) || ( EmailFieldName == ' ' ) || !EmailFieldName ) {
			alert("Invalid E-mail address, please reenter.");		
		}else{
			alert("The e-mail entered for field " + EmailFieldName + " is invalid, please re-enter." );
		}

			return(false);
		}
	a++
	}

	if( ( a >= NewLen -1 ) || ( EmailFieldValue.charAt(a) != "." ) ) {
				if (( EmailFieldName == '' ) || ( EmailFieldName == ' ' ) || !EmailFieldName ) {
			alert("Invalid E-mail address, please reenter.");		
		}else{
			alert("The e-mail entered for field " + EmailFieldName + " is invalid, please re-enter." );
		}
		return( false );
	} 
	else {
		return( true ); 
	}
}
///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//CheckEmail Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CheckPickList & CheckPickListValue Functions
// ============================================
// Author: 
//		Jim Coll
//
// Purpose:
//		The purpose of these functions is to check that a selection from a drop down menu has
//      been made. The CheckPickList function can be used on regular string variables defined 
//		within a given function. The CheckPickListValue function checks the .value property of 
//		the variable as opposed to the .text 
//      
// Variables required:
//		theField		 = the select box variable name 
//		strFieldDescript = a string variable containing a descriptive name for the field 
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function CheckPickList(theField,strFieldDescript){

if(theField.options[theField.selectedIndex].text.length>=1) 
  { return(true);}
  else{
   alert(strFieldDescript + ' is a required field.');
   return(false);}
}


function CheckPickListValue(theField,strFieldDescript){

if(theField.options[theField.selectedIndex].value.length>=1) 
  { return(true);}
  else{
   alert(strFieldDescript + ' is a required field.');
   theField.focus();
   return(false);}
}

///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// CheckPickList & CheckPickListValue Functions End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// ValidatePassword Functions
// =============================================
// Author: 
//		Stephen Rojas [9.28.00]
//
// Purpose:
//		The purpose of this function is to check that a string entered as a password fits certain
//      criteria passed through by the user. The criteria the user can control includes minimum 
//		number of numbers, minimum number of letters, minimum and maximum length. The valid 
//      characters for the function are assumed to be all letters and numbers, and are entered as
//		the strPassword string at the beginning of the function
//      
// Variables required:
//		strCheck		 = string submitted to check 
//		minLength		 = minimum length allowed for the password  
//		maxLength		 = maximum length allowed for the password
//		minNumbers		 = minimum number of numbers required for a valid password
//		minLetters		 = minimum number of letters required for a valid password
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function ValidatePassword(strCheck, minLength, maxLength, minNumbers, minLetters){
	var strPassword = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
	var strNumbers = "1234568790";
	var strLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

	//check password length
	if (strCheck.value.length < minLength){
		alert("Password requires at least " + minLength + " characters");
		strCheck.focus()
		return false;
	}
	
	if (strCheck.value.length > maxLength){
		alert("Password requires only " + maxLength + " characters");
		strCheck.focus()
		return false;
	}
	

//check password characters
	allValid = true;
	for (i = 0; i < strCheck.value.length; i++){
		current = strCheck.value.charAt(i);
		for (j = 0; j < strPassword.length; j++){
			if (current == strPassword.charAt(j)){
				break;
			}
			if (j == (strPassword.length-1)){
				allValid = false;
				break;
			}
		}
	}
	if (!allValid){
		alert("Non-valid characters entred in the 'Password' field");
		strCheck.focus()
		return (false);
	}
	
//check minimal number of numbers
	numberCounter = 0;
	for (i = 0; i < strCheck.value.length; i++){
		currentN = strCheck.value.charAt(i);
		for (j = 0; j < strNumbers.length; j++){
			if (currentN == strNumbers.charAt(j)){
				numberCounter++;
				break;
			}
		}
	}
	if (numberCounter < minNumbers){
		alert(minNumbers + " numbers are required in the 'Password' field");
		strCheck.focus()
		return (false);
	}	
	
//check minimal number of letters
	letterCounter = 0;
	i=0;
	j=0;
	for (i = 0; i < strCheck.value.length; i++){
		currentL = strCheck.value.charAt(i);
		for (j = 0; j < strLetters.length; j++){
			if (currentL == strLetters.charAt(j)){
				letterCounter++;
				break;
			}
		}
	}
	if (letterCounter < minLetters){
		alert(minLetters + " letters are required in the 'Password' field!");
		strCheck.focus()
		return (false);
	}

return true; 
}
///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ValidatePassword Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -






// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CompareStrings Function
// =============================================
// Author: 
//		Stephen Rojas [9.28.00]
//
// Purpose:
//		The purpose of this function is simply to compare two strings and return a true or false
//      result
//      
// Variables required:
//		string1		 = first string for comparison 
//		string2		 = second string for comparison
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function CompareStrings(string1, string2){
var equal=true;

	if (string1.value.length == string2.value.length){
		offset = string1.value.indexOf(string2.value)
		if (offset != 0){equal=false;}
	}
	else {equal=false;}
return (equal);
}

///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// CompareString Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -






// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// CheckValidChars Function
// =============================================
// Author: 
//		Jim Coll
//
// Purpose:
//		The purpose of this function is simply to check whether all elements in a string are 
//      within a valid set and returning either true or false.
//      
// Variables required:
//		string1		 = string for comparison 
//		strValid	 = string containing all valid elements
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkValidChars(string1,strValid){
	var i
	for (i=0;i<=string1.length-1;i++) {
		if (strValid.search(string1.charAt(i)) == -1){
			return false;
		}
	}
	return true;
}

///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// CheckValidChars Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// checkMinLength & checkMaxLength Functions 
// =============================================
// Author: 
//		Jim Coll
//
// Purpose:
//		The purpose of these functions is to check whether or not a string is smaller than 
//		given minimum value (checkMinLength) or whether or not a string is greater than a 
//		given value (checkMaxLength), and returning a corresponding true or false value.
//      
// Variables required:
//		string1		 = string for comparison 
//		intMinLength = integer value for minimum limit
//		intMaxLength = integer value for minimum limit
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkMinLength(string1,intMinLength){
	if (string1.length <= intMinLength-1) {
		return false;
	} else {
		return true;
	}
}	

function checkMaxLength(string1,intMaxLength){
	if (string1.length >= intMaxLength+1) {
		return false;
	} else {
		return true;
	}
}	

///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// checkMinLength & checkMaxLength Functions End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// checkNumericRange Function 
// =============================================
// Author: 
//		Jim Coll
//
// Purpose:
//		The purpose of this function is to check whether a given number lies within a given  
//		numeric range, returning a true or false value.
//      
// Variables required:
//		chkNumber   = string for comparison 
//		low			= integer value for minimum limit
//		high        = integer value for minimum limit
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkNumericRange(chkNumber,low,high){
	if ((chkNumber >= low) && (chkNumber <= high)){
		return true;
	} else {
		return false;
	}
}

///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// checkNumericRange Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// checkLeapYear Function 
// =============================================
// Author: 
//		Ed McLaughlin
//
// Purpose:
//		The purpose of this function is to check whether or not a a given year is a leap year.
//		The function is based on the fact that a year which is exactly divisble by four 
//		is a leap year. The exception to the rule is the first year of a century, 
//		or last year, depending on how you look at it. In that case if the year is exactly 
//		divisible by 400 it is also a leap year. So 2000 is a leap year, but 1900 wasn't.
//
// Variables required:
//		year   = year to be checked for leap year status
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkLeapYear(year){
	if (year%4 == 0){
		if(year%100 == 0) {		//century
			if(year%400 == 0) {
				return true;
			} else {
				return false;
			}
		}
		return true;
	} else {
		return false;
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// checkLeapYear Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -





// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// checkDate Function 
// =============================================
// Author: 
//		Ed McLaughlin
//
// Purpose:
//		 Checks that fields entered for a particular date are valid in terms of the number of 
//		 days in a paritular month
//
// Variables required:
//		
//		 month			= the month portion of the date to be validated
//		 day			= the day portion of the date to be validated
//		 year			= the year portion of the date to be validated
//		 descriptioin	= name that describes the field for the date
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function checkDate(month, day, year, description){

   if(month.length == 1){
	   month="0" + month;
	 }


	switch(month) 
	{
		case '04':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in April') 
				return false; 
			}break;
		case '06':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in June') 
				return false; 
			}break;
			
		case '09':
	
			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in September') 
				return false; 
			}break;

		case '11':

			if (!checkNumericRange(day,1,30)){ 
				alert('The day part of ' + description + ' must be between 1 and 30.\n30 days in November') 
				return false; 
			}break;
		case '02':

			if (!checkNumericRange(day,1,29))
			    { 
				alert('The day part of ' + description + ' must be between 1 and 28.\n28 days in February (29 in a leap year).') 
				return false; 
				}
				
				
			if (day == '29') 
			    { 
				if (!checkLeapYear(year))
				    { 
					alert(year + ' is not a leap year.\n Febraury 29 is only valid in a leap year.') 
					return false; 
  				    }
			    }
     }
return(true);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// checkLeapYear Function End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// Browser Time, Date and Date/Time Functions 
// =============================================
// Author: 
//		Stephen Rojas
//
// Purpose:
//		Functions write to the screen date or time or both combined from the browser, not the server i.e.
//		the user's local time
//      
// Variables required:
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function browserTime(){
	var minsArr=new Array(10);
	minsArr[0]="00";
	minsArr[1]="01";
	minsArr[2]="02";
	minsArr[3]="03";
	minsArr[4]="04";
	minsArr[5]="05";
	minsArr[6]="06";
	minsArr[7]="07";
	minsArr[8]="08";
	minsArr[9]="09";
	var time=new Date();
	var hour=time.getHours();
	var mins=time.getMinutes();
	var lmins
	if (mins < 10){
		lmins = minsArr[mins]
		mins = lmins
	}
	if (hour > 12){
		hour = hour-12;
		document.write(" " + hour + ":" + mins + " pm");
	}
	else{
		document.write(" " + hour + ":" + mins + " am");
	}
}

function browserDate(){
	var monthsArr=new Array(13);
	monthsArr[1]="January";
	monthsArr[2]="February";
	monthsArr[3]="March";
	monthsArr[4]="April";
	monthsArr[5]="May";
	monthsArr[6]="June";
	monthsArr[7]="July";
	monthsArr[8]="August";
	monthsArr[9]="September";
	monthsArr[10]="October";
	monthsArr[11]="November";
	monthsArr[12]="December";
	var time=new Date();
	var lmonth=monthsArr[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year<1900) year=1900 + time.getYear();
	else year=time.getYear();
	document.write(lmonth + " ");
	document.write(date + ", " + year);
}

function browserDay(){
	var dayArr=new Array(7);
	dayArr[0]="Sunday";
	dayArr[1]="Monday";
	dayArr[2]="Tuesday";
	dayArr[3]="Wednesday";
	dayArr[4]="Thursday";
	dayArr[5]="Friday";
	dayArr[6]="Saturday";

	var time=new Date();
	var day=time.getDay();
	var lday
	lday = dayArr[day]
	document.write(" " + lday);
}

function browserDateTime(){
browserDate()
browserTime()
}

function browserDayDateTime(){
browserDay()
document.write(", ")
browserDate()
browserTime()
}

function browserDayDate(){
browserDay()
document.write(", ")
browserDate()
}

function monthStringToInt(strMonth){
	var intMonth;
	var strUMonth;
	
	strUMonth = strMonth.toUpperCase()

	switch(strUMonth){
		
		case 'JANUARY':
			intMonth = 1;
		break;	
		case 'FEBRUARY':
			intMonth = 2;		
		break;
		case 'MARCH':
			intMonth = 3;		
		break;
		case 'APRIL':
			intMonth = 4;		
		break;
		case 'MAY':
			intMonth = 5;		
		break;
		case 'JUNE':
			intMonth = 6;		
		break;
		case 'JULY':
			intMonth = 7;		
		break;
		case 'AUGUST':
			intMonth = 8;		
		break;
		case 'SEPTEMBER':
			intMonth = 9;		
		break;
		case 'OCTOBER':
			intMonth = 10;		
		break;
		case 'NOVEMBER':
			intMonth = 11;		
		break;
		case 'DECEMBER':
			intMonth = 12;			
		break;
     }	
	
	return intMonth
}

function monthIntToString(intMonth){
	var strMonth
	var intTransMonth
	
	intTransMonth = ParseInt(intMonth)
	
	switch(intMonth){
		
		case 1:
			strMonth = 'January';
		break;
		case 2:
			strMonth = 'Febraury';		
		break;
		case 3:
			strMonth = 'March';		
		break;
		case 4:
			strMonth = 'April';		
		break;
		case 5:
			strMonth = 'May';		
		break;
		case 6:
			strMonth = 'June';	
		break;
		case 7:
			strMonth = 'July';		
		break;
		case 8:
			strMonth = 'August';
		break;
		case 9:
			strMonth = 'September';
		break;
		case 10:
			strMonth = 'October';
		break;
		case 11:
			strMonth = 'November';
		break;
		case 12:
			strMonth = 'December';
		break;
     }	
	
	return strMonth
}
///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Date, Time and Date/Time Functions End -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// IsInteger() 
// =============================================
// Author: 
//		Zhiyuan Ma
//
// Purpose:
//		Check if the passed in value is an integer
//      
// Variables required:
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function isInteger(inputVal){
	var inputStr = inputVal.toString()
	for (var i=0; i<inputStr.length; i++){
		var oneChar = inputStr.charAt(i);
		if(i==0 && oneChar=="-"){
			continue;
		}
		if (oneChar < "0" || oneChar > "9"){
			return false;
		}
	}
	return true;
}
///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// End of isInteger function
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -