﻿// ************ CONSTANTS ************************
//Virus Threats Displaying parameter.
// If this is 0 nothing will be printed in display even not heading
// based on value the display will be formed
MAX_CURRENT_THREATS_DISPLAY_COUNT = 25
MAX_RECENT_THREATS_DISPLAY_COUNT = 25

//Default Content Settings
dsplycur = 1;
dsplyrec = 1;
dsplyrem = 1;
dsplysrc = 1;
dspylogolnk = 1;
lnklogo = "http://us.mcafee.com";
dsplyfs = 0;
lnkfs = "";
dsplyvs = 0;
lnkvs = "";

//Default Color Settings
defbor = "#E5E3B5";
deftlt = "#000000";
defbgc = "#F9F9ED";
deflnk = "#204658";

//Default Color Variables
colbor = defbor;
coltlt = deftlt;
colbgc = defbgc;
collnk = deflnk;


//Default value if URL value is not valid
DefaultLinklogo = "http://us.mcafee.com";
DefaultLinkfs = "http://us.mcafee.com/root/mfs/default.asp";
DefaultLinkvs = "http://us.mcafee.com/root/package.asp?pkgid=100";


//Pre-cache clear.gif
imgtr = new Image(1, 1);
imgtr.src = "http://images.mcafee.com/mcalerts/clear.gif";
ImageServerDomain = "http://images.mcafee.com/mcalerts";

//	Domain where Virus display code is hosted
SecurityServerDomain = "http://securityalerts.mcafee.com";
SecurityAlertsDomain = "http://securityalerts.mcafee.com";
//	SecurityServerDomain =  "http://mishra.mcafee.com";

SearchDomainWithID = "http://us.mcafee.com/virusInfo/default.asp?id=alphar"
//Mcafee web site domain
McAfeeDomain = "http://us.mcafee.com"

// 	Language code 
LANGUAGECODE = "en-us";

//  Validate flag is use to validate URL name. If there will be matching with search expression
//  Then the url will be replace with default. 
VALIDATE_MCAFEE_URL = 1
SEARCH_EXPRESSION = /syman/gi;

// Language dependent constants

CURRENT_THREATS = "Current Threats"
CURRENT_THREATS_MESSAGE = "virus"
CURRENT_THREATS_RISK_MESSAGE = " Risk"

RECENT_THREATS = "Recent Threats"
COMPLETE_LIST = "Complete list"
COMPLETE_LIST_URL = "http://us.mcafee.com/virusInfo/default.asp?id=recentlyDiscovered"

WORRIED_ABOUT_VIRUSES = "Worried About Viruses?"
WORRIED_ABOUT_VIRUSES_TEXT = "McAfee FreeScan"

NEED_PROTECTION = "Need Protection?"
NEED_PROTECTION_TEXT = "McAfee VirusScan"

VIRUS_SEARCH = "Virus Search"
VIRUS_SEARCH_TEXT1 = "beginning with"
VIRUS_SEARCH_TEXT2 = "containing"
VIRUS_SEARCH_TEXT3 = "ending with"
VIRUS_SEARCH_INVALID_MESSAGE = "Please enter a search criteria."

REMOVAL_TOOLS = "Removal Tools"
REMOVAL_TOOLS_LOVESCAN = "Lovsan"
REMOVAL_TOOLS_KLEZ = "Klez"
REMOVAL_TOOLS_BUGBEAR = "Bugbear"
REMOVAL_TOOLS_STRINGER = "Stinger Removal Tool"

NO_CURRENT_THREATS_MESSAGE = "There are no high risk threats at this time."
NO_RECENT_THREATS_MESSAGE = "There are no recent threats at this time."


// Color Palette related message
COLOR_PALETTE_CLOSE = "Close Color Picker";
COLOR_PALETTE_HEADING = "216 Web Safe Colors";

INVALID_COLOR_MESSAGE = "Entered colors must be in a hexadecimal format (for example, #000000 or #CCAA45)\n" +
		"or be one of the 140 named colors supported by HTML.\n\n" +
		"The selected display element has been reset to it's default value. Please enter a\n" +
		"properly formatted color code, use the color picker to select a color, or enter a\n" +
		"supported color name."

