var JS_E_MARKETER = "D:\\inetpub\\wwwroot\\include\\e_marketer.js (791 lines) 2003-04-11 16:40 Dean Hannotte";
/***********************************************************************

                  eMarketer Global JavaScript Library
                  -----------------------------------
***********************************************************************/
/*--------------------------------------------------------------------*/
/*                      Declare Global Variables                      */
/*--------------------------------------------------------------------*/
var e_DbAds = false;                              // trace ad functions?
var e_DbCookies = false;                          // show cookie access?
var e_Debug = false;                          // Debugging variable that
                                     //  changes the output of e_Write()
                                     //  to reveal instead of generating
                                             //  HTML codes (by changing
                                       //  all '<' characters to '[' and
                                         //  all '>' characters to ']').
var e_Key = '';                                                          //MJ 20040128
var e_QueryString = location.search.substr(1);
var e_ContentGroup = '';  //this will be set in PageStartUC.ascx...

/*--------------------------------------------------------------------*/
/*                  Initialize All Global Variables                   */
/*--------------------------------------------------------------------*/
e_InitializeGlobalVariables();                  // using local variables

/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*                    e_InitializeGlobalVariables                     */
/*--------------------------------------------------------------------*/
function e_InitializeGlobalVariables()
{

/*                                                                    */
/*                          Set e_Key (if exists)                     */
/*                                                                    */
//    alert("Set e_Key");
    var parm1 = e_QueryString;
//    alert("parm1: " + parm1);
    var where_is_ampersand = parm1.indexOf('&');
//    alert("where_is_ampersand: " + where_is_ampersand);
    if (where_is_ampersand > 0)
    {
        parm1 = parm1.substr(0, where_is_ampersand);
    }
    var where_is_equalsign = parm1.indexOf('=');
//    alert("where_is_equalsign: " + where_is_equalsign);
    if (where_is_equalsign == -1)
    {
        e_Key = parm1;
    }
//    alert("e_Key: " + e_Key);
}


/**********************************************************************/
/*                                                                    */
/*                     Form Validation Functions                      */
/*                                                                    */
/**********************************************************************/
/*--------------------------------------------------------------------*/
/*                e_AnyRequiredInputMissing() function                */
/*--------------------------------------------------------------------*/
function e_AnyRequiredInputMissing(a_form)
{
    var rx, label, obj_name, object;

//alert("e_AnyRequiredInputMissing('" + a_form.name + "');");
    for (rx = 0; rx + 1 < e_RequiredInput.length; rx += 2)
    {
        obj_name = e_RequiredInput[rx];
        label    = e_RequiredInput[rx + 1];
        object   = eval(a_form.name + '.' + obj_name);
        if (e_NoInput(object, label)) return true;
    }
    return false;
}

/*--------------------------------------------------------------------*/
/*             e_AnyRequiredSelectionsMissing() function              */
/*--------------------------------------------------------------------*/
function e_AnyRequiredSelectionsMissing(a_form)
{
    var rx, label, obj_name, object;

//alert("e_AnyRequiredSelectionsMissing('" + a_form.name + "');");
    for (rx = 0; rx + 1 < e_RequiredSelections.length; rx += 2)
    {
        obj_name = e_RequiredSelections[rx];
        label    = e_RequiredSelections[rx + 1];
        object   = eval(a_form.name + '.' + obj_name);
        if (e_NoSelection(object, label)) return true;
    }
    return false;
}

