//---- write favicon ----//
document.write('<link rel="shortcut icon" href="http://cdn.nhl.com/favicon.ico"/>');

//---- randnum for doubleclick ads ----//
var time = new Date();
var randnum= (time.getTime());

//---- cookie functions ----//
function setCookie(name, value, expires, path, domain, secure) {
       var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
       document.cookie = curCookie;
     }

function getCookie(name) {
       var dc = document.cookie;
       var prefix = name + "=";
       var begin = dc.indexOf("; " + prefix);
       if (begin == -1) {
         begin = dc.indexOf(prefix);
         if (begin != 0) return null;
       } else
         begin += 2;
       var end = document.cookie.indexOf(";", begin);
       if (end == -1)
         end = dc.length;
       return unescape(dc.substring(begin + prefix.length, end));
     }

function cupWindow(URL) {
var cexists = getCookie('cupcookie');
  if (cexists) {return false;}
  else {
          setCookie('cupcookie','true');
          popRestricted(URL, "myCupWindow", 290, 250);
   }
 }

//---- window functions ----//
// "private" method = you should not have to call this function directly, use one of the other popXXXXX functions, they chain up to this
function popNewWin(URL, winName, winAttribs) {
        winAttribs=winAttribs+"location=0,menubar=0,status=0,titlebar=0,toolbar=0";
        var newWindow=window.open(URL, winName, winAttribs);
        if (newWindow.opener == null) newWindow.opener = mainWindow;
        return newWindow;
}

// For all the popXXXXX funtions:
// URL is the page you would like to be shown in the popped-up window
// winName is a ONE word name for that window
// wwidth is a number for the width of the window
// wheight is a number representing the window's height
function popFlexible(URL, winName, wwidth, wheight) {
        flexibleWin=popNewWin(URL, winName, "width="+wwidth+",height="+wheight+",resizable=1,scrollbars=1,");
        flexibleWin.focus();
}
function popResizable(URL, winName, wwidth, wheight) {
        resizableWin=popNewWin(URL, winName, "width="+wwidth+",height="+wheight+",resizable=1,scrollbars=0,");
        resizableWin.focus();
}
function popScrollable(URL, winName, wwidth, wheight) {
        scrollableWin=popNewWin(URL, winName, "width="+wwidth+",height="+wheight+",resizable=0,scrollbars=1,");
        scrollableWin.focus();
}
function popRestricted(URL, winName, wwidth, wheight) {
        restrictedWin=popNewWin(URL, winName, "width="+wwidth+",height="+wheight+",resizable=0,scrollbars=0,");
        restrictedWin.focus();
}
function popFocusedWindow(onlickStr) {
	newwindow=onlickStr;
	if (window.focus) {newwindow.focus()}
}
function popVideoPlayerWithURL(onlickStr) {
	newwindow=window.open(onlickStr, 'highlightMachine', 'height=610,width=860,resizable=yes,status=no,scrollbars=no,toolbar=no,menubar=no,location=no');
	if (window.focus) {newwindow.focus()}
}