//Create and initialize multidimensionalArray use for Resource file

function MultiDimensionalArrayCT(iRows, iCols) {
    var i;
    var j;
    var a = new Array(iRows);
    for (i = 0; i < iRows; i++) {
        a[i] = new Array(iCols);
        for (j = 0; j < iCols; j++) {
            a[i][j] = "";
        }
    }
    return (a);
}

function MultiDimensionalArrayRT(iRows, iCols) {
    var i;
    var j;
    var a = new Array(iRows);
    for (i = 0; i < iRows; i++) {
        a[i] = new Array(iCols);
        for (j = 0; j < iCols; j++) {
            a[i][j] = "";
        }
    }
    return (a);
} 
// ************ CONSTANTS ************************


//Sets Global Variables
strcode ="";
selinput = 0;
arrcolors = defbor + "," + deftlt + "," + defbgc + "," + deflnk;
splcolors = arrcolors.split(",");

////Sets Color Defaults
function DefaultCode() {
    strcode = '<script src="' + SecurityServerDomain + '/mcalerts/' + LANGUAGECODE + '/AlertConstant.js"></script>\n';
    strcode = strcode + '<script src="' + SecurityServerDomain + '/mcalerts/' + LANGUAGECODE + '/ResourceFile.js"></script>\n';
    strcode = strcode + '<script src="' + SecurityAlertsDomain + '/mcalerts/AlertDisplay.js"></script>\n';
    strcode = strcode + '<script>\n';
    strcode = strcode + '\tDisplayMcAfeeAlerts();\n';
    strcode = strcode + '</script>'
}

function UpdatePreview() {
    var l_queryString = "";
    var l_url;

    // ... McAfee Logo
    if (document.getElementsByName("DisplayLogoLink")[0].checked == true) {
        l_url = document.getElementById('LogoLinkURL').value;
        if (l_url != "http://us.mcafee.com")
            l_queryString += "dspylogolnk=1" + "&lnklogo=" + l_url;
        else
            l_queryString += "&dspylogolnk=0&lnklogo=";
    }
    else {
        l_queryString += "&dspylogolnk=0&lnklogo=";
    }

    // .. Current Threats
    if (document.getElementsByName('DisplayCurrent')[0].checked == false)
        l_queryString += "&dsplycur=0";
    else
        l_queryString += "&dsplycur=1";

    // ... Recent Threats
    if (document.getElementsByName('DisplayRecent')[0].checked == false)
        l_queryString += "&dsplyrec=0";
    else
        l_queryString += "&dsplyrec=1";

    // ... Removal Tools
    if (document.getElementsByName('DisplayRemoval')[0].checked == false)
        l_queryString += "&dsplyrem=0";
    else
        l_queryString += "&dsplyrem=1";

    // ... FreeScan
    if (document.getElementsByName('DisplayFreeScan')[0].checked == true) {
        l_url = document.getElementById('FreeScanURL').value;
        l_queryString += "&dsplyfs=1" + "&lnkfs=" + l_url;
    }
    else
        l_queryString += "&dsplyfs=0" + "&lnkfs=";

    //Updates VirusScan Option Selection
    if (document.getElementsByName('DisplayVirusScan')[0].checked == true) {
        l_url = document.getElementById('VirusScanURL').value;
        l_queryString += "&dsplyvs=1" + "&lnkvs=" + l_url;
    }
    else
        l_queryString += "&dsplyvs=0" + "&lnkvs=";

    // ... Search Option Selection
    if (document.getElementsByName('DisplaySearch')[0].checked == false)
        l_queryString += "&dsplysrc=0";
    else
        l_queryString += "&dsplysrc=1";

    //Updates Colors
    for (i = 1; i < 5; i++) {
        tmp = document.getElementById('format' + i).value.substr(1); // remove the leading # for the query string
        if (tmp.toUpperCase() == "INVALID") {
            tmp = splcolors[i - 1];
        }
        if (i == 1) {
            if (tmp != defbor) {
                l_queryString += '&colbor=' + tmp;
            }
        }
        else if (i == 2) {
            if (tmp != deftlt) {
                l_queryString += '&coltlt=' + tmp;
                count++;
            }
        }
        else if (i == 3) {
            if (tmp != defbgc) {
                l_queryString += '&colbgc=' + tmp;
                count++;
            }
        }
        else if (i == 4) {
            if (tmp != deflnk) {
                l_queryString += '&collnk=' + tmp;
                count++;
            }
        }
    }

    //alert("/VirusInfo/SecurityAlertsPreview.aspx?" + l_queryString);

    self.frames['DisplayFrame'].location.href = "/VirusInfo/SecurityAlertsPreview.aspx?" + l_queryString; 
    //self.frames['DisplayFrame'].location.reload(true);
}

