//  Description:  The refreshFrame() function is used to update a Frames graphics (Typically fraAction, fraNavigate or fraTop)
//                with a graphic represented by the intAction value passed to the function.
function refreshFrame(objFrame, intAction) {
if (isEmpty(objFrame)) {} else{
  if (objFrame.ActionIndex.value != intAction)  {
     //  Refresh the Form 
     if (intAction !== "") {objFrame.ActionIndex.value = intAction}
     objFrame.__Click.value = "$Refresh";
     objFrame.submit()}
}
}  // End of the refreshFrame Function

function isFloat(s) {   
    var i;
    var seenDecimalPoint = false;
    var defaultEmptyOK = false;
    
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == ".") return false;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))}

function isDigit(c)
{   return ((c >= "0") && (c <= "9"))}

function getFieldValue ( theField, vType ) { 

                         //this function will return the field value (or value list) based on the element type 

                         theValue = ""; 
                         sep = ""; 
                         hits = 0; 

                         //text is the user-entered value as a string
                         if ( vType == "text" ) return ( theField.value ); 

                         //textarea is the user-entered value as a string array of one element
                         if ( vType == "textarea" ) return ( theField[0].value ); 

                         //checkboxes & radio buttons are not so simple
                         if ( vType == "checkbox" || vType == "radio" ) { 

                         if ( theField.value == null ) { 

                         //if we're here, we are validating a radio button or a nn multi-element
                         //checkbox 

                         for ( i = 0; i < theField.length; i++ ) { 
                         if ( theField[i].checked ) { 
                         hits++; 
                         if ( hits > 1 ) {
                         sep = "; ";
                         } 
                         theValue += sep + theField[i].value; 
                         } 
                         }
                         } 
                         return ( theValue );

                         } else { 

                         //if we are here, must be an ie checkbox, or nn with a one-element checkbox") 

                         if ( navigator.appName == "Microsoft Internet Explorer" ) { 
                         //ie. return some data so we can validate on the server; 
                         return ("can't validate on client")} 

                         //nn one-element checkbox, see if its checked ...
                         if (theField.checked ) {return ( theField.value )} else {
                         return ( "" )} 
                         } 

                         //select is an array of selection pointers to an array of strings representing the choices
                         if ( vType == "select" ) { 

                         for ( i = 0; i < theField.options.length; i++ ) {
                         if ( theField.options[i].selected ) theValue += theField.options[i].text 
                         } 
                         return ( theValue )}
                         }

function isBlank( str ) {
//alert("isblank string is:  " + str)
	var isValid = false;
 	if ( isNull(str) || isUndef(str) || (str+"" == "") )
 		isValid = true;
	return isValid;
}  // end IsBlank

function isNull( val ) {
	var isValid = false;

 	if (val+"" == "null")
 		isValid = true;
		
	return isValid;
}  // end IsNull

function isUndef( val ) {
	var isValid = false;

 	if (val+"" == "undefined") {
 		isValid = true}
		
	return isValid;
}  // end IsUndef

function DeleteElement(ElementList,ElementName)
{
var objList = document.forms[0].elements[ElementList]
var startpos = objList.value.indexOf(ElementName)  //begining of the name to remove
if (startpos !== -1) 
{
var endpos = startpos + ElementName.length //end of the name to remove
var startstring = objList.value.substring(0, startpos)
var endstring = objList.value.substring(endpos, objList.value.length)
objList.value = startstring + endstring
document.forms[0].__Click.value = '$Refresh';
document.forms[0].submit();
}}


// 
//  Kryos Systems
//
//  Description:  The returnEditStatus function is used to determine if the document is in Edit or Read mode.  The function simply
//                       parses the passed href and considers OpenForm (except Display?OpenForm), EditDocument to be in Edit mode
//                       and all other Notes ? actions as Read Mode.
function returnEditStatus(strLocationHREF) {
    var intEditMode = 0  // Assume the document is NOT in Edit mode until proven otherwise.

    /* Parse out six characters after the Notes Action OpenF or OpenD or EditD, ... */
        var strDocMode = strLocationHREF.substring(strLocationHREF.indexOf("?")+1,strLocationHREF.indexOf("?") + 6)
    
    /*  Note:  All Displayed forms will use the Display suffix as a standard */
         var offset = strLocationHREF.indexOf("Display?OpenForm")
         if (offset != -1) {intEditMode=0
         } else {     
                   /* Make an assesment about the status of the document */
                   if (strDocMode == "EditD" | strDocMode == "OpenF") { intEditMode = 1}
         }  // End of the IF-THEN Else 
return intEditMode
} // End of the returnEditStatus Function

//  Kryos Systems
//
//  Description:  The SwitchToProvidedHREF is used to confirm a document is not in edit mode and switch to the appropriate
//                       URL.  The function takes two parameters that indicate what URL is to be loaded
//                       and if an edit validation is required.  If edit validation is required the function determines in a document
//                        is open in edit mode and prompts the user to save before they proceed.
function SwitchToProvidedHREF(strHREF, intConfirmEditMode) {
  // Extantiate all required objects for manipulation within the function.
      var objHidden = top.fraHidden.document.forms[0]

  /*  Determine the Edit status of the Main Frame (1 = Edit, 0 = Read) */
       var intEditMode = returnEditStatus(location.href)

    /*  If the does not need edit checking then switch views - otherwise confirm a document is not in edit mode */ 
    if (intConfirmEditMode == 0) {
       location.href = strHREF
    }  else {
      /*  If the document is in Edit Read Mode Confirm that they want to save the document. */
        if (intEditMode == 1) {
           if (confirm("Do wish to exit without saving this section?")) {
               location.href = strHREF
           } else {}}
       else {  // Document is in Read mode and you can proceed with your actions.
               location.href = strHREF
       }
     }  // End of the If-then-else based on Edit Mode checks
}  // End of the SwitchEmbeddedView Function


