<script type="text/JavaScript">
<!--
{literal}
// open a popup at the center of the screen
function centeredPopup(url, width, height, options) {
	var top=(screen.height - height) / 2;
	var left=(screen.width - width) / 2;
	window.open(url,"","top="+top+",left="+left+",width="+width+",height="+height+","+options);
}

// Some new functions for dynamic forms
// enable the secondary input if the comparison type is in/not in
function enableSecondaryInput(cmpType, primaryInput, secondaryInput) {
	switch (cmpType.options[cmpType.selectedIndex].value) {
		case 'ni' :
		case 'in' : 
			secondaryInput.disabled=false;
			break;
		default :
			secondaryInput.disabled=true;
			break;
	}
} // end of enableSecondaryInput(cmpType, primaryInput, secondaryInput)

// check that a date is written correctly
checkDate_regexp = {/literal}{$internal_date_format_js}{literal}
function checkDate(input) {
	result_array = checkDate_regexp.exec(input.value);
	if ((result_array != null) && (result_array[0] == input.value)) {
		return true;
	} else {
		alert('{/literal}{$ERROR.invalid_date|addslashes}{literal}');
		return false;
	}
} // end of checkDate(input)
{/literal}
//-->
</script>

<!-- <form method="get" action="query.php" name="query" onSubmit="return checkSavedQueries(this)"> -->

{if $mpfile->project_data.project_id == PUBLIC_PROJECT_ID}
	{assign var=simpleSearch value=1}
{else}
	{assign var=simpleSearch value=0}
{/if}

<!-- DEBUG -->
<form method="GET" action="query.php" name="query" onSubmit="">
	<table border="0" cellspacing="0" cellpadding="7" hspace="0" width="70%">
		<TR valign="top">
			<td colspan="100">
				<table border="0" width="100%">
					<tr valign="bottom">
						<td COLSPAN="2">
							{if $simpleSearch}
								{$TITLE.simple_search} :
							{else}
								{$TITLE.advanced_search} : 
									<i>
										{$mpfile->project_data.project_name}
									</i>
							{/if}
							<!-- &nbsp;<a href="{$smarty.server.PHP_SELF}?op=query&form=advanced">{$STRING.QUERY.AdvancedQueryPage}</a>  -->
							{$STRING.choose_a_project_for_advanced_search} : 
							<SELECT onChange="javascript:window.location.href='query.php?op=query&id=' + (this.options[this.selectedIndex].value)" NAME="domain">
							{foreach key=k item=v name=list_projects from=$list_of_project}
								{if $k == $domain_id}
								<OPTION SELECTED title="" value="{$k}">
								{else}
								<OPTION title="" value="{$k}">
								{/if}
									{$v}
								</OPTION>
							{/foreach}							
							</SELECT>
						</td>
					</tr>
				</table>
			</td>			
		</TR>
		<tr>
			<td colspan=100>
				<hr size="1">
			</td>
		</tr>
		{foreach key=k item=v name=left_panel from=$fc}
			{if $smarty.foreach.left_panel.iteration is odd}
			<!--
				<TR>
					<TD colspan="6">
						<hr>
					</TD>					
				</TR>
			-->
				<TR valign=top>
			{/if}
				<TD align=right width="15%">
					<!-- POPUP of field properties-->
					<font size="1">
						<a 
							onClick="javascript:centeredPopup('{$smarty.server.PHP_SELF|dirname}/popup_field_properties.php?op=show&fid={$v.field_conf_id}', {$popup_field_properties_width}, {$popup_field_properties_height}, 'resizable=yes')"
						>
							<img class="helper" src="{$template_path}/images/smalltxt.gif" alt="?" >
						</a>
					</font>
					<B>{$v.title} :</B>					
				</TD>
				<TD width="85%">
					{build_dynamic_input 
						field_conf=$v 
						name=$v.field_name
						value=''
						mpfile=$mpfile 
						multiple=1
						read_only=0
						override_system=1 
						query_context=1 
						prepare_options=1
					}
				</TD>
				<TD>
				&nbsp;&nbsp;&nbsp;
				</TD>				
			{if $smarty.foreach.left_panel.iteration is even}
				</TR>				
			{/if}
		{/foreach}
{if $no_comments==1}
{else}
				<TR valign=top>
							<TD align=right width="15%">
					<!-- POPUP of field properties-->
					<B>{$STRING.BUGDISPLAY.comments} :</B>					
				</TD>
				<TD width="85%">
					<TEXTAREA NAME="primary_input_comment" COLS="{$default_textarea_width}" ROWS="{$default_textarea_height}"  ></TEXTAREA>
					<BR>{$STRING.comparison} <SELECT  onChange="javascript:enableSecondaryInput(this, form.elements['primary_input_comment'], form.elements['secondary_input_comment'])" NAME="cmptype_comment">
