<script>
function submitMessagingFilter() {
	var filters = [];
	var statusFilters = [];
	var chkEl = document.getElementsByName("status[]");
	if (chkEl) {
		for(var i=0; i<chkEl.length; i++) {
			if (chkEl[i].checked) {
				statusFilters.push(chkEl[i].value);
			}
		}
	}
	filters.push("status:"+statusFilters.join(","));
	var messageFilters = [];
	var chkEl = document.getElementsByName("message[]");
	if (chkEl) {
		for(var i=0; i<chkEl.length; i++) {
			if (chkEl[i].checked) {
				messageFilters.push(chkEl[i].value);
			}
		}
	}
	filters.push("message:"+messageFilters.join(","));
	var chkEl = document.getElementsByName("resolution");
	var resolution = "";
	if (chkEl) {
		for(var i=0; i<chkEl.length; i++) {
			if (chkEl[i].checked) {
				resolution = chkEl[i].value;
				break;
			}
		}
	}
	filters.push("resolution:"+resolution);

	var dateBegin = dojo.byId("date-begin").value;
	var dateEnd = dojo.byId("date-end").value;
	var oDateBegin = dojo.date.stamp.fromISOString(dateBegin);
	var oDateEnd = dojo.date.stamp.fromISOString(dateEnd);
	var comparison = dojo.date.compare(oDateBegin,oDateEnd);
	if (comparison > 0) {
		alert("<?=__('Invalid date range.')?>");
		return;
	}
	filters.push("dateStatus:"+dateBegin+","+dateEnd);
	messagingFilters = filters.join(";");

	dojo.xhrPost({
		url: "<?=$this->baseUrl?>/messaging.raw/set-filters",
		handleAs: "json",
		content: {
			"filters": messagingFilters,
		},
		load: function (data) {
			messagingGridReload();
		},
		error: function (er) {
			alert('err: ' + er);
		}
	});
}

</script>
<div style="float:left;">
<fieldset><legend><?=__('Date Range')?></legend>
	<div class="formRow">
		<dt><label for="date-begin"><?=__('Begin Date')?></label></dt>
		<?=$this->formDateText('dateBegin',date('Y-m-d',strtotime($this->dateBegin)),array('id'=>'date-begin'))?>
	</div>
	<div class="formRow">
		<dt><label for="date-end"><?=__("End Date")?></label></dt>
		<?=$this->formDateText('dateEnd',date('Y-m-d',strtotime($this->dateEnd)),array('id'=>'date-end'))?>
	</div>
</fieldset>
<fieldset><legend><?=__('Status')?></legend>
	<div class="formRow">
	<?foreach ($this->statusOptions as $status):?>
		<div style="float:left;"><input type="checkbox" name="status[]" value="<?=$status?>" <?=isset($this->status[$status])?'checked="checked"':''?> /> <?=$status?> &nbsp; &nbsp;</div>
	<?endforeach;?>
	</div>
</fieldset>
<fieldset><legend><?=__('Message')?></legend>
	<div class="formRow">
	<?foreach ($this->messageOptions as $key=>$value):?>
		<div style="float:left;"><input type="checkbox" name="message[]" value="<?=$key?>" <?=isset($this->message[$key])?'checked="checked"':''?> /> <?=$value?> &nbsp; &nbsp;</div>
	<?endforeach;?>
	</div>
</fieldset>
<fieldset><legend><?=__('Resolution')?></legend>
	<div class="formRow">
		<div style="float:left;"><input type="radio" name="resolution" value="0" <?=($this->resolution=='0')?'checked="checked"':''?> /> Resolved &nbsp; &nbsp;</div>
		<div style="float:left;"><input type="radio" name="resolution" value="1" <?=($this->resolution=='1')?'checked="checked"':''?> /> Unresolved &nbsp; &nbsp;</div>
		<div style="float:left;"><input type="radio" name="resolution" value="2" <?=($this->resolution=='2')?'checked="checked"':''?> /> Resolved & Unresolved &nbsp; &nbsp;</div>
	</div>
</fieldset>
	<br style="clear:left"/>
	<div style="text-align:center;margin-top:10px;">
		<input type="button" value="<?=__('OK')?>" onClick="submitMessagingFilter()" />
	</div>
</div>