function funDisplayStatus(strMessage)

//  Description:   This function determines is used to display the error message to the status bar if the current
//					  browser is Netscape.  First it is checked if there is an error message.  If there is not any then
//					  the original message is displayed instead.
{
var agt=navigator.userAgent.toLowerCase()
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1))
                
var objMain = document.forms[0]
var objErrorMessage= objMain.elements["ErrorMessageText"]

if (objErrorMessage.value != "")
	{
	if (is_nav) {window.status = objErrorMessage.value}}
else {window.status = strMessage}}
function replaceSubstring(strValue, strCharacter, strReplace)
{
  var intKey = strValue.indexOf(strCharacter)
  if (intKey == -1) {return strValue}

  var strNewValue = strValue.substring(0, intKey) + strReplace + strValue.substring((intKey + 1),(strValue.length))
  return replaceSubstring(strNewValue, strCharacter, strReplace)
} // End of the replaceSubstring


/* ---------------------------------------------------------- */
/* Set isnewdoc variable for web page form validation related */
/* to the page type. The 2 lines below have different hide    */
/* when formulas. isnewdoc is set to 1 when it is a new doc & */
/* 0 when it is not a new document.                           */
var isnewdoc = 1;
var isnewdoc = 0;
/* ---------------------------------------------------------- */

/* ---------------------------------------------------------- */
/* PURPOSE : Sets the document object based on browser type.  */
/*                                                            */
/* USAGE   : docObj could be used in a variety of functions   */
/*           that require access to the DOM. The toggleVis    */
/*           functions uses this to determine the visibility  */
/*           state of an element on the document.             */
/* ---------------------------------------------------------- */
function setDocumentObject()
{
var isNew = 0;
var isNS4 = 0;
var isIE4 = 0;

/* Now get the browser name and version */
var brow = ((navigator.appName) + (parseInt(navigator.appVersion)));

/* Assign the browser flag */
if (parseInt(navigator.appVersion >= 5)) 
	{isNew = 1;}
else if (brow == "Netscape4")
	{isNS4 = 1;}
else if (brow == "Microsoft Internet Explorer4")
	{isIE4 = 1;}

/* Now get the document object that is passed to the toggle visibility function */
if (isNS4 || isIE4 || isNew) {
	docObj = (isNS4) ? 'document' : 'document.all';
	styleObj = (isNS4) ? '' : '.style';
	}
/*                         - FIN -                            */
/* ---------------------------------------------------------- */
}

/* ---------------------------------------------------------- */
/* FUNCTION: toggleVis                                        */
/*                                                            */
/* DESC    : Used to toggle the visibility of a page element. */
/*           Elements are defined in between <div> tags and   */
/*           should appear at the end of the form or page.    */
/*           The browser sensing code must be included on the */
/*           page as this is where the docObj variable is set.*/
/*                                                            */
/* PARMS   : currElem - this is the ID of the div element as  */
/*           defined on the <DIV ID='xxx'> tag.               */
/* ---------------------------------------------------------- */
/* AUTHOR  : L. Desautels - Kryos Systems                     */
/*           (2000/05)                                        */
/* ---------------------------------------------------------- */
function toggleVis(currElem) {
	dom = eval(docObj + '.' + currElem + styleObj);
	state = dom.visibility;
	if (state == "visible" || state == "show")
		{dom.visibility = "hidden";}
	else	{dom.visibility = "visible";}
}
/*                         - FIN -                            */
/* ---------------------------------------------------------- */

/* ---------------------------------------------------------- */
/* FUNCTION : OpenSelectedLink                                */
/* USAGE    : To open a page selected from a drop down list.  */
/* PARMS    : strView = the URL of the page                   */
/* ---------------------------------------------------------- */
function OpenSelectedLink(strView,form)
{
	var urlAddress=""
	urlAddress=strView.options[strView.selectedIndex].value
	location.href=urlAddress
}

