// <!--
/*********************************************************************************************************
  This function finds the correct object reference for the current users browser
  Pass the id or the name of the object.  You will be returned the correctly
  formatted reference to the item if found, or false on failure.
  DEPENDS ON: none
*********************************************************************************************************/
function gof(vID)// shortcut function for getObjectFormat
{
   return getObjectFormat(vID);
}

function getObjectFormat(vID)
{
  if (document.getElementById && document.getElementById(vID))
  {
    return document.getElementById(vID);
  }
  else if (document.getElementByName && document.getElementByName(vID))
  {
    return document.getElementByName(vID);
  }
  else if (document.all && document.all(vID))
  {
    return document.all(vID);
  }
  else
  {
    if (document.forms.length)
    {
      for (var i = 0;i<document.forms.length;i++)
      {
        if (document.forms[i].elements.length)
        {
          for (var x = 0; x<document.forms[i].elements.length;x++)
          {
            if (document.forms[i].elements[x].name == vID)
            {
              if (document.forms[i].elements[x].type == 'radio')
              {
                if (document.forms[i].elements[x].checked)
                {
                  return document.forms[i].elements[x];
                }
              }
              else
              {
                return document.forms[i].elements[x];
              }
            }
          }
        }
      }
    }
  }
  return false;
}

/*********************************************************************************************************
  This function tests for an enter key press and evaluates a string of JavaScript code when the enter
  key is pressed in an input field.  It is intended to be called from the field's onKeyPress attribute
.
  The first parameter is the string of JavaScript code.
  The second parameter is the event object (event).
  DEPENDS ON: none
*********************************************************************************************************/
function ifEnter( fonEnter, event )
{
  if ( ( typeof window.event ) == 'object' )
  {
    if ( window.event.keyCode == 13 )
    {
      eval( fonEnter );
      return false;
    }
  }
  else if ( ( typeof event ) == 'object' )
  {
    if ( event.which == 13 )
    {
      eval( fonEnter );
      return false;
    }
  }
  return true;
}


/*********************************************************************************************************
  These function used to add function calls to the onload of a page
  DEPENDS ON: setting the <body onload=""> value to runLoadScripts();
*********************************************************************************************************/
var aOnLoadObjects = new Array( );
      
function addLoadScript( funString )
{
  aOnLoadObjects.push( funString );
}

function runLoadScripts( )
{
  for ( var i = 0; i < aOnLoadObjects.length; i++ )
  {
     eval( aOnLoadObjects[i] );
  }
}


function invalidPermissionNotification( )
{
   alert( 'We are unable to grant access to this portion of the system at this time, as your assigned Security Level does not permit you to access this function.' );
}

/*********************************************************************************************************
  This function will allow you to make a copy of another Object/Array so that changes between
  the objects are not replicated.
  The first parameter can either be the object to be copied.
  An example of use is:
  oNewObject = new cloneObject(oOrigObject);
  DEPENDS ON: cloneObject and cloneArray will call each other
*********************************************************************************************************/
function cloneObject( what )
{
   for ( i in what )
   {
      if ( typeof what[i] == 'object' )
      {
         this[i] = new cloneObject( what[i] );
      }
      else if ( typeof what[i] == 'array' )
      {
         this[i] = cloneArray( what[i] );
      }
      else
      {
         this[i] = what[i];
      }
   }
}

function cloneArray(what)
{
   var xxx = new Array();
   var len = what.length;

   for ( var i = 0; i < len; i++ )
   {
      if ( typeof what[i] == 'object' )
      {
         xxx[i] = new cloneObject( what[i] );
      }
      else if ( typeof what[i] == 'array' )
      {
         xxx[i] = cloneArray( what[i] );
      }
      else 
      {
         xxx[i] = what[i];
      }
   }
   
   return xxx;
}

/*********************************************************************************************************
  This function will update the onSubmit method of a form.  By default, this will cause all functions
    listed as part of the original onsubmit and the new onsubmit to execute together.
  The first parameter can either be the id of a form object, or the id of any element on a form.
  The second paraameter is the name of the function you wish to call additionally as part of the on submit
  The third parameter is not required, if you pass true as the third parameter, the function will stop
    executing on the first function that fails.
  DEPENDS ON: getObjectFormat
*********************************************************************************************************/
function changeMyFormSubmit( id, functionName )
{
  var obj = ( getObjectFormat( id ).tagName.toLowerCase( ) == 'form' )?getObjectFormat( id ):getObjectFormat( id ).form;
  var origOnSubmit = obj.onsubmit;
  
  if ( arguments.length == 3 && arguments[2] )
  {
    obj.onsubmit = function( ){ return ( functionName( ) && origOnSubmit( ) ); };
  }
  else
  {
    obj.onsubmit = function( ){ x = functionName( ); y = origOnSubmit( ); return ( x && y ); };
  }
}

/*********************************************************************************************************
  This function sets the browsers focus to on the object id provided.
  DEPENDS ON: getObjectFormat
*********************************************************************************************************/
function setFocus( oId )
{
  setTimeout( 'var o = getObjectFormat( "' + oId + '" );if( o.select )o.select( );o.focus( );', 1 );
}

/*********************************************************************************************************
  This function gets the correct clientHeight for the browser window.
  DEPENDS ON: none
*********************************************************************************************************/
function canvasHeight( obj )
{
   var height = null;
   if ( window.innerHeight )
   {
      height = window.innerHeight;
   }
   else
   {
      var oDoc = obj.ownerDocument;
      var oBody = oDoc.body;
      height = oBody.clientHeight;
      
      if ( height == 0 )
      {
         var oHtml = oDoc.documentElement;
         height = oHtml.clientHeight;
      }
   }
   
   return height;
}