<OPTION SELECTED title="" value="like">{$STRING.comparison_type_name.like}</OPTION>
<OPTION  title="" value="one_word">{$STRING.comparison_type_name.one_word}</OPTION>
<OPTION  title="" value="all_words">{$STRING.comparison_type_name.all_words}</OPTION>
<OPTION  title="" value="eq">{$STRING.comparison_type_name.eq}</OPTION>
<OPTION  title="" value="ne">{$STRING.comparison_type_name.ne}</OPTION>
<OPTION  title="" value="gt">{$STRING.comparison_type_name.gt}</OPTION>
<OPTION  title="" value="lt">{$STRING.comparison_type_name.lt}</OPTION>
<OPTION  title="" value="ge">{$STRING.comparison_type_name.ge}</OPTION>
<OPTION  title="" value="le">{$STRING.comparison_type_name.le}</OPTION>
<OPTION  title="" value="in">{$STRING.comparison_type_name.in}</OPTION>
<OPTION  title="" value="ni">{$STRING.comparison_type_name.ni}</OPTION>
</SELECT>

<INPUT TYPE="TEXT" size=40 disabled=true  NAME="secondary_input_comment" VALUE={$STRING.disabled}>
				</TD>
				<TD>
				&nbsp;&nbsp;&nbsp;
				</TD>				
				</TR>				
{/if}		
		<TR> <!-- BUTTON : MEET ALL CONDITIONS -->
			<TD colspan=6 align=center>
				<A onClick="javascript:document.forms['query'].meet_all_conditions.checked =
						((document.forms['query'].meet_all_conditions.checked == true)? false:true);" 
					onmouseover="javascript:this.style.color = '#006699'"
					onmouseout="javascript:this.style.color = 'black'"
				>
				{$STRING.meet_all_conditions} : </A>
				<input name="meet_all_conditions" type="checkbox" value="1" checked=true>				
			</TD>
		</TR>
		{if $DiaMeter=="fee"}
		<TR>
			<TD colspan=6 align="left">
				<input name="stat" type="checkbox" value="1" >				
				<A onClick="javascript:document.forms['query'].stat.checked =
						((document.forms['query'].stat.checked == true)? false:true);" 
					onmouseover="javascript:this.style.color = '#006699'"
					onmouseout="javascript:this.style.color = 'black'"
				>
				{$STRING.statistics} </A>
				<SELECT name="stat_field">
					{foreach key=k item=v name=left_panel from=$fc}
						<OPTION value="{$v.field_name}">{$v.title}</OPTION>
					{/foreach}
				</SELECT>
				<input name="weight" type="checkbox" value="1" >				
				<A onClick="javascript:document.forms['query'].weight.checked =
						((document.forms['query'].weight.checked == true)? false:true);" 
					onmouseover="javascript:this.style.color = '#006699'"
					onmouseout="javascript:this.style.color = 'black'"
				>
				{$STRING.weighted} </A>
				<SELECT name="weight_field">
					{foreach key=k item=v name=left_panel from=$fc}
						<OPTION value="{$v.field_name}">{$v.title}</OPTION>
					{/foreach}
				</SELECT><br/>
				&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="RADIO" VALUE="isPie"   NAME="ChartSelect" checked=true><A onClick="javascript:document.forms['query'].ChartSelect[0].checked = true" 
				>{$STRING.QUERY.isPie} &nbsp;&nbsp;</A> <INPUT TYPE="RADIO" VALUE="isBar"   NAME="ChartSelect"><A onClick="javascript:document.forms['query'].ChartSelect[1].checked =true" 
				>{$STRING.QUERY.isBar} &nbsp;&nbsp;</A>
			</TD>
		</TR>
		{/if}
		<TR>
			<TD>
				{$STRING.order_by_field_name} : 
				<SELECT name="order">
					{foreach key=k item=v name=left_panel from=$fc}
						<OPTION value="{$v.field_name}">{$v.title}</OPTION>
					{/foreach}
				</SELECT>
				<br>
				{$STRING.sort_order} : <br/>
				<INPUT type="radio" name="sort" value="asc" checked=true> 
				<A onClick="javascript:document.forms['query'].sort[0].checked = true" >{$STRING.asc}</A> 
				&nbsp;&nbsp;&nbsp;<br/>
				<INPUT type="radio" name="sort" value="desc">
				<A onClick="javascript:document.forms['query'].sort[1].checked = true" >{$STRING.desc} </A>
			</TD>
		</TR>
	</table>
	<br>
	<br>
	{if $smarty.session.uid}
		{$STRING.QUERY.SaveThisQueryAs}: <input maxlength="40" type="text" name="savedqueryname">
		<br><br>
	{/if}
	{if not $simpleSearch}
		<input type="hidden" name="project_id[]" value="{$mpfile->project_data.project_id}">
	{/if}
	<input type="hidden" name="op" value="doquery">
	<input type="hidden" name="savedqueryoverride" value="0">	
	<input type="submit" value="{$STRING.search}">
	<input type="reset" value="{$STRING.reset}">	
</form>

{if count($queries)}
	<br><br>
	<b>
		{$STRING.QUERY.SavedQueries}
	</b>
	<br>
		{section name=query loop=$queries}
		<a href="{$smarty.server.PHP_SELF}?{$queries[query].saved_query_string}">
			{$queries[query].saved_query_name}
		</a> (<a 
			href="{$smarty.server.PHP_SELF}?op=delquery&queryid={$queries[query].saved_query_id}&form=simple" 
			onClick="return confirm('{$STRING.QUERY.SureDeleteSavedQuery}');">{$STRING.delete}</a>)<br>
	{/section}
{/if}