/*--------------------------------------------------------------------*/
/*                        e_BadDate() function                        */
/*--------------------------------------------------------------------*/
function e_BadDate(object, label)
{
    if (typeof label == 'undefined') label = 'the date';
//    alert("e_BadDate('" + object.value + "', '" + label + "');");
// Allow yyyymmdd dates, too:
    if (object.value.length == 8)
    {
//alert("Object value is 8.");
        expand = 'y';
        for (xx = 0; xx < object.value.length; xx++)
        {
            var mychar = object.value.substr(xx, 1);
//alert("char = '" + char + "'.");
            if (mychar < '0' ||  mychar > '9')
            {
                expand = 'n';
//alert("expand = '" + expand + "'.");
            }
        }
        if (expand == 'y')
        {
            object.value = object.value.substr(0, 4) + '-'
                         + object.value.substr(4, 2) + '-'
                         + object.value.substr(6, 2);
        }
    }
    var err_msg = new String('');
    var sep_1   = object.value.indexOf('-', 0);
    var sep_2   = object.value.indexOf('-', sep_1 + 1);
    var yyyy_s  = object.value.substr(0, sep_1);
    var mm_s    = object.value.substr(sep_1 + 1, sep_2 - (sep_1 + 1));
    var dd_s    = object.value.substr(sep_2 + 1);
    var yyyy    = Math.floor(yyyy_s);
    var mm      = Math.floor(mm_s);
    var dd      = Math.floor(dd_s);

    if (object.value == '' || sep_2 == -1)
    {
        err_msg = "Please enter " + label + " in YYYYMMDD or YYYY-MM-DD format. "
            + "(In the latter case, month and day values need not be zero-filled when less than 10.)";
    }
    else if (yyyy_s.length != 4)
    {
        err_msg = "The year component of " + label + "', " + yyyy_s + "', must be 4 digits.";
    }
    else if (mm_s.length > 2)
    {
        err_msg = "The month component of " + label + ", '" + mm_s + "', cannot be larger than 2 digits.";
    }
    else if (dd_s.length > 2)
    {
        err_msg = "The day component of " + label + ", '" + dd_s + "', cannot be larger than 2 digits.";
    }
    else if (isNaN(yyyy) || yyyy < 1991 || yyyy > 2010)
    {
        err_msg = "The year component of " + label + ", '" + yyyy + "', must lie within 1991 and 2010.";
    }
    else if (isNaN(mm) || mm < 1 || mm > 12)
    {
        err_msg = "The month component of " + label + ", '" + mm + "', must lie within 1 and 12.";
    }
    else if (isNaN(dd) || dd < 1 || dd > 31)
    {
        err_msg = "The day component of " + label + ", '" + dd + "', must lie within 1 and 31.";
    }

    if (err_msg != '')
    {
        object.focus();
        object.select();
        alert(err_msg);
        return true;
    }
    if (mm_s.length < 2) mm_s = '0' + mm_s;
    if (dd_s.length < 2) dd_s = '0' + dd_s;
    object.value = yyyy_s + '-' + mm_s + '-' + dd_s;
//    alert("object.value = '" + object.value + "'.");
    return false;
}

/*--------------------------------------------------------------------*/
/*                  e_EmailAddressIsValid() function                  */
/*--------------------------------------------------------------------*/
function e_EmailAddressIsValid(object)
{
    return (!e_BadEmailAddress(object));
}

/*--------------------------------------------------------------------*/
/*                 e_BadEmailAddress() function                       */
/*--------------------------------------------------------------------*/
function e_BadEmailAddress(object, label)
{
//alert("e_BadEmailAddress('" + object.name + "=" + object.value + "', '" + label + "');");
    if (object.value == "")
    {
        object.focus();
        object.select();
        if (typeof label == 'undefined')
        {
            alert("Please enter your email address.");
        }
        else
        {
            alert("Please enter " + label + ".");
        }
        return true;
    }
    if (object.value.indexOf("@") == -1)
    {
        object.focus();
        object.select();
        alert("A valid email address would have an at-sign ('@') in it.");
        return true;
    }
    if (object.value.indexOf(".") == -1)
    {
        object.focus();
        object.select();
        alert("A valid email address would have a period ('.') in it.");
        return true;
    }
    if (object.value.indexOf("*") != -1)
    {
        object.focus();
        object.select();
        alert("A valid email address would not have an asterisk ('*') in it.");
        return true;
    }
    if (object.value.indexOf("?") != -1)
    {
        object.focus();
        object.select();
        alert("A valid email address would not have a question mark ('?') in it.");
        return true;
    }
    var badchars = /[^A-Za-z0-9@._-]/;
    var badx = object.value.search(badchars);
    if (badx > -1)
    {
        var badchar = object.value.substr(badx, 1);
        object.focus();
        object.select();
        if (confirm("Do you want to use this email "
            + "address even though there's a '" + badchar
            + "' in position " + (badx + 1) + "?"))
        {
            return false;
        }
        return true;
    }
    return false;
}

