//=====================================================================||
//              NOP Design / Cyberitas Core Loader Module              ||
//                                                                     ||
// For more information on the Cyberitas Dynamic Toolkit, or NOP Design||
// systems, please visit us on the WWW at http://www.cyberitas.com     ||
//                                                                     ||
// Javascript portions of the software are available as freeware from  ||
// NOP Design/Cyberitas.  You must keep this comment unchanged in      ||
// your code.  Please contact Cyberitas for license restrictions.      ||
//                                                                     ||
// Core Module,       v. 1.0                                           ||
// Last Modified:     4/1/2005                                         ||
// Last Editor:       Scott M.                                         ||
//                                                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Static Definitions                            ||
//                      --------------------                           ||
// These static definitions are used for convenience and legibility    ||
// throughout the code.  Do not change them.                           ||
//---------------------------------------------------------------------||
var CYBER_BROWSER_TYPE_UNSUPPORTED  = 0;
var CYBER_BROWSER_TYPE_MSIE         = 1;
var CYBER_BROWSER_TYPE_GECKO        = 2;
var CYBER_BROWSER_TYPE_OPERA        = 3;


//---------------------------------------------------------------------||
//                       Global Variables                              ||
//                      ------------------                             ||
// All global variables used by the Cyber Core are defined here.  Do   ||
// not change their default values, as they are automatically          ||
// configured during the load phase.                                   ||
//---------------------------------------------------------------------||
var g_eCyberBrowserType = CYBER_BROWSER_TYPE_UNSUPPORTED;
var g_ModalDialogWindow;
var g_ModalDialogInterval;
var g_ModalDialog = new Object;
    g_ModalDialog.value = '';
    g_ModalDialog.callback = '';
