/*   4/01/2005 - ALIWEB's Common JavaScript                             */

// identifyBrowser() - Note which browser we're using

//      Modal Dialog Box Code
// deadend() - Block Navigator and IE link activity when dialog window active.
// disableForms() - Disable form elements and links in all frames for IE
// enableForms() - Restore IE form elements and links to normal behavior.
// checkModal() - EVERY frame' s onFocus; Return focus to dialog window if open
// blockEvents() - Disable form elements while dialog is open
// unblockEvents() - Cancel previous blockEvents()
// openDialog() - Generate a modal dialog window
// WriteHelpWindow() - Write out the desired web page
// WriteSearchWindow() - Write out the desired web page
// WritePSSearchWindow() - Write out the desired web page
// WriteCAGEWindow() - Write out the desired web page

//      String Functions
// String.IsWhite() - Return true if passed character is whitespace
// String.RTrim() - Remove trailing spaces in a string
// String.LTrim() - Remove leading spaces in a string
// String.AllTrim() - Remove leading and trailing spaces in a string
// String.Substr() - Return a part of a string using our normal notation
// String.Left() - Return the leftmost part of a string
// String.Right() - Return the rightmost part of a string
// String.StrAt() - Return the position of a string within a string
// String.RtStrAt() - Return the rightmost position of a string within a string
// String.StrTran() - Replace all instances of sStr1 with sStr2 in this string
// String.Upper() - Convert a string to uppercase
// String.PadLeft() - Pad a string on the left to the desired length
// String.makeLen() - Make a string the desired length
// String.deCode() - Decode the contents of a string
// Empty() - Return true if the passed string is empty
// EmptyN() - Return true if the passed string varible = 0
// TrimAtSpace() - Return a string variable up to the first space
// extrToken() - Extract and return parts of a string around a token
// between() - Return true if a test value is between min and max values

//      Other Functions
// checkFormVar() - Make sure the search variable has an entry
// LoadChoice() - Generic array constructor
// makeFNumb() - Convert a string to floating point number; make NaNs = 0
// makeINumb() - Convert a string to integer number; make NaNs = 0
// formatNum() - Generic positive number decimal formatting function
// RoundOff() - Round off a number to the desired number of decimal places
// RoundUp() - Round a number up to the desired number of decimal places
// Add2Msg() - Add the passed string to a message prefacing with "," if needed
// setSearch() - Generic function to save the Full Search results
// saveSearch() - Generic function to save the Partial Search results
// clearIDField() - Clear the ID field as a manual search entry was made
// checkLookup() - Make sure there's something in the lookup field
// getRadioValue() - Return the value of the whichever radio button is checked
// updateSelectObj() - Update our select dropdown
// getSelectedValue() - Define our variable from dropdown
// ButtonHit() - Checks a field and empty it if its not empty

//      Date Functions
// isDate() - Date field validation (called by other validation functions that specify minYear/maxYear)
// monthDayFormat() - Check the entered month or day size
// checkMonthLength() - Check the entered month for too high a value
// checkLeapMonth() - Check the entered February date for too high a value

//      Key Variables
var Browser = identifyBrowser();

// identifyBrowser() - Note which browser we're using
function identifyBrowser() {
  var agent = navigator.userAgent.toLowerCase();

  if (typeof window.opera != "undefined")   {
    var version = parseFloat(agent.replace(/.*opera[\/ ]([^ $]+).*/, "$1"));
    if (version >= 7)   {
      return "opera7";
    }
    else if (version >= 5)  {
      return "opera5";
    }
    return false;
  }
  else if (typeof document.all != "undefined")  {
    if (typeof document.getElementById != "undefined")  {
      var browser = agent.replace(/.*ms(ie[\/ ][^ $]+).*/, "$1").replace(/ /, "");
      if (typeof document.uniqueID != "undefined")  {
        if (browser.indexOf("5.5") != -1)   {
          return browser.replace(/(.*5\.5).*/, "$1");
        } else {
          return browser.replace(/(.*)\..*/, "$1");
        }
      } else {
        return "ie5mac";
      }
    }
    return false;
  }
  else if (typeof document.getElementById != "undefined")   {
    if (agent.indexOf("gecko") != -1)   {
      var nPosn = agent.indexOf("firefox");
      if (nPosn > 0) {
        var str = agent;
        str = str.substr(nPosn+8,10);
        str = str.substr(0,str.indexOf("."));
        return "firefox" + str;
      } else {
        return "mozilla";
      }
    }
  }
  return false;
}

/************************** Modal Dialog Box Code ***********************/
/*--------------------------------------------------------------------
|                 From "Simulating Modal Dialog Windows"             |
|                           by Danny Goodman                         |
| for "View Source" developer magazine from Netscape Communications  |
|               <http://developer.netscape.com/viewsource/>          |
--------------------------------------------------------------------*/
//  Adapted by Ken Green 8/05/2000

/***************************** Global Variables *************************/
// Variable for browser version branching
var BrowVer = parseInt(navigator.appVersion);
var Nav4 = ((navigator.appName == "Netscape") && (BrowVer >= 4));

// Setup a variable to note when our search window is closing
var SrchWinClosing = false;

// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object();

// Since links in IE4 cannot be disabled, preserve IE link onclick event
// handlers while they're "disabled."  Restore when re-enabling the main
// window.
var IELinkClicks

/********************** General Routines (do not edit) ******************/
// deadend() - Block Navigator and IE link activity when dialog window active.
function deadend() {
    if (dialogWin.win && !dialogWin.win.closed) {
        dialogWin.win.focus()
        return false
    }
}

// disableForms() - Disable form elements and links in all frames for IE
function disableForms() {
    IELinkClicks = new Array()
    for (var h = 0; h < frames.length; h++) {
        for (var i = 0; i < frames[h].document.forms.length; i++) {
            for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
                frames[h].document.forms[i].elements[j].disabled = true
            }
        }
        IELinkClicks[h] = new Array()
        for (i = 0; i < frames[h].document.links.length; i++) {
            IELinkClicks[h][i] = frames[h].document.links[i].onclick
            frames[h].document.links[i].onclick = deadend
        }
    }
}

// enableForms() - Restore IE form elements and links to normal behavior.
function enableForms() {
    for (var h = 0; h < frames.length; h++) {
        for (var i = 0; i < frames[h].document.forms.length; i++) {
            for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
                frames[h].document.forms[i].elements[j].disabled = false
            }
        }
        for (i = 0; i < frames[h].document.links.length; i++) {
            frames[h].document.links[i].onclick = IELinkClicks[h][i]
        }
    }
}

// checkModal() - EVERY frame' s onFocus; Return focus to dialog window if open
function checkModal() {
    if (dialogWin.win && (!dialogWin.win.closed) && !SrchWinClosing ) {
        dialogWin.win.focus();
    }
}

// blockEvents() - Disable form elements while dialog is open
function blockEvents() {
    if (Nav4) {
        window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
        window.onclick = deadend
    } else {
        disableForms()
    }
    window.onfocus = checkModal
}

// unblockEvents() - Cancel previous blockEvents()
function unblockEvents() {
    if (Nav4) {
        window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
        window.onclick = null;
        window.onfocus = null;
    } else {
        enableForms();
    }
}

/**************************** Page Creation Code ************************/

