/* Functions used in every page for text size/colour switching
 *
 * 16-Aug-2005 [Mike Ford] Extract into separate file 
 */

function init_customize()
{
// check for the features we require to allow font-size/colour shuffling
// and do initial stylesheet setup

	_js_1_3 = true;
	_cookies = init_cookies();
	_dynamic_customize = _cookies && document.getElementById;

	if (_dynamic_customize) {
		// ok so far, but now check for browsers we know (think?) don't do dynamic style switching
		// and disallow for them (adjust this list as/when people complain!)
		var ua = navigator.userAgent;
		var i;
		if ((i=ua.indexOf('Opera')) != -1) {
			// This is Opera: versions <7 don't do dynamic switching.
			if (parseInt(ua.slice(i+6))<7) _dynamic_customize = false;
		}
		else if ((i = ua.indexOf('Netscape6/')) != -1) {
			// This is Netscape 6:
			//    6.0 doesn't display the selectors correctly (broken CSS) so turn the feature off
			//         completely by pretending it has no cookies.
			//    6.1 doesn't do dynamic stylesheet updating.
			//    6.2 doesn't do dynamic stylesheet updating reliably.
			var v = parseFloat(ua.slice(i+10));
			if (v<6.09) _cookies = false;
			else _dynamic_customize = false;
		}
		else if ((i = ua.indexOf('Netscape/7')) != -1) {
			// This is Netscape 7:
			//    7.0 doesn't do dynamic stylesheet updating reliably.
			//    7.1 and upwards seem to be fine.
			var v = parseFloat(ua.slice(i+9));
			if (v<7.09) _dynamic_customize = false;
		}
		else if (ua.indexOf('Safari') != -1) {
			// Tested Safari does not do dynamic stylesheet updating:
			_dynamic_customize = false;
		}
	}
}

function init_cookies()
{
	var can_cook = navigator.cookieEnabled;

	// if cookieEnabled property is undefined, be more cunning:
	if (can_cook===undefined) {
		// first, instantiate the cookie object, set a dummy value and save it.
		lssSettings = new leedsMetCookie('lss', 24*365);
		lssSettings.t_t = 't';
		lssSettings.save();
		lssSettings = null;
	}

	if (can_cook!==false) {
		// cookieEnabled property is either undefined or true -- do the only or second cookie
		// fetch (respectively)
		lssSettings = new leedsMetCookie('lss', 24*365);
		if (can_cook===undefined) {
			// being cunning: see if we got the test value, and delete it if we did.
			if (lssSettings.t_t) {
				// ok, cookies work
				delete lssSettings.t_t;
				lssSettings.save()
				can_cook = true;
			}
			else {
				// no, they don't -- return the bad news
				can_cook = false;
			}
		}
	}
	return can_cook;
}

function text_size(new_size)
{
	lssSettings.size = new_size;
	lssSettings.save();
	if (_dynamic_customize)
		set_text_size(new_size);
	else
		window.location.reload();
}

function text_colour(new_colour_set)
{
	set_text_colour(new_colour_set);
	lssSettings.colour = new_colour_set;
	lssSettings.save();
	if (_dynamic_customize)
		set_text_colour(new_colour_set);
	else
		window.location.reload();
}

function set_text_size(new_size)
{
	sizeLink = document.getElementById('css-text-size');
	sizeLink.href = "/lis/lss/css/text-size-" + new_size + ".css";
}

function set_text_colour(new_colour_set) {
	colourLink = document.getElementById('css-text-colour');
	colourLink.href = "/lis/lss/css/text-colour-" + new_colour_set + ".css";
}