/************************************************
添加新功能的步骤：
0. 在enumdefine.js中加入对应项
1. 在key.js中加入key植;
2. 在language.js中加入对应的language
3. 在fielddefaultvalue.js中加入对应的defaultvalue
4. 在init.js中加入初始化项目
5. 在common.js中更改对应的函数
6. 更改multisingleedit.js
7. 更改menubar.js的location
8. 在server上的query.xml中加入对应项, 重起server的iis.
* 在工程中查询汉字方法："[^\u1-\u127]"
*///************************************************


//Begin==========================================功能描述：增加记录=================================================
var bugchars = '!#$^&*()+|}{[]?><~%:;/,=`"\'';
function Add(pvsflexGrid, pobjModifyColor, pIsAllowEdit, pIsAutoSize, pobjASPXValue)
{
	if (pIsAllowEdit == false){return;}
	with (pvsflexGrid)
	{
		AddItem("");
		
		AddRecordInit(pvsflexGrid, Rows - 1, pobjASPXValue);
		//SelectionMode = flexSelectionFree;
		SelectionMode = 3;
		Row = Rows - 1;
		Col = FixedCols;
		focus();
		ScrollTrack = true;
		Cell(ModifyColorStyle, Row, FixedCols, Row, Cols - 1) = pobjModifyColor.InsertColor;
		
		if (pIsAutoSize == true)
		{
			AutoSize (1, Cols-1);
		}
		Sequence(pvsflexGrid,"Sequence","");
	}
}
//End==========================================功能描述：增加记录=================================================

