/* ********************************************************** */
/* Global Variables and Constants *************************** */
/* ********************************************************** */


/* ********************************************************** */
/* Functions ************************************************ */
/* ********************************************************** */

/**************************************************************
 Function Name: isUSZip
 Parameters:   s             string:  representing Zip Code
			   allowNull     boolean: true if s is not req.
									  false if s is required
 Returns:  true if s is a valid USZip Code
							(matches either ##### or #####-####)
		   false if s is not valid
***************************************************************/
function isUSZip(s,allowNull)
{
	if ((allowNull==true) && (s==""))
	{
		return true;
	}
	if ((!s.match(/\d{5}/)) && (!s.match(/\d{5}\-\d{4}/)))
	{
		return false;
	}
	else return true;
}
	

	

/***************************************************************
Function Name: isEmail
Parameters: s ............... String: representing email address
			allowNull ....... Boolean: true if s is not req'd
									   false if s is req'd
Returns:  true .................. if s is a valid email address 
		  false ................. if s is not valid
		  
Note: This function only tests for the existence of the @ symbol
	  in the input string.  It does no domain searching for a
	  "truly" valid email address.

***************************************************************/  
  //Returns true if the input s is a valid email address
function isEmail(s,allowNull)
{
	if((allowNull==true)&& (s==""))
	{
		return true;
	}
	if ((!s.match(/@/)) || (s==""))
	{
		return false;
	}
	else return true;
	
}
/***************************************************************
Function Name: isTime
Parameters: s .............String: representing input time

Returns: true if s is a valid time format.  That is, (hh:mm) or (h:mm)

Note: this function does not check to make sure the numbers themselves
		are valid.
****************************************************************/
function isTime(s)
{
	
	if(s. match(/\d{2}:\d{2}/) || s.match(/\d:\d{2}/))
	{
		return true;
	}
	else
		return false;
}

/***************************************************************
Function Name: isLongTime
Parameters: s .............String: representing input time

Returns: true if s is a valid time format.  That is, (hh:mm) or (h:mm)

Note: this function does not check to make sure the numbers themselves
		are valid.
****************************************************************/
function isLongTime(s)
{
	
	if(s. match(/\d{2}:\d{2}:\d{2} [aApP][mM]/) || s.match(/\d:\d{2}:\d{2} [aApP][mM]/))
	{
		return true;
	}
	else
		return false;
}

/***************************************************************
Function Name: isShortTime
Parameters: s .............String: representing input time

Returns: true if s is a valid time format.  That is, (hh:mm) or (h:mm)

Note: this function does not check to make sure the numbers themselves
		are valid.
****************************************************************/
function isShortTime(s)
{
	
	if(s. match(/\d{2}:\d{2} [aApP][mM]/) || s.match(/\d:\d{2} [aApP][mM]/))
	{
		return true;
	}
	else
		return false;
}

/***************************************************************
Function Name: CheckPhoneNumber
Parameters: objToCheck .............object holding the phone number
			allowNull  .............boolean for if this object may
									contain a null value or zero
									length string.

Logic: The value of the object is passed to ReplaceAllChars to filter
	   all non-numeric numbers out.  Then the returned string is
	   checked for the appropriate length for a phone number + area
	   code (10 numbers).  If longer than 10 the first 10 numbers are
	   used truncating the remaining.  If longer or equal to 10 chars
	   this function inserts the 10 digits into a mask for consistent format.
	   If less than 10 characters the functions throws an ALERT telling
	   the user so and does not mask the numbers.

****************************************************************/
function CheckPhoneNumber(objToCheck,allowNull)
{
	var sString;
	var sControlName
	var sMask;
	var nReply;
	
	sString = objToCheck.value;
	//alert("sString = " + sString);
	
	if(sString != "")
	{
		sString=ReplaceAllChars(sString);
		//alert(sString);
		if(sString.length > 10)
		{
			sString = sString.substring(0, 10);
		}
		if(sString.length < 10)
		{
			alert("Invalid Phone Number. Phone number should be formatted as (123) 456-7890."); 
		}
		else
		{
			sMask = "(" + sString.substring(0,3) + ")" + sString.substring(3,6) + "-" + sString.substring(6, 10);
			
			objToCheck.value = sMask;
		}
	}
	else if(!allowNull){
		//A null value for the entry is not allowed
		alert("Please enter a valid phone/fax number.");
	}
}
/***************************************************************
Function Name: ReplaceAllChars
Parameters: sString .............String: representing input phone

Returns: sString , filters out non-numeric characters

Note: this function does not check to make sure the numbers themselves
		are valid.
****************************************************************/
function ReplaceAllChars(sString)
{
	window.onerror = null;
	
	//alert(sString);
	var nLenString;
	var nCount;
	var vTemp;
	var sTempString="";
	//alert("inside ReplaceAllChars()"+sString);
	nLenString = sString.length;
	
	for(nCount=0; nCount<nLenString; nCount++)
	{
		vTemp = parseInt(sString.charAt(nCount));
		//alert(vTemp);
		if(!(isNaN(vTemp)))
		{
			sTempString = sTempString + vTemp;
		}
	}
	sString = sTempString;
	return sString;
	
}
/****************************************************************
Function Name: isUSPhoneNumber
Parameters:  s ...............  string representing phone number
			 allowNull .......  boolean: true if s is not req'd
										 false if s is req'd
Returns:  true ........... if s is a valid US Phone number in
						   1 of the 5 predefined formats
							1		(###) ###-####
							2		(###)###-####
							3		###.###.####
							4		###-###-####
							5		##########
		  false .......... if s is not in the predetermined form
*****************************************************************/

function isUSPhoneNumber(s,allowNull)
{
	if((allowNull==true) && (s==""))
	{
		return true;
	}
	re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/
	re2= /\d{10}/
	
	if((!s.match(re) && !s.match(re2))|| (s.match(/\d{11}/)))
	{
		return false;
	}
	else return true;
	
}

/**************************************************************
Function Name: getNavigatorVersion		Author: Ryan Peterson
Parameters: iStr....string where the only number contained in the
					string is the version of NN.
					
Returned:  

**************************************************************/
function getNavigatorVersion(iStr){
	var nCount;
	var nLenString;
	var sTempString="";
	var vTemp;
	var fVersion;
	nLenString = iStr.length;
	
	for(nCount=0; nCount<nLenString; nCount++)
	{
		//document.write(str.charAt(nCount));
		vTemp = parseInt(iStr.charAt(nCount));
		//alert(vTemp);
		if(!(isNaN(vTemp)))
		{
			if(nCount==0){
				sTempString= sTempString+vTemp+".";
			}else{
				sTempString = sTempString + vTemp;
			}
		}
	}
	fVersion=sTempString;
	return fVersion;
}