function yesno() // confirmation popup
{
	args = yesno.arguments; // get arguements
	question = ((args[0]) ? args[0] : 'Are you sure you wish to remove this record?');
	if (confirm(question)) return true;
}
//document.onmousemove = getmouseposition;

oldOnmousemove = document.onmousemove ? document.onmousemove : new Function;
document.onmousemove = getMousePosition;

function getMousePosition()
{
	if (is_ie || is_ie5up || is_nav6up || is_gecko) {
		if (arguments[0]) {
			mouseX = arguments[0].pageX;
			mouseY = arguments[0].pageY;
		} else if (document.body) {
			mouseX = event.clientX + document.body.scrollLeft;
			mouseY = event.clientY + document.body.scrollTop;
			arguments[0] = null;
		}

		oldOnmousemove();
	}
}

// create a cookie
function createCookie(name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name, "", -1);
}

function getSize(xSizeb)
{
	var xSize = 0+'b';

	xSizeb = parseInt(xSizeb);
	xSizekb = xSizeb / 1024;
	xSizemb = xSizekb / 1024;
	xSizegb = xSizemb / 1024;
	xSizetb = xSizegb / 1024;
	xSizepb = xSizetb / 1024;
	if (xSizeb > 1) xSize = Math.round(xSizeb,2)+'b';
	if (xSizekb > 1) xSize = Math.round(xSizekb,2)+'kb';
	if (xSizemb > 1) xSize = Math.round(xSizemb,2)+'mb';
	if (xSizegb > 1) xSize = Math.round(xSizegb,2)+'gb';
	if (xSizetb > 1) xSize = Math.round(xSizetb,2)+'tb';
	if (xSizepb > 1) xSize = Math.round(xSizepb,2)+'pb';
	return xSize;
}

// generate random password
function generate_key(xLength, xType)
{
	// start with a blank password
	var xPassword = '';
	var xChar = '';
	// define possible characters
	if (xType == 'alpha') xPossible = 'abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ';
	else if (xType == 'num') xPossible = '0123456789';
	else xPossible = '0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ';

	// add random characters to $password until $length is reached
	for (i = 1; i <= xLength; i++)
	{
		// pick a random character from the possible ones
		xChar = xPossible.substr(Math.floor(Math.random()*xPossible.length-1), 1);
		// we don't want this character if it's already in the password
		xPassword += xChar;
	}
	return xPassword;
}

// add items to a select
function addOption(mySelect, myValue, myCaption)
{
	var elSel = document.getElementById(mySelect);
	if (elSel.selectedIndex >= 0)
	{
		var elOptNew = document.createElement('option');
		elOptNew.text = myValue;
		elOptNew.value = myCaption;
		var elOptOld = elSel.options[elSel.selectedIndex];
		try { elSel.add(elOptNew, elOptOld); } // standards compliant; doesn't work in IE
		catch(ex) { elSel.add(elOptNew, elSel.selectedIndex); } // IE only
	}
}


function remOption(mySelect, selectNum)
{
	var elSel = document.getElementById(mySelect);
	for (i = elSel.length; i >= 0; i--)
	{
		if (selectNum && selectNum == i) elSel.remove(i);
		else elSel.remove(i);
	}
}

// format as money (number, decimals, decimal char, thousand separator)
/*function number_format(n, c, d, t)
{
	var m = ( c = Math.abs( c ) + 1 ? c : 2, d = d || ".", t = ( n >= 1000 ) ? t || "," : '', /(\d+)(?:(\.\d+)|)/.exec( n + '' ) ), x = m[1].length % 3;
	return ( x ? m[1].substr( 0, x ) + t : '' ) + m[1].substr( x ).replace( /(\d{3})(?=\d)/g, "$1" + t ) + ( c ? d + ( +m[2] ).toFixed( c ).substr( 2 ) : '' );
};*/
function number_format(num, prefix){
   prefix = prefix || '';
   num += '';
   var splitStr = num.split('.');
   var splitLeft = splitStr[0];
   var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
   var regx = /(\d+)(\d{3})/;
   while (regx.test(splitLeft)) {
      splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
   }
   return prefix + splitLeft + splitRight;
}

function number_unformat(num) {
   return num.replace(/([^0-9\.\-])/g,'')*1;
}



// find value in array function
Array.prototype.find = function (s)
{
	for (var i=0; i < this.length; i++)
	if (this[i] == s) return true;
	return false;
}
