
function StatusModule() {

	this.prodTitle = new Array();
	this.prodPage = new Array();
	this.prodInfo = new Array();
				
	this.in_client = navigator.userAgent.indexOf("(R1")>=0 ? "yes" : "no";
	this.statusPlyrObj = this.in_client ? window.external : null;

	if( this.in_client=="no" || this.statusPlyrObj.ComponentVersion("mnetplg:1.0")<=0 )
	document.cookie="mnplugged=no; domain=.real.com; path=/;";

	this.updateNewSubscriptions = function()
	{
		var editionCode = page.getVar('edition_code');
		snaStr = zeitgeist.getRNCookie('RNProduct', 'SN');
		snaValues = snaStr.replace(/^\||\|$/g, '').toLowerCase().split('|');
		html_out = '';
		html_out += '<div class="hl">'+ this.lang['my_account'] + '</div>';
		html_out += '<ul>';

		if (snaValues[0]!='') {
			for(i in snaValues) {
				if (this.snData[snaValues[i]]) {
					var sndat = this.snData[snaValues[i]];
					this.prodTitle[i] = sndat[0];
					this.prodPage[i] = (sndat[1]) ? sndat[1] : false;
					this.prodInfo[i] =  (sndat[2]) ? sndat[2] : false;
					html_out += '<li>';
					if (this.prodPage[i]) {
						if (typeof(this.prodPage[i]['edition']) == 'object') {
							prodPageForEdition = (typeof(this.prodPage[i]['edition'][editionCode]) == 'object') ? 	this.prodPage[i]['edition'][editionCode] : null;
							if (typeof(prodPageForEdition) == 'object') {
								this.prodPage[i] = prodPageForEdition;
							}
						}
						try {
							var params = (typeof this.prodPage[i]['params'] != 'undefined') ? '?'+this.prodPage[i]['params'][editionCode] : '';
						
							if (this.prodPage[i]['target']=='browser') {
								html_out += '<a class="left" href="' + this.prodPage[i]['url'] + params +'" target="">' + this.prodTitle[i] + '</a>';
							}
							else {
								html_out += '<a  class="left" href="javascript://'+ this.prodPage[i]['url'] + '" onClick="javascript:page.openPopUp({ url: \''+this.prodPage[i]['url']+ params +'\', width: 507, height: 400, resize: true });">'+ this.prodTitle[i] +'</a>';
							}
						} catch (e){}
					}
					else {
						html_out += '<span class="left">' + this.prodTitle[i] + '</span>';
					}
											
					if (this.prodInfo[i]) {
						if (typeof(this.prodInfo[i]['edition']) == 'object') {
							prodInfoForEdition = (typeof(this.prodInfo[i]['edition'][editionCode]) == 'object') ? 	this.prodInfo[i]['edition'][editionCode] : null;
							if (typeof(prodInfoForEdition) == 'object') {
								this.prodInfo[i] = prodInfoForEdition;
							}
						}
						var params = (this.prodInfo[i]['params']) ? '?'+this.prodInfo[i]['params'][editionCode] : '';
						if (this.prodInfo[i]['target']=='browser')
							html_out += '<a class="right" href="' + this.prodInfo[i]['url'] + params + '" target=""><img src="' + page.getVar('basepath') + 'inc/guide_status/img/info_gold.gif" width="13" height="13" border="0"></a>';
						else
							html_out += '<a  class="right" href="javascript://'+this.prodInfo[i]['url']+'" onClick="javascript:page.openPopUp({ url: \''+this.prodInfo[i]['url'] + params + '\', width: 507, height: 400,  resize: true });"><img src="' + page.getVar('basepath') + 'inc/guide_status/img/info_gold.gif" width="13" height="13" border="0"></a>';
					}
					html_out += '</li>\n';
				}
			}
		}
		else {
			for(i in this.links) {
				html_out += '<li>';
				html_out += '<a class="full" href="' + this.links[i]['url'] + '" target="">' + this.links[i]['title'] + '</a>';
				html_out += '</li>\n';
			}
		}
		html_out += '<li>';
		if (zeitgeist.isUserLoggedIn()) {
			html_out += '<a class="full" href="javascript:statusModule.signOut();">' + this.lang['sign_out'] +'</a>';
		} else {
			html_out += '<a class="full" href="javascript:statusModule.signIn();">' + this.lang['sign_in'] + '</a>';
		}
		html_out += '</li>\n';
			
		html_out += '</ul>';
		html_out += '<div class="trail"></div>';
		document.getElementById('guide_status').innerHTML = html_out;
	}
	
	this.clearStatus = function() {
		//document.getElementById("statusArea").innerHTML = "";
	}
	

	this.checkReauth = function()  {
		var checkDate =  zeitgeist.getRNCookie('RNUser', 'CD').replace(/^\||\|$/g, '');
		var reauth = false;
		reauth = (checkDate) ? false : true;
		if (!reauth) {
			reauth = (this.getCurrentDateAsYYYYMMDD()<checkDate) ? false : true;
		}
		return reauth;
	}
		
	this.checkReLogin = function() {
		//YYYYMMDD
		var pwDate = zeitgeist.getRNCookie('RNUser', 'PD').replace(/^\||\|$/g, '');		
		var currentDate = this.getCurrentDateAsYYYYMMDD();
		var daysBetween = this.daysBetweenDates(this.getElementsOfYYYYMMDD(pwDate), this.getElementsOfYYYYMMDD(currentDate));
		return (daysBetween>90) ? true : false; // 90 Days
	}
	
	this.signIn = function() {
		this.statusPlyrObj.HandleAction('SignIn');	
	}

	this.signOut = function() {
		this.statusPlyrObj.HandleAction('SignOut');
	}

	this.init = function() {
		if (zeitgeist.isUserLoggedIn()) {
			if (this.checkReauth()) {
				this.statusPlyrObj.ReauthenticateUser("", "", -1, "&step=silentconf", "");
			}
			if (this.checkReLogin()) {
				this.statusPlyrObj.LogoutCurrentUser();
				this.signIn();
			}
		}
		else {
			try { this.statusPlyrObj.LogoutCurrentUser();} catch (e){}
		}
		this.clearStatus();
		this.updateNewSubscriptions();

		window.rpOnLoginFunctions[window.rpOnLoginFunctions.length] = function() { 
			top.location.reload();
 	    };
	}
	
// Helper

	//  getElementsOfYYYYMMDD([YYYYMMDD]) : Array
	this.getElementsOfYYYYMMDD = function(dateStr) {
		return [dateStr.substr(0,4), dateStr.substr(4,2), dateStr.substr(6,2)];
	}

	//daysBetweenDates([ARRAY], [ARRAY]) : INTEGER
	//daysBetweenDates([year,month,day], [year,month,day])	
	//Example: document.write(daysBetweenDates([2003,01,5],[2004,06,01]));
	this.daysBetweenDates = function(arrDate1,  arrDate2) {
		diff=Math.abs(((new Date(arrDate1[0],arrDate1[1],arrDate1[2]).getTime()-new Date(arrDate2[0],arrDate2[1],arrDate2[2]).getTime())/8.64e7))
		return Math.floor(diff);
	}

	this.getCurrentDateAsYYYYMMDD = function() {
		var d = new Date();
		var year = new String(d.getFullYear());
		var month =  new String((d.getMonth() + 1));
		var day =  new String(d.getDate());
		month = (month.length==1) ? "0"+month : month;
		day = (day.length==1) ? "0"+day : day;
		return year+month+day;
	}

}
document.write( "<scr" + "ipt  language=\"JavaScript1.2\" type=\"text/javascript\" src='"+page.getVar('basepath')+"inc/guide_status_adv/sn_data.js'><\/scr" + "ipt>" );