// openDialog() - Generate a modal dialog window
// Parameters:
//    windType -- 'H'elp or 'Search'
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    if windType == 'H'
//        objName = the name of the data array
//        rowOrFunc = nRARow -- The array row to use for the help text
//        currVal = not used
//    if windType == 'S'            // Full Search
//        objName = the name of the data array
//        rowOrFunc = returnFunc -- reference to the function (on this page) that
//                  is to act on the data returned from the search dialog
//        title = title -- the name of the search data
//        currVal = currVal -- the current value of the variable
//    if windType == 'P'            // Partial Search
//        objName = the HREF location of the search window
//        rowOrFunc = returnFunc -- reference to the function (on this page) that
//                  is to act on the data returned from the search dialog
//        title = not used
//        currVal = the current value of the variable (if any)
//    if windType == 'N'            // P/N and NSN Search
//        objName = the name of the data array
//        rowOrFunc = returnFunc -- reference to the function (on this page) that
//                  is to act on the data returned from the search dialog
//        title = title -- the name of the search data
//        currVal = the current value of the P/N
//        cKeyFld = the current value of the Sol. No.
//    if windType == 'R'            // RFID/UID page
//        objName = the name of the data array
//        rowOrFunc = returnFunc -- reference to the function (on this page) that
//                  is to act on the data returned from the search dialog
//        title = title -- the name of the search data
//    if windType == 'T'
//        objName = the name of the data array
//        rowOrFunc = nRARow -- The array row to use for the help text
//        currVal = not used
function openDialog(windType, width, height, objName, rowOrFunc, title, currVal, cKeyFld) {

    // Open the window only if needed
    if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {

        // Initialize properties of the modal dialog object.
        dialogWin.width = width
        dialogWin.height = height
        switch(windType) {
        case 'D':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'windxyzx.htm'
            break;
        case 'S':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'srchxyzx.htm';
            break;
        case 'P':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'srchpszx.htm';
            break;
        case 'V':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'windxyzx.htm'
            break;
        case 'N':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'srchxyzx.htm';
            break;
        case 'R':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'srchxyzx.htm';
            break;
        case 'L':
            dialogWin.returnFunc = rowOrFunc
            dialogWin.url = 'srchxyzx.htm';
            break;
        case 'L':                   // Pallet RFID enty page
            WritePalletRFIDWindow(dialogWin.win, title, currVal)
            break;
        default:
            dialogWin.url = 'helpxyzx.htm';
        }

        // Keep name unique so Navigator doesn't overwrite an existing dialog.
        dialogWin.name = (new Date()).getSeconds().toString()

        // Assemble window attributes and try to center the dialog.
        if (Nav4) {

            // Center on the main window.
            dialogWin.left = window.screenX +
               ((window.outerWidth - dialogWin.width) / 2)
            dialogWin.top = window.screenY +
               ((window.outerHeight - dialogWin.height) / 2)
            var attr = "screenX=" + dialogWin.left +
               ",screenY=" + dialogWin.top + ",resizable=yes,width=" +
               dialogWin.width + ",height=" + dialogWin.height
        } else {

            // The best we can do is center in screen.
            dialogWin.left = (screen.width - dialogWin.width) / 2
            dialogWin.top = (screen.height - dialogWin.height) / 2
            var attr = "left=" + dialogWin.left + ",top=" +
               dialogWin.top + ",resizable=yes,width=" + dialogWin.width +
               ",height=" + dialogWin.height
        }

        // We need some additional attributes for Vendor windows
        if (windType == "V" || windType == "C" || windType == "D" ||
          windType == "P" || windType == "T" || windType == "H" ||
          windType == "R" || windType == "L") {
            attr = attr + ",scrollbars";
        }

        // TESTING ONLY //
        // attr = attr + ",menubar";

        // Open our dialog window
        dialogWin.win = window.open("", dialogWin.name, attr);

        // Go write the page's info and then, set the focus to it
        switch (windType)    {
        case 'V':
            WriteVendorWindow(dialogWin.win, objName, title )
            break
        case 'P':                   // Partial Search
            WritePSSearchWindow(dialogWin.win, objName, currVal);
            break;
        case 'S':                   // Full Search
            WriteSearchWindow(dialogWin.win, objName, title, currVal);
            break;
        case 'N':
            WritePNSearchWindow(dialogWin.win, objName, title, cKeyFld, currVal)
            break
        case 'C':
            WriteCAGEWindow(dialogWin.win, title, currVal)
            break
        default:                    // Help
            WriteHelpWindow(dialogWin.win, objName, rowOrFunc, title );
        }
        dialogWin.win.focus()
    } else {
        dialogWin.win.focus()
    }
}

// WriteHelpWindow() - Write out the desired web page
function WriteHelpWindow( pageObj, arraydata, arRow, bNoHelp ) {

    pageObj.document.writeln('<HTML>\n<HEAD>');
    pageObj.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');

    if (bNoHelp) {
        pageObj.document.writeln('<TITLE>' + arraydata[arRow].Fld1 + '<\/TITLE>\n');
    }  else  {
        pageObj.document.writeln('<TITLE>' + arraydata[arRow].Fld1 + ' Help<\/TITLE>\n');
    }

    pageObj.document.writeln('<' + 'SCRIPT' + ' LANGUAGE="JavaScript">\n');

    pageObj.document.writeln('// Handle click of OK button');
    pageObj.document.writeln('function handleOK() {');
    pageObj.document.writeln('    if (opener) opener.SrchWinClosing = true;');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('<\/' + 'SCRIPT><\/HEAD>\n');

    pageObj.document.writeln('<BODY TEXT="#000000" BGCOLOR="#FFEEAA" LINK="#000099" VLINK="#000099" ALINK="#FF0000"');
    pageObj.document.writeln('    onLoad="if (opener) opener.blockEvents()"');
    pageObj.document.writeln('    onUnload="if (opener) opener.unblockEvents()">\n');

    pageObj.document.writeln('<FORM><CENTER><TABLE WIDTH="90%">\n');

    // Output the help messages
    pageObj.document.writeln('<TR><TD>');
    pageObj.document.writeln( arraydata[arRow].Fld2 );
    pageObj.document.writeln('<CENTER><HR WIDTH="95%"><\/CENTER>');
    pageObj.document.writeln('<\/TD><\/TR>\n');

    pageObj.document.writeln('<TR><TD>');
    pageObj.document.writeln('<CENTER>');
    pageObj.document.writeln('<INPUT TYPE="button" VALUE="   OK   " onClick="handleOK()">');
    pageObj.document.writeln('<\/CENTER>');
    pageObj.document.writeln('<\/TD><\/TR>\n');

    pageObj.document.writeln('<\/TABLE><\/CENTER>\n');
    pageObj.document.writeln('<\/FORM>\n');

    pageObj.document.writeln('<\/BODY>');
    pageObj.document.writeln('<\/HTML>\n');
    pageObj.document.close();
}

// WriteSearchWindow() - Write out the desired web page
function WriteSearchWindow( pageObj, arraydata, title, currValue) {
    pageObj.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
    pageObj.document.writeln('<HTML>\n<HEAD>');
    pageObj.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');
    pageObj.document.writeln('<TITLE>' + title + ' Lookup<\/TITLE>\n');

    pageObj.document.writeln('<' + 'script' + ' type="text/javascript">');

    pageObj.document.writeln('// Handle OK button click');
    pageObj.document.writeln('function handleOK() {');
    pageObj.document.writeln('    if (opener && !opener.closed) {\n');

    pageObj.document.writeln("        // Get our form's data");
    pageObj.document.writeln('        var retData = getFormData(document.Search)\n');

    pageObj.document.writeln("        // Now, call the main window's data loading function");
    pageObj.document.writeln('        opener.dialogWin.returnFunc(retData);');
    pageObj.document.writeln('    } else {');
    pageObj.document.write('        alert("You have closed the main window.\\n');
    pageObj.document.write('\\n');
    pageObj.document.writeln('No action will be taken on the choices in this dialog box.");');
    pageObj.document.writeln('    }');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Handle Cancel button click');
    pageObj.document.writeln('function handleCancel() {');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Extract the search variable and return it');
    pageObj.document.writeln('function getFormData(form) {');
    pageObj.document.writeln('    var nIndex = form.cSrchFld.selectedIndex;');
    pageObj.document.writeln('    var valueString = form.cSrchFld.options[nIndex].value;');
    pageObj.document.writeln('    return valueString');
    pageObj.document.writeln('}');
    pageObj.document.writeln('<\/' + 'script>');
    pageObj.document.writeln('<\/HEAD>\n');

    pageObj.document.writeln('<BODY TEXT="#000000" BGCOLOR="#FFEEAA" LINK="#000099" VLINK="#000099" ALINK="#FF0000"');
    pageObj.document.writeln('    onLoad="if (opener) opener.blockEvents()"');
    pageObj.document.writeln('    onUnload="if (opener) opener.unblockEvents()">\n');

    pageObj.document.writeln('<center>Select your choice from the list</center>');
    pageObj.document.writeln('<FORM NAME="Search" ACTION="">\n');

    pageObj.document.writeln('<!-- The search options -->');
    pageObj.document.writeln('<center>\n');
    pageObj.document.writeln('<select name="cSrchFld" size="15" onclick="handleOK();">');

    // We're passed a value, try to find it in the list
    nSeleRow = 0;
    if (currValue.length > 0)   {
        for (var i = 1; i < arraydata.length; i++) {
            if (arraydata[i].Fld1 == currValue) {
                nSeleRow = i;
                break;
            }
        }
    }
    if (nSeleRow == 0)  {
        nSeleRow = 1
    }

    // Here we need to create our option values from the array
    var cLine = "";
    for (var i = 1; i < arraydata.length; i++) {

        // We want to create something that looks like
        //  <OPTION VALUE="X">search value
        cLine = '<option '

        // Mark the appropriate one selected
        if (i == nSeleRow) {
            cLine = cLine + 'selected '
        }

        // Add the rest of the stuff including our desired value
        cLine = cLine + 'value="' + i + '">' + arraydata[i].Fld1

        // Output this line
        pageObj.document.writeln(cLine);
    }
    pageObj.document.writeln('<\/select></center><BR>\n');

    pageObj.document.writeln('<DIV STYLE="text-align:center">');
    pageObj.document.writeln('<INPUT TYPE="button" VALUE="Cancel" onClick="handleCancel()">');
    pageObj.document.writeln('&nbsp;&nbsp;');
    pageObj.document.writeln('<INPUT TYPE="button" VALUE="   OK   " onClick="handleOK()">');
    pageObj.document.writeln('&nbsp;&nbsp;');
    pageObj.document.writeln('<\/DIV>\n');

    pageObj.document.writeln('<\/FORM>');
    pageObj.document.writeln('<\/BODY>');
    pageObj.document.writeln('<\/HTML>\n');
    pageObj.document.close();
}

