﻿function createWrapper(siteName,privacy,terms) {
    if (privacy == null) { privacy = 552; }
    if (terms == null) { terms = 553; }
    document.write("<div id=\"LinkWarning\" class=\"linkWarning\"></div>");
    document.write("<div id=\"LinkMessage\" class=\"linkMessage\">");
    document.write("<p>Thank you for visiting our web site.  <strong>You are now leaving our site.</strong></p>");
    document.write("<p>This link will take you to a web site not owned or operated by HP Hood LLC, and our Terms of Use and Privacy Policy will not apply for use of that web site.  HP Hood LLC is not responsible for the content, operation, potential collection and use of data for web sites not owned or operated by or on behalf of our company.  HP Hood LLC encourages you to read both the <a id=\"TermsLink\" href=\"/info/default.aspx?id=" + terms + "\">Terms of Use</a> and <a href=\"/info/default.aspx?id=" + privacy + "\">Privacy Policy</a> of this site and every web site you visit. </p>");
    document.write("<p></p>");
    document.write("<br /><br /> ");
    document.write("<p style=\"text-align:right\"><a id=\"lnkContinue\" href=\"#\" onclick=\"shPanel('hidden');\" class=\"linkButton\">Continue</a>&nbsp;<a id=\"lnkReturn\" href=\"#\" onclick=\"returnSite();\" class=\"linkButton\">Return to " + siteName + "</a></p>");
    document.write("</div>");
}

//Code Developed By Don Jereczek
//HP Hood IT Services
//Last Modified 09/11/2009

function setLinkWarning() {
    //Common Variables
    var validDomains = 'hood.com,hphood.com,careers.hphood.com,kemps.com,heluvagood.com,crowleyfoods.com,milkmandelivers.com,hoodhomedelivery.com,pennmaid.com,rosenbergers.com,maggiocheese.com,axelrod.com,brighams.com,besimplysmart.com,hphoodllc.com,hoodcottagecheese.com';
    var cImage = '/images/global/LinkWarningBackground.png';
    var warningWrapper = document.getElementById('LinkWarning')
    var warningMessage = document.getElementById('LinkMessage');
    var msgWidth = 350;
    var msgHeight = 320;

    //Set height of background image
    var docHeight;
    if (typeof document.height != 'undefined') {
        docHeight = document.height + 20;
    }
    else if (document.compatMode && document.compatMode != 'BackCompat') {
        docHeight = document.documentElement.scrollHeight;
    }
    else if (document.body && typeof document.body.scrollHeight !=
    'undefined') {
        docHeight = document.body.scrollHeight;
    }

    //Get actual height of window
    var winH
    var winV

    if (navigator.appName == 'Netscape') {
        winH = window.innerHeight;
        winV = window.innerWidth;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        winV = parseInt(document.documentElement.offsetWidth, 10);
        winH = parseInt(document.documentElement.offsetHeight, 10);
    } else if (document.body) {
        winV = parseInt(document.body.offsetWidth, 10);
        winH = parseInt(document.body.offsetHeight, 10);
    }


    //if window height is greater than content set image height to window height
    if (docHeight < winH) {
        docHeight = winH;
    }

    //Set image height
    warningWrapper.style.height = docHeight + 'px';

    //Set left and top position of dialog
    warningMessage.style.top = parseInt((winH - msgHeight) / 2) + 'px';
    warningMessage.style.left = parseInt((winV - msgWidth) / 2) + 'px';

    //Get IE Version
    var appVer = navigator.appVersion.toLowerCase();
    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);
    var iePos = appVer.indexOf('msie');
    if (iePos != -1) {
        is_minor = parseFloat(appVer.substring(iePos + 5, appVer.indexOf(';', iePos)))
        is_major = parseInt(is_minor);
    }

    //Based on IE version display background overlay image
    if ((iePos != -1) && (is_major < 7) && (is_minor >= 5.5)) {
        warningWrapper.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + cImage + "', sizingMethod='scale')";
    } else {
        warningWrapper.style.backgroundImage = 'url(' + cImage + ')';
    }

    //Fetch all anchor tags in site
    var linkTypes = new Array('a', 'area');

    for (var lt = 0; lt < linkTypes.length; lt++) {
        var getLinks = document.getElementsByTagName(linkTypes[lt]);

        //Loop through links and domains to determine if hphood site
        for (var i = 0; i < getLinks.length; i++) {
            var currLink = getLinks[i];
            if (currLink.href.substring(0, 4) == 'http') {
                var url = currLink.href
                url = url.substring(url.indexOf("://") + 3, url.length - url.indexOf("://") + 3).replace('www.', '');
                if (url.indexOf("/") != -1) { url = url.substring(0, url.indexOf("/")); }
                if (validDomains.indexOf(url) == -1) {
                    if (currLink.target.toLowerCase() == '_blank') {
                        currLink.onclick = new Function("hideSite('" + getLinks[i].href + "',true)");
                    } else {
                        currLink.onclick = new Function("hideSite('" + getLinks[i].href + "',false)");
                    }
                    currLink.href = '#';
                    currLink.target = '_self';
                }
            }
        }
    }
}

function hideSite(redirect,newWindow){
    shPanel('visible');
    document.getElementById('lnkContinue').href = redirect;
    if (newWindow == true){
        document.getElementById('lnkContinue').target = '_blank';
    }
}

function returnSite(){
    shPanel('hidden');
}

function shPanel(state){
    document.getElementById('LinkWarning').style.visibility = state;
    document.getElementById('LinkMessage').style.visibility = state;
}