///////////////////////////////////////////////////////////////////////////////
// Product        : fcClient
//
// Series         : First Choice Web Series(tm)
//
// Name           : client_utility.js
//
// Description    : Common Cient Side JavaScript Utility Functions
//
// Author         : First Choice Software, Inc.
//                  8900 Business Park Drive
//                  Austin, TX  78759
//                  (512) 418-2905
//                  EMAIL: support@fchoice.com
//                  www.fchoice.com
//
// Platforms      : This version supports Clarify 4.5 and later
//
// Copyright (C)  2002 First Choice Software, Inc.
// All Rights Reserved.
///////////////////////////////////////////////////////////////////////////////

/**  VALIDATION CODE  **/

function Validate() {

  var bError = false;
  var strMsg = 'Please enter values for the following required fields:\n';
  var objInput;
  var strValue;
  var i;

  // iterate through all of the objects in the form marked as required
  // and validate the objects according to type
  //
  // getElementsByTagName with a wildcard is only supported on IE6up
  // not on IE5.5
  // so, if we get an empty array back from the wildcard search,
  // then use the old IE methods (document.all)

  all_fields = document.getElementsByTagName("*");
  var element_count = all_fields.length;
  var bOldBrowser = false;

  if (element_count <= 0){
     element_count = document.all.length;
     var bOldBrowser = true;
   }

  for(i = 0;i < element_count; i++) {
                //objInput = all_fields[i];
                if (bOldBrowser) {
                         objInput = document.all[i];
                } else {
                         objInput = all_fields[i];
                }
    if( (objInput.style.required == 'true') || (objInput.getAttribute('required') == 'true') ) {
      switch(objInput.type) {
        // validate text and hidden boxes
        case 'text':
        case 'input':
        case 'textarea':
        case 'hidden':
        case 'password':
          try {
            strValue = objInput.value;
            // remove spaces
            strValue = strValue.replace(/ /g, '');
            if(strValue.length == 0 && objInput.getAttribute('errShow').length > 0) {
              strMsg += '    -- ' + objInput.getAttribute('errShow') + '\n';
              bError = true;
            }
          } catch(e) { }
          break;
        // validate dropdown boxes
        case 'select-one':
          try {
            strValue = objInput.options[objInput.selectedIndex].innerHTML;
            if((strValue.length == 0 || strValue.slice(0,14).toUpperCase() == 'PLEASE SPECIFY') && (objInput.getAttribute('errShow').length > 0)) {
              strMsg += '    -- ' + objInput.getAttribute('errShow') + '\n';
              bError = true;
            }
          } catch(e) { }
          break;
      }
    }
  }

  if(bError) {
    alert(strMsg);
    return false;
  } else {
    return true;
  }
}

function ColorRequired() {

  var i;
  var required_fields  = new Array();
  var required_fields2 = new Array();
  var the_color = GetRequiredColor();
  //var the_color = "ffff99";

  // iterate through all of the objects in the form marked as required
  // and set the background color to yellow for text boxes

  //getElementsByTagName with a wildcard is only supported on IE6up
  //not on IE5.5
  //so, if we get an empty array back from the wildcard search,
  //then use the old IE methods (document.all)

  required_fields = document.getElementsByTagName("*");
  var element_count = required_fields.length;
  var bOldBrowser = false;

  if (element_count <= 0){
     element_count = document.all.length;
     var bOldBrowser = true;
   }

  for(i = 0;i < element_count; i++) {
    try {
      if (bOldBrowser) {
         objInput = document.all[i];
      } else {
         objInput = required_fields[i];
      }
      if(objInput.getAttribute('required') == 'true'){
        objInput.style.backgroundColor = the_color;
      }
      if(objInput.style.required == 'true'){
        objInput.style.backgroundColor = the_color;
      }
    } catch(e) { }
  }
//
//If the opener is find_by_id, close it
//
//This may seem like a weird place for this code (and it is).
//However, this color required function is common to all objects,
//so by adding the following code here, its automatically executed
//by all other object windows.
  try {
     if (window.opener.name == 'find_by_id'){
              window.opener.close();
     }
  } catch (e) {}

}

/**  END VALIDATION CODE  **/


/**  DIRTY FLAG CODE  **/

