	function str2c(n){
	  if(-1 == n.indexOf(".")){
	   return seti2c(n);
	  }else{
	   var i,istr,f,fstr,a,rstr;
	   a = n.split(".");
	   i = a[0];
	   f = a[1];
	   istr = seti2c(i);
	   fstr = setf2c(f);
	   rstr = istr+fstr;
	   rstr = rstr.replace(/^元/,"");
	   return rstr;
	  }
	}

	function i2c(n){
	 if(typeof(n) == "number"){
	  if(-1 == n.toString().indexOf(".")){
	   return seti2c(n);
	  }else{
	   var i,istr,f,fstr,a,rstr;
	   a = n.toString().split(".");
	   i = a[0];
	   f = a[1];
	   istr = seti2c(i);
	   fstr = setf2c(f);
	   rstr = istr+fstr;
	   rstr = rstr.replace(/^元/,"");
	   return rstr;
	  }
	 }else{
	  return "---";
	 }
	}

	function seti2c(n){
	 var ns = n.toString();
	 var tempstr = "";
	 for(var i=1;i<ns.length+1;i++){
	  switch(i){
	   case 1:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"元"+tempstr;
		}else{
		 tempstr = "元"+tempstr;
		}
		break;
	   case 2:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"拾"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 3:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"佰"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 4:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"仟"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 5:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"万"+tempstr;
		}else{
		 tempstr = "万"+tempstr;
		}
		break;
	   case 6:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"拾"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 7:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"佰"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 8:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"仟"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 9:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"亿"+tempstr;
		}else{
		 tempstr = "亿"+tempstr;
		}
		break;
	   case 10:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"拾"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 11:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"佰"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   case 12:
		var t = ns.substr(ns.length-i,1);
		if(t!="0"){
		 tempstr = t+"仟"+tempstr;
		}else{
		 tempstr = "0"+tempstr;
		}
		break;
	   default:break;
	  }
	 }
	 return g2b(tempstr);
	}

	function setf2c(n){
	 var ns = n.toString();
	 var tempstr = "";
	 for(var i=0;i<ns.length;i++){
	  switch(i){
	   case 0:
		var t = ns.substr(i,1);
		if(t!="0"){
		 tempstr += t+"角";
		}else{
		 tempstr += "0";
		}
		break;
	   case 1:
		var t = ns.substr(i,1);
		if(t!="0"){
		 tempstr += t+"分";
		}
		break;
	   default:break;
	  }
	 }
	 return g2b(tempstr);
	}

	function g2b(s){
		rs = s.replace(/0+/g,"0");
		rs = rs.replace(/0(元|万|亿)/g,"$1");
		rs = rs.replace("亿万","亿");
		rs = rs.replace(/0/g,"零");
		rs = rs.replace(/1/g,"壹");
		rs = rs.replace(/2/g,"贰");
		rs = rs.replace(/3/g,"叁");
		rs = rs.replace(/4/g,"肆");
		rs = rs.replace(/5/g,"伍");
		rs = rs.replace(/6/g,"陆");
		rs = rs.replace(/7/g,"柒");
		rs = rs.replace(/8/g,"捌");
		rs = rs.replace(/9/g,"玖");
		return rs;
	}

  function test() {
	alert("test javascript");
  }

  // 大小写转换
  // arg1: 原控件，arg2: 目标控件
  function amount2big(srcFormObj, dstFormObj) {
	var s = srcFormObj.value;
    if (isSpace(s)) {
	  s = "0";
//      alert("金额不能为空");
//      return false;
    }

	var tmp;
//	alert("原金额:" + srcFormObj.value);
	tmp = str2c(s);
//	alert("目标金额:" + tmp);
	dstFormObj.value = tmp;
    return true;
  }

  // 小写金额格式化
  // arg1: 原控件，arg2: 目标控件，arg3: 小数位
  function amountformat(srcFormObj, dstFormObj, n) {
	var s, r, t, l, i, d;
	s = srcFormObj.value;
    if (isSpace(s)) {
//      alert("金额不能为空");
	  s = "0";
//      return false;
    }

	n = n > 0 && n <= 20 ? n : 2;
	s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
	l = s.split(".")[0].split("").reverse(),
	r = s.split(".")[1];
	t = "";
	for(i = 0; i < l.length; i ++ )
	{
		t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
	}
	d = t.split("").reverse().join("") + "." + r;

	dstFormObj.value = d;
    return true;
  }

  // 大小写转换 + 小写金额格式化
  // arg1: 原控件，arg2: 目标控件，arg3: 小数位
  function amountformat2(srcFormObj, dstFormObj, n) {
	var s, r, t, l, i, d;
	s = srcFormObj.value;

	if (isSpace(srcFormObj.value)) {
//      alert("金额不能为空");
//      return false;
//	  return true;
	  s = "0";
    }
	
	// 小写金额格式化
	n = n > 0 && n <= 20 ? n : 2;
	s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
	l = s.split(".")[0].split("").reverse(),
	r = s.split(".")[1];
	t = "";
	for(i = 0; i < l.length; i ++ )
	{
		t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
	}
	d = t.split("").reverse().join("") + "." + r;

	srcFormObj.value = d;

	// 大小写转换
	var tmp;
	tmp = rmoney(srcFormObj.value);
//	alert("恢复:"+tmp);
	tmp = i2c(tmp);
//	alert("大写:"+tmp);
	dstFormObj.value = tmp;

	return true;
  }

	function rmoney(s)
	{
		return parseFloat(s.replace(/[^\d\.-]/g, ""));
	}

	// 计算合同到期日
	// arg1 期限  arg2 起始日  arg3 到期日  arg4 计算方式
