/* saves visitor's SBMUG style preferences */



/* savePrefs: "Save settings and close SBMUG Preferences" */

function savePrefs() {
//	frame1url = window.parent.frame1.location.pathname // for two-frame frameset
//	window.parent.location.href = frame1url // for two-frame frameset
	parent.location.reload() // for single page
}



/* closePrefs: "Close SBMUG Preferences" */

function closePrefs() {
//	frame1url = window.parent.frame1.location.pathname // for two-frame frameset
//	window.parent.location.href = frame1url // for two-frame frameset
	parent.location.reload() // for single page
}



/* eraseCookie: "Use SBMUG's original theme" */

function eraseCookie(name,value,days) {
	var date = new Date();
	date.setTime(date.getTime() + (days*24*60*60*1000));
	var expires = "; expires=" + date.toGMTString();
	document.cookie = name+"=" + "" + expires + "; path=/";

//	parent.frame1.location.reload() // for two-frame frameset
//	parent.frame2.location.reload() // for two-frame frameset
	parent.location.reload() // for single page
}



/* load settings into SELECT menus */

function loadSettings() {
	if (document.cookie != "") {

	SBMUGprefs = unescape(document.cookie.split("=")[1])

	document.forms["prefs"].hc.value = SBMUGprefs.split("+")[1]
	document.forms["prefs"].important.value = SBMUGprefs.split("+")[2]
	document.forms["prefs"].text.value = SBMUGprefs.split("+")[3]

	document.forms["prefs"].link.value = SBMUGprefs.split("+")[4]
	document.forms["prefs"].visited.value = SBMUGprefs.split("+")[5]
	document.forms["prefs"].active.value = SBMUGprefs.split("+")[6]

	document.forms["prefs"].theme.selectedIndex = SBMUGprefs.split("+")[14]
	
	document.forms["prefs"].ff.selectedIndex = SBMUGprefs.split("+")[15]
	document.forms["prefs"].fs.selectedIndex = SBMUGprefs.split("+")[16]
	document.forms["prefs"].lh.selectedIndex = SBMUGprefs.split("+")[17]

	document.forms["prefs"].cff.selectedIndex = SBMUGprefs.split("+")[18]
	document.forms["prefs"].cfs.selectedIndex = SBMUGprefs.split("+")[19]
	document.forms["prefs"].clh.selectedIndex = SBMUGprefs.split("+")[20]

	document.forms["prefs"].hff.selectedIndex = SBMUGprefs.split("+")[21]
	}
}



/* initializing cookie variables */

var theme	//	0

var hc	//	1
var important // 2
var text	//	3

var link	//	4
var visited //	5
var active //	6

var ff	//	7
var fs	//	8
var lh	//	9

var cff	//	10
var cfs	//	11
var clh	//	12

var hff	//	13

var themeInd //	14

var ffInd	//	15
var fsInd	//	16
var lhInd	//	17

var cffInd //	18
var cfsInd //	19
var clhInd //	20

var hffInd //	21


/* set theme */


