<!-- 
//###########################################################
// MISCELLANEOUS USEFUL FUNCTIONS
//
// by ScottTaylor
//###########################################################

//*******************************************************************
// popup(url,winx,winy)
//
// This function pops up a window which will open the specified 
// URL and sizes the window to winx by winy pixels. If the window
// has already been opened it closed and a new window reopened.
//
// by ScottTaylor
//*******************************************************************
var popWin;
function popup(url,winx,winy){
	if (popWin) popWin.close();
	popWin = window.open("","popup","SCROLLBARS=1,WIDTH="+winx+",HEIGHT="+winy+",RESIZABLE=1");
	popWin.location.href=url;
	if(popWin.opener==null) popWin.opener=window;
	popWin.opener.name="opener";
	popWin.focus();
}


//###########################################################
// FORM VALIDATION FUNCTIONS
//
// by ScottTaylor
//###########################################################

//**********************************************************
// validInt()
//
// This function ensures that only integer values are 
// included in the value.
//
// by ScottTaylor
//**********************************************************
function validInt(intVar)
{
	var intLen = intVar.length;		// length of integer string
	var retValue = true;
	
	for (var i = 0; i < intLen; i++ ) 
	{				
		var ch = intVar.substr(i, 1);
		if ( i == 0 ){
			if (( ch < "0" || ch > "9" ) && ( ch != "-" )) 
				retValue = false;
		}
		else{
			if ( ch < "0" || ch > "9" )
				retValue = false;
		}
	}
	
	return retValue;
	
}	// end validInt


//**********************************************************
// validFloat()
//
// This function ensures that only float values are 
// included in the value.
//
// by ScottTaylor
//**********************************************************
function validFloat(fltVal)
{
	var fltLen = fltVal.length;		// length of integer string
	var retValue = true;
	var dotCount = 0;
	
	for (var i = 0; i < fltLen; i++ ) 
	{				
		var ch = fltVal.substr(i, 1);
		if (( ch < "0" || ch > "9" ) && ( ch != "." ) && (ch != "-"))
			retValue = false;
		else if ((ch == "-") && (i != 0))
			retValue = false;
		else if ((ch == ".") && (dotCount > 0))
			retValue = false;
		else if (ch==".")
			dotCount = dotCount + 1;
	}
	
	return retValue;
	
}	// end validFloat



//**********************************************************
// isEmpty()
//
// This function ensures that the value is not = ""
//
// by ScottTaylor
//**********************************************************
function isEmpty(myVar)
{
	if (myVar.length == 0)
		return true;
	else
		return false;
	
}	// end isEmpty



//**********************************************************
// emptyFields()
//
// This function ensures that the form contains no empty fields
//
// by ScottTaylor
//**********************************************************
function emptyFields(formName)
{
	var numElements = formName.elements.length;

	for( i = 0; i < numElements; i++ )
	{
		if ( formName.elements[i].value == "" )
		{
			return true;
		}
	}
	return false;

}	// end emptyFields



//**********************************************************
// validEmail()
//
// This function tests email address validity
//
// by ScottTaylor
//**********************************************************
function validEmail(email) {
  invalidChars = " /:,;"
  if (email == "") {
    return false;
  }

  for (i=0; i<invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (email.indexOf(badChar,0) != -1) {
      return false;
    }
  }

  atPos = email.indexOf("@",1);
  if (atPos == -1) {
    return false;
  }

  if(email.indexOf("@",atPos+1) != -1) {
    return false;
  }

  periodPos = email.indexOf(".",atPos)
  if (periodPos == -1) {
    return false;
  }

  if (periodPos+3 > email.length) {
    return false;
  }

  if ( atPos+1 == periodPos ) {
  	return false;
  }

  return true;

}  // end validEmail



//**********************************************************************
// validDate()
//
// This function verifies that a date contains only valid entries for the following format:
// [M]M / [D]D / [YY]YY
//
// by ScottTaylor
//**********************************************************************
function validDate(strDate) {
    var strLen = strDate.length;			// length of entire date string
    var retValue = true;						// returns True if date is valid, False if not
    var slash1pos = null;						// position of first "/" in date string
    var slash2pos = null;						// position of second "/" in date string
    
    var month;
    var day;
    var year;
     
    if ( strLen > 10 ) 
      retValue = false;
    else  { 
		for (var i = 0; i < strLen; i++ ) {				// find positions of the slashes
			var ch = strDate.substr(i, 1);
			if (( ch < "0" || ch > "9" ) && ( ch != "/" ))
				retValue = false;
			else  {
				if ( ch == "/" ) {
					if ( !slash1pos ) 
						slash1pos = i;
					else if ( !slash2pos ) 
						slash2pos = i;
					else 
						retValue = false; 
				}  // end if
			}	// end if/else			
		}  // end for loop
		
		if ( slash1pos == 1 ) {							// M/
			month = strDate.substr(0,1);
			if ( slash2pos == 3 ) {						// M/D/
				day = strDate.substr(2,1);
				if ( strLen == 6 )							// M/D/YY
					year = strDate.substr(4,2);
				else if ( strLen == 8 )						// M/D/YYYY
					year = strDate.substr(4,4);
				else 
					retValue = false;
		
			}
			else if ( slash2pos == 4 ) {				// M/DD/
				day = strDate.substring(2,4);
				if ( strLen == 7 ) 						// M/DD/YY
					year = strDate.substr(5,2);
				else if (strLen == 9 )  				// M/DD/YYYY
					year = strDate.substr(5,4);
				else 
					retValue = false;
			}
			else 
				retValue = false;
		}
		else if ( slash1pos == 2 ) {					// MM/
			month = strDate.substring(0,2);
			if ( slash2pos == 4 ) {					// MM/D/
				day = strDate.substr(3,1);
				if ( strLen == 7 ) 						// MM/D/YY
					year = strDate.substr(5,2);
				else if ( strLen == 9 ) 				// MM/D/YYYY
					year = strDate.substr(5,4);
				else 
					retValue = false;
			}
			else if ( slash2pos == 5 ) {				// MM/DD/
				day = strDate.substr(3,2);
				if ( strLen == 8 ) 						// MM/DD/YY
					year = strDate.substr(6,2);
				else if ( strLen == 10 ) 				// MM/DD/YYYY
					year = strDate.substr(6,4);
				else
					retValue = false;
			}
			else 
				retValue = false;
		}
		else 
			retValue = false;
			
		if ( strDate.length == 0 )
			retValue = true;
		else if ( strDate.length != 0 && retValue == true ) {
			if ( (parseInt(month) == 0) || (parseInt(month) > 12) ||
				(parseInt(day) == 0) || (parseInt(day) > 31) || 
				( year.length == 4 && year.substr(0,1) == 0 ) )
				retValue = false;
		}	
			
		return retValue;

	} // end if
} // end function
//-->