
 var arrSections = new Array();
 
 //private properties
 var mstrCurrentLocation;
 var mobjHTTPrequest;
 
 function initialize()
 {
    //set the current location
	var File= new MqFiles;			
	mstrCurrentLocation=File.getCurrentLocation("document");
		    
	//set the HTTPRequest applet
	if(parent){
		if(parent.objAdmin){
			mobjHTTPrequest=parent.objAdmin.GetHTTPRequest();
		}else{
			if(parent.parent){
				if(parent.parent.objAdmin){
					mobjHTTPrequest=parent.parent.objAdmin.GetHTTPRequest();
				}
			}
		}
	}
 }
		
 //----Editor GUI Functions---------------------------------------------------------------
 function GetTableListByProject()
 {	
	//first close all the child windows
	OnBeforeNavigate();	
	var strTables;
	if(IsValidProject()){
		var strProj = GetProject();
		
		var strCurrentLocation=mstrCurrentLocation; 
		
		strTables=mobjHTTPrequest.Get(strCurrentLocation + "WCMQeDict.ASP?WCI=GetTableList&Proj=" + strProj);
		
		BuildTablesCombo(strTables);
	}else{
		strTables = TableIDSeparator;
		BuildTablesCombo(strTables);
	}
	m_objMqButton.DisableButton(UPDATE_NOW_BUTTON);		
 }
 
 function BuildTablesCombo(strTables)
 {
	var arrTables = new Array();
	var arrIDVal = new Array();
	var x, z;

	var currentDoc = document.frmEDict;

	if (strTables.substring(strTables.length - TableListSeparator.length) == TableListSeparator){
		strTables = strTables.substring(0, strTables.length - TableListSeparator.length);
	}	
	arrTables = strTables.split(TableListSeparator);		
		
	currentDoc.lstTables.length=0;
	
	for(x=0; x<arrTables.length; x++)
	{	
		arrIDVal = arrTables[x].split(TableIDSeparator);

		z = new Option(unescape(arrIDVal[1]), unescape(arrIDVal[0]));

		currentDoc.lstTables.length++;
			currentDoc.lstTables.options[x] = z;
	}
	currentDoc.lstTables.selectedIndex=0;

	ResetGrid();
 }
 
 function GetFieldListByTable()
 {

	//first close all the child windows
	OnBeforeNavigate();

	if (IsValidTable()){
		var strProj = GetProject();
		var strCurrentTable = GetTable();
		var strCurrentLocation=mstrCurrentLocation; 
		var strFields=mobjHTTPrequest.Get(strCurrentLocation + "WCMQeDict.ASP?WCI=GetFieldList&Proj=" + strProj + "&TableName=" + strCurrentTable);
		
		if (strFields.substring(0,SectionSeparator.length*2) == SectionSeparator+SectionSeparator){
			ResetGrid();
		}else{
			BuildFieldsGrid(strFields);
		}
		m_objMqButton.EnableButton(UPDATE_NOW_BUTTON);
	}else{
		ResetGrid();
		m_objMqButton.DisableButton(UPDATE_NOW_BUTTON);
	}
 }
 
 function BuildFieldsGrid(strAllFields)
 {
	var strHeader, strFields,i;
	var strColType="";
	var strSort="";
	var arrHeader = new Array();
	var arrProperties = new Array();
	
	if (strAllFields.substring(strAllFields.length - TableListSeparator.length) == TableListSeparator){
		strAllFields = strAllFields.substring(0, strAllFields.length - TableListSeparator.length);
	}	

	arrSections=strAllFields.split(SectionSeparator);
	if (arrSections[HEADER_SECTION]){
		strHeader=arrSections[HEADER_SECTION];
	}
	if (arrSections[FIELDS_SECTION]){
		strFields=arrSections[FIELDS_SECTION];
	}else{
		strFields="";
	}
	
	if (arrSections[PROPERTIES_SECTION]){
		arrProperties=arrSections[PROPERTIES_SECTION].split(TableListSeparator);
	}

	SetHiddenPropertyFields(arrProperties);

	if (strHeader){	
		strHeader=g_MqRef.MqStr.StripTrailing(strHeader, TableListSeparator);
		arrHeader=strHeader.split(TableListSeparator);
	}
	
	var lngNumCols = arrHeader.length;
	var strColWidth = GetColWidths(arrHeader);
	
	var strHeaderToSet="";
	for(i=0;i<lngNumCols;i++){
		strHeaderToSet+=GetHeaderCaptionByName(unescape(arrHeader[i])) + GRID_PROP_SEP;
		strColType+="ro" + GRID_PROP_SEP;
		strSort+="str" + GRID_PROP_SEP;
	}
	
	strHeaderToSet=g_MqRef.MqStr.StripTrailing(strHeaderToSet, GRID_PROP_SEP);
	strColType=g_MqRef.MqStr.StripTrailing(strColType, GRID_PROP_SEP);
	strSort=g_MqRef.MqStr.StripTrailing(strSort, GRID_PROP_SEP);
	var arrValues=GetDataArray(strFields,TableListSeparator,RowSeparator);
	LoadGrid(strHeaderToSet, strColWidth, strColType, strSort, arrValues);
	
	if (IsChoiceOrder()){
		SetMoveUpDownArrowsOn();
	}else{
		SetMoveUpDownArrowsOff();
	}	
 }
 
 //----Open Windows Functions-------------------------------------------------------------
 
 function Open_Add_Table_Win()
 {
	var strOpenWin=FindOpenWindow(ADD_TABLE_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ);
	}else{ 
		if(strOpenWin.length>0){
			alert(MSG_CLOSE_OPEN_WINDOWS);
			SetWindowFocus(strOpenWin);
		}else{
			var strProj = GetProject();
			OpenChildWindow('WCMQeDict.ASP?WCI=AddTable&Proj=' + strProj, WIN_ADD_TABLE, 'width=485,height=200');	
		}
	} 
}
 
 function Open_Rename_Table_Win()
 {
	var strOpenWin=FindOpenWindow(RENAME_TABLE_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL);
	}else{
		if (!IsValidTable()){
			window.alert(MSG_SELECT_PROJ_CL);
		}else{
			if(strOpenWin.length>0){
				alert(MSG_CLOSE_OPEN_WINDOWS);
				SetWindowFocus(strOpenWin);
			}else{ 
				var strProj = GetProject();
				var strTableName = GetTable();
			   	OpenChildWindow('WCMQeDict.ASP?WCI=RenameTable&Proj=' + strProj + '&TableName=' + strTableName, WIN_RENAME_TABLE, 'width=400,height=160');
			}
		}
	}
 }
 
 function Open_Copy_Table_Win()
 {
	var strOpenWin=FindOpenWindow(COPY_TABLE_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL);
	}else{
		if (!IsValidTable()){
			window.alert(MSG_SELECT_PROJ_CL);
		}else{
			if(strOpenWin.length>0){
				alert(MSG_CLOSE_OPEN_WINDOWS);
				SetWindowFocus(strOpenWin);
			}else{
				var strProj = GetProject(); 
				var strTableName = GetTable();
			   	OpenChildWindow('WCMQeDict.ASP?WCI=CopyTable&Proj=' + strProj + '&TableName=' + strTableName, WIN_COPY_TABLE, 'width=485,height=155');
			}
		}
	}
 }
 
 function Open_Delete_Table_Win()
 {
	var strOpenWin=FindOpenWindow(DELETE_TABLE_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL);
	}else{
		if (!IsValidTable()){
			window.alert(MSG_SELECT_PROJ_CL);
		}else{
			if(!IsEditable()){
				window.alert(MSG_CANT_DELETE_CL);
			}else{
				if(strOpenWin.length>0){
					alert(MSG_CLOSE_OPEN_WINDOWS);
					SetWindowFocus(strOpenWin);
				}else{ 
					var strProj = GetProject();
					var strTableName = GetTable();
				   	OpenChildWindow('WCMQeDict.ASP?WCI=DeleteTable&Proj=' + strProj + '&TableName=' + strTableName, WIN_DELETE_TABLE, 'width=400,height=130');
				}
			}
		}
	}
 }
 
 function ImportChoices()
 {
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ);
	}else{
	   	var strProj = GetProject();
	   	OpenChildWindow('TmplImportParams.htm?Proj=' + strProj, WIN_IMPORT, 'width=400,height=250');			
	}
 }
 
 function Open_Add_Row_Win()
 {
	var strOpenWin=FindOpenWindow(ADD_ROW_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL);
	}else{
		if (!IsValidTable()){
			window.alert(MSG_SELECT_PROJ_CL);
		}else{
			if(!IsEditable()){
				window.alert(MSG_CANT_ADD_CHOICES);
			}else{
				if(strOpenWin.length>0){
					alert(MSG_CLOSE_OPEN_WINDOWS);
					SetWindowFocus(strOpenWin);
				}else{ 
					var strSelectedCOID;
					var strProj = GetProject();
					var strTableName = GetTable();
					if (IsChoiceOrder()){
						strSelectedCOID = escape(GetSelectedCOID());
					}else{
						strSelectedCOID = "";
					}

				   	OpenChildWindow('WCMQeDict.ASP?WCI=AddRow&Proj=' + strProj + '&TableName=' + strTableName + "&SelectedCOID=" + strSelectedCOID, WIN_ADD_ROW, 'width=450,height=150', true, 450, 300);
				}
			}
		}
	}
 }
 
 function Open_Rename_Row_Win()
 {
	var strSelectedFieldID = escape(GetSelectedItem(0));
	var strOpenWin=FindOpenWindow(RENAME_ROW_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL_CHOICE);
	}else{
		if (!IsValidTable()){
			window.alert(MSG_SELECT_PROJ_CL_CHOICE);
		}else{
			if(!IsEditable()){
				window.alert(MSG_CANT_RENAME_CHOICES);
			}else{
				if(strSelectedFieldID === ""){
					window.alert(MSG_SELECT_PROJ_CL_CHOICE);
				}else{
					if(strOpenWin.length>0){
						alert(MSG_CLOSE_OPEN_WINDOWS);
						SetWindowFocus(strOpenWin);
					}else{
						var strProj = GetProject();
						var strTableName = GetTable();
					   	OpenChildWindow('WCMQeDict.ASP?WCI=RenameRow&Proj=' + strProj + '&TableName=' + strTableName + '&FieldID=' + strSelectedFieldID, WIN_RENAME_ROW, 'width=400,height=150');
					}
				}
			}
		}
	}
 }
 
 function Open_Delete_Row_Win()
 {
	var strSelectedFieldID = escape(GetSelectedItem(0));
	var strOpenWin=FindOpenWindow(DELETE_ROW_INVALID_OPEN_WIN);
	if (!IsValidProject()){
		window.alert(MSG_SELECT_PROJ_CL_CHOICE);
	}else{
		if (!IsValidTable){
			window.alert(MSG_SELECT_PROJ_CL_CHOICE);
		}else{
			if(!IsEditable()){
				window.alert(MSG_CANT_DELETE_CHOICES);
			}else{
				if(strSelectedFieldID === ""){
					window.alert(MSG_SELECT_PROJ_CL_CHOICE);
				}else{
					if(strOpenWin.length>0){
						alert(MSG_CLOSE_OPEN_WINDOWS);
						SetWindowFocus(strOpenWin);
					}else{
						var strProj = GetProject();
						var strTableName = GetTable();
					   	OpenChildWindow('WCMQeDict.ASP?WCI=DeleteRow&Proj=' + strProj + '&TableName=' + strTableName + '&FieldID=' + strSelectedFieldID, WIN_DELETE_ROW, 'width=450,height=140');
					}
				}
			}
		}
	}
 }

 //-----------Window Manipulation--------------------------------------------------
 function RefreshWindow()
 {
     window.location = "WCMQeDict.ASP?WCI=Editor";
 }

 function SetMoveUpDownArrowsOn()
 {
	var currentDoc = document.frmEDict;
	
	currentDoc.imgup.src = "../../../Theme/images/buttons/upOff.gif";
	currentDoc.imgup.alt = TT_INCREASE_COID;
	currentDoc.imgdown.src = "../../../Theme/images/buttons/downOff.gif";
	currentDoc.imgdown.alt = TT_DECREASE_COID;
 }
 
  function SetMoveUpDownArrowsOff()
 {
	var currentDoc = document.frmEDict;
  
	currentDoc.imgup.src = "../../../Theme/images/buttons/updis.gif";
	currentDoc.imgup.alt = "";
	currentDoc.imgdown.src = "../../../Theme/images/buttons/downdis.gif";
	currentDoc.imgdown.alt = "";		
 }
 
 function MoveSelectedUp()
 {	
	if(choicesGrid){
		if (IsChoiceOrder()){
			if (GetSelectedItem(1) === ""){
				window.alert(MSG_SELECT_PROJ_CL_CHOICE);
			}else if(IsAtBeginning()){
				var lngChoiceID=GetSelectedCOID();
				objString.InitializeString(MSG_CHOICE_FIRST_IN_LIST);
				window.alert(objString.FormatStringVar(lngChoiceID + ";",";"));
			}else{
				var numRows;
				var x;
				var strID, strField, strCOID, strColor, strType, strPrevID, strPrevField, strPrevCOID, strPrevColor, strPrevType;

				numRows = choicesGrid.getRowsNum();

				for(x=0; x<numRows; x++)
				{
					if(IsRowSelected(x)){
						
						var lngRowID=choicesGrid.getRowId(x);
						var lngPrevRowID=choicesGrid.getRowId(x-1);
						strID = choicesGrid.cells(lngRowID,NID_COL).getValue();
						strField = choicesGrid.cells(lngRowID,NAME_WCO_COL).getValue();
						strCOID = choicesGrid.cells(lngRowID,COID_COL).getValue();
						
						if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
							strColor = choicesGrid.cells(lngRowID,COLOR_WCO_COL).getValue();
						}
						if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
							strType = choicesGrid.cells(lngRowID,TYPE_WCO_COL).getValue();
						}
						
						strPrevID = choicesGrid.cells(lngPrevRowID,NID_COL).getValue();
						strPrevField = choicesGrid.cells(lngPrevRowID,NAME_WCO_COL).getValue();
						strPrevCOID = choicesGrid.cells(lngPrevRowID,COID_COL).getValue();
						if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
							strPrevColor = choicesGrid.cells(lngPrevRowID,COLOR_WCO_COL).getValue();
						}
						if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
							strPrevType = choicesGrid.cells(lngPrevRowID,TYPE_WCO_COL).getValue();
						}
									
						var strProj = GetProject();
						var strTableToMoveRow = GetTable();
				
						var strCurrentLocation=mstrCurrentLocation; 
						var strMessage=mobjHTTPrequest.Get(strCurrentLocation + "WCMQeDict.ASP?WCI=eDictMoveRow&Proj=" 
							+ strProj + "&TableName=" + strTableToMoveRow + "&FieldID=" + escape(strID)   
							+ "&FieldCOID=" + escape(strCOID) + "&PrevFieldID=" + escape(strPrevID) + "&PrevFieldCOID=" + escape(strPrevCOID));
	
						if (strMessage==VALUE_MOVED_MSG){
							//alert(strMessage);
							//window.close();

							choicesGrid.cells(lngPrevRowID,NAME_WCO_COL).setValue(strField);
							choicesGrid.cells(lngPrevRowID,NID_COL).setValue(strID);
							if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
								choicesGrid.cells(lngPrevRowID,COLOR_WCO_COL).setValue(strColor);
							}
							if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
								choicesGrid.cells(lngPrevRowID,TYPE_WCO_COL).setValue(strType);
							}
										
							choicesGrid.cells(lngRowID, NAME_WCO_COL).setValue(strPrevField);
							choicesGrid.cells(lngRowID, NID_COL).setValue(strPrevID);
							if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
								choicesGrid.cells(lngRowID,COLOR_WCO_COL).setValue(strPrevColor);
							}
							if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
								choicesGrid.cells(lngRowID,TYPE_WCO_COL).setValue(strPrevType);
							}
							choicesGrid.selectRowById(lngPrevRowID, true);

							break;
						}else{
							if (strMessage!=HTTP_REQ_CANCEL_PROCESS){
								alert(strMessage);	
							}	
						}
					}
				}
			}  
		}//else we do nothing  
	}
 }
 
 function MoveSelectedDown()
 {
	if(choicesGrid){
 		if (IsChoiceOrder()){
 			if (GetSelectedItem(1) === ""){
				window.alert(MSG_SELECT_PROJ_CL_CHOICE);
			}else if(IsAtEnd()){
				var lngChoiceID=GetSelectedCOID();
				objString.InitializeString(MSG_CHOICE_LAST_IN_LIST);
				window.alert(objString.FormatStringVar(lngChoiceID + ";",";"));
			}else{
				
				var x;
				var strID, strField, strCOID, strColor, strType, strPrevID, strPrevField, strPrevCOID, strPrevColor, strPrevType;
				var numRows =choicesGrid.getRowsNum();
				
				for(x=0; x<numRows; x++)
				{
					if(IsRowSelected(x)){
						
						var lngRowID=choicesGrid.getRowId(x);
						var lngNextRowID=choicesGrid.getRowId(x+1);
						
						
						strID = choicesGrid.cells(lngRowID,NID_COL).getValue();
						strField = choicesGrid.cells(lngRowID,NAME_WCO_COL).getValue();
						strCOID = choicesGrid.cells(lngRowID,COID_COL).getValue();
						
						if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
							strColor = choicesGrid.cells(lngRowID,COLOR_WCO_COL).getValue();
						}
						if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
							strType = choicesGrid.cells(lngRowID,TYPE_WCO_COL).getValue();
						}
										
						strPrevID = choicesGrid.cells(lngNextRowID,NID_COL).getValue();
						strPrevField = choicesGrid.cells(lngNextRowID,NAME_WCO_COL).getValue();
						strPrevCOID = choicesGrid.cells(lngNextRowID,COID_COL).getValue();
						
						if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
							strPrevColor = choicesGrid.cells(lngNextRowID,COLOR_WCO_COL).getValue();
						}
						if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
							strPrevType = choicesGrid.cells(lngNextRowID,TYPE_WCO_COL).getValue();
						}
										
						var strProj = GetProject();
						var strTableToMoveRow = GetTable();
				
						var strCurrentLocation=mstrCurrentLocation; 
						var strMessage=mobjHTTPrequest.Get(strCurrentLocation + "WCMQeDict.ASP?WCI=eDictMoveRow&Proj=" 
							+ strProj + "&TableName=" + strTableToMoveRow + "&FieldID=" + escape(strID)   
							+ "&FieldCOID=" + escape(strCOID) + "&PrevFieldID=" + escape(strPrevID) + "&PrevFieldCOID=" + escape(strPrevCOID));
	
						if (strMessage==VALUE_MOVED_MSG){
							//alert(strMessage);
							//window.close();
							
							choicesGrid.cells(lngNextRowID,NID_COL).setValue(strID);
							choicesGrid.cells(lngNextRowID,NAME_WCO_COL).setValue(strField);
							if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
								choicesGrid.cells(lngNextRowID,COLOR_WCO_COL).setValue(strColor);
							}
							if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
								choicesGrid.cells(lngNextRowID,TYPE_WCO_COL).setValue(strType);
							}
												
							choicesGrid.cells(lngRowID, NID_COL).setValue(strPrevID);
							choicesGrid.cells(lngRowID, NAME_WCO_COL).setValue(strPrevField);
							
							if(choicesGrid.getColumnCount()>COLOR_WCO_COL){
								choicesGrid.cells(lngRowID,COLOR_WCO_COL).setValue(strPrevColor);
							}
							if(choicesGrid.getColumnCount()>TYPE_WCO_COL){
								choicesGrid.cells(lngRowID,TYPE_WCO_COL).setValue(strPrevType);
							}
												
							choicesGrid.selectRowById(lngNextRowID);

							break;
						}else{
							if (strMessage!=HTTP_REQ_CANCEL_PROCESS){
								alert(strMessage);	
							}	
						}
					}
			    }
			}
		}//else we do nothing
	}
 }
 
 function GetColWidths(arrHeaders)
 {
 	var strColWidth="";
	var lngTableWidth=100;
	
	var lngNumVisibleCols=arrHeaders.length;
	
	if(lngNumVisibleCols>6){
		lngTableWidth=1000;
	}
	
	var COL_WIDTH_ID_FIELD=10;
	var COL_WIDTH_CHOICE_ORDER_FIELD=10;
	
	lngTableWidth=lngTableWidth-COL_WIDTH_ID_FIELD;
	lngNumVisibleCols=lngNumVisibleCols-1;
	
	if(IsChoiceOrder()){
		lngTableWidth=lngTableWidth-COL_WIDTH_CHOICE_ORDER_FIELD;
		lngNumVisibleCols=lngNumVisibleCols-1;
	}
	
	

	var lngDefWidth=Math.round(lngTableWidth/(lngNumVisibleCols));
	for(var i=0; i<arrHeaders.length; i++){
		if(arrHeaders[i].toLowerCase()=="nid"){
			strColWidth+=COL_WIDTH_ID_FIELD + GRID_PROP_SEP;
		}else{
			if(arrHeaders[i].toLowerCase()=="nchoiceid"){
				strColWidth+=COL_WIDTH_CHOICE_ORDER_FIELD + GRID_PROP_SEP;
			}else{
				strColWidth+=lngDefWidth + GRID_PROP_SEP;
				
			}
		}
	}
	
	return strColWidth;
 }
 
 function GetSelectedCOID()
 {
 	var arrHeader = new Array();
	var arrFields = new Array();
	var strSelectedCOID="";
	var i, intColNum;
	
	if (arrSections[HEADER_SECTION]){
		arrHeader=arrSections[HEADER_SECTION].split(TableListSeparator);
	}
	if (arrSections[FIELDS_SECTION]){
		arrFields=arrSections[FIELDS_SECTION].split(TableListSeparator);
	}

	for(i=0; i<arrHeader.length; i++){
		if (arrHeader[i].toLowerCase()==strFieldChoiceID.toLowerCase()){
			intColNum = parseInt(arrFields[i]);
			i=arrHeader.length;
		}
	}
	strSelectedCOID=GetSelectedItem(intColNum);
	
	return strSelectedCOID;
 }
 
 
 function SetHiddenPropertyFields(arrProperties)
 {
	var currentDoc = document.frmEDict;
 
	currentDoc.txtChoiceOrderProperty.value=arrProperties[0];
	currentDoc.txtEditableProperty.value=arrProperties[1];
 }
 
 
 function GetHeaderCaptionByName(strName)
 {
	var strLCaseName=strName.toLowerCase();
	
	if (strLCaseName == strFieldID.toLowerCase()){
		return FIELD_ID;
	}else if (strLCaseName == strFieldChoiceID.toLowerCase()){
		return FIELD_CHOICE_ID;
	}else if (strLCaseName == strFieldName.toLowerCase()){
		return FIELD_NAME;
	}else if(strLCaseName==strFieldColor.toLowerCase()){
		return FIELD_COLOR;
	}else if(strLCaseName==strFieldType.toLowerCase()){
		return FIELD_TYPE;
	}else{
		return strName;
	} 
 }
 
 
 function GetHeaderNameByCaption(strCaption)
 {
	var strLCaseCaption=strCaption.toLowerCase();
	
	if (strLCaseCaption == FIELD_ID.toLowerCase()){
		return strFieldID;
	}else if (strLCaseCaption == FIELD_CHOICE_ID.toLowerCase()){
		return strFieldChoiceID;
	}else if (strLCaseCaption == FIELD_NAME.toLowerCase()){
		return strFieldName;
	}else if(strLCaseCaption==FIELD_COLOR.toLowerCase()){
		return strFieldColor;
	}else if(strLCaseCaption==FIELD_TYPE.toLowerCase()){
		return strFieldType;
	}else{
		return strCaption;
	}
 } 
 
 
 function IsValidProject()
 {
	var strSelVal=GetProject();
	
	if (strSelVal=="-1"){
		return false;
	}else{
		return true;
	}
 }
 
 
 function IsValidTable()
 {
	var strSelVal=GetTable();
	
	if (strSelVal=="0" || strSelVal=="NullField"){
		return false;
	}else{
		return true;
	}
 }

 function GetProject()
 {
	var objLstProj=document.getElementById("lstProjects");
	
	if(objLstProj){
		return objLstProj.options[objLstProj.selectedIndex].value;
	}else{
		return "-1";
	}
 }


 function GetTable()
 {
	var objTblLst=document.getElementById("lstTables");
	
	if(objTblLst){
		return objTblLst.options[objTblLst.selectedIndex].value;
	}else{
		return "0";
	}
 }


 function SetCurrentTable(strTableName)
 {
	var currentDoc = document.frmEDict;
	var i;
	var intLen = currentDoc.lstTables.length;
	intIndex=0;

	for(i=0; i<intLen; i++){
		
		if(unescape(currentDoc.lstTables.options[i].text).toLowerCase() == unescape(strTableName).toLowerCase()){
			intIndex=i;
			i=intLen;
		}
	}	
	currentDoc.lstTables.selectedIndex=intIndex;
 }


 function IsEditable()
 {
	if (document.frmEDict.txtEditableProperty.value==BLN_FALSE){
		return false;
	}else{
		return true;
	}
 }

 function IsAtEnd()
 {
	var blnReturn=false;
	
	if(choicesGrid){
		blnReturn=IsRowSelected(choicesGrid.getRowsNum()-1);
	}
	
	return blnReturn;
 }

 function IsAtBeginning()
 {
	return IsRowSelected(0);
 }

 function IsChoiceOrder()
 {
	if (document.frmEDict.txtChoiceOrderProperty.value==BLN_TRUE){
		return true;
	}else{
		return false;
 	}
 }
 
 function UpdateCLs()
 {
	if(mobjHTTPrequest){
		var strProj = GetProject();
		var strCurrentTable = GetTable();
		
		var co = mobjHTTPrequest.Get(mstrCurrentLocation + "WCMQeDict.ASP?WCI=wciUpdateChoiceLists&Proj=" + strProj + "&TableName=" + strCurrentTable);

		if (co!=mobjHTTPrequest.CANCEL_PROCESS){
								
			var objResponse=mobjHTTPrequest.Response(co);
									
			if (objResponse){
				if (objResponse.HasErrors()){
					objResponse.ProcessErrors("",true);
				}else{
					alert(MSG_CHOICES_UPDATED_IN_VIEWS);
				}
			}
		}
	}
 }
 
 
