<?php
session_start();
$username = $_SESSION['staff'];


if($_SESSION['staff']!= null)
{
?>
	
<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="calendar-setup.js"></script>
<script type="text/javascript" src="calendar-en.js"></script>
<style type="text/css"> @import url("calendar-win2k-cold-1.css"); </style>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>

<center>
<h2>Daily Bookstore Management - Apply Leave</h2>
</center>

<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset>
<legend><img src="Picture/leave.gif" width="30" height="30">Leave</legend>
<table>
<td valign="top">
<a href="addleave.php"><img src="Picture/apply.gif" width="30" height="30" alt="apply"><a href="addleave.php">Apply Leave</a><br/>
<?php
if(($_SESSION['staff_level']=='IT Staff')||($_SESSION['staff_level']=='IT Staff')){;
?>
<br/>
<a href="leavemain.php"><img src="Picture/leave.gif" width="30" height="30" alt="leave"><a href="leavemain.php">New Leave List</a><br/>
<br/>
<a href="leaveoldlist.php"><img src="Picture/record.gif" width="30" height="30" alt="apply"><a href="leaveoldlist.php">Leave Record</a><br/>
<?php
}else{
}
?>
</td>
</tr>
</table>
</fieldset>
</td>

<td width="75%">
<center>
<form name="form" method="post" action="addleaveaction.php">
<fieldset style="width:80%">
<legend><img src="Picture/leave.gif" width="30" height="30">Apply Leave</legend>

<table align="center">
<tr>
<td>Form ID: </td>
<td>
<?php
include("leaveID.php");
$leaveNo = "$index";
echo "<input type='hidden' name='leaveNo' ID='leaveNo' value='$leaveNo'>$leaveNo";
?>
</td>
</tr>

<tr>
<td>Your Name: </td>
<td><input type="text" name="staffName" id="staffName" onfocus="getleave()">
</td>
</tr>

<script language="Javascript">
$().ready(function() {
	$("#staffName").autocomplete("staffauto.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
</script>

<tr>
<td>Period: </td>
<td><input type="text" id="cal-field-1" name="leaveStartDate"/>
			<button type="submit" id="cal-button-1">Date</button>
			<script type="text/javascript">
			Calendar.setup({
			inputField : "cal-field-1",
			button : "cal-button-1",
			align : "Tr"
			});
			</script> To 
			<input type="text" id="cal-field-2" name="leaveEndDate"/>
          <button type="submit" id="cal-button-2">Date</button>
          <script type="text/javascript">
            Calendar.setup({
              inputField    : "cal-field-2",
              button        : "cal-button-2"
            });
          </script></td>
</tr>

<tr>
<td>Time: </td>
<td><input type="text" name="leaveStartTime" id="leaveStartTime" value="HH:MM:SS"> To <input type="text" name="leaveEndTime" id="leaveEndTime" value="HH:MM:SS"></td>
</tr>

<script language="Javascript">
var xmlHttp;
function GetXmlHttpObject(){
    
    var xmlHttp=null;
    try {
        
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     } catch (e) {
         
     //Internet Explorer
        try {
        
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
        
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
     }
    return xmlHttp;
}

function getleave(){
	
    xmlHttp=GetXmlHttpObject();
    if(xmlHttp==null) {
        
        alert ("Browser does not support HTTP Request");
        return;
    }
    var name=document.getElementById("staffName");
    var url="getleave.php?";
    var n="value="+name.value;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    xmlHttp.send(n);

function stateChanged() { 
    
    if (xmlHttp.readyState=="4" || xmlHttp.readyState=="200"){
    
        var str_text=xmlHttp.responseText;
        if (str_text != ""){
            //alert("没有这个名字的数据");
			//}
        //else {
            
            str_text = str_text.split('|');
			
            document.getElementById("staffPayLeave").value = str_text[0];
			document.getElementById("leaveBalance").value = str_text[1];
        }
		}
    } 
}
</script>

<tr>
<td>Your No Pay Leave (Hours): </td>
<td><input type="text" name="staffPayLeave" ID="staffPayLeave" size="25" readonly></td>
</tr>

<tr>
<td>No Pay Leave Left (Hours): </td>
<td><input type="text" name="leaveBalance" ID="leaveBalance" size="25" readonly></td>
</tr>

<tr>
<td>Reason: </td>
<td><textarea id="leaveReason" name="leaveReason" rows="5" cols="80" maxlength="10000"></textarea></center></td>
</tr>

<tr>
<td colspan="2" align="center">
<input type="button" name="Submit" value="Submit" onclick='submitcheck(staffName.value,leaveStartDate.value,leaveEndDate.value,leaveReason.value);'>
<input type="submit" name="Cancel" value="Cancel">
</td>
</tr>

<script language="Javascript">
	function submitcheck(a,b,c,d){
	if((a=="")||(b=="")||(c=="")||(d="")){
	alert("Please check your leave apply details.");
	}else{
	this.form.submit();
	}
}
</script>

</table>
</fieldset>
</form>
</center>

<center>
<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved.
<br/>
Website:<a href="../bookstore" target="_blank">www.dailybook.com.my
</div>
</center>

</body>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>