function uf_SetListRowBGColor(aobj_Tr, ai_Row)
{
	var ls_Color = "";
	if (aobj_Tr == null) return;
	
	if (ai_Row % 2 == 0) 
		ls_Color = "#FFFFFF";
	else
		ls_Color = "#EAEAEA";
	
	aobj_Tr.style.background = ls_Color;	
}

//显示模态对话框，x,y为窗口左上坐标，w，h为窗口高和宽
function uf_ShowModalDialog(as_URL,ai_Width,ai_Height, aobj_Arguments){
	var li_X =(screen.width-ai_Width)/2;
	var li_Y =(screen.height-ai_Height)/2;
	
	if (aobj_Arguments == null) aobj_Arguments = "";
	
	return window.showModalDialog(as_URL, aobj_Arguments, "dialogHeight:"+ai_Height+"px;dialogWidth:"+ai_Width+"px;dialogTop:"+li_Y+"px;dialogLeft:"+li_X+"px;status:no;scroll:off");
}

function uf_ShowModelessDialog(as_URL,ai_Width,ai_Height, aobj_Arguments){
	var li_X =(screen.width-ai_Width)/2;
	var li_Y =(screen.height-ai_Height)/2;
	
	if (aobj_Arguments == null) aobj_Arguments = "";
	
	return window.showModelessDialog(as_URL, aobj_Arguments, "dialogHeight:"+ai_Height+"px;dialogWidth:"+ai_Width+"px;dialogTop:"+li_Y+"px;dialogLeft:"+li_X+"px;status:no;scroll:off");
}

function uf_OpenWindow(as_URL,ai_Width,ai_Height, aobj_Arguments){
	var li_X =(screen.width-ai_Width)/2;
	var li_Y =(screen.height-ai_Height)/2;

	if (aobj_Arguments == null) aobj_Arguments = "";	
	return window.open(as_URL,aobj_Arguments,"width="+ai_Width+",height="+ai_Height+",directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,fullscreen=no,left="+li_X+",top=" + li_Y);
}


function uf_SetFocus(as_ObjName){
	// 设置对象焦点
	var lobj_O = eval("document.all."+as_ObjName);
	if (lobj_O != null) lobj_O.focus();	
}

function trim(as_Str){ 
	if (as_Str == null) return "";
	return(as_Str.replace(/^\s*/,"").replace(/\s*$/,""));
} 


////Records类开始///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is a class
function Records(as_RecordsString){
	//properties
	this.is_RecordsString = "";
	this.iarrs_Records = new Array;
	
	this.RECORD_BEGIN = "<RECORD>";
	this.RECORD_END = "</RECORD>";
		
	//method
	this.setRecordsString = setRecordsString;
	this.getRecordsString = getRecordsString;
	this.getRecordCount = getRecordCount;
	this.getFieldValue = getFieldValue;
	this.addRecordString = addRecordString;
		
	//初始化
	this.setRecordsString(as_RecordsString);
}	

function setRecordsString(as_String){	
	var ls_Records, ls_Record;
	var i;
	var li_Pos_RecBegin, li_Pos_RecEnd;
	
	if (as_String == null) as_String = "";
	if (as_String == "") return;
	
	this.is_RecordsString = as_String;
	ls_Records = as_String;
	
	//将ls_Records分割，并放入iarrs_Records
	li_Pos_RecBegin = 0;
	i = -1;	
	while (ls_Records.indexOf(this.RECORD_BEGIN,li_Pos_RecBegin) >= 0)
		{
			//get the beginning and end of the record
			li_Pos_RecBegin = ls_Records.indexOf(this.RECORD_BEGIN,li_Pos_RecBegin);
			li_Pos_RecEnd   = ls_Records.indexOf(this.RECORD_END,li_Pos_RecBegin) + this.RECORD_END.length;
			
			ls_Record = ls_Records.substring(li_Pos_RecBegin,li_Pos_RecEnd);
			
			i ++;
			this.iarrs_Records[i] = ls_Record;
										
			li_Pos_RecBegin = li_Pos_RecEnd ;			
		}
	
}

function getRecordsString(){
	var ls_Return = "";
	
	for (var i= 0; i < this.getRecordCount(); i ++)
		{	ls_Return += this.iarrs_Records[i];
		}
	
	return ls_Return;
}

function getRecordCount(){	
	if (this.iarrs_Records == null) return 0;
	return this.iarrs_Records.length;	
}

function getFieldValue(ai_Row, as_FieldName){
	var ls_Rec = "";
	 
	if (ai_Row > this.getRecordCount() || ai_Row <= 0)
		{	alert("Records.getFieldValue(): ai_Row is out of range");
			return "";
		}
	ls_Rec = this.iarrs_Records[ai_Row -1];
	
	var lrec_R = new Record(ls_Rec);
	return lrec_R.getFieldValue(as_FieldName);	
	
}