//function UpdateDisplay(f) {
//    errfound = false;
//    showdisplay = 0;

//    for (i = 1; i < 5; i++) {
//        tmp = eval("document.configurator.format" + i + ".value");
//        if (tmp.toUpperCase() == "INVALID") {
//            MsgColorError(i);
//            showdisplay++;
//            i = 5;
//            errfound = true;
//        }
//    }
//    if (showdisplay == 0) {
//        UpdateThisColor(f);
//        document.configurator.submit();
//    }
//    else {
//        //UpdateCodeSnippet();
//    }
//    return !errfound;
//}

//Selects Color form Color Picker & Updates Swatch/Form Field
function SetColor(c, r) {
    //alert("C: "+c + "varia"+ r)
    selcolor = c.replace('#', '');
    //eval("document.images['swatch" + selinput + "'].src = ImageServerDomain +'/swatch.gif'");
    document.getElementById('bg' + selinput).style.background = c;
    //alert("C: "+eval("document.images['swatch" + selinput + "'].src"))
    if (selinput == 1) {
        colbor = selcolor;
    }
    else if (selinput == 2) {
        coltlt = selcolor;
    }
    else if (selinput == 3) {
        colbgc = selcolor;
    }
    else if (selinput == 4) {
        collnk = selcolor;
    }
    document.getElementById('format' + selinput).value = c;
    document.getElementById('format' + selinput).select();
    document.getElementById('format' + selinput).focus();
    CloseCP();
    UpdateCodeSnippet()
    return true;
}
//Opens Color Picker
function OpenCP(n) {
    //alert('Color Plate' + strColorPalette);
    document.getElementById('format' + n).select();
    document.getElementById('format' + n).focus();
    selinput = 0;
    document.getElementById('ShowCP').innerHTML = strColorPalette;
    document.getElementById('ShowCP').style.top = 485;
    document.getElementById('ShowCP').style.left = 355;
    document.getElementById('ShowCP').style.visibility = "visible";
    selinput = n;
}
//Closes Color Picker
function CloseCP() {
    document.getElementById('ShowCP').style.visibility = "hidden";
    //eval("document.configurator.format" + selinput + ".focus()");
}

