// start platform and browser detection variables
var ie = (document.all) ? true : false;
var ns = (document.layers) ? true : false;
var moz = (document.getElementById && !document.all) ? true : false;

var platform = (navigator.platform.toLowerCase().indexOf("mac") >= 0) ? "mac" : "win";
var browser = (ns) ? "ns" : "ie";
// end browser detection variables


// start common functions
function openPrivacyWin() {
    var myWin = window.open("http://www.merck.com/policy/privacy/home.html","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=477,height=400")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openPrivacyWinSpanish() {
    var myWin = window.open("http://www.merck.com/policy/privacy/sp_policy.html","Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openPrivacyWinAppendQueryString(queryString) {
    var myWin = window.open("http://www.merck.com/policy/privacy/home.html" + queryString,"Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openPrivacyWinAppendQueryStringSpanish(queryString) {
    var myWin = window.open("http://www.merck.com/policy/privacy/sp_policy.html" + queryString,"Healthcare","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=631,height=400")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openPAPWin() {
    var myWin = window.open("http://www.merck.com/program/pap/","Physician","toolbar=no,scrollbars=1,location=no,statusbar=0,menubar=0,resizable=1,width=760,height=480")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openExternalWin(product, url) {
    if(! confirm("Thank you for visiting " + product + ".com.\n\nMerck does not review or control the content at the site to which this hyperlink connects;\ntherefore, this hyperlink does not constitute an endorsement by Merck of the content of any\nnon-Merck site.\n\nDo you wish to continue?"))
        return false;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
        externalWin.opener=window;
    externalWin.opener.name="opener";
    return false;
}

function openExternalWinMerckSchering(product, url) {
    if(! confirm("Thank you for visiting " + product + ".com.\n\nMerck/Schering-Plough does not review or control the content at the site to which this\nhyperlink connects; therefore, this hyperlink does not constitute an endorsement by\nMerck/Schering-Plough of the content of any non-Merck/Schering-Plough site.\n\nDo you wish to continue?"))
        return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
        externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openExternalWinSpanish(product, url) {
    if(! confirm("¡Gracias por visitar " + product + ".com!\n\nMerck no revisa ni controla el contenido del sitio al que lo llevará este hiperenlace;\npor lo tanto, este hiperenlace no significa que Merck respalde el contenido de cualquier sitio que\nno sea de Merck.\n\n¿Usted desea continuar?"))
        return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
        externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openExternalWinMerckScheringSpanish(product, url) {
    if(! confirm("Gracias por visitar " + product + ".com.\n\nMerck/Schering-Plough no analiza ni controla el contenido del sitio al cual lo llevará este hiperenlace.\nPor lo tanto, este hiperenlace no constituye un respaldo de parte de\nMerck/Schering-Plough del contenido de cualquier sitio que no sea de Merck/Schering-Plough.\n\n¿Desea continuar?"))
        return;

    var externalWin = window.open(url,null,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500");
    if (externalWin.opener == null)
        externalWin.opener=window;
        externalWin.opener.name="opener";
}

function openPopup(url) {
    var popupWin = window.open(url,null,"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=566,height=400");
    if (popupWin.opener == null)
        popupWin.opener=window;
        popupWin.opener.name="opener";
}

function openRCGateway(url,transferURL) {
    if (getCookie('RCGatewayTerms')) {
        window.location = transferURL;
    } else {
        var popupWin = window.open(url + '?transfer=' + transferURL,null,"toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=566,height=305");
        if (popupWin.opener == null)
            popupWin.opener=window;
            popupWin.opener.name="opener";
    }
}

function openMedWatch() {
    var myWin = window.open("http://www.merck.com/consumer/side_effects/","MedWatch","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=450,height=450")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function openPharmaCode(url) {
    var myWin = window.open(url,"PharmaCode","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=200")
    if (myWin.opener == null)
        myWin.opener = window;
    myWin.opener.name = "opener";
}

function activate(imgName) {
    if (document.images)
        var last_position = document[imgName].src.lastIndexOf("_");
        if(document[imgName].src.substr(last_position+1,2).toLowerCase().indexOf("on") < 0)
        document[imgName].src = eval("btn_" + imgName + "_over.src");
}

function inactivate(imgName) {
    if (document.images)
        var last_position = document[imgName].src.lastIndexOf("_");
        if(document[imgName].src.substr(last_position+1,2).toLowerCase().indexOf("on") < 0)
        document[imgName].src = eval("btn_" + imgName + "_off.src");
}

function openInParentWin(url) {
    parent.opener.location.href=url;
    parent.opener.focus();
    //parent.self.close();
}

function allowSubmission(theForm) {
    return (theForm.redirectPage.selectedIndex > 0);
}

function changeParentLocation(url) {
    opener.location.href = url;
    opener.name = "opener";
    opener.focus();
}

function gotoMerck() {
    if (window.name == "Healthcare") //the HCP consent popup
        self.close()

    window.open("http://www.merck.com","merck","");
    /*if (opener != null) {
        if (opener.closed) {
            if (window.name == "merck")
                window.name = "main";

            window.open("http://www.merck.com","merck","");
        } else {
            opener.location.href="http://www.merck.com";
            self.close();
        }
    } else {
        window.location.href="http://www.merck.com";
    }*/

    return false;
}

function AttachEvent(obj,evt,fnc,useCapture){
    if (obj.addEventListener){
        obj.addEventListener(evt,fnc,useCapture);
        return true;
    } else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
    else if (obj['on'+evt]){
        //this untested, designed not to whack existing inline code for old browsers
        obj['old_on'+evt]=obj['on'+evt];
        obj['new_on'+evt]=fnc;
        obj['on'+evt]=new Function("this.old_on"+evt+"(); this.new_on"+evt+"();");
    }else obj['on'+evt]=fnc;
}

/**
 * Sets a Cookie with the given name and value.
 *
 * 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
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toUTCString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Sets a Cookie with the given name and value.
 *
 * cookieName       Name of the cookie
 * cookieValue      Value of the cookie
 * nDays            Expiration date of the cookie
 * path             Path where the cookie is valid
 */
function createCookie(cookieName, cookieValue, nDays, path) {
     var today = new Date();
     var expire = new Date();
     if (nDays==null || nDays==0) nDays=1;
     expire.setTime(today.getTime() + 3600000*24*nDays);
     document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString()+";path=" + path;
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * 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)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=0";
    }
}

/*
* Busy-wait (pause) for the specified number of milliseconds.
*/
function pause(millisec) {
    var timeNow = new Date();
    var timeDone = timeNow.getTime() + millisec;
    while (true) {
        timeNow = new Date();
        if (timeNow.getTime() > timeDone)
            return;
    }
}

/*
* Generate server-side access log metrics for a simulated page hit.
* Call 'pause' after this if the browser is being redirected to a new page.
*/
function trackPageHit(url) {
    if (document.images) {
        var newImage = new Image;
        newImage.src = url;
        pause(100); // Needed for IE6
    }
}

// end common functions



/************************************************************************************
DESCRIPTION: Change font size of disclaimer text upon selecting state 'TX' or 'CA'

PARAMETERS:
    fname - form name
    textid - Existing css ID or Class of disclaimer text (make sure to remove any font-size from this style.
    ******CREATE TWO CLASSES WITH DEFAULT AND LARGE FONT SIZES****
    class1 - Default font size class (normally 12px)
    class2 - Large font size class (normally 14pt)  *make sure its PT not PX
************************************************************************************/
function changeFontSize(fname,textid,class1,class2) {
    var i = document[fname].state.selectedIndex;
    var st = document[fname].state.options[i].value;

    if((st=="CA") || (st=="TX")) {
        if (document.getElementById) {
            document.getElementById(textid).className = class2;
            }
    } else {
        if (document.getElementById) {
            document.getElementById(textid).className = class1;
            }
        }
    }


/**********************************************************************************/
/****************  New global validation functions added 09/21/07  ****************/
/* *** 01/02/2008 -- Fixed validation for Phone/isNumeric -- GS *******************/
/**********************************************************************************/


/***********************************************************
DESCRIPTION: Removed leading and trailing spaces
PARAMETERS:  s - String to be modified
RETURNS:     string with no leading or trailing spacess
************************************************************/
function globalTrim(s)
{
    var str = s.replace(/^\s+/,'');
    str = str.replace(/\s+$/,'');
    return str;
}
/***********************************************************
DESCRIPTION: Checks if a string is empty
PARAMETERS:  strValue - String to be tested for validity
RETURNS:     True if valid (empty), otherwise false (not empty).
************************************************************/
function isGlobalEmpty(field)
{
    if (field == undefined)
    {
        return true;
    }
    strValue = globalTrim(field.value);
    if(strValue.length > 0) return false;
    return true;
}

/***********************************************************
DESCRIPTION: Checks if a string is a minimum length
PARAMETERS:  strValue  - String to be tested for validity
             minLength - Minimum length of string
RETURNS:     True if valid (length greater than minLength), otherwise false (not longer than minLength).
************************************************************/
function isGlobalMinLength(field,minLength)
{
    if (field == undefined)
    {
        return true;
    }
    strValue = globalTrim(field.value);
    if(strValue.length >= minLength) return false;
    return true;
}

/************************************************
DESCRIPTION: Validates that a string is a United States zip code in 5 digit format
             or zip+4 format. The following are acceptable:
             12345
             12345-1234
             12345+1234
             12345 1234
             123451234
PARAMETERS:  strValue - String to be tested for validity
RETURNS:     True if valid, otherwise false.
*************************************************/
function isGlobalValidUSZip(strValue)
{
    if (globalTrim(strValue).search(/(^\d{5}$)|(^\d{5}-\d{4}$)|(^\d{5}\+\d{4}$)|(^\d{5}\W+\d{4}$)|(^\d{9}$)/) == -1) return false;
    return true;
}

/************************************************
DESCRIPTION: check whether text entered by a user is numeric.
PARAMETERS:  sText - Source string
RETURNS:     True or false.
*************************************************/
function isGlobalNumeric(field)
{
    var ValidChars = "0123456789.";
    var isNumber=true;
    var Char;
    var sText;
    if (typeof field == 'string')
    {
        sText = globalTrim(field);
    }
    else
    {
        sText = globalTrim(field.value);
    }

    for (i = 0; i < sText.length && isNumber == true; i++)
    {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            isNumber=false;
        }
    }
    return isNumber;
}

/***************************************************************
DESCRIPTION: check whether the at least on checkbox is checked
PARAMETERS:  checkBoxList - field name
RETURNS:     True or false.
****************************************************************/
function isGlobalChecked(checkBoxList)
{
    var checked = false;

    if (checkBoxList != undefined)
    {   //Tip = must use as array to check the status i.e. allcheck[].checked instead of allcheck.checked
        for(i=0;i<checkBoxList.length;i++)
        {
            if(checkBoxList[i].checked)
            {
                checked = true;
                i = checkBoxList.length;
            }
        }
    }
    return checked;
}

/*******************************************************
DESCRIPTION: Check that a string contains only letters
PARAMETERS:  strValue - Source string
RETURNS:     True or false.
******************************************************/
function isGlobalAlphabetic(strValue)
{
   if ((strValue != undefined) && (strValue.search))
   {
      strValue = globalTrim(strValue);
      if(strValue.replace(" ", "").search(/[^a-zA-Z]/) != -1)
      {
          return false
      }
   }
   return true;
}

/*******************************************************
DESCRIPTION: Check that the string is a valid email address
PARAMETERS:  strValue - Source string
RETURNS:     True or false.
******************************************************/
function isGlobalValidEmailAddress(email,engMessage)
{
    var errMessage     = "";
    var x              = email.search(/ /);
    var y              = email.search(/,/);
    var z              = email.search(/;/);
    var englishMessage = true;
    if ((typeof engMessage != 'undefined') && (!engMessage))
    {
        englishMessage=false;
    }

    if ((x != -1) || (y != -1) || (z != -1))
    {   // Check for more than one email address
        isErr       = true;
        if (englishMessage)
        {
            errMessage += "You are only allowed to enter one e-mail address at a time.\r\n";
        }
        else
        {
            errMessage += "Sólo puede ingresarse una dirección de correo electrónico..\r\n";
        }
    }
    if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.([A-Za-z0-9]{2,3})$/) == -1)
    {   // Check for valid email address
        isErr       = true;
        if (englishMessage)
        {
            errMessage += "Please enter a valid e-mail address\r\n";
        }
        else
        {
            errMessage += "Ingrese una dirección de correo electrónico válida\r\n";
        }
    }

    return errMessage
}

/**************************************************************************************************/
/****  Global function to support common field validation
/****  DESCRIPTION: Check all required fields exist.
/****               Check all fields needing formatting are correct
/****  PARAMETERS:  thisForm - form containing input fields
/****               localErrors - text string containing errors from a location validation function
/****  RETURNS:     True or false.
/**************************************************************************************************/
function globalValidateFields(thisForm)
{
    return globalValidateFields(thisForm,"");
}
function globalValidateFields(thisForm,localErrors)
{
    return globalValidateFields(thisForm,"",'en');
}
function globalValidateFields(thisForm,localErrors,lang)
{
    return globalValidateFields(thisForm,"",'en',false);
}
function globalValidateFields(thisForm,localErrors,lang,returnMessage)
{
    // Set variables
    var isErr      = false; // for any type of error
    var errMessage = "";
    var errField   = "";    // if there is an error, focus on the first required form field error
    var englishMessage=true;
    if ((typeof lang != 'undefined') && (lang.toLowerCase() == 'es'))
    {
        englishMessage=false;
    }

    var requiredFields  = thisForm.reqf.value;
//alert('requiredFields='+requiredFields);

    // *******************
    // Check for firstname
    // *******************
    if (requiredFields.indexOf('firstname') >= 0)
    {
        if(isGlobalEmpty(thisForm.firstname))
        {   // firstname field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a first name.\r\n";
            }
            else
            {
                errMessage += "Ingrese un nombre.\r\n";
            }
            if (errField.length <= 0) errField = "firstname";
        }
    }

    // ******************
    // Check for lastname
    // ******************
    if (requiredFields.indexOf('lastname') >= 0)
    {
        if(isGlobalEmpty(thisForm.lastname))
        {   // lastname field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a last name that is at least 2 characters long.\r\n";
            }
            else
            {
                errMessage += "Ingrese un apellido de, al menos, dos caracteres.\r\n";
            }
            if (errField.length <= 0) errField = "lastname";
        }
        else if(isGlobalMinLength(thisForm.lastname,2))
        {   // lastname must have at least 2 characters (CPM requirement)
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a last name that is at least 2 characters long.\r\n";
            }
            else
            {
                errMessage += "Ingrese un apellido de, al menos, dos caracteres.\r\n";
            }
            if (errField.length <= 0) errField = "lastname";
        }
    }

    // ****************
    // Check for gender
    // ****************
    if (requiredFields.indexOf('gender') >= 0)
    {
        var valueSelected = isGlobalChecked(thisForm.gender);
        if (!valueSelected)
        {
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please select male or female\r\n";
            }
            else
            {
                errMessage += "Seleccione masculino o femenino\r\n";
            }
            if (errField.length <= 0) errField = "gender";

        }
    }

    // ***************
    // Check for email
    // ***************
    if (requiredFields.indexOf('email') >= 0)
    {
        if (isGlobalEmpty(thisForm.email))
        {  // email field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply an email address.\r\n";
            }
            else
            {
                errMessage += "Ingrese una dirección de correo electrónico.\r\n";
            }
            if (errField.length <= 0) errField = "email";
        }
    }

    // ***************************************************************
    // Check email is in the proper format and only one email in field
    // ***************************************************************
    if (thisForm.email != undefined)
    {
        if (!isGlobalEmpty(thisForm.email))
        {   // email field contains a value
            var email = globalTrim(thisForm.email.value);
            var msg = isGlobalValidEmailAddress(email,englishMessage)
            if (0 < msg.length)
            {
                isErr = true;
                errMessage += msg;
                if (errField.length <= 0) errField = "email";
            }
        }
    }

    // ******************
    // Check for address1
    // ******************
    if (requiredFields.indexOf('address1') >= 0)
    {
        if(isGlobalEmpty(thisForm.address1))
        {   // address1 field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a street address, PO Box or apartment number.\r\n";
            }
            else
            {
                errMessage += "Ingrese un domicilio, apartado de correos o número de apartamento.\r\n";
            }
            if (errField.length <= 0) errField = "address1";
        }
    }

    // ******************
    // Check for address2
    // ******************
    if (requiredFields.indexOf('address2') >= 0)
    {
        if(isGlobalEmpty(thisForm.address2))
        {   // address2 field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a street address, PO Box or apartment number.\r\n";
            }
            else
            {
                errMessage += "Ingrese un domicilio, apartado de correos o número de apartamento.\r\n";
            }
            if (errField.length <= 0) errField = "address2";
        }
    }

    // ******************
    // Check for address3
    // ******************
    if (requiredFields.indexOf('address3') >= 0)
    {
        if(isGlobalEmpty(thisForm.address3))
        {   // address3 field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a street address, PO Box or apartment number.\r\n";
            }
            else
            {
                errMessage += "Ingrese un domicilio, apartado de correos o número de apartamento.\r\n";
            }
            if (errField.length <= 0) errField = "address3";
        }
    }

    // **************
    // Check for city
    // **************
    if (requiredFields.indexOf('city') >= 0)
    {
        if(isGlobalEmpty(thisForm.city))
        {   // city field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a city.\r\n";
            }
            else
            {
                errMessage += "Ingrese una ciudad.\r\n";
            }
            if (errField.length <= 0) errField = "city";
        }
    }

    // ***************
    // Check for state
    // ***************
    if (requiredFields.indexOf('state') >= 0)
    {
        if(thisForm.state.selectedIndex == 0)
        {
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please select a state.\r\n";
            }
            else
            {
                errMessage += "Seleccione un estado.\r\n";
            }
            if (errField.length <= 0) errField = "state";
        }
    }

    // ********************
    // Check for postalcode
    // ********************
    if (requiredFields.indexOf('postalcode') >= 0)
    {
        if(isGlobalEmpty(thisForm.postalcode))
        {   // postalcode field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply a zip code.\r\n";
            }
            else
            {
                errMessage += "Ingrese un código postal.\r\n";
            }
            if (errField.length <= 0) errField = "postalcode";
        }
    }

    // **************************************
    // Check for postalcode has only 5 digits
    // **************************************
    if (thisForm.postalcode != undefined)
    {
        if(!isGlobalEmpty(thisForm.postalcode))
        {
            var postalcode = thisForm.postalcode.value; // remove whitespace around value
            if (!isGlobalValidUSZip(postalcode))
            {   // Check zip code is in valid format
                isErr       = true;
                if (englishMessage)
                {
                    errMessage += "Please enter a valid ZIP Code containing only 5 digits.\r\n";
                }
                else
                {
                    errMessage += "Ingrese un código postal válido que sólo contenga 5 dígitos.\r\n";
                }
                if (errField.length <= 0) errField = "postalcode";
            }
        }
    }

    // ******************************
    // Check for postalcode extension
    // ******************************
    if (requiredFields.indexOf('postalcodeextension') >= 0)
    {
        if(isGlobalEmpty(thisForm.postalcodeextension))
        {   // postalcodeextension field is empty
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please enter your ZIP Code extension\r\n";
            }
            else
            {
                errMessage += "Ingrese su extensión de código postal\r\n";
            }
            if (errField.length <= 0) errField = "postalcodeextension";
        }
    }

    // *****************************************************
    // Check that the postalcode extension has only 4 digits
    // *****************************************************
    if (thisForm.postalcodeextension != undefined)
    {
        if(!isGlobalEmpty(thisForm.postalcodeextension))
        {
            if(thisForm.postalcodeextension.value.search(/(^\d{4}$)/) == -1)
            {
                isErr       = true;
                if (englishMessage)
                {
                    errMessage += "Please enter a valid 4 digit ZIP Code extension\r\n";
                }
                else
                {
                    errMessage += "Ingrese una extensión válida de código postal de 4 dígitos\r\n";
                }
                if (errField.length <= 0) errField = "postalcodeextension";
            }
        }
    }

    // *********************
    // Check for birth_month
    // *********************
    if (requiredFields.indexOf('birth_month') >= 0)
    {
        if(thisForm.birth_month.selectedIndex == 0)
        {
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply the month of the birth.\r\n";
            }
            else
            {
                errMessage += "Ingrese el mes de nacimiento.\r\n";
            }
            if (errField.length <= 0) errField = "birth_month";
        }
    }

    // *******************
    // Check for birth_day
    // *******************
    if (requiredFields.indexOf('birth_day') >= 0)
    {
        if(thisForm.birth_day.selectedIndex == 0)
        {
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply the day of the birth.\r\n";
            }
            else
            {
                errMessage += "Ingrese el día de nacimiento.\r\n";
            }
            if (errField.length <= 0) errField = "birth_day";
        }
    }

    // ********************
    // Check for birth_year
    // ********************
    if (requiredFields.indexOf('birth_year') >= 0)
    {
        if(thisForm.birth_year.selectedIndex == 0)
        {
            isErr       = true;
            if (englishMessage)
            {
                errMessage += "Please supply the year of the birth.\r\n";
            }
            else
            {
                errMessage += "Ingrese el año de nacimiento.\r\n";
            }
            if (errField.length <= 0) errField = "birth_year";
        }
    }

    // ********************
    // Check for home_phone
    // ********************
    if (requiredFields.indexOf('home_phone') >= 0)
    {
        if(isGlobalEmpty(thisForm.home_phone))
        {   // phone field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter your phone number.\r\n";
            }
            else
            {
                errMessage += "Ingrese su número telefónico.\r\n";
            }
            if (errField.length <= 0) errField = "home_phone";
        }
    }

    // **********************
    // Check for office_phone
    // **********************
    if (requiredFields.indexOf('office_phone') >= 0)
    {
        if(isGlobalEmpty(thisForm.office_phone))
        {   // phone field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter your phone number.\r\n";
            }
            else
            {
                errMessage += "Ingrese su número telefónico.\r\n";
            }
            if (errField.length <= 0) errField = "office_phone";
        }
    }

    // ***************************
    // Check for age range
    // ***************************
    if (requiredFields.indexOf('question(age_range)') >= 0)
    {
        var theList = document.getElementsByName('question(age_range)');
        var valueSelected=false;
        if (theList != undefined)
        {
            if (theList[0].selectedIndex > 0)
            {
                valueSelected=true;
            }
        }

        if(!valueSelected)
        {
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please select an age range\r\n";
            }
            else
            {
                errMessage += "Seleccione una age range\r\n";
            }
            if (errField.length <= 0) errField = "question(age_range)";
        }
    }


    // ***************************
    // Check for professional type
    // ***************************
    if (requiredFields.indexOf('question(proftype)') >= 0)
    {
        var theList = document.getElementsByName('question(proftype)');
        var valueSelected=false;
        if (theList != undefined)
        {
            if (theList[0].selectedIndex > 0)
            {
                valueSelected=true;
            }
        }

        if(!valueSelected)
        {
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter your Professional Designation\r\n";
            }
            else
            {
                errMessage += "Seleccione una designación profesional\r\n";
            }
            if (errField.length <= 0) errField = "question(proftype)";
        }
    }


    // ********************
    // Check for speciality
    // ********************
    if (requiredFields.indexOf('question(specialty)') >= 0)
    {
        var theList = document.getElementsByName('question(specialty)');
        var valueSelected=false;
        if (theList != undefined)
        {
            if (theList[0].selectedIndex > 0)
            {
                valueSelected=true;
            }
        }

        if(!valueSelected)
        {
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter your Specialty\r\n";
            }
            else
            {
                errMessage += "Seleccione una especialidad\r\n";
            }
            if (errField.length <= 0) errField = "question(specialty)";
        }
    }

    if ((localErrors != undefined) && (0 < localErrors.length))
    {
        isErr = true;
        errMessage += localErrors;
    }

    if (returnMessage)
    {
        if (isErr)
        {
            return errMessage;
        }
        else
        {
            return "";
        }
    }


    if (isErr)
    {
        alert(errMessage);
        if (0 < errField.length)
        {
            var f = document.getElementsByName(errField);
            f[0].focus();
        }
        return false;
    }
    else
    {
        return true;
    }
}

