/*	customise.js - XXinit functions use names from customise.html
	needs mjas.js to be included before it in same HTML page	*/

/*	this code will be executed when file is included in an HTML page	*/
var expiryDate = new Date;
expiryDate.setFullYear( expiryDate.getFullYear() + 1 );	// a year from now

/*	the functions to select and check current options	*/
function bcinit()
{
	var bcs = document.transformer.bgcolour;
	var bc = getValue( "Background" );
	if ( !bc )
		bc = "white";
	for ( var i = 0; i < bcs.length; i++ )	{
		if ( bcs.options[ i ].value == bc )	{
			bcs.options.selectedIndex = i;
			return;
		}
	}
}

function fcinit()
{
	var fcs = document.transformer.fontcolour;
	var fc = getValue( "Colour" );
	if ( !fc )
		fc = "black";
	for ( var i = 0; i < fcs.length; i++ )	{
		if ( fcs.options[ i ].value == fc )	{
			fcs.options.selectedIndex = i;
			return;
		}
	}
}

function ffinit()
{
	var ffs = document.transformer.typeface;
	var ff = getValue( "Font" );
	if ( !ff )
		ff = "Verdana, Geneva, sans-serif";
	for ( var i = 0; i < ffs.length; i++ )	{
		if ( ffs.options[ i ].value == ff )	{
			ffs.options.selectedIndex = i;
			return;
		}
	}
}

function fsinit()
{
	var fsr = document.transformer.fontsize;
	var fs = getValue( "Fontsize" );
	if ( !fs )
		fs = "1";
	for ( var i = 0; i < fsr.length; i++ )	{
		if ( fsr[ i ].value == fs )	{
			fsr[ i ].checked = true;
			return;
		}
	}
}

function lhinit()
{
	var lhr = document.transformer.lineheight;
	var lh = getValue( "Lineheight" );
	if ( !lh )
		lh = "1";
	for ( var i = 0; i < lhr.length; i++ )	{
		if ( lhr[ i ].value == lh )	{
			lhr[ i ].checked = true;
			return;
		}
	}
}

function lsinit()
{
	var lsr = document.transformer.spacing;
	var ls = getValue( "Spacing" );
	if ( !ls )
		ls = "0";
	for ( var i = 0; i < lsr.length; i++ )	{
		if ( lsr[ i ].value == ls )	{
			lsr[ i ].checked = true;
			return;
		}
	}
}

/*	the change functions	*/
function bcchange( colour )
{
	document.body.style.backgroundColor = colour;
	setCookie( "Background", colour, expiryDate.toUTCString() );
}

function fcchange( colour )
{
	document.body.style.color = colour;
	setCookie( "Colour", colour, expiryDate.toUTCString() );
}

function ffchange( family )
{
	document.body.style.fontFamily = family;
	setCookie( "Font", family, expiryDate.toUTCString() );
}

function fschange( num )
{
	document.body.style.fontSize = num + 'em';
	setCookie( "Fontsize", num, expiryDate.toUTCString() );
}

function lhchange( size )
{
	document.body.style.lineHeight = size;
	setCookie( "Lineheight", size, expiryDate.toUTCString() );
}

function lschange( num )
{
	document.body.style.letterSpacing = num + 'em';
	setCookie( "Spacing", num, expiryDate.toUTCString() );
}

/*	function to activate preferences - e.g. on page load	*/
function setPrefs()
{
	var bc = getValue( "Background" );
	if ( bc )
		bcchange( bc );
	var fc = getValue( "Colour" );
	if ( fc )
		fcchange( fc );
	var ff = getValue( "Font" );
	if ( ff )
		ffchange( ff );
	var fs = getValue( "Fontsize" );
	if ( fs )
		fschange( fs );
	var lh = getValue( "Lineheight" );
	if ( lh )
		lhchange( lh );
	var ls = getValue( "Spacing" );
	if ( ls )
		lschange( ls );
}

/*	special function to initialise the customise.html page	*/
function setAll()
{
	setPrefs();
	bcinit();
	fcinit();
	ffinit();
	fsinit();
	lhinit();
	lsinit();
}

/*	EOF	*/