//
// Code to display a marketing popup in the current document
// uses a div, so it can't be blocked.
// This was just copied verbatim from the MMDI marketing pop-up I did, so the
// variable names should be updated.  Yet another thing to fix when their is 
// time.  I love it when they asks for things the day something is supposed
// to be released.
//


function showMarketing()
{
}

//
// cookieName - pretty self-explanatory
// endDate - JS Date object specifying when to stop showing this message to
//			 anyone regardless of whether they have seen it yet
// cssFile - relative path to the css for the popup
function showMarketingPopup(cookieName, endDate, headlineText, msgDiv, cssFile)
{
	// look for the cookie
	var splashSeen = false;
	var cookieName = cookieName + "=";
	var cookies = document.cookie.split(';');
	for (var i = 0; i < cookies.length; i++) {
	        var c = cookies[i];
	        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
	        if (c.indexOf(cookieName) != -1) {
	                splashSeen = true;
	                break;
	        }
	}
	
	if (new Date().getTime() < endDate.getTime() && !splashSeen) {
    	var mktingMsgDiv = document.createElement("div");
    	mktingMsgDiv.className = "mainDiv";

        // create the msg header
        var headline = document.createElement("span");
        headline.className = "headline";
        mktingMsgDiv.appendChild(headline);

        headline.appendChild(document.createTextNode(headlineText));

		mktingMsgDiv.appendChild(msgDiv);
        document.body.appendChild(mktingMsgDiv);

        var closeWindowLink = document.createElement("a");
        closeWindowLink.className = "closeWinLink";
        mktingMsgDiv.appendChild(closeWindowLink);

        closeWindowLink.setAttribute("href", "javascript: void(0);");
        closeWindowLink.onclick = function()
        {
        	document.body.removeChild(mktingMsgDiv);

            // set a cookie, so they don't get it all again
            document.cookie =
            	cookieName + '=seen; ' +
                'expires=' + new Date(endDate.getTime() + 1000 * 60 * 60 * 24).toUTCString() +
                ';' +
                ' path=/';

                return false;
        };

        closeWindowLink.appendChild(document.createTextNode("Close"));

		var styleElement = document.createElement("link");
		styleElement.setAttribute("type", "text/css");
		styleElement.setAttribute("rel", "stylesheet");
		styleElement.setAttribute("href", cssFile);
		
		var bodyHead = document.getElementsByTagName("head")[0];
		if (bodyHead != null)
			bodyHead.appendChild(styleElement);
			
        mktingMsgDiv.style.display = 'block';
	} // end if (!splashSeen)
	
	return true;
}
