/**
 * js for the ors move notification
 * SJW
 */

var COOKIE_DONTSHOW	= 'ors_move_dontshow';
var COOKIE_TIMEOUT	= 'ors_move_timeout';
var COOKIE_AUTO		= 'ors_move_auto';
var TIMEOUT			= 1 / 3/ 24;	// 20 minutes (in days)

// cookie manipulation
// http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * have the info dialog automatically open once per TIMEOUT period until "don't show me this again" clicked.
 * this is called from the master page
 */
function autoOpenDialog(){
	if(readCookie(COOKIE_DONTSHOW) || readCookie(COOKIE_TIMEOUT))
		return;
	createCookie(COOKIE_TIMEOUT, 1, TIMEOUT);
	window.ors_move_auto = 1;	// let the dialog know it was opened automatically
	$('#move_tab1').click();		// trigger the shadowbox
}

/**
 * close the Shadowbox and don't automatically show it again
 */
function dontShowAgain(){
	createCookie(COOKIE_DONTSHOW, 1, 3650);	// don't auto show for 10 years
	window.parent.Shadowbox.close();
}

/**
 * initialise the "dont show this again" button if it is needed
 */
function initDontShow(){
	$(document).ready(function(){
		// only display the "dont show again" button if the dialog has been opened automatically
		if(parent.window.ors_move_auto) {
			$('#shadowbox_dont_show_again', parent.document).show();
			$('#dont_show_again', parent.document).click(dontShowAgain);
			delete(parent.window.ors_move_auto);
		}
	});
}