function format_num(value){
  value = value+"";
  var dotindex=value.indexOf(".");
	if(dotindex==-1){
		value += ".00";
	}else{
		value = formatNum(value,2);
	}
	return value;
}

function formatNum(strValue,intCount)
{		
	if (0==intCount)
	{
		return(strValue);
	}
	var i;
	var strTemp;
	var j=0;
	strTemp = "1";
	for(i=1;i<=intCount;i++)
	{
		strTemp= strTemp +"0";
	} 
	if(strValue==""||null==strValue)
	{
		strValue="0";
	}
	strValue=Math.round(strValue*strTemp);
	strValue=strValue/strTemp;
	strTemp=new String(strValue);
	for (i=0;i<strTemp.length;i++)
	{
		if (strTemp.substr(i,1)==".")
		{ 
			j=i;  
		}
	}
	i=i-j;	
	if (i==strTemp.length)
	{
		strTemp=strTemp+".";
		for(j=0;j<intCount;j++)
		{
			strTemp=strTemp+"0";
		}
	}
	else
	{
		if (intCount-i<intCount)
		{
			for(j=0;j<intCount-i+1;j++)
			{
				strTemp=strTemp+"0";
			}	
		}
	}
	return(strTemp);
} 


/* Stephen Added on 2007-04-05 */
function trim(str) {
	if(str==undefined)
		return;
	var len = str.length;

	while(len > 0) {
		if (str.charAt(0) == ' ') {
			str = str.substring(1, len);
			len = len - 1;
		} else {
			break;
		}
	}

	while(len > 0) {
		if (str.charAt(len - 1) == ' ') {
			str = str.substring(0, len - 1);
			len = len - 1;
		} else {
			break;
		}
	}

	return str;
}

function trimAll(oform) {
	var len = oform.elements.length;

	for (i=0;i<len;i++) {
		if (oform.elements[i].type != "button" && oform.elements[i].type != "submit" && oform.elements[i].type != "reset")
			oform.elements[i].value = trim(oform.elements[i].value);
	}
	return true;
}


function isDigit(theNum){
	var theMask='0123456789';
	if (isEmpty(theNum)) return(false);
	else if (theMask.indexOf(theNum)==-1) return(false);
	return(true);
}

function isEmpty(str){
	return str==null || str.length==0 ;
}

function isTrimEmpty(str){
	return  str == null || str.trim().length==0 ;
}

function isInt(theStr){
	var flag=true;
	if (isEmpty(theStr)) {flag=false;}
	else
	{ for (var i=0;i<theStr.length;i++){
		if (isDigit(theStr.substring(i,i+1))==false) {
			flag=false; break;}
		}
	}
	return(flag);
}

function isFloat(float1)
{
	regExp=/[^[\+\-]?\d\.]/
	if(isNaN(float1) || regExp.exec(float1))
		return false;
	return true;
}

function isDecimalBeyond(count,value){
	if ( isFloat(value) ){
		var dotindex=value.indexOf(".");
		return dotindex>0 && (value.length-dotindex-1>count) ;
	} else 
		return true;
}

function isBeyond2decimal(value){
	return isDecimalBeyond(2,value);
}

function getValue(obj){//get selected value
	// obj -- list object
	return obj.options[obj.selectedIndex].value;
}

function getText(obj){//get selected text
	// obj -- list object
	return obj[obj.selectedIndex].text;
}

function arrayOf(obj){
	if(obj==null)
		return new Array();
	if(obj==undefined)
		return new Array(obj);
	return obj;
}

function radio$(radioName) {
    var obj = document.getElementsByName(radioName);
     for(i = 0;i<obj.length;i++){
          if(obj[i].checked)
             return obj[i].value;
      }
     return "undefined";
}

String.prototype.trim = function(){ 
   return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

String.prototype.toDate = function(){
	var ymd = this.split("-");
	return new Date(ymd[0],ymd[1]-1,ymd[2]);
}

Date.prototype.toStdString = function(){
	var mon = this.getMonth()+1;
	var dd = this.getDate();
    return (isMoziila()? (this.getYear()+1900):this.getYear())+"-"+(mon<10?("0"+mon):mon)+"-"+(dd<10?("0"+dd):dd);
}

function isMoziila(){
    return  (typeof HTMLElement!="undefined" && ! HTMLElement.prototype.insertAdjacentElement);
} 

function leadWithZero(num){
	return num<10?("0"+num):num;
}

function isEmailAddress(email){
	var reg = /^[_a-z0-9A-Z\.]+@([_a-z0-9A-Z]+\.)+[a-z0-9A-Z]{2,3}$/; 
	 return reg.exec(email)!=null ;
} 
// date format should be yyyy-MM-dd
function daysBetween(date1,date2){
	return (date1.toDate()-date2.toDate())/24/60/60/1000;
}
// date format should be yyyy-MM-dd
function lastDay(dateStr){
	var date1 = dateStr.toDate();
	date1.setMonth(date1.getMonth()+1);
	date1.setDate(0);
	return date1.toStdString();
}
// date format should be yyyy-MM-dd
function addDays(dateStr,days){
	var date1 = dateStr.toDate();
	date1.setDate((date1.getDate()+days));
	return date1.toStdString();
}
// date format should be yyyy-MM-dd
function addMonths(dateStr,months){
	var date1 = dateStr.toDate();
	date1.setMonth((date1.getMonth()+months));
	return date1.toStdString();
}

/* end */ 