function AttachChangeEvent() {

  var i;

  //getElementsByTagName with a wildcard is only supported on IE6up
  //not on IE5.5
  //so, if we get an empty array back from the wildcard search,
  //then use the old IE methods (document.all)

  all_fields = document.getElementsByTagName("*");

  var element_count = all_fields.length;
  var bOldBrowser = false;

  if (element_count <= 0){
     element_count = document.all.length;
     var bOldBrowser = true;
   }

  for(i = 0;i < element_count; i++) {
    try {
      if (bOldBrowser) {
         objInput = document.all[i];
      } else {
         objInput = all_fields[i];
      }

      var objId = objInput.Id;
      switch(objInput.type) {
        // validate text and hidden boxes
        case 'text':
        case 'textarea':
        case 'hidden':
        case 'password':
        case 'radio':
        case 'checkbox':
        case 'input':
        case 'select-one':
          //If they have set no_dirty=true, then dont set the dirty bit
          if (objInput.getAttribute('no_dirty') != "true" ){
             objInput.attachEvent('onchange', SetDirty);
             //document.getElementById(objId).setAttribute('onchange', 'javascript:SetDirty()');
          break;
          }
      }
    } catch(e) { }
  }

//onkeypress event handler
  document.onkeypress = event_handler;

//on before unload eventhandler
  window.onbeforeunload=CheckDirty;

//onkeydown event handler
  document.onkeydown=onkeydown_event_handler;

}

//events for window manager
  window.attachEvent('onload', DoWindowOnLoad);
  window.attachEvent('onunload', DoWindowOnUnLoad);

function DoWindowOnLoad(){
   // try to find the console screen by navigating through the
   // opening windows until it is found
   try {
     var winConsole = window.opener;
     var bFound = false;

     while(!bFound && winConsole != null) {
       if(winConsole.name == 'console') {
         winConsole.frames[2].AddWinToArray(this);
         bFound = true;
       } else {
         // set the window to either a parent or an opener
         winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
       }
     }
   } catch(e) { }
}


function DoWindowOnUnLoad(){
   try {
     var winConsole = window.opener;
     var bFound = false;

     while(!bFound && winConsole != null) {
       if(winConsole.name == 'console') {

       if(window.screenTop>10000){
         winConsole.frames[2].CloseOneWindow(this);
       }else{
         //this is a save (post) operation - update the open window list
         winConsole.frames[2].AddWinToArray(this);
       }


         bFound = true;
       } else {
         // set the window to either a parent or an opener
         winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
       }
     }
   } catch(e) { }
}

function OpenHelpPage(){
  //See if there is help available for this page
  //The help page will be stored in a hidden field called help_page
  //If not, see if the parent page has a help page defined.
  //If there is, then open this page
  //Else, tell the user there's no help available for this page
  //Don't post the default browser help

  the_elem = document.getElementById('help_page');
  if (!the_elem){
    the_elem = parent.document.getElementById('help_page');
  }

  if (the_elem){
     var help_page = the_elem.value;
     if (help_page.length > 0){
        var nHeight = 500;
        var nWidth = 700;
        var nTop = (screen.height / 2) - (nHeight / 2);
        var nLeft = (screen.width / 2) - (nWidth / 2);
        var strProp = 'menubars=no,toolbars=no,scrollbars=yes,status=no,resizable=no,width=' + nWidth + ',height=' + nHeight + ',top=' + nTop + ',left=' + nLeft;
        var win = window.open(help_page,'',strProp);
        win.focus();
        return false;
     }
  }

    alert('No help available for this page');
    return false;
}

function SetDirty() {
  try {
    document.getElementById('dirty_flag').value = '1';
  } catch(e) { }
}

/**  END DIRTY FLAG CODE  **/


/**  MENU CODE  **/

// Global variables

var activeMenuID = '';  // the id of the menu which is currently active
var timer = null;  // timeout variable

//If they press F1, call our custom help function
document.onhelp=OpenHelpPage;


// Hides a menu from view
function hideMenu(id) {

  var the_menu = document.getElementById(id);
  if(the_menu) {
    the_menu.style.visibility='hidden';
    the_menu.style.zIndex = 1;
  }

  var find_by_id = 'sel_find_by_id';
  if (document.getElementById(find_by_id)){
     document.getElementById(find_by_id).style.visibility = 'visible';
  }
}