//	caldayline(formUpdate.XXID5,formUpdate.XXID22,formUpdate.XXID37,formUpdate.XXID36)
	function caldayline(srcFormObj,beginFormObj,endFormObj,typeFormObj)
	{
		if (!typeFormObj[0].checked) {
			return true;
		}
		
		// 计算过程
		// add code here

		endFormObj.value = getlastdate(beginFormObj.value,srcFormObj.value);

		return true;
	}

	// 复制合同到期日
	// arg1 固定到期日  arg2 到期日  arg3 计算方式
	function copydayline(srcFormObj,dstFormObj,typeFormObj)
	{
		if (!typeFormObj[1].checked) {
			return true;
		}

		dstFormObj.value = srcFormObj.value;

		return true;
	}

	function getlastdate(date, month){
		var addmon = parseInt(month);
		var date = new Date(date.replace(/-/g,'/'));

		var days = date.getDate();
		var month = date.getMonth()+1;
		var year = date.getYear();
		
		var mm = month + addmon;
		var toYear = year;
		if(toYear < 100){
			toYear = toYear + 1900;
		}
		if(mm / 12 > 1){
			toYear = toYear + parseInt(mm/12);
			if(mm%12==0){
				toYear = toYear -1;
			}
		}
		var toMonth = mm % 12;
		if(mm % 12 == 0){
			toMonth = 12;
		}
		var toDay = days;
		
		if((toMonth == 4 || toMonth == 6 || toMonth == 9 || toMonth == 11) && days >30 ){
			toDay = 30;
		}
		if(toYear % 4 == 0 && toYear % 100 != 0 || toYear % 400 == 0){
			if(toMonth == 2 && days > 29){
				toDay = 29;
			}
		}else{
			if(toMonth == 2 && days > 28){
				toDay = 28;
			}
		}

		var toLate = toDay;
		if((toMonth == 2 || toMonth == 4 || toMonth == 6 || toMonth == 8 || toMonth == 9 || toMonth == 11) && toDay==1){
			toLate = 31;
			toMonth = toMonth - 1;
		}else if(toMonth == 1 && toDay == 1){
			toLate = 31;
			toMonth = 12;
			toYear = toYear - 1;
		}else if(toMonth == 3 && toDay == 1){
			if(toYear % 4 == 0 && toYear % 100 != 0 || toYear % 400 == 0){
				toLate = 29;
			}else{
				toLate = 28;
			}
			toMonth = toMonth - 1;
		}else if((toMonth == 5 || toMonth == 7 || toMonth == 10 || toMonth == 12) && toDay == 1){
			toLate = 30;
			toMonth = toMonth - 1;
		}else{
			toLate = toLate - 1;
		}
		var strMonth = toMonth + "";
		var strLateDay = toLate + "";
		if(toMonth<10){
			strMonth = "0"+strMonth;
		}
		if(toLate < 10){
			strLateDay =  "0"+strLateDay ;
		}
		
		return(toYear+'-'+strMonth+'-'+strLateDay);
	}

	function number2big(srcFormObj,dstFormObj)
	{
		if (srcFormObj.value == "0" || srcFormObj.value == "") {
			dstFormObj.value = "叁";
		} else if (srcFormObj.value == "1") {
			srcFormObj.value = "壹";
			dstFormObj.value = "肆";
		} else if (srcFormObj.value == "2") {
			srcFormObj.value = "贰";
			dstFormObj.value = "伍";
		} else if (srcFormObj.value == "3") {
			srcFormObj.value = "叁";
			dstFormObj.value = "陆";
		} else if (srcFormObj.value == "4") {
			srcFormObj.value = "肆";
			dstFormObj.value = "柒";
		} else if (srcFormObj.value == "5") {
			srcFormObj.value = "伍";
			dstFormObj.value = "捌";
		} else if (srcFormObj.value == "6") {
			srcFormObj.value = "陆";
			dstFormObj.value = "玖";
		} else if (srcFormObj.value == "7") {
			srcFormObj.value = "柒";
			dstFormObj.value = "拾";
		} else if (srcFormObj.value == "8") {
			srcFormObj.value = "捌";
			dstFormObj.value = "拾壹";
		} else if (srcFormObj.value == "9") {
			srcFormObj.value = "玖";
			dstFormObj.value = "拾贰";
		}

		return true;
	}
