/******************************************************************
	Author:       
	Create Date : 2004-04-25
	Function    : 单据管理

	Explain			:	本js文件用来支持单据模式的生成，包括显示、新增和编辑

	
 ******************************************************************/
function getItems(voucherName){
	var tempName = voucherName;
	while(tempName.indexOf('$')!=-1){
		tempName = tempName.replace('$','.');
	}
	var items = parent.getVOITEMS(tempName);
	return items;
}

//var _vcss = "voucherDetailInput";
var _vcss = "readcss";
function orderGoNextLine(voucherName){
	//获取单据配置对象。
	var items = getItems(voucherName);
	if(items==null){
		alert("没有单据:"+voucherName+"的配置对象!");
		return;
	}
	//当前单据最大值加1.
	maxrowid = eval(voucherName+"_VOUCHER_ROWS");
	maxrowid=maxrowid+1;
	eval(voucherName+"_VOUCHER_ROWS="+maxrowid);

	key_dynamicRows = eval(voucherName+"_DYNAMIC_ROWS");
	mytable = document.all(voucherName) ;	
	//插入到最后一行之前
	mynewrow = mytable.insertRow(mytable.rows.length-key_dynamicRows) ; 
	mynewrow.bgColor="";//设置行的背景色
	mynewrow.rowid = maxrowid ;//设置行的id
	mynewrow.isNewTag = "true";//设置行的newTarge,表明是一个动态生成的新行
	//列公共API
	var eventStr = "onkeyPress=\"javaScript:Keypress(this); touchOnKeyPress(this);\"";
	var _cellNum = -1;//列号
	var _isFocusTag = false;//是否为焦点标签
    
	//根据items配置文件插入各个列元素。
	for( i = 0 ; i < items.length ; i++ )  {		
		if(items[i].isListItem=="false") continue;
		if(items[i].isListItem=="view") continue;
		//alert(items[i].name+":"+items[i].isListItem);
		_cellNum++;
    // private event
    eventStr = " onchange=\"javaScript: touchOnChange(this);\"  onblur=\"javaScript: touchOnblur(this);\"  onmousedown=\"javaScript: touchOnMouseDown(this);\" ";	
  	//var eventStr_onBlur = "";
  	//var eventStr_onKeyUp = "";	  
  	// support width and self width
  	var widthStr = "";
		/*
	  	var suppWidthStr = "";
	  	if (items[i].width != -1) {
	  	    widthStr = " style='width:" + items[i].width + "' ";
	  	}
	  	if(items[i].suppWidth != -1) {
	  	    suppWidthStr = " style='width:" + items[i].suppWidth + "' ";
	  	} else {
	  	    suppWidthStr = " style='width:50' ";  
	  	}
		*/
		// insert a new cell
		mynewrow.insertCell() ;
		var _css = "editcss";
    _vcss = "voucheredit";
		//设置是否可以编辑
		var _readonly = "";
		if(items[i].showmode == "readonly"){
		    _readonly = "readonly";
		    _vcss = "readcss";
		}

		// 取缺省的选项值
		str = "";
		var value = item.init;
		if(value=="undefined"||value==null) value="";
		//alert("value:"+value);
		optionStr = items[i].optionStr;
	   
		if(optionStr.length > 0){
			str = getSelectControl(items[i],maxrowid,widthStr,_vcss,eventStr,_readonly,optionStr,value,voucherName)
		} else {
			typeStr = items[i].type;
			
			str = getControlForType(typeStr,voucherName,items[i],value,maxrowid,_vcss,widthStr,eventStr,_readonly);
		}
		
		mynewrow.cells(_cellNum).align = "center" ;
		mynewrow.cells(_cellNum).nowrap = true ;
		mynewrow.cells(_cellNum).innerHTML = str ;
		
		//设置焦点
		if(i==1) {
			//var firstCell = document.getElementById(voucherName+"_"+items[i].name+maxrowid);
			//firstCell.focus();
			//非SELECT设置选中标志
			/*
			if(firstCell.tagName != "SELECT") {
				firstCell.select();
			}
			*/
		}
		
	}
	
	//判断是否可以删除，如果可以删除，那么就添加一个checkbox选择项，用于支持外部的删除按钮删除。
	var isDelete =  eval(voucherName+"_ISDELETE");//单据表
	if(isDelete) {
	  	mynewrow.insertCell() ;
	  	str = "<input type='checkbox' "
  			+ "  name='"+voucherName+"_selected"+maxrowid+"'"
  			+ "  class='"+_css+"' "
	  		+ "  rowid='" + maxrowid +"'"
  			+ "  onfocus=\"orderChangeCurRow('" +voucherName+"',"+maxrowid + ")\""
  			+ "  onclick=\"orderChangeCurRow('"+voucherName+"'," + maxrowid + ")\""
	  		+ "  caption='选择'"
  			+ "  style='width:100%'" 
			+ "  value='0'"
  			+ "  onblur=\"javaScript: touchOnblur(this);\""
	  		+ " "
  			+ eventStr
  			+">" ;
	//str+="<input type='hidden' name='"+voucherName+"_existid"+maxrowid+"'>";
	  	mynewrow.cells(_cellNum+1).align = "center" ;
  		mynewrow.cells(_cellNum+1).nowrap = true ;
	  	mynewrow.cells(_cellNum+1).innerHTML = str ;
  }
  　//以下加入隐藏字段
	hidden_col = eval(voucherName+"_VOUCHER_COLUMNS_DEFHIDDEN");
	str = "";
	if(hidden_col != null) {
		for(var i = 0; i < hidden_col.length; i++) {
	  	  str+="<input type='HIDDEN' name='"+hidden_col[i].name+maxrowid+"' "
  		     + " value='"+hidden_col[i].defalutValue+"' "
  			 + " caption='"+hidden_col[i].caption+"'>";  
	  	}
  		if(mynewrow.children(0) != null) {
	      mynewrow.children(0).insertAdjacentHTML("afterBegin",str); 
		}
  }
  //插入一个特殊标记，用于标记当前行
 
  touchAfterInsertRow(voucherName);
  //当前单据的最大记录数量，自动加1//全局变量"key_VOUCHERCOUNT"自加1
  eval("document.all('"+voucherName+"_VOUCHERCOUNT')").value = parseInt(eval("document.all('"+voucherName+"_VOUCHERCOUNT')").value) + 1; 

  //将焦点自动设置到新增行，即活动行的上一行上
  /*
	  for( i = 0 ; i < items.length ; i++ ){
		if(items[i].isListItem == "false")
			continue;
		//eval( " document.mainForm." + items[i].name + maxrowid + ".select() ;" ) ;
		if(eval("document.mainForm." + items[i].name + maxrowid + "_code") != null && eval("document.mainForm." + items[i].name + maxrowid + "_code").readOnly == false) {
		    _checkTabButton(eval( " document.mainForm." + items[i].name + maxrowid + "_code"));
		    eval( " document.mainForm." + items[i].name + maxrowid + "_code.focus() ;" );
		    eval( " document.mainForm." + items[i].name + maxrowid + "_code.select() ;" );
		} else if(eval( " document.mainForm." + items[i].name + maxrowid).tagName == "INPUT" && eval( " document.mainForm." + items[i].name + maxrowid).type == "text") {//如果是文本框
		    _checkTabButton(eval( " document.mainForm." + items[i].name + maxrowid));
		    eval( " document.mainForm." + items[i].name + maxrowid + ".focus() ;" ) ;
		    eval( " document.mainForm." + items[i].name + maxrowid + ".select() ;" ) ;
		} else {
		    _checkTabButton(eval( " document.mainForm." + items[i].name + maxrowid));
		   eval( " document.mainForm." + items[i].name + maxrowid + ".focus() ;" ) ;
		}
		return ;
  }*/

}

