var type = "IE"; //Variable used to hold the browser name
BrowserSniffer();

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP"; //Opera
	else if (document.all) type="IE"; //Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN"; //Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO"; //Mozila e.g. Netscape 6 upwards
	else type = "IE"; //I assume it will not get here
}


function writeLayer(id, str) {
	
	if (type=="IE") { document.all[id].innerHTML = str; }
	if (type=="NN") { document.layers[id].document.open();
		document.layers[id].document.write(str);
		document.layers[id].document.close();
	}
	if (type=="MO" || type=="OP") {
		document.getElementById(id).innerHTML = str;
	}
}

function LTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		s = s.substring(j, i);
	}

	return s;
}

function RTrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}

	return s;
}

function Trim(s){
	return RTrim(LTrim(s));
}