//---- div toggling, tokenizing, & related print functions ----//
function printPage() {
    //some ABSOLUTE lameness here.....    var foo = document.getElementById("mediaLeftNaviTD");    if(foo) {
        if(foo.width == 5) { 
            foo.width=131;
            toggleGroupOn('mediaTopNavDiv,mediaLeftNaviDiv,mediaLeadersDiv');
        } else {
            foo.width=5;
            toggleGroupOff('mediaTopNavDiv,mediaLeftNaviDiv,mediaLeadersDiv');
        }
        return; //lame    }

    var foo2 = document.getElementById("leftNaviTD");    if(foo2) {
        if(foo2.width == 5) { 
            foo2.width=159;
            toggleGroupOn('topAdDiv,leftNaviDiv,networkNaviDiv,rightAdDiv');
        } else {
            foo2.width=5;
            toggleGroupOff('topAdDiv,leftNaviDiv,networkNaviDiv,rightAdDiv');
        }
        return;    }
}String.prototype.tokenize = tokenize;function tokenize() {    var input             = "";    var separator         = " ";    var trim              = "";    var ignoreEmptyTokens = true;    try {        String(this.toLowerCase());    } catch(e) {        window.alert("Tokenizer Usage: string myTokens[] = myString.tokenize(string separator, string trim, boolean ignoreEmptyTokens);");        return;    }    if(typeof(this) != "undefined") {          input = String(this);    }    if(typeof(tokenize.arguments[0]) != "undefined") {        separator = String(tokenize.arguments[0]);    }    if(typeof(tokenize.arguments[1]) != "undefined") {        trim = String(tokenize.arguments[1]);    }    if(typeof(tokenize.arguments[2]) != "undefined") {        if(!tokenize.arguments[2])            ignoreEmptyTokens = false;    }    var array = input.split(separator);    if(trim)        for(var i=0; i<array.length; i++) {            while(array[i].slice(0, trim.length) == trim)                array[i] = array[i].slice(trim.length);            while(array[i].slice(array[i].length-trim.length) == trim)                array[i] = array[i].slice(0, array[i].length-trim.length);        }    var token = new Array();    if(ignoreEmptyTokens) {        for(var i=0; i<array.length; i++)            if(array[i] != "")                token.push(array[i]);    } else {        token = array;    }    return token;}function toggleSingleLayerOnGroupOff(whichLayer, allLayers) {    return toggleMultipleOffAndMultipleOn(allLayers, whichLayer);}function toggleSingleLayerOffGroupOn(whichLayer, allLayers) {    return toggleMultipleOffAndMultipleOn(whichLayer, allLayers);}function toggleGroupOn(layersOn) {    return toggleMultipleOffAndMultipleOn(undefined, layersOn);}
function toggleGroupOff(layersOff) {    return toggleMultipleOffAndMultipleOn(layersOff, undefined);}function toggleMultipleOffAndMultipleOn(layersOff, layersOn) {    if(layersOff) {        var tokensOff = layersOff.tokenize(",", "", false);        // First, turn layers OFF        for(var i=0; i<tokensOff.length; i++) {            if (document.getElementById) {                var poop = document.getElementById(tokensOff[i]).style;                poop.display = 'none';            } else if (document.all) {                var poop = document.all[tokensOff[i]].style;                poop.display = 'none';            } else if (document.layers) {                var poop = document.layers[tokensOff[i]].style;                poop.display = 'none';            }        }    }    if(layersOn) {        var tokensOn  = layersOn.tokenize(",", "", false);        // Now, ON        for(var i=0; i<tokensOn.length; i++) {            if (document.getElementById) {                // this is the way the standards work                var style2 = document.getElementById(tokensOn[i]).style;                style2.display = '';            } else if (document.all) {                // this is the way old msie versions work                var style2 = document.all[tokensOn[i]].style;                style2.display = '';            } else if (document.layers) {                // this is the way nn4 works                var style2 = document.layers[tokensOn[i]].style;                style2.display = '';            }        }    }}

function popPrintWin(URL, winName, wwidth, wheight) {
        var winAttribs="width="+wwidth+",height="+wheight+",resizable=1,scrollbars=1,location=0,menubar=0,status=0,titlebar=0,toolbar=0";
        var newWindow=window.open(URL, winName, winAttribs);
        if (newWindow.opener == null) newWindow.opener = mainWindow;
        newWindow.focus();
        return newWindow;
}

function printThisDotcomPage() {
    if(document.getElementById) {        var foo2 = document.getElementById("printMeNHL");        if(foo2) {            var clonedFullContent = foo2.cloneNode(true);            clonedFullContent.style.overflow="visible";    		var newWin = popPrintWin("", "printWin", 975, 700);

            var objectTags = clonedFullContent.getElementsByTagName("p");            for(var k=0; k<objectTags.length; k++) {                if(objectTags[k] && objectTags[k].id && (objectTags[k].id=='removeForPrintPage') && objectTags[k].hasChildNodes()) {
                    while(objectTags[k].hasChildNodes()) {                        objectTags[k].removeChild(objectTags[k].firstChild);                    }                } else if(objectTags[k] && objectTags[k].id && (objectTags[k].id=='removeForPrintPage') && (objectTags[k].nextSibling != null)) {
                    while(objectTags[k].nextSibling.hasChildNodes()) {                        objectTags[k].nextSibling.removeChild(objectTags[k].nextSibling.firstChild);                    }                }
            }

            var scriptTags = clonedFullContent.getElementsByTagName("object");            for(var kk=0; kk<scriptTags.length; kk++) {                if(scriptTags[kk]) {                    while(scriptTags[kk].hasChildNodes()) {                        scriptTags[kk].removeChild(scriptTags[kk].firstChild);                    }//                    scriptTags[kk].innerHTML = "";
                }            }

//    		var newWin = popPrintWin("", "printWin", 975, 700);            var printWinBody = newWin.document.getElementsByTagName("body")[0];            if(printWinBody) {                while(printWinBody.hasChildNodes()) {  //just in case it has elements already                    printWinBody.removeChild(printWinBody.firstChild);                }            }            var printWinHead = newWin.document.getElementsByTagName("head")[0];            if(!printWinHead) {                printWinHead = newWin.document.createElement('head');                newWin.document.appendChild(printWinHead);            }            var printWinTitle = newWin.document.getElementsByTagName("title")[0];            if(!printWinTitle) {                printWinTitle = newWin.document.createElement('title');                printWinTitle.text = "NHL.com Hockey News!";                if(printWinHead) {                    printWinHead.appendChild(printWinTitle);                }            }            printWinBody.style.backgroundColor="#FFFFFF";            printWinBody.style.margin="10px;10px;10px;10px";            var printWinPrinterButtonLink = newWin.document.createElement('a');            var printWinPrinterButtonImage = newWin.document.createElement('img');            printWinPrinterButtonLink.id="printWinLinkToPrint";            printWinPrinterButtonImage.src="http://cdn.nhl.com/images/printMe.gif";            printWinPrinterButtonImage.border="0";            printWinPrinterButtonImage.align="right";            printWinPrinterButtonLink.appendChild(printWinPrinterButtonImage);            printWinBody.appendChild(printWinPrinterButtonLink);            var printWinLinks = clonedFullContent.getElementsByTagName("a");            var numLinks = printWinLinks.length;            for(var i=0; i<numLinks; i++) {                var aLink = printWinLinks[i];                aLink.disabled="DISABLED";                if(aLink.innerHTML.length>100) {
                	if(aLink.innerHTML.indexOf('<img') < 0) {	                	aLink.innerHTML=aLink.innerHTML.substring(0,100)+"...";
                	}
                }                aLink.href="javascript:void(0)";                if(aLink.target) {                    aLink.target = "";                }            }
            var fullDiv = newWin.document.createElement('div');            fullDiv.innerHTML = clonedFullContent.innerHTML;            printWinBody.appendChild(fullDiv);            var printWinStyleSheet = newWin.document.createElement('link');            printWinStyleSheet.rel = "StyleSheet";            printWinStyleSheet.href = "http://cdn.nhl.com/css/nhl.css";            printWinStyleSheet.type = "text/css";            var printWinHead = newWin.document.getElementsByTagName("head")[0];            printWinHead.appendChild(printWinStyleSheet);            var printMeLink = newWin.document.getElementById("printWinLinkToPrint");            if(printMeLink)                printMeLink.href = "javascript:this.print()";            var foo2 = newWin.document.getElementById("homePrintEmailSearchBar");            if(foo2)                foo2.style.display='none';        }    } else {        alert("Sorry, your browser does not support this feature");    }}