//======================================================================
//在单据中，通过快捷键"ALT+SPACE"触发生成新行
//如果页面中有多个单据  
//    1. 焦点不在任何一个单据上：点击该快捷键时，第一个单据新生成一行
//    2. 焦点在其中一个单据上：  点击该快捷键时，该单据新生成一行
//======================================================================
function _hiddenButtonOnclick() {

  var activeObj=document.activeElement;
  var voucherName = "";
  if(activeObj != null && activeObj != "undefined" && activeObj.rowid != null) {
    voucherName = activeObj.name.substring(0, activeObj.name.indexOf("VO_")+2);
  } else {
    var _tables = document.getElementsByTagName("TABLE");  
    for(var i = 0; i < _tables.length; i++) {
      if(_tables[i].id != null && _tables[i].id.indexOf("$") > 0 && _tables[i].id.indexOf("VO") > 0) {
        voucherName = _tables[i].id;
        break;
      }
    }
  }

	var isAdd    =  eval(voucherName+"_ISADD");
	//如果可以新增，添加一条新记录
	if(isAdd != null && isAdd == true) {
    if(document.getElementById(voucherName) != null && touchBeforeInsertRow(voucherName)) {
        orderGoNextLine(voucherName);
    }
  }
  
}

//**********************************************************************



//======================================================================
//动态生成单据的操作区,本操作区的目的实际上就是动态的往表中插入一个活动行
//======================================================================
function orderInit(voucherName)  {

    //快捷键"ALT+SPACE"触发生成新行的隐含缺省隐藏按钮，有且只有一个
    if(document.getElementById("_voucher_hiddenButton") == null) {
       document.write("<input type='button' value='hiddenbutton' id='_voucher_hiddenButton' style='display:none' onclick='_hiddenButtonOnclick();'>");
       addSpeedKeyScript("_voucher_hiddenButton", new Array("ALT", "SPACE"));  
    }
	//如果可以增加，那么就加入动态行，这样鼠标选择时可以支持插入新行
	var isAdd    =  eval(voucherName+"_ISADD");
	if(isAdd) {
  	   //插入一行	
    	mytable = document.all(voucherName) ;
  		key_dynamicRows = eval(voucherName+"_DYNAMIC_ROWS");
  		if(key_dynamicRows==1)
  			mynewrow = mytable.insertRow( mytable.rows.length) ;
  		if(key_dynamicRows==2)
  			mynewrow = mytable.insertRow( mytable.rows.length-1) ;
  		//mynewrow.bgColor="#FFF0D0";
  		mynewrow.bgColor = "#5199E3";
  		//items  = eval(voucherName+"_VOUCHER_COLUMNS");
		var items = getItems(voucherName);
		if(items==null) {
			alert("没有配置:"+voucherName);
			return;
		}
  		//maxrowid = voucherName+"_VOUCHER_ROWS";
	  	//往行中插入列
  		var columnNum = -1;//显示的列数目
		//alert(items.length);
		for(var i = 0; i < items.length; i++) {
			//alert(items[i].isListItem);
  			if(items[i].isListItem == "true"||items[i].isListItem.indexOf("new")!=-1) {
  				columnNum++;
  			}
  		}
		//如果可以删除，那么增加一个选择列
  		var isDelete =  eval(voucherName+"_ISDELETE");
  		if(isDelete) {
  			columnNum++;
  		}
		
  		for( i = 0 ; i <= columnNum ; i++ )  {
			
  			//往表中插入一个元素，并设置元素的html.
  			mynewrow.insertCell();
  			str = "<input type='text' class='"+_vcss+"' style=\"background-color:#5199E3;width:100%; cursor:'hand'\" onfocus=\"if(touchBeforeInsertRow('"+voucherName+"')) {orderGoNextLine('"+voucherName+"');}\" onclick=\"if(touchBeforeInsertRow('"+voucherName+"')) {orderGoNextLine('"+voucherName+"');}\"readOnly>" ;
  			mynewrow.cells(i).innerHTML = str ;
  		}
	}

}
//**********************************************************************

//**********************************************************************
//删除当前选择的行，可能是多行删除
//参数:key当前的表明
//**********************************************************************
function deleteSelectedRows(voucherName){
	maxrowid = eval(voucherName+"_VOUCHER_ROWS");
	for( i = 0 ; i <= maxrowid ; i++ )  {
		eval( "theObj = document.all."+voucherName+"_selected" + i + " ; " ) ;
		//alert(voucherName+"_selected"+i);
		if( theObj == null ) continue ;
		if(theObj.checked){
			orderDeleteLine(voucherName,i);
		}
	}
	touchAfterDeleteRow();//当删除行之后触发
}