/**************************************************************************************************/
/****  Global function to support finding out if a question is answered
/****  DESCRIPTION: Return true if a question has an answer
/****  PARAMETERS:  questionName - name of the question
/****  RETURNS:     True or false.
/**************************************************************************************************/
function globalIsQuestionAnswered(questionName)
{
    var isAnswered = false;
    var question   = 'question(' + questionName + ')';

    var field = document.getElementsByName(question);
    if ((field) && (0 < field.length))
    {
        for(var i=0; i < field.length; i++)
        {
            if (field[i].checked)
            {
                isAnswered = true;
                break;
            }
        }
    }
    else
    {
        field = document.getElementsByName('multipleAnswerQuestion');
        for(var i=0; i < field.length; i++)
        {
            var value = field[i].value;
            if (0 <= value.indexOf(questionName))
            {
                if (field[i].checked)
                {
                    isAnswered = true;
                    break;
                }
            } // if (0 <= value.indexOf(question))
        } // for(var i=0; i < field.length; i++)
    } // if (field)

    return isAnswered;
}

/**************************************************************************************************/
/****  Global function to support user authentication
/****  DESCRIPTION: Check all required fields for user authentication
/****  PARAMETERS:  requestInfo - form containing input fields
/****  RETURNS:     True or false.
/**************************************************************************************************/
function globalValidateUser(thisForm)
{
    return globalValidateUser(thisForm,"");
}
function globalValidateUser(thisForm,localErrors)
{
    return globalValidateUser(thisForm,"",'en');
}
function globalValidateUser(thisForm,localErrors,lang)
{
    return globalValidateUser(thisForm,"",'en',false);
}
function globalValidateUser(requestInfo,localErrors,lang,returnMessage)
{
    // Set variables
    var isErr = false; // for any type of error
    var errMessage = "";
    var errField = ""; // if there is an error, focus on the first required form field error
    var requiredFields  = requestInfo.reqf.value;
    var englishMessage=true;
    if ((typeof lang != 'undefined') && (lang.toLowerCase() == 'es'))
    {
        englishMessage=false;
    }

    if (requiredFields.indexOf('username') >= 0)
    {
        if(isGlobalEmpty(requestInfo.username))
        {  // username field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter a username\n";
            }
            else
            {
                errMessage += "Ingrese un nombre de usuario\n";
            }
            if (errField.length <= 0) errField = "username";
        }
    }
    if (requiredFields.indexOf('password') >= 0)
    {
        if(isGlobalEmpty(requestInfo.password))
        {  // password field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter a password\n";
            }
            else
            {
                errMessage += "Ingrese una contraseña\n";
            }
            if (errField.length <= 0) errField = "password";
        }
    }
    if (requiredFields.indexOf('secondpassword') >= 0)
    {
        if(isGlobalEmpty(requestInfo.secondpassword))
        {  // secondpassword field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter a confirmation password\n";
            }
            else
            {
                errMessage += "Ingrese su contraseña nuevamente para validarla\n";
            }
            if (errField.length <= 0) errField = "secondpassword";
        }
    }
    if (requiredFields.indexOf('securityquestion') >= 0)
    {
        if(requestInfo.securityquestion.selectedIndex == 0)
        {
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please select a security question\n";
            }
            else
            {
                errMessage += "Elija una pregunta de seguridad\n";
            }
            if (errField.length <= 0) errField = "securityquestion";
        }
    }
    if (requiredFields.indexOf('securityanswer') >= 0)
    {
        if(isGlobalEmpty(requestInfo.securityanswer))
        {  // securityanswer field is empty
            isErr = true;
            if (englishMessage)
            {
                errMessage += "Please enter a security answer\n";
            }
            else
            {
                errMessage += "Ingrese una respuesta a su pregunta de seguridad\n";
            }
            if (errField.length <= 0) errField = "securityanswer";
        }
    }
    if ((localErrors != undefined) && (0 < localErrors.length))
    {
        isErr = true;
        errMessage += localErrors;
    }

    if (returnMessage)
    {
        if (isErr)
        {
            return errMessage;
        }
        else
        {
            return "";
        }
    }

    if (isErr)
    {
        alert(errMessage);
        if (0 < errField.length)
        {
            var f = document.getElementsByName(errField);
            f[0].focus();
        }
        return false;
    }
    else
    {
        return true;
    }
}