// WritePSSearchWindow() - Write out the desired web page
function WritePSSearchWindow( pageObj, newHREF, currValue ) {

    pageObj.document.writeln('<HTML>\n<HEAD>');
    pageObj.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');
    pageObj.document.writeln('<TITLE>Lookup Retrieval</TITLE>\n');
    pageObj.document.writeln('<' + 'SCRIPT' + ' LANGUAGE="JavaScript">');
    pageObj.document.writeln('<!' + '--');

    pageObj.document.writeln('// Go get the search info');
    pageObj.document.writeln('function getSrch() {\n');

    pageObj.document.writeln("    // Get the search info");
    pageObj.document.writeln('    location.href = "' + newHREF + '";');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('//-->');
    pageObj.document.writeln('</' + 'SCRIPT>');
    pageObj.document.writeln('</HEAD>\n');

    pageObj.document.writeln('<BODY TEXT="#000000" BGCOLOR="#FFEEAA"');
    pageObj.document.writeln('    onLoad="setTimeout(' + "'getSrch()'" +
      ',500);">\n');

    pageObj.document.writeln('<!-- Top of Page Bar and Menu -->');
    pageObj.document.writeln('<TABLE WIDTH="100%">');
    pageObj.document.writeln('<TR><TD ALIGN="MIDDLE" BGCOLOR="#0080C0">');
    pageObj.document.writeln('<CENTER><B><FONT FACE="Arial" COLOR="#FFFFFF" SIZE=+2>');
    pageObj.document.writeln('Lookup Retrieval</FONT></B></CENTER>');
    pageObj.document.writeln('</TD></TR>');
    pageObj.document.writeln('<TR BGCOLOR="#FFFF99"><TD>&nbsp;</TD></TR>');
    pageObj.document.writeln('</TABLE>\n');

    pageObj.document.writeln('<!-- Advise the report info -->');
    pageObj.document.writeln('<BR><BR>');
    pageObj.document.writeln('<CENTER>');
    pageObj.document.writeln('<TABLE BORDER="4" CELLSPACING="4" CELLPADDING="5" WIDTH="75%">');
    pageObj.document.writeln('<TR>');
    pageObj.document.writeln('  <TD VALIGN="MIDDLE" ALIGN="MIDDLE">');
    pageObj.document.writeln('    <BR>Lookup information is being retrieved for: ' + currValue + '<BR><BR>');
    pageObj.document.writeln('    Please wait for just a moment.<BR><BR>');
    pageObj.document.writeln('  </TD>');
    pageObj.document.writeln('</TR>');
    pageObj.document.writeln('</TABLE></CENTER>');
    pageObj.document.writeln('<BR><BR><BR>\n');

    pageObj.document.writeln('</BODY>');
    pageObj.document.writeln('</HTML>\n');
    pageObj.document.close();
}

// WritePNSearchWindow() - Write out the desired web page
function WritePNSearchWindow( pageObj, arraydata, title, cKeyFld, cCurrVal) {

    pageObj.document.writeln('<HTML>\n<HEAD>');
    pageObj.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');
    pageObj.document.writeln('<META NAME="Author" CONTENT="Marvin Burt">');
    pageObj.document.writeln('<TITLE>' + title + ' Lookup</TITLE>\n');

    pageObj.document.writeln('<' + 'SCRIPT' + ' LANGUAGE="JavaScript">');

    pageObj.document.writeln('// Handle OK button click');
    pageObj.document.writeln('function handleOK() {');
    pageObj.document.writeln('    if (opener && !opener.closed) {\n');

    pageObj.document.writeln("        // Get our form's data");
    pageObj.document.writeln('        var retData = getFormData(document.Search)\n');

    pageObj.document.writeln("        // Now, call the main window's data loading function");
    pageObj.document.writeln('        opener.dialogWin.returnFunc(retData);');
    pageObj.document.writeln('    } else {');
    pageObj.document.write('        alert("You have closed the main window.\\n');
    pageObj.document.write('\\n');
    pageObj.document.writeln('No action will be taken on the choices in this dialog box.");');
    pageObj.document.writeln('    }');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Handle Cancel button click');
    pageObj.document.writeln('function handleCancel() {');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Extract the search variable and return it');
    pageObj.document.writeln('function getFormData(form) {');
    pageObj.document.writeln('    var nIndex = form.cSrchFld.selectedIndex;');
    pageObj.document.writeln('    var valueString = form.cSrchFld.options[nIndex].value;');
    pageObj.document.writeln('    return valueString');
    pageObj.document.writeln('}');
    pageObj.document.writeln('</' + 'SCRIPT>');
    pageObj.document.writeln('</HEAD>\n');

    pageObj.document.writeln('<BODY TEXT="#000000" BGCOLOR="#FFEEAA" LINK="#000099" VLINK="#000099" ALINK="#FF0000"');
    pageObj.document.writeln('    onLoad="if (opener) opener.blockEvents()"');
    pageObj.document.writeln('    onUnload="if (opener) opener.unblockEvents()">\n');

    pageObj.document.writeln('<CENTER>Select your choice from the list');
    pageObj.document.writeln('<FORM NAME="Search">\n');

    pageObj.document.writeln('<!-- The search options -->');
    pageObj.document.writeln('<select name="cSrchFld" size="15" onclick="handleOK();">');

    // We're passed a value, try to find it in the list
    nSeleRow = 0
    nCnt = 0;
    for (var i = 1; i < arraydata.length; i++) {

        // Is the current part number on file?
        if (arraydata[i].Fld1 == cKeyFld)  {

            // Alway mark the first hit
            nCnt = nCnt + 1;
            if (nCnt == 1) {
                nSeleRow = i;
            }

            // The part number matches the current value
            if (arraydata[i].Fld3 == cCurrVal)  {
                nSeleRow = i;
                break;
            }
        }
    }

    // Here we need to create our option values from the array
    var cLine = "";
    for (var i = 1; i < arraydata.length; i++) {

        // We want to create something that looks like
        //  <OPTION VALUE="X">search value
        if (arraydata[i].Fld1 == cKeyFld)  {
            cLine = '<option '

            // Mark the appropriate one selected
            if (nSeleRow == i) {
                cLine = cLine + 'selected '
            }

            // Add the rest of the stuff including our desired value
            cLine = cLine + 'value="' + i + '">' + arraydata[i].Fld2

            // Output this line
            pageObj.document.writeln(cLine);
        }
    }
    pageObj.document.writeln('</select><BR><BR>\n');

    pageObj.document.writeln('<DIV STYLE="text-align:right">');
    pageObj.document.writeln('<FORM>');
    pageObj.document.writeln('<INPUT TYPE="button" VALUE="Cancel" onclick="handleCancel();">');
    pageObj.document.writeln('&nbsp;&nbsp;');
    pageObj.document.writeln('<INPUT TYPE="button" VALUE="   OK   " onclick="handleOK();">');
    pageObj.document.writeln('&nbsp;&nbsp;');
    pageObj.document.writeln('</DIV>\n');

    pageObj.document.writeln('</FORM>');
    pageObj.document.writeln('</CENTER>');

    pageObj.document.writeln('</BODY>');
    pageObj.document.writeln('</HTML>\n');
    pageObj.document.close();
}

