/*********************************************************************
*
*	Standard library
*
*********************************************************************/

/* php-like functions */
function ucfirst (str)
{
	return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();
}

function floatval (str)
{
	var n = parseFloat(str);
	if (isNaN (n)) return 0;
	return n;
}

function intval (str)
{
	return floor(floatval(n));
}

function number_format (number, decimals, dec_point, thousands_sep)
{
	var exponent = "";
	var numberstr = number.toString ();
	var eindex = numberstr.indexOf ("e");
	if (eindex > -1) {
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}
	if (decimals != null) {
		var temp = Math.pow (10, decimals);
		number = Math.round (number * temp) / temp;
	}
	var sign = number < 0 ? "-" : "";
	var integer = (number > 0 ? Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	var fractional = number.toString ().substring (integer.length + sign.length);
	dec_point = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
	if (decimals != null && decimals > 0) {
		for (i = fractional.length - 1, z = decimals; i < z; ++i) fractional += "0";
	}
	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
	if (thousands_sep != null && thousands_sep != "") {
		for (i = integer.length - 3; i > 0; i -= 3) integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}
	return sign + integer + fractional + exponent;
}

/* other functions */
function openwin (url,w,h,x,y,name)
{
	a = arguments;
	url = a[0] ? a[0] : "about:blank";
	w = a[1] ? a[1] : 300;
	h = a[2] ? a[2] : 200;
	x = a[3] ? a[3] : screen.width/2 - w/2;
	y = a[4] ? a[4] : screen.height/2 - h/2;
	popwin = window.open (url,name,"width="+w+",height="+h+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,fullscreen=no");
	if (popwin) {
		popwin.resizeTo (w,h);
		popwin.moveTo (x,y);
		popwin.focus();
	}
	setTimeout ("popwin.focus()",500);
}

