
//Global Variables for QBE
	var bSelectedQuery = false;
	var oQBEArray = new Array();
	var m_bQuerySubmit;
	var aQBEId = new Array();
	var aOperators = new Array();
	var m_bXtraLoaded = false;
	var m_bXtraLayLoaded = false;
	var m_oSecurityElement;
	var m_nCountOfQBEElements=0;
	
function DrawQBE(cButtonText,bAddRow){
	//Writes out HTML for the QBE area of a list

			var cHTML = '';
			var oNode;
			var oParentNode;
			var i;
			var cLabel;
			var cLabelData;
			var cLabelSize;
			var cDataType;
			var bShowAll = true;
			var cBOBlank=''; // boolean option
			var cBOTrue=''; // boolean option
			var cBOFalse=''; // boolean option
			var cJoinedField;
			var cJoinedFieldDataType;
			var oTempNode;
			var cJoinedFieldData;
			var colNum = 1;
			var cFilterField;

			AddStatus('Refreshing List');
		
		//need to renew array object here because we need to refresh this array
		//when clear sort is called otherwise we stack up the array on
		//every clear sort and when remove fields the removed field
		//would not be removed from this array and clear sort would error out.		
			oQBEArray = new Array();
		
			if(!cButtonText || cButtonText == '') cButtonText = 'Go';
		
		//get QBE to check against  
		
			var xndQBE = QBE.selectSingleNode('QBE');

		//Get Reference to QBE Contents	
			try{
				var oDIVQBEContents = DIVQBEContents;
			} catch(e){
				//No QBE just exit
				return;
			}		
			
			oDIVQBEContents.innerHTML='';
			var nSystemID = DIVQBEContents.systemid;
			var cTemplateID = DIVQBEContents.templateid;
		
		//Create Query DIV
			var oDIVQBE = document.createElement('<div id="hgSPECQuery" type="tabcollapse" name="Query" class="tabBorder">');
			oDIVQBEContents.appendChild(oDIVQBE);
			
		//Create Table
			var oQBETbl = document.createElement('<table border=\"0\" width=\"100%\" cellspacing=\"0\">');
			oDIVQBE.appendChild(oQBETbl);
			
		//Create Rows
			var oRow = oQBETbl.insertRow();
		
		//Create Cell
			var oCell = oRow.insertCell();
		
			oCell.colSpan="4";
			oCell.bgColor='#F0F4F7';
			oCell.className='toolbar';
			oCell.noWrap=true;

		//Build HTML
			cHTML = "&nbsp;&nbsp;<A  class='toolbar'  href='#' onclick='eventsavequery();'><img class='toolbar' alt='Update/save existing query' src='images/save.ico' width='16' height='16'>&nbsp;Save</A>";
			cHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='toolbar'  href='#' onclick='eventsaveAsquery();'><img class='toolbar' alt='Save this query'  width='16' height='16' src='images/saveAs.ico'>&nbsp;Save As</A>";
			cHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='toolbar'  href='#' onclick='eventDeleteQuery();'><img class='toolbar' alt='Delete this query' width='16' height='16' src='images/delete.ico'>&nbsp;Delete</A>";
			cHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='toolbar'  href='#' onclick='showAddQBEDiv();'><img class='toolbar' alt='Edit this Query' width='16' height='16' src='images/edit.ico'>&nbsp;<label class='toolbar' id='editcloseqbe' style='cursor:hand' name='editcloseqbe' onmouseout='underlineText(false)' onmouseover='underlineText(true)'>Edit</label></A>";
			cHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='toolbar'  href='#' onclick='eventQueryName(\"reset\");'><img class='toolbar' alt='Get default query' width='16' height='16' src='images/reset.ico'>&nbsp;Reset</A>";
			cHTML += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='toolbar' href='#' onclick='clearQBE();'><img class='toolbar' alt='Clear query fields'  width='16' height='16' src='images/selectClear.ico'>&nbsp;Clear</a>&nbsp;&nbsp;&nbsp;&nbsp;";
	
		//Fill Cell
			oCell.innerHTML = cHTML;
		
		//Insert Row - Toolbar Border
			oRow = oQBETbl.insertRow();
			oCell = oRow.insertCell();
			oCell.bgColor='#003366';
			oCell.height='1';
			oCell.colSpan='4';			
			
			
		//Insert Row
			oRow = oQBETbl.insertRow();
			
		//Insert Cell
			oCell = oRow.insertCell();
			oCell.bgColor="#F0F4F7";
			oCell.colSpan="4";
			oCell.align="right";
			oCell.innerHTML = "&nbsp;&nbsp;&nbsp;";
			
		//Insert Row
			oRow = oQBETbl.insertRow();
			
		//Insert Cell
			oCell = oRow.insertCell();
			oCell.bgColor="#F0F4F7";
			oCell.colSpan="4";
			oCell.align="left";
			oCell.innerHTML = '<span id="tclist2" name="tclist2"></span>';


//			if(oParentNode.childNodes.length > 0){	
				//clear id array

		
			 	aQBEId = new Array();

			
				

				//loop through all QBE values and draw appropriate items	
				//MB:11/20/2003 - for(i=0; i<oParentNode.childNodes.length; i++){
				for(i=0; i<xndQBE.childNodes.length; i++){
					//MB:11/20/2003 -oNode = oParentNode.childNodes.item(i);
					
					oNode = xndQBE.childNodes.item(i);
					
						
										
						//MB:11/20/2003 - var bLastItem=(i==(oParentNode.childNodes.length-1));
						var bLastItem=(i==(xndQBE.childNodes.length-1));
				
						//Check the QBE to see if the node exists:
						try{
							var nodeName = oNode.attributes.getNamedItem('id').text;
						}catch(e){}
					
						//only display labels that are set to visible
						if(QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'visible', 'false')=='true'){					
							//cache variables

							cLabel = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'label', 'NO LABEL');
							cLabelData = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'id', '');
							cDataType = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'type', '');
							cFilterField = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'filterfield', '');							

							//check joined field
							cJoinedField = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'joinedfield', '')
							
							if(cJoinedField > ''){
								try{
									cJoinedFieldDataType = QueryColAttribute(nSystemID, cTemplateID, cJoinedField, 'type', '')
									cJoinedFieldData = cJoinedField;
																		
									try{
										if(QueryColAttribute(nSystemID, cTemplateID, cJoinedField, 'originaltype', '')=='security'){
											m_oSecurityElement = 'cbo'+cLabelData;
										}
									}catch(e){ }
									
								}catch(e){} //ignore errors
							}else{
								cJoinedFieldDataType = '';
								cJoinedFieldData = '';
								cOrigFldType = '';
							}
							
								
							if(cDataType=='boolean'){
								try{
									cLabel = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'label', 'NO LABEL');
									cBOBlank = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'blank', '');
									cBOFalse = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'false', '');
									cBOTrue = QueryColAttribute(nSystemID, cTemplateID, oNode.nodeName.toLowerCase(), 'true', '');
								} catch(e){}
							}				
						
							//default field size if no size given
							cLabelSize = 20;
							
							//failsafe if no Label was found
							if(cLabel == '') cLabel = oNode.nodeName.toLowerCase(); // cLabel = oNode.attributes.getNamedItem('id').text;
							
							
							//Start Row
							//Insert Row
							oRow = oQBETbl.insertRow();
							oRow.className='formLabel';
					
								
							//Get Id test to set label id
							var cIdName = oNode.nodeName.toLowerCase();
														
							//add the qbe list id's to the array
							aQBEId[colNum] = "QBE" + colNum.toString(); 
					
					
							//Insert Cell
							oCell = oRow.insertCell();
							oCell.className='formlabel';
							oCell.width="20%";
							oCell.noWrap=true;
							oCell.innerHTML='&nbsp;<label onmouseout="JavaScript:try{QBELabelsOut()}catch(e){};" onmouseover="JavaScript:try{QBELabelsOver()}catch(e){};" onmousedown="JavaScript:try{SelectedDraggableItem(\'QBE\')}catch(e){};" name="' + cIdName + '" id="QBE' + colNum +  '">' + cLabel + ':</label>';
							
							
							//Insert Cell
							oCell = oRow.insertCell();
							oCell.width="20%";
							oCell.innerHTML= buildOperator(cLabelData,cLabel,cDataType,cBOBlank,cBOFalse,cBOTrue,cJoinedFieldDataType);
							
										
							//Insert Cell
							oCell = oRow.insertCell();
							if(bLastItem){
								oCell.noWrap=true;
							} else {
								oCell.colSpan='2';
							}
							
							oCell.innerHTML = buildInput(cLabelData,cLabelSize,cDataType,bLastItem,cJoinedField,cJoinedFieldDataType,cJoinedFieldData,cFilterField);
							
							 colNum = colNum + 1;
						
						//clear variables
							cJoinedField = '';
							cJoinedFieldDataType = '';
							cJoinedFieldData = '';
							cLabel = '';
							cLabelData = '';
							cDataType = '';
							cBOBlank = '';
							cBOFalse = '';
							cBOTrue = '';
							cOrigFldType = '';
							
							
							
						}
				}
				m_nCountOfQBEElements=colNum - 1;
				
			totalQBENum = colNum;
			//we need this if qbe is redrawn during drag drop procedure
			if (chkAddQBE.checked){
				editcloseqbe.innerText = "Close";
			}else{
				editcloseqbe.innerText = "Edit";
			}
						
			try{
			updateQueryTempDiv();		
			}catch(e){}

			RemoveStatus();
			return;		

	}
    
   function underlineText(bUnderline){	
		//underlines buttons that are 
			event.srcElement.style.textDecoration = (bUnderline) ? "underline":""   
   }
   
    function eventsavequery(){
	      //***SAVES CURRENT QUERY		
			var cCurrentAtt = '';
			var cSelectedGuid = '';
			var cSaveAsQueryname = '';
			if (QBE.selectSingleNode("QBE/command/currentquery").text == "Default")
			{
				alert("Sorry, you can not save over the default public query");
				return;				
			}
			try{		  
				var oOptionNode = XMLObj.selectSingleNode("hgXML/sq");
			
			if(oOptionNode.hasChildNodes){
						//loop to build options
						
						for(var i=0; i< oOptionNode.childNodes.length; i++)
						{
							cOption = oOptionNode.childNodes(i).text;
							cCurrentAtt = oOptionNode.childNodes(i).attributes.getNamedItem("current").text
							//if true then current query
							if (cCurrentAtt=='true'){
								 //current query name
								mSaveAsQueryname =  cOption;
								cSaveAsQueryname = cOption;
								 //current guid
								mSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
								cSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
							}
					
						}	
			}	
		}catch(e){ }
		
	  		//Current query is saved
	     		//alert("save=" + cSaveAsQueryname);
				QBE.selectSingleNode("QBE/command/saveasqueryname").text = cSaveAsQueryname;
				QBE.selectSingleNode("QBE/command/queryguid").text = cSelectedGuid;		
				refreshList();
		
    }
    
    
    function SaveAsQBECancel(){
		HideElem(SpanSaveAsQBEName);
		HideElem(DIVSaveAsQBEPublic);
    }
    
    function eventsaveAsquery(){
		//show save As dialog
	
		if(cDragType==null||cDragType!='QBE'){
			chkAddQBE.checked=true;
			editcloseqbe.innerText = "Close";
			ShowEditQBEArea();
		}
		
		if (cSavePublicQuery == "True") ShowElem(DIVSaveAsQBEPublic); // {cHasPublicRight = 'public'}else{cHasPublicRight ='';}
		
		ShowElem(SpanSaveAsQBEName);

    }


    function SaveAsQBEComplete(){
		cSaveAsQueryName = SaveAsQBEName.value;

		if(!cSaveAsQueryName){cSaveAsQueryName = ''}
		if (cSaveAsQueryName.toLowerCase() == "default")
		{
			alert("Sorry, you can not use Default as a save name");
			return;				
		}
		
		if (cSaveAsQueryName != '')
		{
			//check dupes on public queries   selectSingleNode("hgXML/fielddata[@id='" + sColBeingDropped + "']"

			try{
				//var xndQT = XMLObj.selectSingleNode("hgXML/sq/queryname[@public='True']");
				var xndQT = XMLObj.selectSingleNode("hgXML/sq");
				if(xndQT != null){
					for(var xndN = xndQT.firstChild; xndN!=null; xndN=xndN.nextSibling){
						//alert(xndQT.text.toLowerCase());
						//alert(arrSaveAsQueryName[1]);
						//alert(cSaveAsQueryName);
						if(xndN.attributes.getNamedItem('public').text == 'True' && xndN.text.toLowerCase() == cSaveAsQueryName.toLowerCase() && SaveAsQBEPublic.checked){
							alert("Sorry, this public name you are saving already exists.");
							return;				
						}
					}
				}else{
					var xndQT = QueryTemplates.selectSingleNode("hgXML");
					if(xndQT != null){
						for(var xndN = xndQT.firstChild; xndN!=null; xndN=xndN.nextSibling){
						if(xndN.attributes.getNamedItem('public').text == 'True' && xndN.text.toLowerCase() == cSaveAsQueryName.toLowerCase() && SaveAsQBEPublic.checked){
								alert("Sorry, this public name you are saving already exists.");
								return;				
						}
					}
				}	
			}			
			}catch(e){
				alert("in catch");
				var xndQT = QueryTemplates.selectSingleNode("hgXML");
				if(xndQT != null){
					for(var xndN = xndQT.firstChild; xndN!=null; xndN=xndN.nextSibling){
						if(xndN.attributes.getNamedItem('public').text == 'True' && xndN.text.toLowerCase() == cSaveAsQueryName.toLowerCase() && SaveAsQBEPublic.checked){
								alert("Sorry, this public name you are saving already exists.");
								return;			
						}
					}
				}
			}
	
		
			mSaveAsQueryname =  cSaveAsQueryName;	
				//on a save as the current guid should be set to nothing
			mSelectedGuid = "";	
			
			  //change saveAs node
		    QBE.selectSingleNode("QBE/command/saveasqueryname").text = cSaveAsQueryName;
				//no guid cause we have a new save
			QBE.selectSingleNode("QBE/command/queryguid").text = "";
				//save if public query
			QBE.selectSingleNode("QBE/command/public").text = SaveAsQBEPublic.checked ? '1': '0';
				//type
			//QBE.selectSingleNode("QBE/command/type").text = arrSaveAsQueryName[2];
		
			refreshList();
		} else {
				alert('You must specify a name to save the query');
			}
    
    }
   function eventQueryName(cReset){
		//select box query name event
		var cQueryName;
		var cSelectGuid;
			//if reset hit then we need default query
		
		if(cReset){
			cQueryName = "Default"
			cSelectGuid = ""
			QBE.selectSingleNode("QBE/command/queryname").text = cQueryName;
			QBE.selectSingleNode("QBE/command/queryguid").text =  cSelectGuid;
			bSelectedQuery = true;
			refreshList();
		}else{
		
					//if option 0 not selected then set the proper variables		
				if (event.srcElement.options[event.srcElement.selectedIndex].text != "- Select -")		{
						
					mQueryName = event.srcElement.options[event.srcElement.selectedIndex].text;	
					cQueryName = event.srcElement.options[event.srcElement.selectedIndex].text;
					cQueryName = cQueryName.replace(" (User)", "");
					cQueryName = cQueryName.replace(" (Public)", "");
					
					mSelectedGuid = event.srcElement.options[event.srcElement.selectedIndex].value;
					cSelectGuid =  event.srcElement.options[event.srcElement.selectedIndex].value;
					  //change qbe command nodes
						
				    QBE.selectSingleNode("QBE/command/queryname").text = cQueryName;
					QBE.selectSingleNode("QBE/command/queryguid").text =  cSelectGuid;			
					bSelectedQuery = true;

						refreshList();
				}	
	   }		
    }
    
    function eventDeleteQuery(){
    	      //***DELETES CURRENT QUERY		
			var cCurrentAtt = '';
			var cSelectedGuid = '';
			var cSaveAsQueryname = '';
			
			if (QBE.selectSingleNode("QBE/command/currentquery").text == "Default")
			{
				alert("Sorry, you can not delete the DEFAULT public query");
				return;				
			}
			try{		  
				var oOptionNode = XMLObj.selectSingleNode("hgXML/sq");
			
			if(oOptionNode.hasChildNodes){
						//loop to build options
						
						for(var i=0; i< oOptionNode.childNodes.length; i++)
						{
							cOption = oOptionNode.childNodes(i).text;
							cCurrentAtt = oOptionNode.childNodes(i).attributes.getNamedItem("current").text
							//if true then current query
							if (cCurrentAtt=='true'){
								 //current query name
								//mSaveAsQueryname =  cOption;
								cSaveAsQueryname = cOption;
								 //current guid
								//mSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
								cSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
							}
					
						}	
			}	
		}catch(e){}
		
	  		//Current query is saved
	     		//alert(cSelectedGuid);				
				QBE.selectSingleNode("QBE/command/deletequery").text = cSelectedGuid;		
				refreshList();
		
    }
    function getQueryTempOptions()
    {
		//get values to put into the queryname dropdown
		var cDat = '<option value=\"\" selected>- Select -</option>';
		var cOption;	
		var cValOption = '';
		var cPublic = '';
		var cType = '';	
		try{    //if process query is hit
		  
			var oOptionNode = XMLObj.selectSingleNode("hgXML/sq");
			
			if(oOptionNode.hasChildNodes){
				//loop to build options
				
				for(var i=0; i< oOptionNode.childNodes.length; i++)
				{
					cOption = oOptionNode.childNodes(i).text;
					cValOption = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
					// cType = oOptionNode.childNodes(i).attributes.getNamedItem("type").text
					//if (cType != "") {cType = ' ,' + cType}	else {cType = ""}
					if(oOptionNode.childNodes(i).attributes.getNamedItem("public").text == 'True'){cPublic = ' (Public)'}else{cPublic = ' (User)';}
				cDat += '<option value=\"' + cValOption + '\">' + cOption + cPublic + '</option>'; 
				}	
			}
		}catch(e){ 
			//on first load no xmlobj so get from QueryTemplates nodes
		
				var oOptionNode = QueryTemplates.selectSingleNode("hgXML");		
				//alert(oOptionNode);
				     
				if(oOptionNode != null){
					if(oOptionNode.hasChildNodes){
							//loop to build options
							for(var i=0; i<oOptionNode.childNodes.length; i++)
							{							        
								cOption = oOptionNode.childNodes(i).text;							  
								cValOption = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text;
							//	 cType = oOptionNode.childNodes(i).attributes.getNamedItem("type").text
								//if (cType != "") {cType = ' ,' + cType}	else {cType = ""}
								if(oOptionNode.childNodes(i).attributes.getNamedItem("public").text == 'True'){cPublic = ' (Public)'}else{cPublic = ' (User)';}							
							   cDat += '<option value=\"' + cValOption + '\">' + cOption + cPublic + '</option>'; 
							}			
					}
				}
		}
	
		return cDat;
    }
  
    function meUser(){
	
    }
	
	function buildOperator(cFieldName,cFieldLabel,cDataType,cBooleanBlank,cBooleanFalse,cBooleanTrue,cJoinedFieldDataType)
	{
		var cData = '';	
				
		//cData += '<td width="20%">';

		//alert('Type: ' + cDataType + '\nJoined Type: ' + cJoinedFieldDataType);
		if(cJoinedFieldDataType=='user' || cJoinedFieldDataType == 'validated' || cJoinedFieldDataType == 'location' || cJoinedFieldDataType == 'security' || cJoinedFieldDataType=='state'){
			switch(cJoinedFieldDataType){
				case 'user':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\" name=\"OPT' + cFieldName + '\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '	<option value=\"13\">Is Current User</option>';			
					cData += '	<option value=\"1\">Starts with</option>';
					cData += '	<option value=\"2\">Ends with</option>';
					cData += '	<option value=\"3\">Contains</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';			
					break;
				
				case 'validated':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
					break;
				
				case 'location':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
					break;				
				
				case 'security':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
					break;

				case 'state':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
					break;
			
			}
		}else{
			switch(cDataType){
				case 'boolean':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class="small" datasrc="#QBE" datafld="' + cFieldName + '">';
					cData += '  <option value="">' + cBooleanBlank + '</option>';
					cData += '  <option value="1">' + cBooleanTrue + '</option>';
					cData += '  <option value="0">' + cBooleanFalse + '</option>';			
					cData += '</select>';				
					break;
					
				case 'validated':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
					break;
				case 'memo':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"1\">Starts with</option>';
					cData += '	<option value=\"2\">Ends with</option>';
					cData += '	<option value=\"3\">Contains</option>';				
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';			
					break;
				case 'integer':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"12\">&gt;=</option>';
					cData += '	<option value=\"11\">&lt;=</option>';
					cData += '	<option value=\"10\">&gt;</option>';
					cData += '	<option value=\"9\">&lt;</option>';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';
					break;	
				case 'date':
					cData += '<select id=\"OPT' + cFieldName + '\" name=\"dateSelect\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"12\">&gt;=</option>';
					cData += '	<option value=\"11\">&lt;=</option>';
					cData += '	<option value=\"10\">&gt;</option>';
					cData += '	<option value=\"9\">&lt;</option>';
					cData += '	<option value=\"0\">Is</option>';
					cData += '	<option value=\"4\">Is Between</option>';
					cData += '	<option value=\"14\">&lt;=Current Date</option>';					
					cData += '	<option value=\"15\">&gt;=Current Date</option>';									
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';
					break;	
				case 'datetime':
					cData += '<select id=\"OPT' + cFieldName + '\" name=\"dateSelect\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"12\">&gt;=</option>';
					cData += '	<option value=\"11\">&lt;=</option>';
					cData += '	<option value=\"10\">&gt;</option>';
					cData += '	<option value=\"9\">&lt;</option>';
					cData += '	<option value=\"0\">Is</option>';
					cData += '	<option value=\"4\">Is Between</option>';
					cData += '	<option value=\"14\">&lt;=Current Date</option>';					
					cData += '	<option value=\"15\">&gt;=Current Date</option>';									
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';
					break;
				case 'user':
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\" name=\"OPT' + cFieldName + '\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '	<option value=\"13\">Is Current User</option>';			
					cData += '	<option value=\"1\">Starts with</option>';
					cData += '	<option value=\"2\">Ends with</option>';
					cData += '	<option value=\"3\">Contains</option>';
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';			
					break;	
				default:
					cData += '<select id=\"OPT' + cFieldName + '\" onafterupdate=\"modifiedOperator()\"  class=\"small\" datasrc="#QBE" datafld=\"' + cFieldName + 'Operator\">';
					cData += '	<option value=\"0\">Is</option>';
					cData += '  <option value=\"16\">Is Not</option>';
					cData += '	<option value=\"1\">Starts with</option>';
					cData += '	<option value=\"2\">Ends with</option>';
					cData += '	<option value=\"3\">Contains</option>';				
					cData += '  <option value=\"6\">Is Empty</option>';
					cData += '  <option value=\"5\">Is Not Empty</option>';
					cData += '</select>';				
				
			}
		}
		//cData += '</td>';
		
		//return
		return cData;	
	}
	
	function buildInput(cFieldName,cFieldSize,cDataType,bLastItem,cJoinedField,cJoinedFieldDataType,cJoinedFieldData,cFilterField)
	{
		var cData = '';		
		var oOptions = new Array();
		var oOptionNode;
		var cOption;
		var cQuery;
		var cFilterType;
		
		if(cFilterField!='' && cFilterField!='undefined'){
			cFilterType = QueryColAttribute(DIVQBEContents.systemid, DIVQBEContents.templateid, cFilterField, 'type','');
		}
			
		cData +='<span id=\"qbeCell' + cFieldName + '\" style=\"visibility:hidden\">';
		
		if(cJoinedFieldDataType > '' && cJoinedFieldDataType != 'string'){
		//if(cJoinedFieldDataType == 'validated' || cJoinedFieldDataType == 'location' || cJoinedFieldDataType == 'security'){
			
			switch(cJoinedFieldDataType){
				case 'validated':	
				
					//array for clearQuery function					
					oQBEArray[oQBEArray.length] = 'cbo' + cFieldName;
										
					//start tag for combo box
					cData += '<select onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"small\" name=\"cbo' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\">';
					
					//search xml for passed fieldname
					oOptionNode = KeywordsXML.selectSingleNode('hgXML/' + cJoinedField + '/options/data');

					//options section
					cData += '<option value=\"\" selected>- Select -</option>';
					
					//make sure field had options associated to it
					try{
						if(oOptionNode!=null){
							if(oOptionNode.hasChildNodes){
								//loop to build options
								
								for(i=0; i<oOptionNode.childNodes.length; i++){							
									
									try{
										cOption = oOptionNode.childNodes(i).attributes.getNamedItem("Keyword").text;
										var cOptionID = oOptionNode.childNodes(i).attributes.getNamedItem("ID").text;
										cData += '<option id=\"' + cOptionID + '\" value=\"' + cOption + '\">' + cOption + '</option>';
									}catch(e){}
								}
							}
						}
					} catch(e){
						//alert('error loading keywords for field: ' + cFieldName);
					}
					
					//close tag for combo box
					cData += '</select>';
					
					break;
					
				case 'location':
				
						
						
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'cbo' + cFieldName;
					
					//start tag for combo box
					cData += '<select onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"small\" name=\"cbo' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\">';
					
					//search xml for passed fieldname
					oOptionNode = KeywordsXML.selectSingleNode('hgXML/' + cJoinedField + '/options/data');
					
					//options section
					cData += '<option value=\"\" selected>- Select -</option>';

					try{					
						//make sure field had options associated to it
						if(oOptionNode.hasChildNodes){
							//loop to build options
							for(i=0; i<oOptionNode.childNodes.length; i++)
							{
								try{
									cOption = oOptionNode.childNodes(i).attributes.getNamedItem("Keyword").text;
									cData += '<option value=\"' + cOption + '\">' + cOption + '</option>'; 
								}catch(e){}
							}
						}
					} catch(e){
						//alert('error loading keywords for field: ' + cFieldName);
					}
					
					
					//close tag for combo box
					cData += '</select>';
					break;

				case 'security':					
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'cbo' + cFieldName;
					
					//start tag for combo box
					cData += '<select onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"small\" name=\"cbo' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\">';
					
					//search xml for passed fieldname
					oOptionNode = KeywordsXML.selectSingleNode('hgXML/' + cJoinedField + '/options/data');
					
					//options section
					cData += '<option value=\"\" selected>None</option>';

					try{
						//make sure field had options associated to it
						if(oOptionNode.hasChildNodes){
							//loop to build options
							for(i=0; i<oOptionNode.childNodes.length; i++)
							{
								try{
									cOption = oOptionNode.childNodes(i).attributes.getNamedItem("Keyword").text;
									cData += '<option value=\"' + cOption + '\">' + cOption + '</option>'; 
								}catch(e){}
							}
						}
					} catch(e){
						//alert('error loading keywords for field: ' + cFieldName);
					}
					
					
					//close tag for combo box
					cData += '</select>';
					break;

				case 'state':
				
					
				
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'cbo' + cFieldName;
					
					//start tag for combo box
					cData += '<select onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"small\" name=\"cbo' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\">';

					
					//search xml for passed fieldname
					oOptionNode = KeywordsXML.selectSingleNode('hgXML/' + cJoinedField + '/options/data');
					
					//options section
					cData += '<option value=\"\" selected>None</option>';

					try{
						//make sure field had options associated to it
						if(oOptionNode.hasChildNodes){
							//loop to build options
							for(i=0; i<oOptionNode.childNodes.length; i++)
							{
								
							
								try{
									cOption = oOptionNode.childNodes(i).attributes.getNamedItem("Keyword").text;
									cData += '<option value=\"' + cOption + '\">' + cOption + '</option>'; 
								}catch(e){}
							}
						}
					} catch(e){
						//alert('error loading keywords for field: ' + cFieldName);
					}

					
					//close tag for combo box
					cData += '</select>';
					break;

				
				case "user":																														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//field mappings to handle the xml return from the pop-up
					cQuery = cFieldName + "=username";
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"User Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/23_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectUser('','','" + cQuery + "','');\">";														
					break;
						
				case "users":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"User Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/23_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectUsers('');\">";														
					break;							
					
				case "group":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//field mappings to handle the xml return from the pop-up
					cQuery = cFieldName + "=groupname";
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"User Group Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/22_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectGroup('','', '" + cQuery + "');\">";														
					break;	
					
				case "groups":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cField  + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"User Group Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/22_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectGroups('');\">";														
					break;	
									
				case "supplier":																					
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//field mappings to handle the xml return from the pop-up
					cQuery = cFieldName + "=suppliername";
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Supplier Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/20_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectSupplier('','','" + cQuery + "');\">";														
					break;
					
				case "contact":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=contactname";
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Contact Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/28_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectContact('" + null + "','" + cFieldName +"','" + cQuery + "','" + cFilterType + "','','" + cFilterField + "');\">";														
					break;
												
				case "customer":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=customername";
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Customer Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/71_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectCustomer('" + null + "','" + cFieldName +"','" + cQuery + "');\">";														
					break;
				
				case "part":
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					//text box to hold queryable text
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Part Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/21_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectPart('','','" + cFieldName + "');\">";														
					break;

				case "calproc":													
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=calproc";
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Calibration Procedure Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/18_System.ico\" id=\"SelectImage\" onClick=\"hgEditSelectCalProc('" + null + "','" + cFieldName +"','" + cQuery + "');\">";														
					break;	

				case "equip":														
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=equipnumber";
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Equipment Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/16_system.ico\" id=\"SelectImage\" onClick=\"hgEditSelectEquip('" + null + "','" + cFieldName +"','" + cQuery + "');\">";														
					break;
					
				case "document":
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					//cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Equipment Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/16_system.ico\" id=\"SelectImage\" onClick=\"hgEditSelectEquip('','" + cFieldName +"');\">";																		
					break;							

				case "manual":
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					//cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Equipment Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/16_system.ico\" id=\"SelectImage\" onClick=\"hgEditSelectEquip('','" + cFieldName +"');\">";																		
					break;							

				case "cpid":
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=model";
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Model Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/92_system.ico\" id=\"SelectImage\" onClick=\"hgEditSelectModel('" + null + "','" + cFieldName +"','" + cQuery + "');\">";														
				
					break;
				
				case "cpidunit":
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					
					cQuery = cFieldName + "=model";
					
					cData += "<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt" + cFieldName + "\" datasrc=\"#QBE\" datafld=\"" + cFieldName + "\"  size=\"" + cFieldSize + "\">";
					cData += "&nbsp;&nbsp;<img name=\"" + cJoinedField + "\" alt=\"Model Search\" style=\"cursor:hand\" class=\"toolBar\" width=\"16\" height=\"16\" src=\"images/92_system.ico\" id=\"SelectImage\" onClick=\"hgEditSelectCPIDUnit('" + null + "','" + cFieldName +"','" + cQuery + "');\">";																		
					break;																				


				
			}
		}else{		
		     
		    
		       
			//build appropriate input type
			switch(cDataType)
			{
				case 'string':	//text input box
			
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
					cData += '<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\"  size=\"' + cFieldSize + '\">';
					break;
				
				case 'validated':	//combo box
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'cbo' + cFieldName;
					
					//start tag for combo box
					cData += '<select onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"small\" name=\"cbo' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\">';
					
					//search xml for passed fieldname
					oOptionNode = KeywordsXML.selectSingleNode('hgXML/' + cJoinedField + '/options/data');
										
					//options section
					cData += '<option value=\"\" selected>- Select -</option>';
					
					//make sure field had options associated to it
					try{
						if(oOptionNode.hasChildNodes){
							//loop to build options
							for(i=0; i<oOptionNode.childNodes.length; i++)
							{
								cOption = oOptionNode.childNodes(i).attributes.getNamedItem("Keyword").text;
								cData += '<option value=\"' + cOption + '\">' + cOption + '</option>'; 
							}
						}
					} catch(e){
						//nothing
					}					
					//close tag for combo box
					cData += '</select>';
					break;
					
				case 'date':
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
	
					//build text box & select image to pick date
					cData += '<input id=\"dateText"  onblur=\"dateChanged()\" onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\" size=\"' + cFieldSize + '\">';
					cData += '&nbsp;&nbsp;<img id=\"SelectImage\" alt="Select Date" align=\"absbottom\" style=\"cursor:hand\" width=\"16\" height=\"16\" src=\"images/selectDate.ico\" onclick=\"ShowCalendar(GetAbsoluteLeft(this),GetAbsoluteTop(this),txt' + cFieldName + ')">';				
					cData += '&nbsp;&nbsp;&nbsp;<span id=\"spDI' + cFieldName + '\" style=\"display:none; visibility:hidden\"><input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + 'uppervalue' + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + 'uppervalue' + '\" size=\"' + cFieldSize + '\">';
					cData += '&nbsp;&nbsp;<img id=\"SelectImage\" alt="Select Date" align=\"absbottom\" style=\"cursor:hand\" width=\"16\" height=\"16\" src=\"images/selectDate.ico\" onclick=\"ShowCalendar(GetAbsoluteLeft(this),GetAbsoluteTop(this),txt' + cFieldName +  'uppervalue' +  ')"></span>';				
					break;
			
				case 'datetime':
					//array for clearQuery function
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;
	
					//build text box & select image to pick date
					cData += '<input id=\"dateText"  onblur=\"dateChanged()\" onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\" size=\"' + cFieldSize + '\">';
					cData += '&nbsp;&nbsp;<img id=\"SelectImage\" alt="Select Date" align=\"absbottom\" style=\"cursor:hand\" width=\"16\" height=\"16\" src=\"images/selectDate.ico\" onclick=\"ShowCalendar(GetAbsoluteLeft(this),GetAbsoluteTop(this),txt' + cFieldName + ')">';				
					cData += '&nbsp;&nbsp;&nbsp;<span id=\"spDI' + cFieldName + '\" style=\"display:none; visibility:hidden\"><input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + 'uppervalue' + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + 'uppervalue' + '\" size=\"' + cFieldSize + '\">';
					cData += '&nbsp;&nbsp;<img id=\"SelectImage\" alt="Select Date" align=\"absbottom\" style=\"cursor:hand\" width=\"16\" height=\"16\" src=\"images/selectDate.ico\" onclick=\"ShowCalendar(GetAbsoluteLeft(this),GetAbsoluteTop(this),txt' + cFieldName +  'uppervalue' +  ')"></span>';				
					break;
														
				case "boolean":
					oQBEArray[oQBEArray.length] = 'xxx' + cFieldName;
					break;
					
				default:
					oQBEArray[oQBEArray.length] = 'txt' + cFieldName;				
					cData += '<input onchange=\"modified()\" onkeypress=\"inlineTrapEnter(refreshList);\" class=\"inputEditSolid\" name=\"txt' + cFieldName + '\" datasrc=\"#QBE\" datafld=\"' + cFieldName + '\"  size=\"' + cFieldSize + '\">';				
				
				//case 'boolean':
					//nohting to do here
			}
		}
		cData +='&nbsp;';		
		cData += '</span>'; 
		
		// </td>';
				
		//return
		return cData;
	}

	function modified()
	{
		//called by onChange event for qbe fields to indicate modified statement
	
		//Set Flag so that we know it has been modified	
			QBE.selectSingleNode('QBE/command/modified').text = "true";	

		/*
			try{
				//Get Modified Field Name
					var cField = event.srcElement.id.toString().substring(3,event.srcElement.id.toString().length);
				
				//Get Reference to the QBE Page Elements related to this operator


				if(event.srcElement.options[event.srcElement.selectedIndex].value  == 4 && event.srcElement.name == "dateSelect" ){
				  var ospDate = eval("document.all.spDI" + cField)
				    ospDate.style.display = '';
					 ospDate.style.visibility = 'visible';
				}else if (event.srcElement.name == "dateSelect" && event.srcElement.options[event.srcElement.selectedIndex].value  != 4)
				 {
				    var ospDate = eval("document.all.spDI" + cField)
					 ospDate.style.display = 'none';
					 ospDate.style.visibility = 'hidden';
		
				 }
				
			}catch(e){};
		*/

		//if(event.srcElement.options(event.srcElement.selectedIndex.option.value)
			
	}
	
	function modifiedOperator(){
		//Called when one of the field operators on the QBE is modified

		//Set Flag so that we know it has been modified	
			QBE.selectSingleNode('QBE/command/modified').text = "true";	

		//Handle Operator Value
			HandleOperatorValue(event.srcElement);
		
	}
	
	function HandleOperatorValue(oOperator){
		//Hides or Shows QBE Elements based on the current operator
		//oOperator is the <SELECT> element that is the operator
				
			try{
				//Get Modified Field Name
					var cField = oOperator.id.toString().substring(3,oOperator.id.toString().length);
				
				//Get Selected Operator
					//var nOperator = oOperator.options[oOperator.selectedIndex].value;
					
					var oNode = QBE.selectSingleNode('QBE/' + cField + 'operator');
					nOperator = oNode.text;					
					
				//Handle Special Operators that don't require a QBE value to be entered
					
					switch(nOperator)	
						{
							case '5':	//is not null
								document.all['qbeCell' + cField].style.visibility='hidden';
								break;

							case '6':	//is null
								document.all['qbeCell' + cField].style.visibility='hidden';
								break;

							case '13':	//is current user
								document.all['qbeCell' + cField].style.visibility='hidden';
								break;

							case '15':	//is >= Current Date
								document.all['qbeCell' + cField].style.visibility='hidden';
								break;

							case '14':	//is <=Current Date
								document.all['qbeCell' + cField].style.visibility='hidden';
								break;
															
							default:
								//Make sure the input area is visible
								document.all['qbeCell' + cField].style.visibility='visible';
						
						}
						
					
				//Handle Between
					if(nOperator  == 4 && oOperator.name == "dateSelect" ){
						var ospDate = eval("document.all.spDI" + cField)
					    ospDate.style.display = '';
						ospDate.style.visibility = 'visible';
					}else if (oOperator.name == "dateSelect" && nOperator  != 4)
					 {
					    var ospDate = eval("document.all.spDI" + cField)
						ospDate.style.display = 'none';
						ospDate.style.visibility = 'hidden';
		
					 }
				

				
			}catch(e){
				//alert('handle operator error: ' + e.description);
			};	
	
	}
	
	function dateChanged(){
		   	//validate the date in QBE 
		if(event.srcElement.id == "dateText" && event.srcElement.value != "" ){
			var oDateManip = new DateManip();					
						bValidDate=oDateManip.isProperDate(oDateManip.LongToStandard(event.srcElement.value));					
						if (!bValidDate) {
							var cField = event.srcElement.name.toString().substring(3,event.srcElement.name.toString().length )						
							alert(QueryColAttribute(DIVQBEContents.systemid,DIVQBEContents.templateid,cField, 'label','') + " does not contain valid date.");
							//Attempt to highight the label associated with the field
							
						
							try {
								//can't do this for lists
								var dateLabel = eval("document." + cField)
								dateLabel.style.color="red";						
							} catch(e) {} // ignore errors
							
							// Attempt to set focus to object. Ignore errors, because we cannot be positive
							// of the object name. 
							try {
								var dateInputBox = eval("document.all.txt" + cField)
								dateInputBox.focus();					
							} catch(e) {} // ignore errors
						
						 // event.srcElement.value = ""
						}
		}
	
	}
	

	
	
	function clearQBE()
	{			
		//Clear all query fields using an Array					
		for(i = 0; i<oQBEArray.length; i++){
			var cField = oQBEArray[i];	
			try{			
				document.all[cField].value = '';
			} catch(e){
				QBE.selectSingleNode("QBE/" + cField.substring(3,cField.length)).text = '';
			}
			try{
				document.all[cField + 'uppervalue'].value = '';
			} catch(e){
				//Ignore
			}			
				//Reset query option box	
			resetQueryOptions(cField.substring(3,cField.length));		
		}	
	}			
	
	function GetDefaultQueryOperator(cType){

		switch(cType)
		{
			case 'string':	
				return "1";
				
			case 'date':	
				return "12";
				
			case 'integer':
				return "0";
				
			case 'user':	
				return "3";
				
			case 'memo':	
				return "3";

			case 'boolean':	
				return "";
				
			case 'security':	
				return "0";
				
			case 'state':
				return "0";
				
			case 'location':	
				return "0";
				
			case 'validated':	
				return "0";

			default:
				return "1";
		}		

	}		
	
   function resetQueryOptions(cFieldID){

		var cType = '';
		
		var cParentField = QueryColAttribute(DIVQBEContents.systemid,DIVQBEContents.templateid,cFieldID,'joinedfield','');
		if(cParentField!=''){
			cType = QueryColAttribute(DIVQBEContents.systemid,DIVQBEContents.templateid,cParentField,'type','');
		} else {
			cType = QueryColAttribute(DIVQBEContents.systemid,DIVQBEContents.templateid,cFieldID, 'type','');
		}

		QBE.selectSingleNode("QBE/" + cFieldID + "operator").text = GetDefaultQueryOperator(cType);

		if(cType=='date'){
			var ospDate = eval("document.all.spDI" + cFieldID)
			ospDate.style.display = 'none';
			ospDate.style.visibility = 'hidden';
		}
		

		try{		
			var oOperator = document.all['OPT' + cFieldID];
			HandleOperatorValue(oOperator);
		} catch(e){
			
		}   
   }
   
	function NextPage()
	{
		// advance to next page
		var nPage = parseInt(QBE.selectSingleNode('QBE/currentpage').text);
		QBE.selectSingleNode('QBE/currentpage').text=++nPage;
		refreshList();
	}
		
	function FirstPage(){
		QBE.selectSingleNode('QBE/currentpage').text=1;
		refreshList();		
	}
	
	function LastPage(){
		QBE.selectSingleNode('QBE/currentpage').text=DIVPageCount.pagecount;
		refreshList();			
	}
		
	function PreviousPage()
	{
		// advance to previous page
		var nPage = parseInt(QBE.selectSingleNode('QBE/currentpage').text);
		QBE.selectSingleNode('QBE/currentpage').text=--nPage;
		refreshList();
	}
	
	function showDateBetweenBox(){
	    //check if aux date box needs to be displayed by checking selected index 
			
			//If DIVQBEContents is not defined then exit
			try{
				if(DIVQBEContents==null){
					return;
				} 
			} catch(e){
				return;
			}
			
			var oOpts = document.body.getElementsByTagName("SELECT");
			for(var x=0;x<oOpts.length;x++){
				var oOpt = oOpts[x];
				if(oOpt.id.indexOf('OPT')!=-1){
					HandleOperatorValue(oOpt);
				}
			}

			return;
			
	}

	function listFirstLoad(bGetDataOnFirstLoad){
		
		//Turn off flag for first load since it has now been handled
			m_bFirstLoad = false;
		
		if(bGetDataOnFirstLoad){
			// set wait message
				DIVDataTable.innerHTML="<p class='header1' align='center'><img src='images/PleaseWait.gif' border='0'><br>Please wait... retrieving records</p>";
			
		}else{
		//show please select query div
			var cHTML='<table><tr><td><img src="images/spacer.gif" height="80" width="1"></td><td align="center" width="100%" Height="100%" class="listHeader">Please Click Go</td></tr></table>';
			DIVDataTable.innerHTML= cHTML;
		}
		
		
		DrawQBE('',false);
		
		
		initLayout();		
		
		updateQueryTempDiv();		
		
		//check to see if date between box needs to be showed
		window.setTimeout(showDateBetweenBox,200);
		//showDateBetweenBox();

		


		//If Getting Data on First Request then Get It.			
			if(bGetDataOnFirstLoad) getQueryList(true);
		
	}
	
	function getQueryList(bQuerySubmit){
		//Uses the Global Form to retrieve the list

			SetDefaultStatus('Retrieving Data ...');
			AddStatus('Retrieving Data');
			
		// Get List Data URL - The URL to call for the record data
		// Function Defined in HTML file - Value usually configured in Template XML
			var cURL = getListHandlerURL()	
			
		// Setting up String Variable that defines the hidden
		//		form variables that need to be in the IFrame form 
		//		submit.  This format is defined in FORMSUBMIT.JS
		
			var cFormVars = 'QBE&=' + QBE.xml;
			cFormVars += '##!';
			cFormVars += 'exc&=' + mColList;
			cFormVars += '##!';
			cFormVars += 'srcSend&=list';
			cFormVars += '##!';

		// Call the globalForm function to create IFRAME and Submit Request for List Data	
		// globalForm is defined in FORMSUBMIT.JS
			globalForm(cURL, cFormVars, myFormCallBackFunc);
				
					
	}

	function myFormCallBackFunc()
	{	

		ClearDefaultStatus();
		ShowStatus('Data Retrieved - Preparing to Display');	
	
		var first = true;
		try{
				//alert(GlobalIFrame.document.body.innerHTML)
		 	var cIFrameXML =    GlobalIFrame.document.all["tttt"].selectSingleNode('hgXML').xml;
		        //var cIFrameXML = document.GlobalIFrame.document.body.innerText;	   	
		}catch(e){}	 	

		if(cIFrameXML){  			
				//problem getting data  island  from iframe with 2 xml nodes in it
				// was resolved by replacing xml2 with xml after we got the 1st one
			cIFrameXML = cIFrameXML.replace("<data><xml2", "<data><xml");
			cIFrameXML = cIFrameXML.replace("</xml2>", "</xml>");
				//this will cause readystate of xmlobj to change which then 
				//goes to querycallback function
							
			XMLObj.loadXML(cIFrameXML);
				//this must be called to kill the Iframe and form to 
				//prevent duplicates and prevent memory leaks
			killGlobalIFrameForm();
		 }
				//iframe is load when pages loads-ignore that first load
		 first = false;
				//GlobalIFrame.document.body.innerHTML = '';		 
		if(cIFrameXML){
			callbackGetQueryList();
			cIFrameXML=''; 
		}
		
		RemoveStatus();
		try{
			QueryTree.tabIndex=1;
			QueryTree.focus();
		} catch(e){
			//ignore
		}		
		
		
	}
	
	function callbackGetQueryList()
	{		
			// callback function... handle results of 'getQueryList'
			//close Layout dragdrop div open	
		  try{
			if(chkAddcolumns.checked == true){
				chkAddcolumns.checked = false;
				ShowEditLayoutArea();
				//paintTcBox("chkAddcolumns");
				editcloselayout.innerText = "Edit Layout";
			}
				//close qbe dragdrop div open	
				
			if (chkAddQBE.checked == true){
				chkAddQBE.checked = false;
				ShowEditQBEArea();
				//paintTcBox("chkAddQBE");
				editcloseqbe.innerText = "Edit";
		   }
		   }catch(e){}
			QBE.loadXML(XMLObj.selectSingleNode('hgXML/QBE').xml);		
			
				//if error occured try look for refreshlayout node in XMLObj
				//and load it into layout
			try{
				var cRefLay = XMLObj.selectSingleNode('hgXML/refreshlayout/hgXML').xml;
				Layout.loadXML(cRefLay);
			}catch(e){}

			//Store Layout Data
			
			mColList = '';
			
			try{
				Layout.loadXML(XMLObj.selectSingleNode('hgXML/hgXML').xml);
				SavedLayouts.loadXML(XMLObj.selectSingleNode('hgXML/savedlayouts').xml);
				
			} catch(e){
				alert('failed');
			}

			
		//Setup Saved Layouts
			SetupSavedLayouts();
			buildPage();			// Function is expected to be on implementing page			
			UseXMLObjComplete();
			updateSQDropDown();
				//check to see if date between box needs to be showed
			
		
			
			window.setTimeout(showDateBetweenBox,500);
			//showDateBetweenBox();
		//	if (QBE.selectSingleNode("QBE/command/type").text == "open"){
	//				CollapseAction("Query",true);
		//		}
		
		
		

	}
	
	function SortBy(cFieldName)
	{
		SortField.value =cFieldName;
		refreshList();
	}
	
	function collapseState(){
		/***Shows or hides query div if QBe div is redrawn***/
		
		//do not check do this if we are editing qbe drag drop		
	  if (chkAddQBE.checked == false){
	
		if (isCollapsed()){
				//collapse		
			////CollapseAction("Query",false);
			////bQueryDivCollapsed = true;
		}else{			
				//uncollapse	
			////CollapseAction("Query",true);
			////bQueryDivCollapsed = false;
		}	
	 }
			
	}
	
	function updateSQDropDown(){
		//Purpose: updates stored query drop down list
	
			//redraw qbe if selected query from drop down:
			
			DrawQBE('',false);
			initLayout();
			
			updateQueryTempDiv();
			
			chkAddQBE.checked =false;
			
			ShowEditQBEArea();
			
			//paintTcBox("");
			bSelectedQuery =false;	
	}
	
	function updateQueryTempDiv(){
	
		/****updates name of current query and sets current query guid***/
		
			var cQN = "";
			var cCurrentAtt = '';
			var cSelectedGuid = '';
			var cPublic = '';
			var cModified = '';
			var cType = '';
			try{    //if process query is hit
		  
			var oOptionNode = XMLObj.selectSingleNode("hgXML/sq");
			
			if(oOptionNode.hasChildNodes){
						//loop to build options
						
						for(var i=0; i< oOptionNode.childNodes.length; i++)
						{
							cOption = oOptionNode.childNodes(i).text;
							cCurrentAtt = oOptionNode.childNodes(i).attributes.getNamedItem("current").text
							//if true then current query
							if (cCurrentAtt=='true'){
								 //current query namearizvi	aa
								cQN =  cOption;
									//current guid- needed when you want to save same query-for save As this is removed
								mSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text								
								cSelectedGuid = oOptionNode.childNodes(i).attributes.getNamedItem("guid").text
																		
								if(oOptionNode.childNodes(i).attributes.getNamedItem("public").text == "True"){cPublic = ' (Public)';}else{cPublic = ' (User)';}
								QBE.selectSingleNode("QBE/command/queryguid").text = cSelectedGuid;
							
								
							}
					
						}						
						QBE.selectSingleNode("QBE/command/queryname").text = "";						
			}	
						if(cQN == ""){cQN = "Default";cPublic = " (Public)";}		
		}catch(e){
			try{
			//no XMLOBJ so firstload
		   	var cQueryNameState = QBE.selectSingleNode("QBE/querynamestate").text;
			
				if(cQueryNameState == ''){ 
					cQN = "Default"
					cPublic = " (Public)"
				}else{
					cQN = cQueryNameState;
					var oQueryTempNode = QueryTemplates.selectSingleNode("hgXML")
					for(var i=0; i< oQueryTempNode.childNodes.length; i++){
						if(oQueryTempNode.childNodes(i).attributes.getNamedItem("guid").text ==  QBE.selectSingleNode("QBE/queryguidstate").text)
						{
								//current guid- needed when you want to save same query-for save As this is removed
							mSelectedGuid = oQueryTempNode.childNodes(i).attributes.getNamedItem("guid").text								
							cSelectedGuid = oQueryTempNode.childNodes(i).attributes.getNamedItem("guid").text									
							QBE.selectSingleNode("QBE/queryguidstate").text = cSelectedGuid;
	
							if(oQueryTempNode.childNodes(i).attributes.getNamedItem("public").text == "True"){cPublic = ' (Public)';}else{cPublic = ' (User)';}
						
						}						
					}
				}
				}catch(e){}
			}	
					

				//get image if public query
			if(cPublic == " (Public)"){
				cPublic = "<img alt='Public Query' class='toolBar' width='16' height='16' src='images/global.ico'>"
			}else{cPublic = ""}
			
			try{
			     var test = QBE.selectSingleNode("QBE/command/modified")
		
				if(test.text == "true"){
					cModified = "<img alt='Query Modified' class='toolBar' width='16' height='16' src='images/modified.ico'>"
				}else{cModified = ""}
			}catch(e) {} // do nothing			
			try{
			
				hgSPECQuery.name="<span><table width='100' cellpadding='0' cellspacing='0' border='0'><tr><td align='center' width='150' nowrap><label class='tabHeader'>" + cQN + "</label></td><td nowrap>" + cPublic + "</td><td nowrap>&nbsp;&nbsp;" + cModified + "</td></tr></table></span>";
			
				
					//this is set to as a flag on server dataisland let property so it can keep track
					//of current query and assign it a true or false value in function getStoredQueries
				QBE.selectSingleNode("QBE/command/currentquery").text = cQN;
					//get rid of save as name
				QBE.selectSingleNode("QBE/command/saveasqueryname").text = "";
						//draw and fill the select sqdropdown box
			
			
				CollapseMessage ("Query","<span style='word-wrap:false' id='sqdropdown' bgcolor='white' name='sqdropdown'>" + "&nbsp;&nbsp;<select valign=bottom class=small id=SelQuery name=SelQuery onclick='eventQueryName();'>" + getQueryTempOptions() + "</SELECT>&nbsp;&nbsp;<a class='toolbar' href='#' onclick='refreshList();'><img id='pqimg' alt='Process Query' class='toolBar' src='images/search2_over.gif'></img> Go</a></span>");				
				collapseState();
				//alert(QBE.selectSingleNode("QBE/command/type").text)
				if(QBE.selectSingleNode("QBE/command/CollapseType").text == "open"){
					CollapseAction("Query",true);					
				}else{CollapseAction("Query",false);}
			}catch(e){}
			
	}
	function showAddQBEDiv()
	{
		/******shows and hides the edit qbe drag drop div*****/
		
			//if the edit layout div is checked(open) then close it before 
			//working with QBE
		if(chkAddcolumns.checked == true){
			chkAddcolumns.checked = false;
			ShowEditLayoutArea();
			//paintTcBox("chkAddcolumns");
			editcloselayout.innerText = "Edit Layout";
		}
		
		try{
		if (chkAddQBE.checked == false){
		
			editcloseqbe.innerText = "Close";
			chkAddQBE.checked = true;
			
				ShowEditQBEArea();

			
		}else if (chkAddQBE.checked == true){
	
			chkAddQBE.checked = false;
			ShowEditQBEArea();
			//paintTcBox("chkAddQBE");
			editcloseqbe.innerText = "Edit";
		}
		}catch(e){}		
		 
	}
	
	function showAddLayoutDiv()
	{
		/******shows and hides the edit qbe drag drop div*****/
			//if the QBE div is checked(open) then close it before 
			//working with Layout div
		if (chkAddQBE.checked == true){
			chkAddQBE.checked = false;
			ShowEditQBEArea();
			//paintTcBox("chkAddQBE");
			editcloseqbe.innerText = "Edit";
		}
		
		try{
		if (chkAddcolumns.checked == false){
			
			editcloselayout.innerText = "Close Layout";
			editcloselayout.title = "Close Layout edit box";
			chkAddcolumns.checked = true;
			
ShowEditLayoutArea();

			
		}else if (chkAddcolumns.checked == true){
			chkAddcolumns.checked = false;
			ShowEditLayoutArea();
			//paintTcBox("chkAddcolumns");
			editcloselayout.innerText = "Edit Layout";
			editcloselayout.title = "Edit List Layout";
		}
		}catch(e){}		
		 
	}
	

	function processFindXML(cSourceXML, cQueryString)
	{
		var oNodeArray=null;
		var oNode=null;
		var cDestNode='';
		var cSourceNode='';

		var oSourceXML = RandomUse; // new ActiveXObject("Msxml2.DOMDocument"); // Create an XML object	
		try {		
		oSourceXML.loadXML(cSourceXML);				
		} catch(e) {}  // ignore errors

		// Remove trailing semicolon if present
		if (cQueryString.charAt(cQueryString.length)==";")
			cQueryString=cQueryString.substr(cQueryString,cQueryString.length-1);  // remove it
					
		// We will parse through the Query String and assign the source nodes
		// to the destination nodes in the detail recordset
			
		// We will split the query string assignments into an array
		oNodeArray = cQueryString.split(";");
					
		// Now loops through the tabs and process the includes
		for (var iCounter=0; iCounter < oNodeArray.length; iCounter++) {
			// Now split up the tab so we can grab the destination node and the source node
			oNode = oNodeArray[iCounter].split("=");  // assignments are seperated by an '=' 
				
			cDestNode = oNode[0];  
			cSourceNode = oNode[1];			
				
			// Node we will attempt to update the detail recordset		
			try {
				QBE.selectSingleNode('QBE/' + cDestNode).text = NodeAttribute(oSourceXML.selectSingleNode('data/z:row'),cSourceNode);
			} catch(e) {
				//alert(e.description);
				QBE.selectSingleNode('QBE/' + cDestNode).text = "";
			}
				
				
		}
			
	}
	
	function hgEditSelectPart(cIDField, cDescriptionField, cNumberField){
		var oArray = GetPart();
		if(oArray!=null){
			try{
				var oDR=QBE;
				var oXML= RandomUse; // new ActiveXObject("Msxml2.DOMDocument");
				try{
					oXML.loadXML(oArray[1]);
				}catch(e){}
				
				if(cIDField!=null && cIDField!=''){
					var cID = 'QBE/' + cIDField;
					oDR.selectSingleNode(cID).text=NodeAttribute(oXML.selectSingleNode('data/z:row'),'partguid');
				}
				if(cDescriptionField!=null && cDescriptionField!=''){
					var cDesc = 'QBE/' + cDescriptionField;
					oDR.selectSingleNode(cDesc).text=NodeAttribute(oXML.selectSingleNode('data/z:row'),'partdescription');
				}
				if(cNumberField!=null && cNumberField!=''){
					var cNum = 'QBE/' + cNumberField;
					oDR.selectSingleNode(cNum).text=NodeAttribute(oXML.selectSingleNode('data/z:row'),'partnumber');
				}
			} catch(e){
				//do nothing
			}
		}
	}

