<?php
header("Content-type: text/html; charset=windows-1256");

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


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


$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");


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


//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



$querydflwh="select default_warehouse_code as defaultwarehouse from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_warehouse_code != '' ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}

//Projects List
$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";
			  
//$resultfromproject=mysql_query($queryproject,$connection) or die(mysql_error());

//Costcenter List
$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(loginstk.costcent_code,'%') ".
 			   " where user_account='".$_SESSION['useraccount']."' ".
 			   " order by costcent.costcent_code";
			  
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentrows   = mysql_num_rows($costcentresult);
if ($costcentrows == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
//$resultcostcent=mysql_query($querycostcent,$connection) or die(mysql_error());



//Warehouse List
$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);
if ($whexist == 0)
	$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
	
$resultwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());


$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());


$strt = $_SESSION['StartFinancial_Date'];
$end = $_SESSION['EndFinancial_Date'];

if (empty($txtDate))	
	$txtDate = displayToday();

if($txtvisittype == '') $txtvisittype=0;
if($txtfollowchk == '') $txtfollowchk=0;

if (empty($mainaction))	$mainaction = 'insert';
$message = ereg_replace("'"," ",$message);

if ($txtvisitid != '') {
	// Read From Temp Tables For Selected Record				 
	$query = "select visit.customer_code,Customer_Name, visit.salesmen_code,Ledger_name, date_format(visit_date,'%d/%m/%y'), 
			date_format(visit_starttime,'%H:%i'),date_format(visit_endtime,'%H:%i'), visit_note, visit_request,c1.office_contact,
			Customer_Address, Visit_type,visit_followup,date_format(Visit_followupdate,'%d/%m/%y'),
			visit_priceoffered, visit_paymentterms, visit_creditlimit, visit_gift, visit_result, visit_commission,
			c1.office_address as main_address,visit_branchofficeId,visit_projectId, c2.office_address as branch_address, customerproject_desc,
			date_format(visit_followTime,'%H:%i')
			from visit
			left join salesmen on salesmen.Ledger_number=visit.salesmen_code
			left join Customer on Customer.Customer_Code=visit.customer_code
			left join Customer_Offices c1 on c1.customer_officeId = visit.visit_mainofficeId
			left join Customer_Offices c2 on c2.customer_officeId = visit.visit_branchofficeId
			left join customer_project p on p.customerproject_id = visit.visit_projectId
			where visit_reference=$txtvisitid "; 
	$result = mysql_query($query,$connection);
	$rows = mysql_fetch_row($result);	
	
	if($txtClientCode == ''){
	$txtClientCode = $rows[0];
	$txtClientName = $rows[1];
	}
	$txtSalesmanCode = 	$rows[2];
	$txtSalesmanName = 	$rows[3];
	$txtDate = 	$rows[4];
	
	$visitStart = explode(":",$rows[5]);
	$txtvisitstarthr = $visitStart[0];
	$txtvisitstartmn = $visitStart[1];
	
	$visitEnd = explode(":",$rows[6]);
	$txtvisitendhr = $visitEnd[0];
	$txtvisitendmn = $visitEnd[1];
	
	$txtvisitnote = $rows[7];
	$txtvisitrequest = $rows[8];
	
	$txtClientContact = $rows[9];
	$txtClientAddress = $rows[10];
	
	$txtvisittype = $rows[11];
	$txtfollowchk = $rows[12];
	if($txtfollowchk == 1) {
		$txtFollowDate = $rows[13];
		$visitfollowtime = explode(":",$rows[25]);
		$txtvisitfollowhr = $visitfollowtime[0];
		$txtvisitfollowmn = $visitfollowtime[1];

	}
	$txtvisitprice = $rows[14];
	$txtvisitpayterms = $rows[15];

	$txtvisitcredit = $rows[16];
	$txtvisitgift = $rows[17];

	$txtvisitresult = $rows[18];

	$txtvisitcommision = $rows[19];
	
	if($txtMainOfficeId =='')
	$txtMainOfficeId = $rows[20];
	if($txtBranchOfficeId =='')
	$txtBranchOfficeId = $rows[21];
	if($txtcustomerprojectId =='')
	$txtcustomerprojectId = $rows[22];
	if($txtBranchOffice =='')
	$txtBranchOffice = $rows[23];
	if($txtcustomerproject =='')
	$txtcustomerproject = $rows[24];
	
	
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
}

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

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

