/* SESSION EXPIRATION INFO */
var expirationTimeChecker = new Date().getTime();

function SessionExpiration()
{
	if(expirationTimeChecker + session_expiration * 1000 <= new Date().getTime())
	{
		alert("Your session has expired. Please log in again.");
		window.location = mainurl;
	}
}

if (session_expiration)
{
	window.setTimeout("SessionExpiration()", session_expiration * 1000);
}

/* DEBUG */
function DebugOpen()
{
	dbg = document.getElementById('Debug');
	dbg.style.height = '300px';
	dbg.style.width = '100%';
}

function DebugClose()
{
	dbg = document.getElementById('Debug');
	dbg.style.height = '20px';
	dbg.style.width = '20px';
}

  
/* Displays e-mail templates - TO BE REMOVED?  */
function thumbnail_ezine() 
{
	win = window.open(prefix_js + 'ModOptIn/TemplateThumbnails', '', 'toolbar=0,width=660,height=430,left=10,top=10,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1');
}

/* SALESLETTER */

function loadfunc()
{
	today = (new Date()).getTime();
	the_day = (new Date()).getTime();
	the_day = the_day + 86399000;

	countdown();
}

function countdown()
{
	time = (the_day - today);
	days = (time - (time % 86400000)) / 86400000;
	time = time - (days * 86400000);
	hours = (time - (time % 3600000)) / 3600000;
	time = time - (hours * 3600000);
	mins = (time - (time % 60000)) / 60000;
	time = time - (mins * 60000);
	secs = (time - (time % 1000)) / 1000;
	if (days + hours + mins + secs > 1) document.getElementById('c_timer').innerHTML = (hours+' hours, '+mins+' minutes and '+secs+' seconds');
	else document.getElementById('ctimer').innerHTML = "Site is ready!";
	today = today + 1000;
	ID = window.setTimeout("countdown()",1000);
}

function GetIdUser() {
	return id_user;
}

function GetMainUrl() {
	return mainurl;
}

/* CONTEXT HELP */
function ExpandHelp(pPage)
{
	var helplayer = document.getElementById("ContextHelpWindow");
	helplayer.style.display = "block";	
	
	var helpbutton = document.getElementById('ContextHelpView');
	helpbutton.style.display = 'none';
	
	// check if there is content and load if not
	
	helpiframe = document.getElementById("ContextHelpFrame");
	
	if (helpiframe.src == "")
	{
		helpiframe.src = "ModHelp/GetContextHelp/" + pPage;
	}
	
}

function CloseHelp()
{
	var helplayer = document.getElementById("ContextHelpWindow");
	helplayer.style.display = "none";
	
	var helpbutton = document.getElementById('ContextHelpView');
	helpbutton.style.display = 'inline';
	
}

// for external links, to avoid losing pagerank
function ExternalLink(url)
{
	window.open(url,'_self');
	// TODO: add new window routine, however we don't like doing it
}

/* selecting chosen feature in features page */
function SelectFeature()
{
	var featureId = 'Feature' + document.location.hash.substring(1);
	if (document.getElementById(featureId))
	{
		document.getElementById(featureId).className = 'VirtualTour VirtualTourSelected';
	}
	window.scrollBy(0,-30);
}

if ((document.location.pathname.indexOf('features-') != -1) && (document.location.hash != ''))
{
	window.onload = SelectFeature;
}

/* context help */