/*--------------------------------------------------------------------*/
/*                       e_BadRange() function                        */
/*--------------------------------------------------------------------*/
function e_BadRange(a_object, a_label, a_min, a_max)
{
    if (e_NoInput(a_object, a_label)) return true;
    value = parseFloat(a_object.value);
    if (isNaN(a_object.value) || value < a_min || value > a_max)
    {
        a_object.focus();
        a_object.select();
        alert("Please enter " + a_label + " between "
            + a_min + " and " + a_max + ".");
        return true;
    }
    return false;
}

/*--------------------------------------------------------------------*/
/*                     e_HighlightAll() function                      */
/*--------------------------------------------------------------------*/
function e_HighlightAll(a_select)
{
//     alert("e_HighlightAll('" + a_select.name
//         + '[' + a_select.options.length + "]')");
// Skip the last entry, which will be a 'window stopper'.
    for (xx = 0; xx < a_select.options.length - 1; xx++)
    {
        a_select.options[xx].selected = true;
    }
}

/*--------------------------------------------------------------------*/
/*                             e_NoChoice() function                  */
/*                                                                    */
/* NOTE: This function works for radio buttons as well as checkboxes. */
/*       For radio buttons, each button has the same name. Passing    */
/*       that name to this function passes an array of buttons.       */
/*       For checkboxes, each button has a different name, so you     */
/*       must create an array of button names and then pass that      */
/*       array to this function to achieve the same effect.           */
/*                                                                    */
/*--------------------------------------------------------------------*/
function e_NoChoice(objects, label)
{
    for (xx = 0; xx < objects.length; xx++)
    {
        if (objects[xx].checked) return false;
    }
    objects[0].focus();
    objects[0].select();
    alert("Please choose " + label + ".");
    return true;
}

/*--------------------------------------------------------------------*/
/*                        e_NoInput() function                        */
/*--------------------------------------------------------------------*/
function e_NoInput(object, label)
{
    if (object.value == '')
    {
        object.focus();
        object.select();
        alert("Please enter " + label + ".");
        return true;
    }
    return false;
}

/*--------------------------------------------------------------------*/
/*                 e_NoSelection() function                           */
/*--------------------------------------------------------------------*/
function e_NoSelection(object, label)
{
    if (object.selectedIndex == -1
    ||  object.options[object.selectedIndex].value == ''
    ||  object.options[object.selectedIndex].value == '[not set]') // PHP constant
    {
        object.focus();
        alert("Please select " + label + ".");
        return true;
    }
    return false;
}


/**********************************************************************/
/*                                                                    */
/*                     Page-Generating Functions                      */
/*                                                                    */
/**********************************************************************/

/*--------------------------------------------------------------------*/
/*                   e_JumpToBrowsePage() function                    */
/*                                                                    */
/*             (required to browse the eStat Database)                */
/*--------------------------------------------------------------------*/
/*CZ 4/25/2007 added xsrc= */
function e_JumpToBrowsePage(a_url_parms)
{
    //alert("BEGIN e_JumpToBrowsePage()"); return;
    var args = e_GetArgs(a_url_parms);
    var url = "";
    if(args["xsrc"] != null && args["xsrc"] != "") //CZ 5/9/2007 added && args["xsrc"] != ""
    {
        var url = String("/SearchBrowse.aspx?pathID=" + args["f_path_id"] + "&xsrc=" + args["xsrc"]);
    }
    else
    {
        var url = String("/SearchBrowse.aspx?pathID=" + args["f_path_id"]);
    }
    window.location = url;
}


/*--------------------------------------------------------------------*/
/*                        e_LeftPad() function                        */
/*--------------------------------------------------------------------*/
function e_LeftPad(value, bytes, pad_char)
{
    var result = new String('' + value);
    while (result.length < bytes)
    {
        result = pad_char + result;
    }
    return result;
}




/*--------------------------------------------------------------------*/
/*                          e_Tab() function                          */
/*--------------------------------------------------------------------*/
function e_Tab()
{
    return "&nbsp;&nbsp;&nbsp;";
}

/*--------------------------------------------------------------------*/
/*                       e_Translate() function                       */
/*--------------------------------------------------------------------*/
function e_Translate(text, from_char, to_char)
{
    var x;

    for (x = 0; x < text.length; x++)
    {
        this_char = text.charAt(x);
        if (this_char == from_char)
        {
            text = text.substr(0, x)
                 + to_char
                 + text.substr(x + 1);
        }
    }
    return text;
}

