/*
	Browser Detect

	Based on a script written by Peter Paul Koch (http://www.quirksmode.com)
	Written by Evan Hanson (http://www.evanhanson.com) (2008; may need periodic updates)

	Stores the user's OS, browser, browser version and navigator string to
	global variables. 

	They can be accessed as follows: _OS, _browser, _version, _navigator
*/

// Globals to hold _browser info
var detect = navigator.userAgent.toLowerCase();
var _OS, _browser, _version, _navigator;

function getBrowserInfo() {

	if(checkIt('konqueror')) {
		_browser 							= "Konqueror";
		_OS									= "Linux";
	} else if(checkIt('safari')) _browser 	= "Safari"
	else if(checkIt('omniweb')) _browser 	= "OmniWeb"
	else if(checkIt('opera')) _browser		= "Opera"
	else if(checkIt('webtv')) _browser		= "WebTV";
	else if(checkIt('icab')) _browser 		= "iCab"
	else if(checkIt('msie')) _browser 		= "Internet Explorer"
	else if(!checkIt('compatible')) {
		_browser 							= "Netscape Navigator"
		_version							= detect.charAt(8);
	} else _browser							= "???";

	if(!_version)
		_version = detect.charAt(place + _navigator.length);

	if (!_OS)
		if(checkIt('linux')) _OS 			= "Linux";
		else if(checkIt('x11')) _OS 		= "Unix";
		else if(checkIt('mac')) _OS 		= "Mac"
		else if(checkIt('win')) _OS 		= "Windows"
		else _OS 							= "???";
}

// Utility method used by getBrowserInfo()
checkIt = function(string) {
	place = detect.indexOf(string) + 1;
	_navigator = string;
	return place;
}

// Import an external CSS stylesheet.
importCSS = function(path) {
	var head = document.getElementsByTagName("head")[0];         
	var css = document.createElement('link');
	css.type = 'text/css';
	css.rel = 'stylesheet';
	css.href = path;
	css.media = 'screen';
	head.appendChild(css);
}

// Import an external javascript file.
importJS = function(path) {
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = path;
	document.getElementsByTagName('head')[0].appendChild(script);
}

// Trims whitespace from a string.
String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

// Creates a new image object using a String object as its path.
String.prototype.preloadImage = function() {
	var im = new Image();
	im.src = this;
	return im;
}

// Checks if an object exists. true or false.
exists = function(obj) {
	if(typeof window[obj] == "undefined") return false; else return true;
}

// Momentarily highlights an element e in the given color clr.
point = function(e, clr) {
	new Effect.Highlight(e, {startcolor: '#'+clr, restorecolor: true, duration: 1.0, queue: {scope: 'pointer', limit: 1} });
}

// Returns part a given element's ID string, from its first underscore on.
// Useful when elements are named as "element_1", "element_2", etc...
getId = function(el) {
	return $(el).id.substr(($(el).id.indexOf("_")+1));
}

// "Initializes" a text field. i.e. sets the field such that its initial text
// will disappear on focus and reappear if no new text has been entered on blur.
// The field's normal & hober colors can be set with the parameters color1 & color2.
initField = function(field, blanktext, color1, color2) {
	if(!color1) color1 = '#000';
	if(!color2) color2 = '#000';
	var f = $(field);
	f.observe('focus', function() {
		f.setStyle({ color: color1 });
		if(f.value == blanktext) {
			f.value = "";
		}
	});
	
	f.observe('blur', function() {
		if(f.value == "") {
			f.value = blanktext;
			f.setStyle({ color: color2 });
		}
	});
}