function WriteChoicesGrid()
{
	ResizeGrid();
}
	
function ResizeGrid()
{
	var objGrid=document.getElementById("choices_grid");
				
	if(objGrid){
					
		var intBodyHeight;
					
		if (document.all){
			if (document.documentElement && document.documentElement.offsetHeight){
				intBodyHeight=document.documentElement.offsetHeight;
			}else{
				intBodyHeight=document.body.offsetHeight;
			}
		}else{
			intBodyHeight=window.innerHeight;
		}

		if(intBodyHeight>200){
			objGrid.style.height=(intBodyHeight-150) + "px";	
		}
	}
}

function ResetGrid()
{
	LoadGrid("", "*", "ro", "str", null);
}

function LoadGrid(strHeaders, strWidths, strColTypes, strSorting, arrValues)
{
	choicesGrid = new dhtmlXGridObject('choices_grid');
	choicesGrid.setImagePath("../../../js/codebasegrid/imgs/");
	choicesGrid.setNoHeader(false);
	choicesGrid.setColAlign("left");
	choicesGrid.setSkin("dhx_skyblue");
				
	choicesGrid.setHeader(strHeaders);
	choicesGrid.setInitWidthsP(strWidths);
	choicesGrid.setColTypes(strColTypes);
	choicesGrid.setColSorting(strSorting);
	choicesGrid.init();
	choicesGrid.attachEvent("onRowDblClicked", Open_Rename_Row_Win);
	if(arrValues){
		choicesGrid.parse(arrValues, "jsarray");
	}
}

