/**
 * Utility functions
 * 
 * @copyright Byng Systems LLP
 * @author Ollie Maitland
 * @version 0.1
 */
 
 	/**
 	 * Get element
 	 * 
 	 * @param String id
 	 * @return DomElement
 	 */
	function ge (id) {
		
		return document.getElementById (id);
	}
	
	/**
	 * Create element
	 * 
	 * @param String id
	 * @return DomElement
	 */
	function ce (tag) {
		
		return document.createElement(tag);
		
	}
	
	/**
	 * Check is a varaible is an object
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isObject(a) {
    	return (a && typeof a == 'object') || isFunction(a);
	}
	
	/**
	 * Check is a varaible is emtpy
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isEmpty (s) {
		return (a == null || a == "");		
	}
	
	/**
	 * Check if a variable is a function
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isFunction(a) {
    	return typeof a == 'function';
	}
	
	/**
	 * Check if a variable is a string
	 * 
	 * @param String s
	 * @return boolean
	 */
	function isString(s) {
    	return typeof s == 'string';
	}
		
	/**
	 * Check is a variable is an array
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isArray(a) {
    	return isObject(a) && a.constructor == Array;
	}

	/**
	 * Check if a variable is "undefined"
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isUndefined(a) {
    	return typeof a == 'undefined';
	}
	
	/**
	 * Check if a variable is "number"
	 * 
	 * @param mixed a
	 * @return boolean
	 */
	function isNumber(a) {
    	return typeof a == 'number';
	} 	
	
	/**
	 * Trim a string
	 * 
	 * @param String s
	 * @return String
	 */
	function trim (s) {
		if (s) { return s.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); } else { return ''; };
	}
	
	/**
	 * Get the browser engine name
	 * 
	 * @return String
	 */
	function getBrowser () {
		
		var browser;
		var version;

		if (navigator.appVersion.indexOf("MSIE")!=-1){
			
			browser = 'MSIE';
			temp=navigator.appVersion.split("MSIE")
			version=parseFloat(temp[1])
		}
		
		if(navigator.userAgent.indexOf("Firefox")!=-1) {
			
			browser = 'Firefox';
			var versionindex=navigator.userAgent.indexOf("Firefox")+8
			version = parseInt(navigator.userAgent.charAt(versionindex));
		}
			
		if (navigator.appName.indexOf('Netscape') != -1) {
			
			browser = 'Netscape';
			
		}
		
		return browser;
	}
	
	/**
	 * Get browser version
	 * 
	 * @return int
	 */
	function getBrowserVersion () {
	
		var browser;
		var version;

		if (navigator.appVersion.indexOf("MSIE")!=-1){
			
			browser = 'MSIE';
			temp=navigator.appVersion.split("MSIE")
			version=parseFloat(temp[1])
		}
		
		if(navigator.userAgent.indexOf("Firefox")!=-1) {
			
			browser = 'Firefox';
			var versionindex=navigator.userAgent.indexOf("Firefox")+8
			version = parseInt(navigator.userAgent.charAt(versionindex));
		}		
		
		return version;
	}
	
	/**
	 * Convert a date to a Unix timestamp
	 * 
	 * @param Date date
	 */
	function toUnixtime( date )
	{
		if (!date) date = new Date();
		return Math.round(date.getTime()/1000.0);
	}
	
