// 
//  Kryos Systems
//
//  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;
}


//document.oncontextmenu=new Function("return false")
