/**************************************
*             Generic                 *
**************************************/
function bookmark(url, desc)
{
	opera=navigator.userAgent.indexOf("Opera")!=-1;
	if (isIE()) window.external.AddFavorite(url, desc); 					//If IE
	else if (opera) alert("Please press CTRL+T to bookmark this site."); 	//If opera
	else alert("Please press CTRL+D to bookmark this site.");				//Others, eg Netscape/Mozilla
}

function isDefined(variable) {return (!(!( variable||false )));}

/* Returns true if user is using IE */
function isIE() {
	var ua = navigator.userAgent.toLowerCase();
	return ((ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && 
			(ua.indexOf('webtv') == -1) &&
			(location.href.indexOf('seenIEPage') == -1));
}

function isIE6() {
  var ua = navigator.userAgent.toLowerCase();
  return ((ua.indexOf('msie 6.0') != -1) && (ua.indexOf('opera') == -1));
}

//Converts a value to a currency with specified number of decimals
function number_format(val, decimalCount) {
	if (decimalCount == 0) return Math.ceil(val);

	var i = parseFloat(val);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

/* Creates a popup of specified url */
function popup(name, pg, width, height, scrollbars) {
	var popup = window.open(pg, name, "toolbar=0,scrollbars=" + scrollbars + ",location=0,statusbar=0," + 
									"menubar=0,resizable=0,width=" + width + ",height=" + height);
}

function linkify(obj)
{
	var range = $(obj).getSelection();
	if (range.length == 0)
	{
		alert("Error, please select some text to add a link to.");
		return;
	}

	var lnk = prompt("Please enter the URL of your link", "http://");
	if (lnk == null)	return;
	if (lnk == 'http://' || lnk == '')
	{
		alert("Error, invalid link.");
		return;
	}
	
	$(obj).replaceSelection('<a href="' + lnk + '">' + range.text + '</a>', true);
}
