<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Form_GridTransport.php");

if ($modedt=='' and $actionmode=='edit')
	$modedt = 'add_vehicleservice';
	
if ($modedtparts=='' and $actionmode=='edit')
	$modedtparts = 'add_vehicleparts';
	
	
$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT FI_vehicle as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}


if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");

//User Access
$querylog=" select ifNull(FI_VehicleApp,0) As FI_VehicleApp, ifNull(FI_VehicleDel,0) As FI_VehicleDel, ".
          " ifNull(FI_VehicleMod,0) As FI_VehicleMod from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Access Mode On Insert/Edit/Delete
$InsMode = '';
if ($FI_VehicleApp == 0)
	$InsMode = ' disabled ';
	
if(!isset($actionmode))
$actionmode='';

if ($perpage == '') $perpage = 30;
if ($startrange == '') $startrange = 0;

if($actionmode=='edit' or $actionmode=='view'){

	$query_edit="select null, vehicle_make
			,vehicle_model,vehicle_year,vehicle_color,vehicletype_id,fueltype_id,employee_id,vehicle_note
			,vehicle_active,insurance_reference,date_format(insurance_startdate,'%d/%m/%Y'),date_format(insurance_enddate,'%d/%m/%Y'),vehicle_platenumber
			,date_format(vehicle_acquisitiondate,'%d/%m/%Y'),vehicle_odometertype,vehicle_odometeracuisition
			,vehicle_licensereference,date_format(license_startdate,'%d/%m/%Y')
			,date_format(license_enddate,'%d/%m/%Y'),item_picture
			,date_format(permit_startdate,'%d/%m/%Y'),date_format(permit_enddate,'%d/%m/%Y'),date_format(roadpermit_startdate,'%d/%m/%Y'),date_format(roadpermit_enddate,'%d/%m/%Y')
			,date_format(road_startdate,'%d/%m/%Y'),date_format(road_enddate,'%d/%m/%Y')
			,vehicle.ledger_number,vehicle.asset_id,assets.assets_ref,assets_name,ledger_name, vehicle.project_code, project_name
			,engineNbr , chassisNbr, vehicle.staff_code, Staff_fullName
			 from vehicle 
			 left join assets on assets.assets_id = vehicle.asset_id
			 left join ledger on ledger.ledger_number = vehicle.ledger_number
			 left join project on project.project_code = vehicle.project_code
			 left join staff on staff.staff_code = vehicle.staff_code
			 where vehicle_id='".$vehicle_id."'";

	 
	//echo $query_edit;
	$resultedit = mysql_query($query_edit, $connection) or die(mysql_error());
	while($row=mysql_fetch_array($resultedit)){
			
			$vehicle_make 				= $row[1];
			$vehicle_model 				= $row[2];
			$vehicle_year 				= $row[3];
			$vehicle_color 				= $row[4];
			$vehicletype_id 			= $row[5];
			$fueltype_id 				= $row[6];
			$employee_id 				= $row[7];
			$vehicle_note 				= $row[8];
			$vehicle_active 			= $row[9];
			$insurance_reference 		= $row[10];
			$insurance_startdate 		= $row[11];
			$insurance_enddate 			= $row[12];
			$vehicle_platenumber 		= $row[13];
			$vehicle_acquisitiondate 	= $row[14];
			$vehicle_odometertype 		= $row[15];
			$vehicle_odometeracuisition = $row[16];
			$vehicle_licensereference 	= $row[17];
			$license_startdate 			= $row[18];
			$license_enddate 			= $row[19];
			$item_picture 				= $row[20];
			$permit_startdate			= $row[21];
			$permit_enddate				= $row[22];
			$roadpermit_startdate		= $row[23];
			$roadpermit_enddate			= $row[24];
			$road_startdate				= $row[25];
			$road_enddate				= $row[26];
			$ledger_number				= $row[27];
			$asset_id					= $row[28];
			$assets_ref					= $row[29];
			$assets_name1				= $row[30];
			$ledger_name				= $row[31];
			$project_code				= $row[32];
			$project_name				= $row[33];
			$engine_number				= $row[34];
			$chassis_number				= $row[35];
			$staff_code					= $row[36];
			$staff_name					= $row[37];
	}
}



print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<script type="text/javascript" language="javascript">
var tabberOptions = {
  'manualStartup':true,
  'onClick': function(argsObj) {

    var t = argsObj.tabber; /* Tabber object */
    var id = t.id; /* ID of the main tabber DIV */
    var i = argsObj.index; /* Which tab was clicked (0 is the first tab) */
    var e = argsObj.event; /* Event object */
	
	if (id == 'tab1') document.getElementById('PTabIndex').value = i;
  },

  /* Optional: set an ID for each tab navigation link */
  'addLinkId': true
};

</script>
<script type="text/javascript" language="javascript">