//Resets Color Fields & Swatch to Default Colors
function ResetColors() {
    //selinput = 1;
    CloseCP();
    for (i = 0; i < splcolors.length; i++) {
        document.getElementById('bg' + (i + 1)).style.background = splcolors[i];
        //eval("document.images['swatch" + (i + 1) + "'].src = ImageServerDomain +'/swatch.gif'");
        document.getElementById('format' + (i + 1)).value = splcolors[i];
    }
    document.getElementById('format1').select();
    document.getElementById('format1').focus();
    UpdateCodeSnippet();
}
//Updates Selected Field with Entered Color
function UpdateThisColor(f) {
    var errfound = false;
    var flg = 0;
    var strnamedc = "|aliceblue|ghostwhite|navajowhite|antiquewhite|gold|navy|aqua|goldenrod|oldlace|aquamarine|gray|olive|azure|green|olivedrab|beige|greenyellow|orange|bisque|honeydew|orangered|black|hotpink|orchid|blanchedalmond|indianred|palegoldenrod|blue|indigo|palegreen|blueviolet|ivory|paleturquoise|brown|khaki|palevioletred|burlywood|lavender|papayawhip|cadetblue|lavenderblush|peachpuff|chartreuse|lawngreen|peru|chocolate|lemonchiffon|pink|coral|lightblue|plum|cornflowerblue|lightcoral|powderblue|cornsilk|lightcyan|purple|crimson|lightgoldenrodyellow|red|cyan|lightgreen|rosybrown|darkblue|lightgrey|royalblue|darkcyan|lightpink|saddlebrown|darkgoldenrod|lightsalmon|salmon|darkgray|lightseagreen|sandybrown|darkgreen|lightskyblue|seagreen|darkkhaki|lightslategray|seashell|darkmagenta|lightsteelblue|sienna|darkolivegreen|lightyellow|silver|darkorange|lime|skyblue|darkorchid|limegreen|slateblue|darkred|linen|slategray|darksalmon|snow|darkseagreen|maroon|springgreen|darkslateblue|mediumaquamarine|steelblue|darkslategray|mediumblue|tan|darkturquoise|mediumorchid|teal|darkviolet|mediumpurple|thistle|deeppink|mediumseagreen|tomato|deepskyblue|mediumslateblue|turquoise|dimgray|mediumspringgreen|violet|dodgerblue|mediumturquoise|wheat|firebrick|mediumvioletred|white|floralwhite|midnightblue|whitesmoke|forestgreen|mintcream|yellow|fuchsia|mistyrose|yellowgreen|gainsboro|moccasin|cyan|fuchsia|magenta|"
    selinput = f;
    var newcolor = document.getElementById('format' + f).value;

    var repcolor = newcolor.replace("#", "");
    var ucnewcolor = repcolor.toUpperCase();
    //Checks To See If Named Color in 140 List
    //alert("we are" + ucnewcolor);
    ucnewcolor = trim(ucnewcolor);

    if (strnamedc.indexOf("|" + newcolor.toLowerCase() + "|") > -1) {
        flg = 1;
    }
    //Checks for HexDec Format
    if (flg == 0) {
        if (repcolor.length == 6) {
            validlst = "0123456789ABCDEF";
            for (i = 0; i < 6; i++) {
                if (validlst.indexOf(ucnewcolor.charAt(i)) == -1) {
                    flg = 0;
                    i = 6;
                }
                else {
                    flg = 1;
                }
            }
        }
        else {
            flg = 0;
        }
    }
    if (flg == 1) {
        SetColor(newcolor, 1);
    }
    else {
        MsgColorError(f);
        errfound = true;
    }
    return !errfound;
}

function MsgColorError(f) {
    eval("document.getElementById('bg" + f + "').style.background = 'white';");
    //eval("document.images['swatch" + f + "'].src = ImageServerDomain +'/error.gif'");
    eval("document.getElementById('format" + f + "').value = 'INVALID'");
    eval("document.getElementById('format" + f + "').select()");
    eval("document.getElementById('format" + f + "').focus()");
    UpdateCodeSnippet();
    alert(INVALID_COLOR_MESSAGE);
}