// Shows a menu and hides a previously open menu
function showMenu(id) {
  if (activeMenuID != '' && activeMenuID != id)
    hideMenu(activeMenuID);

  var the_menu = document.getElementById(id);

  if (the_menu) {
    the_menu.style.visibility='visible';
    the_menu.style.zIndex=3;
  }
  clearTimeout(timer);
  activeMenuID = id;

  var find_by_id = 'sel_find_by_id';
  if (document.getElementById(find_by_id)){
     document.getElementById(find_by_id).style.visibility = 'hidden';
  }
}

// Hides menu after a specified delay; keeps menus from disappearing too rapidly
function startTimer(id) {
  timer = setTimeout('hideMenu(\'' + id + '\')', 2000);
}

// stops the hide timer
function onItem(id) {
  clearTimeout(timer);
}

// starts the hide timer
function offItem(id) {
  startTimer(id);
}

/**  END MENU CODE  **/



/**  GENERAL  **/


//room
// update the room list
function update_room(type,obj_id,id) {
try {
  var winConsole = window.opener;
  var bFound = false;

obj_id = unescape(obj_id) + '';
id = unescape(id) + '';

  if(id!='0'){


    while(!bFound && winConsole != null) {

      if(winConsole.name == 'console') {
          var console_left = winConsole.frames['console_left'];
        if (console_left){
            var newValue = type + ' ' + unescape(id) + '|' + type + '|' + obj_id;
            param = newValue.split("|");

            //Get the Room Select List
            sel_room = console_left.document.getElementById('sel_room');

            var name = param[0];
            idx = name.indexOf(' obsolete ');
            if(idx > 0) {
              name = name.substr(0,idx);
              obs = true;
            } else {
              obs = false;
            }

            // remove existing occurrence of item
            for (i=0; i< sel_room.options.length; i++) {
//              if(sel_room.options[i].text==name) {
              if(unescape(sel_room.options[i].text)==unescape(name)) {
                sel_room.options[i] = null;
                i=sel_room.options.length;
              }
            }

            // add new occurrence of item if not obsolete(extra param)
            if(!obs) {
              if(param.length == 3) {
                oOption = console_left.document.createElement("OPTION");
                oOption.text = unescape(param[0]);
                oOption.value = unescape(param[1]) + '|' + unescape(param[2]);
                oOption.selected = true;

                //Add the new option to the top of the list
                //IE & NN use the 2nd param to .add differently
                //See DHTML Reference book
                if (document.all){
                  sel_room.add (oOption,0);
                }else {
                 var first_option = sel_room[0];
               sel_room.add (oOption,first_option);
             }
           }
         }

           //Remove any over the limit
           limit_field = console_left.document.getElementById('limit');
           if (limit_field) {limit=limit_field.value;}
           else {limit = 10;}
           while (sel_room.length > limit) {
             sel_room.remove(limit)
           }

          }
        bFound = true;
      } else {
        // set the window to either a parent or an opener
        winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
      }
    }
  }

} catch(e) {return;}

}

//room


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater")
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);

    //gms 5/1/03
    var is_nav7 = (is_nav && (agt.indexOf("netscape/7.0") != -1) );
    var is_nav7up = (is_nav && (agt.indexOf("netscape/7") != -1) );

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1);

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));

//--> end hide JavaScript


function FormatSeconds(nSeconds) {

  var nDays;
  var nHours;
  var nMinutes;

  // Break the seconds into days, hours and minutes
  nDays = Math.floor(nSeconds / (60 * 60 * 24));
  nHours = Math.floor((nSeconds / (60 * 60)) - (nDays * 24));
  nMinutes = Math.floor((nSeconds / 60) - (nDays * 24 * 60) - (nHours * 60));

  // add the leading zeros

  if(nDays <= 9) {
    nDays = '00' + nDays;
  } else if(nDays >= 10 && nDays <= 99) {
    nDays = '0' + nDays;
  }

  if(nHours <= 9) {
    nHours = '0' + nHours;
  }

  if(nMinutes <= 9) {
    nMinutes = '0' + nMinutes;
  }

  // return the formatted values
  return nDays + ' ' + nHours + ':' + nMinutes;

}


