searchText = "enter keywords";

function search(el) {
	if (el.value == searchText) el.value = "";
	else if (el.value == "") el.value = searchText;
}

function validateSearch(frm) {
	if (frm.query.value == searchText) {
		frm.query.focus();
		return false;
	}
	return true;
}

function customiseColourTheme(value) {
	switch (value) {
		case 1:
			theme = "green";
			initConnection("user-preferences?a=theme&colour=1&return", false);
			break;
		case 2:
			theme = "red";
			initConnection("user-preferences?a=theme&colour=2&return", false);
			break;
		default:
			theme = "blue";
			initConnection("user-preferences?a=theme&colour=0&return", false);
	}

	file = "media/theme-" + theme + ".css";

	if (el = document.getElementById("user-pref-colour")) {
		el.href = file;
	}
	else {
		head = document.getElementsByTagName("head");
		if (head[0]) {
			css = head[0].appendChild(document.createElement("link"));
			css.id = "user-pref-colour";
			css.rel = "stylesheet";
			css.type = "text/css";
			css.href = file;
		}
	}
}

function customiseTextSize(value) {
	switch (value) {
		case 1:
			theme = "large";
			initConnection("user-preferences?a=text&size=1&return", false);
			break;
		case 2:
			theme = "largest";
			initConnection("user-preferences?a=text&size=2&return", false);
			break;
		default:
			theme = "normal";
			initConnection("user-preferences?a=text&size=0&return", false);
	}

	file = "media/theme-text-" + theme + ".css";

	if (el = document.getElementById("user-pref-text")) {
		el.href = file;
	}
	else {
		head = document.getElementsByTagName("head");
		if (head[0]) {
			css = head[0].appendChild(document.createElement("link"));
			css.id = "user-pref-text";
			css.rel = "stylesheet";
			css.type = "text/css";
			css.href = file;
		}
	}
}

function customise(what, value) {
	ua = navigator.userAgent.toLowerCase();

	if (ua.indexOf("safari") != -1) {
		return;
	}
	else {
		switch (what) {
			case "colour":
				customiseColourTheme(value);
				break;
			case "text":
				customiseTextSize(value);
				break;
		}
		return false;
	}
}

function initConnection(url, callback) {
	http_request = false;

	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}

	if (!http_request) {
		alert("Could not create the necessary transport mechanism. Your action may not have completed.");
		return false;
	}

	if (callback != false) http_request.onreadystatechange = callback;
	http_request.open("GET", url);
	http_request.send(null);
}
