﻿
/* --- master page functions --- */
function clrSearchForm() {
    if (document.getElementById('ctl00_TextBox1').value == 'Search') {
        document.getElementById('ctl00_TextBox1').value = '';
    }
}
/* --- master page functions --- */



/* --- default page functions --- */

function hilite(choice) {
    document.getElementById(choice).className = 'hiliteChoiceOn';
}

function unhilite(choice) {
    document.getElementById(choice).className = 'hiliteChoiceOff';
}

function sendTracking(action, product, email, who, reason) {
    /*
    Have to send this XHR to a page located
    in the same domain. Otherwise, we could
    just send the request to a web service
    on our app server...
    */
    var url = 'epcTrack.aspx?a=' + action + '&p=' + product.substr(0, product.indexOf('_')) + '&e=' + email + '&w=' + who + '&r=' + reason;
    //alert(url);
    
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else // Internet Explorer 5/6
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhr.open("GET", url, false);
    xhr.send("");

    var strResponse = xhr.responseText;
    
    //comment next line for production deployment:    
    //alert(strResponse);
    }

function Get_Cookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) return null;
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
    }

function turnOff(product, who, reason) {

    sendTracking('uncheck', product, Get_Cookie('epcEmail'), who, reason);

    //mam case 1 - if we are unchecking mam.d, and mam.w is originally unchecked, then prompt to try mam.w
    if (product == 'MAM_OptIn' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_originalMamVal').value == 'On' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_MAMSUM_OptIn').value == 'Off') {
        hilite('MAMSUM_OptIn');
        turnOn('MAMSUM_OptIn', 'POPUP', 'WEEKLY_OFFER');
        showdeadcenterdiv('200', '200', 'mam_1_q1');
    }

    //mam case 2 - if we are unchecking mam.w, and mam.d is originally unchecked, then prompt to try mam.d
    else if (product == 'MAMSUM_OptIn' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_originalMamsumVal').value == 'On' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_MAM_OptIn').value == 'Off') {
        hilite('MAM_OptIn');
        turnOn('MAM_OptIn', 'POPUP', 'DAILY_OFFER');
        showdeadcenterdiv('200', '200', 'mam_2_q1');
    }

    //uwd case 1 - if we are unchecking uwd.d, and uwd.w is originally unchecked, then prompt to try uwd.w
    else if (product == 'UWD_OptIn' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_originalUwdVal').value == 'On' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_UWDSUM_OptIn').value == 'Off') {
        hilite('UWDSUM_OptIn');
        turnOn('UWDSUM_OptIn', 'POPUP', 'WEEKLY_OFFER');
        show('uwd_1_q1');
        showdeadcenterdiv('200', '200', 'uwd_1_q1');
    }

    //uwd case 2 - if we are unchecking uwd.w, and uwd.d is originally unchecked, then prompt to try uwd.d
    else if (product == 'UWDSUM_OptIn' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_originalUwdsumVal').value == 'On' && document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_UWD_OptIn').value == 'Off') {
        hilite('UWD_OptIn');
        turnOn('UWD_OptIn', 'POPUP', 'REPORT_OFFER');
        show('uwd_2_q1');
        showdeadcenterdiv('200', '200', 'uwd_2_q1');
    }

    document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_' + product).value = 'Off';
    document.getElementById(product + '_span').innerHTML = unescape('%0D%0A') + '<span><img src="images/big_check_Off.gif" alt="Click this to OPT OUT of this category." onclick="turnOn(\'' + product + '\', \'USER\', \'' + product + '_OPTIN_CLICK\');" class="chkImgOn" /></span>' + unescape('%0D%0A');
}


function turnOn(product, who, reason) {

    sendTracking('check', product, Get_Cookie('epcEmail'), who, reason);
    document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_' + product).value = 'On';
    document.getElementById(product + '_span').innerHTML = unescape('%0D%0A') + '<span><img src="images/big_check_On.gif" alt="Click this to OPT INTO this category." onclick="turnOff(\'' + product + '\', \'USER\', \'' + product + '_OPTOUT_CLICK\');" class="chkImgOn" /></span>' + unescape('%0D%0A');
}



function yesTry(product) {
    //mam case 1
    if (product == 'MAMSUM') {
        unhilite('MAMSUM_OptIn');
        hide('mam_1_q1');
    } else if (product == 'MAM') {
        unhilite('MAM_OptIn');
        hide('mam_2_q1');
    } else if (product == 'UWDSUM') {
        unhilite('UWDSUM_OptIn');
        hide('uwd_1_q1');
    } else if (product == 'UWD') {
        unhilite('UWD_OptIn');
        hide('uwd_2_q1');
    }
    sendTracking('yes_click', product + '_', Get_Cookie('epcEmail'), 'USER', 'YES_' + product);
}