/* ---------------------------------------------------------- */
/* FUNCTION : setMsg(msg)                                     */
/* USAGE    : Sets the window status message                  */
/* PARMS    : The message                                     */
/* ---------------------------------------------------------- */
function setMsg(msg)
{
	window.status = msg;
	return true;
}
/* ---------------------------------------------------------- */
/* FUNCTION : checkDate(strDate,strMonth,strYear,objTarget    */
/* USAGE    : Used to validate a date entered on a form       */
/* PARMS    : The format of the date, the month, year and     */
/*             resulting field.                               */
/* ---------------------------------------------------------- */
function checkDate(strDate, strMonth, strYear, objTarget) {
  var strMonthNumber = 0
  var strCompiledDate = strDate + " " + strMonth + " " + strYear;

  // If the year is blank then return to calling program.
  if (strYear == "") {return true}
  
  /* Using form values, create a new date object
      which looks like "Wed Jan 1 00:00:00 EST 1975". */
  var datCompiledDate = new Date( strCompiledDate );
  
  /* Convert the date to a string so we can parse it. */
  var strCompiledDate = datCompiledDate.toGMTString();

  /* Split the string at every space and put the values into an array so,
      using the previous example, the first element in the array is "Wed", the
      second element is "Jan", the third element is "1", etc. */
  var arrCompiledDate = strCompiledDate.split( ' ' );

  /* If we entered "Feb 31, 1975" in the form, the "new Date()" function
     converts the value to "Mar 3, 1975". Therefore, we compare the month
     in the array with the month we entered into the form. If they match,
     then the date is valid, otherwise, the date is NOT valid. */
  if ( arrCompiledDate[2] != strMonth ) {
    alert( 'Please ensure that a valid date is entered.' );
    return false
    } else {
               // Retrieve Month Number String         
              strMonthNumber = (strMonth == "Jan") ? "1" : strMonthNumber
              strMonthNumber = (strMonth == "Feb") ? "2" : strMonthNumber
              strMonthNumber = (strMonth == "Mar") ? "3" : strMonthNumber
              strMonthNumber = (strMonth == "Apr") ? "4" : strMonthNumber
              strMonthNumber = (strMonth == "May") ? "5" : strMonthNumber
              strMonthNumber = (strMonth == "Jun") ? "6" : strMonthNumber
              strMonthNumber = (strMonth == "Jul") ? "7" : strMonthNumber
              strMonthNumber = (strMonth == "Aug") ? "8" : strMonthNumber 
              strMonthNumber = (strMonth == "Sep") ? "9" : strMonthNumber
              strMonthNumber = (strMonth == "Oct") ? "10" : strMonthNumber
              strMonthNumber = (strMonth == "Nov") ? "11" : strMonthNumber
              strMonthNumber = (strMonth == "Dec") ? "12" : strMonthNumber
             
              /*  Write out the Value of the consolidated Date */
              objTarget.value = strMonthNumber + "/" + strDate + "/" + strYear;
              return true
              }  // End of the else valid Date.
} // End of the checkDate function.

// 
//  Kryos Systems
//
//  Description:   The validatePhone function is used to validate and return the phone number to the 
//                        calling routine for display in the hidden phone number field.
function validatePhone(objPhone,strAC, strPP, strPS, bolValidate)
{
    // Build the Phone Number in case Validation is not requried.
    var objAreaCode = objPhone.elements[strAC]
    var objPP = objPhone.elements[strPP]
    var objPS = objPhone.elements[strPS]

    var strPhoneNumber = "(" + objAreaCode.value + ") " + objPP.value + "-" + objPS.value;

   // Validate the Date.
   if (bolValidate != 0) {
      if ((bolValidate == 2 ) & ((objAreaCode.value == "") | (objPP.value == "") | (objPS.value == ""))) {
           alert("Please ensure the Phone Number is in the format (xxx) xxx-xxxx") 
           //objAreaCode.focus()
          return ""}
          
      // Validate the Area Code    
      if  ((objAreaCode.value != "") & (objAreaCode.value.length < 3)) {
         alert("Please ensure the Area Code is at least 3 numbers - more for International Numbers")
         if (bolValidate == 2) {
             //objAreaCode.focus()
            }
          return ""}      
     
      // Ensure main body of Phone number is correct. 
      if  ((objPP.value != "") & (objPP.value.length != 3)) {
         alert("Please ensure the phone number prefix is 3 digits")
         if (bolValidate == 2) {
             //objPP.focus()
             }
          return ""}         
          
      // Ensure main body of Phone number is correct. 
      if  ((objPS.value != "") & (objPS.value.length != 4)) {
         alert("Please ensure the phone number suffix is 4 digits")
         if (bolValidate == 2) {
             //objPS.focus()
             }
          return ""}         
          
      else {return strPhoneNumber}}
    else {return strPhoneNumber}
} // End of the the validatePhone Funtion


function funMainCheckPhoneNumber(objNumber ,intDesiredLength ,strName, objAreaCode,objPP,objPS,objPhoneNumber)
//  Description:   The function takes a field from a phone number and determines if it is of the proper
//  length and is all numbers.  If it is valid (and all the other fields have a value) then the
//  phone number is set.
{

var blnValid = "No";
if (objNumber.value != "")
	{if (funValidPhone(objNumber,intDesiredLength, strName) == "No")
		{objPhoneNumber.value = ""
		objNumber.focus()}
    else
		{if (funCheckPhoneNumbers(objAreaCode,objPP,objPS) == "OK")
			{objPhoneNumber.value = funGetPhoneNumber(objAreaCode,objPP,objPS)
			blnValid = "Yes"}}	
	if (blnValid == "No")
		{objPhoneNumber.value = ""}}

 return ""
}

function funGetPhoneNumber(objAreaCode,objPP,objPS)
{return "(" + objAreaCode.value + ") " + objPP.value + "-" + objPS.value}

function funValidPhone(objNumber,intDesiredLength,strName)
//  Description:   The function takes a field from a phone number and determines if it is of the proper
//					  length and is all numbers.  If it is valid (and all the other fields have a value) then the
//					  phone number is set.
{
var blnValid = "Yes"

if (objNumber.value.length != "")
	{	if ((objNumber.value.length < intDesiredLength) && (strName == "area code"))
		{funSetErrorMessage( "Please ensure that the " + strName + " is at least " + intDesiredLength + " numbers.")
		blnValid = "No"}
	else
		{if ((objNumber.value.length != intDesiredLength) && (strName != "area code"))
			{funSetErrorMessage( "Please ensure that the " + strName + " has " + intDesiredLength + " numbers.")
			blnValid = "No"}
		else {if (funIsNumber(objNumber) == "No")
				{funSetErrorMessage( "Please ensure that the " + strName + " has only numbers.")
				blnValid = "No"}}
		}
	}
return blnValid
}


function funCheckPhoneNumbers(objAreaCode,objPP,objPS)
{if ((objAreaCode.value != "") && (objPP.value != "") && (objPS.value != "")) {return "OK"} else {return "Not OK"}}   

