(function() {
try {
if(!ognc.exists) { throw "ogncObjUndefined"}

//Commonly used functions/helpers
ognc.utils = 
{
	
	/*Universal function to get parameter from url srting */
	getParameter : function(aP){var qS = new String(location.search.substring(1,location.search.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}},
	
	//Return just the URL
	getBaseUrl: function() {
		return window.location.protocol + "//" + window.location.hostname + ((window.location.port)? ":" + window.location.port : "" );
	},
	
	//return jsut the anchor id
	getAnchor: function () {
		return window.location.hash;
	},
	
	//Random number 
    nocacheRandom: function(){
        var axel = Math.random() + "";
        var ord = axel * 1000000000000000000;
        return ord;
    },
    
	//Popup window template
    new_window: function(options) {
			options.name	= options.name || "ubk_"+(new Date()).getMilliseconds();
			options.replace	= options.replace || false;
			options.width	= options.width || 1024;
			options.height	= options.height || 768;
			options.left	= options.left || (screen.availWidth - options.width) / 2;
			options.top		= options.top || ((screen.availHeight - options.height) / 2) - 40;
			
			var window_features = [];

			window_features.push("width=" + options.width);
			window_features.push("height=" + options.height);
			window_features.push("left=" + options.left);
			window_features.push("top=" + options.top);

			if (options.directories)	{ window_features.push("directories=" + options.directories); }
			if (options.location)		{ window_features.push("location=" + options.location); }
			if (options.menubar)		{ window_features.push("menubar=" + options.menubar); }
			if (options.resizable)		{ window_features.push("resizable=" + options.resizable); }
			if (options.scrollbars)		{ window_features.push("scrollbars=" + options.scrollbars); }
			if (options.status)			{ window_features.push("status=" + options.status); }
			if (options.toolbar)		{ window_features.push("toolbar=" + options.toolbar); }

			window.open(options.url, options.name, window_features.join(','), options.replace);
			if (options.close) window.close();
	},
	
   //Function to convert hex format to a rgb color  
    rgb2hex : function(rgb) { 
		// for IE which does not have rgb but already hex
		if(rgb.indexOf("rgb(") >= 0) {
			rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
			function hex(x) {
				hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 
				return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];  
			}  
			return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
		} else if(rgb.indexOf("#") >= 0 && rgb.length == 7) {
			return rgb;
		} else if(rgb.indexOf("#") >= 0 && rgb.length == 4) {
			return rgb[0] + rgb[1] + rgb[1] + rgb[2] + rgb[2] + rgb[3] + rgb[3];
		} else {
			switch(rgb) {
				case 'black':
					return "#000000";
				case 'white':
				default:
					return "#ffffff";
			}
		}
    }
	
}

} catch(e) { console.log("error: " + e);}
})();
