/**********************************************************************
** 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: 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: Sets a Cookie with the given name and value.
**
** Params:
**     name       Name of the cookie
**     value      Value of the cookie
**     [expires]  Expiration date of the cookie 
**                (default: end of current session)
**     [path]     Path where the cookie is valid 
**                (default: path of calling document)
**     [domain]   Domain where the cookie is valid
**                (default: domain of calling document)
**     [secure]   Boolean value indicating if the cookie transmission 
**                requires a secure transmission
**
** Returns: none.
***********************************************************************/
function setCookie(vp_name_str,
                   vp_value_str,
                   vp_expires_d,
                   vp_path_str,
                   vp_domain_str,
                   vp_secure_z)
{
    document.cookie = vp_name_str + "=" + escape(vp_value_str) +
                     ((vp_expires_d) ? "; expires=" + vp_expires_d.toGMTString() : "") +
                     ((vp_path_str) ? "; path=" + vp_path_str : "") +
                     ((vp_domain_str) ? "; domain=" + vp_domain_str : "") +
                     ((vp_secure_z) ? "; secure" : "");
}

/**********************************************************************
** Purpose: Gets the value of the specified cookie.
**
** Params:
**     name  Name of the desired cookie.
**
** Returns: a string containing value of specified cookie,
**          or null if cookie does not exist.
***********************************************************************/
function getCookie(vp_name_str)
{
    var vl_documentCookie = document.cookie;
    var vl_prefix_str = vp_name_str + "=";
    var vl_begin_i = vl_documentCookie.indexOf("; " + vl_prefix_str);
    var vl_returnVal_str = "";

    if (vl_begin_i == -1)
    {
        vl_begin_i = vl_documentCookie.indexOf(vl_prefix_str);

        if (vl_begin_i != 0)
        {
            vl_returnVal_str = null;
        }
    }
    else
    {
        vl_begin_i = vl_begin_i + 2;
    }

    if(vl_returnVal_str != null)
    {
        var vl_end_i = vl_documentCookie.indexOf(";", vl_begin_i);

        if (vl_end_i == -1)
        {
            vl_end_i = vl_documentCookie.length;
        }

        vl_returnVal_str = unescape(vl_documentCookie.substring(vl_begin_i + vl_prefix_str.length, vl_end_i));
    }

    return vl_returnVal_str;
}

/**********************************************************************
** Purpose: Deletes the specified cookie.
**
** Params:
**   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)
**
** Returns: none.
***********************************************************************/
function deleteCookie(vp_name_str, vp_path_str, vp_domain_str)
{
    if (getCookie(vp_name_str) != null)
    {
        document.cookie = vp_name_str + "=" + 
                          ((vp_path_str) ? "; path=" + vp_path_str : "") +
                          ((vp_domain_str) ? "; domain=" + vp_domain_str : "") +
                          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}