function funIsNumber(objNumber)
//  Description:   This function determines if a value contains only numbers
{var intCurrentPosition = -1
var blnNumber = "Yes"
var inStr = objNumber.value

// Loop through the string and see if any character is anything besides a number
for (intCurrentPosition = 0 ; intCurrentPosition < inStr.length ;  intCurrentPosition ++)
	{var ch = inStr.substring( intCurrentPosition , intCurrentPosition+1)
	if ((ch < "0") || (ch > "9"))
		{if (ch != ".") {blnNumber = "No"}}}
}

function funAreLetters(objString)
//  Description:   This function determines if a value contains only letters; be it capital or small.

{
var intCurrentPosition = -1
var blnLetters = "Yes"
var inStr = objString.value

// Loop through the string and see if any character is anything besides a letter
for (intCurrentPosition = 0 ; intCurrentPosition < inStr.length ;  intCurrentPosition ++)
	{
	var ch = inStr.substring( intCurrentPosition , intCurrentPosition+1)
	if (((ch < "a") || (ch > "z")) && ((ch < "A") || (ch > "Z")))
		{blnLetters = "No"}}
return blnLetters}



function validatePostalZipCode(objPostalZip,strCountry)
//
//	This function uses the name of a country to determine the method of validation.  If the country is Canada it will check it for being a valid postal code.  If
//	the country is United Stated it checks it as a valid zip code.  If it is blank then it checks to see if is valid as either a postal code or a zip code.  If it is none
//	of the above it returns an error message.  When the Postal/Zip is not valid for its condition an error message is returned
{
var blnFailed = "No"

if (objPostalZip.value == "") {return}
if (strCountry == "Canada") {
	blnFailed = validatePostalCode(objPostalZip,blnFailed)

	if (blnFailed == "Yes")	{
		alert ("Please ensure that the postal code is L#L#L# or L#L #L# (L = Letter)")
		return blnFailed}	
	}
else if (strCountry == "United States")
	{
	blnFailed = validateZipCode(objPostalZip,blnFailed)
	if (blnFailed == "Yes")
		{alert ("Please ensure that the zip code is #####, ##### ####, or #####-#### (# = Number)")
	     return blnFailed}
	}
else if (strCountry == "")
	{
	blnFailed = validatePostalCode(objPostalZip,blnFailed)
	if (blnFailed =="Yes")
		{blnFailed = "No"
		blnFailed = validateZipCode(objPostalZip,blnFailed)
		if (blnFailed == "Yes")
			{alert ("Please ensure that the postal/zip is valid as either a postal or zip code")
			return blnFailed}}
	} else
	{alert ("Please ensure country is either Canada, United States or blank")
	return blnFailed}
}

function validateZipCode(objZipCode,blnFailed)
//
//	This function checks the zip code to determine if it is valid.  First it checks the length to make sure it isn't too big or too small.  Since there are two
//  different lengths of zip codes out there this handles both the ##### and #####-####.  It then checks to make sure the first 5 characters are 
//	numbers.  If they are it checks the sixth character to see if it is a hyphen and does different things based on the length.  If the length of the zip 
//  code is 9 then it means that no hyphen was there (ie entered as #########) and thus it squeezes a hyphen in.  If the length was ten characters
//  it just replaces the sixth character with a hyphen.  After inserting the hyphen the function makes sure the last four characters are numbers.  If it fails
//	any of the validation checks a variable is passed back saying that the validation failed.
{
var strZipCode = objZipCode.value

if ((strZipCode.length != 5) && (strZipCode.length != 9) && (strZipCode.length != 10))
	{blnFailed = "Yes"}
else 	{
	for (intCurrentPosition = 0 ; intCurrentPosition <=4 ;  intCurrentPosition ++)
		{var ch = strZipCode.charAt( intCurrentPosition)
		if ((ch < "0") || (ch > "9"))
			{blnFailed = "Yes"}}
	if (strZipCode.length >= 9)
		{if ((strZipCode.charAt(5) != "-") && (strZipCode.length == 9))
			{strZipCode = strZipCode.substring(0,5) + "-" + strZipCode.substring(5,10)}
		else if ((strZipCode.charAt(5) != "-") && (strZipCode.length == 10))
			{strZipCode = strZipCode.substring(0,5) + "-" + strZipCode.substring(6,10)	}
		for (intCurrentPosition = 6 ; intCurrentPosition <= 9 ;  intCurrentPosition ++)
			{var ch = strZipCode.charAt(intCurrentPosition)
			if ((ch < "0") || (ch > "9"))
				{blnFailed = "Yes"}}
		}
	}

if (blnFailed == "No")
	{objZipCode.value = strZipCode}
	
return blnFailed
}