/*********************************************************************************************************
**********************************************************************************************************
**********************************************************************************************************
                  PROTOTYPE FUNCTIONS BELOW
**********************************************************************************************************
**********************************************************************************************************
*********************************************************************************************************/

/*********************************************************************************************************
  This prototyp allows you to check that a number resides within a specified range.  The range numbers
  are included in the allowable values.  This function will return true if the numbers value is within
  the specified range, otherwise it returns false.
  DEPENDS ON: none
*********************************************************************************************************/
Number.prototype.checkRange = function ( min, max )
{
  if ( min <= this.valueOf( ) && this.valueOf( ) <= max )
  {
    return true;
  }
  
  return false;
}

/*********************************************************************************************************
  This prototype fixes inconsistencies in the string.split method across various browsers.
  DEPENDS ON: none
*********************************************************************************************************/
/*
	Cross-Browser Split 0.2.1
	By Steven Levithan <http://stevenlevithan.com>
	MIT license
*/
var nativeSplit = nativeSplit || String.prototype.split;

String.prototype.split = function ( s /* separator */, limit )
{
	// If separator is not a regex, use the native split method
	if ( !( s instanceof RegExp ) )
	{
		return nativeSplit.apply( this, arguments );
	}
	else
	{
     	/* Behavior for limit: If it's...
     	 - Undefined: No limit
     	 - NaN or zero: Return an empty array
     	 - A positive number: Use limit after dropping any decimal
     	 - A negative number: No limit
     	 - Other: Type-convert, then use the above rules */
  	
     	if ( limit === undefined || +limit < 0 )
     	{
     		limit = false;
     	}
     	else
     	{
     		limit = Math.floor( +limit );
     		if ( !limit )
     		{
     			return [];
     		}
     	}
     	
  	   var  flags = ( s.global ? "g" : "" ) + ( s.ignoreCase ? "i" : "" ) + ( s.multiline ? "m" : "" );
  		var  s2 = new RegExp( "^" + s.source + "$", flags );
  		var  output = [];
  		var  lastLastIndex = 0;
  		var  i = 0;
  		var  match;
  	
  		if ( !s.global )
     	{
     		s = new RegExp( s.source, "g" + flags );
     	}

     	while ( ( !limit || i++ <= limit ) && ( match = s.exec( this ) ) )
  	   {
         var zeroLengthMatch = !match[0].length;
         
         // Fix IE's infinite-loop-resistant but incorrect lastIndex
         if ( zeroLengthMatch && s.lastIndex > match.index )
         {
          s.lastIndex = match.index; // The same as s.lastIndex--
         }
         
         if ( s.lastIndex > lastLastIndex )
         {
            // Fix browsers whose exec methods don't consistently return undefined for non-participating capturing groups
            if ( match.length > 1 )
            {
  				   match[0].replace(s2, function ()
     				                     {
                                       for ( var j = 1; j < arguments.length - 2; j++ )
                                       {
                                          if ( arguments[j] === undefined )
                                          {
                                             match[j] = undefined;
                                          }
                                       }
     				                     }
     		                       );
        		}
        			
        		output = output.concat( this.slice( lastLastIndex, match.index ), ( match.index === this.length ? [] : match.slice( 1 ) ) );
        		lastLastIndex = s.lastIndex;
        	}
        	
        	if ( zeroLengthMatch )
        	{
        		s.lastIndex++;
        	}
      }
   
      return ( lastLastIndex === this.length ) ? ( s.test( "" ) ? output : output.concat( "" ) ) : ( limit      ? output : output.concat( this.slice( lastLastIndex ) ) );
   }
};

String.prototype.pad = function( len, pad, where )
{
   // This function returns a string paded to the requested length
   // using the padding string requested.
   // If the string is already longer than the requested length
   // it is returned unchanged.
   // The first parameter is the length of the returned string.
   // The second parameter is the padding string.  If this string is
   // empty, a space is used for the padding string.
   // The third parameter is the padding location.
   //    0 - Pad on the left
   //          (Right aligns the initial string in the result.)
   //    1 - Pad on the right
   //          (Left aligns the initial string in the result.)
   //    2 - Pad on the left and right
   //          (Center aligns the initial string in the result
   //           with any odd padding character on the left.)
   var sPad; 
   var sPadding; 
   var lPadding; 
   var sResult;
   
   lPadding = len - this.length;
   if ( lPadding > 0 )
   {
      if ( pad )
      { 
         sPad = pad;
      }
      else 
      {
         sPad = '';
      }
      
      sPadding = new Array( Math.ceil( lPadding / sPad.length ) + 1 );
      sPadding = sPadding.join( sPad );
      switch ( where )
      {
         case 0: // Left Padding - Right Align
               sResult = sPadding + this;
            break;
         
         case 1: // Right Padding - Left Align
               sResult = this + sPadding;
            break;
         
         default: // Left & Right Padding - Center Align
               sResult = sPadding.substr( 0, lLeft ) + this + sPadding.substr( lLeft, lPadding - lLeft );
            break;
      }
   }
   else
   { 
      sResult = this;
   }
   
   return sResult;
}

String.prototype.trim = function()
{
   return this.replace(/^\s*|\s*$/g,"");
}

/*********************************************************************************************************
  This prototype allows you to check if an array contains a value.
  Returns true if it does or false if it does not.
  DEPENDS ON: none
*********************************************************************************************************/
Array.prototype.in_array = function( vNeedle /*, bIndex*/ )
{
   var bFlag = false;
   for ( var ndx = 0; ndx < this.length; ndx++ )
   {
      if ( this[ndx]==vNeedle )
      {
         if ( arguments.length>1 && arguments[1] )
         {
            bFlag = ndx;
         }
         else
         {
            bFlag = true;
         }
         
         break;
      }
   }
   
   return bFlag;
}
// -->