function isInteger(val) {
        var digits="1234567890";
        for (var i=0; i < val.length; i++) {
                if (digits.indexOf(val.charAt(i))==-1) { return false; }
                }
        return true;
        }

///////////////////////////////////////////////////////////////////////////////////
//Function to trim leading and trailing spaces
///////////////////////////////////////////////////////////////////////////////////
function FCTrim(strItem) {
  strItem = strItem.replace(/^\s*/, '').replace(/\s*$/, '');
  return strItem;
}



function event_handler(evt) {

  var r = '';
  if (document.all) {
    r += event.ctrlKey ? 'Ctrl-' : '';
    r += event.altKey ? 'Alt-' : '';
    r += event.shiftKey ? 'Shift-' : '';
    r += event.keyCode;

    if (event.ctrlKey && event.shiftKey){
       switch(event.keyCode){
       case 1:
         // ctrl-shift-a = Accept
         try { document.getElementById('accept').click(); } catch (e) { }
         break;
       case 4:
         // ctrl-shift-d = Dispatch
         try { document.getElementById('dispatch').click(); } catch (e) { }
         break;
       case 5:
         // ctrl-shift-e = Log Email
         try { document.getElementById('log_email').click(); } catch (e) { }
         break;
       case 6:
         // ctrl-shift-f = Log Research
         try { document.getElementById('log_research').click(); } catch (e) { }
         break;
       case 7:
         // ctrl-shift-g = Change Status
         try { document.getElementById('chg_status').click(); } catch (e) { }
         break;
       case 8:
         // ctrl-shift-h = Log Phone
         try { document.getElementById('log_phone').click(); } catch (e) { }
         break;
       case 9:
         // ctrl-shift-i = Find By ID
         setFocusToConsoleLeftControl('txt_find_by_id');
         break;
       case 11:
         // ctrl-shift-k = Close Case
         try { document.getElementById('close').click(); } catch (e) { }
         break;
       case 12:
         // ctrl-shift-l = Activity Log
         try { document.getElementById('activity_log').click(); } catch (e) { }
         break;
       case 13:
         // ctrl-shift-m = Move
         try { document.getElementById('move').click(); } catch (e) { }
         break;
       case 14:
         // ctrl-shift-n = Done
         try { document.getElementById('done').click(); } catch (e) { }
         break;
       case 15:
         // ctrl-shift-o = Log Notes
         try { document.getElementById('log_notes').click(); } catch (e) { }
         break;
       case 16:
         // ctrl-shift-p = Print
         try { document.getElementById('print').click(); } catch (e) { }
         break;
       case 17:
         // ctrl-shift-q = Quit/Logoff
         clickConsoleControl('logout');
         break;
       case 19:
         // ctrl-shift-s = Save
         try { document.getElementById('save').click(); } catch (e) { }
         break;
       case 25:
         // ctrl-shift-y = Yank
         try { document.getElementById('yank').click(); } catch (e) { }
         break;

    } //end of switch
   }


    if (event.ctrlKey){
       switch(event.keyCode){
       case 10:
         // ctrl-enter = Send (used on eeo page)
         try { document.getElementById('send').click(); } catch (e) { }
         break;
       } //end of switch
   }

  }
  else if (document.getElementById) {
    r += evt.ctrlKey ? 'Ctrl-' : '';
    r += evt.altKey ? 'Alt-' : '';
    r += evt.shiftKey ? 'Shift-' : '';
    r += evt.charCode;
  }
  else if (document.layers) {
    r += evt.modifiers & Event.CONTROL_MASK ? 'Ctrl-' : '';
    r += evt.modifiers & Event.ALT_MASK ? 'Alt-' : '';
    r += evt.modifiers & Event.SHIFT_MASK ? 'Shift-' : '';
    r += evt.which;
  }
  //alert(r);

  return true;
}

function setFocusToConsoleLeftControl(control){
//First try by looping through the openers/parents
  try {
    var winConsole = window.opener;
    var bFound = false;

    while(!bFound && winConsole != null) {
      if(winConsole.name == 'console') {
            winConsole.frames['console_left'].document.getElementById(control).focus();
        bFound = true;
      } else {
        // set the window to either a parent or an opener
        winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
      }
    }
  } catch(e) { }

//Second, try by starting at the top window - as they're probably on one of the console pages
  if (!bFound){
     try {
       var winConsole = window.top;
       var bFound = false;
       while(!bFound && winConsole != null) {
         if(winConsole.name == 'console') {
               winConsole.frames['console_left'].document.getElementById(control).focus();
           bFound = true;
         } else {
           // set the window to either a parent or an opener
           winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
         }
       }
     } catch(e) { }

  }

}

