/*
 * Modifies current String prototype object to include a trim()
 * function that trims extra spaces from the left and right end
 * of the String object's text
 */
	String.prototype.trim = function(){ return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); };

/*
 * String trim functions
 */
	function trim(str){
		return str.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(str){
		return str.replace(/^\s+/,"");
	}
	function rtrim(str){
		return str.replace(/\s+$/,"");
	}
	
	function shorten(str, length, suffix){
		length = parseInt(length);
		suffix = suffix || '...';
		if( length > 0 && str.length > length ){
			limit = length - suffix.length;
			str = str.substring(0,limit) + suffix;
		}
		return str;
	}


/*
 * Returns an array containing the current width and height of the screen
 * (Cross-Browser compatible)
 */
	function getScreenSize(){
		var w = 0;
		var h = 0;
		if(typeof(window.innerWidth) == 'number'){
			w = window.innerWidth;
			h = window.innerHeight;
		}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
		return Array(w,h);
	}
	
/*
 * Returns an array containing the browser name and version
 * (requires jQuery)
 */
	function getBrowser(){
		var name = "";
		var version = jQuery.browser.version.charAt(0);
		if(jQuery.browser.safari) name = "safari";
		if(jQuery.browser.opera) name = "opera";
		if(jQuery.browser.msie){ name = "ie";
			var idx = navigator.userAgent.search('MSIE');
			if( idx != -1 ){
				var ua = navigator.userAgent.substring( idx );
				ua = ua.substring( 5, ua.search(';') );
				var version = parseInt( ua );
			}
		}
		if(jQuery.browser.mozilla) name = "firefox";
		
		if(navigator.appVersion.search("Chrome") != -1) name = "chrome";
		if(navigator.appVersion.search("Macintosh") != -1 && jQuery.browser.mozilla) name = "firefox-mac";
		if(isIPhone()) name = "iphone";
		
		var browser = {
			"name" : name,
			"version" : version
		};
		return browser;
	}
	
/*
 * Returns TRUE or FALSE whether the current browser is IE
 * and, if specified, the correct version (requires jQuery)
 */
	function isIE(version){
		var browser = getBrowser();
		if(browser['name'] == "ie"){
			if(version != null && parseInt(version)){
				return (browser['version'] == version) ? true : false;
			}else{
				return true;
			}
		}else{
			return false;
		}
	}
	
/*
 * Returns TRUE or FALSE whether the current browser is an iPhone
 * browser
 */
	function isIPhone(){
		if(navigator.appVersion.indexOf("iPhone") != -1){
			return true;
		}else{
			return false;
		}
	}
	
/*
 * Useful for attaching the browser name as a class to the <body> tag
 * (requires jQuery)
 */
	function setBrowserClass(){
		var browser = getBrowser();
		var browserClass = browser['name'];
		if( browser['name'] == 'ie' ) browserClass += browser['version'];
		if( browser['name'] && !$('body').hasClass(browserClass) ){
			$('body').addClass(browserClass);
			return true;
		}else{
			return false;
		}
	}

/*
 * Keyboard/Mouse functions
 */
	function getMouseXY(e){
		var x = 0;
		var y = 0;
		if(!e) var e = window.event;
		if(e.pageX || e.pageY){
			x = e.pageX;
			y = e.pageY;
		}else{
			x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		return Array(x,y);
	}
	
	function isEnterKey(e){
		e = e || window.event;
		if(e.keyCode == 13){
			return true;
		}
		return false;
	}
	
	function keyPressed(e, keyCode){
		e = e || window.event;
		if(e.keyCode == keyCode){
			return true;
		}
		return false;
	}
	
	function clearClick(){
		$(".clearClick").each(function(i,elem){
			$(elem).focus(function(){
				if($(this).val() == $(this).attr("rel"))
					$(this).val("");
			});
			$(elem).blur(function(){
				if($(this).val() == "")
					$(this).val($(this).attr("rel"));
			});
		});
	}

/*
 * JavaScript equivalents of common PHP functions
 */
	function is_numeric(str){
		return ( isNaN(str) ) ? false : true;
	}

	function mktime(hours, minutes, ampm, month, day, year){
		var dateObj = new Date();
		dateObj.setFullYear(intval(year), intval(month)-1, intval(day));
		hours = intval(hours);
		minutes = intval(minutes);
		if(ampm == "PM" && hours < 12){
			hours += 12;
		}else if(ampm == "AM" && hours == 12){
			hours = 0;
		}
		dateObj.setHours(hours, minutes);
		return dateObj;
	}

	function intval(str){
		if( !is_numeric(str) ){
			return 0;
		}else{
			if(str.charAt(0) == '0' && str.length > 1){
				str = str.substring(1);	
			}
			return parseInt(str);
		}
	}

	function ucfirst(str){
		var first = str.charAt(0).toUpperCase();
		str = first + str.substring(1);
		return str;
	}
	
	function in_array( needle, haystack ){
		var in_array = false;
		for( var i=0; i<haystack.length; i++ ){
			if( needle == haystack[i] ){
				in_array = true;
				break;
			}
		}
		return in_array;
	}

/*
 * Returns a DOM reference to a SWF object
 */
	function getSWF( id ){
		if(navigator.appName.indexOf("Microsoft") != -1){
			return window[id];	
		}else{
			return document[id];
		}
	}