function validatePostalCode(objPostalCode,blnFailed)
//
//	This function checks the postal code to see if it is valid as LLL LLL or LLLLLL.  First it checks the length to make sure it isn't too big or too small.  
//  If it is okay then it is changed to all uppercase.  Then the first 3 characters are checked to see if they are all letters.  If they are then the fourth
//  character is checked to see if it is a space.  If it is no then the length is checked.  If it is 6 characters it squeezes a space into the middle.  If it is 7
//  characters it replace the fourth character with a space.  Then it checks the last 3 characters to make sure they are numbers.  If it fails
//	any of the validation checks a variable is passed back saying that the validation failed.
{
var strPostalCode = objPostalCode.value

if ((strPostalCode.length < 6) || (strPostalCode.length > 7))
	{blnFailed = "Yes"}
else {
	strPostalCode = strPostalCode.toUpperCase()
	for (intCurrentPosition = 0 ; intCurrentPosition <= 2 ;  intCurrentPosition ++)
		{var ch = strPostalCode.charAt( intCurrentPosition)
		if (intCurrentPosition == 1)
			{if ((ch < "0") || (ch > "9"))
				{blnFailed = "Yes"}}
		else if ((ch < "A") || (ch > "Z"))
			{blnFailed = "Yes"}
		}
	if ((strPostalCode.length == 7) && (strPostalCode.charAt(3) != " "))
		{strPostalCode = strPostalCode.substring(0,3) + " " + strPostalCode.substring(4,7)}
	else if (strPostalCode.charAt(3) != " ")
		{strPostalCode = strPostalCode.substring(0,3) + " " + strPostalCode.substring(3,6)}
	for (intCurrentPosition = 4 ; intCurrentPosition <= 6 ;  intCurrentPosition ++)
		{
		var ch = strPostalCode.charAt(intCurrentPosition)
		if (intCurrentPosition == 5)
			{if ((ch < "A") || (ch > "Z"))
				{blnFailed = "Yes"}}
		else if ((ch < "0") || (ch > "9"))
			{blnFailed = "Yes"}}	
	}


if (blnFailed == "No")
	{objPostalCode.value = strPostalCode}
return blnFailed
}

function TrimEndSpaces(strTemp)
{
var intCurrentPosition = strTemp.length - 1
var intSpaceCounter = 0
var blnDone = "No"

while ((intCurrentPosition != 0) && (blnDone == "No"))
	{if (strTemp.charAt(intCurrentPosition) == " ")
		{intSpaceCounter ++}
	else
		{blnDone = "Yes"}
	intCurrentPosition --}

strTemp = strTemp.substring(0,(strTemp.length - intSpaceCounter))
return strTemp
}

function validatePercent(strPercent)
{
var strTemp = ""
var errMessage = ""

errMessage = funIsNumberOrPercent(strPercent) 

if  ((errMessage != "") && (strPercent != ""))
	{alert (errMessage)
	return "Yes"}
else 
	{if (strPercent.charAt(strPercent.length -1) == "%")
		{strTemp = strPercent.substring(0,strPercent.length-1)}
	else
		{strTemp = strPercent}
	if  ((strTemp != "") && ((strTemp > 100) || (strTemp < 0)))
		{alert ("Percent Values must be between 0 and 100.")
		return "Yes"}}
}

function funIsNumberOrPercent(strNumber)

//  Description:   This function determines if a value contains only numbers, pluses, minuses, or percent signs.  If it has any of the later three they
//						must be either in the first position (plus & minus) or last (percent). also if there are only signs then it is not valid.  Finally a percent
//						cannot be all symbols.  It must have some numbers.
{var intCurrentPosition = -1
var strError = ""
var intSignCount = 0
var intDecimalCount = 0

// Loop through the string and see if any character is anything besides a number, plus, minus, or percent
for (intCurrentPosition = 0 ; intCurrentPosition < strNumber.length ;  intCurrentPosition ++)
	{
	var ch = strNumber.charAt( intCurrentPosition)
	if  (((ch == "-") || ( ch == "+")) && (intCurrentPosition != 0))
		{strError = "Plusses and minuses can only begin a percent"
		}
	else if ((ch == "%") && (intCurrentPosition != strNumber.length -1))
		{strError = "Percent signs come at the end of a percent"
		}
	else if (((ch < "0") || (ch > "9")) && (ch != ".") && (ch != "%") && (ch != "+") && (ch != "-"))
		{strError = "A percent can only have #s, +, -, %, or decimals"
		}
	if ((ch == "+") || (ch == "-") || (ch == "%") || (ch == "."))
		{intSignCount ++}
	if (ch  == ".")
		{intDecimalCount ++
		if (intDecimalCount > 1)
			{strError = "Only one decimal in a percent"
			return "Yes"}}
	if (strError != "")
		{return strError}
	}
	
if (intSignCount ==strNumber.length)
	{strError = "A percent must have some numbers"
     }	
return strError
}

//**********************

function IsCurrency(objNumber)
//
//  Description:   This function determines if the passed value is a currency value
{
    var i;
    var seenDecimalPoint = false;
    var defaultEmptyOK = false;
    var s = replaceSubstring(replaceSubstring(replaceSubstring(replaceSubstring(objNumber.value, ",", ""), "$", ""), ")", ""), "(", "-")
    if (isEmpty(s)) return true

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if ((c =="-" || c == "$") & i <= 1) {
          } else {
          if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
          else if (!isDigit(c)) {objNumber.value = 0
                                       return};
         }
    }

    objNumber.value = parseFloat(s)
}  // End of the IsCurrency Function

function ResetListBox(listBox) {

// Purpose: 	This function resets a list box so nothing is selected
// Inputs:  	listBox - the listBox to be reset
// Returns: 	None
// Created By:	Steve Jeske, Kryos Systems Associates, Sept 28/2000

	for (var i = 0; i < listBox.length; i++) {
		if (listBox.options[i].selected) {
			listBox.options[i].selected = false;
		}	
	}
}

function ResetRadioField(buttonGroup) {

// Purpose: 	This function resets a radio button so nothing is selected
// Inputs:  	buttonGroup - the radio button group to reset
// Returns: 	None
// Created By:	Steve Jeske, Kryos Systems Associates, Sept 28/2000

	for (var i = 0; i < buttonGroup.length; i++) {
		if (buttonGroup[i].checked) {
			buttonGroup[i].checked = false;
		}	
	}
}