//======================================================================
//删除指定行
//参数: num 指定行号,也是被删除行的ID
//======================================================================
function orderDeleteLine(voucherName,num )  {
	//当前事件源失去焦点
	//window.event.srcElement.blur() ;
	//获取当前表
	mytable = document.all(voucherName) ;	
	for( k = 0 ; k < mytable.rows.length ; k++ )   {
	    if( parseInt( mytable.rows(k).rowid ) == num )   {
		mytable.deleteRow(k) ;
		break ;
	  }
	}	
}
//**********************************************************************


//======================================================================
//	响应键盘事件,在form中调用
//	Ctrl + K  	删除当前行
//	Enter		跳转到下一个输入框
//======================================================================
function orderOnKeyPress(voucherName)  {
	/*window.event.cancelBubble = true ;
	if( window.event.ctrlKey && window.event.notnullCode == 11 && !isNaN( window.event.srcElement.rowid ))
		orderDeleteLine(voucherName,parseInt( window.event.srcElement.rowid ) ) ;

	if( window.event.notnullCode != 13 )  
		return ;

	if( window.event.srcElement.tagName != "INPUT" )
		return ;

	srcEle = window.event.srcElement ;
	srcEleFlag = parseInt( window.event.srcElement.flag ) ;
	srcEleID = parseInt( window.event.srcElement.rowid ) ;

	obj = document.mainForm ; 
	curpositionflag = 0 ;
	for( i = 0 ; i < obj.all.length ; i ++ )  {
		if( curpositionflag == 0 && srcEle != obj.all( i ) )
			continue ;
		curpositionflag = 1 ;
		if( srcEle == obj.all( i ) )
			continue ;
		if( obj.all( i ).tagName == "INPUT" && obj.all( i ).type == "text" && obj.all( i ).flag != "100" )  {
			obj.all( i ).select() ;
			obj.all( i ).focus() ;
			return ;
		} 
	}*/
	
	return;
		
}
//**********************************************************************

//======================================================================
//改变当前行为指定行
//======================================================================
function orderChangeCurRow(voucherName,num )  {
	window.event.cancelBubble = true ;
	key_line = eval(voucherName+"_VOUCHER_CURRENT_LINE");
	key_line = num ;
}
//**********************************************************************



//======================================================================
// 响应单据行失去焦点事件,作如下处理:
// 1.删除空行
// 2.去掉重复输入
//======================================================================
function orderRowLoseFocus(voucherName)  {
  /*
	items = eval(voucherName+"_VOUCHER_COLUMNS");
	maxrowid = eval(voucherName+"_VOUCHER_ROWS");
	//事件源事件判断
	srcEle = window.event.srcElement ;
	//事件源不能是输入框
	if( srcEle.tagName != "INPUT" && srcEle.type != "text" && srcEle.tagName != "SELECT")  {
	//删除空行
    mytable = document.all(voucherName) ;
		for( i = 1 ; i <= maxrowid ; i++ )  {
      IfDel = true;
			IfFlag=false;
			//
			for( j = 0 ; j < items.length ; j++ )  {
				theObjTemp = document.all(items[j].name +  i);
				if (theObjTemp != null){
					if(  theObjTemp.value != "" )  {
					IfDel = false;
					break;
				}
				IfFlag = true;
				}
				}
				//
				if( IfDel && IfFlag){
					orderDeleteLine(voucherName,i)
				}		
		}
		return ;
	}
		
	//检查是否有重复输入
	//第一步：找出不能重复输入的列
	//标记是否为5
	theColumn = -1 ;
	for( i = 0 ; i < items.length ; i++ )  {
		if( items[i].flag == 5 )  {
			theColumn = i ;
			break ;
		}
	}

	if( theColumn == -1 )
		return true;	
	if( srcEle.name == null || srcEle.name.indexOf(items[theColumn].name) != 0 )
		return true;

	//第二步：检查是否有重复输入
	curResults = new Array() ;
	for( i = 1 ; i <= maxrowid ; i++ )  {
		eval( "theObj = document.all." + items[theColumn].name + "" + i + " ; " ) ;
		if( theObj == null )
			continue ;
		//检查
		for( j = 0 ; j < curResults.length ; j++ )
			if (( theObj.value == curResults[j] ) && (theObj.value!=""))  {
				alert( items[theColumn].caption + "的值不能重复！") ;
				theObj.select();
				theObj.focus() ;
				return false;
			}                 
		curResults[curResults.length] = theObj.value ;
	}
  */
	return true ;
}
//**********************************************************************


//======================================================================
//删除当前行
//======================================================================
function orderDeleteCurRow(voucherName)  {
	key_line = eval(voucherName+"_VOUCHER_CURRENT_LINE");
	if( key_line == -1 )
		return ;
	mytable = document.all(voucherName) ;
	for( i = 0 ; i < mytable.rows.length ; i++ )   {
		if( parseInt( mytable.rows(i).rowid ) == key_line)   {
			mytable.deleteRow(i) ;
			break ;
		}
	}

}

//======================================================================
//弹出新窗口
//======================================================================
function openItemWin(openurl)  {
    window.showModalDialog(openurl, '', 'dialogWidth:500px;dialogHeight:350px;status:no');
}
//======================================================================

//======================================================================
//如果页面中有多个单据，返回指定单据的最大行号，只能增加，不能减少
// @ param voucherName   : 指定单据索引
//======================================================================
//var maxRowId = 0;
function getMaxRowId(voucherName) {
/*  var rowCount = getRowCount(voucherName);
  
  if(maxRowId < rowCount) {
    maxRowId = rowCount;
  } else {
	maxRowId++;
  }
  
  return maxRowId+1;*/
  
  var maxRowId = 	eval(voucherName+"_VOUCHER_ROWS");
  
  if(maxRowId < 0) {
    return;
  }
  
  return maxRowId;
} 

//======================================================================
//如果页面中有多个单据，返回指定单据的当前行数
//======================================================================
function getRowCount(voucherName) {
  var mytable = document.all(voucherName);
  
  return mytable.rows.length - 3;
} 


//======================================================================
//页面重载方法:如果单据项为number类型，则焦点离开时调取该方法
//======================================================================
function orderFieldBlur(objName) {
}

//======================================================================
//页面重载方法:当新增单据行以后触发
//======================================================================
function touchAfterInsertRow(voucherName) {}
//======================================================================


//======================================================================
//页面重载方法:当新增单据行以后触发
//======================================================================
function touchBeforeInsertRow(voucherName) {
  return true;  
}
//======================================================================


