<!DOCTYPE HTML >
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<title></title>
	<!--MqRelPath--><link rel="stylesheet" type="text/css" href="../../theme/css/censusmain.css"/><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" type="text/css" href="<BASE_VD>/theme/css/censusmain.css"/></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqsysutils.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqsysutils.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/window.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/window.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/cmqsysmsg.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/cmqsysmsg.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery-1.7.1.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery-1.7.1.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/jquery/jquery-ui.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/jquery/jquery.ui.core.js"></MqAbsPath-->
	<!--MqRelPath--><link rel="stylesheet" href="../../js/jquery/jquery.ui.all.css"><!--/MqRelPath--><!--MqAbsPath><link rel="stylesheet" href="<BASE_VD>/js/jquery/jquery.ui.all.css"></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqlist.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqlist.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/keylistener.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/keylistener.js" ></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqformelements.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqformelements.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/mqviewfields.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/mqviewfields.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/autosuggest.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/autosuggest.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/CMqHTTPRequest.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/CMqHTTPRequest.js"></script></MqAbsPath-->
	<!--MqRelPath--><script type="text/javascript" src="../../js/VNChoiceField.js"></script><!--/MqRelPath--><!--MqAbsPath><script type="text/javascript" src="<BASE_VD>/js/VNChoiceList.js"></script></MqAbsPath-->

	<script type="text/javascript" src="../../js/jquery/jquery.ui.dialog.js"></script>
	
	<script type="text/javascript" src="../../js/cmqlookupitemint.js"></script>
	<script type="text/javascript" src="../../js/initlookupitemint.js"></script>

	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
	<style>
  
		.hidden {display:none !important;}
 
		.filters-menu {
			width: 500px;
			padding:20px;
			background-color:white;
			border-radius:4px;
			border:1px solid #cccccc;
			height:225px;
			overflow:auto;
		}

		.filter {
			height:24px;
			margin-bottom:10px;
			display:inline-block;
			width:100%;
			transition:border-color 0.5s ease;
		}

		.filter-field-text {
			font-family: "Open Sans", sans-serif;
			font-size:12px;
			width:175px;
			height:17px;
			border: #A9B4C4 1px solid;
			padding:2px 1px 2px 6px
		}

		.filter-value {
			width:180px;
			display:inline-block;
			position:relative;
		}

		.filter-value input {
			font-family: "Open Sans", sans-serif;
			font-size:12px;
			width:165px;
			height:17px;
			border: #A9B4C4 1px solid;
			padding:2px 1px 2px 6px;
			position:relative !important;
		}

		.filter-operator {
			font-family: "Open Sans", sans-serif;
			font-size:12px;
			height:23px;
			width:80px;
			border: #A9B4C4 1px solid;
		}

		.remove-filter-button {
			border-radius:2px;
			display:inline-block;
			width:10px;
			color:#dd3333;
			border:1px solid #BDBECE;
			background-color:#F9FAFD;
			text-decoration:none;
			font-size:12px;
			font-weight:200;
			padding:2px 3px;
			margin-left:2px;
			margin-right:2px;
			position:relative;
		}

		.remove-filter-button:hover, .remove-filter-button:active {
			background-color:#FDF5CE;
			border:1px solid #FBCB09;
		}

		.add-filter-container {
			display:block;
			height:20px;
		}
		.add-filter-button {
			border-radius:2px;
			display:inline-block;
			color:#3498db;
			border:1px solid #BDBECE;
			background-color:#F9FAFD;
			text-decoration:none;
			font-size:13px;
			font-weight:600;
			padding:2px 5px;
			position:relative;
		}
		.add-filter-button i {
			font-weight:200;
			font-size:11px;
		}
		.add-filter-button:hover, .add-filter-button:active {
			background-color:#FDF5CE;
			border:1px solid #FBCB09;
		}
		.ui-autocomplete {
			font-family: "Open Sans", sans-serif;
			font-size:12px;
			max-height: 100px;
			overflow-y: auto;
			overflow-x: hidden;
		}
		.ui-menu-item {
			border:1px solid transparent;
		}
		.filter-value .BrowseAlternateChoiceListState1, .filter-value .BrowseAlternateChoiceListState1:hover {
			position:absolute;
			top:-2px;
			left:auto;
			right:2px;
		}
  </style>
	<script type="text/javascript">
	
		// always define this object for the system messages
		var objSysMsg = new CMqSysMsg();
		var m_objMqButton=new MqButton();
		var objMqStr = new MqString();
		var m_strWinID=parseInt( Math.random() * 1000);
		var objRequest=new CMqHTTPRequest_js();
	
		var m_objLookupItemInfoColl=new Array();

		var m_objAutoSuggest = new CMqAutoSuggest();
		m_objAutoSuggest.Initialize("", document);

		var fields = JSON.parse(objMqStr.DecodeHTML(objRequest.Get("SQE.ASP?WCI=GetFields", true)));
		CloseWindowByEscKey(false);
		var m_objMainRef=parent;
		
		function LoadSettings()
		{
			var strFilters=m_objMainRef.m_objSLInput.GetAdhocFilters();
			if(strFilters) {
				var arrFilters = JSON.parse(strFilters);
				if(arrFilters.length > 0) {
					arrFilters.forEach(addExistingFilter);
				} else {
					addFilter();
				}
			} else {
				addFilter();
			}

			var objTBar=m_objMainRef.objFrames.GetFrameWindow(m_objMainRef.TOOLBAR_FRAME_ID);
			if(objTBar){
				var objSortsMain = objTBar.document.getElementById('cbosort');
				var objSortsAdv = document.getElementById('sorts');
				CopySelectValues(objSortsMain, objSortsAdv);
				
				var objLayoutsMain = objTBar.document.getElementById('cbolayout');
				var objLayoutsAdv = document.getElementById('layouts');
				CopySelectValues(objLayoutsMain, objLayoutsAdv);
			}
			
			var objChkDD=document.getElementById("chkDD");
			
			if(objChkDD){
				if(m_objMainRef.m_objSLDD.DDIsEnabled()){
					objChkDD.checked=true;
				}else{
					objChkDD.checked=false;
				}
			}
			
			g_MqRef.ResMgr.ProcessAll(document);
		}
		
		function CopySelectValues(objFromCbo, objToCbo)
		{
			if(objFromCbo){
				if(objToCbo){
					objToCbo.options.length=objFromCbo.options.length;
					for(var x=0; x<objFromCbo.options.length;x++){
						objToCbo.options[x] = new Option(objFromCbo.options[x].text, objFromCbo.options[x].value);
						if(objFromCbo.options[x].selected){
							objToCbo.options[x].selected=true;
						}
					}					
				}
			}
		}
		
		function ApplyAdvSettings()
		{
			var blnForceReloadSL=false;
			
			var objTBar=m_objMainRef.objFrames.GetFrameWindow(m_objMainRef.TOOLBAR_FRAME_ID);
			
			if(objTBar){
				var objSortsMain = objTBar.document.getElementById('cbosort');
				var objSortsAdv = document.getElementById('sorts');
				
				var objLayoutsMain = objTBar.document.getElementById('cbolayout');
				var objLayoutsAdv = document.getElementById('layouts');
				
				var objChkDD=document.getElementById("chkDD");
				if(objChkDD){
					if(objChkDD.checked){
						m_objMainRef.m_objSLDD.EnableDD();
					}else{
						m_objMainRef.m_objSLDD.DisableDD();
					}
				}
				if(SetSelectValues(objSortsAdv, objSortsMain)){
					//reload the querybar
					blnForceReloadSL=true;
				}
				
				if(SetSelectValues(objLayoutsAdv, objLayoutsMain)){
					//reload the querybar
					blnForceReloadSL=true;
				}

				SubmitFilters(blnForceReloadSL);
				CloseWindow();
			}
		}
		
		function SetSelectValues(objFromCbo, objToCbo)
		{
			if(objFromCbo){
				if(objToCbo){
					if(objToCbo.value!=objFromCbo.value){
						for(var x=0; x<objFromCbo.options.length;x++){
							if(objToCbo.options[x].value==objFromCbo.value){
								objToCbo.options[x].selected=true;
							}
						}
						objToCbo.value=objFromCbo.value;
						return true;
					}
				}
			}
			return false;
		}
		
		function ToggleChk()
		{
			var objChk=document.getElementById("chkDD");
			if(objChk){
				objChk.checked=!objChk.checked;
			}
		}
		
		var filterID=1;

		function removefilter(ID) {
			$("#filter"+ID).remove();
			if(!($(".filter").length)) {
				addFilter();
			}
		}

		function addFilter() {
			
			var strFilterID = "filter"+filterID;
			$('<div class="filter" id="'+strFilterID+'">'+
					'<input class="filter-field-text ui-autocomplete-input" type="text" placeholder="' + 
						g_MqRef.RESX["QRY_FILTER.SELECT_FLD"] + '"> '+
					'<input type="hidden" class="filter-field" value="-1">' +
					'<select class="filter-operator" id="'+strFilterID+'-operator">' +
						objRequest.Get("SQE.ASP?WCI=GetOperators") + 
					'</select> ' + 
					'<div class="filter-value" id="'+strFilterID+'-value">' +
						objRequest.Get("SQE.ASP?WCI=GetValue&FLD=-1&OP=0") + 
					'</div>' +
					'<a class="remove-filter-button" title="' + g_MqRef.RESX["QRY_FILTER.DELETE_ROW"] + 
						'" href="#" onclick="removefilter('+filterID+');">'+
						'<i class="fa fa-times"></i>'+
					'</a>'+
				'</div>'
			).insertBefore($(".add-filter-container"));

			$('#'+strFilterID+'>.filter-field-text').autocomplete({
				source: fields,
				minLength:0,
				change: function(event,ui){
					$(this).val((ui.item ? ui.item.value : ""));
				},
				select: function(event, ui) {
					$('#'+strFilterID+'>.filter-field').val(ui.item.field);
					updateFilterValueHTML(strFilterID);
				}
			});

			$('#'+strFilterID+'>.filter-operator').change(function() {
				updateFilterValueHTML(strFilterID);
			});

			//Apply filters when pressing enter in value input
			$("#"+strFilterID+"-value input").keypress(function (e) {
				var keyCode = e.which;
				if(keyCode == 13)
				{
					ApplyAdvSettings();
				}
			});

			//Place focus on newly added field
			//$('#'+strFilterID+'>.filter-field-text').focus(); 
			
			//Add autocomplete event handler
			$('#'+strFilterID+'>.filter-field-text').on("click focus", function(){$(this).autocomplete("search","")});

			filterID++;
		}

		function updateFilterValueHTML(strFilterID) {
			var strOperator = $('#'+strFilterID+'-operator').val();
			var strField = $('#'+strFilterID+'>.filter-field').val();
			var strRequest = "SQE.ASP?WCI=GetValue&FLD="+ strField +"&OP=" + strOperator;
			var strHTML = objRequest.Get(strRequest);
			strHTML = strHTML.replace(/IDREF/g,strFilterID);

			$("#"+strFilterID+"-value").html(strHTML);
		}

		function addExistingFilter(objFilter) {
			var strFilterID = "filter"+filterID;
			addFilter();
			$('#'+strFilterID+'>.filter-field-text').val(objFilter.fieldText);
			$('#'+strFilterID+'>.filter-field').val(objFilter.field);
			$('#'+strFilterID+'>.filter-operator').val(objFilter.operator);
			updateFilterValueHTML(strFilterID);
			$('#'+strFilterID+'>.filter-value input').val(objFilter.value);
		}

		function SubmitFilters(blnForceReloadSL) {
			var arrFilters = [];
			
			$(".filter").each(function(i, elem) {
				var objFilter = new Object();
				objFilter.ID = $(elem).attr("id");
				objFilter.field = $(elem).children(".filter-field").val();
				objFilter.fieldText = $(elem).children(".filter-field-text").val();
				objFilter.operator = $(elem).children(".filter-operator").val();
				objFilter.operatorText = $(elem).children(".filter-operator").children(':selected').text();
				objFilter.value = $(elem).find(".filter-value input").val();
				if(objFilter.field != -1) {
					arrFilters.push(objFilter);
				}
			})
			
			m_objMainRef.m_objSLInput.SetAdhocFilters(JSON.stringify(arrFilters));
			var objTBarB=m_objMainRef.objFrames.GetFrameWindow(m_objMainRef.TOOLBARB_FRAME_ID);
			objTBarB.updateFilters(blnForceReloadSL);
		}

		function decodeEntities(encodedString) {
			var textArea = document.createElement('textarea');
			textArea.innerHTML = encodedString;
			return textArea.value;
		}
		
		</script>
