<?php
include("../session.php");
include("../connect.php");

$user=$_SESSION['admin'];
$id=$_GET["id"];
//echo "admin success!!!";
				
?>
<html>
<head>
<link href="header.css" rel="stylesheet" type="text/css"/>
<link type="text/css" rel="stylesheet" href="overflow.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
$(".flip").click(function(){
    $(".panel").slideToggle("slow");
  });
/*$(".flip2").click(function(){
    $(".panel2").slideToggle("slow");
  });
$(".flip3").click(function(){
    $(".panel3").slideToggle("slow");
  });*/
});
</script>
</head>
<div id="content2">
<body>
<!-----------------Outer table--------------->
<table width=1000 border=0 cellspacing=10 cellpadding=3 >
<tr>
	<td colspan=2 >
	<?php include("head.php");?>
	</td>
	</tr>
<tr>
	<td colspan=2>
			<div class=main>&nbsp;&nbsp;>>
			<a href="<?php echo"admin.php";?>">&nbsp;Home&nbsp;</a>>>
			<a href="<?php echo"viewCompany.php";?>">&nbsp;Listing Company&nbsp;</a>>>
			&nbsp;Update License&nbsp;
			</div></td>
	</tr>
<tr>
	<td valign=top colspan=2>
	<!--------------------Inner table 2----------------------->
	<?php
	$query=mysql_query("SELECT * from company where id='$id'");
		
	$display=mysql_fetch_array($query);
	
	$id=$display['id'];
	$name=$display['cName'];
	$cPerson=$display['cPerson'];
	$eDate=$display['expireDate'];
	
	$pQuery=mysql_query("select * from price order by id desc");
	$displayP=mysql_fetch_array($pQuery);
	$price=$displayP['price'];
	?>
	<table class=corners cellspacing=1 cellpadding=10 width=80% align=center>
	<tr>
		<td>
	
	<fieldset>
		<legend>Update License <b><?php echo $id;?></b></legend>
	<form action="<?php echo "updating.php";?>" method="POST" onsubmit="return finalCheck();">
		<table align=center width=400 cellpadding=5 cellspacing=3>
		<tr>
			<td>Company Name :</td>
			<td><input type="hidden" name="id" value="<?php echo $id;?>" />
			<?php echo $name; ?></td>
			</tr>
		<tr>
			<td>In charge Person :</td>
			<td><?php echo $cPerson; ?></td>
			</tr>
		<tr>
			<td>Expire Date :</td>
			<td><input type="hidden" name="expire" value="<?php echo $eDate; ?>">
			<font color=red><?php echo $eDate; ?></font></td>
			</tr>
		<tr>
			<td>Update Year :</td>
			<td>
			<input type="hidden" name="price" value="<?php echo $price;?>"/>
			<select name="year" id="year2" onchange="calculatePay(this.value,expire.value,price.value)" style="width:101;">
				<option value="a">Select Year:</option>
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				</select>
			</td>
			</tr>
		<tr>
			<td>Payment Type :</td>
			<td><select name="pType" style="width:101;">
					<option value="cash">Cash</option>
					</select>
			</td>
			</tr>
		<tr>
			<td><b>Next Expire Date :</b></td>
			<td><font color=green><div id=next2></div></font></td>
			</tr>
		<tr>
			<td><b>Total Payment :</b></td>
			<td><div id="total">RM 0</div></td>
			</tr>
		<tr>
			<td colspan=2 align=center>
			<input type="submit" value="Update" />
			<input type="reset" value="Reset" onclick="empty();" />
			</td>
			</tr>
		</table>
		</form>
	</fieldset>
	
		
		</td>
		</tr>
	</table>
	<!----------------------End inner table 2-------------------->
	
	</td>
	</tr>
</table>
<!-----------------------End outer table-------------------------->
</div>
<script type="text/javascript">
function finalCheck(){
	if(document.getElementById('year2').value=="a"){
		alert("Please select update year.");
		return false;
	}
	
	var where_to= confirm("Do you really want update license");
	if (where_to==false){
		return false;
	}
	
	return true;
}
function empty(){
	document.getElementById('total').innerHTML = "";
	document.getElementById('next2').innerHTML = "";
}
function calculatePay(year,expire,price){
	if(year=="a"){
		year=0;
		document.getElementById("total").innerHTML = "";
		document.getElementById("next2").innerHTML = "";
		return;
	}
	var payment = parseInt(year) * parseInt(price);

	//document.write(payment);
	document.getElementById("total").innerHTML = "RM "+payment;
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('next2').innerHTML=xmlhttp.responseText;
    }
  }
  
xmlhttp.open('GET','valiLicense.php?year='+year+'&expire='+expire,true);

xmlhttp.send();

}


</script>

</body>
</html>