function GetDataArray(strValuesList,strFieldSep,strRowSep)
{
	var arrData;	
	
	//if the last part of the string is the row separator, remove it so we don't add an extra row
	strValuesList=g_MqRef.MqStr.StripTrailing(strValuesList, strRowSep);

	if(strValuesList!="")
	{		
		arrData=strValuesList.split(strRowSep);
			
		for(var i=0;i<arrData.length;i++) {	
			arrData[i]=arrData[i].split(strFieldSep);	
			
			for(var k=0; k<arrData[i].length; k++){
				arrData[i][k]=g_MqRef.MqStr.MqHtmlEncode(unescape(arrData[i][k]));
			}
		}
	}
	
	return arrData;
}

function GetSelectedItem(lngColID)
{
	if(choicesGrid){
		if(choicesGrid.cells){			
			var rowID = choicesGrid.getSelectedId();	
			
			if(rowID){
				if(choicesGrid.cells(rowID,lngColID)){
					return choicesGrid.cells(rowID,lngColID).getValue();
				}
			}
		}
	}
}

function IsRowSelected(lngRowIndex)
{
	var blnReturn = false;
	
	if(choicesGrid){
		var selRowID = choicesGrid.getSelectedId();				
		var lngRowID = choicesGrid.getRowId(lngRowIndex);
					
		if(selRowID==lngRowID){
			blnReturn=true;
		}
	}
	return blnReturn;
}