//======================================================================
//页面重载方法:当新增单据行以后触发
//======================================================================
function touchAfterDeleteRow() {}
//======================================================================



//==============================================
// 更改列表各列的名称
// @ param newNamesArray : 二维数组（如：new Array(new Array("paraName1","newName1"), new Array("paraName2","newName2"))）
//         第一维：列标识名
//         第二维：列的新名称
//==============================================
function replaceColumnNames(newNamesArray) {
  
  var newColumnNamesNum = newNamesArray.length;
  
  for(var i = 0; i < newColumnNamesNum; i++) {
    var paraObj = document.getElementById("_title_"+newNamesArray[i][0]);
    
    if(paraObj != null) {
      
      var needInSign = "";
      var oldInnerHTML = paraObj.innerHTML;
      var pos = oldInnerHTML.indexOf("</FONT>");//是否存在必填标志
      if(pos != -1) {
        needInSign = "<font color=red>*</font>";
      }
      paraObj.innerHTML = needInSign + newNamesArray[i][1];
    }
    
  }
  
}
//**********************************************


//=====================================================================================
// 资源文件
//=====================================================================================
//var _g_dt_imgCBB = "../dateControl/images/cbb_drop.gif";//测试



//=====================================================================================
// 将页眉中的删除文字替换为特定按钮
// parameter:
//  key：         单据索引
//  buttName：    按钮名称
//  shortcutName: 快捷键字母
//  isRead:       是否为只读[注意：该属性现在无用]
//=====================================================================================
function setVoucherDelSign(voucherName, buttName, shortcutName, isRead) {//isRead:无用
  var delCharTD = eval(voucherName+"_delSign");// 删除文字所在的TD对象
  if(delCharTD != null && delCharTD.tagName == "TD") {
    delCharTD.innerText = "";
    delCharTD.insertAdjacentHTML("afterBegin", "<input type='BUTTON' style='width:33' value='删["+shortcutName+"]' name='"+buttName+"' onclick='buttonOnclick(this)' class='orderButton' accesskey='"+shortcutName+"' readOnly>");    
  }
}

//=====================================================================================
// 通过读取工作区中的字段配置以及相应的子对象的值对象数组，显示单据列表
// curVoucherName: 当前单据名称
// pageStyle		 ：当前单据操作方式(包括'NEW'、'EDIT'、'VIEW'三种模式)
//=====================================================================================
function showVoucher(curVoucherName, pageStyle) {
   
	//以下做数据输入验证。
	if(pageStyle != "NEW" && pageStyle != 'VIEW' && pageStyle != 'EDIT') {
		alert("单据功能类型设置不正确，必须为：{'NEW'||'VIEW'||'EDIT'}");	
		return;
	}
	if(curVoucherName == null || curVoucherName == "null") {
		alert("对应的列表对象不明，请检查配置信息！");
		return;
	}
	//以下获取配置对象。
	var tempName = curVoucherName;
	while(tempName.indexOf('$')!=-1){
		tempName = tempName.replace('$','.');
	}
	
	var VOITEMS = parent.getVOITEMS(tempName);
	if(VOITEMS==null) {
		alert("没有配置:"+tempName);
		return;
	}
	/**********以下开始生成代码***********/
	//生成一个隐藏标签
	document.write("<INPUT TYPE='HIDDEN' NAME='_VOUCHER_TAG_' VALUE='"+curVoucherName+"'>\r\n");
	document.write("<INPUT TYPE='HIDDEN' NAME='"+curVoucherName+"_VOUCHERCOUNT' VALUE='0'>\r\n");
	
	//构造单据容器
	document.write("<table id='"+curVoucherName+"' cellspacing='1' width='100%'>\r\n");
	//以下显示单据标题
	makeVoucherTitle(VOITEMS,curVoucherName,pageStyle);
	
	//取列表中的当前记录
	//var CURRENTKEY = parent.CURRENTLISTWS.CURRENTKEY;//列表中的当前记录关键字段
	var CURRENTKEY = parent.getCurrentKey();
	
	var vouchers = parent.getVOUCHERSByKey(curVoucherName,CURRENTKEY);	
	//alert("vouchers. of "+CURRENTKEY+" has vouchers: "+vouchers.length);
	//如果为"EDIT"模式，构造已经存在的值对象对应标签对象
	eval("document.all('"+curVoucherName+"_VOUCHERCOUNT')").value = vouchers.length; 
	if( pageStyle == "EDIT") {
		var _VOUCHER_ROWS = 0;
		
		for(var i = 0; i < vouchers.length; i++) {
			var voucher = vouchers[i];
			++_VOUCHER_ROWS;//当前行数自增
			
			document.write("\t\t <tr height='18' class='voucherText' align='center' rowid='"+_VOUCHER_ROWS+"'> \r\n");
			//构造页面标签

			makeRecordEdit(VOITEMS, voucher.childBeanArray, curVoucherName, _VOUCHER_ROWS);
           
			document.write("\t\t </tr> \r\n");
		}
		//设置初始化行数		
		eval(curVoucherName+"_VOUCHER_ROWS="+_VOUCHER_ROWS);
	} else if( pageStyle == "VIEW") {
		//alert(curVoucherName);
		for(var i = 0; i < vouchers.length; i++) {
			var voucher = vouchers[i];
			//alert("childName:"+voucher.childName);
			//alert("parentKey:"+voucher.parentKey);
			//alert("atrrs:"+voucher.childBeanArray);
			document.write("\t\t <tr height='18' class='voucherrow' align='center' rowid='"+_VOUCHER_ROWS+"'> \r\n");
			//显示数据
            
			makeRecordView(VOITEMS, voucher.childBeanArray, curVoucherName);
			document.write("\t\t </tr> \r\n");
		}
	}
	document.write("</table> \r\n");	
	//如果不是查看模式，构造初始化对象
	
	if(pageStyle != "VIEW") {
		//- - - - - - - - - - - - - - - - - - - - - - - - - - - /
		//建立JAVASCRIPT单据对象
		//- - - - - - - - - - - - - - - - - - - - - - - - - - - /
		for(var i = 0; i < VOITEMS.length; i++) {
			var item = VOITEMS[i];
			if(item.voucherName == curVoucherName) {
				//设置当前字段的类型
				eval(curVoucherName+"_VOUCHER_COLUMNS_TYPES["+curVoucherName+"_VOUCHER_COLUMNS_TYPES.length++] = '"+item.type+"'; ");
				//new orderDetailColumn(curVoucherName, item.name, item.caption, item.value, item.notnull, item.isNum, item.minLen, item.maxLen, item.min, item.max, item.precLen, "true", item.width, item.suppWidth, item.selectMode, item.isListItem, item.optionStr);
			}
		}
		orderInit(curVoucherName);
	}
}