/*--------------------------------------------------------------------*/
/*                         e_Write() function                         */
/*--------------------------------------------------------------------*/
function e_Write(text)
{
    if (e_Debug == false)
    {
        document.write("" + text);
        return;
    }
    var text2 = new String("");
    if (e_FirstTime)
    {
        e_FirstTime = false;
        document.writeln("<P>JS_EMARKETER: ");
        document.writeln("'" + JS_EMARKETER + "'.<BR>");
    }
    for (t = 0; t < text.length; t++)
    {
        var this_char = text.charAt(t);
        if (this_char == "<")
        {
            text2 = text2 + "&lt;";
        }
        else if (this_char == ">")
        {
            text2 = text2 + "&gt;";
        }
        else if (this_char == "&")
        {
            text2 = text2 + "&amp;";
        }
        else
        {
            text2 = text2 + this_char;
        }
    }
    text2 += "<BR>";
    document.write("" + text2);
}

/**********************************************************************/
/*                                                                    */
/*                        Cookie Functions                            */
/*                                                                    */
/**********************************************************************/
//from http://www.hypergurl.com/popup.html

function e_GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return e_GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function e_SetCookie (name, value) {
var argv = e_SetCookie.arguments;
var argc = e_SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function e_DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = e_GetCookie(name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function e_GetCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

/**********************************************************************/
/*                                                                    */
/*                     Miscellaneous Functions                        */
/*                                                                    */
/**********************************************************************/

/*--------------------------------------------------------------------*/
/*                        e_GetArgs() function                        */
/*--------------------------------------------------------------------*/

function e_GetArgs(a_querystring) {
        var args = new Object();
        // Get Query String
        var query = a_querystring
        // Split query at the comma
        var pairs = query.split("&");

        // Begin loop through the querystring
        for(var i = 0; i < pairs.length; i++) {

                // Look for "name=value"
                var pos = pairs[i].indexOf('=');
                // if not found, skip to next
                if (pos == -1) continue;
                // Extract the name
                var argname = pairs[i].substring(0,pos);

                // Extract the value
                var value = pairs[i].substring(pos+1);
                // Store as a property
                args[argname] = unescape(value);
        }
        return args; // Return the Object
}


/*--------------------------------------------------------------------*/
/*                        e_ChartSubdir function                      */
/*--------------------------------------------------------------------*/
//takes a 6 digit chart file num as a parameter
//currently used in web_admin/quicktags.js

function e_ChartSubdir(a_chart_file_num)
{
    var zeros = "000000";

    var floor = Math.floor((a_chart_file_num - 1) / 1000) * 1000 + 1;
    floor = floor + '';  //convert number to string!!!
    floor = zeros.substr(0, 6 - floor.length) + floor;

    var ceil  = Math.ceil (a_chart_file_num / 1000) * 1000;
    ceil = ceil + '';  //convert number to string!!!
    ceil = zeros.substr(0, 6 - ceil.length) + ceil;

    return floor + "-" + ceil;
}

/*--------------------------------------------------------------------*/
/*                        e_ChartSubdir function                      */
/*--------------------------------------------------------------------*/
//takes a 6 digit chart file num as a parameter
//currently used in web_admin/quicktags.js

function e_ChartImgSrc(a_chart_file_num)
{
    if (a_chart_file_num.length == 5)    //handle this common error
    {
        a_chart_file_num = "0" + a_chart_file_num;
    }
    var src = "/images/chart_gifs/" + e_ChartSubdir(a_chart_file_num) + "/" + a_chart_file_num + ".gif";
    return src;
}





/**********************************************************************/
/*                                                                    */
/*                     Popup Window Functions                         */
/*                                                                    */
/**********************************************************************/

/*--------------------------------------------------------------------*/
/*                    e_PopupWindow() function                        */
/*--------------------------------------------------------------------*/
function e_PopupWindow(a_url)
{
//    alert("e_PopupWindow('" + a_url + "');");
    open_url = a_url;
    open_window_name = new String('');
    //width = screen.availWidth - 50;
    width = 800;
    //height = screen.availHeight - 150;
    height = 600;
    open_window_features = new String("scrollbars=yes,menubar=yes,addressbar=1,"
                         + "resizable=yes,toolbar=yes,"
                         + "left=25, top=25, width=" + width + ", height=" + height);
    window.open(open_url, open_window_name, open_window_features);
}

/*--------------------------------------------------------------------*/
/*                    e_PopupWindow2() function                       */
/*--------------------------------------------------------------------*/
function e_PopupWindow2(winurl,winname,winfeatures)
      {
              //This launches a new window and then
              //focuses it if window.focus() is supported.
              newwin = window.open(winurl,winname,winfeatures);
              //if(javascript_version > 1.0)
              //{
                      //delay a bit here because IE4 encounters errors
                      //when trying to focus a recently opened window
              //        setTimeout('newwin.focus();',250);
              //}
      }


/*--------------------------------------------------------------------*/
/*                    e_OpenWindow() function                         */
/*--------------------------------------------------------------------*/
function e_OpenWindow(pageName,attributes)
{
    window.open(pageName,'',attributes);
}


/*--------------------------------------------------------------------*/
/*                        e_InsightExpressPopup() function            */
/*--------------------------------------------------------------------*/
//MJ 20041118
function e_InsightExpressPopup(a_content_group)
{
    //return;  //MJ 20041129 - disabled (eventually remove all calls as well...)
    var db = "";

    if (db) alert("BEGIN e_PopupWindowPromo().");
    if (db) alert("a_content_group: " + a_content_group);
    if (a_content_group == "Extranet")   // This variable is set in PageStartUC.ascx
    {
        if (db) alert("Not showing popup window if page is in extranet format. EXITING e_InsightExpressPopup().");
        return;
    }
    randomSurvey(); //defined in include/insight_express.js, which is also included on every page...

}
/*--------------------------------------------------------------------*/
/*                        e_PopupWindowPromo() function                */
/*--------------------------------------------------------------------*/
function e_PopupWindowPromo(a_state, a_content_group)
{
    //return;  //MJ 20040809 - disabled (eventually remove all calls as well...)
    var db = "";

    if (db) alert("BEGIN e_PopupWindowPromo().");
    if (db) alert("a_state: " + a_state);
    if (db) alert("a_content_group: " + a_content_group);

    /*-----------------Set expiration date variables----------------------*/

        var shortExpDays = 1; // number of days the cookie should last
        var longExpDays = 2*356; // number of days the cookie should last
        var shortExp = new Date();
        var longExp = new Date();
        shortExp.setTime(shortExp.getTime() + (shortExpDays*24*60*60*1000));
        longExp.setTime(longExp.getTime() + (longExpDays*24*60*60*1000));


    if (a_state == "just_clicked")
    {
        if (db) alert("Popup window link was clicked!  Setting cookie so user doesn't get popup again. EXITING e_PopupWindowPromo().");
        e_SetCookie('c_survey_popup', "doNotShow", longExp);
        return;
    }

    if (location.search.indexOf("popup=y") != -1)
    {
        if (db) alert("popup=y detected in URL.  Forcing popup window");
    }
    else
    {

    /*-------------------Check if page is in extranet format--------------*/


        if (a_content_group == "Extranet")   // This variable is set in PageStartUC.ascx
        {
            //e_SetCookie('c_trackref_extranet', "y", longExp);
            if (db) alert("Not showing popup window if page is in extranet format. EXITING e_PopupWindowPromo().");
            return;
        }


    /*---------------Check if user has already viewed popup today---------*/

        var survey_cookie = e_GetCookie('c_survey_popup');
        if (db) alert("survey_cookie: " + survey_cookie);

        if (survey_cookie == "doNotShow")
        {
            if (db) alert("Popup window already viewed. EXITING e_PopupWindowPromo().");
            return;
        }

    }

/*------------Open popup window if you have gotten this far-----------*/
//MJ 20030925
//Uncomment this part when we are ready to actually start showing the popup window!!!

    if (db) alert("Opening popup window...");
    var page = "/Popup.aspx";
    var windowprops = "width=321,height=288,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no";  //MJ 20050913

    TheNewWin = window.open(page, "TheNewPop", windowprops);
//    TheNewWin.blur();  //uncomment this line to make it a pop-under!!!

    e_SetCookie('c_survey_popup', "doNotShow", shortExp);

    if (db) alert("EXITING e_PopupWindowPromo().");
}


/**********************************************************************/
/*                               E N D                                */
/**********************************************************************/