function ValidateDate(strDateFormat,strDateString,strFourYearDigits)
// Kryos Systems
//
//  This function is used to validate a numeric date field.  First it validates that the field is not blank or filled with any invalid
// characters.  Then it makes sure that the formatting is in a valid format.  The reason it checks this is that it allows code
// to dynamically change the formatting and if the formatting is incorrect then the date will be invalid.  Next it grabs
// the day, month, and year from the date string.  It checks these to determine that they have the correct formatting.  Finally
// it checks that there are valid # of days in the month (ie not 30 in a February leap year).
//
//	Given :	strDateFormat - the format of the date (ie dmy would be DD/MM/YYYY or day/month/year
//				strDateString -	the string containing the date
//				strFourYearDigits - Yes/No if to display a four digit year 
//
//  Returns:	One of three things
//					1) The updated date if all went well
//					2) The old entered string (if it was a non fatal error)
//					3) "Failed" if it is a fatal error
//
//	Note:		A fatal error is one where the field should not be saved with the data inside of it.  Making a variable fatal will return
//				Failed instead of the original string, allowing you to flag and use things like focus on these particular ones.  
//				Depending on the usage of this field, this may vary from application to application.  To set a fatal 
//				error just change the Error variable to "Yes".
//
// Created : Aaron Howard/Kryos - March 22, 2000
//

{
//Possible Fatal Errors
	var ErrorIsBlank = "No"						//The field has no value
	var ErrorInvalidCharacters = "Yes"			//A character is in the string that is not a number or a hyphen
	var ErrorFormatStringInvalid = "No"		//Either the D, M or Y is missing in the format string
	var ErrorDayIsInvalid = "Yes" 				//There are >31 or < 1 days in the month
	var ErrorMonthIsInvalid = "Yes"				//The month is >12 or <1
	var ErrorYearIsInvalid = "No"				//Not currently used
	var ErrorDaysInMonth = "Yes"				//Certain months have only 30 days
	var ErrorFebruaryInvalid = "Yes"			//February has 29 days some years, only 28 others


	var intTempDay = 0
	var intPositionDay = -1
	var intPositionMonth = -1
	var intPositionYear = -1	
	var strTempLetter = ""
	var strTempString = ""
	var dteCurrentDate = new Date()
	var intCurrentDay = dteCurrentDate.getDate()
	var intCurrentMonth = dteCurrentDate.getMonth() + 1
	var intCurrentYear = dteCurrentDate.getYear()
	var strDone = "No"
	var strValidDateCharacters = "1234567890/"

    //Check to see if it is empty
	if (strDateString =="")
		{
		return IsFatalError(ErrorIsBlank,strDateString)
		}
	
	//Check to see if there are any invalid characters
	if (AnyInvalidCharacters(strDateString,strValidDateCharacters))
		{
		alert("Only numbers and /'s are allowed in dates.")
		return IsFatalError(ErrorInvalidCharacters,strDateString)
		}
   	
// This verifies that the formatting has day, month, and year	
	for (intCurrentPosition=0; intCurrentPosition<=2;intCurrentPosition++)
		{
		strTempLetter =strDateFormat.charAt(intCurrentPosition)
		if (IsDay(strTempLetter))
			{
			intPositionDay = intCurrentPosition
			}
		else if (IsMonth(strTempLetter))
			{
			intPositionMonth = intCurrentPosition
			}
		else if (IsYear(strTempLetter))
			{
			intPositionYear = intCurrentPosition
			}
		else
			{
			// Format string is invalid
			return IsFatalError(ErrorFormatStringInvalid,strDateString)
			}
	}
	
// If it does not have a day, month or year as a format choice
	if ((intPositionMonth==-1) || (intPositionDay==-1) || (intPositionYear==-1))
		{
		return strDateString
		}
	
//Grab the day, month, and year from the date string.  Then validate that it is okay.	
	intCurrentPosition =0
	while (intCurrentPosition <=2)
		{
		strTempLetter =strDateFormat.charAt(intCurrentPosition)
		if (IsDay(strTempLetter))
			{
			intDay = ValidateDay(GetField(strDateString,intCurrentPosition))
			if (intDay == false)
				{
				return IsFatalError(ErrorDayIsInvalid,strDateString)
				}
			strTempString = strTempString + intDay + "/"
			}
		else if (IsMonth(strTempLetter))
			{
			intMonth = ValidateMonth(GetField(strDateString,intCurrentPosition))
			if (intMonth == false)
				{
				return IsFatalError(ErrorMonthIsInvalid,strDateString)
				}
			strTempString = strTempString + intMonth + "/"
			}
		else if (IsYear(strTempLetter))
			{
			intYear = ValidateYear(GetField(strDateString,intCurrentPosition))
			if (intYear == false)
				{
				return IsFatalError(ErrorYearIsInvalid,strDateString)
				}
			if (strFourYearDigits == "No")
				{
				intYear = intYear + ""
				intYear = intYear.substring(intYear.length-2, intYear.length)
				}

			strTempString = strTempString + intYear + "/"
			}
		intCurrentPosition++
		}
	
		
//Check # Days in month
if (((intMonth==4) || (intMonth==6) || (intMonth==9) || (intMonth==11)) && (intDay==31))
	{
	alert(GetMonthName(intMonth) + " does not have 31 days")
	return IsFatalError(ErrorDaysInMonth,strDateString)
	}
//Check February leap year
else if (intMonth==2)
	{
	var isLeap = (intYear %4 ==0 && (intYear%100 !=0 || intYear %400 ==0))
	intTempDay = intDay
	if ((intTempDay>29) || (intTempDay==29) && (!isLeap))
		{
		alert("February " + intYear + " does not have " + intDay + " days.")
		return IsFatalError(ErrorFebruaryInvalid,strDateString)
		}
	return strTempString.substring(0,strTempString.length-1)
	}

return strTempString.substring(0,strTempString.length-1)
}

