//**********
// This source file is used mostly in the settings page
// Parameters passed to function:
// nstyle =	"pointer" variable to the style arrays located in mycookie.js
// nfontsize = 	"pointer" variable to the fontsize array located in mycookie.js
// nmode = 	to change modes
// NOTE - "-5" MEANS "IGNORE" FOR CHANGES TO THE COOKIE
//**********
function changesettings(nstyle, nfontsize, nmode)
{
	//* These variables are used for storing new values into the cookie
	var style = 0;
	var fontsize = 0;
	var mode = 0;

	//* 1- Unpack the cookie and put data into relevant variables
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("cssdata=");

	if(pos != -1)
	{
		//* Cookie exists. Extract relevant data items and place into variables
		var start = pos + 8;
		var end = allcookies.indexOf(";", start);
		if(end == -1)
			end = allcookies.length;

		var value = allcookies.substring(start, end);

		style = value.substring(0, 1);
		fontsize = parseInt(value.substring(1, 2));
		mode = value.substring(2, 3);
	}

	//* 2- Apply changes to relevant variables
	// NOTE - "-5" MEANS "IGNORE"
	if(nstyle != -5)
		style = nstyle;

	if(nfontsize != -5)
	{
		fontsize = fontsize + nfontsize;

		//* This is the boundary for the smallest fontsize in the array
		if(fontsize < 0)
			fontsize = 0;

		//* This is the boundary for the largest fontsize in the array
		if(fontsize > 9)
			fontsize = 9;

	}

	if(nmode != -5)
		mode = nmode;

	//* 3- Pack the cookie with the new data
	var the_cookie = "cssdata=" + style + fontsize + mode;
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	the_cookie = the_cookie + ";expires=" + nextyear.toGMTString();
	document.cookie = the_cookie;

	// Refresh current page
	this.location.href = this.location.href;
}