//********************************specific to Expanding & Collapsing QBE section**********************************************
//--Global declaration
	var gxmlDoc = null;
	var garrLayoutParts = new Array();
	var arrParts = new Array("HPFrameHL", "HPFrameDL");
	var blnIE5    = false;
	var blnBorder = false;
	var blnTrack  = false;
	var blnDebug  = false;
	var blnMoved  = false;
	
	var userAgent = navigator.userAgent;
	var MSIEIndex = userAgent.indexOf("MSIE");
	if (userAgent.indexOf("Win")  != -1 &&
		userAgent.indexOf("MSIE") != -1 &&
		userAgent.substring((MSIEIndex + 5),(MSIEIndex + 6)) > 4)
	{
		blnIE5 = true;
	}
	
	//--Object declaration
	function objPart(strPartName, strState, strOrder)
	{
		this.name	= strPartName;
		this.state	= strState;
		this.order	= strOrder;
	}
	function showHideContent(id,bOn,bMouseOver)
	{
		var bMO = false;
		var oContent = document.all.item(id+"Content");
		var oImage   = document.all.item(id+"Tab3");
		
	
		if (!oContent || !oImage) return;
	
		if (event.srcElement && event.srcElement.src)
		{
			bMO = (event.srcElement.src.toLowerCase().indexOf("_mo.gif") != -1);
			bOn = (oContent.style.display.toLowerCase() == "none");
		}
	
		// If the user passed in a mouse over status, we will overide
		// the default, this will allow you to byPass the highlighting or
		// or force it to hightlight
		
		if (bMouseOver==true)
			bMO=true;
		else if(bMouseOver==false)
			bMO=false;
	
		if (bOn == false)
		{
			oContent.style.display = "none";
			oImage.src = "images/expand" + (bMO? "_mo.gif" : ".gif");
		}
		else
		{
			oContent.style.display = "";
			oImage.src = "images/collapse" + (bMO? "_mo.gif" : ".gif");
		}
	
		for (var i = 0; i < garrLayoutParts.length; i++)
		{
			if (id == garrLayoutParts[i].name)
				garrLayoutParts[i].state = bOn ? "EXPAND" : "COLLAPSE";
		}
	
		if (event.srcElement)
			saveState();
		
	}

	function setBorder(id,bOn)
	{
		var oTab    = document.all.item(id+"Tab");
		var oTab1   = document.all.item(id+"Tab1");
		var oTab2   = document.all.item(id+"Tab2");
		var oTab3   = document.all.item(id+"Tab3");
		var oBorder = document.all.item(id+"Content");
	
		if (!oTab || !oTab1 || !oTab2 || !oTab3 || !oBorder) 
			return;
	
		if (bOn)
		{
			oBorder.style.borderColor = "#003366";
			oTab.bgColor = "#003366";
			oTab1.src    = "images/curve_mo.gif";
			oTab2.color  = "#FFFFFF";
			if (oBorder.style.display == "none")
				oTab3.src = "images/expand_mo.gif";
			else
				oTab3.src = "images/collapse_mo.gif";
		}
		else
		{		
			oBorder.style.borderColor = blnBorder? "#003366" : "#ffffff";
			oTab.bgColor = "#CCCCCC";
			oTab1.src	 = "images/curve.gif";
			oTab2.color  = "#003366";
			if (oBorder.style.display == "none")
				oTab3.src = "images/expand.gif";
			else
				oTab3.src = "images/collapse.gif";
		}
	}
	
	function saveState()
	{
	
		var udoLayout = oLayout;
	
		for (var i = 0; i < garrLayoutParts.length; i++)
			udoLayout.setAttribute(garrLayoutParts[i].name, (garrLayoutParts[i].state + "," + garrLayoutParts[i].order));
		
		try{
			udoLayout.save("HPLayoutStore");
		}catch(e){
			alert(e.message);
		}
		
	}

	

	function loadSavedShowHide()
	{
		var udoLayout = oLayout;
		if (!udoLayout)
			return;
	
	
		udoLayout.load("HPLayoutStore");
			
		for (var i = 0; i < garrLayoutParts.length; i++)
		{
			var strAttr = udoLayout.getAttribute(garrLayoutParts[i].name);
			if (strAttr)
			{
				var strstate = strAttr.split(',')[0];
				if (strstate)
				{
					if (strstate == "EXPAND")
						showHideContent(garrLayoutParts[i].name, true);
					else if (strstate == "COLLAPSE")
						showHideContent(garrLayoutParts[i].name, false);
				}
			}
		}
	}
	