function setTheme() {

	theme = document.forms["prefs"].theme.value

	if (theme == "Original") {
	document.forms["prefs"].hff.options[1].selected = true;
	document.forms["prefs"].ff.options[1].selected = true;
	document.forms["prefs"].fs.options[1].selected = true; // 12px (9pt)
	document.forms["prefs"].lh.options[1].selected = true; // 1.17em
	document.forms["prefs"].cff.options[13].selected = true;
	document.forms["prefs"].cfs.options[1].selected = true; // 10px
	document.forms["prefs"].clh.options[3].selected = true; // 1.33em
	document.forms["prefs"].hc.value = "#EE0033";
	document.forms["prefs"].important.value = "#EE0033";
	document.forms["prefs"].text.value = "#131300";
	document.forms["prefs"].link.value = "#EE0033";
	document.forms["prefs"].visited.value = "#0080FF";
	document.forms["prefs"].active.value = "#FF3333";
	}

	if (theme == "Apple") {
	document.forms["prefs"].hff.options[12].selected = true;
	document.forms["prefs"].ff.options[12].selected = true;
	document.forms["prefs"].fs.options[1].selected = true; // 12px (9pt)
	document.forms["prefs"].lh.options[4].selected = true; // 1.5em
	document.forms["prefs"].cff.options[12].selected = true;
	document.forms["prefs"].cfs.options[2].selected = true; // 11px
	document.forms["prefs"].clh.options[3].selected = true; // 1.33em
	document.forms["prefs"].hc.value = "#2971A7";
	document.forms["prefs"].important.value = "#EE0033";
	document.forms["prefs"].text.value = "#505050";
	document.forms["prefs"].link.value = "#2971A7";
	document.forms["prefs"].visited.value = "CornflowerBlue";
	document.forms["prefs"].active.value = "#FF3333";
	}

	if (theme == "Blog") {
	document.forms["prefs"].hff.options[19].selected = true;
	document.forms["prefs"].ff.options[4].selected = true;
	document.forms["prefs"].fs.options[2].selected = true; // 13px
	document.forms["prefs"].lh.options[4].selected = true; // 1.5em
	document.forms["prefs"].cff.options[19].selected = true;
	document.forms["prefs"].cfs.options[2].selected = true; // 11px (8.25pt)
	document.forms["prefs"].clh.options[3].selected = true; // 1.33em
	document.forms["prefs"].hc.value = "#2971A7";
	document.forms["prefs"].important.value = "#EE0033";
	document.forms["prefs"].text.value = "#131300";
	document.forms["prefs"].link.value = "#2971A7";
	document.forms["prefs"].visited.value = "CornflowerBlue";
	document.forms["prefs"].active.value = "#FF3333";
	}

	createCookie('SBMUGprefs','',3652);
}



/* create cookie */

function createCookie(name,value,days) {

	/* set variables for SBMUGprefs */
	theme = document.forms["prefs"].theme.value
	themeInd = document.forms["prefs"].theme.selectedIndex
	
	hc = document.forms["prefs"].hc.value
	important = document.forms["prefs"].important.value
	text = document.forms["prefs"].text.value

	link = document.forms["prefs"].link.value
	visited = document.forms["prefs"].visited.value
	active = document.forms["prefs"].active.value

	ff = unescape(document.forms["prefs"].ff.value)
	fs = document.forms["prefs"].fs.value
	lh = document.forms["prefs"].lh.value
	ffInd = document.forms["prefs"].ff.selectedIndex
	fsInd = document.forms["prefs"].fs.selectedIndex
	lhInd = document.forms["prefs"].lh.selectedIndex

	cff = unescape(document.forms["prefs"].cff.value)
	cfs = document.forms["prefs"].cfs.value
	clh = document.forms["prefs"].clh.value
	cffInd = document.forms["prefs"].cff.selectedIndex
	cfsInd = document.forms["prefs"].cfs.selectedIndex
	clhInd = document.forms["prefs"].clh.selectedIndex

	hff = unescape(document.forms["prefs"].hff.value)
	hffInd = document.forms["prefs"].hff.selectedIndex

	value = escape(theme + '+' + hc + '+' + important + '+' + text + '+' + link + '+' + visited + '+' + active + '+' + ff + '+' + fs + '+' + lh + '+' + cff + '+' + cfs + '+' + clh + '+' + hff + '+' + themeInd + '+' + ffInd + '+' + fsInd + '+' + lhInd + '+' + cffInd + '+' + cfsInd + '+' + clhInd + '+' + hffInd)

	/* write cookie */
	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=/";
//	parent.frame1.history.go(0); // for two-frame frameset
//	parent.frame2.history.go(0); // for two-frame frameset
	parent.history.go(0); // for single page
}



/* read cookie (for testing) */

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;
}



/* view cookie (for testing) */

function viewCookie() {
	if (document.cookie) {
		document.location = "javascript:alert(unescape(document.cookie))";
	}
}