var g_bCyberBrowserEditCapable = false;
var g_strCyberInstallDir = '.';
var g_bCyberHandlesOnload = false;
var g_aCyberOldOnLoad = Array();
var g_aCyberRegisteredModules = Array();
var g_fCyberCoreBuild = 20050401;
var g_aCyberModuleConfig = Array();

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreInitialize                                    ||
// PARAMETERS:  Installation Directory                                 ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Initializes use of the CyberCore, and makes sets the   ||
//              install directory for module/image loading.            ||
//---------------------------------------------------------------------||
function CyberCoreInitialize( strInstallDirectory )
{
   g_strCyberInstallDir = strInstallDirectory;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreModuleLoaded                                  ||
// PARAMETERS:  Module Name                                            ||
// RETURNS:     True on module found                                   ||
// PURPOSE:     Determines if a particular modules has alread been     ||
//              loaded (registered)                                    ||
//---------------------------------------------------------------------||
function CyberCoreModuleLoaded( strModuleName )
{
   for( i=0; i < g_aCyberRegisteredModules.length; i++ ) {
      if( g_aCyberRegisteredModules[i] == strModuleName ) {
         return true;
      }
   }
   return false;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreRegisterLoad                                  ||
// PARAMETERS:  Module Name                                            ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     All CyberModules should self register with this        ||
//              function to keep dependencies satisfied.               ||
//---------------------------------------------------------------------||
function CyberCoreRegisterLoad( strModuleName )
{   
   var i;
   var bLoaded = false;
   for( i=0; i < g_aCyberRegisteredModules.length; i++ ) {
      if( g_aCyberRegisteredModules[i] == strModuleName ) {
         bLoaded = true;
         break;
      }
   }
   if( !bLoaded ) {
     g_aCyberRegisteredModules[g_aCyberRegisteredModules.length] = strModuleName;
     if( !g_aCyberModuleConfig[strModuleName] )
        g_aCyberModuleConfig[strModuleName] = Array();
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreRequireModule                                 ||
// PARAMETERS:  Module required                                        ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Loads a CyberCore Javascript module, handling          ||
//              any dependencies / cross loads.                        ||
//---------------------------------------------------------------------||
function CyberCoreRequireModule( strModuleName )
{
   var i;
   var bLoaded = false;
   for( i=0; i < g_aCyberRegisteredModules.length; i++ ) {
      if( g_aCyberRegisteredModules[i] == strModuleName ) {
         bLoaded = true;
         break;
      }
   }
   if( !bLoaded ) {
     document.write('<scr' + 'ipt src="' + g_strCyberInstallDir + '/Cyber' + strModuleName + '.js"');
     document.write(' language="Javascript1.2"></scr' + 'ipt>');
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreAddOnLoad                                     ||
// PARAMETERS:  Function to register onLoad call to                    ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Adds a function call to the document onload, preserving||
//              any existing function calls.                           ||
//---------------------------------------------------------------------||
function CyberCoreAddOnLoad( pFunction )
{
   switch( g_eCyberBrowserType ){
   case CYBER_BROWSER_TYPE_OPERA:
   case CYBER_BROWSER_TYPE_MSIE:
      if( window.onload ){
         if( !g_bCyberHandlesOnload ){
            g_aCyberOldOnLoad[g_aCyberOldOnLoad.length] = window.onload;
         }
      }
      window.onload = cyberCoreDoOnLoad;
      g_bCyberHandlesOnload = true;
      g_aCyberOldOnLoad[g_aCyberOldOnLoad.length] = pFunction;
      break;
   case CYBER_BROWSER_TYPE_GECKO:
      window.addEventListener('load', pFunction, false);
      break;
   default:
      window.addEventListener('load', pFunction, false);
      break;
   }
}


function cyberCoreDoOnLoad()
{
    var iNumCalls = g_aCyberOldOnLoad.length;
    for( var i=0; i < iNumCalls; i++ ) {
       g_aCyberOldOnLoad[i]();
    }
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSetConfigOption                               ||
// PARAMETERS:  Module name, Configuration option key, value           ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Sets a configuration option for a specific module      ||
//---------------------------------------------------------------------||
function CyberCoreSetConfigOption( strModuleName, strKey, strValue )
{
   if( g_aCyberModuleConfig[strModuleName] ){
      g_aCyberModuleConfig[strModuleName][strKey] = strValue;
   } else {
      g_aCyberModuleConfig[strModuleName] = Array();
      g_aCyberModuleConfig[strModuleName][strKey] = strValue;
   }

}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreRequireModule                                 ||
// PARAMETERS:  Module required                                        ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Loads a CyberCore Javascript module, handling          ||
//              any dependencies / cross loads.                        ||
//---------------------------------------------------------------------||
function CyberCoreGetConfigOption( strModuleName, strKey )
{
   if( g_aCyberModuleConfig[strModuleName] )
      return g_aCyberModuleConfig[strModuleName][strKey];
   else
      return null;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSleep                                         ||
// PARAMETERS:  Number of milliseconds to sleep for                    ||
// RETURNS:     Nothing                                                ||
// PURPOSE:     Provides generic sleep capability for CyberCore modules||
//---------------------------------------------------------------------||
function CyberCoreSleep( iMilliSeconds )
{
   var then,now; 
   then=new Date().getTime();
   now=then;
   while((now-then)<iMilliSeconds)
   {
      now = new Date().getTime();
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreOpenPopup                                     ||
// PARAMETERS:  Url to open, display options for opened window         ||
// RETURNS:     True if window is believed to have been opened.        ||
// PURPOSE:     Generic popup window handler                           ||
//---------------------------------------------------------------------||
function CyberCoreOpenPopup( strUrl, strOptions )
{
   var pWin = window.open(strUrl, '', strOptions); 
   if( !pWin ) {
      return false;
   }

   return true;
}

function cyberCoreModalDialogMaintainFocus()
{
  try
  {
    if (g_ModalDialogWindow.closed)
     {
        window.clearInterval(g_ModalDialogInterval);
        g_ModalDialog.callback(g_ModalDialog.value);
        return;
     }
    g_ModalDialogWindow.focus(); 
  }
  catch (everything) {   }
}


function cyberCoreModalDialogRemoveWatch()
{
   g_ModalDialog.value = '';
   g_ModalDialog.isOpen = false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreDismissModalDialog                            ||
// PARAMETERS:  Value to return to caller                              ||
// RETURNS:     false (for use in HREFs)                               ||
// PURPOSE:     Dismisses a window opened with CyberCoreShowModalDialog||
//---------------------------------------------------------------------||
function CyberCoreDismissModalDialog( strReturnValue )
{
   if( g_eCyberBrowserType == CYBER_BROWSER_TYPE_MSIE ){
      window.returnValue = strReturnValue;
      window.close();
   } else {
      window.opener.g_ModalDialog.value = strReturnValue;
      window.close();
   }

   return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreShowModalDialog                               ||
// PARAMETERS:  Callback function to call on window close              ||
//              URL to load into window, JS arguments to window,       ||
//              display options.                                       ||
// RETURNS:     True if window believed to have been opened            ||
// PURPOSE:     Displays a modal dialog that must be answered before   ||
//              continuing.                                            ||
//---------------------------------------------------------------------||
function CyberCoreShowModalDialog( CallBackFunction, strUrl, xArguments, iWidth, iHeight, bCenter, bResize, bScroll, bStatus )
{
   var bReturn = false;
   if( g_eCyberBrowserType == CYBER_BROWSER_TYPE_MSIE ){
      var strOptions = 'dialogHeight: ' + iHeight + 'px;';
      strOptions += 'dialogWidth: ' + iWidth + 'px;';
      if( bCenter ) strOptions += 'center: 1;';
      else  strOptions += 'center: 0;';
      if( bResize ) strOptions += 'resizable: 1;';
      else  strOptions += 'resizable: 0;';
      if( bScroll ) strOptions += 'scroll: 1;';
      else  strOptions += 'scroll: 0;';
      if( bStatus ) strOptions += 'status: 1;';     
      else  strOptions += 'status: 0;';     
      strOptions += 'help: 0;';
      strReturn = window.showModalDialog( strUrl, xArguments, strOptions );
      CallBackFunction(strReturn);
      bReturn = true;
   } else {
      var strOptions = 'height=' + iHeight + ',';
      strOptions += 'width=' + iWidth + ',';
      if( bResize ) strOptions += 'resizable=1;';
      else  strOptions += 'resizable=0;';
      if( bScroll ) strOptions += 'scrollbars=1;';
      else  strOptions += 'scrollbars=0;';
      if( bStatus ) strOptions += 'status=1;';     
      else  strOptions += 'status=0;';     
      strOptions += 'toolbar=0,location=0,menubar=0,';
      bReturn = CyberCoreSimulatedModal( CallBackFunction, strUrl, xArguments, strOptions );
   }

   return bReturn;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSimulatedModal                                ||
// PARAMETERS:  Callback function to call on window close              ||
//              URL to load into window, JS arguments to window,       ||
//              display options.                                       ||
// RETURNS:     True if window believed to have been opened            ||
// PURPOSE:     Displays a 'simulated' modal dialog.  You most likely  ||
//              wish to call CyberCoreShowModalDialog not this         ||
//              which will fall back to this function if required.     ||
//---------------------------------------------------------------------||
function CyberCoreSimulatedModal( CallBackFunction, strUrl, xArguments, strDisplayOptions )
{
   cyberCoreModalDialogRemoveWatch();
   g_ModalDialogWindow=window.open(strUrl, xArguments, strDisplayOptions); 
   if( !g_ModalDialogWindow ) {
      alert( "Could not create modal window!  Please make sure you disable your popup blocker(s) to use this function." );
      return false;
   }
   g_ModalDialogWindow.dialogArguments = xArguments;
   g_ModalDialog.callback = CallBackFunction;
   g_ModalDialogWindow.focus(); 
   g_ModalDialogInterval = window.setInterval("cyberCoreModalDialogMaintainFocus()",5);
   
   return true;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreAttachEvent                                   ||
// PARAMETERS:  What to attach to, function to call                    ||
// RETURNS:     True if valid event to be catptured                    ||
// PURPOSE:     Attach an function call to an event.                   ||
//---------------------------------------------------------------------||
function CyberCoreAttachEvent( strEvent, pObjectToAttachTo, FunctionCall )
{
   if (g_eCyberBrowserType == CYBER_BROWSER_TYPE_MSIE || g_eCyberBrowserType == CYBER_BROWSER_TYPE_OPERA) {
      switch( strEvent ){
         case "onkeydown":
         case "onkeypress":
         case "onmousedown":
         case "onmousemove":
         case "onclick":
         case "onmouseup":
         case "ondrag":
         case "ondrop":
         case "oncut":
         case "onpaste":
         case "onblur":
         case "onunload":
         case "onload":
         case "onchange":
         case "onmouseover":
         case "onmouseout":
         case "oncontextmenu":
            pObjectToAttachTo.attachEvent( strEvent, FunctionCall );
            return true;
            break;
         default:
            return false;
            break;
      }
    } else if( g_eCyberBrowserType == CYBER_BROWSER_TYPE_GECKO || g_eCyberBrowserType == CYBER_BROWSER_TYPE_UNSUPPORTED ) {
      switch( strEvent ){
         case "onkeydown":
         case "onkeypress":
         case "onclick":
         case "onmousedown":
         case "onmouseup":
         case "onmousemove":
         case "onblur":
         case "onunload":
         case "onload":
         case "onchange":
         case "onmouseover":
         case "onmouseout":
         case "oncontextmenu":
            var strTemp = strEvent.replace(/^on/i, '');
            pObjectToAttachTo.addEventListener(strTemp, FunctionCall, true );
            return true;         
         case "ondrag":
         case "ondrop":
         case "oncut":
         case "onpaste":
         default:
            return false;
            break;
      }
   }
   return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreRemoveEvent                                   ||
// PARAMETERS:  What to remove from, function to call                  ||
// RETURNS:     True if valid event to be catptured                    ||
// PURPOSE:     Detach a function call from an event.                  ||
//---------------------------------------------------------------------||
function CyberCoreRemoveEvent( strEvent, pObjectToAttachTo, FunctionCall )
{
   if (g_eCyberBrowserType == CYBER_BROWSER_TYPE_MSIE || g_eCyberBrowserType == CYBER_BROWSER_TYPE_OPERA) {
      switch( strEvent ){
         case "onkeydown":
         case "onkeypress":
         case "onmousedown":
         case "onmousemove":
         case "onclick":
         case "onmouseup":
         case "ondrag":
         case "ondrop":
         case "oncut":
         case "onpaste":
         case "onblur":
         case "onunload":
         case "onload":
         case "onchange":
         case "onmouseover":
         case "onmouseout":
         case "oncontextmenu":
            pObjectToAttachTo.detachEvent(strEvent, FunctionCall );
            return true;
            break;
         default:
            return false;
            break;
      }
    } else if( g_eCyberBrowserType == CYBER_BROWSER_TYPE_GECKO || g_eCyberBrowserType == CYBER_BROWSER_TYPE_UNSUPPORTED ) {
      switch( strEvent ){
         case "onkeydown":
         case "onkeypress":
         case "onclick":
         case "onmousedown":
         case "onmouseup":
         case "onmousemove":
         case "onblur":
         case "onunload":
         case "onload":
         case "onchange":
         case "onmouseover":
         case "onmouseout":
         case "oncontextmenu":
            var strTemp = strEvent.replace(/^on/i, '');
            pObjectToAttachTo.removeEventListener(strTemp, FunctionCall, true );
            return true;         
         case "ondrag":
         case "ondrop":
         case "oncut":
         case "onpaste":
         default:
            return false;
            break;
      }
   }
   return false;   
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreFindWidth                                     ||
// PARAMETERS:  Object to query                                        ||
// RETURNS:     Width of object in pixels                              ||
// PURPOSE:     Determines the width of an object                      ||
//---------------------------------------------------------------------||
function CyberCoreFindWidth(obj)
{
   var cursize = 0;
   if (document.getElementById || document.all) {
      cursize = obj.offsetWidth;
   } else if (document.layers)
      obj.width;

   return cursize;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreFindHeight                                    ||
// PARAMETERS:  Object to query                                        ||
// RETURNS:     Height of object in pixels                             ||
// PURPOSE:     Determines the height of an object                     ||
//---------------------------------------------------------------------||
function CyberCoreFindHeight(obj)
{
   var cursize = 0;
   if (document.getElementById || document.all) {
      cursize = obj.offsetHeight;
   } else if (document.layers)
      obj.height;

   return cursize;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreFindPosX                                      ||
// PARAMETERS:  Object to query                                        ||
// RETURNS:     X position in pixels                                   ||
// PURPOSE:     Determines the X-axis position of an object            ||
//---------------------------------------------------------------------||
function CyberCoreFindPosX(obj)
{
   var curleft = 0;
   if (document.getElementById || document.all) {
      while (obj.offsetParent) {
         curleft += obj.offsetLeft;
         obj = obj.offsetParent;
      }
   } else if (document.layers)
      curleft += obj.x;

   return curleft;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreFindPosY                                      ||
// PARAMETERS:  Object to query                                        ||
// RETURNS:     Y position in pixels                                   ||
// PURPOSE:     Determines the Y-axis position of an object            ||
//---------------------------------------------------------------------||
function CyberCoreFindPosY(obj)
{
   var curtop = 0;
   if (document.getElementById || document.all) {
      if( !obj.offsetParent ){
         curtop += obj.offsetTop;
      }
      while (obj.offsetParent) {
         curtop += obj.offsetTop;
         obj = obj.offsetParent;
      }
   } else if (document.layers)
      curtop += obj.y;

   return curtop;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSetObjectPosition                             ||
// PARAMETERS:  X, Y position                                          ||
// RETURNS:     N/A                                                    ||
// PURPOSE:     Moves an object to specified location                  ||
//---------------------------------------------------------------------||
function CyberCoreSetObjectPosition(obj, xPos, yPos)
{
   var pStyle = obj.style || obj;
   var strStyle = (g_bCyberBrowserEditCapable)? 'px' : '';
   pStyle.left = xPos + strStyle;
   pStyle.top = yPos + strStyle;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreInitializeWaitDialog                          ||
// PARAMETERS:  None                                                   ||
// RETURNS:                                                            ||
// PURPOSE:     Writes initial DIV used by wait dialog. MUST BE CALLED ||
//              before onLoad is fired, and before DisplayWaitDialog   ||
//---------------------------------------------------------------------||
function CyberCoreInitializeWaitDialog()
{
   document.write('<div id="CyberCoreWaitDialog" style="position:absolute;visibility:hidden;left:0px;top:0px;z-index:999999;">');
   document.write('<table cellpadding=4 cellspacing=0 style="background-color: #ECE9D8;border: 2px solid #00138C;" width="300" height="80">');
   document.write('<tr><td style="font-family:arial,helvetica;font-size:10pt;background-color:#00138C;color:#ffffff;">');
   document.write('<b>Please wait!</b><br>');
   document.write('</td></tr><tr><td style="font-family:arial,helvetica;font-size:10pt;">');   
   document.write('<div id=CyberCoreWaitProgress>Please be patient as we process your request.</div>');
   document.write('<br><img src="'+g_strCyberInstallDir+'/images/progress.gif" alt="">');
   document.write('</td></tr></table>');
   document.write('</div>');
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreDisplayWaitDialog                             ||
// PARAMETERS:  Object to center on, or null for top left.             ||
// RETURNS:                                                            ||
// PURPOSE:     Displays wait dialog for user.  InitializeWaitDialog   ||
//              must be called before onLoad to use this function.     ||
//---------------------------------------------------------------------||
function CyberCoreDisplayWaitDialog( pCenterOnObject )
{
   var pWait = document.getElementById('CyberCoreWaitDialog');
   if( pWait ) {
      if( pCenterOnObject ) {
         var xPos = CyberCoreFindPosX(pCenterOnObject);
         var yPos = CyberCoreFindPosY(pCenterOnObject);
         var widthObj = CyberCoreFindWidth(pCenterOnObject);
         var widthDlg = CyberCoreFindWidth(pWait);
         var heightObj = CyberCoreFindHeight(pCenterOnObject);
         var heightDlg = CyberCoreFindHeight(pWait);
         if( widthObj && widthDlg && heightObj && heightDlg ){
            xPos = xPos + ((widthObj - widthDlg) / 2);
            yPos = yPos + ((heightObj - heightDlg) / 2);
         }
         if( xPos && yPos ) {
            pWait.style.top = yPos+'px';
            pWait.style.left = xPos+'px';
         }
      }
      pWait.style.visibility = 'visible';
   } else {
      window.status = "Processing, please wait...";
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreUpdatedWaitDlg                                ||
// PARAMETERS:  Message to display to user                             ||
// RETURNS:                                                            ||
// PURPOSE:     Updates message shown on DisplayWaitDialog             ||
//---------------------------------------------------------------------||
function CyberCoreUpdatedWaitDlg( strMessage )
{
   var pTxt = document.getElementById('CyberCoreWaitProgress');
   if( pTxt ) {
      pTxt.innerHTML = strMessage;
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreDismissWaitDialog                             ||
// PARAMETERS:  Non                                                    ||
// RETURNS:                                                            ||
// PURPOSE:     Hides a displayed wait dialog                          ||
//---------------------------------------------------------------------||
function CyberCoreDismissWaitDialog()
{
   var pWait = document.getElementById('CyberCoreWaitDialog');
   if( pWait ) {
      pWait.style.visibility = 'hidden';
   } else {
      window.status = "Complete.";
   }
   var pTxt = document.getElementById('CyberCoreWaitProgress');
   if( pTxt ) {
      pTxt.innerHTML = 'Please be patient as we process your request.';
   }
}

function cyberCoreStripUnwanted(item, StripChar)
{
  var strRet="";
  var aLoc = item.split("");
  for(var i=0; i < aLoc.length; i++)
  {
    if(aLoc[i] != StripChar) {
       strRet += aLoc[i];
    }
  }
  return(strRet);
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreValidatePrice                                 ||
// PARAMETERS:  Field to be validated                                  ||
// RETURNS:     True on field is specified type                        ||
// PURPOSE:     Validates data type of user entered text               ||
//---------------------------------------------------------------------||
function CyberCoreValidatePrice( priceField )
{
   var bad = false;
   var tmp = new String(priceField.value);
   tmp = cyberCoreStripUnwanted(tmp, '$' );
   tmp = cyberCoreStripUnwanted(tmp, ',' );

   if( tmp.length == 0 ) {
      return false;
   }

   for ( var i = 0; i < tmp.length; i++ ) {
      if ( tmp.charAt(i)!="." &&
           tmp.charAt(i)!="$" &&
           tmp.charAt(i)!="-" &&
           tmp.charAt(i)!="," &&
           tmp.charAt(i)!="0" &&
           !parseInt(tmp.charAt(i))
         ){
         bad = true;
      }
   }
   return !bad;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreValidateNullablePrice                         ||
// PARAMETERS:  Field to be validated                                  ||
// RETURNS:     True on field is specified type                        ||
// PURPOSE:     Validates data type of user entered text               ||
//---------------------------------------------------------------------||
function CyberCoreValidateNullablePrice( priceField )
{
   var bad = false;
   var tmp = new String(priceField.value);
   tmp = cyberCoreStripUnwanted(tmp, '$' );
   tmp = cyberCoreStripUnwanted(tmp, ',' );

   for ( var i = 0; i < tmp.length; i++ ) {
      if ( tmp.charAt(i)!="." &&
           tmp.charAt(i)!="$" &&
           tmp.charAt(i)!="-" &&
           tmp.charAt(i)!=")" &&
           tmp.charAt(i)!="(" &&
           tmp.charAt(i)!="," &&
           tmp.charAt(i)!="0" &&
           !parseInt(tmp.charAt(i))
         ){
         bad = true;
      }
   }
   return !bad;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreValidateNumber                                ||
// PARAMETERS:  Field to be validated, whether to clean number         ||
// RETURNS:     True on field is specified type                        ||
// PURPOSE:     Validates data type of user entered text, normalizes   ||
//              number if bClean is true.                              ||
//---------------------------------------------------------------------||
function CyberCoreValidateNumber( numberField, bClean )
{
   if ( parseFloat(numberField.value) >= 0 ) {
      if( bClean ) numberField.value = parseFloat(numberField.value);
      return true;
   } else {
      if( numberField.value.length > 0 ){
         if( bClean ) numberField.focus();
         return false;
      }
   }
   return false;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreValidateWholdNumber                           ||
// PARAMETERS:  Field to be validated, whether to clean number         ||
// RETURNS:     True on field is specified type                        ||
// PURPOSE:     Validates data type of user entered text, normalizes   ||
//              number if bClean is true.                              ||
//---------------------------------------------------------------------||
function CyberCoreValidateWholeNumber( numberField, bClean )
{
   if ( parseInt(numberField.value) >= 0 ) {
      if( bClean ) numberField.value = parseInt(numberField.value);
      return true;
   } else {
      if( numberField.value.length > 0 ){
         if( bClean ) numberField.focus();
         return false;
      }
   }
   return false;
}

//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreArrayIsSet                                    ||
// PARAMETERS:  Array to verify                                        ||
// RETURNS:     TRUE if array is set, FALSE otherwise                  ||
// PURPOSE:     Handles browser differences between null, undefined    ||
//              and otherwise when determining if an array is          ||
//              allocated                                              ||
//---------------------------------------------------------------------||
function CyberCoreArrayIsSet( aArray )
{
   if (typeof aArray == "undefined") {
      return false;
   }

   //array must contain an element
   for (var key in aArray) {
      return true;
   }
              
   //Empty array
   return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreGetObject                                     ||
// PARAMETERS:  id of object to retrieve                               ||
// RETURNS:     object, or NULL if not found                           ||
// PURPOSE:     Cross-browser function to get an object's style object ||
//              given its id                                           ||
//---------------------------------------------------------------------||
function CyberCoreGetObject(objectId) 
{
   if(document.getElementById && document.getElementById(objectId)) {
     // W3C DOM
     return document.getElementById(objectId);
   } 
   else if (document.all && document.all(objectId)) {
     // MSIE 4 DOM
     return document.all(objectId);
   } 
   else if (document.layers && document.layers[objectId]) {
     // NN 4 DOM.. note: this won't find nested layers
     return document.layers[objectId];
   } 
   else {
     return null;
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSetVisible                                    ||
// PARAMETERS:  id of object, desired visibility                       ||
// RETURNS:     true if success                                        ||
// PURPOSE:     Toggles the visibility of the specified object         ||
//---------------------------------------------------------------------||
function CyberCoreSetVisible(objectId, bVisible) 
{
   // first get the object's stylesheet
     var styleObject = CyberCoreGetObject(objectId);

     if (styleObject) {
         if( styleObject.style ) {
            if ( bVisible ) {
               styleObject.style.visibility = 'visible';
            }
            else {
               styleObject.style.visibility = 'hidden';
            }         
            return true;
         }
     }
     return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreGetVisible                                    ||
// PARAMETERS:  id of object                                           ||
// RETURNS:     true if visible                                        ||
// PURPOSE:     Gets the visibility state of the specified object      ||
//---------------------------------------------------------------------||
function CyberCoreGetVisible(objectId) 
{
     var styleObject = CyberCoreGetObject(objectId);

     if (styleObject) {
         if( styleObject.style ) {
            if ( styleObject.style.visibility == 'visible' ) {
               return true;
            }
         }
     }
     return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreSetDisplay                                    ||
// PARAMETERS:  id of object, desired display mode                     ||
// RETURNS:     true if success                                        ||
// PURPOSE:     Toggles the visibility of the specified object         ||
//---------------------------------------------------------------------||
function CyberCoreSetDisplay(objectId, bDisplay) 
{
     var styleObject = CyberCoreGetObject(objectId);

     if (styleObject) {
         if( styleObject.style ) {
            if ( bDisplay ) {
               styleObject.style.display = 'block';
            }
            else {
               styleObject.style.display = 'none';
            }         
            return true;
         }
     }
     return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreGetDisplay                                    ||
// PARAMETERS:  id of object                                           ||
// RETURNS:     true if block display                                  ||
// PURPOSE:     Gets the visibility state of the specified object      ||
//---------------------------------------------------------------------||
function CyberCoreGetDisplay(objectId) 
{
     var styleObject = CyberCoreGetObject(objectId);

     if (styleObject) {
         if( styleObject.style ) {
            if ( styleObject.style.display == 'none' ) {
               return false;
            }
         }
     }
     return true;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberMouseEventIsRightClick                            ||
// PARAMETERS:  mouse event                                            ||
// RETURNS:     true if mouse event represents a right button click    ||
// PURPOSE:     Determines if the right mouse button was clicked       ||
//---------------------------------------------------------------------||
function CyberMouseEventIsRightClick(objMouseEvent) 
{
   var bRightclick;

   bRightclick = false;

   if (objMouseEvent.which) {
      bRightclick = (objMouseEvent.which == 3);
   }
   else {
      if (objMouseEvent.button) {
         bRightclick = (objMouseEvent.button == 2);
      }
   }

   return bRightclick;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberGetMouseXPosition, CyberGetMouseYPosition         ||
// PARAMETERS:  mouse event                                            ||
// RETURNS:     mouse position relative to document in pixels          ||
// PURPOSE:     Gets the position of the mouse cursor                  ||
//---------------------------------------------------------------------||
function CyberGetMouseXPosition(objMouseEvent) 
{
   var iPosition = 0;
   
   if ( objMouseEvent.pageX ) {
      iPosition = objMouseEvent.pageX;
   }
   else {
      if ( objMouseEvent.clientX ) {
         if ( g_eCyberBrowserType == CYBER_BROWSER_TYPE_GECKO ) {
            iPosition = objMouseEvent.clientX + document.body.scrollLeft;
         }
         else {
            iPosition = objMouseEvent.clientX;
         }         
      }
   }

   return iPosition;
}


function CyberGetMouseYPosition(objMouseEvent) 
{
   var iPosition = 0;
   if ( objMouseEvent.pageY ) {
      iPosition = objMouseEvent.pageY;
   } else {
      if ( objMouseEvent.clientY ) {
         if ( g_eCyberBrowserType == CYBER_BROWSER_TYPE_GECKO ) {
            iPosition = objMouseEvent.clientY + document.body.scrollTop;
         } else {
            iPosition = objMouseEvent.clientY;
         }
      }
   }

   return iPosition;
}


//---------------------------------------------------------------------||
// FUNCTION:    CyberCoreCheckmarkAll                                  ||
// PARAMETERS:  id of object                                           ||
// RETURNS:     true if success                                        ||
// PURPOSE:     Checks (or unchecks) all checkboxes inside of the      ||
//              specified container object                             ||
//---------------------------------------------------------------------||
function CyberCoreCheckmarkAll(objectId, bSetOn) 
{
   var pObj = CyberCoreGetObject(objectId);
   
   if ( pObj ) {
      var aInput = pObj.getElementsByTagName('input');

      for (var i=0; i< aInput.length; i++) {
         if (aInput[i].type == 'checkbox') {
            aInput[i].checked = bSetOn;
         }
      } 
      
      return true;
   }

   return false;
}


//---------------------------------------------------------------------||
//                    Cyber Core Initialization                        ||
//                        ------------------                           ||
// This section will initialize the CMS editor, and check for supported||
// browsers.  Old document onloads are called after the CMS onload     ||
// completes.                                                          ||
//---------------------------------------------------------------------||
g_eCyberBrowserType = CYBER_BROWSER_TYPE_UNSUPPORTED;
var tmpMsVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { tmpMsVersion = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { tmpMsVersion = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { g_eCyberBrowserType = CYBER_BROWSER_TYPE_OPERA; tmpMsVersion = 0; }
if (tmpMsVersion >= 5.5) {
   g_bCyberBrowserEditCapable = true;
   g_eCyberBrowserType = CYBER_BROWSER_TYPE_MSIE;
} else {
   if( navigator.product == "Gecko" ) {
      if( navigator.productSub > 20030210 ) {
         g_bCyberBrowserEditCapable = true;
      }      
      g_eCyberBrowserType = CYBER_BROWSER_TYPE_GECKO;
   }
}