//********************************************end QBE Expanding & Collapseing************************************************				
//*******************************************************************************
// HTMLEncode
//*******************************************************************************
	function HTMLEncode(cText) {
		var oRegExp;
	
		try {
			cText = Trim(cText);
		}
		catch (e) {
		}
	
		oRegExp = new RegExp("'", "g");
		cText = cText.replace(oRegExp, "&lsquo;");
		oRegExp = new RegExp("\"", "g");
		cText = cText.replace(oRegExp, "&quot;");
	
		return cText;
	}
//************************************************************************************
function htmlEncode2(cString){
	//replace all greater than signs
	if(cString.indexOf('>') > -1){
		do{
			cString = cString.replace('>', '&gt;');
		}
		while (cString.indexOf('>') > -1)
	}

	//replace all less than signs
	if(cString.indexOf('<') > -1){
		do{
			cString = cString.replace('<', '&lt;');
		}
		while (cString.indexOf('<') > -1)
	}
	
	//replace all single quotes	
	if(cString.indexOf('\'') > -1){
		do{
			cString = cString.replace('\'', "&apos;");
		}
		while (cString.indexOf('\'') > -1)
	}

	return cString;
}

function ValidateQBE(){
	//Checks Query Fields to ensure valid entries 
	
		var cFld = '';
		var cVal = '';
		var cLbl = '';
		var oFldNode;
		var oFldType;
	
		
		try{
			var oNodeUpper = QBE.selectSingleNode('QBE/currentpage');
			
			while(oNodeUpper.nextSibling){
				oNodeFld = oNodeUpper.nextSibling;
				oNodeOpr = oNodeFld.nextSibling;			
				oNodeUpper = oNodeOpr.nextSibling;
				
				if(oNodeFld.text!=''){
					cFld = oNodeFld.nodeName;
					cVal = oNodeFld.text;
					var cType = QueryColAttribute(DIVQBEContents.systemid, DIVQBEContents.templateid,cFld,'type','');
					if(cType=='integer'){
						if(!IsNumeric(cVal)){
							cLbl = QueryColAttribute(DIVQBEContents.systemid, DIVQBEContents.templateid,cFld,'label','');
							alert('You must enter a numeric value for the ' + cLbl + ' field.');
							return false;
						}					
					}
				}
			}


		} catch(e){
			//alert(e.description);
			return true;

		}	
		return true;
	
}