function clickConsoleControl(control){
//First try by looping through the openers/parents
  try {
    var winConsole = window.opener;
    var bFound = false;

    while(!bFound && winConsole != null) {
      if(winConsole.name == 'console') {
      winConsole.document.getElementById(control).click();
        bFound = true;
      } else {
        // set the window to either a parent or an opener
        winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
      }
    }
  } catch(e) { }

//Second, try by starting at the top window - as they're probably on one of the console pages
  if (!bFound){
     try {
       var winConsole = window.top;
       var bFound = false;
       while(!bFound && winConsole != null) {
         if(winConsole.name == 'console') {
           winConsole.document.getElementById(control).click();
           bFound = true;
         } else {
           // set the window to either a parent or an opener
           winConsole = (winConsole.opener != null) ? winConsole.opener : winConsole.parent;
         }
       }
     } catch(e) { }

  }

}


//Click an element & set the dirty bit
function click_element(element_id) {
  try {
    document.getElementById(element_id).click();
  } catch (e) { }
  SetDirty();
}

/**  END GENERAL  **/


function GridRowClickHandler(the_tr,the_table,the_prev){
  //Selected Row Index
  var sel_index = the_tr.rowIndex;
  //get the table and it's multi-select capability
  var the_table = document.getElementById(the_table);
  var multi = false;
  if(the_table.multi == 'true') multi = true;

  //Table Rows
  var trArray = the_table.rows;
  //Selected Color
  var sel_color = GetGridRowSelectColor();

  if(multi) {
    var first = 0;
    var count = 0;
    var ctrl = false;
    var shift = false;

    // trap control keycodes
    if(window.event && event.ctrlKey) ctrl = true;
    if(window.event && event.shiftKey) shift = true;

    if(ctrl || shift) {
      for(i = 1; i < the_table.rows.length; i++) {
        if(trArray[i].selected == 1) {
          count++;
          if(first == 0) first = i;
        }
      }
    }

    orig_color = trArray[sel_index].getAttribute("defColor");
    //If the defColor attribute isn't defined, set to the table background color
    if (orig_color == null) orig_color = the_table.bgColor;

    if(trArray[sel_index].selected == 1) {
      //turn off all of the table rows
      if((ctrl && (count == 1 || count == 0)) || (!ctrl)) {
        for(i = 1; i < the_table.rows.length; i++) {
          trArray[i].bgColor = orig_color;
          trArray[i].selected = 0;
        }
        //now set the color of the selected row
        trArray[sel_index].bgColor = sel_color;
        trArray[sel_index].selected = 1;

      } else if(ctrl && count > 1) {
        //now set the color of the selected row
        trArray[sel_index].bgColor = orig_color;
        trArray[sel_index].selected = 0;
      }
    } else {
      if(!ctrl) {
        for(i = 1; i < the_table.rows.length; i++) {
          trArray[i].bgColor = orig_color;
          trArray[i].selected = 0;
        }
      }

      //Set the color of the selected row
      trArray[sel_index].bgColor = sel_color;
      trArray[sel_index].selected = 1;
    }

  } else {
    //Set a variable equal to the passed in variable name
    eval('var prev = ' + the_prev);

    //If we had a previous row selected, set it back to its default color
    if (prev >= 0){
       orig_color = trArray[prev].getAttribute("defColor");
       //If the defColor attribute isn't defined, set to the table background color
       if (orig_color == null) { orig_color = the_table.bgColor}
       trArray[prev].bgColor = orig_color;
    }

    //Set the previous selected row to the current selected row index
    eval(the_prev + '= sel_index');

    //Set the color of the selected row
    trArray[sel_index].bgColor = sel_color;
  }
}