//Begin==========================================Get Value from recordset with keyValue=================================================
function GetValueWithKey(pfmRecordset, pKey, pKeyValue, pReturnKey, pIsEmptyToNull)
{
	var rtValue;
	if (pfmRecordset == null || pKeyValue == "" || pKeyValue == null) 
	{
		if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
		{
			return "";
		}
		else
		{
			return "{00000000-0000-0000-0000-000000000000}";//null;
		}
	}
	with (pfmRecordset)
	{
		//debugger;
		aFilter=pKey + " = \'" + pKeyValue.replace(/'/g, "''") + "\'";
		Filter = aFilter;
		
		//if (State == adStateClosed){Open();}
		if (BOF && EOF)
		{
			Filter="";
			if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
			{
				return "";				
			}
			else
			{
				return "{00000000-0000-0000-0000-000000000000}";//null;
			}
		}
		MoveFirst();
		rtValue = Fields(pReturnKey).Value;
		Filter="";
		return rtValue;
	}
}

function GetValueWith3Keys(pfmRecordset, pKey1, pKeyValue1,pKey2, pKeyValue2, pKey3, pKeyValue3,pReturnKey, pIsEmptyToNull)
{
	if (pfmRecordset == null || pKeyValue1 == "" || pKeyValue1 == null) 
	{
		if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
		{
			return "";
		}
		else
		{
			return "{00000000-0000-0000-0000-000000000000}";//null;
		}
	}
	with (pfmRecordset)
	{
		Filter = pKey1 + " = '" + pKeyValue1 + "' and " + pKey2 + " = '" + pKeyValue2 + "' and " +pKey3 + " = '" + pKeyValue3 + "'";
		
		//if (State == adStateClosed){Open();}
		if (BOF && EOF)
		{
			if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
			{
				return "";				
			}
			else
			{
				return "{00000000-0000-0000-0000-000000000000}";//null;
			}
		}
		MoveFirst();
		return Fields(pReturnKey).Value;
	}
}

//End==========================================Get Value from recordset with keyValue=================================================

//Begin==========================================功能描述：Get Value from recordset with keyValue=================================================
function GetRowObjValueWithKey(pfmRecordset, pKey, pKeyValue,  pIsEmptyToNull)
{
	if (pfmRecordset == null || pKeyValue == "" || pKeyValue == null) 
	{
		if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
		{
			return "";
		}
		else
		{
			return "{00000000-0000-0000-0000-000000000000}";//null;
		}
	}
	with (pfmRecordset)
	{
		Filter = pKey + " = '" + pKeyValue + "'";
		
		//if (State == adStateClosed){Open();}
		if (BOF && EOF)
		{
			if (pIsEmptyToNull == undefined || pIsEmptyToNull == false)
			{
				return "";				
			}
			else
			{
				return "{00000000-0000-0000-0000-000000000000}";//null;
			}
		}
		MoveFirst();
		returnobj	= new Object();
		for( var i = 0; i < Fields.Count; i++)
		{
			returnobj[Fields(i).Name]		= Fields(i).value;
		}
		return returnobj;
	}
}
//End==========================================功能描述：Get Value from recordset with keyValue=================================================



//Begin==========================================功能描述：快捷键=================================================
var ShortCutHeadKey_Alt;
var ShortCutHeadKey_Ctrl;
var ShortCutHeadKey_Shift;

function ShortCutHeadKey_SetValue(pValue)
{		 
	ShortCutHeadKey_Alt = pValue;
    ShortCutHeadKey_Ctrl = pValue;
    ShortCutHeadKey_Shift = pValue;    
}

function Set_Alt_Ctrl_Shift(pwindow_event_keyCode, pValue, pType)
{
	if (pType == 0)
	{
		switch (pwindow_event_keyCode)
		{	    
		case (18): //Alt
			ShortCutHeadKey_SetValue(0);
			ShortCutHeadKey_Alt = pValue;
			break;
		case (17): //Ctrl 
			ShortCutHeadKey_SetValue(0);
			ShortCutHeadKey_Ctrl = pValue;
			break;
		case (16): //Shift
			ShortCutHeadKey_SetValue(0);
			ShortCutHeadKey_Shift = pValue;
			break;
		default:
		}
	}	
	else if (pType == 1)
	{
		switch (pwindow_event_keyCode)
		{	    
		case (18): //Alt
			ShortCutHeadKey_Alt = pValue;
			break;
		case (17): //Ctrl 
			ShortCutHeadKey_Ctrl = pValue;
			break;
		case (16): //Shift
			ShortCutHeadKey_Shift =pValue;
			break;
		default:
		}
	}
}
  
function AltUp() {	
	if (window.event.keyCode == 16 || window.event.keyCode == 17 || window.event.keyCode == 18)
	{		
		Set_Alt_Ctrl_Shift(window.event.keyCode, 0, 1);
		//window.alert(ShortCutHeadKey_Alt);
	}	
}

function IsShortCutValid(window_event_keyCode, pShortCutHeadKey, pKeyCode)
{	
	var ResultValue
	
	ResultValue = 0;
	if (pShortCutHeadKey == 1)
	{
		if (window_event_keyCode == pKeyCode)
		{				
			ResultValue = 1;
		}
	}
	return(ResultValue);
}
//End==========================================功能描述：快捷键=================================================

//Begin==========================================功能描述：让控件得到焦点=================================================
function SetFocus(pObject)
{	
	if (pObject.disabled == false)
	{
		pObject.focus();
	}
}
//End==========================================功能描述：让控件得到焦点=================================================

//Begin==========================================功能描述：网格取序=================================================
//Refresh a refered col of VsFlexGrid
//pstrColIndexSequence:ColIndex for "Sequence"
//pstrColIndexTotal:colIndex for "Total"
function Sequence(pVsFlexGrid, pstrColIndexSequence, pstrColIndexTotal)
{  
  var SortRow 
  var lngIndex 
  var arrayTextMatrix = new Array();
  var FoundRow 
  var arrayForColor= new Array();
  var strTotal = "T O T A L";
  
  with (pVsFlexGrid)
  {
    if (Rows <= FixedRows) return;
    //move "Total" to last
    if (pstrColIndexTotal != "")
    {
      FoundRow = FindRow(strTotal,FixedRows, ColIndex(pstrColIndexTotal));
      if (FoundRow > 0)
      {
        for (lngIndex = 1; lngIndex<= Cols - 1; lngIndex++)
        {
          arrayTextMatrix(lngIndex) = TextMatrix(FoundRow, lngIndex);
          arrayForColor(lngIndex) = Cell(flexcpForeColor, FoundRow, lngIndex);
        }
        RemoveItem (FoundRow);
        AddItem ("");
        for (lngIndex = 1; lngIndex <= Cols - 1; lngIndex++)
        {
          TextMatrix(Rows - 1, lngIndex) = arrayTextMatrix(lngIndex);
          Cell(flexcpBackColor, Rows - 1, lngIndex) = QBColor(7);
          if (lngIndex = ColIndex(pstrColIndexTotal))
          {
            Cell(flexcpForeColor, Rows - 1, lngIndex) = vbBlue;
          }
          else
          {
            Cell(flexcpForeColor, Rows - 1, lngIndex) = arrayForColor(lngIndex);
          }
        }
      }
    }
    
    //Add Sequence No.
    SortRow = 1;
    for (lngIndex = FixedRows; lngIndex <= Rows - 1;lngIndex++)
    {
      if (RowHidden(lngIndex) == false)
      {
        TextMatrix(lngIndex, ColIndex(pstrColIndexSequence)) = SortRow;
        SortRow = SortRow + 1;
      }      
    }
    if (FoundRow > 0)
    {
		TextMatrix(Rows - 1, ColIndex(pstrColIndexSequence)) = "";
	}
  }
}
//End==========================================功能描述：网格取序=================================================

//Begin==========================================功能描述：在网格上移动记录指针=================================================
function Move(pvsflexGrid, pDirection)
{				
	with (pvsflexGrid)
	{
		if (Rows <= FixedRows){return;}
		switch (pDirection)
		{
			case objMove.MoveFirst:
				Row = FixedRows;
				break;
			case objMove.MovePrevious:
				if (Row != FixedRows && Rows != FixedRows)
				{
					Row = Row - 1;
				}
				break;
			case objMove.MoveNext:
				if (Row != Rows - 1)
				{
					Row = Row + 1;
				}
				break;
			case objMove.Last:
				Row = Rows - 1;
				break;
			default:						
				break;
		}
	}
}
//End==========================================功能描述：在网格上移动记录指针=================================================

//Begin==========================================功能描述：删除网格记录--加入删除标志=================================================
function Delete(pvsflexGrid, pIsConfirm, pobjModifyColor, pIsAllowEdit, pIsAutoSize)
{
	var IsAllowDelete
	
	if (pIsAllowEdit == false){return;}
	
	IsAllowDelete = true;
	if (pIsConfirm == true)
	{ 
		if (window.confirm(strConfirmDelete) == false)
		{
			IsAllowDelete = false;
		}				
	}
	
	if (IsAllowDelete == true)
	{
		with (pvsflexGrid)
		{
			for (var lngRowIndex = SelectedRows - 1; lngRowIndex >=0; lngRowIndex--)
			{
				if (SelectedRow(lngRowIndex) >= FixedRows)
				{
					if (Cell(ModifyColorStyle, SelectedRow(lngRowIndex), FixedCols, SelectedRow(lngRowIndex), Cols - 1) == pobjModifyColor.InsertColor)
					{
						RemoveItem(SelectedRow(lngRowIndex));
					}
					else
					{
						Cell(ModifyColorStyle, SelectedRow(lngRowIndex), FixedCols, SelectedRow(lngRowIndex), Cols - 1) = pobjModifyColor.DeleteColor;
					}
				}
			}
			if (pIsAutoSize == true)
			{
				AutoSize (1, Cols-1);
			}
		}
		Sequence(pvsflexGrid,"Sequence","");
	}
}
//End==========================================功能描述：删除网格记录--加入删除标志=================================================

//Begin==========================================功能描述：恢复网格记录--加入NoChange标志=================================================
function Undelete(pvsflexGrid, pobjModifyColor, pIsAllowEdit)
{
	if (IsAllowEdit == false){return;}
	with (pvsflexGrid)
	{
		for (var lngRowIndex = SelectedRows - 1; lngRowIndex >=0; lngRowIndex--)
		{
			if (SelectedRow(lngRowIndex) >= FixedRows)
			{
				if (Cell(ModifyColorStyle, SelectedRow(lngRowIndex), FixedCols, SelectedRow(lngRowIndex), Cols - 1) == pobjModifyColor.DeleteColor)
				{
					Cell(ModifyColorStyle, SelectedRow(lngRowIndex), FixedCols, SelectedRow(lngRowIndex), Cols - 1) = pobjModifyColor.NoChangeColor;
				}
			}
		}
	}
	Sequence(pvsflexGrid,"Sequence","");
}
//End==========================================功能描述：恢复网格记录--加入NoChange标志=================================================

//Begin==========================================功能描述：删除Recordset单条记录=================================================
function DeleteRecord(pRecordset, pIsDeleteAllRecord, pPrimaryKey, pPrimaryKeyValue)
{
	with (pRecordset)
	{
		if (pIsDeleteAllRecord == false)
		{
			Filter = pPrimaryKey + " = '" + pPrimaryKeyValue + "'";
		}
		else
		{
			Filter = adFilterNone;
		}
		if (!(BOF && EOF)){MoveFirst;}
		while (!EOF)
		{
			Delete();
			MoveNext;
		}							
	}
}
//End==========================================功能描述：删除Recordset单条记录=================================================

//Begin==========================================功能描述：网格AfterEdit事件模块--对于多记录编辑网格与单记录编辑网格的相互编辑=================================================
function AfterEditForMultiAndSingleGrid(pvsflexGridEdit_Source, pvsflexGridEdit_Destination, pIsMultiToSingle, pobjModifyColor)
{	
	var CurrentCol = 1;
	
	with (pvsflexGridEdit_Destination)
	{
		if (pIsMultiToSingle == true)
		{
			if (pvsflexGridEdit_Source.Col < pvsflexGridEdit_Source.FixedCols){return;}
			for (var lngRow = FixedRows; lngRow <= Rows - 1; lngRow++)
			{
				if (RowData(lngRow).toUpperCase() == pvsflexGridEdit_Source.ColKey(pvsflexGridEdit_Source.Col).toUpperCase())
				{
					TextMatrix(lngRow, CurrentCol) = pvsflexGridEdit_Source.Cell(flexcpTextDisplay, pvsflexGridEdit_Source.Row, pvsflexGridEdit_Source.Col);
					break;
				}
			}
		}
		else
		{
			if (pvsflexGridEdit_Source.Row < pvsflexGridEdit_Source.FixedRows){return;}
			TextMatrix(Row, ColIndex(pvsflexGridEdit_Source.RowData(pvsflexGridEdit_Source.Row))) = pvsflexGridEdit_Source.Cell(flexcpTextDisplay, pvsflexGridEdit_Source.Row, CurrentCol);
			
			if (Cell(ModifyColorStyle, Row, FixedCols, Row, Cols - 1) == pobjModifyColor.NoChangedColor)
			{
				Cell(ModifyColorStyle, Row, FixedCols, Row, Cols - 1) = pobjModifyColor.UpdateColor;
			}
			Cell(flexcpFontBold, Row, ColIndex(pvsflexGridEdit_Source.RowData(pvsflexGridEdit_Source.Row))) = true;
		}
	}	
}
//End==========================================功能描述：网格AfterEdit事件模块--对于多记录编辑网格与单记录编辑网格的相互编辑=================================================

//Begin==========================================功能描述：从记录集中填充网格，分为增加（修改）和删除，删除行为只能单行删除记录=================================================
function FillGrid(pRecordset, pvsflexGrid, pIsReloadAll, pPrimaryKey, pPrimaryKeyValue, pFilter, pIsInsertHead, pIsDelete, pobjModifyColor, pIsAutoSize, pobjHTML, pHTML , pobjKey, prstComboList, poRelation, oConst, IsAddInsertFlag)
{
	var FoundRow;
	var InsertRow;

	
	//删除
	with (pvsflexGrid)
	{	
		if (pIsReloadAll == false && pIsDelete == true)
		{
			FoundRow = FindRow(pPrimaryKeyValue, FixedRows, ColIndex(pPrimaryKey));
			if (FoundRow > 0)
			{
				RemoveItem(FoundRow);
			}	
			if (pIsAutoSize == true)
			{
				AutoSize (1, Cols-1);
			}
			Sequence(pvsflexGrid,"Sequence","");
			return;
		}
	}
	
	//增加（修改）
	if (pRecordset == null){return;}
	with (pvsflexGrid)
	{	
		pRecordset.Filter = pFilter;
		if (pIsReloadAll == true)
		{
			Rows = FixedRows;
		}
		if (!(pRecordset.BOF && pRecordset.EOF))
		{
			pRecordset.MoveFirst;
		}
		if (pIsReloadAll == true)
		{
			Rows = pRecordset.RecordCount + FixedRows;
			InsertRow = FixedRows-1;
		}
		while (!pRecordset.EOF)
		{
			if (pIsReloadAll == false)
			{
				FoundRow = FindRow(pPrimaryKeyValue, FixedRows, ColIndex(pPrimaryKey));
				if (FoundRow > 0)
				{
					InsertRow = FoundRow;
				}	
				else
				{
					if (pIsInsertHead == true)
					{			
						AddItem ("", FixedRows);
						InsertRow = FixedRows;
						if (IsAddInsertFlag == undefined)
						{
						
						}
						else if (IsAddInsertFlag == true)
						{
							Cell(ModifyColorStyle, InsertRow, FixedCols, InsertRow, Cols - 1) = pobjModifyColor.InsertColor;
						}
					}
					else
					{
						AddItem ("");
						InsertRow = Rows - 1;
						if (IsAddInsertFlag == undefined)
						{
						
						}
						else if (IsAddInsertFlag == true)
						{
							Cell(ModifyColorStyle, InsertRow, FixedCols, InsertRow, Cols - 1) = pobjModifyColor.InsertColor;
						}
					}
				}
			}
			else
			{				
				InsertRow = InsertRow + 1;
				Cell(ModifyColorStyle, InsertRow, FixedCols, InsertRow, Cols - 1) = pobjModifyColor.NoChangedColor;
			}
			FillSingleRecordToGrid(pobjHTML, pHTML, pRecordset, pvsflexGrid, InsertRow, pobjKey, prstComboList, poRelation, oConst);
			pRecordset.MoveNext();
		}
		if (pIsAutoSize == true)
		{
			AutoSize (1, Cols-1);
		}
	}
	Sequence(pvsflexGrid,"Sequence","");
}
//End==========================================功能描述：从记录集中填充网格，分为增加（修改）和删除，删除行为只能单行删除记录=================================================

//Begin==========================================功能描述：转换XML去记录集=================================================
function CastXMLToRecordset(pXMLStream)
{
	var ReturnRecordset = new ActiveXObject("ADODB.Recordset");
	
	ReturnRecordset.Open(pXMLStream);
	return ReturnRecordset;
}
//End==========================================功能描述：转换XML去记录集=================================================

//Begin==========================================功能描述：将待发送的记录集转换成DOMDocument并将没修改过的记录删除=================================================
function CastRecordsetToXML(pRecordset, pSelectName)
{
	var NodeNameData = "rs:data";
	var NodeNameRow = "z:row";
	var XMLStream = new ActiveXObject("MSXML2.DOMDocument");
	
	with (pRecordset)
	{
		Filter = adFilterNone;
		if (!(EOF && BOF)){
		MoveFirst;}
	}
	
	pRecordset.Save (XMLStream,adPersistXML);
	var childNode = XMLStream.documentElement.selectNodes(NodeNameData);
	for (var i = 0; i < childNode.length; i++)
	{
		var childNodeNext = childNode.item(i);
		for (var j = childNodeNext.childNodes.length - 1; j >= 0; j--)
		{
			if (childNodeNext.childNodes.item(j).nodeName.toUpperCase() == NodeNameRow.toUpperCase())
			{
				childNodeNext.removeChild(childNodeNext.childNodes.item(j));
			}
		}
	}
	
	var Root = "OmnicareRoot";
	var Leaf = "OmnicareLeaf";
	var CDATA = "<![CDATA[";
	var XML;

	XML = ("<" + Root + "><" + Leaf + " Source = '" + pSelectName + "'>" + CDATA + XMLStream.xml + "]]></" + Leaf + "></" + Root + ">");
	XML = XML.replace(/&quot;/g, "#dq#");
	XML = XML.replace(/&lt;/g, "#lt#");
	XML = XML.replace(/&gt;/g, "#gt#");
	XML = XML.replace(/</g, "&lt;");
	XML = XML.replace(/>/g, "&gt;");
	

//alert(XML);
	return (XML); 	
}
//End==========================================功能描述：将待发送的记录集转换成DOMDocument并将没修改过的记录删除=================================================

//Begin==========================================功能描述：取新的GUID=================================================
function CreateGUID()
{
	var objGUID = new ActiveXObject("WebTools.GUID");
	var NewGUID = objGUID.ToString(0x9);
	
	return "{" + NewGUID + "}";
}
//End==========================================功能描述：取新的GUID=================================================

//Begin==========================================功能描述：从服务器中传过来的XML的错误提示=================================================
function GetXMLErrorPrompt(result)
{
	var xfaultcode   = result.errorDetail.code;
	var xfaultstring = result.errorDetail.string;    
	var xfaultsoap   = result.errorDetail.raw;
	
	window.alert("ERROR. Method call failed! \n Fault Code:" + xfaultcode + "Fault String:" + xfaultstring + "SOAP Data:" + xfaultsoap);
}
//End==========================================功能描述：从服务器中传过来的XML的错误提示=================================================

function ErrorPromptForE(e)
{
	alert("Name: " + e.name + "\n Number: " + e.number + "\n Description: " + e. description + "\n Message: " + e.message);
}

//Begin==========================================功能描述：生成不同的XML=================================================
//del
function CreateXML(pRequestPageName, pXMLDetail)
{
	var str1 = "<RequestPage Name='" + pRequestPageName + "'>";
	str1 = str1.replace(/</g, "&lt;");
	str1 = str1.replace(/>/g, "&gt;");
	var str2 =  "</RequestPage>";
	str2 = str2.replace(/</g, "&lt;");
	str2 = str2.replace(/>/g, "&gt;");
	var XML =  str1 + pXMLDetail + str2;

	//XML = XML.replace(/</g, "&lt;");
	//XML = XML.replace(/>/g, "&gt;");
	return (XML);
}
//End==========================================功能描述：生成不同的XML=================================================
			
//Begin==========================================功能描述：生成不同的XML=================================================
//del
function CreateXMLDetail(pSelectName, pPageSize, pFilter)
{
	var str1 = "<Select Name='" + pSelectName + "' PageSize='"+ pPageSize +"' Filter=\"";
	str1 = str1.replace(/</g, "&lt;");
	str1 = str1.replace(/>/g, "&gt;");
	var str2 = "\" />";
	str2 = str2.replace(/</g, "&lt;");
	str2 = str2.replace(/>/g, "&gt;");
	
	
	pFilter	= CaseXMLGUIDNULLFormatToNull(pFilter);
	
	var Filter = pFilter.replace(/&/g,"#amp#");
	Filter= Filter.replace(/</g, "&amp;lt;");
	Filter= Filter.replace(/'/g,"&apos;&apos;");
	Filter= Filter.replace(/"/g,"#dq#");
	Filter= Filter.replace(/#apos#/g,"&apos;");
	
	
	
	var XMLDetail = str1 + Filter + str2;
	
	return (XMLDetail);
}
//End==========================================功能描述：生成不同的XML=================================================
//del
function CaseXMLGUIDNULLFormatToNull(pFilter)
{
	var indexofguid	= pFilter.indexOf("{00000000-0000-0000-0000-000000000000}") ;
	while(indexofguid != -1)
	{
		var substring	= pFilter.substring(0,indexofguid);
		var indexlast	= substring.lastIndexOf( "=" );
		if( indexlast != -1 )
		{
			var head = pFilter.substring(0, indexlast);
			head += " IS NULL ";
			head += pFilter.substring( indexofguid+38, pFilter.length-1);
			pFilter	= head;
		}
		else
		{
			break;
		}
		indexofguid	=  pFilter.indexOf("{00000000-0000-0000-0000-000000000000}") ;
	}
	return pFilter;
}

//Begin==========================================功能描述：Null GUID=================================================
function GetID(pStr)
{
	var ResultValue = pStr;
	
	if (pStr == "" )//|| pStr == "{00000000-0000-0000-0000-000000000000}")
	{
		ResultValue = "{00000000-0000-0000-0000-000000000000}";
	}
	return (ResultValue);
}
//End==========================================功能描述：Null GUID=================================================

//Begin==========================================功能描述：从服务器中取出XML并转换成Recordset=================================================
//Del
function GetRstFromXML(ResultValue)
{
	//debugger;
	var arrayRst = new Array();
	var objDoc = new ActiveXObject("Msxml2.DOMDocument");
	objDoc.async = false;
	objDoc.loadXML(ResultValue);
	var leafs = objDoc.getElementsByTagName("OmnicareLeaf");
	var objDoc2;
	
	for(var i = 0; i < leafs.length; i++)
	{
		arrayRst[i] = new ActiveXObject("ADODB.Recordset");

		objDoc2 = new ActiveXObject("Msxml2.DOMDocument");
		objDoc2.async = false;
		objDoc2.loadXML(leafs[i].text);
		arrayRst[i].Open(objDoc2);
	}
	return arrayRst;
}
//End==========================================功能描述：从服务器中取出XML并转换成Recordset=================================================

//Begin==========================================功能描述：从网格获取制定字段的内容=================================================
function GETCurrentValueWithKey(pvsflexGrid, pColKey, pIsCastNull)
{
	
	var ReturnValue = "";
	
	with (pvsflexGrid)
	{
		if (Row < FixedRows){return ReturnValue;}
		ReturnValue = TextMatrix(Row, ColIndex(pColKey));		
	}
	if ((pIsCastNull != undefined || pIsCastNull == true) && ReturnValue=="")
	{
		ReturnValue	= null;
	}
	return(ReturnValue);
}
//End==========================================功能描述：从网格获取制定字段的内容=================================================


function CastEmptytoNum(pValue)
{	
	var ReturnValue;
	if (pValue == "")
	{
		ReturnValue = 0;
	}	
	else
	{
		ReturnValue = (new Number(pValue)).valueOf();
	}
	return(ReturnValue);
}

function CastNulltoString(pValue)
{
	var ReturnValue = pValue;
	if (pValue == null)
	{
		ReturnValue = "";
	}
	else
	{
		if( !isNaN(pValue) )
		{
			ReturnValue = (new Number(pValue)).toString();
		}
	}	
	return(ReturnValue);
}

function CastNulltoNum(pValue)
{
	var ReturnValue;
	if (pValue == null)
	{
		ReturnValue = "0.00";
	}	
	else
	{
		if( !isNaN(pValue) )
		{
			ReturnValue = (new Number(pValue)).toString();
		}
	}
	return(ReturnValue);
}


//Begin==========================================功能描述：获取小数位个数=================================================
function getDecimalDigits(numberString)
{
	var decimaldigits = 0;
	if(numberString.indexOf(".") != -1)
		decimaldigits = numberString.length - numberString.indexOf(".") - 1;
	return decimaldigits;
}
//End==========================================功能描述：获取小数位个数=================================================

//Begin==========================================功能描述：将字符串格式化成制定的小数位数=================================================
function FormateNumberString(numberString, DecimalDigits)
{
	var endCharIndex = 0;
	var substr = numberString;
	if(numberString.indexOf(".") != -1)
	{
		endCharIndex = numberString.indexOf(".") + DecimalDigits + 1;
		substr = numberString.substring(0,endCharIndex);
	}
	return substr;
}
//End==========================================功能描述：将字符串格式化成制定的小数位数=================================================
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}


function GetCurrentDate(dayAdd)
{
   var d, s = ""; //Declare variables.
	
	d=addDays(new Date(),dayAdd); 
 //  d = new Date();                           //Create Date object.
//	d=d+dayAdd;
   	s = (d.getYear()) + "-";   
   	if ((d.getMonth()+1)>9)
   	{
		s += (d.getMonth()+1) + "-";    
	}
	else
	{
		s +="0" + (d.getMonth()+1) + "-";    
	}
	
	if (d.getDate()>9)
   	{
		s += d.getDate();
	}
	else
	{
		s +="0" + d.getDate();    
	}
	           
   return(s);                                //Return date.
}

function AddOneDay(DateIn)
{
   
   var fy,fm,fd;
	fy=DateIn.substring(0,4);
	fm=DateIn.substring(5,7);
	fd=DateIn.substring(8,10);
	
	var iDate,d, s = ""; //Declare variables.
	iDate= new Date(fy,fm-1,fd);
	d=addDays(iDate,1); 
 //  d = new Date();                           //Create Date object.
//	d=d+dayAdd;
   	s = (d.getYear()) + "-";   
   	if ((d.getMonth()+1)>9)
   	{
		s += (d.getMonth()+1) + "-";    
	}
	else
	{
		s +="0" + (d.getMonth()+1) + "-";    
	}
	
	if (d.getDate()>9)
   	{
		s += d.getDate();
	}
	else
	{
		s +="0" + d.getDate();    
	}
	           
   return(s);                                //Return date.
}


function GetCurrentTime()
{
	var d, s = "";     //Declare variables.
	var c = ":"; 	   

	d = new Date();                           //Create Date object.
	s = d.getHours() + c;
	s += d.getMinutes() + c;
	s += d.getSeconds();

	return(s);                                //Return date.
}

function GetCurrentDateTime()
{
	var d, s = "";     //Declare variables.
	var c = ":"; 	   

	d = new Date();                           //Create Date object.
	s = (d.getMonth() + 1) + "-";            //Get month
	s += d.getDate() + "-";     //Get day   
	s += d.getYear() + " ";                   //Get year.
	s += d.getHours() + c;
	s += d.getMinutes() + c;
	s += d.getSeconds();

	return(s);                                //Return date.
}

function GetCurrentYear()
{
	var d, s = "";     //Declare variables.
	
	d = new Date();                           //Create Date object.
	s = d.getYear();     //Get year
	s = s.toString();
//	if (s.length > 2)
//	{
//		s = s.substr(2,2);
//	}
	
	return(s);
}	
	
function Log(Str, IsOverWrite, IsRequireDate, FilePath)
{		
	var fso, tf;
	
	if (FilePath == undefined)
	{
		FilePath = ("d:/Log.txt");
		//FilePath = Server.MapPath("Log.txt");
	}
	fso = new ActiveXObject("Scripting.FileSystemObject");
	if (IsOverWrite == true)
	{
		tf = fso.CreateTextFile(FilePath, true);
	}
	else
	{
		if (fso.FileExists(FilePath))
		{
			tf = fso.OpenTextFile(FilePath,8);
		}
		else
		{
			tf = fso.CreateTextFile(FilePath);
		}
	}
	if (IsRequireDate == true)
	{	
		tf.WriteLine((new Date()).toString() + ":   " + Str);
	}
	else
	{
		tf.WriteLine(Str);
	}
	tf.Close();
}



function CastNulltoEmpty(pValue)
{
	var ReturnValue = pValue;
	if (pValue == null )//|| pValue== "{00000000-0000-0000-0000-000000000000}")
	{
		ReturnValue = "";
	}
	return(ReturnValue);
}


function FillCombo( pRst, pControl,pGrid,pKey,pKeyName,pShowName)
{
	pControl.clearAttributes();
	try
	{
		if (pRst.State == 0){return;}
	}	
	catch(e)
	{
		alert(e);
		return;
	}
	with(pRst)
	{		
		if( EOF && BOF ) 
		{
			return;
		}
		//Filter	= "";
		MoveFirst();
		if( pControl.options[0].innerText == "" )
		{
			while( pControl.options.length != 0)
			{
				pControl.options.remove(0);			
			}
			var Element = document.createElement("OPTION");
			pControl.add(Element);
			Element.innerText = "";
			var i	= 1;//0;
			while( !EOF)
			{
				var Element = document.createElement("OPTION");
				pControl.add(Element);
				Element.innerText = Fields(pShowName).value;
				//if( pGrid != undefined && pGrid != null && pGrid != "" && Fields(pKeyName).value == pGrid.TextMatrix(pGrid.Row, pGrid.ColIndex(pKey)))
				if( pGrid != undefined && pGrid != null && Fields(pKeyName).value == pGrid.TextMatrix(pGrid.Row, pGrid.ColIndex(pKey)))
				{
					pControl.selectedIndex	= i;
				}
				MoveNext();
				i++;
			}
		}
		else
		{
			for( var i = 0; i < pControl.options.length; i++)
			{
				if( pGrid != undefined && pGrid != null && pGrid != "" && pControl.options[i].innerText == pGrid.TextMatrix(pGrid.Row, pGrid.ColIndex(pKey)))
				{
					pControl.selectedIndex	= i;
					break;
				}
			}
		}
		Filter	= "";
	}
}		


function FillComboSel( pRst, pControl,pKey,pKeyName,pShowName)
{
	pControl.clearAttributes();
	try
	{
		if (pRst.State == 0){return;}
	}	
	catch(e)
	{
		alert(e);
		return;
	}
	with(pRst)
	{		
		if( EOF && BOF ) 
		{
			return;
		}
		//Filter	= "";
		MoveFirst();
		if( pControl.options[0].innerText == "" )
		{
			while( pControl.options.length != 0)
			{
				pControl.options.remove(0);			
			}
			var Element = document.createElement("OPTION");
			pControl.add(Element);
			Element.innerText = "";
			var i	= 1;//0;
			while( !EOF)
			{
				var Element = document.createElement("OPTION");
				pControl.add(Element);
				Element.innerText = Fields(pShowName).value;
				if(Fields(pKey).value == pKeyName)
				{
					pControl.selectedIndex	= i;
				}
				MoveNext();
				i++;
			}
		}
		else
		{
			for( var i = 0; i < pControl.options.length; i++)
			{
				if(Fields(pKey).value == pKeyName)
				{
					pControl.selectedIndex	= i;
					break;
				}
			}
		}
		Filter	= "";
	}
}		

function ComboSel(pControl,pKey)
{

			for( var i = 0; i < pControl.options.length; i++)
			{
				if( pControl.options[i].innerText == pKey)
				{
					pControl.selectedIndex	= i;
					break;
				}
			}
		
}		



function FillComboAll( pRst, pControl,FieldName)
{
	if (FieldName=="")
	{
		//pControl.clearAttributes();
		while( pControl.options.length != 0)
				{
					pControl.options.remove(0);			
				}
	}
	else
	{		
		pControl.clearAttributes();
		try
		{
			if (pRst.State == 0){return;}
		}	
		catch(e)
		{
			alert(e);
			return;
		}
		with(pRst)
		{		
			if( EOF && BOF ) 
			{
				while( pControl.options.length != 0)
				{
					pControl.options.remove(0);			
				}
				return;
			}
			
			MoveFirst();
			
				while( pControl.options.length != 0)
				{
					pControl.options.remove(0);			
				}
				var Element = document.createElement("OPTION");
				pControl.add(Element);
				Element.innerText = "";
				var i	= 1;//0;
				var textValue="";
				while( !EOF)
				{
				
					var Element = document.createElement("OPTION");
					if (textValue != Fields(FieldName).value)
					{
						pControl.add(Element);
						Element.innerText = Fields(FieldName).value;
					}
					textValue= Fields(FieldName).value;
					MoveNext();
					i++;
				}
			
			Filter	= "";
		}
	}
}		

function FillListBoxAll( pRst, pControl,FieldName)
{
	if (FieldName=="")
	{
		//pControl.clearAttributes();
		while( pControl.options.length != 0)
				{
					pControl.options.remove(0);			
				}
	}
	else
	{		
		//pControl.clearAttributes();
		
		try
		{
			if (pRst.State == 0){return;}
		}	
		catch(e)
		{
			alert(e);
			return;
		}
		with(pRst)
		{		
			if( EOF && BOF ) 
			{
				return;
			}
			
			MoveFirst();
			
				while( pControl.options.length != 0)
				{
					pControl.options.remove(0);			
				}
				
				var i	= 1;//0;
				var textValue=""
				while( !EOF)
				{
					var Element = document.createElement("OPTION");
					if (textValue != Fields(FieldName).value)
					{
						pControl.add(Element);
						Element.innerText = Fields(FieldName).value;
					}
					textValue= Fields(FieldName).value;
					MoveNext();
					i++;
				}
			
			Filter	= "";
		}
	}
}		

function lbxSelectAll(fControl,tControl)
{
		for (var i=0;i<fControl.options.length;i++)
				{
					var Element = document.createElement("OPTION");
					tControl.add(Element);
					Element.innerText = fControl.options[i].innerText;
						
				}
		while( fControl.options.length != 0)
				{
					fControl.options.remove(0);			
				}
}

function lbxRemove(oControl)
{
			for (var i=oControl.options.length-1;i>=0;i--)
				{
						
						oControl.options.remove(i)
					
						
				}
}
function lbxSelect(fControl,tControl)
{

		for (var i=0;i<fControl.options.length;i++)
				{
					if (fControl.options[i].selected)
					{
						var Element = document.createElement("OPTION");
						tControl.add(Element);
						Element.innerText = fControl.options[i].innerText;
						
					}
						
				}
		for (var i=fControl.options.length-1;i>=0;i--)
				{
					if (fControl.options[i].selected)
					{
						
						fControl.options.remove(i)
					}
						
				}
				
	
}


//日期的输入
function OnDateChange( pControl, objdatatimetype )
{
	var transdate = new Object();
	var strDateTime =pControl.value;
	if (strDateTime == ""){strDateTime = GetCurrentTime();}
	transdate.Date			= new Date(strDateTime);
	transdate.DateSelect	= objdatatimetype;
	var selected = window.showModalDialog("GetDateTime.aspx",
		transdate ,"dialogHeight:40px;dialogWidth:15;status:no;help:no;");
	pControl.value = selected.toString();
}

function GetPageURL()
{
	var Location=window.location.href;
	
	Location=Location.substr(0,Location.lastIndexOf("/"))+"/";
	return Location;
}


function rd(number,decimalDigits)
{
	var strnumber = number.toString();
	return  Math.round(number*Math.pow(10,decimalDigits))/Math.pow(10,decimalDigits);	
}	

function rdStr(rdnum,DecimalDigits)
{
	var strnumber=rd(rdnum,DecimalDigits).toString();
	var nNum = strnumber.indexOf( "." );
	var nZero2Add = 0;
	if ( nNum > -1 )
	{
		nNum = strnumber.length - nNum - 1;
		nZero2Add = DecimalDigits - nNum;
	}
	else
	{
		nZero2Add = DecimalDigits;
		strnumber += ".";
	}		
	for ( var i=0; i<nZero2Add; i++ )
	{
		strnumber += "0";
	}
return strnumber;
}

function ShowCombo(pControl,pGrid,pKey)
{
	for( var i = 0; i < pControl.options.length; i++)
		{
				if( pGrid != undefined && pGrid != null && pGrid != "" && pControl.options[i].innerText == pGrid.TextMatrix(pGrid.Row, pGrid.ColIndex(pKey)))
				{
					pControl.selectedIndex	= i;
					break;
				}
		}
}


function rdStr(rdnum,DecimalDigits)
{

	var strnumber=round(rdnum,DecimalDigits).toString();
	var nNum = strnumber.indexOf( "." );
	var nZero2Add = 0;
	if ( nNum > -1 )
	{
		nNum = strnumber.length - nNum - 1;
		nZero2Add = DecimalDigits - nNum;
	}
	else
	{
		nZero2Add = DecimalDigits;
		strnumber += ".";
	}		
	for ( var i=0; i<nZero2Add; i++ )
	{
		strnumber += "0";
	}
return strnumber;
}

function GetCookieValue(ckiName,eleName)
			{
		
				if (document.cookie)
				{
					//get Cookie set
					cLen =ckiName.length;
					index=document.cookie.indexOf(ckiName);
					indexEnd=document.cookie.indexOf("#",index+cLen);
					CookieSet = document.cookie.substring(index+cLen+1,indexEnd);
					
					//cookie element
					cLen =eleName.length;
					index=CookieSet.indexOf(eleName);
					indexEnd=CookieSet.indexOf("&",index+cLen);
					if (index>indexEnd)
						indexEnd=CookieSet.length ;
													
					return  CookieSet.substring(index+cLen+1,indexEnd);
					
				}
				else
				{
					return null;
				}
			}
			

String.prototype.trim = function()
	{
		// Use a regular expression to replace leading and trailing 
		// spaces with the empty string
		return this.replace(/(^\s*)|(\s*$)/g, "");
	}	
	
	function fileSave()
		{
			
			window.frmMain.cmdlg.CancelError = false;
			window.frmMain.cmdlg.FilterIndex = 1;
			window.frmMain.cmdlg.DialogTitle = "Save file as";
			window.frmMain.cmdlg.Filter = "Excel file (*.xls)";

			// Calling the dialog:
			window.frmMain.cmdlg.ShowSave();

			return window.frmMain.cmdlg.FileName;
		}
	
function getAbsoluteLeft( ob ){
 if(!ob){return null;}
   var obj = ob;
   var objLeft = obj .offsetLeft;
   while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){
     objLeft += obj .offsetParent.offsetLeft;
     obj = obj .offsetParent;
   }
 return objLeft ;
}

// get absolute TOP position

function getAbsoluteTop( ob ){
 if(!ob){return null;}
 var obj = ob;
 var objTop = obj .offsetTop;
 while( obj != null && obj .offsetParent != null && obj .offsetParent.tagName != "BODY" ){
   objTop += obj .offsetParent.offsetTop;
   obj = obj .offsetParent;
 }
 return objTop ;
}

function isNumber(a) 
 {
      return typeof a == 'number' && isFinite(a);
 }
 

function CardValidate(cardNumber, expDate)
{
	
	var toDay = GetCurrentDate(0);
	toDay=toDay.substring(0,7);
	if (expDate>=toDay)
	{
		/*
		total=0;
		temp=0;
		for (i=0;i<cardNumber.length;i++)
		{
			if(((i+1)%2) == 0)
			{
				total+=parseInt(cardNumber.charAt(i));
			}
			else
			{
				temp=parseInt(cardNumber.charAt(i))*2;
				if (temp>9)
				{
					temp = temp-9;
				}
				total +=temp;
			}
			
		}
		if ((total%10)==0)
		{
			return true;
		}
		else
		{
			return false;
		}
		*/
	return true;
	}
	else
	{
		return false;
	}
	
	
}

function DateDiff(fmDate,toDate)
{
	
	var fy,fm,fd;
	var ty,tm,td;
	var one_day=1000*60*60*24;
	fy=fmDate.substring(0,4);
	fm=fmDate.substring(5,7);
	
	ty=toDate.substring(0,4);
	tm=toDate.substring(5,7);
	
	fd=fmDate.substring(8,10);
	td=toDate.substring(8,10);
	
	var fdate= new Date(fy,fm-1,fd);
	var tdate= new Date(ty,tm-1,td);
	return Math.ceil((tdate.getTime()-fdate.getTime())/(one_day));
	
}

	function showtext(element, text)
			{
				document.getElementById(element).innerText=text;
			
			}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var lastdot=str.lastIndexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.substring(lastdot+1)==""){
		    alert("Invalid E-mail ID")
		    return false
		}
		 
		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		if(CharsInBag(str)==false){
		    alert("Invalid E-mail ID")
		    return false
		 }
		 var arrEmail=str.split("@")
		 var ldot=arrEmail[1].indexOf(".")
		 if(isInteger(arrEmail[1].substring(ldot+1))==false){
		    alert("Invalid E-mail ID")
		    return false
		 }
 		 return true		
	}

function ValidateMailAddress(txtEmail){
	var emailID=txtEmail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 function CharsInBag(s)
{   var i;
var lchar="";
    // Search through string's characters one by one.
    // If character is not in bag.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
		if(i>0)lchar=s.charAt(i-1)
        if (bugchars.indexOf(c) != -1 || (lchar=="." && c==".")) return false;
    }
    return true;
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
        if ((c >= "0") && (c <= "9") && (c != ".")) return false;
    }
    // All characters are numbers.
    return true;
}

function isGuessInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
        if ((c < "0") || (c > "9")) return false;
    }
    // All characters are numbers.
    return true;
}