// version 3.5
var prestyle = new Array(17); //preload style sheets
	for (i=1; i<=17; i++)
	{
		prestyle[i-1] = new Image(); //shortcut method
	}
   	prestyle[0].src = "format/01.css";
	prestyle[1].src = "format/02.css";
	prestyle[2].src = "format/03.css";
	prestyle[3].src = "format/04.css";
	prestyle[4].src = "format/05.css";
	prestyle[5].src = "format/06.css";
	prestyle[6].src = "format/07.css";
	prestyle[7].src = "format/08.css";
	prestyle[8].src = "format/09.css";
	prestyle[9].src = "format/10.css";
	prestyle[10].src = "format/size_10.css";
	prestyle[11].src = "format/size_12.css";
	prestyle[12].src = "format/size_14.css";
	prestyle[13].src = "format/size_16.css";
	prestyle[14].src = "format/size_18.css";
	prestyle[15].src = "format/bold_00.css";
	prestyle[16].src = "format/bold_01.css";
	
var style_num, style_number, font_size, font_bold, num_styles, doubleclick, cookies;
style_num = "011000"; //default style number 01, font 10 (11 revised 6003), bold 00 = no	
num_styles = 10; //change number to suit
expireDate=new Date;
expireDate.setTime(expireDate.getTime()+1*90*24*60*60*1000); //3 months

function check_style() //check style set by user
{
	if (document.cookie.indexOf("message=") != -1) //check for existence of cookie
	{	
		//alert(document.cookie.indexOf(";"));	
		cookies = document.cookie.split(";"); // cookies array
		for (i=0; i<cookies.length; i++)
		{
			if (cookies[i].indexOf("message=") != -1)
			{
				m = cookies[i].indexOf("message=");
				//alert("m");
				//alert(m);
				style_num = cookies[i].substring(8+m,15+m);
			}
		}
		//alert(cookies.length);
		//alert(cookies[0]);
		//alert(cookies[1]);
		//alert("style_num from cookie");
		//alert(style_num);
	}
	else
	{
		if (location.search) //check for existence of URL substring
		{
			style_num = location.search.substring(1); //entire substring minus first ? character
			doubleclick = style_num.split("?"); //split substring
			style_num = doubleclick[0].substring(6); //extract style number
			//alert("style_num from substring");
			//alert(style_num);
		}
	}
}

function break_style_num()
{
	style_number = style_num.substring(0,2);
	//alert(style_number);
	font_size = style_num.substring(2,4);
	//alert(font_size);
	font_bold = style_num.substring(4,6);
	//alert(font_bold);
}

function make_style_num()
{
	style_num = style_number + "" + font_size + "" + font_bold;
	//alert("new style number");
	//alert(style_num);
}

check_style();
break_style_num();
//alert(style_num);
document.write('<link href="format/' + style_number +  '.css" type="text/css" rel="stylesheet">');
document.write('<link href="format/size_' + font_size +  '.css" type="text/css" rel="stylesheet">');
document.write('<link href="format/bold_' + font_bold +  '.css" type="text/css" rel="stylesheet">');

function previous_style()
{
	style_number = parseInt(style_number, 10) - 1;
	if (style_number < 1)
		style_number = num_styles;
	if (style_number < 10)
		style_number = "0" + style_number;
	make_style_num();
	document.styleSheets[0].href="format/" + style_number + ".css";
}

function next_style()
{
	style_number = parseInt(style_number, 10) + 1;
	if (style_number > num_styles)
		style_number = 1;
	if (style_number < 10)
		style_number = "0" + style_number;
	make_style_num();
	document.styleSheets[0].href="format/" + style_number + ".css";
}

function previous_font()
{
	font_size = parseInt(font_size, 10);
	if (font_size > 10)
		font_size = font_size - 2;
	if (font_size < 10) //not relevant here as not allowing less than 10
		font_size = "0" + font_size;
	make_style_num();
	document.styleSheets[1].href="format/size_" + font_size + ".css";
}

function next_font()
{
	font_size = parseInt(font_size, 10);
	if (font_size < 18)
		font_size = font_size + 2;
	if (font_size < 10) //not relevant here as not allowing less than 10
		font_size = "0" + font_size;
	make_style_num();
	document.styleSheets[1].href="format/size_" + font_size + ".css";
}

function previous_bold()
{
	font_bold = parseInt(font_bold, 10);
	if (font_bold == 1)
		font_bold = font_bold - 1;
	if (font_bold < 10) // always true here
		font_bold = "0" + font_bold;
	make_style_num();
	document.styleSheets[2].href="format/bold_" + font_bold + ".css";
}

function next_bold()
{
	font_bold = parseInt(font_bold, 10);
	if (font_bold == 0)
		font_bold = font_bold + 1;
	if (font_bold < 10) // always true here
		font_bold = "0" + font_bold;
	make_style_num();
	document.styleSheets[2].href="format/bold_" + font_bold + ".css";
}

function set_cookie() // on page unload
{		
	document.cookie = "message=" + style_num + ";expires=" + expireDate.toGMTString();
}

function intercept(what)
{		
	what.href += "?style=" + style_num;
}

function standard_download(what)
{
	what.href = "standard_download.asp?style=" + style_num;
}