function addRecordString(as_Record){
	if (as_Record == null || as_Record == "")
		{	alert("Records.addRecord(): as_Record is empty");
			return;
		}
	this.iarrs_Records[this.iarrs_Records.length] = as_Record;	
}
function formatNumber(number,pattern)
	{
		var str			= number.toString();
		var strInt;
		var strFloat;
		var formatInt;
		var formatFloat;
		if(/\./g.test(pattern))
		{
			formatInt		= pattern.split('.')[0];
			formatFloat		= pattern.split('.')[1];
		}
		else
		{
			formatInt		= pattern;
			formatFloat		= null;
		}

		if(/\./g.test(str))
		{
			if(formatFloat!=null)
			{
				var tempFloat	= Math.round(parseFloat('0.'+str.split('.')[1])*Math.pow(10,formatFloat.length))/Math.pow(10,formatFloat.length);
				strInt		= (Math.floor(number)+Math.floor(tempFloat)).toString();				
				strFloat	= /\./g.test(tempFloat.toString())?tempFloat.toString().split('.')[1]:'0';			
			}
			else
			{
				strInt		= Math.round(number).toString();
				strFloat	= '0';
			}
		}
		else
		{
			strInt		= str;
			strFloat	= '0';
		}
		if(formatInt!=null)
		{
			var outputInt	= '';
			var zero		= formatInt.match(/0*$/)[0].length;
			var comma		= null;
			if(/,/g.test(formatInt))
			{
				comma		= formatInt.match(/,[^,]*/)[0].length-1;
			}
			var newReg		= new RegExp('(\\d{'+comma+'})','g');

			if(strInt.length<zero)
			{
				outputInt		= new Array(zero+1).join('0')+strInt;
				outputInt		= outputInt.substr(outputInt.length-zero,zero)
			}
			else
			{
				outputInt		= strInt;
			}

			var 
			outputInt			= outputInt.substr(0,outputInt.length%comma)+outputInt.substring(outputInt.length%comma).replace(newReg,(comma!=null?',':'')+'$1')
			outputInt			= outputInt.replace(/^,/,'');

			strInt	= outputInt;
		}

		if(formatFloat!=null)
		{
			var outputFloat	= '';
			var zero		= formatFloat.match(/^0*/)[0].length;

			if(strFloat.length<zero)
			{
				outputFloat		= strFloat+new Array(zero+1).join('0');
				//outputFloat		= outputFloat.substring(0,formatFloat.length);
				var outputFloat1	= outputFloat.substring(0,zero);
				var outputFloat2	= outputFloat.substring(zero,formatFloat.length);
				outputFloat		= outputFloat1+outputFloat2.replace(/0*$/,'');
			}
			else
			{
				outputFloat		= strFloat.substring(0,formatFloat.length);
			}

			strFloat	= outputFloat;
		}
		else
		{
			if(pattern!='' || (pattern=='' && strFloat=='0'))
			{
				strFloat	= '';
			}
		}

		return strInt+(strFloat==''?'':'.'+strFloat);
	}

////Records类结束///////////////////////////////////////////////////////////////////////////////////////////////////////////////////


////Record类开始///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is a class
function Record(as_RecString){
	//properties
	this.is_RecString = as_RecString;
		
	//method
	this.setRecordString = setRecordString;
	this.getRecordString = getRecordString;	
	this.getFieldValue = getRecFieldValue;
}	

function setRecordString(as_String){
	if (as_String == null) as_String = "";
	this.is_RecString = as_String;
}

function getRecordString(){
	return this.is_RecString;
}

function getRecFieldValue(as_FieldName){
	var ls_Rec = "",ls_RecString,ls_Field,ls_Name,ls_Value = "";
	var li_Row,li_Pos, li_Pos_FBegin,li_Pos_FEnd;
	var li_Pos_NameBegin,li_Pos_NameEnd, li_Pos_ValueBegin,li_Pos_ValueEnd ;
	var FIELD_BEGIN ="<FIELD>", FIELD_END="</FIELD>";
	var NAME_BEGIN ="<NAME>", NAME_END="</NAME>",VALUE_BEGIN="<VALUE>",VALUE_END="</VALUE>";
	
	ls_Rec = this.is_RecString;
	
	//search each field
	li_Pos_FBegin = 0;
	while (ls_Rec.indexOf(FIELD_BEGIN,li_Pos_FBegin) >= 0)
		{
			//get the beginning and end of the field
			li_Pos_FBegin = ls_Rec.indexOf(FIELD_BEGIN,li_Pos_FBegin);
			li_Pos_FEnd   = ls_Rec.indexOf(FIELD_END,li_Pos_FBegin) + FIELD_END.length;
			
			ls_Field = ls_Rec.substring(li_Pos_FBegin,li_Pos_FEnd);
			
			//get the name
			li_Pos_NameBegin = ls_Field.indexOf(NAME_BEGIN) + NAME_BEGIN.length;
			li_Pos_NameEnd   = ls_Field.indexOf(NAME_END);
			ls_Name = ls_Field.substring(li_Pos_NameBegin,li_Pos_NameEnd);
			 
			if (ls_Name == as_FieldName) 
				{	li_Pos_ValueBegin = ls_Field.indexOf(VALUE_BEGIN) + VALUE_BEGIN.length;
					li_Pos_ValueEnd   = ls_Field.indexOf(VALUE_END);
					ls_Value = ls_Field.substring(li_Pos_ValueBegin,li_Pos_ValueEnd);
					break;
				}
				
			li_Pos_FBegin = li_Pos_FEnd ;			
		}
	
	
	return ls_Value;
}
////Record类结束///////////////////////////////////////////////////////