function PerformGlobalWorkflow(operation){
  all_fields = document.getElementsByTagName("input");
  var element_count = all_fields.length;
  var post_data = '';
  var post_data_overflow = 0;

  for(i = 0;i < element_count; i++) {
     objInput = all_fields[i];
     if (objInput.getAttribute('type') == 'checkbox') {
        if (objInput.checked) {
           var t_id = objInput.getAttribute('id');
           var t_data = post_data;
           if (post_data != '') { post_data+= "|"; }
           post_data+= t_id

             if(post_data.length > 1990) {
               var p = i;
               post_data_overflow = post_data.length;
               post_data = t_data;
               i = element_count;
             }

        }
     }
  }

   if(post_data_overflow > 0) {
      alert('There were too many items specified (' + element_count + '). \n' + p + ' items will be processed. \nExcess items will not be processed.');
    }

  if (post_data == ''){
     alert('No objects selected.');
  } else {
   //alert('number to process = ' + element_count);
   //alert('perform global workflow: ' + operation);
   //alert(post_data);
   //alert(post_data.length);

   switch (operation){
      case 'yank':
         OpenActionWindow(post_data, 'batch', 'yank');
         break;
      case 'accept':
         OpenActionWindow(post_data, 'batch', 'accept');
         break;
      case 'move':
         OpenMoveWindow(post_data, 'batch');
         break;
      case 'dispatch':
         OpenDispatchWindow(post_data, 'batch');
         break;
      case 'assign':
         OpenAssignWindow(post_data, 'batch');
         break;
      case 'reject':
         OpenRejectWindow(post_data, 'batch');
         break;
      case 'change_cr_status':
         OpenChangeCRStatusWindow(post_data, 'batch');
         break;
      case 'change_status':
         OpenBatchChangeStatusWindow(post_data, 'batch');
         break;
      case 'change_pr_status':
         OpenBatchChangePRStatusWindow(post_data, 'batch');
         break;
      case 'change_case_fields':
         OpenBatchChangeCaseFieldsWindow(post_data, 'batch');
         break;   
      case 'change_cr_fields':
         OpenBatchChangeCRFieldsWindow(post_data, 'batch');
         break;                   
   } //end switch

  } //end if

}

function formatCurrency(num,symbolCurrency) {
  var fcUndefined;
  if (fcUndefined == symbolCurrency){
    symbolCurrency = '';
  }

  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num)) {
    num = "0";
  }

  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();

  if(cents<10) {
    cents = "0" + cents;
  }

  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
    num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
  }

  return (((sign)?'':'-') + symbolCurrency + num + '.' + cents);
}

function isNumeric(val) {
  var digits="-1234567890.,";
  for (var i=0; i < val.length; i++) {
    if (digits.indexOf(val.charAt(i))==-1) { return false; }
  }
  return true;
}

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}


///////////////////////////////////////////////////////////////////////////////////
//Function to pretty-up a date to be consistent with the Clarify fat client
///////////////////////////////////////////////////////////////////////////////////
function PrettyDate(in_date)
{
  var out_date = in_date;

  var zero_dt = new Date('1/1/1753');
  var zero_dt_str = formatDate(zero_dt,"MMM dd, yyyy");

  var end_dt = new Date('12/31/4712');
  var end_dt_str = formatDate(end_dt,"MMM dd, yyyy");

  var in_dt = new Date(in_date);
  var in_dt_str = formatDate(in_dt,"MMM dd, yyyy");

  if (in_dt_str == zero_dt_str){ out_date = '?/?/? ?:?:?'; }
  if (in_dt_str == end_dt_str) { out_date = '*/*/* *:*:*'; }

  return out_date;
}