function makeVoucherTitle(VOITEMS,curVoucherName,pageStyle){
	/*
     * 以下生成子表标题。
	 */
	document.write("\t <tr height='18' class='listtitleborder' align='center'> \r\n");
	//以下在上传下载中特殊处理用。
	/*var unvisibleFields = new Array();
	for(var i = 0; i < VOITEMS.length; i++) {
		var item = VOITEMS[i];
		if(item.hreffield != null && item.hreffield != "undefined" && item.hreffield.length > 0) {
				unvisibleFields[unvisibleFields.length++] = item.hreffield;
		}		
	}*/
	var str="";
	var viewMode = pageStyle.toLowerCase();
	//alert("viewMode:"+viewMode);
	for(var i = 0; i < VOITEMS.length; i++) {
		var item = VOITEMS[i];
		//alert(item.name+":"+item.isListItem);
		if(item.isListItem=="true"||item.isListItem.indexOf(viewMode)!=-1) {
			//跳过不该显示的字段。
			var _isExist = false;
			/*for(var j = 0; j < unvisibleFields.length; j++){
				if(unvisibleFields[j] != null && unvisibleFields[j] == item.name) {
					_isExist = true;
					break;
				}
			}*/
			if((_isExist && pageStyle == "VIEW") || (pageStyle == "VIEW" && item.type == "file")) {
				continue;
			}
			//显示子表标题
			str += "\t\t <td id='_title_"+item.name+"' width='"+item.showwidth+"'> \r\n";
			//不能为空
			if(item.notnull == "true" && pageStyle != "VIEW") {
				str += "\t\t\t <font color=red>*</font> \r\n";
			}
			str += "\t\t\t "+item.caption+" \r\n";
			str += "\t\t </td> \r\n";
		}
	}
	if(pageStyle != "VIEW") {
		str += "\t\t <td id='"+curVoucherName+"_delSign'>选择</td> \r\n";
	}
	document.write(str);
	document.write("\t </tr> \r\n");
}

//----------------------------------------------------------/
//标签对应值显示
//		VOITEMS  Array 单据配置对象
//		_curBeanArray			 Array 其中一条记录对应的对象
//----------------------------------------------------------/
function makeRecordView(VOITEMS, attrs, _voucherName) {

	//alert("makeRecordView:"+attrs);
	for(var i = 0; i < VOITEMS.length; i++) {//标签对应的字符串	
		var item = VOITEMS[i];
		
		for(var j = 0; j < attrs.length; j++) {
			var attr = attrs[j];
			
			//名称相符
			if(attr==null) continue;
		      // alert("attr名称:"+attr[0]);
			  // alert("item名称:"+item.name);
		     
			if(attr[0]!=item.name) continue;			 
			if( item.isListItem == "true"||item.isListItem.indexOf("view")!=-1) {
				//根据类型进行构造				
				document.write("\t\t <td align='center' nowrap> \r\n");
				//如果是file类型，显示超链接,此处在上传下载中特殊处理。
				if(item.hreffield != null && item.hreffield !="null") {  
				        var name=attr[1];
	                    var mname;
	                    var curroid;
				        for(var f=0;f<name.length;f++)
				        {
				          if(isNaN(name.substring(f,f+1)))
				          {
				             curroid=name.substring(f+1);
				             mname=name.substring(0,f+1);
				          }
				        }
				     if(item.hreffield=="true")
				     {   	        
				      document.write("\t\t <a target='_self' href='/view/jsp/gmit/jzt/buying/EOrderMaintain/templeatmakeorder/uploadmessage.jsp?currMOID="+curroid+"' text='"+mname+"'/>"+mname+"</a>");
				     }
					 else
					 {  
				        document.write("\t\t <a target='_blank' href='"+_getBeanValue(attrs, item.hreffield)+"'/>"+mname+"</a>");    
				     }
				     
				} 
				else {
					//此处要处理选择的情况。
					//判断格式化小数
					if(item.type=="double"&&item.prec!=""&&item.prec>0){
					   attr[1]=formatFloatBit(attr[1],item.prec);
					}//格式化小数结束
					
					document.write("\t\t "+_getItemMapValue(item, attr[1])+"\r\n");
				}
				document.write("\t\t </td> \r\n");
			}
			
		}
	}
}

//------------------------------------------------------/
// 如果有对应的选择项，根据值来映射名称
// 参数： _curListItem 			配置对象
// 				_curListItemValue 当前值
// 返回： 与当前值匹配的选择项名称	
//------------------------------------------------------/
function _getItemMapValue(_curListItem, _curListItemValue) {
  
	//是否存在选择项
	if(_curListItem.optionStr != null && _curListItem.optionStr != "undefined" && _curListItem.optionStr.length > 0) {
		//直接赋予<option/>不成功，需要解析后生成option
		var _optionStr = _curListItem.optionStr;
		var _curValue  = "";
		var _curText   = "";
		var pos = 0;
		var _selectLength = 0;
		while(_optionStr.indexOf("<option") != -1) {
			pos = _optionStr.indexOf("<option value='");
			_optionStr = _optionStr.substring(15);
			_curValue = _optionStr.substring(0, _optionStr.indexOf("'"));
			pos = _optionStr.indexOf("</option>");
			_curText  = _optionStr.substring(_optionStr.indexOf(">")+1 , pos);
			
			//如果有匹配的值，返回对应的显示字符
			if(_curValue == _curListItemValue) {
				return _curText;
			}
			
			if(_curText.length*25 > _selectLength) {
				_selectLength = _curText.length*25;
			}
			
			_optionStr = _optionStr.substring(pos+9);
		}
		
	}
	
	//如果没有匹配的值，直接返回该值
	return _curListItemValue;
		
}

//根据字段名称获取相应的值，仅仅适用于字段中有连接字段的情况
function _getBeanValue(_curBeanArray, _curFieldName) {	
	for(var i = 0; i < _curBeanArray.length; i++) {
		var _curBean = _curBeanArray[i];		
		if(_curBean[0] != null && _curBean[0] == _curFieldName) {				
			return _curBean[1];
		}
	}
	
	return "";
}


