﻿//Code Developed By Don Jereczek
//HP Hood IT Services
//Last Modified 06/13/2007

function setLinkWarning(){
    //Common Variables
    var validDomains = new Array('hphood.com','kemps.com','heluvagood.com','crowleyfoods.com','milkmandelivers.com','hoodhomedelivery.com','pennmaid.com','rosenbergers.com','maggiocheese.com','axelrod.com','kempsemail.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;
    
    //Set left and top position of dialog
    warningMessage.style.top = parseInt((winH - msgHeight)/2);
    warningMessage.style.left = parseInt((winV - msgWidth)/2);

    //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
    myBody = document.getElementsByTagName('body')[0];
    var linkTypes = new Array('a','area');

    for (var lt=0; lt<linkTypes.length; lt++){
    var getLinks = myBody.getElementsByTagName(linkTypes[lt]);
    var isValid = false;
    
    //Loop through links and domains to determine if hphood site
    for (var i=0; i<getLinks.length; i++) {
        for (var i2=0; i2<validDomains.length; i2++){
            var currIndex = getLinks[i].href.indexOf(validDomains[i2]);
            if (currIndex != -1){
                isValid = true;
            }
        }
        
        //If no match is found wrap script around link
        if (isValid == false){
            if (getLinks[i].target.toLowerCase() == '_blank'){
                getLinks[i].onclick = new Function("hideSite('"+getLinks[i].href+"',true)");
            }else{
                getLinks[i].onclick = new Function("hideSite('"+getLinks[i].href+"',false)");
            }
            getLinks[i].href = '#';
            getLinks[i].target = '_self';
        }else{
            isValid = false;
        }
        
    }
    }
}

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;
}