function chgPage(page)
{
	$('page').value = page;
	$('filter').submit();
}
String.prototype.trim=function()  
{
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}
function addOption(selectId, txt, val)
{
    $(selectId).options.add(new Option(txt, val));
}
function removeOptions(selectId)
{
	for (i=$(selectId).options.length-1; i>=0; i--) {
		$(selectId).options.remove(i);
	}
}
function addOptions(selectId, opts)
{
	for(var v in opts){
		$(selectId).options.add(new Option(opts[v], v));
	}
}
function addBookmark(){
	var _title=document.title;
	var _url=document.location.href;
	if (window.sidebar) {
		window.sidebar.addPanel(_title, _url,"");
	} else if( document.all ) {
		window.external.AddFavorite( _url, _title);
	} else if( window.opera && window.print ) {
		return true;
	}
}
function run()
{
	var requestModule = arguments[0];
	var requestFunction = arguments[1];
	var requestParams = Array(arguments.length-2);
	for(i=0; i<arguments.length-2; i++) {
		requestParams[i]=arguments[i+2];
	}
    xajax.config.requestURI ="/xajaxrequest/" +  requestModule;
    xajax.request({ xjxcls: requestModule + 'Ajax', xjxmthd: requestFunction }, {mode:'asynchronous', method: 'post', parameters:requestParams});
}
function hour2day(hours, language)
{
	var text = '';
	
    var days = Math.floor(hours / 24);
    var hours = Math.ceil(hours % 24);
    
    if (language == 'zh') {
        if (days > 0) {
            text = days.toString() + '天';
        }
        if (hours > 0) {
            text = text + hours.toString() + '小时';
        }
    } else {
        if (days == 1) {
            text = days.toString() + ' Day ';
        } else if (days > 1) {
            text = days.toString() + ' Days ';
        }
        if (hours == 1) {
            text = text + hours.toString() + ' Hour';
        } else if (hours > 1) {
            text = text + hours.toString() + ' Hours';
        }
    }
	
	return text;
}

function moneyFormat(num, currency)
{
	var money = '';
	
	num = num.toString().replace(/\$|\,/g, '');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if(cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
	num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	money = (((sign) ? '' : '-') + num + '.' + cents);
	
    switch (currency) {
        case 'MYR':
            money = 'RM ' + money;
            break;
        case 'SGD':
            money = 'SGD ' + money;
            break;
        case 'PHP':
            money = 'PHP ' + money;
            break;
        case 'VND':
            money = 'VND ' + money;
            break;
        case 'USD':
            money = money + ' USD';
            break;
        case 'IDR':
            money = money + ' Rupiah';
            break;
        case 'THB':
            money = money + ' Baht';
            break;
    }
	return money;
}

function number2string(amount)
{
    if (amount == 0) return 0;
    var text = '';
    if (amount >= 1000000000) {
        floor1  = Math.floor(amount / 10000000) / 100;
        amount = amount - floor1 * 1000000000;
        text = text + floor1 + 'b';
    }
    if (amount >= 1000000) {
        floor2  = Math.floor(amount / 10000) / 100;
        amount = amount - floor2 * 1000000;
        text = text + floor2 + 'm';
    }
    if (amount >= 1000) {
        floor3  = Math.floor(amount / 10) / 100;
        amount = amount - floor3 * 1000;
        text = text + floor3 + 'k';
    }
    if (amount > 0) text = text + amount;
    return text;
}

function dump_props(obj, objName) {
   var result = ""
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + "<BR>"
   }
   result += "<HR>"
   return result
}