/**************************************************************************************************/
/****  Global function to support validating required fields for 'Send to a Friend' functionality
/****  DESCRIPTION: Check all required fields exist.
/****               Check email addresses are valid
/****  PARAMETERS:  sendto - form containing input fields
/****               localErrors - text string containing errors from a location validation function
/****  RETURNS:     True if valid, alert window with errors if false.
/**************************************************************************************************/
function globalValidateSend(sendto)
{
    // Set variables
    var isErr = false; // for any type of error
    var errMessage = "";
    var errField = ""; // if there is an error, focus on the first required form field error

    // Get form values
    var toEmail = sendto.toEmail.value;
    var fromEmail = sendto.fromEmail.value;

    if (isGlobalEmpty(sendto.toEmail))
    {   // email field is empty
        isErr = true;
        errMessage = errMessage + "Please enter your friend's e-mail address\r\n";
        if (errField.length <= 0) errField = "toEmail";
    }
    else
    {
        toEmail = globalTrim(toEmail);
        var msg = isGlobalValidEmailAddress(toEmail);
        if (msg.length > 0)
        {
            isErr = true; errMessage += msg;
            if (errField.length <= 0) errField = "toEmail";
        }
    }

    if (isGlobalEmpty(sendto.fromEmail))
    {   // email field is empty
        isErr = true;
        errMessage = errMessage + "Please enter your valid e-mail address\r\n";
        if (errField.length <= 0) errField = "toEmail";
    }
    else
    {
        fromEmail = globalTrim(fromEmail);
        var msg = isGlobalValidEmailAddress(fromEmail);
        if (msg.length > 0)
        {
            isErr = true; errMessage += msg;
            if (errField.length <= 0) errField = "fromEmail";
        }
    }

    if (isErr)
    {
        alert(errMessage);
//        eval("sendto." + errField + ".focus()");

        return false;
    }

    return true;
}

