//乘积
function chengji(obj1, obj2, obj3) {
	  if (obj1 == null || obj2 == null || obj3 == null) {
		return false;
	  }
	  if (obj1.value == "") {
		obj1.value = 0;
	  }
	  if (obj2.value == "") {
		obj2.value = 0;
	  }
   	  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 xiangjia(obj1, obj2, obj3) {
	  if (obj1 == null || obj2 == null || obj3 == null) {
		return false;
	  }
	  if (obj1.value == "") {
		obj1.value = 0;
	  }
	  if (obj2.value == "") {
		obj2.value = 0;
	  }
   	  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 xiangjian(obj1, obj2, obj3) {
	  if (obj1 == null || obj2 == null || obj3 == null) {
		return false;
	  }
	  if (obj1.value == "") {
		obj1.value = 0;
	  }
	  if (obj2.value == "") {
		obj2.value = 0;
	  }
   	  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 = v2 - v1;
	    obj3.value = v3.toFixed(2);
	  }
	  return true;
}

//日期yyyy-MM-dd，年份可增加
function nian(obj1, num1, obj2) {
  if (obj1 == null || obj2 == null) {
	return false;
  }
  var v1 = obj1.value;
  var vYYYY = 0;
  var v2 = "";

  if (v1 != "" && v1.length >= 10) {
    vYYYY = parseInt(v1.substring(0,4));

    if (vYYYY > 0) {
     vYYYY = vYYYY + parseInt(num1);
     v2 = vYYYY.toString() + v1.substring(4);

     obj2.value = v2;
    }	

  }

  return true;
}

//数字范围
function shuzifanwei(obj1,num1,num2,vAlertMessage) {
  	if (obj1 == null) {
    	  return false;
  	}
	if (obj1.value == "") {
          alert(vAlertMessage);
	  return false;
	}
   	if (!isPrice(obj1.value)) {
	   return false;
	}
        if (obj1.value != "") {
	    var v1 = parseFloat(obj1.value);
	    if (num2 != null && num2 != "" && v1 > num2) {
		if (vAlertMessage != "") {
		  alert(vAlertMessage);
		}
		return false;
	    }
	    if (num1 != null && num1 != "" && v1 < num1) {
		if (vAlertMessage != "") {
		  alert(vAlertMessage);
		}
		return false;
	    }
	}
	return true;
}

//明细：乘积后合计
function mingxi_chengji_heji(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;
}

//明细：乘积后合计
//如果objId1, objId2有值，则obj5不能为空，sum(objId3 = objId1 * objId2) = objTotalId，
function mingxi_chengji_heji2(objId1, objId2, objId3, objCountId, objTotalId, objId5, vMessage) {
	//把合累计到obj4
	var vCount = eval("formUpdate." + objCountId + ".value");
	var v1 = "";
	var v2 = "";
	var v3 = 0;
	var v5 = "";
	var vTotal = 0;
	var flag = false;

	for (var i=0; i<vCount; i++) {
	  v1 = eval("formUpdate." + objId1 + "["+ i + "].value;");
	  v2 = eval("formUpdate." + objId2 + "["+ i + "].value;");
	  v5 = eval("formUpdate." + objId5 + "["+ i + "].value;");

	  if (v1 != "" && !isPrice(v1) || v2 != "" && !isPrice(v2)) {
		alert("数据格式不正确");
		return false;
	  }
          if (v1 != "" && v2 != "") {
		if (v5 == "") {
		  alert(vMessage);
		  return false;
		}

		v3 = parseFloat(v1) * parseFloat(v2);
		eval("formUpdate." + objId3 + "["+ i + "].value=" + v3 + ";");	
                vTotal += v3;	
		flag = true;
	  }

	}
	if (flag) {
	  eval("formUpdate." + objTotalId + ".value=" +  vTotal);
	} else {
	  eval("formUpdate." + objTotalId + ".value=''");
	}
	
	return true;
}

//小于或等于的数量:obj1的值不可大于obj2,不可小于0
function shuliang_xiaoyu(obj1, obj2, obj1Desc, obj2Desc) {
  if (obj1 == null || obj2 == null) {
    alert(obj1Desc + "或" + obj2Desc + "不存在");
    return false;
  }

  if (obj1.value != "" && !isPrice(obj1.value)) {
    alert(obj1Desc + "数据格式不正确");
    return false;
  }
  if (obj2.value != "" && !isPrice(obj2.value)) {
    alert(obj2Desc + "数据格式不正确");
    return false;
  }
  var v1 = parseFloat(obj1.value)
  var v2 = parseFloat(obj2.value)
  if (v1 <=0 || v1>v2) {
    alert(obj1Desc + "不可小于等于0，也不可大于" + obj2Desc);
    return false;
  }
  return true;

}


//用品专用yongpin.xml
function yongpin_kucun() {
   //购买金额=购买单价*入库数量；本次入库总数=历史入库总数+入库数量；当前库存=本次入库总数-历史领用总数
   chengji(formUpdate.XXID4, formUpdate.XXID14, formUpdate.XXID15);
   xiangjia(formUpdate.XXID8, formUpdate.XXID4, formUpdate.XXID6);
   xiangjian(formUpdate.XXID9, formUpdate.XXID6, formUpdate.XXID7);
   return true;
}


//金额转大写

  // 大小写转换
  // arg1: 原控件，arg2: 目标控件
  function amount2big(srcFormObj, dstFormObj) {
	var s = srcFormObj.value;
    if (isSpace(s)) {
	  s = "0";
    }

    var tmp;
    tmp = str2c(s);
    dstFormObj.value = tmp;
    return true;
  }
//-------------------------------这些是被金额转大写调用的
	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;
	}
//-------------------------------这些是被金额转大写调用的：结束