<!--
/**********************************************************************
** 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: 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: 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;
}
//-->