//**********************

function IsFatalError(strIsFatal,strValidString)
//This returns either a Failed messgae or a valid string dependant on if the string is valid

{
if (strIsFatal =="Yes")
	{
	return "Failed"
	}
else
	{
	return strValidString
	}
}

//**********************

function AnyInvalidCharacters(strStringToCheck,strListofValidCharacters)
//  This searches goes through a string and determines if it has any invalid characters.  It is given one string to search and
//  and another that contains all the valid characters.  It then searches the second string with each character in the first 
//  string to see if it exists in the latter and returns false if any of the characters is not in the list of valid characters
//
//  Given :	strStringToCheck - a string full of characters to check
//				strListofValidCharacters - a string full of all the characters to compare
//
//	Returns:	true - if any character is not in the valid character list
//				false- if all the characters are in the valid character list
//
//	Created:	Aaron Howard/Kryos March 22, 2000

{
	var strDone = "No"
	var intCurrentCharacter = 0
	
	while ((intCurrentCharacter < strStringToCheck.length) && (strDone=="No"))
    		{ 
		if (strListofValidCharacters.indexOf(strStringToCheck.charAt(intCurrentCharacter)) == -1)
			{
			return true
			}
		intCurrentCharacter++ 
		}
 	return false
}

//*******************

function GetMonthName(intMonthNumber)
// This function returns the month name corresponding to the month number.
//
//  Given:	intMonthNumber a number from 1 to 12
//	Returns:	The month name corresponding to the month number
//
//	Created:	Aaron Howard/Kryos March 22, 2000

{
if (intMonthNumber==1)
	{return "January"}
else if (intMonthNumber==2)
	{return "February"}
else if (intMonthNumber==3)
	{return "March"}
else if (intMonthNumber==4)
	{return "April"}
else if (intMonthNumber==5)
	{return "May"}
else if (intMonthNumber==6)
	{return "June"}
else if (intMonthNumber==7)
	{return "July"}
else if (intMonthNumber==8)
	{return "August"}
else if (intMonthNumber==9)
	{return "September"}
else if (intMonthNumber==10)
	{return "October"}
else if (intMonthNumber==11)
	{return "November"}
else if (intMonthNumber==12)
	{return "December"}
}

//*******************

function ValidateDay(intDay)
// This function determines if the day is not blank, and is between 1 and 31.  If the day is blank then it is replaced with the
//	current day.  Also, if the day has only one digit, it calls a function to add a zero to the front (ie 7 -> 07)
//
//  Given:	intDay- the date
//	Returns:	false 	- if the date is not between 1 and 31
//				intDay- the new updated date
//
//	Created:	Aaron Howard/Kryos March 22, 2000

{
	var dteCurrentDate = new Date()
	var intCurrentDay = dteCurrentDate.getDate()

	if (intDay == "")
		{
		intDay = intCurrentDay
		}
	else if ((intDay <1) || (intDay>31))
		{
		alert ("The day must be between 1 and 31")
		return false
		}
	
	intDay = CheckIfToAddZero(intDay)
	return intDay
}

//*******************

function ValidateMonth(intMonth)
// This function determines if the month is not blank, and is between 1 and 12.  If the month is blank then it is replaced with the
//	current month.  Also, if the month has only one digit, it calls a function to add a zero to the front (ie 7 -> 07)
//
//  Given:	intMonth- a number corresponding to the current month
//	Returns:	false 	- if the month is not between 1 and 12
//				intMonth- the new updated month
//
//	Created:	Aaron Howard/Kryos March 22, 2000


{
	var dteCurrentDate = new Date()
	var intCurrentMonth = dteCurrentDate.getMonth() + 1
	
	if (intMonth == "")
		{
		//This makes it a number so it does not crash the CheckItToAddZero
		intMonth = intCurrentMonth + 0
		}
	else if ((intMonth <1) || (intMonth>12))
		{
		alert ("The month must be between 1 and 12")
		return false
		}

	intMonth = CheckIfToAddZero(intMonth)
	return intMonth
}

//*******************

function ValidateYear(intYear)
// This function validates the year in several methods.  It determines that the year is not blank, If ti is then it sets it to the current
//  year.  It calls a function to add a zero to the front (ie 7 -> 07) if there is only one digit and then it does some formatting. If 
//  the year is less than 70 then it assumes it is in the 20th century and adds 2000 to the number.  If it is between 70 and 
//  99 then it adds 99.  Otherwise it leaves it alone.
//  
//  Note:		Due to bug in Netscape Navigator 4.08 that assumes if the current year is 2000, it thinks it is 100; this function
//				adds 1900 to the number until 2020.  Hopefully Netscape will have it fixed by then.
//
//  Given:	intYear- a number corresponding to the current year
//	Returns:	intYear- the new updated year
//
//	Created:	Aaron Howard/Kryos March 22, 2000

{
	var dteCurrentDate = new Date()
	var intCurrentYear = dteCurrentDate.getYear()

//This is to get around a bug in Netscape navigator
	if ((intCurrentYear >= 100) && (intCurrentYear <= 120))
		{
		intCurrentYear +=1900
		}
	if (intYear == "")
		{
		return intCurrentYear
		}
	else
		{
		intYear = CheckIfToAddZero(intYear)
		if ((intYear>70) && (intYear <=99))
			{
			intYear= 19 + intYear
			}
		else if (intYear <69)
			{
			intYear=20+ intYear
			}
		}

	return intYear
}

