// Internet Explorer doesn't display correctly white spaces on tags PRE with innerHTML
// this simple function verify if browser is IE to use outerHTML instead of innerHTML
function ie() {
	var	browser = navigator.userAgent.toUpperCase();
	return (browser.indexOf("MSIE") >= 0 && browser.indexOf("OPERA") < 0);
};

// this function just verify user selected options
function highlight() {
	var 	full = document.getElementById("fullhighlight").checked,			// full highlight ?
		html = document.getElementById("usehtml").checked,				// use html tags instead of \n\r or \t ?
		code = document.getElementById("source").value.replace(/^\s*|\s*$/, ""),	// wich highlighter need to use ?
		JSH = full ? JSHFull : JSHFast;
	
	// if user has wrote something ...
	if(code.length > 0) {
		
		// code will be highlighted text
		code = JSH.parse(code, html);
		
		// if user has IE ...
		if(ie()) {
			// ... enjoy outerHTML "hacks" to presever white spaces
			document.getElementById("jshcode").outerHTML = "<pre id=\"jshcode\">" + code + "</pre>";
			document.getElementById("htmljshcode").outerHTML = "<pre id=\"htmljshcode\">" + code.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;") + "</pre>";
		}
		else {
			// this code is for Browsers
			document.getElementById("jshcode").innerHTML = code;
			document.getElementById("htmljshcode").innerHTML = code.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
		};
	};
};

// theme Object defines wich classes parser should use
var theme = {
	"comments":"jshcomments",	// single or multiline comments span class
	"strings":"jshstrings",		// strings span class
	"numbers":"jshnumbers",		// numbers span class
	"operators":"jshoperators",	// operators span class
	"globals":"jshglobals",		// OPTIONAL: global top level functions or some reserved words
	"properties":"jshproperties",	// OPTIONAL: Objects properties (i.e. str.length )
	"methods":"jshmethods"		// OPTIONAL: Objects methods (i.e. str.charAt(... )
},

// JSHighLighter with full sintax (strings, numbers, operators, comments, globals, properties, methods)
JSHFull = new JSHighLighter(theme, true),

// JSHighLighter with basic highlight (strings, numbers, operators, comments)
JSHFast = new JSHighLighter(theme);