// WriteCAGEWindow() - Write out the desired web page
function WriteCAGEWindow( pageObj, title, cNSNcPN) {

    pageObj.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Final//EN">');
    pageObj.document.writeln('<HTML>');
    pageObj.document.writeln('<HEAD>');
    pageObj.document.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');
    pageObj.document.writeln('<TITLE>' + title + '</TITLE>\n');

    pageObj.document.writeln('<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">\n');

    pageObj.document.writeln('/************************* Required variable check **********************/\n');

    pageObj.document.writeln('// Empty() - Return true if the passed string is empty');
    pageObj.document.writeln('function Empty( strIn ) {\n');
    pageObj.document.writeln('    // If its length = 0 we can return quickly');
    pageObj.document.writeln('    if (strIn.length == 0)  {');
    pageObj.document.writeln('        return true;');
    pageObj.document.writeln('    }\n');
    pageObj.document.writeln('    // Otherwise, check all characters until we get the first non-space one');
    pageObj.document.writeln('    for (var nPosn = 0; nPosn < strIn.length; nPosn++)  {');
    pageObj.document.writeln('        if (strIn[nPosn] != " ") {');
    pageObj.document.writeln('            return false;');
    pageObj.document.writeln('        }');
    pageObj.document.writeln('    }\n');
    pageObj.document.writeln('    // Here it must be empty');
    pageObj.document.writeln('    return true;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// String.Left() - Return the leftmost part of a string        ');
    pageObj.document.writeln('function strLeft(nLen)                                         ');
    pageObj.document.writeln('{                                                              ');
    pageObj.document.writeln('    /*   Inputs: nLen = number of characters desired (0 = none)');
    pageObj.document.writeln('        Example: var s123 = "OneTwoThree";                     ');
    pageObj.document.writeln('                 var sOne = c123.Left(3)            // = "One" ');
    pageObj.document.writeln('    */                                                         ');
    pageObj.document.writeln('    return this.substring(0, nLen);                            ');
    pageObj.document.writeln('}                                                              ');
    pageObj.document.writeln('String.prototype.Left = strLeft                                ');

    pageObj.document.writeln('// String.Right() - Return the rightmost part of a string      ');
    pageObj.document.writeln('function strRight(nLen)                                        ');
    pageObj.document.writeln('{                                                              ');
    pageObj.document.writeln('    /*   Inputs: nLen = number of characters desired (0 = none)  ');
    pageObj.document.writeln('        Example: var s123 = "OneTwoThree";                       ');
    pageObj.document.writeln('                 var sOne = c123.Right(5)            // = "Three"');
    pageObj.document.writeln('    */                                                           ');
    pageObj.document.writeln('    var nPos = this.length - nLen;                               ');
    pageObj.document.writeln('    return this.substr(nPos, nLen);                              ');
    pageObj.document.writeln('}                                                                ');
    pageObj.document.writeln('String.prototype.Right = strRight                                ');

    pageObj.document.writeln('// String.StrAt() - Return the position of a string within a string');
    pageObj.document.writeln('function strStrAt(sFindStr)                                                   ');
    pageObj.document.writeln('{                                                                             ');
    pageObj.document.writeln('    /*   Inputs: sFindStr = the string to be found                            ');
    pageObj.document.writeln('        Returns: The string position where sFindStr is found (-1 if not there)');
    pageObj.document.writeln('        Example: var sStr = "ABCDABCD";                                       ');
    pageObj.document.writeln('                 nPosnD = sStr.StrAt("D");          // 4                      ');
    pageObj.document.writeln('           Note: Returns only the first instance of sFindStr in sStr          ');
    pageObj.document.writeln('    */                                                                        ');
    pageObj.document.writeln('    var nPosn = this.indexOf(sFindStr);                                       ');
    pageObj.document.writeln('    nPosn = nPosn + 1;                                                        ');
    pageObj.document.writeln('    return nPosn;                                                             ');
    pageObj.document.writeln('}                                                                             ');
    pageObj.document.writeln('String.prototype.StrAt = strStrAt                                             ');

    pageObj.document.writeln('// TrimAtSpace() - Return a string variable up to the first space             ');
    pageObj.document.writeln('function TrimAtSpace( strVar )  {                                             ');
    pageObj.document.writeln('    var nSpPosn = strVar.StrAt(" ")                                           ');
    pageObj.document.writeln('    if (nSpPosn)    {                                                         ');
    pageObj.document.writeln('        var retStr = strVar.Left(nSpPosn);                                    ');
    pageObj.document.writeln('    } else  {                                                                 ');
    pageObj.document.writeln('        var retStr = strVar;                                                  ');
    pageObj.document.writeln('    }                                                                         ');
    pageObj.document.writeln('    return retStr;                                                            ');
    pageObj.document.writeln('}                                                                             ');

    pageObj.document.writeln('// String.Upper() - Convert a string to uppercase');
    pageObj.document.writeln('function strUpper()                              ');
    pageObj.document.writeln('{                                                ');
    pageObj.document.writeln('    var sStr = this.toUpperCase();               ');
    pageObj.document.writeln('    return sStr;                                 ');
    pageObj.document.writeln('}                                                ');
    pageObj.document.writeln('String.prototype.Upper = strUpper                ');

    pageObj.document.writeln('// checkFormVar() - Make sure the search variable has an entry');
    pageObj.document.writeln('function checkFormVar( srchValue )  {                         ');
    pageObj.document.writeln('    if (Empty(srchValue))    {                                ');
    pageObj.document.writeln('        alert("At least one or two characters must be entered before a search will work.")');
    pageObj.document.writeln('        return false;                                         ');
    pageObj.document.writeln('    }                                                         ');
    pageObj.document.writeln('    return true;                                              ');
    pageObj.document.writeln('}                                                             ');

    pageObj.document.writeln('// String.RTrim() - Remove trailing spaces in a string                     ');
    pageObj.document.writeln('function strRTrim()                                                        ');
    pageObj.document.writeln('{                                                                          ');
    pageObj.document.writeln('    // Returns: A new string with all trailing whitespace removed.         ');
    pageObj.document.writeln('    var nPosn = this.length;                                               ');
    pageObj.document.writeln('    if (!this.IsWhite(nPosn))   {                                          ');
    pageObj.document.writeln('        return this;                                                       ');
    pageObj.document.writeln('    }                                                                      ');
    pageObj.document.writeln('    while ( this.IsWhite(--nPosn) ) ;                                      ');
    pageObj.document.writeln('    return this.substring(0, nPosn);                                       ');
    pageObj.document.writeln('}                                                                          ');
    pageObj.document.writeln('String.prototype.RTrim = strRTrim                                          ');

    pageObj.document.writeln('// String.LTrim() - Remove leading spaces in a string                      ');
    pageObj.document.writeln('function strLTrim()                                                        ');
    pageObj.document.writeln('{                                                                          ');
    pageObj.document.writeln('    // Returns: A new string with all leading whitespace removed.          ');
    pageObj.document.writeln('    var nPosn = 0;                                                         ');
    pageObj.document.writeln('    if (!this.IsWhite(nPosn+1))   {                                        ');
    pageObj.document.writeln('        return this;                                                       ');
    pageObj.document.writeln('    }                                                                      ');
    pageObj.document.writeln('    while ( this.IsWhite(++nPosn) );                                       ');
    pageObj.document.writeln('    return this.substring(nPosn-1);                                        ');
    pageObj.document.writeln('}                                                                          ');
    pageObj.document.writeln('String.prototype.LTrim = strLTrim                                          ');

    pageObj.document.writeln('// String.AllTrim() - Remove leading and trailing spaces in a string       ');
    pageObj.document.writeln('function strAllTrim()                                                      ');
    pageObj.document.writeln('{                                                                          ');
    pageObj.document.writeln('    // Returns: A new string with leading AND trailing whitespace removed. ');
    pageObj.document.writeln('    var Str = this.LTrim();                                                ');
    pageObj.document.writeln('    return Str.RTrim();                                                    ');
    pageObj.document.writeln('}                                                                          ');
    pageObj.document.writeln('String.prototype.AllTrim = strAllTrim                                      ');

    pageObj.document.writeln('// String.Substr() - Return a part of a string using our normal notation   ');
    pageObj.document.writeln('function strSubstr(nStart, nLength)                                        ');
    pageObj.document.writeln('{                                                                          ');
    pageObj.document.writeln('    /*   Inputs: nStart = starting position (1-based)                      ');
    pageObj.document.writeln('                 nLen (optional) = number of characters desired (0 = none) ');
    pageObj.document.writeln('       Examples: 1: var c123 = "OneTwoThree";                              ');
    pageObj.document.writeln('                    var cTwo = c123.Substr(4, 3)        // = "Two"         ');
    pageObj.document.writeln('                 2: var cFour = c123.Substr(12, 4)      // = ""            ');
    pageObj.document.writeln('    */                                                                     ');

    pageObj.document.writeln('    // We may not have the 2nd argument                                    ');
    pageObj.document.writeln('    var nLen = this.length;                                                ');
    pageObj.document.writeln('    if (arguments.length == 2)                                             ');
    pageObj.document.writeln('        nLen = nLength;                                                    ');

    pageObj.document.writeln('    // Handle trivial stuff first                                          ');
    pageObj.document.writeln('    if (nStart < 1 || nLen < 1 || nStart > this.length) {                  ');
    pageObj.document.writeln('        return "";                                                         ');
    pageObj.document.writeln('    }                                                                      ');

    pageObj.document.writeln('    /* Here we know that:                                                     ');
    pageObj.document.writeln('        nStart >= 1                                                           ');
    pageObj.document.writeln('        nStart <= this.length                                                 ');
    pageObj.document.writeln('        nLen >= 1                                                             ');
    pageObj.document.writeln('    */                                                                        ');

    pageObj.document.writeln('    // substring() is a built-in string method.  However, it wants a beginning');
    pageObj.document.writeln('    //  position (0-based)                                                    ');
    pageObj.document.writeln('    var nBegPosn = nStart - 1;          // 0 <= nBegPosn < this.length        ');

    pageObj.document.writeln('    /* substring() also wants an ending position (0-based) that is or position');
    pageObj.document.writeln('        after the last character to be included.  For example:                ');
    pageObj.document.writeln('                       Posn:  0123456789                                      ');
    pageObj.document.writeln('                        Str: "1234567890"                                     ');
    pageObj.document.writeln('            substring(0,9) = "123456789"                                      ');
    pageObj.document.writeln('        posn 9 points to "0" which is AFTER the last character.               ');
    pageObj.document.writeln('        If nBegPosn = 0 (nStart = 1) and nLen = 9,                            ');
    pageObj.document.writeln('           nEndPosn = 9 = nBegPosn + nLen                                     ');
    pageObj.document.writeln('    */                                                                        ');
    pageObj.document.writeln('    var nEndPosn = nBegPosn + nLen;                                           ');
    pageObj.document.writeln('    if (nEndPosn > this.length) {                                             ');
    pageObj.document.writeln('        nEndPosn = this.length;                                               ');
    pageObj.document.writeln('    }                                                                         ');
    pageObj.document.writeln('    var sStr = this.substring(nBegPosn, nEndPosn);                            ');
    pageObj.document.writeln('    return sStr;                                                              ');
    pageObj.document.writeln('}                                                                             ');
    pageObj.document.writeln('String.prototype.Substr = strSubstr                                           ');

    pageObj.document.writeln('// handleCAGE() - Handle the Submit CAGE button click');
    pageObj.document.writeln('function handleCAGE() {\n');

    pageObj.document.writeln('    // We must have a CAGE');
    pageObj.document.writeln('    var cVal = document.RequestCAGE.cCAGE.value;');
    pageObj.document.writeln('    if ( Empty(cVal) )  {');
    pageObj.document.writeln('        alert("CAGE code is required")');
    pageObj.document.writeln('        return false;');
    pageObj.document.writeln('    }\n');

    pageObj.document.writeln('    //  Do the call to CPS');
    pageObj.document.writeln('    GetName(cVal);\n');

    pageObj.document.writeln('    // Done');
    pageObj.document.writeln('    return true;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Get our cage name from CPS');
    pageObj.document.writeln('function GetName(cCAGE) {\n');

    pageObj.document.writeln('    var cNSNcPN = document.RequestCAGE.cNSNcPN.value;');
    pageObj.document.writeln('    url = currentDomain();');
    pageObj.document.writeln('    var cTaskUrl = url + "Fox/wc.dll?wTasks~GetNSNCageName~Params=" + cCAGE + "^" + cNSNcPN;\n');

    pageObj.document.writeln('    // Open a new window for the report');
    pageObj.document.writeln('    document.location.href = cTaskUrl;\n');

    pageObj.document.writeln('   return true;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// Goto the OEM RFQ page');
    pageObj.document.writeln('function gotoOemRFQ() {\n');

    pageObj.document.writeln('    var cNSNcPN = document.RequestCAGE.cNSNcPN.value;');
    pageObj.document.writeln('    url = currentDomain();');
    pageObj.document.writeln('    var cTaskUrl = url + "Fox/wc.dll?wTasks~OemRFQ~Params=" + cNSNcPN;\n');

    pageObj.document.writeln('    // Open a new window for the report');
    pageObj.document.writeln('    document.location.href = cTaskUrl;\n');

    pageObj.document.writeln('   return true;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('// handleCancel() - Handle the Cancel button click');
    pageObj.document.writeln('function handleCancel() {');
    pageObj.document.writeln('    //if (opener && !opener.closed) {');
    pageObj.document.writeln('    //    opener.dialogWin.returnFunc(0);');
    pageObj.document.writeln('    //}');
    pageObj.document.writeln('    window.close();');
    pageObj.document.writeln('    return false;');
    pageObj.document.writeln('}\n');

    pageObj.document.writeln('</SCRIPT>\n');

    pageObj.document.writeln('</HEAD>\n');

    pageObj.document.writeln('<BODY BACKGROUND="ali85sm.gif" TEXT="#000000" LINK="#000099" VLINK="#000099" ALINK="#FF0000"');
    pageObj.document.writeln('    onLoad="document.RequestCAGE.cCAGE.focus();');
    pageObj.document.writeln('    document.RequestCAGE.cCAGE.select();');
    pageObj.document.writeln('    if (opener) opener.blockEvents()"');
    pageObj.document.writeln('    onUnload="if (opener) opener.unblockEvents()">\n');

    pageObj.document.writeln('<!-- Top of Page Heading -->');
    pageObj.document.writeln('<TABLE WIDTH="95%" ALIGN=CENTER>');
    pageObj.document.writeln('    <TR>');
    pageObj.document.writeln('        <TD BGCOLOR="#000099" ALIGN=CENTER>');
    pageObj.document.writeln('            <FONT FACE="Arial Black" COLOR="#FFFFFF" SIZE=+2>');
    pageObj.document.writeln('            ' + title + '</FONT>');
    pageObj.document.writeln('        </TD>');
    pageObj.document.writeln('    </TR>');
    pageObj.document.writeln('</TABLE>\n');

    pageObj.document.writeln('<!-- Define our form -->');
    pageObj.document.writeln('<FORM NAME="RequestCAGE">\n');

    pageObj.document.writeln('<!-- All entries will be in one table -->');
    pageObj.document.writeln('<INPUT TYPE="hidden" NAME="cNSNcPN" VALUE="' + cNSNcPN + '">');
    pageObj.document.writeln('<CENTER>');
    pageObj.document.writeln('Usage Limitation:	For use by U.S. Government and their contractors and sub-contractors.');
    pageObj.document.writeln('<BR>');
    pageObj.document.writeln('<BR>');
    pageObj.document.writeln('To verify please enter your CAGE Code: <INPUT TYPE="text" SIZE="10" MAXLENGTH="10" NAME="cCAGE" VALUE="">');
    pageObj.document.writeln('<BR>');
    pageObj.document.writeln("<FONT SIZE=2>(Don't remember your CAGE, <A HREF='Javascript:onClick=gotoOemRFQ()'>click here</A>.)</FONT>");
    pageObj.document.writeln('</CENTER>');
    pageObj.document.writeln('<BR>\n');

    pageObj.document.writeln('<!-- Command buttons -->\n');
    pageObj.document.writeln('<TABLE WIDTH="40%" SUMMARY="" ALIGN=CENTER>');
    pageObj.document.writeln('    <TR>');
    pageObj.document.writeln('        <TD WIDTH="20%" ALIGN="MIDDLE">');
    pageObj.document.writeln('            <INPUT TYPE="button" VALUE="Submit CAGE" NAME="BUTTON" onClick="handleCAGE()">');
    pageObj.document.writeln('        </TD>');
    pageObj.document.writeln('        <TD WIDTH="60%"></TD>');
    pageObj.document.writeln('        <TD WIDTH="20%" ALIGN="MIDDLE">');
    pageObj.document.writeln('            <INPUT TYPE="button" VALUE=" Cancel " onClick="handleCancel()">');
    pageObj.document.writeln('        </TD>');
    pageObj.document.writeln('    </TR>');
    pageObj.document.writeln('</TABLE>\n');

    pageObj.document.writeln('</FORM>\n');

    pageObj.document.writeln('</BODY>');
    pageObj.document.writeln('</HTML>');
    pageObj.document.close();
}


/***************************** String Functions *************************/

// String.IsWhite() - Return true if passed character is whitespace
function strIsWhite( nPosn )
{
    // Returns: true if the character at the passed position is whitespace.
    // CAUTION: This function assumes 1-based string positions
    var cChar = this.charAt(nPosn-1);

    // Whitespace is: "\t\n\r "
    strWhite = "\t\n\r ";
    var nSpcPosn = strWhite.indexOf(cChar);
    return (nSpcPosn > -1);
}
String.prototype.IsWhite = strIsWhite

// String.RTrim() - Remove trailing spaces in a string
function strRTrim()
{
    // Returns: A new string with all trailing whitespace removed.
    //           (Whitespace is: "\t\n\r ")
    if (this.length == 0)  {
        return "";
    }
    var nPosn = this.length;
    if (!this.IsWhite(nPosn))   {
        return this;
    }
    brkPosn = -1;
    for (var nPosn = this.length; nPosn > 0; nPosn--)  {
        if (!this.IsWhite(nPosn)) {
            brkPosn = nPosn;
            break;
        }
    }
    if (brkPosn == -1)  {
        return "";
    }
    return this.substring(0, nPosn);
}
String.prototype.RTrim = strRTrim

// String.LTrim() - Remove leading spaces in a string
function strLTrim()
{
    // Returns: A new string with all leading whitespace removed.
    //           (Whitespace is: "\t\n\r ")
    if (this.length == 0)  {
        return "";
    }
    if (!this.IsWhite(1))   {
        return this;
    }
    brkPosn = -1;
    for (var nPosn = 1; nPosn <= this.length; nPosn++)  {
        if (!this.IsWhite(nPosn)) {
            brkPosn = nPosn;
            break;
        }
    }
    if (brkPosn == -1)  {
        return "";
    }
    return this.substring(brkPosn-1);
}
String.prototype.LTrim = strLTrim

// String.AllTrim() - Remove leading and trailing spaces in a string
function strAllTrim()
{
    // Returns: A new string with leading AND trailing whitespace removed.
    //           (Whitespace is: "\t\n\r ")
    if (this.length == 0)   {
        return "";
    }
    var Str = this.LTrim();
    return Str.RTrim();
}
String.prototype.AllTrim = strAllTrim

// String.Substr() - Return a part of a string using our normal notation
function strSubstr(nStart, nLength)
{
    /*   Inputs: nStart = starting position (1-based)
                 nLen (optional) = number of characters desired (0 = none)
       Examples: 1: var c123 = "OneTwoThree";
                    var cTwo = c123.Substr(4, 3)        // = "Two"
                 2: var cFour = c123.Substr(12, 4)      // = ""
    */

    // We may not have the 2nd argument
    var nLen = this.length;
    if (arguments.length == 2)
        nLen = nLength;

    // Handle trivial stuff first
    if (nStart < 1 || nLen < 1 || nStart > this.length) {
        return "";
    }

    /* Here we know that:
        nStart >= 1
        nStart <= this.length
        nLen >= 1
    */

    // substring() is a built-in string method.  However, it wants a beginning
    //  position (0-based)
    var nBegPosn = nStart - 1;          // 0 <= nBegPosn < this.length

    /* substring() also wants an ending position (0-based) that is or position
        after the last character to be included.  For example:
                       Posn:  0123456789
                        Str: "1234567890"
            substring(0,9) = "123456789"
        posn 9 points to "0" which is AFTER the last character.
        If nBegPosn = 0 (nStart = 1) and nLen = 9,
           nEndPosn = 9 = nBegPosn + nLen
    */
    var nEndPosn = nBegPosn + nLen;
    if (nEndPosn > this.length) {
        nEndPosn = this.length;
    }
    var sStr = this.substring(nBegPosn, nEndPosn);
    return sStr;
}
String.prototype.Substr = strSubstr

// String.Left() - Return the leftmost part of a string
function strLeft(nLen)
{
    /*   Inputs: nLen = number of characters desired (0 = none)
        Example: var s123 = "OneTwoThree";
                 var sOne = c123.Left(3)            // = "One"
    */
    return this.substring(0, nLen);
}
String.prototype.Left = strLeft

// String.Right() - Return the rightmost part of a string
function strRight(nLen)
{
    /*   Inputs: nLen = number of characters desired (0 = none)
        Example: var s123 = "OneTwoThree";
                 var sOne = c123.Right(5)            // = "Three"
    */
    var nPos = this.length - nLen;
    return this.substr(nPos, nLen);
}
String.prototype.Right = strRight

// String.StrAt() - Return the position of a string within a string
function strStrAt(sFindStr)
{
    /*   Inputs: sFindStr = the string to be found
        Returns: The string position where sFindStr is found (0 if not there)
        Example: var sStr = "ABCDABCD";
                 nPosnD = sStr.StrAt("D");          // 4
           Note: Returns only the first instance of sFindStr in sStr
    */
    if (this.length = 0)  {
        return -1;
    }
    var nPosn = this.indexOf(sFindStr);
    return nPosn + 1;
}
String.prototype.StrAt = strStrAt

// String.RtStrAt() - Return the rightmost position of a string within a string
function strRtStrAt(sFindStr)
{
    /*   Inputs: sFindStr = the string to be found
        Returns: The rightmost string position where sFindStr is found (-1 if
                    not there)
        Example: var sStr = "ABCDABCD";
                 nPosnD = sStr.RtStrAt("C");          // 7
           Note: Returns the rightmost instance of sFindStr in sStr
    */
    if (this.length = 0)  {
        return 0;
    }
    var nPosn = this.lastIndexOf(sFindStr);
    nPosn = nPosn + 1;
    return nPosn;
}
String.prototype.RtStrAt = strRtStrAt

// String.StrTran() - Replace all instances of sStr1 with sStr2 in this string
function strStrTran(sStr1, sStr2)
{
    /*   Inputs: sStr1 = the string to be replaced
                 sStr2 = the string to be substituted (may be empty)
        Returns: number of substitutions
    */

    // Handle all instances
    var sLeft = "";
    var sRight = this.Left(this.length);
    var nStrPosn = sRight.StrAt(sStr1);
    while (nStrPosn > 0)    {

        // Extract the leftmost part and add sStr2 to it
        if (nStrPosn == 1)
            sLeft = sLeft + sStr2;
        else
            sLeft = sLeft + sRight.Left(nStrPosn-1) + sStr2;

        // Extract the rightmost part
        nStrPosn = nStrPosn + sStr1.length;
        if (nStrPosn > sRight.length)  {
            sRight = "";
        } else {
            sRight = sRight.Substr(nStrPosn);
        }

        // Any more instances?
        var nStrPosn = sRight.StrAt(sStr1);
    }

    // Put them together
    var sStrOut = sLeft + sRight;
    return sStrOut;
}
String.prototype.StrTran = strStrTran

// String.Upper() - Convert a string to uppercase
function strUpper()
{
    var sStr = this.toUpperCase();
    return sStr;
}
String.prototype.Upper = strUpper

// String.PadLeft() - Pad a string on the left to the desired length
function strPadLeft(desLen, padChar)
{
    // The default pad character is a space
    if (!padChar)   {
        padChar = " ";
    }
    cStrOut = this;
    while(cStrOut.length < desLen)  {
        cStrOut = padChar + cStrOut;
    }
    return cStrOut;
}
String.prototype.PadLeft = strPadLeft

// String.makeLen() - Make a string the desired length
function strMakeLen(desLen)
{
    var sStr = this;
    while (sStr.length < desLen)  {
        sStr = sStr + "          ";
    }
    if (sStr.length > desLen)  {
        var sStr = sStr.Left(desLen);
    }
    return sStr;
}
String.prototype.makeLen = strMakeLen

// String.deCode() - Decode the contents of a string
function strDeCode(desLen)
{
    var sStr = this;

    // First we'll convert the + signs into spaces
    sStr = sStr.StrTran("+", " ");

    // Convert "&amp;" into "&"
    sStr = sStr.StrTran("&amp;", "&");
    return sStr;
}
String.prototype.deCode = strDeCode;

// Empty() - Return true if the passed string is empty
function Empty( strIn ) {

    // If it's length = 0 we can return quickly
    if (strIn.length == 0)  {
        return true;
    }

    // Otherwise, check all characters until we get the first non-space one
    for (var nPosn = 0; nPosn < strIn.length; nPosn++)  {
        if (strIn[nPosn] != ' ') {
            return false;
        }
    }

    // Here it must be empty
    return true;
}

// EmptyN() - Return true if the passed string varible = 0
function EmptyN( strNumIn ) {

    // If the string is empty, the number must also be empty
    if (Empty(strNumIn)) {
        return true;
    }

    // Convert the string to a number
    var numIn = makeFNumb(strNumIn);
    return (numIn == 0);
}

// TrimAtSpace() - Return a string variable up to the first space
function TrimAtSpace( strVar )  {
    var nSpPosn = strVar.StrAt(" ")
    if (nSpPosn)    {
        var retStr = strVar.Left(nSpPosn);
    } else  {
        var retStr = strVar;
    }
    return retStr;
}

// extrToken() - Extract and return parts of a string around a token
function extrToken(strIn, token)
{
    // Split strIn at the 1st instance of a token into an object containing:
    //  .fragment - a string fragment UP TO but not including the token
    //  .remainder - the remainder of the string past the token
    var str2Chk = strIn;
    var tokenPosn = str2Chk.StrAt(token);
    if (tokenPosn == 0)   {
        var cFrag = strIn;
        str2Chk = "";
    } else {
        cFrag = str2Chk.Left(tokenPosn-1);
        if (tokenPosn+1 > str2Chk.length)  {
            str2Chk = "";
        } else {
            str2Chk = str2Chk.Substr(tokenPosn+1);
        }
    }
    var retObj = new Object();
    retObj.fragment = cFrag;
    retObj.remainder = str2Chk;
    return retObj;
}

// between() - Return true if a test value is between min and max values
function between(xTestValue, xMinValue, xMaxValue) {
    return (xTestValue >= xMinValue && xTestValue <= xMaxValue);
}

/***************************** Other Functions **************************/

// checkFormVar() - Make sure the search variable has an entry
function checkFormVar( srchValue )  {
    if (Empty(srchValue))    {
        alert("At least one or two characters must be\n" +
          "entered before a search will work.")
        return false;
    }
    return true;
}

// Generic array constructor
function LoadChoice( cFld1, cFld2, cFld3, cFld4, cFld5, cFld6, cFld7,
  cFld8, cFld9, cFld10, cFld11, cFld12, cFld13, cFld14, cFld15, cFld16,
  cFld17, cFld18, cFld19, cFld20, cFld21, cFld22) {
  this.Fld1 = cFld1;
  if (cFld2 != null) {
    this.Fld2 = cFld2;
    if (cFld3 != null)  {
      this.Fld3 = cFld3;
      if (cFld4 != null)  {
        this.Fld4 = cFld4;
        if (cFld5 != null)  {
          this.Fld5 = cFld5;
          if (cFld6 != null)  {
            this.Fld6 = cFld6;
            if (cFld7 != null)  {
              this.Fld7 = cFld7;
              if (cFld8 != null)  {
                this.Fld8 = cFld8;
                if (cFld9 != null)  {
                  this.Fld9 = cFld9;
                  if (cFld10 != null)  {
                    this.Fld10 = cFld10;
                    if (cFld11 != null)  {
                      this.Fld11 = cFld11;
                      if (cFld12 != null)  {
                        this.Fld12 = cFld12;
                        if (cFld13 != null)  {
                          this.Fld13 = cFld13;
                          if (cFld14 != null)  {
                            this.Fld14 = cFld14;
                            if (cFld15 != null)  {
                              this.Fld15 = cFld15;
                              if (cFld16 != null)  {
                                this.Fld16 = cFld16;
                                if (cFld17 != null)  {
                                  this.Fld17 = cFld17;
                                  if (cFld18 != null)  {
                                    this.Fld18 = cFld18;
                                    if (cFld19 != null)  {
                                      this.Fld19 = cFld19;
                                      if (cFld20 != null)  {
                                        this.Fld20 = cFld20;
                                        if (cFld21 != null)  {
                                          this.Fld21 = cFld21;
                                          if (cFld22 != null)  {
                                            this.Fld22 = cFld22;
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

// makeFNumb() - Convert a string to floating point number; make NaNs = 0
function makeFNumb( cExpr )   {

    // Convert the string to a floating point expression, base 10.  Get rid
    //  of all commas first.
    var strExpr = "" + cExpr
    strExpr = strExpr.StrTran(",", "");
    var fExpr = parseFloat(strExpr, 10);

    // If it's Not a Number, make it 0
    if (isNaN(fExpr))   {
        fExpr = 0.0;
    }
    return fExpr;
}

// makeINumb() - Convert a string to integer number; make NaNs = 0
function makeINumb( cExpr )   {

    // Convert the string to an integer, base 10  Get rid of all commas first
    var strExpr = "" + cExpr
    strExpr = strExpr.StrTran(",", "");
    var iExpr = parseInt(strExpr, 10);

    // If it's Not a Number, make it 0
    if (isNaN(iExpr))   {
        iExpr = 0;
    }
    return iExpr;
}

// formatNum() - Generic positive number decimal formatting function
function formatNum(expr, decplaces, addCommas) {

	// Raise incoming value by power of 10 times the number of decimal places;
    // round to an integer; convert to string
    var strRaw = "" + RoundOff(expr, decplaces)

	// Establish location of decimal point
    var decpoint = strRaw.indexOf(".") + 1;

    // Put in the decimal point if we need to
    if (decpoint == 0)  {
        var strDec = strRaw + ".";
        decpoint = strDec.indexOf(".") + 1;
    } else {

        // Preface with a 0 if we start with the decimal point
        if (decpoint == 1)  {
            var strDec = "." + strRaw;
            decpoint = 2;
        } else {
            var strDec = strRaw;
        }
    }

    // Add 0s to make sure we have enought decimal places
    nDecimals = strDec.length - decpoint;
    var nDecNeeded = decplaces - nDecimals;
    for (var i=1; i <= nDecNeeded; i++)  {
        strDec = strDec + "0";
    }

        // Do we need to put in commas
    if (addCommas && decpoint > 4)   {

        // How many commas do we need?
        var nCommas = parseInt((decpoint-1) / 3);

        // Add each comma that we need
        for (var i=1; i<=nCommas; i++)  {

            // Where does this comma go
            var nPosn = decpoint - 1 - (i * 3);

            // Put in the comma
            strDec = strDec.Left(nPosn) + ',' + strDec.Substr(nPosn+1);
        }
    }
    return strDec;
}

// RoundOff() - Round off a number to the desired number of decimal places
function RoundOff( nNumVar, nDecPlcs )  {

	// Raise the incoming value by power of 10 times the decimal places
    var nPower = Math.pow(10,nDecPlcs);
    var nNumb = nNumVar * nPower;
    var bIsNeg = (nNumVar < 0);

    // How do we want to change this integer?  First, get the remainder
    var intNumb = Math.floor(nNumb)
    var nRemainder = nNumb - intNumb;

    // Is this an odd or even number?
    nChgdInt = Math.floor(intNumb / 2) * 2;

    // Even numbers will be unchanged; Odd numbers will be smaller
    var bIsEven = (nChgdInt == intNumb ? true : false);

    // Now calculate the delta we'll use to change the number
    var nDelta = 0.5
    if (nRemainder == 0.500000 && bIsEven)   {
        var nDelta = 0
    }
    if (bIsNeg) {
        nDelta = nDelta * -1;
    }

    // Add the delta, take the integer, divide by the power, and return.
    nNumb = Math.floor( nNumb + nDelta);
    return (nNumb / nPower);
}

// RoundUp() - Round a number up to the desired number of decimal places
function RoundUp( nNumVar, nDecPlcs )  {

	// Raise the incoming value by power of 10 times the decimal places
    var nPower = Math.pow(10,nDecPlcs);
    var nNumb = nNumVar * nPower;

    // Get the remainder
    var intNumb = Math.floor(nNumb)
    var nRemainder = nNumb - intNumb;

    // If there is any remainder, we increment the integer; otherwise we
    //  leave it alone
    if (nRemainder > 0) {
        intNumb = intNumb + 1;
    }

    // Done
    return (intNumb / nPower);
}

// Add2Msg() - Add the passed string to a message prefacing with "," if needed
function Add2Msg(str2Add, strMsg)  {
    var retMsg = strMsg;
    if (!Empty(strMsg)) {
        retMsg = retMsg + ", ";
    }
    return retMsg + str2Add;
}

// Global variable defining the form variable called for the search
var formSrchVar = null;
var srchArray = null;

// setSearch() - Generic function to save the Full Search results
function setSearch( ndxArray ) {

    // Note that we're in the process of closing
    SrchWinClosing = true;

    // Load our variable(s) from the array
    if (ndxArray > 0)   {
        formSrchVar.value = srchArray[ndxArray].Fld1;

        // Clear the search variable and array fields
        formSrchVar = null;
        srchArray = null;
    }
}

// saveSearch() - Generic function to save the Partial Search results
function saveSearch( seleValue ) {

    // Note that we're in the process of closing
    SrchWinClosing = true;

    // Save our search results
    formSrchVar.value = seleValue;

    // Clear the search variable field
    formSrchVar = null;
}

// clearIDField() - Clear the ID field as a manual search entry was made
function clearIDField() {
    document.frmEntries.cSrchID.value = "";
}

// checkLookup() - Make sure there's something in the lookup field
function checkLookup(chkVar, srchNoun) {

    // If it's empty, we can't look it up
    if (Empty(chkVar.value)) {
        var msg = "Nothing has been entered in the " + srchNoun + "field.";
        alert(msg);
        return false;
    }
    return true;
}

// getRadioValue() - Return the value of the whichever radio button is checked
function getRadioValue(oFrmVar, btnCount)   {

    // For radio buttons, all buttons have the same name.  So, oFrmVar is
    //  the radio button object passed like form.cCageType.

    // Look thru all values
    for (x = 0; x < btnCount; x++)  {
        if (oFrmVar[x].checked) {
            return oFrmVar[x].value;
        }
    }
    return false;
}

// updateSelectObj() - Update our select dropdown
function updateSelectObj( oObj, aRA, currEntry)   {

    // Check our parameters
    if (!currEntry)  currEntry = "";

    // Set our variables
    var isIE = (Browser.Left(2) == "ie");
    while (oObj.length > 0) {
        oObj.remove(0);
    }

    // Update the object
    for (var j = 1; j < aRA.length; j++) {

        // Create a new option
        var newOpt = document.createElement("option");
        var cValue = aRA[j].Fld1;
        newOpt.text = aRA[j].Fld2;
        newOpt.value = cValue;
        if (isIE)   {
            oObj.add(newOpt);
        } else {
            oObj.add(newOpt, null);
        }
        if (cValue == currEntry) {
            oObj.selectedIndex = j-1;
        }
    }

    // Done
    return true;
}

// getSelectedValue() - Define our variable from dropdown
function getSelectedValue(seleVar)   {

    // Get what is selected
    var seleStr = ""
    if (seleVar)    {
        for (var i = 0; i < seleVar.length; i++)    {
            if (seleVar.options[i].selected)    {
                var cVal = seleVar.options[i].value
                if (!Empty(cVal) ) {
                    seleStr = cVal
                    break;
                }
            }
        }
    }

    // Now return it
    return seleStr;
}

// isDate() - Date field validation (called by other validation functions that specify minYear/maxYear)
function isDate(gField,minYear,maxYear,minDays,maxDays) {
	var inputStr = gField.value;

	// convert hyphen delimiters to slashes
	while (inputStr.indexOf("-") != -1) {
		inputStr = replaceString(inputStr,"-","/")
	}
	var delim1 = inputStr.indexOf("/")
	var delim2 = inputStr.lastIndexOf("/")
	if (delim1 != -1 && delim1 == delim2) {
		// there is only one delimiter in the string
		alert("The date entry is not in an acceptable format.\n\nYou can enter dates in the following formats: mmddyyyy, mm/dd/yyyy, or mm-dd-yyyy.  (If the month or date data is not available, enter \'01\' in the appropriate location.)")
		gField.focus()
		gField.select()
		return false
	}
	if (delim1 != -1) {
		// there are delimiters; extract component values
		var mm = parseInt(inputStr.substring(0,delim1),10)
		var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10)
	} else {
		// there are no delimiters; extract component values
		var mm = parseInt(inputStr.substring(0,2),10)
		var dd = parseInt(inputStr.substring(2,4),10)
		var yyyy = parseInt(inputStr.substring(4,inputStr.length),10)
	}
	if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {
		// there is a non-numeric character in one of the component values
		alert("The date entry is not in an acceptable format.\n\nYou can enter dates in the following formats: mmddyyyy, mm/dd/yyyy, or mm-dd-yyyy.")
		gField.focus()
		gField.select()
		return false
	}
	if (mm < 1 || mm > 12) {
		// month value is not 1 thru 12
		alert("Months must be entered between the range of 01 (January) and 12 (December).")
		gField.focus()
		gField.select()
		return false
	}
	if (dd < 1 || dd > 31) {
		// date value is not 1 thru 31
		alert("Days must be entered between the range of 01 and a maximum of 31 (depending on the month and year).")
		gField.focus()
		gField.select()
		return false
	}

	// validate year, allowing for checks between year ranges
	// passed as parameters from other validation functions
	if (yyyy < 100) {
		// entered value is two digits, which we allow for 1930-2029
		if (yyyy >= 30) {
			yyyy += 1900
		} else {
			yyyy += 2000
		}
	}

	var today = new Date()
  	if (!minYear) {
  		// function called with specific day range parameters
  		var dateStr = new String(monthDayFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy)
  		var testDate = new Date(dateStr)
  		if (testDate.getTime() < (today.getTime() + (minDays * 24 * 60 * 60 * 1000))) {
  			alert("The most likely range for this entry begins " + minDays + " days from today.")
  		}
  		if (testDate.getTime() > today.getTime() + (maxDays * 24 * 60 * 60 * 1000)) {
  			alert("The most likely range for this entry ends " + maxDays + " days from today.")
  		}
    } else if (minYear && maxYear) {
		// function called with specific year range parameters
		if (yyyy < minYear || yyyy > maxYear) {
			// entered year is outside of range passed from calling function
			alert("The most likely range for this entry is between the years " + minYear + " and " + maxYear + ".  If your source data indicates a date outside this range, then enter that date.")
		}
	} else {
		// default year range (now set to (this year - 100) and (this year + 25)
		var thisYear = today.getYear()
		if (thisYear < 100) {
			thisYear += 1900
		}
		if (yyyy < minYear || yyyy > maxYear) {
			alert("It is unusual for a date entry to be before " + minYear + " or after " + maxYear + ". Please verify this entry.")
		}
	}
	if (!checkMonthLength(mm,dd)) {
		gField.focus()
		gField.select()
		return false
	}
	if (mm == 2) {
		if (!checkLeapMonth(mm,dd,yyyy)) {
			gField.focus()
			gField.select()
			return false
		}
	}
	// put the Informix-friendly format back into the field
	gField.value = monthDayFormat(mm) + "/" + monthDayFormat(dd) + "/" + yyyy
	return true
}

// monthDayFormat() - Check the entered month or day size
function monthDayFormat(nValue) {
    var cValue = "" + nValue;
	if (cValue.length == 1) {
		cValue = "0" + cValue;
	}
	return cValue;
}

// checkMonthLength() - Check the entered month for too high a value
function checkMonthLength(mm,dd) {
	var months = new Array("","January","February","March","April","May","June","July","August","September","October","November","December")
	if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
		alert(months[mm] + " has only 30 days.")
		return false
	} else if (dd > 31) {
		alert(months[mm] + " has only 31 days.")
		return false
	}
	return true
}

// checkLeapMonth() - Check the entered February date for too high a value
function checkLeapMonth(mm,dd,yyyy) {
	if (yyyy % 4 > 0 && dd > 28) {
		alert("February of " + yyyy + " has only 28 days.")
		return false
	} else if (dd > 29) {
		alert("February of " + yyyy + " has only 29 days.")
		return false
	}
	return true
}

// ButtonHit() - Checks a field and empty it if its not empty
function ButtonHit(oButtonObj, callFunc, cOtherID)  {

    // Disable the button if its enabled
    if (!hasClass(oButtonObj, "disabled")) {
        addClass(oButtonObj, "disabled");

        // Do same for another button on the page
        if (cOtherID)  {
            var oOther = idObj(cOtherID)
            if (!hasClass(oOther, "disabled")) {
                addClass(oOther, "disabled");
            }
        }

        // Call the function
        bRetVal = callFunc();
        oTmpButtonObj = oButtonObj;
    }
}