function showlistSalesman(str){
  var vdate, vcode;
  vdate=document.visit.txtDate.value;
  vcode=encodeURIComponent(document.visit.txtSalesmanCode.value);
  
  window.open('List_SorSalesman.php?frm=7&item='+str+'&PLedger_number='+vcode+'&TransDate='+vdate,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function showlistProjects(str){
  var  vcode;
  vcode=document.getElementById("txtClientCode").value;
  
  window.open('List_SorCustomerProjects.php?frm=1&item='+str+'&Pcustomercode='+vcode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistBranches(str){
  var  vcode,vmain;
  vcode=document.getElementById("txtClientCode").value;
  vmain=document.getElementById("txtMainOfficeId").value;
  window.open('List_SorCustomerBranches.php?frm=1&item='+str+'&Pcustomercode='+vcode+'&mainoffice='+vmain,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	
}

function PostChanges(){
	var x = document.visit;
	if(x.txtvisitid.value=='') var vmode='Post';
	else var vmode='Edit';
	if(document.getElementById("txtSalesmanCode").value == ''){
		alert("A Salesman must be selected!");
		return 0;
	} else if(document.getElementById("txtClientCode").value == ''){
		alert("A Client must be selected!");
		return 0;
	}  else if(document.getElementById("txtfollowchk").value == '1' && document.getElementById("txtFollowDate").value == ''){
		alert("Follow Up Date is Empty!");
		return 0; 
	} else {
		x.action = 'Form_Visit_Actions.php?mode='+vmode;
		x.submit();
	}
}

function ClearPage(){
	var x = document.visit;
	x.txtvisitrequest.value='';
	x.txtSalesmanCode.value='';
	x.txtSalesmanName.value='';
	x.txtClientCode.value='';
	x.txtClientName.value='';
	x.txtClientContact.value='';
	x.txtClientAddress.value='';
	x.txtDate.value='';
	x.txtvisitstarthr.value='';
	x.txtvisitstartmn.value='';
	x.txtvisitendhr.value='';
	x.txtvisitendmn.value='';
	x.txtvisitendhr.value='';
	x.txtvisitnote.value='';
	x.txtvisitid.value='';
	x.txtfollowchk.vaue='0';
	document.getElementById("txtfollowchk").checked=false;
	x.txtvisittype.value='';
	x.txtFollowDate.value='';
	x.txtvisitfollowhr.value='';
	x.txtvisitfollowmn.value='';
	
	x.txtcustomerproject.value='';
	x.txtBranchOffice.value='';
	x.txtvisitprice.value='';
	x.txtvisitpayterms.value='';
	x.txtvisitcredit.value='';
	x.txtvisitgift.value='';
	x.txtvisitcommision.value='';
	x.txtvisitresult.value='';
	
	x.txtBranchOfficeId.value='';
	x.txtcustomerprojectId.value='';
	
	x.mode.value='';
	x.mainaction.value='';	
	x.message.value='';
	x.action = 'Form_Visit.php';
	x.submit();
	
}



function OpenCustomer(){ 
	 
	
	Win_Employee = window.open('List_Customers.php?frm=4&PLedgerNo=&fromcallerid=1&isfound=','List_Customers', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=900,height=750,left=250,top=200');		
	Win_Employee.creator = self;
	Win_Employee.focus();
	
}
function checkFollowup(){
	if(document.getElementById("txtfollowchk").checked){
		document.getElementById("txtFollowDate").disabled=false;
		document.getElementById("txtfollowchk").value=1;
		document.getElementById("txtfollowchk").checked=true;
		document.getElementById("txtvisitfollowhr").disabled=false;
		document.getElementById("txtvisitfollowmn").disabled=false;
	}
	else {
		document.getElementById("txtFollowDate").disabled=true;
		document.getElementById("txtFollowDate").value='';
		document.getElementById("txtfollowchk").value=0;
		document.getElementById("txtfollowchk").checked=false;
		document.getElementById("txtvisitfollowhr").disabled=true;
		document.getElementById("txtvisitfollowmn").disabled=true;
	}
		
}
function searchvisit(){
Win_Employee = window.open('Form_VisitSearch.php','Form_VisitSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=900,height=750,left=250,top=200');		
	
}

function PrintPrev(visitId){
	if (visitId != "") vMsg = "Do you want to Print current Visit with Ref: "+visitId+"?";
	
	if (confirm (vMsg))
	{
		str = 'Rep_VisitPreview.php?visitId='+visitId;
		window.open(str);
	}	
	
}

function changeMain(){
	document.visit.txtClientContact.value='';
	document.visit.submit();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Visit</title>



<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>

</head>
<body >
<form name='visit' method='post'  enctype='multipart/form-data'>
<input type='hidden' name='mode' value='$mode'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='txtvisitid' value='$txtvisitid'>
<input type='hidden' name='txtBranchOfficeId' value='$txtBranchOfficeId'>
<input type='hidden' name='txtcustomerprojectId' value='$txtcustomerprojectId'>
HERE;

//$message='';

	
//Initializations




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'>Visit</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='800px' align='left'>";


echo" <button type='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";	

echo" <button type='button' id='btnPost' name='btnPost' onclick='PostChanges();return false;' title='Save Changes'><span><span>Save</span></span></button>";

if($txtvisitid == '')
echo" <button type='button' id='btnSearch' name='btnSearch' onclick='searchvisit();return false;' title='Search'><span><span>Search</span></span></button>";
echo"</td>";



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

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";
   
   	

print <<<HERE

		<table border="0" style='table-layout:fixed'>
		  <col width=80>
		  <col width=70>
		  <col width=50>
		  <col width=120>
		  <col width=40>
		  <col width=70>
		  <col width=50>
		  <col width=70>
		  <col width=150>
		  <col width=150>
		  <col width=150> <col width=150>

		<tr bgcolor="#F7F7F7" height='30'>
          <td valign="center" align='left' ><span class="style1">Reference&nbsp;<span class="style16">*</span></span></td>
		  <td colspan='7'><font face='Verdana' size='2'><b>&nbsp;$txtvisitid</b></font></td>
HERE;
echo "<td colspan='2'><span class='style1'>Type &nbsp;&nbsp;&nbsp;</span>";		
echo "<select name='txtvisittype' id='txtvisittype' >";
echo "<option value='1' ".($txtvisittype==1?'selected':'').">Visit</option>";
echo "<option value='2' ".($txtvisittype==2?'selected':'').">Call</option>";
echo "<option value='3' ".($txtvisittype==3?'selected':'').">Mail</option>";
echo "</select></td></tr>";
echo "<tr height='30px'><td align='left' ><span class='style1'>Salesman <span class='style16'>*</span></span></td>
		<td colspan='7'><span class='style1'><label>
				<input type='text'   name='txtSalesmanCode' id='txtSalesmanCode' value='$txtSalesmanCode' style='width:95px;' maxlength='10'  />
				<input type='text'   name='txtSalesmanName' id='txtSalesmanName' value='$txtSalesmanName' style='width:250px;'  />
			</label>
			</span>
			<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Salesman ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistSalesman(1); ' /> </span></label></td>";

print <<<HERE
		  <td align="left" colspan='4'><span class="style1">Date&nbsp;<span class="style16">*</span></span>
		  <input type='text' name='txtDate' id='txtDate' value='$txtDate'  onBlur=checkDateFormat(this,$strt,$end)  maxlength='10'  style='width:70px;'>
		                   <A HREF="#" onClick="displayCalendar(document.visit.txtDate,'dd/mm/yyyy',this);  return false; " NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A>

HERE;
print <<<HERE
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="style1">Start Time&nbsp;<span class="style16"></span></span>
		 <input type='number' name='txtvisitstarthr' id='txtvisitstarthr' value='$txtvisitstarthr' max='23' min='0' style='width:40px;text-align:right;'>:<input type='number' name='txtvisitstartmn' id='txtvisitstartmn' value='$txtvisitstartmn' max='59' min='0' style='width:40px;text-align:left;'>
HERE;

print <<<HERE
		 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="style1">End Time&nbsp;<span class="style16"></span></span>
		  <input type='number' name='txtvisitendhr' id='txtvisitendhr' value='$txtvisitendhr' max='23' style='width:40px;text-align:right;'>:<input type='number' name='txtvisitendmn' id='txtvisitendmn' value='$txtvisitendmn' max='59'  style='width:40px;text-align:left;'></td>
HERE;
			
echo"</tr>";

echo "<tr height='30px'><td align='left' ><span class='style1'>Client <span class='style16'>*</span></span></td>
		<td colspan='7'><span class='style1'><label>
				<input type='text'   name='txtClientCode' id='txtClientCode' value='$txtClientCode' style='width:95px;' maxlength='10'  />
				<input type='text'   name='txtClientName' id='txtClientName' value='$txtClientName' style='width:250px;'  />
			</label>
			</span>
			<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Salesman ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='OpenCustomer(); ' /> </span></label></td>";
echo "<td colspan='4'><span class='style1'><input type='checkbox' name='txtfollowchk' id='txtfollowchk' value='$txtfollowchk' onclick=\"checkFollowup();\" ".($txtfollowchk == 1?' checked ':'').">Follow Up</span>";	

echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style1'>Follow Up Date</span>
<input type='text' name='txtFollowDate' id='txtFollowDate' value='$txtFollowDate'  onBlur=checkDateFormat(this,$strt,$end)  maxlength='10'  style='width:90px;' 
		".($txtfollowchk == 0?' disabled ': '')." > ";
print <<<HERE
<A HREF="#" onClick="displayCalendar(document.visit.txtFollowDate,'dd/mm/yyyy',this);  return false; " NAME="anchor1" ID="anchor1"><img src='./img/cal.gif' border=0 align=center></A>
HERE;
echo " &nbsp;&nbsp;<span class='style1'>Follow up Time&nbsp;<span class='style16'></span></span>
		 <input type='number' name='txtvisitfollowhr' id='txtvisitfollowhr' value='$txtvisitfollowhr' max='23' min='0' style='width:40px;text-align:right;' ".($txtfollowchk == 0?' disabled ': '').">:<input type='number' name='txtvisitfollowmn' id='txtvisitfollowmn' value='$txtvisitfollowmn' max='59' min='0' style='width:40px;text-align:left;' 
		 ".($txtfollowchk == 0?' disabled ': '').">";
echo " </td>";
echo"</tr>";

$queryct = "select office_contact from Customer_Offices
			where Customer_Code='$txtClientCode' and if('$txtMainOfficeId' !='', customer_officeId= '$txtMainOfficeId', 1=1) ";
$resct = mysql_query($queryct,$connection);	
$rwct = mysql_fetch_row($resct);
if($txtClientContact == '')	$txtClientContact = $rwct[0];	
echo"   <tr height='20px'><td></td></tr>";
echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Client Contact </span></td><td colspan='2'> <input type='text'   name='txtClientContact' id='txtClientContact' value='$txtClientContact' style='width:150px;'  readonly /></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'>Client Address </span></td><td  colspan='2'> <input type='text'   name='txtClientAddress' id='txtClientAddress' value='$txtClientAddress' style='width:150px;'  readonly /></td>";			
echo "</tr>";

echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Main Office</span></td><td colspan='2'> 
	<select name='txtMainOfficeId' id='txtMainOfficeId' onchange=\"changeMain();\" style='width:150px;'>";
$querymain = "select customer_officeId,office_address from Customer_Offices 
			where Customer_Code = '$txtClientCode' and mainoffice_id is null ";
$resmain = mysql_query($querymain,$connection);
while($rwmain = mysql_fetch_row($resmain)){
echo "<option value='$rwmain[0]'>$rwmain[1]</option>";
}
echo "</select></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'>Branch </span></td><td  colspan='2'> <input type='text'   name='txtBranchOffice' id='txtBranchOffice' value='$txtBranchOffice' style='width:150px;'  readonly />
<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Branch ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistBranches(1); ' /> </span></label></td>";			
echo "</tr>";

echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Project</span></td><td colspan='2'> <input type='text'   name='txtcustomerproject' id='txtcustomerproject' value='$txtcustomerproject' style='width:150px;'  readonly />
<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistProjects(1); ' /> </span></label></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'> </span></td><td  colspan='2'> </td>";			
echo "</tr>";

echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Price Offered</span></td><td colspan='2'> <input type='text'   name='txtvisitprice' id='txtvisitprice' value='$txtvisitprice' style='width:385px;'  /></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'>Payment Terms</span></td><td  colspan='2'> <input type='text'   name='txtvisitpayterms' id='txtvisitpayterms' value='$txtvisitpayterms' style='width:385px;'  /></td>";			
echo "</tr>";

echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Credit Limit</span></td><td colspan='2'> <input type='text'   name='txtvisitcredit' id='txtvisitcredit' value='$txtvisitcredit' style='width:385px;'  /></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'>Gift</span></td><td  colspan='2'> <input type='text'   name='txtvisitgift' id='txtvisitgift' value='$txtvisitgift' style='width:385px;'  /></td>";			
echo "</tr>";

echo "<tr height='30px'>";
echo "<td align='left'><span class='style1'>Result</span></td><td colspan='2'> <input type='text'   name='txtvisitresult' id='txtvisitresult' value='$txtvisitresult' style='width:385px;'  /></td>";			
echo "<td  colspan='5'></td>";
echo "<td align='left'><span class='style1'>Commission Offered</span></td><td  colspan='2'> <input type='text'   name='txtvisitcommision' id='txtvisitcommision' value='$txtvisitcommision' style='width:385px;'  /></td>";			
echo "</tr>";

echo"   <tr height='30px' bgcolor='#F7F7F7'>
		   <td align='left'><span class='style1'>Remarks </span></td>
		   <td align='left' colspan='7'><textarea name='txtvisitnote' id='txtvisitnote' rows='4' cols='45' style='width:385px;'>".htmlspecialchars($txtvisitnote, ENT_QUOTES)."</textarea></td>
		</td>";

//echo "</tr>";
//echo"   <tr height='20px'><td></td></tr>";
echo" 
   <td align='left'><span class='style1'>Terms & Conditions</span></span></td>
   <td align='left' colspan='7'><textarea name='txtvisitrequest' id='txtvisitrequest' rows='4' cols='45' style='width:385px;'>".htmlspecialchars($txtvisitrequest, ENT_QUOTES)."</textarea></td>
	</td>";

echo"</tr>";

echo"   <tr height='40px'><td></td></tr>";
/*
$querysearch = "select visit_reference,visit.customer_code, visit.salesmen_code,date_format(visit_date,'%d/%m/%y'), date_format(visit_starttime,'%H:%i'),
				date_format(visit_endtime,'%H:%i'), visit_note, visit_request,Visit_type,visit_followup,date_format(Visit_followupdate,'%d/%m/%y')
				from visit ";
$resultsearch = mysql_query($querysearch,$connection);				

echo "<tr><td colspan='12'><table border='0' style='table-layout:fixed'>
		<col width=20><col width=20><col width=80><col width=120><col width=120><col width=80><col width=60><col width=60>
		<col width=60><col width=80><col width=250><col width=250>";

echo "					<tr bgcolor='#D0D0D0' height='25px'>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
							<td align='center'><span class='style1'>Reference</span></td>
							<td align='center'><span class='style1'>Customer Code</span></td>
							<td align='center'><span class='style1'>Salesman Code</span></td>
							<td align='center'><span class='style1'>Date</span></td>
							<td align='center'><span class='style1'>Start Time</span></td>
							<td align='center'><span class='style1'>End Time</span></td>
							<td align='center'><span class='style1'>Type</span></td>
							<td align='center'><span class='style1'>Follow Up Date</span></td>
							<td align='center'><span class='style1'>Note</span></td>
							<td align='center'><span class='style1'>Request</span></td>
						</tr>";
	$ct=0;					
while($rowsdt = mysql_fetch_row($resultsearch)){
	
	$ct+=1;

		if($ct%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
						
		if($rowsdt[8] == 0)	$typename='';	
		else if($rowsdt[8] == 1) $typename='Visit';	
		else if($rowsdt[8] == 2) $typename='Call';	
		else if($rowsdt[8] == 3) $typename='Mail';				
							
		 if($rowsdt[0] == $txtvisitid) $Color="style='background-color:#1e87a5'";
		
			 
		echo "<tr ".$Color."  >";
		echo "	<td align='center' valign='center' style='cursor:pointer;'><span style='font-size:13px;'><img src='img/button_edit.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"UpdateDetail('".$rowsdt[0]."');\" title='Edit Record'  ></span></td>";
		echo "	<td align='center' valign='center' style='cursor:pointer;'><span style='font-size:13px;'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='hand'\" onclick=\"DeleteDetail('".$rowsdt[0]."');\" title='Delete Record'  ></span></td>";
		echo "	<td align='left' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[0]."</span></td>";
		echo "	<td align='left' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[1]."</span></td>";
		echo "	<td align='left' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[2]."</span></td>";
		echo "	<td align='left' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[3]."</span></td>";
		echo "	<td align='left' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[4]."</span></td>";
		echo "	<td align='center' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[5]."</span></td>";
		echo "	<td align='center' style='cursor:pointer;'><span style='font-size:13px;'>".$typename."</span></td>";
		echo "	<td align='center' style='cursor:pointer;'><span style='font-size:13px;'>".($rowsdt[9]==1?$rowsdt[10]:'')."</span></td>";
		echo "	<td align='center' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[6]."</span></td>";
		echo "	<td align='center' style='cursor:pointer;'><span style='font-size:13px;'>".$rowsdt[7]."</span></td>";
		echo "</tr>";	
}							

echo "</table></td></tr>";*/
echo"   </table></td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo"   </table></td></tr>"; 

echo" </table>  ";//end of last table menu

if(($mode=='Post' or $mode=='Edit') && $txtvisitid != ''){
	echo "<script>";
	echo "PrintPrev('$txtvisitid'); ";
	echo "ClearPage(); ";
	echo "</script>";
	
}

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

HERE;

?>