//----------------------------------------------------------/
//标签构造器
//		VOITEMS  Array 单据配置对象
//		_curBeanArray			 Array 其中一条记录对应的对象
//	  _rowid						 int	 当前行号
//----------------------------------------------------------/
function makeRecordEdit(VOITEMS, _curBeanArray, _voucherName, _rowid) {
	//标签对应的字符串
	
	for(var i = 0; i < VOITEMS.length; i++) {
		var item = VOITEMS[i];
	
		//如果是file控件，一定没有相应的BEAN，进行特殊处理
		
		if(item.type == "file" && item.isListItem != "false") {
			//构造file控件
			
			document.write("\t\t <td align='center' nowrap> \r\n");
			
			document.write("\t\t "+_getTagStr(item, null, _rowid,_voucherName)+"\r\n");
			document.write("\t\t </td> \r\n");
		}
		
		//显示标签
		
		for(var j = 0; j < _curBeanArray.length; j++) {
			var _curBean = _curBeanArray[j];
			//名称相符
			
			if(_curBean != null && _curBean[0] == item.name) {
				//将不能为null，但是不显示的字段值进行隐藏处理
				//if(item.notnull == "true" && (item.isListItem == "false"|| item.isListItem.indexOf("edit")==-1)) {
				if(item.notnull == "true" && item.isListItem == "false" && item.pk !="true") {
					document.write("<input type='HIDDEN' name='"+_voucherName+"_"+item.name+_rowid+"' value='"+_curBean[1]+"'>");
				}
				//alert(item.name+":"+item.isListItem);
				if(item.isListItem=="false") continue;
				if(item.isListItem!="true" && item.isListItem.indexOf("edit")==-1) continue;
				//if(item.isListItem.indexOf("edit")==-1) continue;
				//根据类型进行构造
				document.write("\t\t <td align='center' nowrap> \r\n");
				
				document.write("\t\t "+_getTagStr(item, _curBean, _rowid,_voucherName)+"\r\n");
				document.write("\t\t </td> \r\n");
				
			}
		}
		
	}
	//_rowid是从1开始的。
	
	document.write("\t\t <td><input type='checkbox' name='"+_voucherName+"_selected"+_rowid+"'></td> \r\n");
	//存在的标志。
	
	document.write("<input type='hidden' name='"+_voucherName+"_existid"+_rowid+"' value='"+_rowid+"'>");
	
	//alert("\t\t <td><input type='checkbox' name='"+_voucherName+"_selected"+_rowid+"'></td> \r\n");
}

//-------------------------------------------------------/
//获取对应的显示控件.
// item: 当前字段配置信息对象
// _curBean				: 当前字段对应值对象
// _rowid					: 当前行号
//-------------------------------------------------------/
function _getTagStr(item, _curBean, _rowid,_voucherName) {


	//显示颜色的字段直接返回字符串
	if(item.name=="zaStorage"&&_voucherName=="gmit$jzt$buying$form$VEOrderPlanItemForm"){
	return _curBean[1]
	}


	var widthStr = "";
	var suppWidthStr = "";
	if (item.width != -1) {
	  widthStr = " style='width:" + item.width + "' ";
	}
	if(item.suppWidth != -1) {
	  suppWidthStr = " style='width:" + item.suppWidth + "' ";
	} else {
	  suppWidthStr = " style='width:50' ";  
	}
	//设置是否可以编辑
	var _readonly = "";
	var _css = "editcss";
	//var _tagvcss = "voucheredit";
	var _tagvcss = "editcss";
  if (item.pk == "true" || item.fk == "true") {      
    _readonly = "readonly";
    _css = "readcss";
    //_tagvcss = "orderDetailInput";
    _tagvcss = "readcss";
  } else if (item.showmode == "readonly") {
		_readonly = "readonly";
    _tagvcss = "readcss";
  }		
  
	// public event
	var eventStr = "onkeyPress=\"javaScript:Keypress(this); touchOnKeyPress(this);\"";
  // private event
  var eventStr = " onchange=\"javaScript: touchOnChange(this);\" "
       + " onblur=\"javaScript: touchOnblur(this);\" "
       + " onmousedown=\"javaScript: touchOnMouseDown(this);\" ";		
  if(_curBean !=null){
  var value = _curBean[1];
//格式化小数
if(item.type=="double"&&item.prec!=""&&item.prec>0){
value=formatFloatBit(value,item.prec);
}//格式化小数结束
  
  }
	
	//alert("value:"+_curBean[1]);
	// 取缺省的选项值
	var str = "";
	optionStr = item.optionStr;	

	if(optionStr.length > 0){    		
		str = getSelectControl(item,_rowid,widthStr,_tagvcss,eventStr,_readonly,optionStr,value,_voucherName)
	}
	else{
		
		typeStr = item.type		
		
		str = getControlForType(typeStr,_voucherName,item,value,_rowid,_tagvcss,widthStr,eventStr,_readonly);
		
	}		
	return str;	
	
}


//
function _getMapStr(_optionStr, _curFieldValue) {
	//直接赋予<option/>不成功，需要解析后生成option
	var _curValue  = "";
	var _curText   = "";
	var pos = 0;
	var _selectLength = 0;
	var _returnOptionStr = _optionStr;
	while(_optionStr.indexOf("<option") != -1) {
		
		pos = _optionStr.indexOf("<option value='");
		_optionStr = _optionStr.substring(15);
		_curValue = _optionStr.substring(0, _optionStr.indexOf("'"));
		pos = _optionStr.indexOf("</option>");
		_curText  = _optionStr.substring(_optionStr.indexOf(">")+1 , pos);
		
		
		if(_curValue == _curFieldValue) {
			pos = _optionStr.indexOf("\'");
			
			_returnOptionStr = _returnOptionStr.substring(0, _returnOptionStr.indexOf(_optionStr)) 
						+ _optionStr.substring(0, pos+1) 
						+ " selected "
						+ _optionStr.substring(pos+1);
						
			return _returnOptionStr;
			break;
		}
				
		if(_curText.length*25 > _selectLength) {
			_selectLength = _curText.length*25;
		}
		
		_optionStr = _optionStr.substring(pos+9);	
	}
}


