



var upgradeBrowserComponent = {
	"title" : 'Upgrade your browser',
	"ft" : '<p><a id="upgradeBrowserCloseButton"><img height="23" width="23" src="/digitalAssets/67/67771_icoclose.gif" alt="" /></a></p> <p>We no longer support any Internet Explorer browsers below 7.0. Please upgrade your browser now for best possible view of our web page.</p> <p>Choose to download any of the browsers below:</p> <table width="50%" cellspacing="0" cellpadding="0" border="0">   <tbody>     <tr>       <td align="left"><img height="19" width="20" src="/digitalAssets/67/67769_icofirefox.gif" alt="" /></td>       <td align="left"><a href="http://www.mozilla.com/firefox/" target="_blank"> Firefox &raquo; </a></td>     </tr>     <tr>       <td align="left"><img height="19" width="20" src="/digitalAssets/67/67770_icochrome.gif" alt="" /></td>       <td align="left"><a href="http://www.google.com/chrome" target="_blank"> Google Chrome &raquo; </a></td>     </tr>     <tr>       <td align="left"><img height="20" width="19" src="/digitalAssets/67/67772_icoie.gif" alt="" /></td>       <td align="left"><a target="_blank" href="http://www.microsoft.com/windows/internet-explorer/default.aspx"> 			Internet Explorer &raquo; </a></td>     </tr>     <tr>       <td align="left"><img height="21" width="19" src="/digitalAssets/67/67774_icosafari.gif" alt="" /></td>       <td align="left"><a target="_blank" href="http://www.apple.com/safari/download/"> Safari &raquo; </a></td>     </tr>     <tr>       <td align="left"><img height="23" width="19" src="/digitalAssets/67/67773_icoopera.gif" alt="" /></td>       <td align="left"><a target="_blank" href="http://www.opera.com/download/"> Opera &raquo; </a></td>     </tr>   </tbody> </table> <p>- NASDAQ OMX Corporate Web Team</p>',
	// POPUP
	"popupStatus" : 0,
	"loadPopup" : function () {
		//loads popup only if it is disabled  
		if(this.popupStatus == 0) {  
			$("#upgradeBrowserPopupBackground").css({  
				"opacity": "0.7"  
			});  
			$("#upgradeBrowserPopupBackground").fadeIn("slow");  
			$("#upgradeBrowserPopup").fadeIn("slow");  
			this.popupStatus = 1;  
		}
	},
	"disablePopup" : function () {
		//disables popup only if it is enabled  
		if(this.popupStatus == 1) {  
			$("#upgradeBrowserPopupBackground").fadeOut("slow");  
			$("#upgradeBrowserPopup").fadeOut("slow");  
			this.popupStatus = 0;  
		}
	},
	"centerPopup" : function () {
		//request data for centering
		var windowWidth = (document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth;
		var windowHeight = (document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight;
		var popupHeight = $("#upgradeBrowserPopup").height();
		var popupWidth = $("#upgradeBrowserPopup").width();
		//centering
		$("#upgradeBrowserPopup").css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});
		//only need force for IE6
		$("#upgradeBrowserPopupBackground").css({
			"height": windowHeight
		});
	},
	"twoWeeksSinceLast" : function (savedUpdateTimeCookie) {
		var dateArray = savedUpdateTimeCookie.split('-');
		var today = new Date();
		var cookieDate = new Date();
		
		var dateArrayYear = parseInt(dateArray[0]);
		var dateArrayMonth = parseInt(dateArray[1]);
		var dateArrayDay = parseInt(dateArray[2]);
		
		cookieDate.setFullYear(dateArrayYear, dateArrayMonth - 1, dateArrayDay);
		
		if(cookieDate < today) {
			return true;
		} else {
			return false;
		}
	},
	getISODate: function( yearAdd, monthAdd, dateAdd, lastWeekDay ) {
    	var dateString = "";
    	var date = new Date();
    	if ( yearAdd != null || yearAdd != undefined ) {
    		date.setFullYear( date.getFullYear() + yearAdd );
    	}
    	if ( monthAdd != null || monthAdd != undefined ) {
    		date.setMonth( date.getMonth() + monthAdd );
    	}
    	if ( dateAdd != null || dateAdd != undefined ) {
    		date.setDate( date.getDate() + dateAdd );
    	}
		if ( lastWeekDay == true ) {
    		if ( date.getDay() == 0 ) { //sunday
    			date.setDate( date.getDate() -2 );
    		} else if ( date.getDay() == 6 ) {	//satday
    			date.setDate( date.getDate() -1 );
    		}
    	}
    	dateString += date.getFullYear() + "-";
    	dateString += ((date.getMonth()+1) < 10 )?"0":"";
    	dateString += (date.getMonth()+1) + "-";
    	dateString += (date.getDate() < 10 )?"0":"";
    	dateString += date.getDate();
    	return dateString;
    }
};
var cookies = {
    	/*
    	 * returns a date from (client's) now
    	 */
		expires: function() {
			var expires = new Date();
			expires.setFullYear(expires.getFullYear() + 1, expires.getMonth() + 1, 28);// One year from client's  now..
			return expires;
		},
		
		/*
		 * Simple key value pair for setting a value in a cookie.
		 * @param name the name key
		 * @value the value for a given (name) key
		 * @expires a valid date object; example date 29/05/2008 23:59:00
		 */
		set: function (name, value, expires) {
			document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString();
		},
		/*
		 * returns a value for a given key. See set for more info.
		 */
		get: function (name) {
			var v = document.cookie.match("(^|;)?" + name + "=([^;]*)(;|$)");
			return v != null ? unescape(v[2]) : null;
		}
	};

jQuery(document).ready(function() {
	var weekAhead = upgradeBrowserComponent.getISODate(0,0,14,false);
	var savedUpdateTimeCookie = cookies.get("CorpUpgradeBrowserShowCookie");

	// Build popup content container.
	var _contentBackground = jQuery("<div>").attr("id", "upgradeBrowserPopupBackground");
	var _content = jQuery("<div>").attr("id", "upgradeBrowserPopup").html("<h2>" + upgradeBrowserComponent.title + "</h2>" + upgradeBrowserComponent.ft);
	
	//document.body.appendChild(_content);
	
	jQuery("body").append(_contentBackground).append(_content);
	
	if((jQuery.browser.msie && jQuery.browser.version < 7) && (savedUpdateTimeCookie == null || savedUpdateTimeCookie == "" || upgradeBrowserComponent.twoWeeksSinceLast(savedUpdateTimeCookie))) {
		cookies.set("CorpUpgradeBrowserShowCookie", weekAhead, cookies.expires());
		upgradeBrowserComponent.centerPopup();
		upgradeBrowserComponent.loadPopup();
	}
	//CLOSING POPUP
	//Click the x event!
	$("#upgradeBrowserCloseButton").click(function(){
		upgradeBrowserComponent.disablePopup();
	});
	//Click out event!
	$("#upgradeBrowserPopupBackground").click(function(){
		upgradeBrowserComponent.disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode == 27 && popupStatus==1) {
			upgradeBrowserComponent.disablePopup();
		}
	});
});