//*******************

function CheckIfToAddZero(intNumber)
{
// This function is used to convert single digit numbers into double digits by adding a zero to the front if they need it.
//
//  Given:	intNumber- a number to maybe change
//	Returns:	intYear- the new number
//
//	Created:	Aaron Howard/Kryos March 22, 2000

//If it is less than 10 but only one digit
intNumber= intNumber+ ""
	if (intNumber.length == 1)
		{
		intNumber ="0" + intNumber
		}
//If it is less than 10 but more than one digit (ie 07)
	else if ((intNumber<=9) && (intNumber.length == 2))
		{
		intNumber = "0"+intNumber.substring(intNumber.length-1,intNumber.length)
		}
	return intNumber
}

//*******************

function GetField(strDateString,intPosition)
// This function parses the date based on a position needed from a format based on DD/MM/YYYY but where the order of the
//  days, months, and years are unknown.  If is given the string to search and the position of the string desired.  Then it pulls
//  off any text before the position (based on if there is a slash in front of it) and any text afterwords.
//  
//  Given:	intDateString	- the date/string to parse in a format similar to DD/MM/YYYY
//				intPosition 		- the position (from 0 to 2) of the date field (ie in the above example the Day would be 0)
//	Returns:	strCurrentString	- the parsed out date field
//
//	Created:	Aaron Howard/Kryos March 22, 2000

{
	var strCurrentString = strDateString
	var intCurrentPosition =0
	var intSlashPosition = 0
	var strDone = "No"

//Remove the starting text
	while ((intCurrentPosition < intPosition) && (strDone=="No"))
		{
		intSlashPosition= strCurrentString.indexOf("/")

		if (intSlashPosition ==-1)
			{
			strCurrentString =""
			strDone="Yes"
			}
		else
			{
			strCurrentString = strCurrentString.substring(intSlashPosition+1, strCurrentString.length)
			}
		intCurrentPosition++
		}

//Remove the ending text		
	if ((intPosition!=2) && (strDone =="No"))
		{
		while (intCurrentPosition < 2)
			{
			intSlashPosition= strCurrentString.indexOf("/")
			if (intSlashPosition >0)
				{
				strCurrentString = strCurrentString.substring(0,strCurrentString.indexOf("/"))
				}
			intCurrentPosition++
			}
		}

	return strCurrentString
}


//*******************

function IsDay(strLetter)
{
	if ((strLetter == "d") || (strLetter == "D"))
		{return true}
	else
		{return false}
}

//*******************

function IsMonth(strLetter)
{
	if ((strLetter == "m") || (strLetter == "M"))
		{return true}
	else
		{return false}
}

//*******************

function IsYear(strLetter)
{
	if ((strLetter == "y") || (strLetter == "Y"))
		{return true}
	else
		{return false}
}

function getCookie(strName) {
var myCookie = " " + document.cookie + ";";
var searchName = " " + strName + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
var result = "";

// Parse the cookie and grab the information in the strName Portion.
if (startOfCookie != -1) {
  startOfCookie += searchName.length;
  endOfCookie = myCookie.indexOf(";", startOfCookie);
  result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return result;
}

//***************************************************************************************

function setCookie(name, value, expiredays) {
//    
// Description:	This function will create a cookie with a given expiry date
//     
// Parameters:	name - name of the cookie to create or update
//            	value - value of the cookie
//		expiredays - number of days until the cookie expires
//
// Returns:	None
//                         
// Created by:	Steve Jeske, Kryos Systems Associates, Sept 19/2000

	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + value + "; expires=" + todayDate.toGMTString() + ";"
}

//***************************************************************************************

function setTempCookie(name, value) {
//    
// Description:	This function will create a temporary cookie
//     
// Parameters:	name - name of the cookie to create or update
//            	value - value of the cookie
//
// Returns:	None
//                         
// Created by:	Steve Jeske, Kryos Systems Associates, Sept 19/2000

	document.cookie = name + "=" + value + ";";
}

function determineIfReviewed() {
//
// Purpose: This function determines if this page is being opened from an content review email or not. If it is  
//		then open up a popup form to allow them to quickly recertify the content.
//	Inputs:		None
//	Returns:	None
//	
//	Created by:	Aaron Howard, Kryos Systems Associates. Apr 21/2003
//
//      Modified by: 

	// Get query string ...
	var href = window.location.href;
	var qs = href.substring(href.indexOf("?"),href.length);

	// Get position of first parameter and if doesn't exist exit...
	var posFirst = qs.indexOf("&");
	if (posFirst == -1) {
		return false;
	}
	
	// Get position of second parameter and if doesn't exist exit ...
	var posSecond = qs.indexOf("&", posFirst+1);
	if (posSecond == -1) {	
        	return false;
	}
	
	// Get UNID ...
	var adminAction = qs.substring(posFirst+1,posSecond);
	var reviewUNID = qs.substring(posSecond+1,qs.length);

	// Open Quick Review Approval window ...
	if (reviewUNID !="") 
	{
		// If this is not approvals then ...
		if (adminAction == "review=true") {
			window.open(href.substring(0, href.toLowerCase().lastIndexOf(".nsf")+4) + '/frmContentReview?OpenForm&reviewUNID=' + reviewUNID,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=400,height=200'); 
			location.replace("?OpenDocument");
			}
	}
	return false;
}