</head>
<body class="MainBackgroundPopup" onload="LoadSettings()" onclick="m_objAutoSuggest.Hide()">
<div id="ifraCal" style="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;width:150px;height:170px;padding:0px;z-index:10;"></div>
<iframe id="ifrAutoSuggest" src="blank.htm" 
	style="position: absolute;width: 400px; height: 170px;z-index: 16;display: none; border: 1px solid gray;overflow: none" frameborder="0" ></iframe>

	<div class="TopToolBarPopup">
		<table width="98%" class="TopToolBarWizard">
			<tr>
				<td>
					<i style='font-size:36px' class='fa fa-cog'></i>
				</td>
		        <td valign="top" style="padding-top:15px; padding-left:10px" width="100%">
		            <div class="WizardTitle"><script type="text/javascript">document.write(g_MqRef.RESX["ADV_QRY_TITLE"]);</script></div>
		            <div class="WizardDescription"><script type="text/javascript">document.write(g_MqRef.RESX["ADV_QRY_DESC"]);</script></div>
		        </td>
		    </tr>
		</table>
	</div>

	<table id="tblMain" marginwidth="0" cellspacing="0" cellpadding="0" border="0" style="margin-left:10px;margin-right:10px;width: 95%;" >
		<tr >
			<td align="center" valign="top" style="width: 65%;padding-bottom: 10px;padding-right:15px;" class="normalfield">
				<div class="filters-menu">
					<script type="text/javascript">document.write(g_MqRef.RESX["ADV_QRY_FILTERS"]);</script><br />
					<div class="add-filter-container">
						<a class="add-filter-button" title="Add filter row" href="#" onclick="addFilter();">
								<i class="fa fa-plus"></i> 
								<span translate="yes" data-res="QRY_FILTER.ADD_ROW"></span>
						</a>
					</div>
				</div>
			</td>
			<td align="center" style="padding-bottom: 10px;" class="normalfield">
				<div style="width:240px;height:225px;padding:20px;background-color:white;border-radius:4px; border:1px solid #cccccc;">
				
					<script type="text/javascript">document.write(g_MqRef.RESX["TOOLBAR.SORT_LBL"]);</script><br />
					<select id="sorts" class="ComboBoxWidth"></select><br /><br />
					
					<script type="text/javascript">document.write(g_MqRef.RESX["TOOLBAR.LAYOUT_LBL"]);</script><br />
					<select id="layouts" class="ComboBoxWidth"></select><br /><br />
					
				
					<script type="text/javascript">
						if(m_objMainRef.m_blnAllowDisableDD){
							var blnWriteChk=true;
							
							if(m_objMainRef.mstrCurrentViewFolder=="Resources%5FLibrary" || m_objMainRef.mstrCurrentViewFolder=="Resources%5FSWAssets"){
								var objTBar=m_objMainRef.objFrames.GetFrameWindow(m_objMainRef.TOOLBAR_FRAME_ID);
								if(objTBar){
									var objQueryList=objTBar.document.getElementById("cboQueries");
									var lngSelectedQuery=objQueryList.value;
									
									if(lngSelectedQuery!=10){
										blnWriteChk=false;
									}
								}
							}
								
							if(blnWriteChk){
								document.write('<input type="checkbox" id="chkDD" checked><span onclick="ToggleChk()">' + g_MqRef.RESX["ENABLE_ASSET_DD"] + '</span>');
							}
						}
					</script>
				</div>
			</td>			
		</tr>
	</table>
	<table  style="margin-left:10px;margin-right:10px;position:absolute;right:0px" border="0">
		<tr>
			<td align=right>
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("OK", g_MqRef.RESX["BUTTON_OK"], 'ApplyAdvSettings()', "", 32, "", g_MqRef.RESX["BUTTON_OK"], 90);</script>
			</td>
			<td align=right>
				<script type="text/javascript">m_objMqButton.WriteTextButtonHTML("Close", g_MqRef.RESX["BUTTON_CLOSE"], 'CloseWindow()', "", 32, "", g_MqRef.RESX["BUTTON_CLOSE"], 90);</script>
			</td>
		</tr>
		</tbody> 
	</table>
	<div style="visibility: hidden;display:none">
		<div id="dialog-modal" style="width:100%;height:100%;padding:0px;margin:0px;overflow:hidden">
			<iframe id="dialog-modal-url" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto"></iframe>
		</div>
		<div id="dialog-modal-orig-width" name="dialog-modal-orig-width" style="display:none"></div>
		<div id="dialog-modal-orig-height" name="dialog-modal-orig-height" style="display:none"></div>
	</div>
</body>
</html>