function showlistProject(str){

	vProjectCode = encodeURIComponent(document.getElementById('project_code').value);
	window.open('List_SorProject.php?frm='+str+'&item=&PProject_Code='+vProjectCode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistledgers(str){
	x=document.vehicle;
	var ledger=x.ledger_number.value;
	win = window.open('List_AccountNo.php?PLedger_Number='+ledger+'&item='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	
	win.creator = self;
	win.focus();
}
function showlistassets(str){
	x=document.vehicle;
	var ledger=x.assets_ref.value;
	win = window.open('List_Asset.php?PLedger_Number='+ledger+'&item='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	
	win.creator = self;
	win.focus();
}

function showlistStaff(){
	 window.open('List_Staff.php?frm=2','mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function editmode () {
	document.vehicle.actionmode.value='edit';
	document.vehicle.action="Form_Vehicle.php";
	document.vehicle.submit();
}

function addvehicle () {

            ClearForm('All');
			document.vehicle.actionmode.value='insert';
			document.vehicle.action="Form_Vehicle.php";
			document.vehicle.submit();
}


function addservice(){
if (document.vehicle.vehicle_id.value!='')
	{
	var str = '';
	var vehicleid = document.vehicle.vehicle_id.value;
	win = window.open('Form_VehicleServices.php?vehicle_id='+vehicleid, 'Form_VehicleSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	//win = window.open('Form_VehicleServices.php?vehicle_id='+vehicleid);		
	}
}

function addparts(){
if (document.vehicle.vehicle_id.value!='')
	{
	var str = '';
	var vehicleid = document.vehicle.vehicle_id.value;
	win = window.open('Form_VehicleParts.php?vehicle_id='+vehicleid, 'Form_VehicleParts', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	//win = window.open('Form_VehicleParts.php?vehicle_id='+vehicleid);		
	}
}

function CancelRecord () {


if (confirm ( "Are you sure you want to Cancel Page?")){
	ClearForm('All');
	
	document.vehicle.actionmode.value='';
			document.vehicle.action="Form_Vehicle.php";
				document.vehicle.submit();
}
}




function CheckFields(){
	x=document.vehicle;
	var vehicle_platenumber=x.vehicle_platenumber.value;
	if (vehicle_platenumber=='')
		{
			alert('Please fill plate number')
			x.vehicle_platenumber.focus();
return 0;
		}
else 		
	return 1;
}


function SubmitRecord() {
	var x=document.vehicle;
	var vehicle_platenumber=x.vehicle_platenumber.value;
	if (vehicle_platenumber=='')
	{
		alert('Please fill plate number')
		x.vehicle_platenumber.focus();
		return 0;
	}
	else {
		document.vehicle.action="Form_Vehicle_Actions.php";
		document.vehicle.submit();
	}
}


function ClearPage(){
	var x = document.vehicle;
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x.message.value == '';
		x.actionmode.value='';
		x.action='Form_Vehicle.php';
		x.submit();
	}	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.vehicle;
	
	x.message.value='';
	x.vehicle_id.value='';
	x.vehicle_make.value='';
	x.vehicle_model.value='';
	x.vehicle_year.value='';
	x.vehicle_color.value='';
	x.vehicletype_id.value='';
	x.fueltype_id.value='';
	x.employee_id.value='';
	x.vehicle_note.value='';
	x.vehicle_active.value='';
	x.insurance_reference.value='';
	x.insurance_startdate.value='';
	x.insurance_enddate.value='';
	x.vehicle_platenumber.value='';
	x.vehicle_acquisitiondate.value='';
	x.vehicle_odometertype.value='';
	x.vehicle_odometeracuisition.value='';
	x.vehicle_licensereference.value='';
	x.license_startdate.value='';
	x.license_enddate.value='';
	x.road_startdate.value='';
	x.road_enddate.value='';
	x.permit_startdate.value='';
	x.permit_enddate.value='';
	x.roadpermit_startdate.value='';
	x.roadpermit_enddate.value='';
	x.vehicleservice_id.value='';
	x.actionmode.value='';
	x.modedt.value='';
	x.modedtparts.value='';
	x.project_code.value = '';
	x.project_name.value = '';
	x.engine_number.value = '';
	x.chassis_number.value = '';
	x.staff_code.value = '';
	x.staff_name.value = '';
	x.service_id.value='';
	x.fuel_id.value='';
}


function searchforvehicle(){
    ClearForm('All');
    x = document.vehicle;
    win = window.open('Form_VehicleSearch.php', 'Form_VehicleSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}
   function PrintPreview() {
	var str = '';
	
	str = 'Form_VehiclePreview.php';
	window.open(str);

}



function ShowDetail() {
		if(document.vehicle.ShowDt.checked){
			document.vehicle.Ledger_ShowDt.value=1;

		}
		else
		{
			document.vehicle.Ledger_ShowDt.value=0;

		}
}

function SubmitRecordParts() {
    var x = document.vehicle;
	
	var vmode=x.modedtparts.value;	
	
		
	if (x.item_code.value =="")
	{
	alert("Part is mandatory!");
	x.item_description.focus();
	return 0;
	}
	
	x.actionmode='edit';
	
	
	
	x.action="Form_Vehicle_Actions.php";
	x.submit();
	}
	
function SubmitRecordFuel(){
	var x = document.vehicle;
	
	x.modedtparts.value = 'SubmitFuel';	
	
		
	if (x.fuel_amount.value =="")
	{
	alert("Amount is Empty!");
		x.fuel_amount.focus();
	return 0;
	}
	
	x.actionmode='edit';
	
	
	
	x.action="Form_Vehicle_Actions.php";
	x.submit();
}
function SubmitRecordService() {
    var x = document.vehicle;
	
	var vmode=x.modedt.value;	
	if (vmode=='add_vehicleservice')
		vmode = 'add_vehicleservice';
	else if (vmode=='edit_vehicleservice')
		vmode = 'edit_vehicleservice';
		
	if (x.service_id.value =="")
	{
	alert("Service is mandatory!");
	x.service_description.focus();
	return 0;
	}
	x.action="Form_Vehicle_Actions.php?actionmode=edit&modedt="+vmode;
	x.submit();
	}
	
	

function showitem(str){
  window.open('Form_VehicleItemlist.php?str='+str,'mywindow','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function showservice(str){

  window.open('Form_servicelist.php?str='+str,'mywindow','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function UpdateDetailParts(Code){
	x = document.vehicle;
	x.modedtparts.value='edit_vehicleparts';
	x.vehiclepart_id.value=Code; 
	 
	x.action="Form_Vehicle.php?vTabFocus=Parts";
	x.submit();
}

function DeleteDetailParts(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehicle;
		x.modedtparts.value='delete_vehicleparts';
		x.vehiclepart_id.value=Code; 
		x.action="Form_Vehicle_Actions.php?vTabFocus=Parts";
		x.submit();
	}
}

function UpdateDetail(Code){
	x = document.vehicle;
	x.actionmode.value='edit';
	x.modedt.value='edit_vehicleservice';
	x.vehicleservice_id.value=Code; 
	x.action="Form_Vehicle.php?vTabFocus=Services";
	x.submit();
}

function DeleteDetail(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehicle;
		x.actionmode.value='edit';
		x.modedt.value='delete_vehicleservice';
		x.vehicleservice_id.value=Code; 
		x.action="Form_Vehicle_Actions.php";
		x.submit();
	}
}


function UpdateDetailFuel(Code){
	x = document.vehicle;
	x.modedtparts.value='edit_vehiclefuel';
	x.fuel_id.value=Code; 
	 
	x.action="Form_Vehicle.php?vTabFocus=Fuel";
	x.submit();
}

function DeleteDetailFuel(Code){


if (confirm ( "Are you sure you want to Delete This Record ?"))
	{
		x = document.vehicle;
		x.modedtparts.value='delete_vehiclefuel';
		x.fuel_id.value=Code; 
		x.action="Form_Vehicle_Actions.php?vTabFocus=Fuel";
		x.submit();
	}
}


function UploadImg(vform){
	var vehicle_id = document.vehicle.vehicle_id.value;
	var service_id = document.vehicle.vehicleservice_id.value;
	
	if (vehicle_id == ''){
		alert('Staff Code Cannot Be Empty!');
		return 0;
	} else {
		win = window.open('UploadImages.php?vform='+vform+'&sc='+staffcode, 'Upload', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');		
		win.creator = self;
		win.focus();	
	}
}

function closeImg(index){
	var imgId = 'imgFrame'+index;
	document.getElementById(imgId).style.display = 'none';
}

function showImg(index){
	var imgId = 'imgFrame'+index;
	document.getElementById(imgId).style.display = 'block';
}

function navigateDiv(startrange,perpage, totalrows){
	let vehicle_id = document.vehicle.vehicle_id.value;
	if (totalrows != '*'){
		let result=totalrows % perpage;
		if (result == 0) result = perpage;
		startrange=totalrows-result;
	}
	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)
			{
				let data = xmlhttp.responseText.split("[BRK]");
				document.getElementById('tyrediv').innerHTML = data[1];				
			}
		}
	xmlhttp.open("GET","Form_Vehicle_Actions.php?actionmode=navigate&vehicle_id="+vehicle_id+"&startrange="+startrange+"&perpage="+perpage,true);
	xmlhttp.send();  
}

</script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Vehicle</title>


<script type="text/javascript" src="dropdown.js"></script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

#tyrediv {
	height: 300px;
    width: 915px;
	position: relative;
}
</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="tabs.css">
</head>
<body >
<form enctype="multipart/form-data" method="post" name="vehicle">
<input type=hidden name='actionmode' value='$actionmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='vehicle_id' value='$vehicle_id'>
<input type=hidden name='modedt' value='$modedt'>
<input type=hidden name='modedtparts' value='$modedtparts'>
<input type='hidden' name='PTabIndex' id='PTabIndex' value='$PTabIndex'>
HERE;



if($actionmode==''){
$status='disabled';
$dis='disabled';

}

if($actionmode=='view'){

$status='readonly';
$dis='disabled';

}

if($actionmode=='insert')
$status='';

$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";



echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Vehicle</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

	 
	
echo"<tr><td  height='18'  valign='top' id='content-top2'>";	
echo"</td></tr>";

 
echo"<tr><td align=left  id='content-body'>";


			echo"<table border=0 align=left width=800> <tr  height='35'>";
			
	
			echo"	<td align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type='button'  value='Add Vehicle'";  	
			
			if($actionmode=='insert' or $actionmode=='edit')
			echo "disabled ";
			
			echo"onclick='addvehicle()'  title='Add Vehicle' $InsMode><span><span>Add Vehicle</span></span></button>" ;
/*
echo"	<button type='button'   ";  	
			
			if ($actionmode=='')
						echo " disabled ";	
			
			echo"onclick='addservice()'  title='addservice'  ><span><span>Services</span></span></button>" ;			
			
echo"	<button type='button'  value='Parts'";  	
			
			if ($actionmode=='')
						echo " disabled ";	
			
			echo"onclick='addparts()' title='Parts'  ><span><span>Parts</span></span></button>" ;		*/				
	
echo"           <button type='button' id='btnClear' name='BtnClear' value='Clear Page' ";

echo"  onclick='ClearPage();'  title='Clear Page'><span><span>Clear Page</span></span></button>";

				
echo"           <button type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
				if ($actionmode=='' )
					echo " disabled ";
				echo" onclick='CancelRecord();'  title='Cancel Changes'><span><span>Cancel</span></span></button>";
				
				
		if($actionmode=='view'){
echo"           <button type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
				
				
				echo" onclick='editmode();'  title='Edit Vehicle' /><span><span>Save</span></span></button>";
	}
else	{
echo"           <button type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($actionmode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();'  title='Save Changes' /><span><span>Save</span></span></button>";}

echo"           <button name='btnSearch' type='button' id='btnSearch' value='Search' onclick='searchforvehicle();' title='Search Vehicle' ";
                if ($actionmode=='edit' or $actionmode=='insert') 
				    echo " disabled ";
			
		        echo " /><span><span>Search</span></span></button>";

				
echo" 			<button name='btnPrint' type='button' id='btnPrint' value='Print' onclick='PrintPreview();'   title='Print' ";
				if ($actionmode=='edit' or $actionmode=='insert') echo " disabled ";
						echo" onclick='PrintPreview();'  title='Print' /><span><span>Print</span></span></button>";

						echo"</td>";
			 
		echo"  </tr></table></td></tr>";
		
	 
echo"<tr><td align=center id='content-body'>";

echo"<table border=0 width=90%><tr><td width=3%></td><td>";

echo"	<div class='tabber' id='tab1' style='width:990px; margin-top:10px; float:left; text-align:left;'>";

  echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>vehicle</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:350px; margin-top:5px; border:0px solid gray;'>";


//1st column	  
echo"  
        <table border='0' width='970px' style='' align='left' valign='top'><tr>
		<td width='300px' valign=top>";
echo"<table border='0' style='' align='center' valign='top'>";
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'><span class='style1'>Plate #</span></td><td><input type='text' name='vehicle_platenumber' value='$vehicle_platenumber' $status></td></tr>";		
echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Make</span></td><td><input type='text' name='vehicle_make' value='$vehicle_make' $status></td></tr>";		
echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Model</span></td><td><input type='text' name='vehicle_model' value='$vehicle_model' $status></td></tr>";		
echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Year</span></td><td><input type='text' name='vehicle_year' value='$vehicle_year' $status></td></tr>";		
echo"<tr bgcolor='#F7F7F7'><td><span class='style1'>Color</span></td><td><input type='text' name='vehicle_color' value='$vehicle_color' $status></td></tr>";		

	$query = "select vehicletype_id,vehicletype_description from vehicletype order by vehicletype_description";
	$result = mysql_query($query, $connection);
	

echo"<tr><td><span class='style1'>Vehicle Type</span></span></td><td><select  name='vehicletype_id'  style='width:150px'  $status>";
echo"<option value=''></option>";
while($row=mysql_fetch_row($result)){
	echo"<option value='$row[0]' ";
	if ($vehicletype_id==$row[0])
		echo " selected ";
	echo"	>";
	echo $row[1];
	echo"</option>";
}

echo"</select>";
echo"</td></tr>";		

$query = "select fueltype_id,fueltype_description from fueltype order by fueltype_description";
	$result = mysql_query($query, $connection);
	
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Type of Fuel</span></td><td><select  name='fueltype_id' style='width:150px'  $status>";
echo"<option value=''></option>";
while($row=mysql_fetch_row($result)){
	echo"<option value='$row[0]' ";
		if ($fueltype_id==$row[0])
			echo " selected ";
		echo">";
	echo $row[1];
	echo"</option>";
}

echo"</select>";
echo"</td></tr>";	


echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Odometer Type</span></td><td><select  name='vehicle_odometertype' style='width:150px'  $status>";
echo"<option value=''></option>";
	echo"<option value='Hrs' "; if ($vehicle_odometertype=='Hrs') echo " selected "; echo">Hrs</option>";
	echo"<option value='Km' "; if ($vehicle_odometertype=='Km') echo " selected "; echo">Km</option>";
	echo"<option value='Miles' "; if ($vehicle_odometertype=='Miles') echo " selected "; echo">Miles</option>";

echo"</select>";
echo"</td></tr>";	


echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Driver&nbsp;<span class='style26'></span></span></td>";
	
	$querydriver = "select employee_id,concat(employee_firstname,' ',employee_lastname) from employee order by employee_lastname ";
	$resultdriver = mysql_query($querydriver, $connection);
	
	
	
	echo"     <td ><span class='style1'><select name='employee_id' id='employee_id' style='height:20px; width:150px; font-size:10px;'   $status  >";
				echo"<option></option>";
				while($driver=mysql_fetch_row($resultdriver)){
				echo"<option ";
					if ($employee_id==$driver[0])
						echo " selected ";
					echo" value='$driver[0]'>$driver[1] </option>";
				}
				echo"</select></span></td></tr>";
				
				if ($vehicle_active=='' or $vehicle_active=='1')
						$checked='checked';
						else
						$checked = '';
						
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Active</td><td><input type=checkbox name='vehicle_active' value='1' $checked $status></td></tr>";				
//echo"<tr height='25px' bgcolor=#F7F7F7><td colspan=2 align=center>** Insurance **</td></tr>";				



echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Odometer on acquisition</span></td><td><input type=text name='vehicle_odometeracuisition' value='$vehicle_odometeracuisition' $status></td></tr>";				
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Project Code</span></td><td><input type=text name='project_code' id='project_code' value='$project_code' $status style='width:145px;' readonly>
	<label><span class='style1'><img src='img/scroll-down-1.png' title=' Select Project ' id='assetsaccountnoimg' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistProject('36');\"  />
	</span></label></td></tr>";				
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Project Name</span></td><td><input type=text name='project_name' id='project_name' value='$project_name' $status style='width:170px;' readonly>
	</td></tr>";	
echo"</table>";


echo"</td>";
//2nd column	  
echo"<td width='400px'  valign=top>";
echo"<table>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>License Ref.</span></td><td colspan=2><input type=text name='vehicle_licensereference' value='$vehicle_licensereference' $status></td></tr>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Insurance Ref.</span></td><td colspan=2><input type=text name='insurance_reference' value='$insurance_reference'  $status></td></tr>";				

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Acquisition Date</span></td><td colspan=2>
<input type=text name='vehicle_acquisitiondate' value='$vehicle_acquisitiondate' style='width:100px' $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.vehicle_acquisitiondate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";



echo"<tr bgcolor=#F7F7F7><td align=center colspan=2>Issue</td><td align=center >Expired</tD></tr>";
echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Vehicle License</span></td><td><input type=text name='license_startdate' value='$license_startdate' style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.license_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td>";				
echo"<td><input type=text name='license_enddate' value='$license_enddate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.license_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";				


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>RoadWorthiness</span></td><td><input type=text name='road_startdate' value='$road_startdate' style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.road_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td>";				
echo"<td><input type=text name='road_enddate' value='$road_enddate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.road_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";				

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Insurance Certificate</span></td><td><input type=text name='insurance_startdate' value='$insurance_startdate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.insurance_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td>";				
echo"<td><input type=text name='insurance_enddate' value='$insurance_enddate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.insurance_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";				


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Hackney Permit</span></td><td><input type=text name='permit_startdate' value='$permit_startdate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.permit_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td>";				
echo"<td><input type=text name='permit_enddate' value='$permit_enddate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.permit_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";				


echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Trailer Road Permit</span></td><td><input type=text name='roadpermit_startdate' value='$roadpermit_startdate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.roadpermit_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td>";				
echo"<td><input type=text name='roadpermit_enddate' value='$roadpermit_enddate'  style='width:100px'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.roadpermit_enddate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";		
echo"</td></tr>";	



				echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Note</style></td>";
				echo"<td colspan=2><textarea style='height:30px;width:240px' name='vehicle_note'  $status>$vehicle_note</textarea> </td>";
				echo"</tr>";
				
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Ledger Number</style></td>";
				echo"<td colspan=2><input type='text' name='ledger_number' id='ledger_number' style='width:90px' value='$ledger_number' $status>
				<span class='style1'><img src='img/scroll-down-1.png' title=' Select Ledger ' id='assetsaccountnoimg' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistledgers(10); '  /></span></label>
				";
				
				echo"<input type='text'  $KeyDown_noarray   name='ledger_name' style='width:130px' id='ledger_name'  value='".htmlspecialchars($ledger_name, ENT_QUOTES)."' $status >";
				echo"</td>";
				echo"</tr>";
				
							
echo"<tr  bgcolor='#F7F7F7'><td><span class='style1'>Asset</style></td>";
				echo"<input type='hidden' name='asset_id' id='asset_id' style='width:90px' value='$asset_id'>";
				echo"<td colspan=2><input type='text' name='assets_ref' id='assets_ref' style='width:90px' value='$assets_ref' $status>
				<span class='style1'><img src='img/scroll-down-1.png' title=' Select Assets ' id='assetsaccountnoimg1' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick='showlistassets(1); '  /></span></label>
				";
				
				echo"<input type='text'  $KeyDown_noarray   name='assets_name1' style='width:130px' id='assets_name1'  value='".htmlspecialchars($assets_name1, ENT_QUOTES)."' $status >";
				echo"</td>";
				echo"</tr>";
echo "<tr bgcolor='#F7F7F7'>
				<td><span class='style1'>Staff</style></td>
				<td colspan='2'><input type='text' name='staff_code' id='staff_code' style='width:90px' value='$staff_code' $status>
				<span class='style1'><img src='img/scroll-down-1.png' title=' Select Staff ' id='staff' width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onClick=\"showlistStaff();\"  /></span></label>
				<input type='text'  $KeyDown_noarray   name='staff_name' style='width:130px' id='staff_name'  value='".htmlspecialchars($staff_name, ENT_QUOTES)."' $status ></td>
	</tr>";			
 

echo"</table>";
echo"</td>";
	

//3rd column	  	
echo"<td width='250px' valign=top>";		  
echo"<table>";

echo"<tr  bgcolor='#F7F7F7'><td colspan='2'><span class='style1'>
	Image";
	echo'<input name="MAX_FILE_SIZE" value="102400" type="hidden">';
echo'<input type="file" name="image" >';
echo"</td>
	</tr>";
echo"<tr><td colspan='2'><span class='style1'>";
echo "<img src='photos/vehicle/$vehicle_platenumber/$item_picture' width='200px' height='200px'>";

echo "</td>
	</tr>";
echo "<tr ><td>&nbsp;</td><td></td></tr>";	
echo "<tr bgcolor='#F7F7F7'><td colspan='2'><span class='style1'>Engine No.</span> &nbsp; <input type='text' name='engine_number' id='engine_number' value='".htmlspecialchars($engine_number)."' $status style='width:150px;''></td></tr>";	
echo "<tr bgcolor='#F7F7F7'><td colspan='2'><span class='style1'>Chassis No.&nbsp;</span>  <input type='text' name='chassis_number' id='chassis_number' value='".htmlspecialchars($chassis_number)."' $status style='width:150px;''></td></tr>";	
echo"</table>";
echo"</td>";
echo"</tr>";
echo"</table>";

echo"</div>";
echo"</div>";
	
 

  
  
  
  

  echo"	<div class='tabbertab'>
				<h2 title='Vehicle'>Services</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:350px; margin-top:5px; border:0px solid gray;'>";
 
	
	echo"<table border=0 width='900'>";
echo '<tr><td colspan="9" align="left" valign="top">';


print <<< HERE
       </td>
      </tr>
HERE;


print <<< HERE
		<tr><th height="15" colspan="9" align="center" valign="top"><span class="style3">Add Services</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td colspan='9' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
       <tr>
      <td>
HERE;



if ($vehicleservice_id != ''){
$querydt= " select vehicleservice_id, vehicleservice.vehicle_id, vehicleservice.service_id
			,date_format(vehicleservice_startdate,'%d/%m/%Y') 
			,vehicleservice_reference
			,vehicleservice_note
			,vehicle.vehicle_platenumber,vehicle_make
			,service.service_description
			,concat(service_frequency,' ',service_repeattype,' or ' ,service_odometer,' (odometer unit)')
			,service_status
			,vehicleservice_workshop, vehicleservice_repairAmount, date_format(vehicleservice_dateCompletion,'%d/%m/%Y'), vehicleservice_repairDuration, vehicleservice_kpiScore
			,date_format(service_requestDate,'%d/%m/%Y'), vehicleservice_quotation, vehicleservice_invoice
			from vehicleservice left join vehicle on vehicle.vehicle_id = vehicleservice.vehicle_id
			left join service on service.service_id = vehicleservice.service_id
		    where vehicleservice_id='".$vehicleservice_id."' ";
		
	
    $resultdt = mysql_query($querydt, $connection);
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehicleservice_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$service_id=$rowdt[2];
		$vehicleservice_startdate=$rowdt[3];
		$vehicleservice_reference=$rowdt[4];
		$vehicleservice_note	= $rowdt[5];
		$vehicle_platenumber	= $rowdt[6];
		$vehicle_make			= $rowdt[7];
		$service_description	= $rowdt[8];
		$service_frequency		= $rowdt[9];
		$service_status			= $rowdt[10];
		$service_workshop	 	= $rowdt[11];
		$service_repairAmount 	= $rowdt[12];
		$service_dateCompletion = $rowdt[13] ;
		$service_repairDuration = $rowdt[14];
		$service_kpiScore 		= $rowdt[15];
		$service_requestDate	= $rowdt[16];
		$service_quote			= $rowdt[17];
		$service_invoice		= $rowdt[18];
	}
}

echo"
<input type=hidden name='service_id' value='$service_id'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='vehicleservice_id' value='$vehicleservice_id'>
<input type=hidden name='opener' value='$opener'>";

echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
		  <col width=160>
		  <col width=300>
		  <col width=200><col width=300>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Service&nbsp;<span class='style26'></span></span></td>";
echo"<td><input type='text' name='service_description' $status value='$service_description' size='25'>";
echo"</label></td>";	
echo"<td colspan='2'><label>";
echo"<input type='text' name='service_frequency' $status value='$service_frequency' size='20'>&nbsp;<img src='img/scroll-down-1.png' title=' Select Service '  width='20' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick=showservice()>";
echo"</label></td></tr>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Reference <span class='style26'></span></span></td>";
echo"<td><input type='text' name='vehicleservice_reference' $status value='$vehicleservice_reference' size='25'>";
echo"</label></td>";	
echo"<td colspan='2'></td></tr>";

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Request Date</span></td><td ><input type=text name='service_requestDate' value='$service_requestDate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.service_requestDate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td><td><span class='style1'>Date Sent To Workshop</span></td><td ><input type=text name='vehicleservice_startdate' value='$vehicleservice_startdate'  $status>
 <A HREF='#' onClick=\"displayCalendar(document.vehicle.vehicleservice_startdate,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1' >
 <image src='./img/cal.gif' border=0 align=center ></image></A>
	</td></tr>";				

echo"<tr bgcolor=#F7F7F7 >
			<td><span class='style1'>WorkShop Name</span></td><td><input type=text name='service_workshop' value='$service_workshop'  $status></td>
			<td><span class='style1'>Amount</span></td><td><input type=text name='service_repairAmount' value='$service_repairAmount'  $status></td>
	</tr>";	

echo"<tr bgcolor=#F7F7F7 >
			<td><span class='style1'>Completion Date</span></td><td><input type=text name='service_dateCompletion' value='$service_dateCompletion' readonly $status>
			<A HREF='#' onClick=\"displayCalendar(document.vehicle.service_dateCompletion,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1' ><image src='./img/cal.gif' border=0 align=center ></image></A></td>
			<td><span class='style1'>Service Duration</span></td><td><input type=text name='service_repairDuration' value='$service_repairDuration'  $status></td>
	</tr>";	
	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=3><textarea  name='vehicleservice_note' $status style='width:400px;height:50px'>$vehicleservice_note</textarea></td></tr>";


echo"<tr bgcolor='#F7F7F7'>
		<td><span class='style1'>KPI Score</span></td><td><input type=text name='service_kpiScore' value='$service_kpiScore' $status></td>
		<td valign='center' align='left' ><span class='style1'>Status</span></td>";
echo"<td>";
echo"<select name='service_status' $status>";

if ($service_status=='N' or $service_status=='')
	$s1 = ' selected ';
else	
if ($service_status=='C' )
	$s2 = ' selected ';
else if ($service_status=='S' )
	$s3 = ' selected ';
echo"<option value='N' $s1>Not Completed</option>";
echo"<option value='C' $s2>Completed</option>";
echo"<option value='S' $s3>Skipped</option>";

echo"</select >";
echo" </td></tr>";

echo"<tr bgcolor=#F7F7F7 >
			<td><span class='style1'>Quotation</span></td><td><div><input type='file' name='service_quote' id='service_quote' $status style='width:180px;' />
			<img src='./img/view_file.png' height='20px' width='20px' title='View Image' onclick=\"showImg('1')\"></div>
			
			<div id='imgFrame1' style='display:none;'>
			<div style='width: 100%;height: 100%;position: absolute;background-color: lightgray;top: 0;left: 0;opacity: 0.5;' onclick=\"closeImg('1')\"></div>
			<div style='position: absolute;top: 25%;left: 25%;width: 700px;height: 450px;'>
				<div style='float: right;border: 2px solid darkgray;background-color: lightgray;'><img src='./icon/cancel.png' height='20px' width='20px' title='View Image' onclick=\"closeImg('1')\"></div>
				<div style='border: 2px solid darkgray;width: 94%;height: 100%;'>
				<img id='img12' src='ImageFile.php?id=$vehicleservice_id&img=1' alt='Photo' name='service_quote1'  style='width:100%; height:100%;'>
				</div>
			</div>
			</div>
			</td>
			<td><span class='style1'>Invoice</span></td><td><div><input type='file' name='service_invoice' id='service_invoice' $status style='width:180px;'/>
						<img src='./img/view_file.png' height='20px' width='20px' title='View Image' onclick=\"showImg('2')\"></div>
			<div id='imgFrame2' style='display:none;'>
			<div style='width: 100%;height: 100%;position: absolute;background-color: lightgray;top: 0;left: 0;opacity: 0.5;' onclick=\"closeImg('2')\"></div>
			<div style='position: absolute;top: 25%;left: 25%;width: 700px;height: 450px;'>
				<div style='float: right;border: 2px solid darkgray;background-color: lightgray;'><img src='./icon/cancel.png' height='20px' width='20px' title='View Image' onclick=\"closeImg('2')\"></div>
				<div style='border: 2px solid darkgray;width: 94%;height: 100%;'><img id='img12' src='ImageFile.php?id=$vehicleservice_id&img=2' alt='Photo' name='service_invoice1'  style='width:100%; height:100%;'></div>
			</div>
			</div>	
			</td>
	</tr>";	
	
	echo"</table></td></tr>";	




			
	echo"<tr><td ><table border=0 align=left width=900> <tr bgcolor=#D8D8D8 height='35'>";
		
	

	echo"<td align='center'><button type='button' name='btnPost' id='btnPost'";//post
	echo" onclick='SubmitRecordService();' 	title='Save Changes' /><span><span>Submit Service</span></span></td>";

				
	 
	echo"  </tr></table></td></tr>";

	

		echo"<tr><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0 width='900'>
		<col width=20>
		<col width=20>
		<col width=200>
		<col width=175>
		<col width=100>
		<col width=100>
		<col width=100>
		";
		
		
echo "<tr   class='Search-Label-bg'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style4'>Service&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Frequency&nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Date &nbsp;<span class='style26'></span></span></td>
		<td><span class='style4'>Status</span></td><td><span class='style4'>WorkShop</span></td>
		
      </tr>";
	  
	 
$querydt= " select vehicleservice_id,service_description,vehicleservice_id,vehicle_platenumber, vehicle_make, vehicle_platenumber, date_format(vehicleservice_startdate,'%d/%m/%Y') 
			, vehicleservice_reference  , vehicleservice_note 
			,concat(service_frequency,' ',service_repeattype,' or ' ,service_odometer,' (odometer unit)')
			,if(service_status='N','Not Completed',if(service_status='C','Completed','Skipped')), vehicleservice_workshop 
			from vehicleservice left join vehicle on vehicle.vehicle_id = vehicleservice.vehicle_id
			left join service on service.service_id = vehicleservice.service_id
		    where vehicleservice.vehicle_id='".$vehicle_id."' ";
//echo $querydt;
$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
while($rowsdt=mysql_fetch_array($resultdt)){
			    
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
						
				
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetail('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetail('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[1]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[9]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[6]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[10]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[11]."</span></td>";
	//echo "	<td align='left'><span class='style5'>".$rowsdt[8]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table></td></tr>";						
echo"</table>";						


	echo"</div>";echo"</div>";
	 
  
  
 


  echo"	<div class='tabbertab'>
				<h2 title='Parts'>Parts</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:350px; margin-top:5px; border:0px solid gray;'>";
 


echo"<table border=0 width='900'>";
echo '<tr><td colspan="9" align="left" valign="top">';


print <<< HERE
       </td>
      </tr>
HERE;


print <<< HERE
		<tr><th height="15" colspan="9" align="center" valign="top"><span class="style3">Add Parts</span></th></tr>
		<tr bgcolor='#F7F7F7' >	
			 <td colspan='9' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>			 
       <tr>
      <td>
HERE;



if ($vehiclepart_id != ''){
$querydt= " select vehiclepart_id, vehiclepart.vehicle_id, vehiclepart.item_code
			,date_format(vehiclepart_startdate,'%d/%m/%Y') 
			,vehiclepart_reference
			,vehiclepart_note
			,vehicle.vehicle_platenumber,vehicle_make
			,items.item_description
			from vehiclepart left join vehicle on vehicle.vehicle_id = vehiclepart.vehicle_id
			left join items on items.item_code = vehiclepart.item_code
		    where vehiclepart_id='".$vehiclepart_id."' ";
		
	
    $resultdt = mysql_query($querydt, $connection);
	while($rowdt=mysql_fetch_row($resultdt)){
        $vehiclepart_id=$rowdt[0];
		$vehicle_id=$rowdt[1];
		$item_code=$rowdt[2];
		$vehiclepart_startdate=$rowdt[3];
		$vehiclepart_reference=$rowdt[4];
		$vehiclepart_note=$rowdt[5];
		$vehicle_platenumber=$rowdt[6];
		$vehicle_make=$rowdt[7];
		$item_description=$rowdt[8];
		
	}
}

echo"

<input type=hidden name='message' value='$message'>
<input type=hidden name='vehiclepart_id' value='$vehiclepart_id'>
<input type=hidden name='opener' value='$opener'>

";





	echo"<table border='0' style='table-layout:fixed' align='left' valign='top'>
		  <col width=160>
		  <col width=120>
		  <col width=400>";

echo"<tr bgcolor='#F7F7F7'><td valign='center' align='left' ><span class='style1'>Parts&nbsp;<span class='style26'></span></span></td>";
echo"<td><input type='text' name='item_code' $status value='$item_code' size='15' style='width:160px'>";
echo"</label></td>";	
echo"<td colspan='2'><label><table><tr><Td>";
echo"<input type='text' name='item_description' $status value='$item_description' size='30'>&nbsp;</td><td>
<img src='img/scroll-down-1.png' title=' Select Service '  width='20' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick=showitem()>";
echo"</label></td></tr></table></td></tr>";




echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Date</span></td><td colspan=2><input type=text name='vehiclepart_startdate' value='$vehiclepart_startdate'  $status>";
print <<<HERE
  	  <A HREF="#" onClick="displayCalendar(document.vehicle.vehiclepart_startdate,'dd/mm/yyyy',this); return false;" NAME="anchor1" ID="anchor1" >
HERE;
  echo"<image src='./img/cal.gif' border=0 align=center ></image></A>";			
echo"</td></tr>";				

echo"<tr bgcolor=#F7F7F7><td><span class='style1'>Reference</span></td><td colspan=2><input type=text name='vehiclepart_reference' value='$vehiclepart_reference'  $status>";
echo"</td></tr>";				


	
echo"<tr bgcolor=#F7F7F7 ><td><span class='style1'>Note</span></td><td colspan=2><textarea  name='vehiclepart_note' $status style='width:400px;height:50px'>$vehiclepart_note</textarea></td></tr>";





	
	echo"</table></td></tr>";	




			
	echo"<tr><td ><table border=0 align=left width=900> <tr bgcolor=#D8D8D8 height='35'>";
		
	

	echo"<td align='center'><button type='button' name='btnPost' id='btnPost' ";//post
	echo" onclick='SubmitRecordParts();' 	title='Save Changes' /><span><span>Submit Parts</span></span></td>";

				
	 
	echo"  </tr></table></td></tr>";

	

		echo"<tr><td valign='top' colspan=5>";
echo "<table style='table-layout:fixed' border=0 width='900'>
		<col width=20>
		<col width=20>
		<col width=80>
		<col width=300>
		<col width=75>
		<col width=75>
		


		";
		
		
echo "<tr   class='Search-Label-bg'><td>&nbsp;</td><td>&nbsp;</td><td><span class='style4'>Parts&nbsp;<span class='style4'></span></span></td>
		<td><span class='style4'>Description&nbsp;<span class='style4'></span></span></td>
		<td><span class='style4'>Date &nbsp;<span class='style4'></span></span></td>
		<td><span class='style4'>Reference</span></td>
		
      </tr>";
	  
	 
$querydt= " select vehiclepart_id,items.item_code,item_description,vehiclepart_id,vehicle_platenumber, vehicle_make, vehicle_platenumber, date_format(vehiclepart_startdate,'%d/%m/%Y') 
			, vehiclepart_reference  , vehiclepart_note 
			from vehiclepart left join vehicle on vehicle.vehicle_id = vehiclepart.vehicle_id
			left join items on items.item_code = vehiclepart.item_code
		    where vehiclepart.vehicle_id='".$vehicle_id."' ";
//echo $querydt;
$resultdt = mysql_query($querydt, $connection) or die(mysql_error());
while($rowsdt=mysql_fetch_array($resultdt)){
			    
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
						
				
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailParts('".$rowsdt[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailParts('".$rowsdt[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[1]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[2]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[7]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rowsdt[8]."</span></td>";
	//echo "	<td align='left'><span class='style5'>".$rowsdt[8]."</span></td>";
	
	
	echo "</tr>";
						
}	
	  
echo"</table> </td></tr>";						
echo"</table>";						
		


	echo"</div>";echo"</div>";
	
	// Fuel tab
 echo"	<div class='tabbertab'>
				<h2 title='Fuel'>Fuel</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:350px; margin-top:5px; border:0px solid gray;'>";
 

echo "<input type=hidden name='fuel_id' value='$fuel_id'>";
if ($fuel_id != ''){
	$queryfuel = "select date_format(vehiclefuel_Date,'%d/%m/%Y'), vehiclefuel_mileage, vehiclefuel_amount from vehicle_fuel where vehiclefuel_id = $fuel_id ";
	$resfuel = mysql_query($queryfuel);
	$rowfuel = mysql_fetch_row($resfuel);
	$fuel_date = $rowfuel[0];
	$fuel_mileage = $rowfuel[1];
	$fuel_amount = $rowfuel[2];
}
echo"<table border=0 width='900'><col width=150px><col width=200px><col width=150px><col width=400px>";
echo"<tr bgcolor='#F7F7F7'>
		<td valign='center' align='left' ><span class='style1'>Date</span></td>
		<td><input type=text name='fuel_date' value='$fuel_date' readonly $status>
			<A HREF='#' onClick=\"displayCalendar(document.vehicle.fuel_date,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1' ><image src='./img/cal.gif' border=0 align=center ></image></A>
		</td>
		<td valign='center' align='left' ><span class='style1'>Current Mileage</span></td>
		<td><input type=text name='fuel_mileage' value='$fuel_mileage' $status></td>
	</tr>";	
echo"<tr bgcolor='#F7F7F7'>
		<td valign='center' align='left' ><span class='style1'>Amount</span></td>
		<td><input type=text name='fuel_amount' value='$fuel_amount' $status></td>
		<td colspan='2'></td>
	</tr>";	
echo "<tr height='40px' bgcolor='#D8D8D8'>
		<td align='center' colspan='4'><button type='button' name='btnPost' id='btnPost' onclick=\"SubmitRecordFuel();\" title='Save Changes'><span><span>Submit Fuel</span></span></button>
		
		</td></tr>";

echo "<tr><td colspan='4' valign='top'><div style='overflow-x:hidden; overflow-y:scroll;height:250px;'>	
	<table border=0><col width=30px><col width=30px><col width=200px><col width=200px><col width=200px>";
echo "<tr class='Search-Label-bg'><td></td><td></td><td><span class='style4'>Date</span></td><td><span class='style4'>Current Mileage</span></td><td><span class='style4'>Amount</span></td></tr>";	
$query1 = "select vehiclefuel_id, date_format(vehiclefuel_Date,'%d-%m-%Y'), vehiclefuel_mileage, vehiclefuel_amount from vehicle_fuel
		where vehicle_id='$vehicle_id' ";
$res1 = mysql_query($query1);
while ($rw = mysql_fetch_array($res1)){
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
	
	echo "<tr ".$Color." >";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=UpdateDetailFuel('".$rw[0]."') title='Edit Record'  ></span></td>";
	echo "	<td align='center' valign='center'><span class='style5'><img src='img/delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=DeleteDetailFuel('".$rw[0]."') title='Delete Record'  ></span></td>";
	echo "	<td align='left'><span class='style5'>".$rw[1]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rw[2]."</span></td>";
	echo "	<td align='left'><span class='style5'>".$rw[3]."</span></td>";
	
	
	echo "</tr>";					
}
echo "</table></div></td></tr>";
echo"</table>";						
		


	echo"</div>";echo"</div>";
  
  
//Changed Tyres

	// Fuel tab
 echo"	<div class='tabbertab'>
				<h2 title='Changedtyre'>Changed Tyres</h2>";	
	echo"		<div id='datagrid-d' style='width:980px; height:350px; margin-top:5px; border:0px solid gray;'>";
 
echo"<table border=0 width='900'><col width=100px><col width=150px><col width=150px><col width=150px><col width=150px><col width=200px>";
echo"<tr height='30px' bgcolor='#1e87a5'>
		<td valign='center' align='left' ><span class='style1'>Date</span></td>
		<td valign='center' align='left' ><span class='style1'>Tyre Type</span></td>
		<td valign='center' align='left' ><span class='style1'>SN</span></td>
		<td valign='center' align='left' ><span class='style1'>Brand</span></td>
		<td valign='center' align='left' ><span class='style1'>Estimated Distance</span></td>
		<td valign='center' align='left' ><span class='style1'>Remark</span></td>
		
	</tr>";	

echo"</table>";						
echo "<div id='tyrediv' >";
showChangedTyre($vehicle_id, $perpage, $startrange, $connection);		
echo "</div>";

	echo"</div>";echo"</div>";
// end changed tyres	
echo"</div>";

		
print <<< HERE
       </td>
      </tr>
	  </table>
HERE;


echo"</td></tr>";


print <<< HERE
      
    <tr height='30'><td align='center' id='content-bottom' ></td></tr>
	  </table>
HERE;




echo"<script type=\"text/javascript\" language=\"javascript\">";
echo"	tabberAutomatic(tabberOptions);";
echo"   vTabIndex = document.getElementById('PTabIndex').value; ";
echo"	if (document.getElementById('tab1')) document.getElementById('tab1').tabber.tabShow(vTabIndex); ";
echo"</script>";

print <<<HERE
</form>
</body>

HERE;

?>