///////////////////////////////////////////////////////////////////////////////
//function to trap for the onkeydown event
//specifically, look for a form refresh (F5)
///////////////////////////////////////////////////////////////////////////////
function onkeydown_event_handler() {
  var temp_keycode = 19;   //19  = pause key
  var F5_keycode   = 116;  //116 = F5
  var tab_keycode  = 9;    //9   = TAB
  var a_keycode    = 65;   //65  = A

  var do_refresh = false;

  // keycode for F5 function
  if (window.event && window.event.keyCode == F5_keycode) {
     //try to set the focus to the done element
     //this will force the onchange event to fire for any elements that were just modified
     try{document.getElementById('done').focus();} catch(e){}
     //invoke the new keycode that can be trapped
     window.event.keyCode = temp_keycode;
  }

  // keycode for TAB function to cycle through Tabs
  if(window.event && window.event.keyCode == tab_keycode && window.event.ctrlKey)  {
    if(document.getElementById('selected_tab')) {
      var i = new Number(document.getElementById('selected_tab').value) + 1;
      if(i >= arrTabs.length) i = 0;
      var tab_id = 'tab_hdr_' + i;
      if(document.getElementById(tab_id).style.visibility != 'visible') {
        if(document.getElementById('tab_prev').style.visibility == 'visible') {
          if(i == 0) {
            TabPrev();
          } else {
            TabNext();
          }
        }
      }
      TabSelect(i);
      SetSelectedIndex(i);
    }
    //invoke the new keycode that can be trapped
    window.event.keyCode = 18;
  }

  // special trap for action menu on this form
  if(window.name == 'part_rqst_detail' || window.name == 'action_item') {
    // keycode for alt-a function
    if(window.event && window.event.keyCode == a_keycode && event.altKey) {
      //invoke the new keycode that can be trapped
      window.event.keyCode = temp_keycode;
      if(window.event && window.event.keyCode == temp_keycode)  {
        showMenu('actionMenu');
      }
    }
  }

  //if this is the keycode we want to trap for...
  //if there is a dirty flag element on this page...
  //if the dirty_flag is set to dirty (1)...
  //ask the user if they want to refresh or stay on this page
  //if they want to refresh, set the dirty_flag to false & refresh
  //if they want to stay, cancel the default action

  if (window.event && window.event.keyCode == temp_keycode)  {
    if (document.getElementById('dirty_flag')){
      if(document.getElementById('dirty_flag').value == '1') {
            var msg = "The information on this page has been changed."
            msg+= "\nPress OK to refresh this page, or Cancel to stay on the current page."
           if (confirm(msg)) {
              document.getElementById('dirty_flag').value = 0;
              document.execCommand("Refresh");
           }else{
              window.event.cancelBubble = true;
              window.event.returnValue = false;
              return false;
           }
      } //end of if dirty_flag.value == 1
   else {
     //page is not dirty
     do_refresh = true;
   }
   } //end of if dirty_flag exists
     //dirty flag doesn't exist on this page
     do_refresh = true;
  }//end of if keycode == temp_keycode

  //do the default action
  window.event.returnValue = true;
  return true;

  //refresh the page
  if (do_refresh){ document.execCommand('refresh'); }

} //end function


///////////////////////////////////////////////////////////////////////////////
//function to check the dirty bit, and then prompt the
//user to stay on this page, or close this page
//only do this if there is a dirty_flag element on the page
//and the Y coordinate is less than zero (meaning the X button)
///////////////////////////////////////////////////////////////////////////////
function CheckDirty(){
//alert('keycode = ' + event.keyCode);
//alert('alt = ' + event.altKey);
//alert('ctrl = ' + event.ctrlKey);


//try to set the focus to the done element
//this will force the onchange event to fire for any elements that were just modified
  try{document.getElementById('done').focus();} catch(e){}

var check = false;
//if they clicked the X, or double-clicked the icon in the upper-left of the window
  if (event.clientY <= 0) {check=true;}
//if they did alt-f4 to close the window
  if (event.altKey)       {check=true;}
//if the did ctrl-w to close the window
  if (event.ctrlKey)      {check=true;}

//if we're to check the dirty bit, then do so
  if (check){
    //if we have a dirty_flag element on this page...
    if (document.getElementById('dirty_flag')){
      if(document.getElementById('dirty_flag').value == '1') {
         if (event.type == "beforeunload") {
            var msg = "The information on this page has been changed."
            msg+= "\nPressing OK will close this page and cancel any changes made."
            //msg+= "\nPress OK to close this page, or Cancel to stay on the current page."
            event.returnValue = msg;
         }
      } //end if
    } //end if
  } //end if

}

///////////////////////////////////////////////////////////////////////////////
//function to toggle color for a html object
///////////////////////////////////////////////////////////////////////////////
function toggleColor(object,color) {
  if(object.style.backgroundColor == color) {
    object.style.backgroundColor = 'white';
  } else {
    object.style.backgroundColor = color;
  }
}
                                                                                                                                                                                                                       

