<!--
/**********************************************************************
** Purpose: Changes the source of a specified image in the document
**
** Params:  Name of image to swap
**          Source of the new image
**
** Returns: n/a
***********************************************************************/

function imageSwap(vp_imageName_str,
                   vp_newSource_str)
{
    var vl_newImage;
    eval("vl_newImage = document.images." + vp_imageName_str);
    vl_newImage.src = vp_newSource_str;
}

/**********************************************************************
** Purpose: Creates an image object to force loading of the image
**
** Params:  A string referring to the image to load
**
** Returns: n/a
***********************************************************************/

function preloadSingle(vp_imageName_str)
{
    var vl_imageObj = new Image();
    vl_imageObj.src = vp_imageName_str;
}

/**********************************************************************
** Purpose: Creates an image object to force loading of the image for
**          multiple images
**
** Params:  An array of strings referring to the images to load
**
** Returns: n/a
***********************************************************************/

function preloadArray(vp_imageNames_a)
{
    var vl_loopCtr_i;
    var vl_imageObj = new Array();
    for(vl_loopCtr_i = 0; vl_loopCtr_i < vp_imageNames_a.length; vl_loopCtr_i++)
    {
        vl_imageObj[vl_loopCtr_i] = new Image();
        vl_imageObj[vl_loopCtr_i].src = vp_imageNames_a[vl_loopCtr_i];
    }
}

/**********************************************************************
** Purpose: Creates a 2D array (3 x n) used to store rollover
**          information for a collection of images.
**
** Params:  None.
**
** Returns: 2D array
***********************************************************************/

function makeRolloverCollection()
{
    var vl_newArray_a = new Array(3);
    vl_newArray_a[0] = new Array();
    vl_newArray_a[1] = new Array();
    vl_newArray_a[2] = new Array();
    return vl_newArray_a;
}

/**********************************************************************
** Purpose: Adds rollover information for an image to the next free 
**          element in an array create with the above.
**
** Params:  The name of the image
**          The "on" source
**          The "off" source
**          The collection array to store it in.
**
** Returns: 2D array
***********************************************************************/

function addToRolloverCollection(vp_name_str,
                                 vp_onSrc_str,
                                 vp_offSrc_str,
                                 vp_collection_a)
{
    var vl_location_i = vp_collection_a[0].length;
    vp_collection_a[0][vl_location_i] = vp_name_str;
    vp_collection_a[1][vl_location_i] = vp_onSrc_str;
    vp_collection_a[2][vl_location_i] = vp_offSrc_str;
    return vp_collection_a;
}

/**********************************************************************
** Purpose: Image swaps the images in a collection.
**
** Params:  The collection to swap
**          The direction to swap (1=turn on, 2=turn off)
**
** Returns: 2D array
***********************************************************************/

function imageSwapCollection(vp_collection_a,
                             vp_direction_i)
{
    var vl_loopCtr_i;
    
    for(vl_loopCtr_i = 0; vl_loopCtr_i < vp_collection_a[0].length; vl_loopCtr_i++)
    {
        imageSwap(vp_collection_a[0][vl_loopCtr_i],
             vp_collection_a[vp_direction_i][vl_loopCtr_i]);
    }
}

/**********************************************************************
** Purpose: Takes an integer and converts it to an equivalent integer
**          of a certain length - this is done by appending '0's to
**          the number as required.
**
** Params:  The integer to convert
**          The desired length of the integer
**
** Returns: The integer converted to the required length
***********************************************************************/

function toXDigits(vp_value_i,
                   vp_digits_i)
{
    var vl_returnVal_str = '' + vp_value_i;
    
    while(vl_returnVal_str.length < vp_digits_i) 
    {
        vl_returnVal_str = '0' + vl_returnVal_str;
    }

    return vl_returnVal_str;
}    

//**********************************************************************
//* Purpose: Inserts a string at the current position in the last
//*          selected text area. The text area in question must be using
//*          the storeCaretPos as described in its comment below
//*
//* Params:  String to insert
//*
//* Returns: None
//***********************************************************************
function insertAtTextAreaCaret(vp_insertText_str)
{
    if(vm_lastTextArea != null)
    {
        if ((vm_lastTextArea.createTextRange) &&
            (vm_lastTextArea.caretPos))
        {
            var caretPos = vm_lastTextArea.caretPos;
            caretPos.text =
                caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? vp_insertText_str + ' ' : vp_insertText_str;
        }
        else
        {
            vm_lastTextArea.value  = text;
        }

        // Return focus to the TextArea
        vm_lastTextArea.focus();
    }
}

//**********************************************************************
//* Purpose: Helper function for the insertAtTextAreaCaret method above.
//*          Any text area that wishes to use the functionality that
//*          is provided by that function must add
//*              OnSelect="storeTextAreaCaretPos(this);"
//*              OnClick="storeTextAreaCaretPos(this);"
//*              OnKeyUp="storeTextAreaCaretPos(this);"
//*	     to its definition.
//*
//* Params:  The text area to store the position of
//*
//* Returns: None
//***********************************************************************
var vm_lastTextArea = null;

function storeTextAreaCaretPos(vp_textArea)
{
    if (vp_textArea.createTextRange)
    {
         vp_textArea.caretPos = document.selection.createRange().duplicate();
    }
    vm_lastTextArea = vp_textArea;
}

