var Common = {};

/**
 * 去除字符串str开始和结束的空格
 */
Common.trim = function(str){
	return str.replace(/(^\s*)|(\s*$)/gi, "");
}

/**
 * 计算字符串str的长度，中文当两个字符
 */
Common.len = function(str){
 	var sStr,iCount,i,strTemp ;
 	iCount = 0 ;
 	sStr = str.split("");
 	for (i = 0 ; i < sStr.length ; i ++){
   		strTemp = escape(sStr[i]); 
   		if (strTemp.indexOf("%u",0) == -1){  	//  表示不是汉字
   			iCount = iCount + 1 ;
   		} else {
   			iCount = iCount + 2 ;
   		}
 	}
  	return iCount ;	
}

Common.intOnly = function(obj){
	if(Common.trim(obj.value) == "") return obj.value = 0;
	return obj.value = obj.value.replace(/\D+/g,'');
}
Common.floatOnly = function(obj){
	var value = parseFloat(obj.value);
	if(isNaN(value)){
		alert("请正确填写金额");
		obj.focus();
	}
}