/*
	function hidedivbynot(srcFormObj, optValue, dstDivObj)
	{
		var hideme = document.getElementById(dstDivObj);
//		alert(srcFormObj.value+"=?"+optValue);
		if (srcFormObj.value != optValue) {
			// hide div
			hideme.style.display = 'none';
		} else {
			hideme.style.display = 'block';
		}

		return true;
	}
*/
	function hidedivbynot2()
	{
		var srcFormObj = document.getElementById('L1XXID3');
		var hideme = document.getElementById('hideme');
		// alert(srcFormObj.value+"=?额度业务");
		if (srcFormObj.value != '额度业务') {
			// hide div
			hideme.style.display = 'none';
		} else {
			hideme.style.display = 'block';
		}
	}

	function initialJs(moduleName, formName)
	{
//		alert(moduleName+":"+formName);
		if (moduleName == "spdb.xml" && formName == "limit")
		{
			var srcFormObj = document.getElementById('L1XXID3');
			var hideme = document.getElementById('hideme');
			// alert(srcFormObj.value+"=?额度业务");
			if (srcFormObj.value != '额度业务') {
				// hide div
				hideme.style.display = 'none';
			} else {
				hideme.style.display = 'block';
			}
		}
	}

	//--------------------2010-2-3 客户管理系统下的扩展
	//客户-合同-金额(金额小写，金额大写，已付，未付)：转换为大写；判断只能大于已付金额；计算出未付金额		
	function cust2_contract_money1(obj1, obj2, obj3, obj4) {
	    //obj1,obj3只能为金额
	    if (!isPrice(obj1.value)) {
		alert("合同总金额只能数字");
	    }	
	    if (!isPrice(obj3.value)) {
		alert("已付金额只能数字");
	    }	
	    amount2big(obj1, obj2);
	    if ( parseFloat(obj1.value) < parseFloat(obj3.value) ) {
		alert("合同总金额小于已付金额");
	    }
	    obj4.value = parseFloat(obj1.value) - parseFloat(obj3.value);
	    return true;
	}
	//客户-合同-已付金额(金额小写，已付，未付)：判断只能大于已付金额；计算出未付金额		
	function cust2_contract_money2(obj1, obj3, obj4) {
	    //obj1,obj3只能为金额
	    if (!isPrice(obj1.value)) {
		alert("合同总金额只能数字");
	    }	
	    if (!isPrice(obj3.value)) {
		alert("已付金额只能数字");
	    }	
	    if ( parseFloat(obj1.value) < parseFloat(obj3.value) ) {
		alert("合同总金额小于已付金额");
	    }
	    obj4.value = parseFloat(obj1.value) - parseFloat(obj3.value);
	    return true;
	}
	//客户-应收款(收款的比例，应收款金额，合同总金额):根据比例计算，不能超过待收款
	function cust2_receivables_money1(obj1, obj2, obj3, obj4) {
	    if (!isPrice(obj1.value)) {
		alert("收款的比例只能数字");
		return false;		
	    }		
	    if (parseFloat(obj1.value) > 100) {
		alert("收款的比例不能大于100");
		return false;	
	    }
	  
	    if (isPrice(obj3.value) && isPrice(obj1.value) && obj3.value != "" && obj1.value != "" ) {	
	      obj2.value = (parseFloat(obj3.value) * parseFloat(obj1.value)) / 100   
	      if (parseFloat(obj2.value) + parseFloat(obj4.value) > parseFloat(obj3.value)) {
		alert("应收款金额大于待收款");
		return false;	
	      }	
	      if (!isPrice(obj2.value)) {
		alert("应收款金额只能数字");
	        return false;	
	      }
            }
	    return true;	
	}
	/*
	function cust2_receivables_money1(obj1, obj2, obj3, obj4) {
	    if (!isPrice(obj1.value)) {
		alert("收款的比例只能数字");	
	    }		
	    if (parseFloat(obj1.value) > 100) {
		alert("收款的比例不能大于100");
	    }
	    if (isPrice(obj3.value)) {	
	      obj2.value = (parseFloat(obj3.value) * parseFloat(obj1.value)) / 100   
	      if (parseFloat(obj2.value) + parseFloat(obj4.value) > parseFloat(obj3.value)) {
		alert("应收款金额大于待收款");
	      }	
	      if (!isPrice(obj2.value)) {
		alert("应收款金额只能数字");
	      }
            }
	    return true;	
	}
	*/
	//客户-已收款（本次收款金额，收款金额大写，合同总金额，上次未付款金额，本次未付款金额）
	function cust2_receipts_money1(obj1, obj2, obj3, obj4, obj5) {
	    if (!isPrice(obj1.value)) {
		alert("本次收款金额只能数字");
	    }		
	    if ( parseFloat(obj4.value) < parseFloat(obj1.value) ) {
		alert("未付款金额小于本次收款金额");
	    }    
	    amount2big(obj1, obj2);
	    obj5.value = parseFloat(obj4.value) - parseFloat(obj1.value);
	    return true;
	}

	//开始时间，结束时间
	function qingjia_time(obj1, obj2) {
	    t2 = obj2.value;
            t1 = obj1.value;
	    if (t2 <= t1) {
		alert("结束时间不能小于或等于开始时间");
		return false;
	    }

	    return true;
        }

	//将天数 * 7 + 小时数 = 最终小时数

        function qingjia_tohour(obj1, obj2, obj3) {
	    t1 = parseInt(obj1.value);
	    t2 = parseInt(obj2.value);
	    if (t2 >= 7) {
		t1 = t1 + parseInt(t2/7);
		t2 = t2%7;
            }
	    t3 = parseInt(t1 * 7) + parseInt(t2);
	    obj1.value = t1;
	    obj2.value = t2;
	    obj3.value = t3;   	
	    leave = parseInt(formUpdate.SYQJ2.value);
	    if (leave < t3) {
		alert("超过剩余天数");
		return false;
	    }
	    if (t3 <=0) {
		alert("请假数必须大于0");
		return false;
	    }	
	    return true;	
	}


	function feiyong(obj1, obj2, vName) {
          amount2big(obj1,obj2);
	  var t1 = parseInt(obj1.value);
	  if (t1 <=0) {
		alert(vName + "必须大于0");
		return false;		
	  }
	  return true;
	}
    
        function jiaban(obj1, vName) {
	  var v = obj1.value;
	  if ((v != "0.5" && !isNum(v)) || v == "0") {
	    alert(vName + "只能为0.5、1、2、3等");
	    return false;
	  }
          return true;
	}
        function tiaoxiu(obj1) {
	  var v = obj1.value;
	  if ((v != "0.5" && !isNum(v)) || v == "0") {
	    alert("调休天数只能为0.5、1、2、3等");
	    return false;
	  }
	  var leave = parseFloat(formUpdate.KXTS.value);
	  if (leave < parseFloat(v)) {
		alert("调休天数超过可休天数");
		return false;
	  }
          return true;
	}

	function chengji(obj1, obj2, obj3) {
	  //if (!isNum(obj1.value) || !isNum(obj2.value)) {
	  //2012-01-11修改 支持小数点
   	  if (!isPrice(obj1.value) || !isPrice(obj2.value)) {
	     return false;
	  }
          if (obj1.value != "" && obj2.value != "") {
	    var v1 = parseFloat(obj1.value);
	    var v2 = parseFloat(obj2.value);
	    var v3 = v1 * v2;
	    obj3.value = v3.toFixed(2);
	  }
	  return true;
	}

	function chengji2(obj1, obj2, obj3, objCount, objTotal) {
          //把合累计到obj4
          var vCount = objCount.value;
	  var v1 = "";
	  var v2 = "";
          var v3 = 0;
          var vTotal = 0;

          for (var i=0; i<vCount; i++) {
	     v1 = eval(obj1 + "["+ i + "].value;");
	     v2 = eval(obj2 + "["+ i + "].value;");
	     if (v1 != "" && !isPrice(v1) || v2 != "" && !isPrice(v2)) {
	          alert("数据格式不正确");
	     	  return false;
	     }
             if (v1 != "" && v2 != "") {
		v3 = parseFloat(v1) * parseFloat(v2);
		eval(obj3 + "["+ i + "].value=" + v3);	
                vTotal += v3;	
	     }


	  }
          objTotal.value = vTotal;
	
	  return true;
	}

	function xiaoyu(obj1, vName, obj2, vName2) {
	  if (!isPrice(obj1.value) || !isPrice(obj2.value)) {
	     return false;
	  }
          if (obj1.value != "" && obj2.value != "") {
	    var v1 = parseFloat(obj1.value);
	    var v2 = parseFloat(obj2.value);

	    if (v1 >v2) {
		alert(vName + "不能大于" + vName2);
		return false;
	    }
	  }
	  return true;
	}


	//手机必须为空或11位数字
	function checkMobileNumber(obj) {
	  if (obj == null) {
	    return true;
	  }
	  var v = obj.value;
	  if (v == "") {
	    return true;
	  }
          if (v == "" || (v.length == 11 && isNum(v)) ) {
          } else { 
	    alert("手机号码必须是11位的数字");
	    return false;
	  }
	  return true;
           
	}