/*************************************************************
DESCRIPTION: To add Spotlight tags to Static files on onClick
PARAMETERS:  filePath - this
             srcDisplay - i.e. "http://ad.doubleclick.net/activity;src=1595705;type=zetia505;cat=zetia995;ord=1;"
             Don't need to include "num" because it is already included in function
RETURNS:     Loads spotlight images
*************************************************************/
function spotlight_static(filePath,srcDisplay,srcSearch) {
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    var spotpixD = new Image();
    spotpixD.src = srcDisplay + "num=" + a + "?";

    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    var spotpixS = new Image();
    spotpixS.src = srcSearch + "num="+ a + "?";

    spotpixS.load; //Loads image before pdf is called
    loadPDF(filePath); //Loads file in new window
    }

//New function with trimmed parameters needed
function tag_spotlight(filePath,srcDisplay,srcSearch) {
    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    var spotpixD = new Image();
    spotpixD.src = "http://ad.doubleclick.net/activity;" + srcDisplay + "num=" + a + "?";

    var axel = Math.random()+"";
    var a = axel * 10000000000000;
    var spotpixS = new Image();
    spotpixS.src = "http://ad.doubleclick.net/activity;" + srcSearch + "num="+ a + "?";

    spotpixS.load; //Loads image before pdf is called
    loadPDF(filePath); //Loads file in new window
    }
