/*
	<meta http-equiv="content-type" 	content="text/html;charset=iso-8859-1">
	
	<meta name="author" 				content="Thomas Wilson">
	<meta name="host" 					content="wehostmacs.com">
	<meta name="host-admin" 			content="noc@wehostmacs.com">
	<meta name="keys"					content="brainfarts, add, apple">
	
	<meta name="creation" 				content="09/05/2005">
	<meta name="last_modified"			content="03/06/2006">
*/

var debug_switches = top.readCookie("debug");	// keep a ram based version of the cookie

/*******************************\
|								|
|			SWITCHES			|
|								|
\*******************************/
 
var sw_debugWindow		 = false;				// open the debug window
var sw_showLocation		 = false;				// display the location text entry box in the browser window
var sw_soundEnabled		 = false;				// enable sound effects
var sw_showScreenInfo	 = false;				// display screen size info in alert at startup
var sw_showBrowserInfo	 = false;				// display browser info from navigator object in alert at startup
var sw_useLastModified	 = false;				// use JavaScript's last-Modified property for display in the footer
var sw_testPopupAlert	 = false;				// short circuit switch to test the blocked popups alert screen
var sw_testVersionAlert	 = false;				// short circuit switch to test the browser version alert screen

var sw_slamMicrosoft	 = false;				// not currently used

//
// -- If the saved switch settings still exist, set switches accordingly
//
if (debug_switches != null) {
	sw_debugWindow		 = (getSwitchState('sw_debugWindow') > 0)		? true : false;
	sw_showLocation		 = (getSwitchState('sw_showLocation') > 0)		? true : false;
	sw_soundEnabled		 = (getSwitchState('sw_soundEnabled') > 0)		? true : false;
	sw_showScreenInfo	 = (getSwitchState('sw_showScreenInfo') > 0)	? true : false;
	sw_showBrowserInfo	 = (getSwitchState('sw_showBrowserInfo') > 0)	? true : false;
	sw_useLastModified	 = (getSwitchState('sw_useLastModified') > 0)	? true : false;
	sw_testPopupAlert	 = (getSwitchState('sw_testPopupAlert') > 0)	? true : false;
	sw_testVersionAlert	 = (getSwitchState('sw_testVersionAlert') > 0)	? true : false;
};

var one_year			= 365;					// one year in days


//
// -- save the state of a named button to a cookie
//
function setSwitchState(name, state) {
	debug_switches = top.updateCookie(debug_switches, name, state);
	top.createCookie("debug", debug_switches, one_year);
};


//
// -- retrieve the state of a named button from the cookie data
//
function getSwitchState(name) {
	var state	= (debug_switches != null) ? top.readCookie(name, debug_switches, '|') : '';
	state		= (state) ? state : '0';
	
	return (state);
};


//
// -- toggle sate of checkbox
//
function toggle(element) {
	var state = getSwitchState(element.name) ^ 1;
	
	if (state >= 0)
		setSwitchState(element.name, state)			// write new state back to cookie
	
	else if (sw_debugWindow)
		top.debugPrint('### ERROR: empty string returned by getSwitchState() - [' + element.name + ']');
};


//
// -- get the state of the checkbox from the cookie
// -- and set the corresponding onscreen button to that state
//
function setButtonState(element) {
	var value = getSwitchState(element.name);

	if (value != "")
		element.checked = (value == "1") ? true : false;
};


//
// -- initialize the cookie - called only if document.cookie returns an empty string
//
function initSavedSwitchStates() {
	with (top.wDebugSwitches.document.debug_switches)
		for (var i = 0; i < elements.length; i++)
			if (elements[i].type == "checkbox")
				setSwitchState(elements[i].name, "0");
};


//
// -- initialize all debug buttons from cookies
//
function initTheButtons() {
	with (top.wDebugSwitches.document.debug_switches)
		for (var i = 0; i < elements.length; i++)
			if (elements[i].type == "checkbox")
				setButtonState(elements[i]);
};


//
// -- display the sate of all check boxes
//
function showStates(theForm) {
	var str = "";
	
	with (theForm)
		for (var i = 0; i < elements.length; i++)
			if (elements[i].type == "checkbox")
				str += elements[i].checked + '\n';
};


//
// -- initialize debug switches
//
function initialize(doInit) {
	if (debug_switches == null || doInit)
		initSavedSwitchStates();
	
	initTheButtons();
};
				
