<?php
//Include the head file
require("../../inc/header.inc");
?>

<script language="JavaScript">
	//the function is called when the page is refresh
	function  page_refresh()
	{
		//in&out,fromdate,todate,fromhour,fromminute,fromsecond,tohour,tominute,tosecond
		
		var down_date_from=document.myform.sel_date_from.value;
		var down_date_to=document.myform.sel_date_to.value;
		var in_out=document.myform.sel_in_out.value;
		var scrollY=document.body.scrollTop;
		var from_h=document.myform.from_hour.value;
		var from_m=document.myform.from_minute.value;
		var from_s=document.myform.from_second.value;
		var to_h=document.myform.to_hour.value;
		var to_m=document.myform.to_minute.value;
		var to_s=document.myform.to_second.value;
		var secondsFrom=from_h*3600+from_m*60+from_s;
		var secondsTo=to_h*3600+to_m*60+to_s;
		if(secondsFrom>secondsTo)
			alert("Time error");
		else
		{	
			if(down_date_from<=down_date_to)
				down_date_to=down_date_from;
			var ur="&from_hour="+from_h+"&from_minute="+from_m+"&from_second="+from_s;
			ur=ur+"&to_hour="+to_h+"&to_minute="+to_m+"&to_second="+to_s+"&sel_in_out="+in_out;	
  		var urll='<?php echo"$PHP_SELF";?>?sel_date_from='+down_date_from+'&sel_date_to='+down_date_to+'&scroll_y='+scrollY+ur;
			window.location.href=urll;
		}
		
	}
</script>
<base target="e1_general_down">
<?php
//File index
echo "<table><tr><td><nobr>";
echo "$strTitlePerformance > MSC > E1";
echo "</td></tr></table>";
echo "<div style=\"position:absolute;top:0;left:840;\">";
$helpId="3.2.3";
showHelp($helpId);
echo "</div>";
?>

<!--================Initial the variables=====================-->
<?php
if(!isset($scroll_y))
	$scroll_y=0;
if(!isset($sel_date_from))
	$sel_date_from=0;
if(!isset($sel_date_to))
	$sel_date_to=0;
if(!isset($sel_in_out))
	$sel_in_out=2;
if(!isset($from_hour))
	$from_hour="00";
if(!isset($from_minute))
	$from_minute="00";		
if(!isset($from_second))
	$from_second="00";
if(!isset($to_hour))
	$to_hour="23";
if(!isset($to_minute))
	$to_minute="59";
if(!isset($to_second))
	$to_second="59";				
//selection date define
$day0=date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
$day1=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-1,date("Y")));
$day2=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-2,date("Y")));
$day3=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-3,date("Y")));
$day4=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-4,date("Y")));
$day5=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-5,date("Y")));
$day6=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-6,date("Y")));	
?>	

<form action="e1_general_down.php" method="post" name="myform">
<table>
	<tr>
		<!--=========================in&out selection=============================-->
		<td>
			<select name="sel_in_out" onChange="javascript:page_refresh()">
				<?php
					$in_out_string=array("In","Out","In&Out");
					for($i=0;$i<3;$i++)
					{
						if($i==$sel_in_out)
							echo "<option selected value=$i>$in_out_string[$i]</option>";
						else
							echo "<option value=$i>$in_out_string[$i]</option>";	
					}
				?>
			</select>
		</td>
		<!--============================date from selection=============================-->
		<td>
			<select name="sel_date_from" onChange="javascript:page_refresh()">
			<?php
				for($i=0;$i<7;$i++)
		  	{
			 		if($i==$sel_date_from)
		  			echo "<option selected value=$i>${day.$i}</option>";			
		  		else
		  			echo "<option value=$i>${day.$i}</option>";
				}
			?>
			</select>to
		</td>
		<td>
			<!--=========================date to selection=================================-->
			<select name="sel_date_to" onChange="javascript:page_refresh()">
			<?php
				for($i=0;$i<=$sel_date_from;$i++)
		  	{
			 		if($i==$sel_date_to)
		  			echo "<option selected value=$i>${day.$i}</option>";			
		  		else
		  			echo "<option value=$i>${day.$i}</option>";
				}
			?>
			</select>
		</td>
		<!--============================the search button=================================-->
		<td>
			<div onClick="javascript:myform.submit();" style="cursor:hand">
				<img align=absBottom border=0 src="../../images/search.gif">
				Search
			</div>
		</td>		
		<?php
			//=====================add some blank unit to justify the table====================
			for($i=0;$i<22;$i++)
			{
				echo "<td>&nbsp</td>";
			}
			//========================wether the select time slot is one day==================
			$slot=$sel_date_from-$sel_date_to+1;
			//echo "slot:$slot<br>";
			if($slot==1)
			{
				//===============================from_hour text=================================
				echo "<td><input type=\"hidden\" name=\"from_hour\" value=$from_hour size=\"2\" maxLength=\"2\"></td>";
				//===============================from_minute text================================
				echo "<td><input type=\"hidden\" name=\"from_minute\" value=$from_minute size=\"2\" maxLength=\"2\"></td>";
				//===============================from_second text================================
				echo "<td><input type=\"hidden\" name=\"from_second\" value=$from_second size=\"2\" maxLength=\"2\"></td>";
				//===============================to_hour text=====================================
				echo "<td><input type=\"hidden\" name=\"to_hour\" value=$to_hour size=\"2\" maxLength=\"2\"></td>";
				//===============================to_minute text===================================
				echo "<td><input type=\"hidden\" name=\"to_minute\" value=$to_minute size=\"2\" maxLength=\"2\"></td>";
				//==============================to_second text====================================
				echo "<td><input type=\"hidden\" name=\"to_second\" value=$to_second size=\"2\" maxLength=\"2\"></td>";
			}		
			else
			{
				//===============================from_hour hidden=================================
				echo "<td><input type=\"hidden\" name=\"from_hour\" value=$from_hour></td>";
				//===============================from_minute hidden================================
				echo "<td><input type=\"hidden\" name=\"from_minute\" value=$from_minute></td>";
				//===============================from_second hidden================================
				echo "<td><input type=\"hidden\" name=\"from_second\" value=$from_second></td>";
				//===============================to_hour hidden=====================================
				echo "<td><input type=\"hidden\" name=\"to_hour\" value=$to_hour></td>";
				//===============================to_minute hidden===================================
				echo "<td><input type=\"hidden\" name=\"to_minute\" value=$to_minute></td>";
				//==============================to_second hidden====================================
				echo "<td><input type=\"hidden\" name=\"to_second\" value=$to_second></td>";
			}
		?>
</tr>
</table>
<table>
<tr>
	
	<td align="right">
		<!--==========================the print button=============================-->
		<div onClick="window.print();" style="position:absolute;top:90;left:840;cursor:hand">
			<img align=absBottom border=0 src="../../images/printer.gif" width="16" height="16">
		</div>
	</td>
</tr>
</table>
</form>