function UpdateCodeSnippet() {
    strcustom = "";
    count = 0;
    showdisplay = 0;

    //Updates McAfee Security Logo Link Selection
    if (document.getElementsByName("DisplayLogoLink")[0].checked == true) {
        strlink = document.getElementById('LogoLinkURL').value;
        if (strlink != "http://us.mcafee.com") {
            strcustom = strcustom + '\tlnklogo = "' + strlink + '";\n';
            alert(strcustom);
            count++;
        }
    }
    else {
        strcustom = strcustom + '\tdspylogolnk = 0;\n';
        strcustom = strcustom + '\tlnklogo = "";\n';
        count = count + 2;
    }

    //Updates Current Threats Option Selection
    if (document.getElementsByName('DisplayCurrent')[0].checked == false) {
        strcustom = strcustom + '\tdsplycur = 0;\n';
        count++;
    }
    
    //Updates Recent Threats Option Selection
    if (document.getElementsByName('DisplayRecent')[0].checked == false) {
        strcustom = strcustom + '\tdsplyrec = 0;\n';
        count++;
    }
    
    //Updates Removal Tools Option Selection	
    if (document.getElementsByName('DisplayRemoval')[0].checked == false) {
        strcustom = strcustom + '\tdsplyrem = 0;\n';
        count++;
    }
    
    //Updates FreeScan Option Selection
    if (document.getElementsByName('DisplayFreeScan')[0].checked == true) {
        strlink = document.getElementById('FreeScanURL').value;
        strcustom = strcustom + '\tdsplyfs = 1;\n';
        strcustom = strcustom + '\tlnkfs = "' + strlink + '";\n';
        count = count + 2;
    }
    
    //Updates VirusScan Option Selection
    if (document.getElementsByName('DisplayVirusScan')[0].checked == true) {
        strlink = document.getElementById('VirusScanURL').value;
        strcustom = strcustom + '\tdsplyvs = 1;\n';
        strcustom = strcustom + '\tlnkvs = "' + strlink + '";\n';
        count = count + 2;
    }
    
    //Updates Search Option Selection
    if (document.getElementsByName('DisplaySearch')[0].checked == false) {
        strcustom = strcustom + '\tdsplysrc = 0;\n';
        count++;
    }

    i = 0
    //Updates Colors
    for (i = 1; i < 5; i++) {
        tmp = document.getElementById('format' + i).value;
        if (tmp.toUpperCase() == "INVALID") {
            tmp = splcolors[i - 1];
        }
        if (i == 1) {
            if (tmp != defbor) {
                strcustom = strcustom + '\tcolbor = "' + tmp + '";\n';
                count++;
            }
        }
        else if (i == 2) {
            if (tmp != deftlt) {
                strcustom = strcustom + '\tcoltlt = "' + tmp + '";\n';
                count++;
            }
        }
        else if (i == 3) {
            if (tmp != defbgc) {
                strcustom = strcustom + '\tcolbgc = "' + tmp + '";\n';
                count++;
            }
        }
        else if (i == 4) {
            if (tmp != deflnk) {
                strcustom = strcustom + '\tcollnk = "' + tmp + '";\n';
                count++;
            }
        }
    }
    //Display <TEXTAREA> Code to Display Based on Custom Requests
    strcustom = strcustom + "\tDisplayMcAfeeAlerts();\n";
    DefaultCode();
    strDisplayCode = strcode.replace("\tDisplayMcAfeeAlerts();\n", strcustom);
    //Display <TEXTAREA> Code
    document.getElementById('DisplayCode').value = strDisplayCode;
    //Dinamically Expand Height of <TEXTAEA> To Reflect Customization Options
    //document.all['DisplayCode'].style.height = (105 + (count * 10));

}

function CopyToClipboard(elem) {
    var l_textToCopy = elem.value; // might need innerHTML instead if we use textarea

    // Because 'innerHTML' encodes some special chars, we need to decode
    // them so the user will get the right code syntax in the clipboard
    //l_textToCopy = l_textToCopy.replace(/</g, "&lt;");
    //l_textToCopy = l_textToCopy.replace(/>/g, "&gt;");
    //l_textToCopy = l_textToCopy.replace(/&/g, "&");

    if (window.clipboardData && clipboardData.setData) { // Explorer
        clipboardData.setData("Text", l_textToCopy);
    }
    else { // Firefox
        try {
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            var Cc = Components.classes;
            var Ci = Components.interfaces;
            var Cstr = Cc["@mozilla.org/supports-string;1"];
            var CTra = Cc["@mozilla.org/widget/transferable;1"];
            var CClp = Cc["@mozilla.org/widget/clipboard;1"];
            var str = Cstr.createInstance(Ci.nsISupportsString);
            if (!str) return false; str.data = l_textToCopy;
            var trans = CTra.createInstance(Ci.nsITransferable);
            if (!trans) return false;
            trans.addDataFlavor("text/unicode");
            trans.setTransferData("text/unicode", str, l_textToCopy.length * 2);
            var clipboard = CClp.getService(Ci.nsIClipboard);
            if (!clipboard) return false;
            clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);
            return true;
        }
        catch (err) {
            alert("For Mozilla Firefox users, please click the textbox above to automatically select the alert code. Copy the selected HTML code [Ctrl+C] and then paste [Ctrl+V] the copied code where you want the alerts to be displayed.");
        }
    }
}


function trim(inputString) {

    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") {
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
    }
    return retValue;
}