function getControlInit(itemControl){
	rv = itemControl.init
	if(rv==null||rv=="null") rv = "";
	return rv;
	//getControlInit(items[i])
}

/**
 * 根据数据类型生成相应的输入控件。
 * @param typeStr 数据类型
 * @param voucherName  控件标志
 * @param 
 */
function getControlForType(type,voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){
	var str="";
	//alert("getControlForType:"+type);
	if(type=="boolean"){
		str= getCheckBoxForBoolean(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	}
	else
	if(type=="int"||type=="long"||type=="float"||type=="double"){
	
		str = getInputForNumber(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	}
	else
	if(type=="String"||type=="java.lang.String"){
		str=getInputForString(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
		/*if(item.hreffield != null && item.hreffield != "null") {
			str=getInputForImg(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
		} else {
			str=getInputForString(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
		}*/
	}
	else
	if(type=="file"){
		
		str=getInputForFile(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	}
	else
	if(type=="java.util.Date"||type=="java.sql.Date"){
		str=getInputForDate(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	}
	else
	if(type=="text"){		
		str = getInputForText(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	} else
	if(type=="function"){		
		str = getInputForButton(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly);
	
	}
	return str;
}

function getCheckBoxForBoolean(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){
	str = "<input type='checkbox' "
		+ "  name='"+voucherName+"_"+item.name+rowid+"'"
		+ "  class='"+vcss+"' "
		+ "  rowid='" + maxrowid +"'"
		+ "  caption='" + item.caption+"'"
		+ "  style='width:100%'" 
		+ "  value='false'"
		+ "  onblur=\"javaScript: touchOnblur(this);\""
		+ "  onclick=\"javaScript: this.value=(this.checked?'true':'false'); touchOnClick(this);\""
		+ " "
		+ eventStr
		+ " "
		+ ((value=="checked")?'checked':'')
		+ " "
		+ _readonly
		+ ">" ;
	return str;
}

function getInputForNumber(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){ 

	str = "<input type='text' "
		+ "  name='"+voucherName+"_"+item.name+rowid+"'"
		+ "  class='"+vcss+"' "
		+ "  rowid='" + rowid +"'"
		+ "  caption='" + item.caption+"'"
		+ "  value='"+value+"'"
		+ "  style='width:100%' " 
		+ " "
		+ widthStr
		+ " "
		+ "  onblur=\"orderFieldBlur('"+item.name+rowid+ "'); touchOnblur(this);\"" 
		+ " "
		+ eventStr
	    + " "
		+ readonly
		+ ">" ;
	return str
}

function getInputForString(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){	
	//alert(vcss+"||"+readonly);
		
	str = "<input type='text' "
		+ " name='"+voucherName+"_"+item.name+rowid+"'"
		+ " class='"+vcss+"' "
		+ " rowid='" + rowid +"'"
		+ " caption='" + item.caption+"'"
		+ " value='"+value+"'"
		+ " style='width:100%' " 
		+ " "
		+ widthStr
		+ " "
		+ "  onblur=\"javaScript: touchOnblur(this);\""
		+ " "
		+ eventStr
		+ " "
	  + readonly
		+">" ;
	
	return str;
}

function getInputForImg(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){	

	str = "<a target='_blank' href='"
		+ value
		+"'"
		+ " name='"+voucherName+"_"+item.name+rowid+"'"
		+ " class='"+vcss+"' "
		+ " rowid='" + rowid +"'"
		+ " caption='" + item.caption+"'"
		+ " value='"+value+"'"
		+ " style='width:100%' " 
		+ " "
		+ widthStr
		+ " "
		+ "  onblur=\"javaScript: touchOnblur(this);\""
		+ " "
		+ eventStr
		+ " "
		+">"
		+ value
		+"</a>";
	
	return str;
}

function getInputForFile(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly){
	str = "<input type='file' "
		+ " name='"+voucherName+"_"+item.name+rowid+"'"
		+ "  class='"+vcss+"' "
		+ "  rowid='" + rowid +"'"
		+ "  caption='" + item.caption+"'"
		+ "  value='"+value+"'"
		+ "  style='width:100%' " 
		+ " "
		+ widthStr
		+ " "
		+ "  onblur=\"javaScript: touchOnblur(this);\""
		+ " "
		+ eventStr
		+ " "
      	+ readonly
		+">" ;
		
	return str;
}
var _g_dt_imgCBB = "/js/dateControl/images/cbb_drop.gif";//使用
function getInputForDate(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly) {
	curDate = new Date();

	year = curDate.getYear();
	month  = curDate.getMonth()+1;
	day = curDate.getDate(); //
	str = "<div id='div_dt_main_" + item.name+rowid + "' style='position:relative;'>"
	    + " <input type='text' id='" + item.name+rowid + "' name='" 
	    + voucherName+"_"+item.name+rowid + "' "					
	    + " isDTPicker=true "
        + " onblur=\"javascript:_dt_check('" + item.name+rowid + "');\" "
        + " value='" + year + "-" + (month < 10 ? "0" + month : month) + "-" 
        + (day < 10 ? "0" + day : day) + "' size='12' >" 
        + " <img id='dt_cbbdrop_" + item.name+rowid + "' src='" + _g_dt_imgCBB 
        + " ' border='0' width='16' height='17' "
        + " onclick=\"javascript:_dt_showDTTable('" + item.name+rowid + "'); touchOnClick(this);\" "
        + " style='margin: -2, -24' >"
	    + " </div><div id='div_dtTable_" + item.name+rowid + "' "
	    + " style='position:absolute; visibility:hidden; left:0; top:22; z-index:2'></div>";
	return str;
}

function getInputForText(voucherName,item,rowid,vcss,widthStr,eventStr,readonly){
	str = "<input type='textarea' "
		+ "  name='"+voucherName+"_"+item.name+rowid+"'"
		+ "  class='"+vcss+"' "
		+ "  rowid='" + rowid +"'"
		+ "  caption='" + item.caption+"'"
		+ "  value='"+getControlInit(item)+"'"
		+ "  style='width:100%'" 
		+ "  onblur=\"javaScript: touchOnblur(this);\""
		+ " "
		+ eventStr
	    + " "
        + readonly
		+">" ;
	return str;
}

function getInputForButton(voucherName,item,value,rowid,vcss,widthStr,eventStr,readonly) {	
   str = "<input type='BUTTON' "
       + "  name='"+voucherName+"_"+item.name+rowid+"'"
       + "  class='button'"
	   + "  value='" + item.caption+"'"
       + "  rowid='" + rowid +"'"
	   + "  onclick='javaScript: voucherButtonOnclick(this);'"
       + " "	
	   +">" ;
	   
   return str;
}
function getSelectControl(item,maxrowid,widthStr,vcss,eventStr,readonly,optionStr,value,voucherName){
	
	var selectModeStr = "";
	 var str="";	 
	
	 str += selectModeStr+ "<select name='"+ voucherName +"_"+ item.name+ maxrowid
	 	 + "' rowid='"+ maxrowid+ "' "+ widthStr+ " class='"+ vcss
		 + "' caption='"+ item.caption+ "' "+ eventStr+ " "+ readonly+ ">";
     str += "<option value=''> 请选择 </option> ";

	 if(optionStr!="#-#" && value!="")	
	    {str+=_getMapStr(optionStr,value);	   
	 }
	 else if (optionStr!="#-#")
        {str+=optionStr;}	
		str +="</select>";	
	 return str;
}
//**********************************************
function _getMapStr(_optionStr, _curFieldValue) {
	//直接赋予<option/>不成功，需要解析后生成option
	
	var _curValue  = "";
	var _curText   = "";
	var pos = 0;
	var _selectLength = 0;
	var _returnOptionStr = _optionStr;
	while(_optionStr.indexOf("<option") != -1) {		
		pos = _optionStr.indexOf("<option value='");
		_optionStr = _optionStr.substring(15);
		_curValue = _optionStr.substring(0, _optionStr.indexOf("'"));
		pos = _optionStr.indexOf("</option>");
		_curText  = _optionStr.substring(_optionStr.indexOf(">")+1 , pos);		
		if(_curValue == _curFieldValue) {
			pos = _optionStr.indexOf("\'");
			
			_returnOptionStr = _returnOptionStr.substring(0, _returnOptionStr.indexOf(_optionStr)) 
						+ _optionStr.substring(0, pos+1) 
						+ " selected "
						+ _optionStr.substring(pos+1);						
			return _returnOptionStr;
			break;
		}				
		if(_curText.length*25 > _selectLength) {
			_selectLength = _curText.length*25;
		}		
		_optionStr = _optionStr.substring(pos+9);	
	}
}


/**********************************************************************************************

根据子表vo的名称或取子表中映射的键值对，得到的结果为key$$value; 例：13$$黎明；

***********************************************************************************************/


function getVoucherMapingName(curVoucherName){
	var str="";
	//以下获取配置对象。
	var tempName = curVoucherName;
	while(tempName.indexOf('$')!=-1){
			tempName = tempName.replace('$','.');
		}	

	var VOITEMS = parent.getVOITEMS(tempName);

	if(VOITEMS==null) {
			alert("没有配置:"+tempName);
			return;
		}
	//取列表中的当前记录
	var CURRENTKEY = parent.getCurrentKey();	

	var vouchers = parent.getVOUCHERSByKey(curVoucherName,CURRENTKEY);	

			for(var i = 0; i < vouchers.length; i++) {

						var voucher = vouchers[i];
						
                       str+=makeRecord(VOITEMS, voucher.childBeanArray);
			}

    return str;

}

function makeRecord(VOITEMS, _curBeanArray){
	var str="";
		for(var i = 0; i < VOITEMS.length; i++) {
		    var item = VOITEMS[i];
            for(var j = 0; j < _curBeanArray.length; j++) {
				var _curBean = _curBeanArray[j];
				//名称相符
				if(_curBean != null && _curBean[0] == item.name) {
				   if(item.isListItem=="false") continue;
				   if(item.isListItem!="true" && item.isListItem.indexOf("edit")==-1) continue;
				      //根据类型进行构造
                     
				      str+=getMaping(item, _curBean);
				}
		    }
		}
		return str;
}

function getMaping(item, _curBean){	
	var str = "";
	var value = _curBean[1];
	optionStr = item.optionStr;	
	 if(optionStr!="#-#" && value!="")	
	    {str+=getMapingValue(optionStr,value);	   
	 }
   
	return str;
}

function getMapingValue(_optionStr, _curFieldValue){
    var _curValue  = "";
	var _curText   = "";
	var pos = 0;
	var _selectLength = 0;
	var _returnOptionStr = "";
    
	while(_optionStr.indexOf("<option") != -1) {		
		pos = _optionStr.indexOf("<option value='");
		_optionStr = _optionStr.substring(15);
		_curValue = _optionStr.substring(0, _optionStr.indexOf("'"));
		pos = _optionStr.indexOf("</option>");
		_curText  = _optionStr.substring(_optionStr.indexOf(">")+1 , pos);		
		if(_curValue == _curFieldValue) {
			pos = _optionStr.indexOf("\'");
			
			_returnOptionStr = _curValue+"$$"+_curText+";";		
			
			return _returnOptionStr;
			break;
		}				
		if(_curText.length*25 > _selectLength) {
			_selectLength = _curText.length*25;
		}		
		_optionStr = _optionStr.substring(pos+9);	
	}
}


//------------------------------------------------------/
// 格式化小数,保留位数
// 参数： value:要格式化的数
//		  currPrec保留小数位数
// 返回： 格式化后的数	
//------------------------------------------------------/
function formatFloatBit(value,currPrec){

	if(value==""||isNaN(value)){
			value=0;
		}
	var tempBit=1;
	for(i=0;i<currPrec;i++){
		tempBit=tempBit*10;
	}
	var value1=Math.round(value*tempBit);
	var valueTempT=value1+"";
	var valueTemp=valueTempT.substring(0,valueTempT.length-currPrec)+"."+valueTempT.substring(valueTempT.length-currPrec,valueTempT.length);
	if(value==0){
		valueTempT="";
			for(i=0;i<currPrec;i++){
				valueTempT=valueTempT+"0";
			}
		valueTemp="0."+valueTempT;
	}
	if(valueTemp.substring(0,1)=="."||valueTemp.substring(0,2)=="-."){
		valueTemp=valueTemp.substring(0,valueTemp.indexOf("."))+"0"+valueTemp.substring(valueTemp.indexOf("."));
	}
	return valueTemp
}