function noTry(product) {
    if (product == 'MAMSUM') {
        hide('mam_1_q1');
        showdeadcenterdiv('200', '200', 'mam_1_q2');
    } else if (product == 'MAM') {
        hide('mam_2_q1');
        showdeadcenterdiv('200', '200', 'mam_2_q2');
    } else if (product == 'UWDSUM') {
        hide('uwd_1_q1');
        showdeadcenterdiv('200', '200', 'uwd_1_q2');
    } else if (product == 'UWD') {
        hide('uwd_2_q1');
        showdeadcenterdiv('200', '200', 'uwd_2_q2');
    }
    sendTracking('no_click', product + '_', Get_Cookie('epcEmail'), 'USER', 'NO_' + product);
}

function yesReport(product) {
    if (product == 'MAMSUM') {
        unhilite('MAMSUM_OptIn');
        hide('mam_1_q2');
    } else if (product == 'MAM') {
        unhilite('MAM_OptIn');
        hide('mam_2_q2');
    } else if (product == 'UWDSUM') {
        unhilite('UWDSUM_OptIn');
        hide('uwd_1_q2');
    } else if (product == 'UWD') {
        unhilite('UWD_OptIn');
        hide('uwd_2_q2');
    }
    sendReport();
    //alert('send report');
    sendTracking('yes_click', product + '_', Get_Cookie('epcEmail'), 'USER', 'YES_REPORT');
}

function noReport(product) {
    if (product == 'MAMSUM') {
        unhilite('MAMSUM_OptIn');
        hide('mam_1_q2');
    } else if (product == 'MAM') {
        unhilite('MAM_OptIn');
        hide('mam_2_q2');
    } else if (product == 'UWDSUM') {
        unhilite('UWDSUM_OptIn');
        hide('uwd_1_q2');
    } else if (product == 'UWD') {
        unhilite('UWD_OptIn');
        hide('uwd_2_q2');
    }
    //alert('no report');
    document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdn_' + product + '_OptIn').value = 'Off';
    document.getElementById(product + '_OptIn_span').innerHTML = unescape('%0D%0A') + '<span><img src="images/big_check_Off.gif" alt="Click this to OPT OUT of this category." onclick="turnOn(\'' + product + '_OptIn\', \'USER\', \'' + product + '_OPTIN_CLICK\');" class="chkImgOn" /></span>' + unescape('%0D%0A');
    sendTracking('no_click', product + '_', Get_Cookie('epcEmail'), 'USER', 'NO_REPORT(' + product + ')');
}

function sendReport() {
    //alert('sending report...');
    //set fld val here
    document.getElementById('ctl00_ContentPlaceHolder1_ListView1_ctrl0_hdnReport').value = 'True';
}

function saveReminder() {
    //alert('Don\'t forget to click the \"Save Changes\" button when you\'re done...');
}

function show(elementIn) {
    document.getElementById(elementIn).style.display = 'inline';
}

function hide(elementIn) {
    document.getElementById(elementIn).style.display = 'none';
}

function showdeadcenterdiv(Xwidth, Yheight, divid) {
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the
    // div passed as arguments to the function:
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the
    // style sheet with display:none; divid is passed as an argument to // the function
    var o = document.getElementById(divid);
    var r = o.style;
    r.position = 'absolute';
    r.top = topOffset + 'px';
    r.left = leftOffset + 'px';
    r.display = "block";
}

function defaultGo() {
    window.location = 'Default.aspx?email=' + document.getElementById('txtEmail').value;
}

/* --- survey functions --- */

function setSurveyFlag() {
    document.getElementById('hdnSurveyFlag').value = 'true';
}

function chkSurvey() {
    if (document.getElementById('hdnSurveyFlag').value == 'true') {
        //fireElement('surveyLink');
        win = window.open("http://www.surveymonkey.com/s.aspx?sm=l_2b2SrED_2fJZqb686nuwQx5g_3d_3d", "mywindow", "location=1,status=1,scrollbars=1,width=600,height=400");
    }
}

//This function will programmatically "click" the hidden survey link.
function fireElement(objID) {
    var target = document.getElementById(objID);
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}
/* --- survey functions --- */


/* --- sample functions --- */
function makeRequest(url) {
    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("MSXML2.ServerXMLHTTP.4.0");
            //	                http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }

    if (!http_request) {
        alert('Error: Cannot create an XMLHTTP instance');
        return false;
    }
    http_request.onreadystatechange = displayContents;
    http_request.open('GET', url, true);
    http_request.send(null);
}

function displayContents() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            //document.getElementById('menuContent').innerHTML = http_request.responseText;
            alert('Your sample has been sent.');
        } else {
            alert('There was a problem with the request.' + http_request.status);
        }
    }
}

function sendSample(typeIn, emailIn) {
//if(typeIn=='' || 
    makeRequest('_generateSample.aspx?type=' + typeIn + '&email=' + emailIn);
    //alert('_generateSample.aspx?type=' + typeIn + '&email=' + emailIn);
}


/* --- sample functions --- */



/* --- default page functions --- */
