﻿<!--// 
var isMac = false;
var isSafari = false;
var isFirefox = false;
var isMSIE = false;
var isMSIE6 = false;

if (navigator.userAgent.indexOf("Macintosh") != -1){
    isMac = true;
}

if (navigator.userAgent.indexOf("Safari") != -1){
	isSafari = true;
} else if (navigator.userAgent.indexOf("MSIE") != -1){
    isMSIE = true;
    if (navigator.userAgent.indexOf("MSIE 6.0") != -1){
	    isMSIE6 = true;
    }
} else if (navigator.userAgent.indexOf("Firefox") != -1){
	isFirefox = true;
}

function showModal(divID, showIt, hasShadow, scrollable, scrollTop){
    var modalDIV = document.getElementById(divID);
    if (modalDIV != null){
	    var anchorDIV = document.getElementsByTagName("BODY")[0];
	    var selectVisibility;
        if (showIt){
            modalDIV.style.display = "block";
			if (scrollTop == null){
				if (isSafari){
					scrollTop = document.body.scrollTop;
				} else {
					scrollTop = document.documentElement.scrollTop;
				}
            	centerDPop(divID);
			}
            selectVisibility = "hidden";
            if (!scrollable){
                document.documentElement.style.overflow = "hidden";
            }
			window.onresize = function(){showModal(divID, showIt, hasShadow, scrollable, scrollTop);}
	    } else {
            modalDIV.style.display = "none";
	        selectVisibility = "visible";
            if (isSafari){
				document.documentElement.style.overflow = "scroll";
			} else {
				document.documentElement.style.overflow = "auto";
			}
			window.onresize = null;
    	}
        if (hasShadow){
            showModalShadow(divID, showIt, scrollable, scrollTop);
        }
        if (document.forms.length > 0){
	        for (var i = 0; i < document.forms[0].elements.length; i++){
    	        if (document.forms[0].elements[i].type == "select-one"){
	    	        //document.forms[0].elements[i].style.visibility = selectVisibility;
		        }
		    }
		}
    }
}

//Centering Functions
function getDPopIndent (popupDimension, isHeight){
	if (isHeight){
		if (window.innerHeight)
			return ((window.innerHeight - popupDimension) / 2);
		else if (window.document.documentElement && window.document.documentElement.clientHeight)
			return ((window.document.documentElement.clientHeight - popupDimension) /2 );
		else if (window.document.body.clientHeight)
			return ((window.document.body.clientHeight - popupDimension) / 2);
	} else {
		if (window.innerWidth)
			return ((window.innerWidth - popupDimension) / 2);
		else if (window.document.documentElement && window.document.documentElement.clientWidth)
			return ((window.document.documentElement.clientWidth - popupDimension) / 2);
		else if (window.document.body.clientWidth)
			return ((window.document.body.clientWidth - popupDimension) / 2);
	}
}

//Get coordinates for centering DHTML Popup
function getDPopCoords(popupWidth, popupHeight){
	var centerCoordinates = getDPopIndent(popupWidth, false) + ',' + getDPopIndent(popupHeight, true);
	return centerCoordinates;
}

function centerDPop(popID){
	var divPop = document.getElementById(popID);
	var coords = getDPopCoords(parseInt(divPop.offsetWidth), parseInt(divPop.offsetHeight)).toString().split(",");
	divPop.style.left = Math.round(parseInt(coords[0])) + "px";
	if (isSafari){
		divPop.style.top = Math.round(parseInt(coords[1]) + document.body.scrollTop) + "px";
	} else {
		divPop.style.top = Math.round(parseInt(coords[1]) + document.documentElement.scrollTop) + "px";
	}
}

function showModalShadow(divID, showIt, scrollable, scrollTop){
	var anchorDIV = document.getElementsByTagName("BODY")[0];
	var divShadow = document.getElementById(divID + "Shadow");
	if (divShadow == null){
	    var writeDIV = document.createElement("div");
	    writeDIV.setAttribute("id", "" + divID + "Shadow");
	    anchorDIV.appendChild(writeDIV);
	}
    if (showIt){
		divShadow = document.getElementById(divID + "Shadow");
		divShadow.className = "modalShadow";
		divShadow.style.width = "100%";
		divShadow.style.left = "0px";
		if (scrollable){
			divShadow.style.height = document.documentElement.clientHeight + "px";
			divShadow.style.top = "0px";
		} else {
			if (isMSIE){
				divShadow.style.height = document.documentElement.clientHeight + "px";
				divShadow.style.top = scrollTop + "px";
			} else {
				divShadow.style.height = (window.innerHeight + 100) + "px";
				divShadow.style.top = (scrollTop - 100) + "px";
				if ((isMac && isFirefox) || isSafari){
					window.scrollTo(0, scrollTop);
				}
			}
		}
        divShadow.style.display = "block";
    } else {
        divShadow.style.display = "none";
	}
}

function showProduct(productID){
	//var selectedProduct = getProductByID(productID);
	//dcsMultiTrack('WT.cg_n','Engagement Activities','WT.cg_s','Template_Download','DCS.dcsuri','/postitlabels/templatedownload.html','WT.ti','Productclicks','WT.ac','Template Download: '+selectedProduct.category + ': ' + selectedProduct.id)
	document.images["productPopupImg"].src = "images/products/MMM_" + productID + ".jpg";
	showModal("productPopup", true, true, false);
}

function hideProduct(){
	showModal("productPopup", false, true, false);
}
//-->