function loadPDF(x) {
    window.open(x.href);
    //x.href = "javascript://"; //replaces the content of href to prevent double page opening
    }
/********************************************************************************
DESCRIPTION:    To send Spotlight and Floodlight tags information from Flash
PARAMETERS:     writeSpotlightTag("xxxxxxx", "prodxxx", "flashxxx");  //search
                writeFloodlightTag("xxxxxx", "prodxxx", "flashxxx");  //display
RETURNS:        Loads spotlight images
********************************************************************************/
function writeSpotlightTag(src, type, cat) {
   var axel = Math.random()+"";
   var a = axel * 10000000000000;
   var newImg = document.createElement('img');
   newImg.src = "http://ad.doubleclick.net/activity;src="+src+";type="+type+";cat="+cat+";ord=1;num="+a+"?";
}
function writeFloodlightTag(src, type, cat) {
   var axel = Math.random()+"";
   var a = axel * 10000000000000;
   var newImg = document.createElement('img');
   newImg.src = "http://fls.doubleclick.net/activityi;src="+src+";type="+type+";cat="+cat+";ord=1;num="+a+"?";
}

/*  *******************************************************************************************  */
/*  DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)  */
/*  *******************************************************************************************  */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n)
{
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr)
{
    return isDate(dtStr,true);
}
function isDate(dtStr, showMessage)
{
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1)
    {
        if (showMessage)
        {
            alert("The date format should be : mm/dd/yyyy")
        }
        return false
    }
    if (strMonth.length<1 || month<1 || month>12)
    {
        if (showMessage)
        {
            alert("Please enter a valid month")
        }
        return false
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
    {
        if (showMessage)
        {
            alert("Please enter a valid day")
        }
        return false
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
    {
        if (showMessage)
        {
            alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        }
        return false
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
    {
        if (showMessage)
        {
            alert("Please enter a valid date")
        }
        return false
    }
    return true
}