//**********************************************************************
//* Purpose: Determines whether a particular e-mail address is valid
//*          or not.
//*
//* Params:  The e-mail address to validate
//*
//* Returns: true if the e-mail address is valid, else false
//***********************************************************************
function isValidEmailAddr(vp_emailAddr_str)
{
    var vl_returnVal_z = true;
    var vl_atPos_i = vp_emailAddr_str.indexOf('@');
    var vl_length_i = vp_emailAddr_str.length;

    if ((vl_returnVal_z == true) &&
        (vp_emailAddr_str.indexOf('@') == -1))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        ((vp_emailAddr_str.indexOf('@') == -1) ||
         (vp_emailAddr_str.indexOf('@') == 0) ||
         (vp_emailAddr_str.indexOf('@') == vl_length_i)))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        ((vp_emailAddr_str.indexOf('.') == -1) ||
         (vp_emailAddr_str.indexOf('.') == 0) ||
         (vp_emailAddr_str.indexOf('.') == vl_length_i)))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        (vp_emailAddr_str.indexOf('@',(vl_atPos_i + 1)) != -1))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        ((vp_emailAddr_str.substring(vl_atPos_i - 1, vl_atPos_i) == '.') ||
         (vp_emailAddr_str.substring(vl_atPos_i + 1, vl_atPos_i + 2) == '.')))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        (vp_emailAddr_str.indexOf('.', (vl_atPos_i + 2)) == -1))
    {
       vl_returnVal_z = false;
    }

    if ((vl_returnVal_z == true) &&
        (vp_emailAddr_str.indexOf(" ") != -1))
    {
       vl_returnVal_z = false;
    }

    return vl_returnVal_z;
}

//**********************************************************************
//* Purpose: Determines whether a particular password is valid or not.
//*
//* Params:  The password to validate
//*
//* Returns: true if the password address is valid, else false
//***********************************************************************
function isValidPassword(vp_password_str)
{
   var vl_validChars_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
   var vl_currentChar_str;
   var vl_result_z = true;

   if (vp_password_str.length == 0 | vp_password_str.length < 4 | vp_password_str.length > 8)
   {
       return false;
   } 
   
   //  test vp_password_str consists of valid characters listed above
   for (i = 0; i < vp_password_str.length && vl_result_z == true; i++)
   {
      vl_currentChar_str = vp_password_str.charAt(i);
      if (vl_validChars_str.indexOf(vl_currentChar_str) == -1)
      {
         vl_result_z = false;
      }
   }
   
   return vl_result_z;
}

//**********************************************************************
//* Purpose: Determines whether a particular number is numeric or not.
//*
//* Params:  The number to validate
//*
//* Returns: true if the number is numeric, else false
//***********************************************************************
function isNumeric(vp_number_str)
   //  check for valid numeric strings	
{
   var vl_validChars_str = "0123456789";
   var vl_currentChar_str;
   var vl_result_z = true;

   if (vp_number_str.length == 0) return false;

   //  test vp_number_str consists of valid characters listed above
   for (i = 0; i < vp_number_str.length && vl_result_z == true; i++)
   {
   
      vl_currentChar_str = vp_number_str.charAt(i);
      
      if (vl_validChars_str.indexOf(vl_currentChar_str) == -1)
      {
         vl_result_z = false;
      }
   }
   
   return vl_result_z;
}

/**********************************************************************
** Purpose: Launches a popup window
**
** Params:  The url, width and height of the window
**          Booleans that determines whether the popup should be
**          resizeable, scrollable, show status bar and show menu.
**
** Returns: A reference to the window
***********************************************************************/

function popup(vp_url_str,
               vp_width_i,
               vp_height_i,
               vp_resize_z,
               vp_scroll_z,
               vp_status_z,
               vp_menu_z)
{
  // Generate a unique name for the window
  var vl_now = new Date();
  var vl_minutes_i = vl_now.getMinutes();
  var vl_seconds_i = vl_now.getSeconds();
  var vl_timestamp_str = "" + vl_minutes_i + vl_seconds_i;

  // Determine resizeable value
  var vl_resize_str;
  var vl_scroll_str;
  var vl_status_str;
  var vl_menu_str;

  var vl_left_i, vl_top_i;
  if((screen.width != null) && (screen.height != null))
  {
    vl_left_i = parseInt((screen.width - vp_width_i) / 2);
    vl_top_i = parseInt((screen.height - vp_height_i) / 2);

    if(screen.width < vp_width_i)
    {
      vp_width_i = screen.width - 10;
      vp_resize_z = true;
      vl_left_i = 5;
    }

    if(screen.height < vp_height_i)
    {
      vp_height_i = screen.height - 10;
      vp_resize_z = true;
      vl_top_i = 5;
    }
  }
  else
  {
    vl_left_i = 100;
    vl_top_i = 100;
  }

  if(vp_resize_z == true)
  {
    vl_resize_str = "1";
  }
  else
  {
    vl_resize_str = "0";
  }
   
  if(vp_scroll_z == true)
  {
    vl_scroll_str = "1";
  }
  else
  {
    vl_scroll_str = "0";
  }
   
  if(vp_status_z == true)
  {
    vp_status_str = "1";
  }
  else
  {
    vp_status_str = "0";
  }
   
  if(vp_menu_z == true)
  {
    vp_menu_str = "1";
  }
  else
  {
    vp_menu_str = "0";
  }

  var vl_window =  window.open(vp_url_str,vl_timestamp_str,
                               "toolbar=0,location=0,directories=0,status=" + vp_status_str + ",menubar=" + vp_menu_str + ",scrollbars=" + vl_scroll_str +
                               ",resizable=" + vl_resize_str + ",top=" + vl_top_i + ",left=" + vl_left_i + ",width=" + vp_width_i + ",height=" + vp_height_i);
  vl_window.focus();
  return vl_window;
}
//-->