/*  OLD FUNCTIONS TO DELETE


	function DrawFindQBE(cButtonText){
		
	
		var cHTML = '';
		var oNode;
		var oParentNode;
		var i;
		var cLabel;
		var cLabelData;
		var cLabelSize;
		var cDataType;
		var cFilterField='';
		var bShowAll = true;
		var cBOBlank=''; // boolean option
		var cBOTrue=''; // boolean option
		var cBOFalse=''; // boolean option

		if(!cButtonText || cButtonText == '') cButtonText = 'Go';
		
		//setup XML object		
		oParentNode = QBEData.selectSingleNode('hgXML');		
			
		//build Query Content DIV
		cHTML += '<div id=\"HPFrameHLContent\" style=\"width:100%;height:10;border-bottom:#ffffff 1px solid;border-left:#ffffff 1px solid;border-right:#ffffff 1px solid;\">';
		cHTML += '<table width=\"100%\" border=\"0\" bgcolor=\"#165189\" cellpadding=\"1\" cellspacing=\"1\">';
		cHTML += '<tr>';
		cHTML += '<td valign=\"top\" colspan=\"100%\">';
		cHTML += '<table border=\"0\" width=\"100%\" cellspacing=\"0\">';
		
		if(oParentNode.childNodes.length > 0){		
			//loop through all QBE values and draw appropriate items	
			for(i=0; i<oParentNode.childNodes.length; i++){
				oNode = oParentNode.childNodes.item(i);
				var bLastItem=(i==(oParentNode.childNodes.length-1));
				
				//only display labels that are set to visible
					if(oNode.attributes.getNamedItem('visible').text == 'True'){				 
					
						//cache variables
							cLabel = oNode.attributes.getNamedItem('label').text;
							cLabelData = oNode.attributes.getNamedItem('id').text;
							cDataType = oNode.attributes.getNamedItem('type').text;
							cFilterField = oNode.attributes.getNamedItem('filterfield').text;

						//check joined field
							cJoinedField = oNode.attributes.getNamedItem('joinedfield').text;
							if(cJoinedField > ''){
								try{
									oTempNode = QBEData.selectSingleNode('hgXML/fielddata[@id=\'' + cJoinedField + '\']');
									cJoinedFieldDataType = oTempNode.attributes.getNamedItem('type').text;
									cJoinedFieldData = oTempNode.attributes.getNamedItem('id').text;
									
									try{
										if(oTempNode.attributes.getNamedItem('originaltype').text == 'security'){
											m_oSecurityElement = eval('cbo'+cLabelData);
										}
									}catch(e){ }
									
								}catch(e){} //ignore errors
							}else{
								cJoinedFieldDataType = '';
								cJoinedFieldData = '';
								cOrigFldType = '';
							}
							
							if(cDataType=='boolean'){
								try{
									cLabel = oNode.firstChild.attributes.getNamedItem('label').text;
									cBOBlank = oNode.firstChild.attributes.getNamedItem('blank').text;
									cBOFalse = oNode.firstChild.attributes.getNamedItem('false').text;
									cBOTrue = oNode.firstChild.attributes.getNamedItem('true').text;
								} catch(e){}
							}					
					
						//default field size if no size given
							cLabelSize = 20;
						
						//failsafe if no Label was found
							if(cLabel == '') cLabel = oNode.attributes.getNamedItem('id').text;
						
						//Start Row
							cHTML += '<tr class=\"formLabel\">';
						
						//Label
							cHTML += '<td class="formLabel" width="28%" nowrap>&nbsp;' + cLabel + ':</td>';
											
						//Operator
							cHTML += buildOperator(cLabelData,cLabel,cDataType,cBOBlank,cBOFalse,cBOTrue,cJoinedFieldDataType);
						
						//Input						
							cHTML += buildInput(cLabelData,cLabelSize,cDataType,bLastItem,cJoinedField,cJoinedFieldDataType,cJoinedFieldData,cFilterField);
							cHTML += '</tr>';
						
						//clear variables
							cJoinedField = '';
							cJoinedFieldDataType = '';
							cJoinedFieldData = ''
							cLabel = '';
							cLabelData = ''
							cDataType = '';
							cBOBlank = '';
							cBOFalse = '';
							cBOTrue = ''
							cOrigFldType = '';
							cFilterField = '';
				}
			}
		}else{
			cHTML += '<tr class=\"formLabel\">';
			cHTML += '<td width="25%">No query set.  Check query XML key.</td>';
			cHTML += '</tr>';
			
		}
		
		//finish table & add Clear/Process buttons
		cHTML += '</tr>';
		cHTML += '<td nowrap align=\"right\" bgcolor=\"#F0F4F7\" colspan=\"100%\">';
		cHTML += '</table>';
		cHTML += '</td>';
		cHTML += '</tr>';
		cHTML += '</table>';
		cHTML += '</div>';
				
		//return results to DIV
		DIVQBEContents.innerHTML = cHTML;
		return;
		
	}
 
 
 	function GetFieldLabelFromXMLForQBE(cField){
		var oFieldNode = QBEData.selectSingleNode('hgXML/fielddata[@id="' + cField + '"]');
		if(oFieldNode!=null){
			try{
				var cLbl = oFieldNode.attributes.getNamedItem('label').text;
				return cLbl;
			} catch(e){
				return cField;
			}
		} else {
			return cField;
		}
	}
	
*/
