// JavaScript Document

//--------------------------------------------------------
// Commonly Used Functions
//--------------------------------------------------------
String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};


function checkEnterKey(e){
	e = e || window.event;
	if(e.keyCode == 13){
		return true;
	}
	return false;
}


function openNewWindow(theURL, winName, winWidth, winHeight){
	var width;
	var height;
	var leftdist;
	var topdist;
	width = screen.width;
	height = screen.height;
	leftdist = Math.round((width - winWidth) / 2);
	topdist = Math.round((height - winHeight) / 2);
	window.open(theURL, winName,'width='+winWidth+',height='+winHeight+',top='+topdist+',left='+leftdist+',resizable=yes,resize=0,menubar=0,location=0,scrollbars=1')
	}

function closeWindow(){
	window.close;
	}
	
		
/*
 * 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;
		}
	}