function printThisPage() {
    if(document.getElementById) {        var foo2 = document.getElementById("printThisDiv");        if(foo2) {            var clonedFullContent = foo2.cloneNode(true);            clonedFullContent.style.overflow="visible";    		var newWin = popPrintWin("", "printWin", 975, 700);

            var objectTags = clonedFullContent.getElementsByTagName("p");            for(var k=0; k<objectTags.length; k++) {                if(objectTags[k] && objectTags[k].id && (objectTags[k].id=='removeForPrintPage') && objectTags[k].hasChildNodes()) {
                    while(objectTags[k].hasChildNodes()) {                        objectTags[k].removeChild(objectTags[k].firstChild);                    }                } else if(objectTags[k] && objectTags[k].id && (objectTags[k].id=='removeForPrintPage') && (objectTags[k].nextSibling != null)) {
                    while(objectTags[k].nextSibling.hasChildNodes()) {                        objectTags[k].nextSibling.removeChild(objectTags[k].nextSibling.firstChild);                    }                }
            }

			// This is a disgusting, pathetic hack.  Please rewrite the print functions, Marc.  Thanks.
            var divTags = clonedFullContent.getElementsByTagName("div");
            for(var ddd=0; ddd<divTags.length; ddd++) {
                if(divTags[ddd] && divTags[ddd].className && (divTags[ddd].className=='newsItemPageContent' || divTags[ddd].className=='bodyText')) {
                	divTags[ddd].className='';
                }
				if(divTags[ddd] && divTags[ddd].className && (divTags[ddd].className=='headshots')) {
					divTags[ddd].style.display = "none";				}
            }

            var scriptTags = clonedFullContent.getElementsByTagName("object");            for(var kk=0; kk<scriptTags.length; kk++) {                if(scriptTags[kk]) {                    while(scriptTags[kk].hasChildNodes()) {                        scriptTags[kk].removeChild(scriptTags[kk].firstChild);                    }                }            }

            var scrpTags = clonedFullContent.getElementsByTagName("script");
            for(var ijk=0; ijk<scrpTags.length; ijk++) {                if(scrpTags[ijk]) {
                	scrpTags[ijk].removeAttribute("src");                }            }

            var printWinBody = newWin.document.getElementsByTagName("body")[0];            if(printWinBody) {                while(printWinBody.hasChildNodes()) {  //just in case it has elements already                    printWinBody.removeChild(printWinBody.firstChild);                }            }            var printWinHead = newWin.document.getElementsByTagName("head")[0];            if(!printWinHead) {                printWinHead = newWin.document.createElement('head');                newWin.document.appendChild(printWinHead);            }            var printWinTitle = newWin.document.getElementsByTagName("title")[0];            if(!printWinTitle) {                printWinTitle = newWin.document.createElement('title');                printWinTitle.text = "NHL.com Hockey News!";                if(printWinHead) {                    printWinHead.appendChild(printWinTitle);                }            }            printWinBody.style.backgroundColor="#FFFFFF";            printWinBody.style.backgroundImage="none";            printWinBody.style.margin="10px;10px;10px;10px";            var printWinPrinterButtonLink = newWin.document.createElement('a');            var printWinPrinterButtonImage = newWin.document.createElement('img');            printWinPrinterButtonLink.id="printWinLinkToPrint";            printWinPrinterButtonImage.src="http://cdn.nhl.com/images/printMe.gif";            printWinPrinterButtonImage.border="0";            printWinPrinterButtonImage.align="right";            printWinPrinterButtonLink.appendChild(printWinPrinterButtonImage);            printWinBody.appendChild(printWinPrinterButtonLink);            var printWinLinks = clonedFullContent.getElementsByTagName("a");            var numLinks = printWinLinks.length;            for(var i=0; i<numLinks; i++) {                var aLink = printWinLinks[i];                aLink.disabled="DISABLED";                if(aLink.innerHTML.length>100) {
                	if(aLink.innerHTML.indexOf('<img') < 0) {	                	aLink.innerHTML=aLink.innerHTML.substring(0,100)+"...";
                	}
                }                aLink.href="javascript:void(0)";                if(aLink.target) {                    aLink.target = "";                }            }
            var fullDiv = newWin.document.createElement('div');            fullDiv.innerHTML = clonedFullContent.innerHTML;            printWinBody.appendChild(fullDiv);

            var styleSheets = document.getElementsByTagName("link");			if(styleSheets) {
				for(var ss=0; ss<styleSheets.length; ss++) {
					if(styleSheets.item(ss).rel == "stylesheet") {						if(styleSheets.item(ss).href) {							var printWinStyleSheet = newWin.document.createElement('link');							printWinStyleSheet.rel = "StyleSheet";							printWinStyleSheet.href = styleSheets.item(ss).href;
							printWinStyleSheet.type = "text/css";							newWin.document.getElementsByTagName("head")[0];							printWinHead.appendChild(printWinStyleSheet);
						}
					}
				}
			}            var printMeLink = newWin.document.getElementById("printWinLinkToPrint");            if(printMeLink)                printMeLink.href = "javascript:this.print()";            var foo2 = newWin.document.getElementById("homePrintEmailSearchBar");            if(foo2)                foo2.style.display='none';        }    } else {        alert("Sorry, your browser does not support this feature");    }
    
    
}
