<?php

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

include("config.inc.php");
include("Functions_Sales.php");
include("form_Customergrid.php");
//Set Time Execution For the Report
ini_set('max_execution_time', $config['ReportTimeExecution']);

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

 
class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			
			
			
			echo "$jsClear";
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.items[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	

//Read From Login Table
$querylog=" select ifNull(FC_CashRegisterDisc,0) As FC_CashRegisterDisc, ifNull(FC_DiscountPerLimit,0) As FC_DiscountPerLimit ".
		  " 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);
}

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,ifnull(cashreg_colortheme,'default') as cashreg_colortheme, ifnull(POS_RedeemPoints,0) as POS_RedeemPoints
			from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

$querymodule="select  ifnull(module_visit,0) as module_visit from module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$frm	   	   = $_GET['frm']; if ($frm == ""){$frm = $_POST["frm"];}
$item 	   	   = $_GET['item'];if ($item == ""){$item = $_POST["item"];}
$message       = $_GET['message'];if ($message == ""){$message = $_POST["message"];}
$startrange    = $_GET['startrange'];if ($startrange == ""){$startrange = $_POST["startrange"];}
$startrange1    = $_GET['startrange1'];if ($startrange1 == ""){$startrange1 = $_POST["startrange1"];}
$txtId 		   = $_GET['txtId'];if ($txtId == ""){$txtId = $_POST["txtId"];}
$PActionMode   = $_GET['PActionMode'];if ($PActionMode == ""){$PActionMode = $_POST["PActionMode"];}
$PCustomerCode = $_GET['PCustomerCode'];if ($PCustomerCode == ""){$PCustomerCode = $_POST["PCustomerCode"];}

$PLedgerNo  = $_POST["PLedgerNo"]; if ($PLedgerNo == ""){$PLedgerNo = $_GET["PLedgerNo"];}
$perpage    = $_POST["perpage"]; if ($perpage == ""){$perpage = $_GET["perpage"];}

$txtCode    = $_POST["txtCode"]; if ($txtCode == ""){$txtCode = $_GET["txtCode"];}
$txtName    = $_POST["txtName"]; if ($txtName == ""){$txtName = $_GET["txtName"];}
$txtPhone1  = $_POST["txtPhone1"]; if ($txtPhone1 == ""){$txtPhone1 = $_GET["txtPhone1"];}
$txtPhone2  = $_POST["txtPhone2"]; if ($txtPhone2 == ""){$txtPhone2 = $_GET["txtPhone2"];}
$txtEmail   = $_POST["txtEmail"]; if ($txtEmail == ""){$txtEmail = $_GET["txtEmail"];}
$txtAddress = $_POST["txtAddress"]; if ($txtAddress == ""){$txtAddress = $_GET["txtAddress"];}
$keyword = $_POST["keyword"]; if ($keyword == ""){$keyword = $_GET["keyword"];}
$vTabFocus 	= $_POST["vTabFocus"]; if ($vTabFocus == ""){$vTabFocus = $_GET["vTabFocus"];} 
$txtCustomerSpecial = $_POST["txtCustomerSpecial"]; if ($txtCustomerSpecial == ""){$txtCustomerSpecial = $_GET["txtCustomerSpecial"];}

if($isfound=='' and $fromcallerid==1)
	$PActionMode = 'Add';
 
print <<<HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
HERE;

if($cashreg_colortheme=='red'){
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-red.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-red.css" />';
}	
else if($cashreg_colortheme=='' || $cashreg_colortheme=='default')	{
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-default.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-default.css" />';
}

print <<<HERE
<title>Select Customer</title>
<script type="text/javascript" language="javascript">

function SelectRecord(value1,value2,value3,Rest, value4, value5, value6){

	vFrm  = document.form1.frm.value;
	vItem = document.form1.item.value;

	if(vFrm=='1'){
		var discExsists= 0;
		opener.document.retailpay.txtRetCustomerCode.value = value1;
		opener.document.retailpay.txtRetCustomerName.value = value2;
		opener.document.retailpay.txtRetRemark.value = value3;
		if(opener.document.retailpay.txtRetCustomerDisc)
			opener.document.retailpay.txtRetCustomerDisc.value = value5;
		if(opener.document.retailpay.txtRetCustomerPt)
			opener.document.retailpay.txtRetCustomerPt.value = value6;
		if(value5>0 && opener.document.retailpay.txtRetCustomerDisc) discExsists= 1;
		opener.document.retailpay.txtRetCustomerName.focus();
		if(discExsists == 0) opener.document.retailpay.submit();
		if(discExsists == 1) 	opener.document.getElementById('txtRetCustomerName').onchange();
	}
	else if(vFrm=='2'){
		if(vItem==1){
			opener.document.form1.fromcustomer.value = value1;
			opener.document.form1.fromcustomerdesc.value = value2;
		} else {
			opener.document.form1.tocustomer.value = value1;
			opener.document.form1.tocustomerdesc.value = value2;
		}	
	} else if(vFrm=='3'){
		opener.document.retail.txtRetCustomerCode.value = value1;
		opener.document.retail.txtRetCustomerName.value = replaceAll(value4, "<br>", "\\n");
		opener.document.retail.txtSaleStatus.value = 'delivery';
		opener.document.retail.txtRetDriverName.focus();
		document.form1.Ledger_Number1.value = value1;
		document.form1.submit();
		
	}else if(vFrm=='4'){
		opener.document.visit.txtClientCode.value = value1;
		opener.document.visit.txtClientName.value = value2;
		opener.document.visit.txtClientAddress.value = value3;
		opener.document.visit.txtClientCode.focus();
		opener.document.visit.submit();
		self.close();
	}else if(vFrm=='5'){
		if(vItem == 1){
		opener.document.form1.fromcustomercode.value = value1;
		opener.document.form1.fromcustomername.value = value2;
		opener.document.form1.fromcustomercode.focus();
		document.form1.submit();
		self.close();
		} else if(vItem == 2){
		opener.document.form1.tocustomercode.value = value1;
		opener.document.form1.tocustomername.value = value2;
		opener.document.form1.tocustomercode.focus();
		document.form1.submit();
		self.close();
		}
	}
	else if(vFrm=='6'){
		opener.document.retail.txtRetCustomerCode.value = value1;
		opener.document.retail.txtRetCustomerName.value = value2;
		opener.document.retail.txtRetCustomerDisc.value = value5;
		opener.document.retail.txtRetCustomerPt.value = value6;
		document.form1.Ledger_Number1.value = value1;
		opener.document.getElementById('txtRetCustomerName').onchange();
		document.form1.submit();
		
	}
	 
	if(vFrm!='3') self.close();
}

function replaceAll(txt, replace, with_this) {   return txt.replace(new RegExp(replace, 'g'),with_this); }

function ClearForm()
{
	document.form1.PLedgerNo.value='';
	document.form1.PActionMode.value='';
	document.form1.startrange.value = 0;
	document.form1.startrange1.value = 0;
	document.form1.submit();
}

function AddRecord() {
	var x = document.form1;
	
	x.PLedgerNo.value='';
	x.PActionMode.value='Add';
	x.submit();
}

function CancelRecord() {
	var x = document.form1;
	
  if(x.module_visit.value == 1 && x.PActionMode.value=='Edit'){
		cancelMain();
		cancelBranch();
		cancelProject();
	}
	x.vTabFocus.value='Customer';
	x.PActionMode.value='';
	x.PCustomerCode.value='';
	
	
	x.customer_officeId.value='';
	x.customer_officeId2.value='';
	x.customerproject_id.value='';
	
	x.txtCode.value='';
	x.txtName.value='';
	x.txtPhone1.value='';
	x.txtPhone2.value='';
	x.txtEmail.value='';
	x.txtAddress.value='';
	if(x.txtLedgerClientCard)
		x.txtLedgerClientCard.value='';
	x.message.value='';
	if(x.txtgroupname)
		x.txtgroupname.value='';
	if(x.txtdescname)
		x.txtdescname.value='';
	x.action='list_customers.php';
	x.submit();
}
function SubmitForm()
{	

  //document.search.keyword.value='';
  document.form1.action='list_customers.php?startrange=0';
  document.form1.submit();

}
function deleteRecord(customercode){
  document.form1.action='List_Customers_Actions.php?PCustomerCode='+customercode+'&actionmode=deleteCustomer';
  document.form1.submit();
}
function SubmitForm1()
{	

  //document.search.keyword.value='';
  document.form1.action='list_customers.php?startrange1=0&vTabFocus=CallingRecords';
  document.form1.submit();

}

function clearform()
{

  document.form1.keyword.value='';
  
  document.form1.action='list_customers.php';
  document.form1.submit();

}


function SubmitRecord() {
	
	
  $('#txtaddressencoded').val((	 encodeURIComponent($("#txtAddress").val())  ));
	
	//return false;
	
	
	var x = document.form1;
	var result = CheckFields();
	
	vFrm  = document.form1.frm.value;
	vtxtId = document.form1.txtId.value;
	
	if (result == 1) {
		x.PActionMode.value='Submit';
		// // // alert(vFrm);
		document.form1.action='list_customers_Actions.php?frm='+vFrm+'&txtId='+vtxtId;
		document.form1.submit();
	}
}

function UpdateRecord(CustomerCode) {
	var x = document.form1;
	if(x.module_visit.value == 1 && x.PCustomerCode.value!=''){
		cancelMain();
		cancelBranch();
		cancelProject();
	}
	var frm = x.frm.value;
	x.customer_officeId.value='';
	x.customer_officeId2.value='';
	x.customerproject_id.value='';
	x.PActionMode.value='Edit';
	x.PCustomerCode.value=CustomerCode;
	x.vTabFocus.value='Customer';
	x.action ='List_Customers.php?frm='+frm+'&PLedgerNo=&fromcallerid=1&isfound=';
	x.submit();

}

function CheckFields(){
  
    var x = document.form1;
	
//	var vCode = x.txtCode.value;
//	var vName = x.txtName.value;

   var vCode  = document.getElementById('txtCode').value;
   var vName  = document.getElementById('txtName').value;   
	
	if (vCode=='' )
	{
		alert("Code is mandatory!");
		x.txtCode.focus();
		return 0;
	}
	else if (vName=='')
	{
		alert("Name is mandatory!");
		x.txtName.focus();
		return 0;
	}
	
	
	else
	return 1 ;	
}


function SetNextPage(startrange, perpage){
	x=document.form1;
	
	x.startrange.value = startrange;
	x.action='List_Customers.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function SetPrvPage(startrange, perpage){
	x=document.form1;
	
	x.startrange.value = startrange;
	x.action='List_Customers.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	x.submit();
}

function SetNextPage1(startrange, perpage, vTabFocus){
	x=document.form1;
	
	x.startrange1.value = startrange;
	x.action='List_Customers.php?PRef=&startrange1='+startrange+'&perpage1='+perpage+'&vTabFocus='+vTabFocus;
	x.submit();
}

function SetPrvPage1(startrange, perpage,vTabFocus){
	x=document.form1;
	
	x.startrange1.value = startrange;
	x.action='List_Customers.php?PRef=&startrange1='+startrange+'&perpage1='+perpage+'&vTabFocus='+vTabFocus;
	x.submit();
}

function SetNextPage2(startrange, perpage, vTabFocus){
	x=document.form1;
	
	x.startrange2.value = startrange;
	x.action='List_Customers.php?PRef=&startrange2='+startrange+'&perpage2='+perpage+'&vTabFocus='+vTabFocus;
	x.submit();
}

function SetPrvPage2(startrange, perpage,vTabFocus){
	x=document.form1;
	
	x.startrange2.value = startrange;
	x.action='List_Customers.php?PRef=&startrange2='+startrange+'&perpage2='+perpage+'&vTabFocus='+vTabFocus;
	x.submit();
}

function OpenKeyboard(field){
	VirtualKeyboard.attachInput(field);
	VirtualKeyboard.open(field,'td');
}
function showlistCreditCard(str){
  var vcode;
  
  x = document.form1;
  vcode  = x.txtLedgerClientnbr.value;
  //vtotal = x.txtRetNetTotal.value;
  
  window.open('List_CreditCards.php?frm=3&item='+str+'&PLedgerNo='+vcode,'List_CreditCards','width=600,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function SearchCust(){
	x = document.form1;
	x.submit();
}

function SubmitMain(){ 
	var x = document.form1;
	var vCustomer_officeId = x.customer_officeId.value;
	if(document.getElementById("txtmainaddress").value == ''){
		alert("Main Address should not be empty!");
		return 0;
	} else{
		x.action = 'List_Customers_Actions.php?actionmode=submitmain&customer_officeId='+vCustomer_officeId;
		x.submit();
	}
}

function UpdateMain(vCustomer_officeId){
	var x = document.form1;
	x.customer_officeId.value=vCustomer_officeId;
	x.vTabFocus.value='Main Office';
	x.submit();
	
}
function deleteMain(vCustomer_officeId){
	var x = document.form1;
	x.action = 'List_Customers_Actions.php?actionmode=deletemain&customer_officeId='+vCustomer_officeId;
	x.submit();
}

function confirmMaininfo(vContactinfo_id,vCustomer_officeId){
var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				/*	var data = xmlhttp.responseText.split("[BRK]");
					if(data[0] !=''){
						alert(data[0]);
						return 0;
					} else{*/
						document.getElementById('maincontactinfo').innerHTML='';
						document.getElementById('maincontactinfo').innerHTML=xmlhttp.responseText;
					//}
				
				}
		}





var vmainaddress = document.getElementById("txtmainaddress").value; 
var vmaincontact = document.getElementById("txtmaincontact").value; 
  
var vctfirstname = document.getElementById("txtctfirstname").value; 
var vctfathername = document.getElementById("txtctfathername").value; 
var vctlastname = document.getElementById("txtctlastname").value; 

var vctposition = document.getElementById("txtctposition").value; 

var vctphone1 = document.getElementById("txtctphone1").value; 
var vctphone2 = document.getElementById("txtctphone2").value; 
var vctphone3 = document.getElementById("txtctphone3").value; 

var vctemail1 = document.getElementById("txtctemail1").value; 
var vctemail2 = document.getElementById("txtctemail2").value; 
var vctwebsite ;


var PCustomerCode = document.form1.PCustomerCode.value;

if(vmainaddress == ''){
	alert('Main Address cannot be empty!');
	return 0;
}
else if(vctfirstname == '' || vctlastname == '' || vctposition == '' || vctphone1 == ''){
		alert('Some Fields are still Empty!');
		return 0;
}else{

	
str ='&PCustomerCode='+PCustomerCode+'&customer_officeId='+vCustomer_officeId+'&contactinfo_id='+vContactinfo_id+'&txtctfirstname='+vctfirstname+
	'&txtctfathername='+vctfathername+'&txtctlastname='+vctlastname+'&txtctposition='+vctposition+
	'&txtctphone1='+vctphone1+'&txtctphone2='+vctphone2+'&txtctphone3='+vctphone3+
	'&txtctemail1='+vctemail1+'&txtctemail2='+vctemail2+'&txtctwebsite='+vctwebsite+
	'&txtmainaddress='+vmainaddress+'&txtmaincontact='+vmaincontact;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=confirmMaininfo'+str);
xmlhttp.send();
}
}

function UpdateMaininfo(vContactinfo_id){
	var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				document.getElementById('maincontactinfo').innerHTML='';
				document.getElementById('maincontactinfo').innerHTML=xmlhttp.responseText;
			}
		}
var vCustomer_officeId = document.form1.customer_officeId.value;

str ='&customer_officeId='+vCustomer_officeId+'&contactinfo_id='+vContactinfo_id;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=UpdateMaininfo'+str);
xmlhttp.send();

}

function deleteMaininfo(vContactinfo_id){
	var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				document.getElementById('maincontactinfo').innerHTML='';
				document.getElementById('maincontactinfo').innerHTML=xmlhttp.responseText;
			}
		}
var vCustomer_officeId = document.form1.customer_officeId.value;

str ='&customer_officeId='+vCustomer_officeId+'&contactinfo_id='+vContactinfo_id;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=deleteMaininfo'+str);
xmlhttp.send();

}

function cancelMain(){
	var x = document.form1;
	x.customer_officeId.value='';
	x.txtmainaddress.value='';
	x.txtmaincontact.value='';
	x.submit();
}

function SubmitBranch(){
	var x = document.form1;
	var vCustomer_officeId2 = x.customer_officeId2.value;
	if(document.getElementById("txtbranchaddress").value == ''){
		alert("Branch Address should not be empty!");
		return 0;
	} else{
		x.action = 'List_Customers_Actions.php?actionmode=submitbranch&customer_officeId2='+vCustomer_officeId2;
		x.submit();
	}
	
}

function UpdateBranch(vCustomer_officeId2){
	var x = document.form1;
	x.customer_officeId2.value=vCustomer_officeId2;
	x.vTabFocus.value='Branches';
	x.submit();
	
}
function deleteBranch(vCustomer_officeId2){
	var x = document.form1;
	x.action = 'List_Customers_Actions.php?actionmode=deletebranch&customer_officeId2='+vCustomer_officeId2;
	x.submit();
}


function confirmBranchinfo(vContactinfo_id2,vCustomer_officeId2){
var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				/*	var data = xmlhttp.responseText.split("[BRK]");
					if(data[0] !=''){
						alert(data[0]);
						return 0;
					} else{*/
						document.getElementById('branchcontactinfo').innerHTML='';
						document.getElementById('branchcontactinfo').innerHTML=xmlhttp.responseText;
					//}
				
				}
		}





var vbranchaddress = document.getElementById("txtbranchaddress").value; 
var vbranchcontact = document.getElementById("txtbranchcontact").value; 
  
var vctfirstname2 = document.getElementById("txtctfirstname2").value; 
var vctfathername2 = document.getElementById("txtctfathername2").value; 
var vctlastname2 = document.getElementById("txtctlastname2").value; 

var vctposition2 = document.getElementById("txtctposition2").value; 

var vctphone12 = document.getElementById("txtctphone12").value; 
var vctphone22 = document.getElementById("txtctphone22").value; 
var vctphone32 = document.getElementById("txtctphone32").value; 

var vctemail12 = document.getElementById("txtctemail12").value; 
var vctemail22 = document.getElementById("txtctemail22").value; 
var vctwebsite2 = document.getElementById("txtctwebsite2").value;

var PCustomerCode = document.form1.PCustomerCode.value;

if(vbranchaddress == ''){
	alert('Branch Address cannot be empty!');
	return 0;
}
else if(vctfirstname2 == '' || vctlastname2 == '' || vctposition2 == '' || vctphone12 == ''){
		alert('Some Fields are still Empty!');
		return 0;
}else{

	
str ='&PCustomerCode='+PCustomerCode+'&customer_officeId2='+vCustomer_officeId2+'&contactinfo_id2='+vContactinfo_id2+'&txtctfirstname2='+vctfirstname2+
	'&txtctfathername2='+vctfathername2+'&txtctlastname2='+vctlastname2+'&txtctposition2='+vctposition2+
	'&txtctphone12='+vctphone12+'&txtctphone22='+vctphone22+'&txtctphone32='+vctphone32+
	'&txtctemail12='+vctemail12+'&txtctemail22='+vctemail22+'&txtctwebsite2='+vctwebsite2+
	'&txtbranchaddress='+vbranchaddress+'&txtbranchcontact='+vbranchcontact;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=confirmBranchinfo'+str);
xmlhttp.send();
}
}

function UpdateBranchinfo(vContactinfo_id2){
	var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				document.getElementById('branchcontactinfo').innerHTML='';
				document.getElementById('branchcontactinfo').innerHTML=xmlhttp.responseText;
			}
		}
var vCustomer_officeId2 = document.form1.customer_officeId2.value;

str ='&customer_officeId2='+vCustomer_officeId2+'&contactinfo_id2='+vContactinfo_id2;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=UpdateBranchinfo'+str);
xmlhttp.send();

}

function deleteBranchinfo(vContactinfo_id2){
	var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				document.getElementById('branchcontactinfo').innerHTML='';
				document.getElementById('branchcontactinfo').innerHTML=xmlhttp.responseText;
			}
		}
var vCustomer_officeId2 = document.form1.customer_officeId2.value;

str ='&customer_officeId2='+vCustomer_officeId2+'&contactinfo_id2='+vContactinfo_id2;  

xmlhttp.open("GET",'List_Customers_Actions.php?actionmode=deleteBranchinfo'+str);
xmlhttp.send();

}

function cancelBranch(){
	var x = document.form1;
	x.customer_officeId2.value='';
	x.txtbranchaddress.value='';
	x.txtbranchcontact.value='';
	x.txtparentaddress.value='';
	x.submit();
}

function SubmitProject(){
	var x = document.form1;
	var vcustomerproject_id = x.customerproject_id.value;
	if(document.getElementById("txtprojectdesc").value ==''){
		alert("Project Description is Empty!");
		return 0;
	} else{
		x.action = 'List_Customers_Actions.php?actionmode=submitproject&customerproject_id='+vcustomerproject_id;
		x.submit();
	}
	
}
function UpdateProject(vcustomerproject_id){
	var x = document.form1;
	x.vTabFocus.value='Projects';
	x.customerproject_id.value=vcustomerproject_id;
	x.submit();
}
function deleteProject(vcustomerproject_id){
	var x = document.form1;
	x.action = 'List_Customers_Actions.php?actionmode=deleteProject&customerproject_id='+vcustomerproject_id;
	x.submit();
}
function cancelProject(){
	var x = document.form1;
	x.customerproject_id.value='';
	x.txtprojectdesc.value='';
	x.txtprojectaddress.value='';
	x.txtprojectcontact.value='';
	x.txtprojectphone.value='';
	x.txtprojectconsname.value='';
	x.txtprojectconsdetail.value='';
	x.txtprojectsituation.value='';
	x.txtprojectiron.value='';
	x.txtprojectcompetitor.value='';
	x.txtprojectparent.value='';
	x.submit();
}

function PrintRecord(){
	var PCustomerCode = document.form1.PCustomerCode.value;
	str = 'Rep_CustomerPreview.php?customer_code='+PCustomerCode;
	window.open(str);
}
function openListPoints(customer_code){
	var str = "List_RedeemPoints.php?&customer_code="+customer_code;
	window.open(str,'List_Points', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width=550,height=400,left=250,top=200');
}
function upload_picture(vContactinfo_id,vCustomer_officeId){
var xmlhttp = new XMLHttpRequest();	
xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{ 		
				/*	var data = xmlhttp.responseText.split("[BRK]");
					if(data[0] !=''){
						alert(data[0]);
						return 0;
					} else{*/
						document.getElementById('maincontactinfo').innerHTML='';
						document.getElementById('maincontactinfo').innerHTML=xmlhttp.responseText;
					//}
				
				}
		}
		
 var vphoto = document.getElementById("photo");
 var files = vphoto.files; 
 var formData = new FormData();

  for (var i = 0; i < files.length; i++) {
  var file = files[i];

 
  // Add the file to the request.
  formData.append('photos[]', file, file.name);
}

	if(vphoto.value==''){
		alert('No File was Selected!');
		return 0;
	} else {
		str = '&photo='+vphoto+'&contactinfo_id='+vContactinfo_id+'&customer_officeId='+vCustomer_officeId;
		xmlhttp.open("POST",'List_Customers_Actions.php?actionmode=uploadpicture'+str);
		xmlhttp.send(formData);
	
	}
}

function show_picture(contactinfo_id){

	var PCustomerCode=document.form1.PCustomerCode.value;
	window.open('List_Items_Picture.php?frm=2&item_code='+contactinfo_id,'itempicture','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

</script>
<style>
.style127{
	font-size:12px;
	color:#186194;
	
}
.style16{
	color:red;
}
.style111{
	color:white;
	font-size:12px;
}
</style>

<script type = "text/javascript" src="jquery-1.9.1.js" > </script>
</head>

<body>
<form id="form1" name="form1" method="post" action="" enctype='multipart/form-data'>
<input type='hidden' name='PActionMode' id='PActionMode'  value='$PActionMode' >
<input type='hidden' name='PCustomerCode' id='PCustomerCode'  value='$PCustomerCode' >
<input type='hidden' name='item' id='item' value='$item' />
<input type='hidden' name='frm' id='frm' value='$frm' />
<input type='hidden' name='message' value='$message' size='200'>
<input type='hidden' name='startrange' value='$startrange'>
<input type='hidden' name='startrange1' value='$startrange1'>
<input type='hidden' name='txtId' value='$txtId'>
<input type='hidden' name='Ledger_Number1' value='$Ledger_Number1'>
<input type='hidden' name='customer_officeId' value='$customer_officeId'>			
<input type='hidden' name='customer_officeId2' value='$customer_officeId2'>				
<input type='hidden' name='customerproject_id' value='$customerproject_id'>		
<input type='hidden' name='vTabFocus' value='$vTabFocus'>	
<input type='hidden' name='module_visit' value='$module_visit'>		


<script type = "text/javascript">

 

$(document).ready ( function ()
{
	//alert($('#txtaddressencoded').val());
});

</script> 

HERE;
//echo "<table><tr><td>":
if($vTabFocus =='') $vTabFocus='Customer';
$tabs = new tabs("CUSTOMER");	
$tabs->start("Customer");
echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of Customers
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr><tr height = 600 valign = top><td id='search-content1'></td><td>
";

echo '  <table width="750" border="0" cellspacing="1" align="center">';

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

if ($startrange1=='') $startrange1 = 0;
if ($perpage1=='')	 $perpage1 = 50;



//if ($PActionMode == 'Add'  || $PActionMode == 'Edit') {

	if (! empty( $_POST['PCustomerCode']) || ($PActionMode == 'Add'  || $PActionMode == 'Edit') )
{
 
	if ($PCustomerCode != '') {
	 
		$sub_query = " Select Customer_Code, Customer_Name, Customer_Telephone1, Customer_Telephone2, Customer_Email, 
					   Customer_Address, customer_special,customer_point,customer_card  ".
					 " ,customer_group, customer_description , customer_website,customer_discountper ".
					 " From Customer ".
					 " Where Customer_Code = '".$PCustomerCode."'";
		// echo $sub_query; exit;		 
				 
		$sub_result=selectData($connection, $sub_query);
		
		$txtCode    = $sub_result[0];
		$txtName    = $sub_result[1];
		$txtPhone1  = $sub_result[2];
		$txtPhone2  = $sub_result[3];
		$txtEmail   = $sub_result[4];
		$txtAddress = urldecode($sub_result[5]);
		$txtCustomerSpecial = $sub_result[6];
		$txtRewardedPoints = $sub_result[7];
		$txtLedgerClientnbr = $sub_result[8];


		$txtLedgerClientCard = $sub_result[8];
	    $txtWebsite = $sub_result[11];
	    $txtdiscountper = $sub_result[12];
		
		$txtgroupname = $sub_result[10];
		$txtdescname = $sub_result[11];
		$CodeMode = ' readonly ';
	}
	else {
		$sub_query = " Select ifNull(Max(Lpad(Customer_Code,10,'0')),0) + 1 ".
					 " From Customer ";
		$sub_result = selectData($connection, $sub_query);
		$txtCode    = $sub_result[0];
	
	}
	
		
	
	echo"<tr><td colspan='5'>";
	echo"  <table width='700' border='0' cellspacing='1' align='left'>";
	echo"	<tr bgcolor='#F7F7F7'> 
		<td height='20' align='left'><span class='style5'><b>Search </b></span></td><td>
		<input type='text' name='searchcustomer' id='searchcustomer' value='$searchcustomer'>";
		
echo " <button type='button' id='btnSearch' name='btnSearch' onclick=\"SearchCust(); return false;\" title='Search'><span><span>Search</span></span></button>";		
echo "</td></tr>";
	echo"	<tr bgcolor='#F7F7F7'>
			  <td height='20' colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td>
			</tr>";
			
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'></span></td>";
	echo"	  <td width='500'><input type='hidden' name='txtCode' id='txtCode' value='$txtCode' style='width:126px;' maxlength='10' $CodeMode   /></td>";
	echo"	</tr>";
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Name</span></td>";
	echo"	  <td width='500'><input type='text' name='txtName' id='txtName' value='".htmlspecialchars($txtName, ENT_QUOTES)."'  style='width:350px;' maxlength='50'  />";
	
	echo"</td>";
	
	if($PLedgerNo!='' and $txtPhone1=='' and $fromcallerid==1)
	{
		
//		$txtPhone1 = $PLedgerNo;
		}
		
	echo"	</tr>";
	if($PActionMode != 'Add' && $module_visit != 1){
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Client's Code</span></td>";
	echo"	  <td width='500'><input type='text' name='txtLedgerClientnbr' id='txtLedgerClientnbr' value='$txtLedgerClientnbr' maxlength='10' style='width:140px;' readonly  />";
	 echo "&nbsp;&nbsp;<img src='img/openlist.png' title=' Select Credit ' width='17' height='17' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCreditCard(3); ' />";
	echo "</td></tr>";
	
	}
	if($module_visit != 1) {
	echo"<tr><td width='100'><span class='style5'>Client's Card</span></td><td width='500'>
	<input type='text' name='txtLedgerClientCard' id='txtLedgerClientCard' value='$txtLedgerClientCard' maxlength='10' style='width:140px;' /></td>";
	echo"</tr>";}
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Phone (1)/(2)</span></td>";
	echo"	  <td width='500'>
					<input type='text' name='txtPhone1' id='txtPhone1' value='".htmlspecialchars($txtPhone1, ENT_QUOTES)."'  style='width:163px;' maxlength='25'  /> - 
					<input type='text' name='txtPhone2' id='txtPhone2' value='".htmlspecialchars($txtPhone2, ENT_QUOTES)."'  style='width:164px;' maxlength='25'  />
			  ";
	if($module_visit != 1){		  
	echo "&nbsp;&nbsp;<span class='style5' style='margin: 0 10px 0px 50px;'>Special Customer</span>&nbsp;&nbsp;<select name='txtCustomerSpecial' id='txtCustomerSpecial'>";
	echo "<option value='0' ";
	if(!$txtCustomerSpecial) echo 'selected';
	echo " >0</option>";
	echo "<option value='1' ";
	if($txtCustomerSpecial == 1) echo 'selected';
	echo " >1</option>";
	echo"</select>";
	}
	echo "</td>";
	echo"	</tr>";
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Email</span></td>";
	echo"	  <td width='500'><input type='text' name='txtEmail' id='txtEmail' value='".htmlspecialchars($txtEmail, ENT_QUOTES)."' style='width:350px;' maxlength='30'  />";
	
	echo "<tr bgcolor = '#F7F7F7'>
	
	<td> <span class = 'style5'>Discount Per</span></td>
	<td> ";
	if( $FC_CashRegisterDisc == 1 )
	echo "<input style = 'width:45px;' type ='text' name = 'txtdiscountper' id = 'txtdiscountper' value='".htmlspecialchars($txtdiscountper, ENT_QUOTES)."' /> %";
	else echo "<span class='style5'>$txtdiscountper %</span><input style = 'width:45px;' type ='hidden' name = 'txtdiscountper' id = 'txtdiscountper' value='".htmlspecialchars($txtdiscountper, ENT_QUOTES)."' />";
	echo "</td>
	
	</tr>";
	// Richard Website
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Website</span></td>";
	echo"	  <td width='500'><input type='text' name='txtWebsite' id='txtWebsite' value='".htmlspecialchars($txtWebsite, ENT_QUOTES)."' style='width:350px;' maxlength='30'  />";
	
	$readonly = "";
	if($POS_RedeemPoints == 1) $readonly="readonly";
	
	if($txtRewardedPoints != '')
	echo "&nbsp;&nbsp;<span class='style5' style='margin: 0 10px 0px 50px;'>  Points</span>&nbsp;
				<input type='text' name='txtRewardedPoints' value='$txtRewardedPoints' $readonly onkeypress='return (event.charCode >= 48 && event.charCode <= 57) || (event.charCode== 46) || (event.charCode >= 0 && event.charCode <= 31)' style='width:80px;'>";
	echo"</td>";
	echo"	</tr>";
	
	
	
	if($module_visit == 1){
		
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Group Name </span></td>";
	echo"	  <td width='500'><input type='text' name='txtgroupname' id='txtgroupname' value='".htmlspecialchars($txtgroupname, ENT_QUOTES)."' style='width:350px;' maxlength='100'  />";
	echo"</td>";
	echo"	</tr>";
	
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Description </span></td>";
	echo"	  <td width='500'><select name='txtdescname' id='txtdescname' style='width:350px;'>";
	echo "<option value='' ".($txtdescname == ''?'selected':'')." ></option>";
	echo "<option value='Dealer' ".($txtdescname == 'Dealer'?'selected':'')." >Dealer</option>";
	echo "<option value='Construction Company' ".($txtdescname == 'Construction Company'?'selected':'')." >Construction Company</option>";
	echo "<option value='Private Sector' ".($txtdescname == 'Private Sector'?'selected':'')." >Private Sector</option>";
	echo "<option value='Manufacturer' ".($txtdescname == 'Manufacturer'?'selected':'')." >Manufacturer</option>";
	echo"</select></td>";
	echo"	</tr>";
	}
	
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Address</span></td>";
	echo"	  <td width='500'>
	
	
	
	<input type = 'hidden' name = 'txtaddressencoded' id = 'txtaddressencoded' value = '' />
	<textarea name='txtAddress' id='txtAddress' cols=42 rows=4>".htmlspecialchars($txtAddress, ENT_QUOTES)."</textarea>
	</td>";
	echo"	</tr>";
	echo"	<tr bgcolor='#DDDDDD'>";
	echo"	  <td colspan='2' align='center'>
		";
echo "<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitRecord(); return false;' title='Submit'><span><span>Submit</span></span></button>";
if( $module_visit == 1 && $PCustomerCode != '')
echo "<button type='button' id='btnPrint' name='btnPrint' onclick='PrintRecord(); return false;' title='Print'><span><span>Print</span></span></button>";
echo "<button type='button' id='btnClear' name='btnClear' onclick='CancelRecord(); return false;' title='Cancel'><span><span>Cancel</span></span></button>";

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

}

if ($PActionMode == '' or $PActionMode == 'Submit') {
	echo"<tr>
		  <td bgcolor='#DDDDDD' ><span class='style4'>Search by <br> Code / Name";
	if($module_visit != 1)
		echo " / Card";	
	echo  "</span></td>
		  <td bgcolor='#DDDDDD'  ><input type='text' name='PLedgerNo' id = 'keyword' value='$PLedgerNo'  size='30'  />
			<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitForm();return false;' title='Find'><span><span>Find</span></span></button>
			<button type='button' id='btnCancel' name='btnCancel' onclick='clearform();return false;' title='Cancel'><span><span>Cancel</span></span></button>
			<button type='button' id='btnAdd' name='btnAdd' onclick='AddRecord();return false;' title='Add'><span><span>Add</span></span></button>

			<span class='style4'>Per page </span><span class='style11'><select name='perpage' id='perpage' value='$perpage' onchange='ClearForm();'>";
              
			
			if ($perpage==10)
				$s10 = 'selected';
			else if ($perpage==20)
				$s20 = 'selected';	
			else if ($perpage==30)
				$s30 = 'selected';	
			else if ($perpage==40)
				$s40 = 'selected';
			else if ($perpage==50)
				$s50 = 'selected';

			
				
        echo'<option '.$s10.' value="10">10</option>
			 <option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';	
			 
	echo"  </td>
		</tr>";
}


echo "<tr><td colspan='2'><table>";

echo"<tr bgcolor='#E5E5E5'>
      <td width='20'>&nbsp;</td>
	  <td width='20'>&nbsp;</td>";
if($module_visit == 1) 	echo "<td width='20'>&nbsp;</td>";  
 echo "<td width='80'><span class='style4'>Code </span></td>
      <td width='250'><span class='style4'>Name </span></td>";
if($module_visit != 1)
echo "<td width='100'><span class='style4'>Card #</span></td>";	
echo "	  <td width='150'><span class='style4'>Phone #</span></td>";
echo "	  <td width='120'><span class='style4'>Disc.%</span></td>";
if($module_visit != 1)	  
echo "<td width='150'><span class='style4'>Rewarded Points</span></td>";
echo "</tr>";


			
$sub_query = " Select Customer.Customer_Code As Ledger_Number, Customer.Customer_Name As Ledger_Name, ".
			" Concat(Customer_Name, ' Tel#: ', Customer_Telephone1) As CustomerRemark, Customer.Customer_Telephone1, ".
			" Concat(Customer_Name, if(ifnull(Customer_Telephone1,'') != '', concat('<br>Tel#: ', Customer_Telephone1), ''), if(ifnull(Customer_Address,'') != '', concat('<br>Address: ', Customer_Address), '')) As CustomerRemark2 ".
			" , Customer_point, customer_card, Customer_DiscountPer as discountper, ifnull(customer_special,0) as customerSpecial ".
			" From Customer ".
			" Where (Customer.Customer_Code like '%".$PLedgerNo."%' or Customer.Customer_Name like '%".$PLedgerNo."%' or Customer.Customer_Telephone1 like '%".$PLedgerNo."%' ";
if($module_visit != 1)
	$sub_query .= " or customer_card like '".$PLedgerNo."%' ";
$sub_query .= "	) ";
if($searchcustomer !='') 
	$sub_query=$sub_query." and (Customer.Customer_Code like '%".$searchcustomer."%' or Customer.Customer_Name like '%".$searchcustomer."%') ";			
if($frm == 5) 	$sub_query=$sub_query." Order By Lpad(Customer.Customer_Code,10,'0') asc";
else	$sub_query=$sub_query." Order By Lpad(Customer.Customer_Code,10,'0') desc";
		

$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($sub_result);

		
$sub_query = $sub_query." limit ".$startrange.",".$perpage;

$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
while($sub_rows=mysql_fetch_array($sub_result)){
	
	extract($sub_rows);
	if($customerSpecial == 0) $CustomerPoint = 0;
	else $CustomerPoint = $Customer_point;
	
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";		

    $desc=ereg_replace("'","%27",$Ledger_Name);
	$CustomerRemark2=ereg_replace("'","%27",$CustomerRemark2);
	$CustomerRemark2 = nl2br($CustomerRemark2);
	echo"<tr $Color>";
	echo " <td align='center' valign='center'><span class='style15'><img src='img/edit.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"UpdateRecord('".$Ledger_Number."')\" title='Edit Record'  ></span></td>";
	echo " <td align='center' valign='center'><span class='style15'><img src='img/select.png'  onMouseOver=\"style.cursor='pointer'\" 
	onclick=\"SelectRecord('$Ledger_Number','$desc','$CustomerRemark','$Rest','$CustomerRemark2','$discountper','$CustomerPoint');\" title='Select Record'  ></span></td>";
if($module_visit == 1)
	echo " <td align='center' valign='center'><span class='style15'><img src='img/delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"deleteRecord('$Ledger_Number');\" title='Delete Record'  ></span></td>";
	echo"  <td align='left'><span class='style5'>$Ledger_Number</span></td>";
	echo"  <td align='left'><span class='style5'>$Ledger_Name</span></td>";
	if($module_visit != 1)
	echo"  <td align='left'><span class='style5'>$customer_card</span></td>";
	echo"  <td align='left'><span class='style5'>$Customer_Telephone1</span></td>";
	echo"  <td align='left'><span class='style5'>$discountper</span></td>";
	if($module_visit != 1) echo"  <td align='left'><span class='style5' style='cursor: pointer' onclick=\"openListPoints('$Ledger_Number')\">$Customer_point</span></td>";
    echo"</tr>";
	
}	

echo "</table></td></tr>";
echo"<tr><td colspan='5'>&nbsp;</td></tr>
	 <tr height='30'><td colspan=5><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff= $startrange - $perpage;
		
if (($diff) >= 0 ){
	$prvstartrange = $startrange - $perpage;
	echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange <= $totalrows){
	$startrange = $startrange + $perpage;
	if  ($startrange < $totalrows)
		echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='170'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";

function fbegin()
{
	mysql_query("START TRANSACTION");
}
function fcommit(){
	mysql_query("COMMIT");
}
function frollback()
{
	mysql_query("ROLLBACK");
}



print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
		//include("toolbar.php");
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

if($frm==3 and $txtId!='' and $Ledger_Number1!=''){
	$query = "update temp_retail set customer_code = '".$Ledger_Number1."', Sale_Type = 'delivery' where sale_id = $txtId ;";
	$result = mysql_query($query,$connection);

	echo'<script type="text/javascript" language="javascript">
			self.close();
			
			 
		</script>';
} 
else if($frm==3 and $txtId=='' and $Ledger_Number1!=''){
	echo'<script type="text/javascript" language="javascript">
			self.close();
		</script>';
}
	
print <<<HERE
&nbsp;</td></tr>
		
   </table>
HERE;
			
$tabs->end();

if( $module_visit != 1){
$tabs->start("CallingRecords");

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of Callers
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";
		
	echo"<tr height = 600 valign = top><td id='search-content1'></td><td>";

echo '  <table width="750" border="0" cellspacing="1" align="center">';

if ($startrange1=='') $startrange1 = 0;
if ($perpage1=='')	 $perpage1 = 50;


echo"<tr>
		  <td bgcolor='#DDDDDD' colspan='3'><span class='style4'>Search by <br> Code / Name</span></td>
		  <td bgcolor='#DDDDDD' colspan='3'><input type='text' name='PLedgerNo1' id = 'keyword1' value='$PLedgerNo1'  size='30'  />
			<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitForm1();return false;' title='Find'><span><span>Find</span></span></button>
			<span class='style4'>Per page </span><span class='style11'><select name='perpage1' id='perpage1' value='$perpage1' onchange='ClearForm1();'>";
              
			
			if ($perpage1==10)
				$s10 = 'selected';
			else if ($perpage1==20)
				$s20 = 'selected';	
			else if ($perpage1==30)
				$s30 = 'selected';	
			else if ($perpage1==40)
				$s40 = 'selected';
			else if ($perpage1==50)
				$s50 = 'selected';

			
				
        echo'<option '.$s10.' value="10">10</option>
			 <option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';	
			 
	echo"  </td>
		</tr>";

echo"<tr bgcolor='#E5E5E5'>
      <td width='20'>&nbsp;</td>
	  <td width='20'>&nbsp;</td>
      <td width='80'><span class='style4'>Date </span></td>
      <td width='250'><span class='style4'>Time </span></td>
	  <td width='150'><span class='style4'>Customer</span></td>
	  <td width='150'><span class='style4'>Phone #</span></td>
    </tr>";


			
$sub_query= " Select concat(substring(callerid_date,-2,2),'/',substring(callerid_date,1,2)) callerid_date,concat(substring(callerid_time,1,2),':',substring(callerid_time,3,4)) callerid_time,Customer.Customer_Code As Ledger_Number, Customer.Customer_Name As Ledger_Name, ".
			" caller_id_status,Concat(Customer_Name, ' Tel#: ', Customer_Telephone1) As CustomerRemark, Customer.Customer_Telephone1, ".
			" Concat(Customer_Name, if(ifnull(Customer_Telephone1,'') != '', concat('<br>Tel#: ', Customer_Telephone1), ''), if(ifnull(Customer_Address,'') != '', concat('<br>Address: ', Customer_Address), '')) As CustomerRemark2 ".
			" From CallerId left join Customer on CallerId.callerid_number = Customer.Customer_Telephone1".
			" Where (ifnull(Customer.Customer_Code,'') like '%".$PLedgerNo1."%' or ifnull(Customer.Customer_Name,'') like '%".$PLedgerNo1."%' or ifnull(Customer.Customer_Telephone1,'') like '%".$PLedgerNo1."%' ) ".
			" Order By callerid_id desc";
		
//echo $sub_query;
$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
$totalrows1 = mysql_num_rows($sub_result);

		
$sub_query = $sub_query." limit ".$startrange1.",".$perpage1;

$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
while($sub_rows=mysql_fetch_array($sub_result)){
	
	extract($sub_rows);

	$ct+=1;

	if($caller_id_status==1)
		$Color="style='background-color:#01DFA5'";
	else			
		$Color="style='background-color:#F5A9BC'";		

    $desc=ereg_replace("'","%27",$Ledger_Name);
	$CustomerRemark2=ereg_replace("'","%27",$CustomerRemark2);

	
	
	echo"<tr $Color>";
	echo " <td align='center' valign='center'><span class='style15'></span></td>";
	echo " <td align='center' valign='center'><span class='style15'></span></td>";
	echo"  <td align='left'><span class='style5'>$callerid_date</span></td>";
	echo"  <td align='left'><span class='style5'>$callerid_time</span></td>";
	echo"  <td align='left'><span class='style5'>$Ledger_Name</span></td>";
	echo"  <td align='left'><span class='style5'>$Customer_Telephone1</span></td>";
    echo"</tr>";
	
}	

echo"<tr><td colspan='5'>&nbsp;</td></tr>
	 <tr height='30'><td colspan=5><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff1= $startrange1 - $perpage1;
		
if (($diff1) >= 0 ){
	$prvstartrange1 = $startrange1 - $perpage1;
	echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=SetPrvPage1('".$prvstartrange1."','".$perpage1."','CallingRecords')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange1 <= $totalrows1){
	$startrange1 = $startrange1 + $perpage1;
	if  ($startrange1 < $totalrows1)
		echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=SetNextPage1('".$startrange1."','".$perpage1."','CallingRecords')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='170'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";




print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
		//include("toolbar.php");
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

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

$tabs->end();
}
if( $module_visit == 1 && $PCustomerCode != ''){
$tabs->start("Main Office");

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Main Office
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";
		
	echo"<tr height = 600 valign = top><td id='search-content1'></td><td>";

echo '  <table width="750" border="0" cellspacing="0" align="center"><col width="90"><col width="200"><col width="160"><col width="100"><col width="100"><col width="100">';

if ($startrange2=='') $startrange2 = 0;
if ($perpage2=='')	 $perpage2 = 50;


echo"<tr>
		  <td bgcolor='#DDDDDD' colspan='3'><span class='style4'></span></td>
		  <td bgcolor='#DDDDDD' colspan='3'>
			<span class='style4'>Per page </span><span class='style11'><select name='perpage2' id='perpage2' value='$perpage2' onchange='cancelMain();'>";
              
			
			if ($perpage2==10)
				$s10 = 'selected';
			else if ($perpage2==20)
				$s20 = 'selected';	
			else if ($perpage2==30)
				$s30 = 'selected';	
			else if ($perpage2==40)
				$s40 = 'selected';
			else if ($perpage2==50)
				$s50 = 'selected';

			
				
        echo'<option '.$s10.' value="10">10</option>
			 <option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';	
			 
	echo"  </td>
		</tr>";

if($customer_officeId != ''){
	$queryoffice = "select office_address, office_contact from Customer_Offices where customer_officeId=$customer_officeId";
	$resoffice = mysql_query($queryoffice,$connection);
	$rowoffice = mysql_fetch_row($resoffice);
	$txtmainaddress = $rowoffice[0];
	$txtmaincontact = $rowoffice[1];
}
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Main Address</span></td><td colspan='4'>";
echo "<input type='text' name='txtmainaddress' id='txtmainaddress' value='$txtmainaddress' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Contact</span></td><td colspan='4'>";
echo "<input type='text' name='txtmaincontact' id='txtmaincontact' value='$txtmaincontact' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='20' bgcolor='#F7F7F7'><td colspan='6'><span class='style5'>Contact Info</span></td></tr>";
echo "<tr height='20' bgcolor='#F7F7F7'><td colspan='6'><div style='overflow:scroll;height:200px;width:750px;border:0px solid #000000;' id='maincontactinfo'>";
mainContactInfo($customer_officeId,$contactinfo_id,$grid_color1,$grid_color2,$connection);
echo "</div></td></tr>";
echo"<tr bgcolor='#DDDDDD'><td colspan='6' align='center'><button type='button' name='btnMain' id='btnMain' onclick=\"SubmitMain(); return false;\" title='Submit'>
<span><span>Submit</span></span></button>
<button type='button' name='btnCancel2' id='btnCancel2' onclick=\"cancelMain(); return false;\" title='Cencel'>
<span><span>Cancel</span></span></button></td></tr>";

echo"<tr><td colspan='6' align='center'><table border=0 width='750px'><col width=40><col width=40><col width=350><col width=350>";
echo "<tr bgcolor='#E5E5E5'><td></td><td></td><td align='center'><span class='style4'>Main Address</span></td><td align='center'><span class='style4'>Contact</span></td></tr>";
$querymain = "select customer_officeId, office_address, office_contact 
			from Customer_Offices 
			where Customer_Code='$PCustomerCode' and mainoffice_id is null ";
$resmain = mysql_query($querymain,$connection);

$totalrows2 = mysql_num_rows($resmain);

		
$querymain = $querymain." limit ".$startrange2.",".$perpage2;
$ct=0;
while($rowmain = mysql_fetch_row($resmain)){
	$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='pointer'\" onclick=\"UpdateMain('".$rowmain[0]."')\" title='Edit Record'  ></span></td>";
	echo " <td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"deleteMain('$rowmain[0]');\" title='Delete Record'  ></span></td>";
	echo"  <td align='left'><span class='style5'>$rowmain[1]</span></td>";
	echo"  <td align='left'><span class='style5'>$rowmain[2]</span></td>";
	echo"</tr>";
}
echo "</table></td></tr>";	
echo"<tr><td colspan='6'>&nbsp;</td></tr>
	 <tr height='30'><td colspan=6><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff2= $startrange2 - $perpage2;
		
if (($diff2) >= 0 ){
	$prvstartrange2 = $startrange2 - $perpage2;
	echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=SetPrvPage2('".$prvstartrange2."','".$perpage2."','Main%20Office')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange2 <= $totalrows2){
	$startrange2 = $startrange2 + $perpage2;
	if  ($startrange2 < $totalrows2)
		echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=SetNextPage2('".$startrange2."','".$perpage2."','Main%20Office')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='170'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";




print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
		//include("toolbar.php");
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

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

$tabs->end();


$tabs->start("Branches");

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Branches
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";
		
	echo"<tr height = 600 valign = top><td id='search-content1'></td><td>";

echo '  <table width="750" border="0" cellspacing="0" align="center"><col width="90"><col width="200"><col width="160"><col width="100"><col width="100"><col width="100">';

if ($startrange3=='') $startrange3 = 0;
if ($perpage3=='')	 $perpage3 = 50;


echo"<tr>
		  <td bgcolor='#DDDDDD' colspan='3'><span class='style4'></span></td>
		  <td bgcolor='#DDDDDD' colspan='3'>
			<span class='style4'>Per page </span><span class='style11'><select name='perpage3' id='perpage3' value='$perpage3' onchange=''>";
              
			
			if ($perpage3==10)
				$s10 = 'selected';
			else if ($perpage3==20)
				$s20 = 'selected';	
			else if ($perpage3==30)
				$s30 = 'selected';	
			else if ($perpage3==40)
				$s40 = 'selected';
			else if ($perpage3==50)
				$s50 = 'selected';

			
				
        echo'<option '.$s10.' value="10">10</option>
			 <option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';	
			 
	echo"  </td>
		</tr>";

if($customer_officeId2 != ''){
	$queryoffice = "select office_address, office_contact,mainoffice_id from Customer_Offices where customer_officeId=$customer_officeId2";
	$resoffice = mysql_query($queryoffice,$connection);
	$rowoffice = mysql_fetch_row($resoffice);
	$txtbranchaddress = $rowoffice[0];
	$txtbranchcontact = $rowoffice[1];
	$txtparentaddress = $rowoffice[2];
}
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Branch Address</span></td><td colspan='4'>";
echo "<input type='text' name='txtbranchaddress' id='txtbranchaddress' value='$txtbranchaddress' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Contact</span></td><td colspan='4'>";
echo "<input type='text' name='txtbranchcontact' id='txtbranchcontact' value='$txtbranchcontact' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Main Address</span></td><td colspan='4'>";
echo "<select name='txtparentaddress' id='txtparentaddress' style='width:400px;'>";
$query = "select customer_officeId,office_address from Customer_Offices where Customer_Code='$PCustomerCode' and mainoffice_id is null ";
$res = mysql_query($query,$connection);
echo "<option value=''></option>";
while($rw = mysql_fetch_row($res)){
	echo "<option value='$rw[0]' ".($txtparentaddress == $rw[0]?'selected':'')." >$rw[1]</option>";
}
echo"</select></td><td></td>";			
echo "</tr>";
echo "<tr height='20' bgcolor='#F7F7F7'><td colspan='6'><span class='style5'>Contact Info</span></td></tr>";
echo "<tr height='20' bgcolor='#F7F7F7'><td colspan='6'><div style='overflow:scroll;height:200px;width:750px;border:0px solid #000000;' id='branchcontactinfo'>";
branchContactInfo($customer_officeId2,$contactinfo_id2,$grid_color1,$grid_color2,$connection);
echo "</div></td></tr>";
echo"<tr bgcolor='#DDDDDD'><td colspan='6' align='center'><button type='button' name='btnBranch' id='btnBranch' onclick=\"SubmitBranch(); return false;\" title='Submit'>
<span><span>Submit</span></span></button>
<button type='button' name='btnCancel3' id='btnCancel3' onclick=\"cancelBranch(); return false;\" title='Cancel'>
<span><span>Cancel</span></span></button></td></tr>";

echo"<tr><td colspan='6' align='center'><table border=0 width='750px'><col width=40><col width=40><col width=200><col width=250><col width=250>";
echo "<tr bgcolor='#E5E5E5'><td></td><td></td><td align='center'><span class='style4'>Branch Address</span></td>
<td align='center'><span class='style4'>Contact</span></td><td align='center'><span class='style4'>Main Address</span></td></tr>";
$querybranch = "select b.customer_officeId, b.office_address, b.office_contact,p.office_address 
			from Customer_Offices b
			left join Customer_Offices p on p.customer_officeId = b.mainoffice_id 		
			where b.Customer_Code=$PCustomerCode and b.mainoffice_id is not null "; 
$resbranch = mysql_query($querybranch,$connection);

$totalrows3 = mysql_num_rows($resbranch);

		
$querybranch = $querybranch." limit ".$startrange3.",".$perpage3;
$ct=0;
while($rowbranch = mysql_fetch_row($resbranch)){
	$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='pointer'\" onclick=\"UpdateBranch('".$rowbranch[0]."')\" title='Edit Record'  ></span></td>";
	echo " <td align='center' valign='center'><span class='style15'><img src='img/c_delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"deleteBranch('$rowbranch[0]');\" title='Delete Record'  ></span></td>";
	echo"  <td align='left'><span class='style5'>$rowbranch[1]</span></td>";
	echo"  <td align='left'><span class='style5'>$rowbranch[2]</span></td>";
	echo"  <td align='left'><span class='style5'>$rowbranch[3]</span></td>";
	echo"</tr>";
}
echo "</table></td></tr>";	
echo"<tr><td colspan='6'>&nbsp;</td></tr>
	 <tr height='30'><td colspan=6><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff3= $startrange3 - $perpage3;
		
if (($diff3) >= 0 ){
	$prvstartrange3 = $startrange3 - $perpage3;
	echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=SetPrvPage2('".$prvstartrange3."','".$perpage3."','Branches')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange3 <= $totalrows3){
	$startrange3 = $startrange3 + $perpage3;
	if  ($startrange3 < $totalrows3)
		echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=SetNextPage2('".$startrange3."','".$perpage3."','Branches')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='170'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";




print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
		//include("toolbar.php");
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

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

$tabs->end();


$tabs->start("Projects");

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' >";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:650px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Projects
			</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";
		
	echo"<tr height = 600 valign = top><td id='search-content1'></td><td>";

echo '  <table width="750" border="0" cellspacing="0" align="center"><col width="120"><col width="170"><col width="160"><col width="100"><col width="100"><col width="100">';

if ($startrange4=='') $startrange4 = 0;
if ($perpage4=='')	 $perpage4 = 50;


echo"<tr>
		  <td bgcolor='#DDDDDD' colspan='3'><span class='style4'></span></td>
		  <td bgcolor='#DDDDDD' colspan='3'>
			<span class='style4'>Per page </span><span class='style11'><select name='perpage4' id='perpage4' value='$perpage4' onchange=''>";
              
			
			if ($perpage4==10)
				$s10 = 'selected';
			else if ($perpage4==20)
				$s20 = 'selected';	
			else if ($perpage4==30)
				$s30 = 'selected';	
			else if ($perpage4==40)
				$s40 = 'selected';
			else if ($perpage4==50)
				$s50 = 'selected';

			
				
        echo'<option '.$s10.' value="10">10</option>
			 <option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';	
			 
	echo"  </td>
		</tr>";

if($customerproject_id != ''){
	$queryproject = "select p1.customerproject_desc, p1.customerproject_address, p1.customerproject_contact,
					p1.customerproject_phone, p1.customerproject_consultantname, p1.customerproject_consultantdetail,
					p1.customerproject_situation, p1.customerproject_ironname, p1.customerproject_competitorname,
					p2.customerproject_id
					from customer_project p1
					left join customer_project p2 on p2.customerproject_id = p1.customerproject_parent
					where p1.customerproject_id = $customerproject_id";
	$resproject = mysql_query($queryproject,$connection);
	$rowproject = mysql_fetch_row($resproject);
	$txtprojectdesc = $rowproject[0];
	$txtprojectaddress = $rowproject[1];
	$txtprojectcontact = $rowproject[2];
	$txtprojectphone = $rowproject[3];
	$txtprojectconsname = $rowproject[4];
	$txtprojectconsdetail = $rowproject[5];
	$txtprojectsituation = $rowproject[6];
	$txtprojectiron = $rowproject[7];
	$txtprojectcompetitor = $rowproject[8];
	$txtprojectparent = $rowproject[9];
}
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Description</span></td><td colspan='4'>";
echo "<select name='txtprojectdesc' id='txtprojectdesc' style='width:400px;'>";
echo "<option value='' ".($txtprojectdesc==''?'selected':'')." ></option>"; 
echo "<option value='DAM' ".($txtprojectdesc=='DAM'?'selected':'')." >DAM</option>";
echo "<option value='Road Construction' ".($txtprojectdesc=='Road Construction'?'selected':'')." >Road Construction</option>";
echo "<option value='Tower' ".($txtprojectdesc=='Tower'?'selected':'')." >Tower</option>";
echo "<option value='Bridge' ".($txtprojectdesc=='Bridge'?'selected':'')." >Bridge</option>";
echo "<option value='Railway' ".($txtprojectdesc=='Railway'?'selected':'')." >Railway</option>";
echo "<option value='Water Corporation' ".($txtprojectdesc=='Water Corporation'?'selected':'')." >Water Corporation</option>";
echo "<option value='Building' ".($txtprojectdesc=='Building'?'selected':'')." >Building</option>";
echo "<option value='House' ".($txtprojectdesc=='House'?'selected':'')." >House</option>";
echo "<option value='Hotel' ".($txtprojectdesc=='Hotel'?'selected':'')." >Hotel</option>";
echo "<option value='Stadium' ".($txtprojectdesc=='Stadium'?'selected':'')." >Stadium</option>";
echo"</select></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Address</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectaddress' id='txtprojectaddress' value='$txtprojectaddress' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Contact</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectcontact' id='txtprojectcontact' value='$txtprojectcontact' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Phone number</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectphone' id='txtprojectphone' value='$txtprojectphone' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Consultant Name</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectconsname' id='txtprojectconsname' value='$txtprojectconsname' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Consultant Details</span></td><td colspan='4'>";
echo "<textarea name='txtprojectconsdetail' id='txtprojectconsdetail' style='width:400px;'>$txtprojectconsname </textarea></td><td></td>";			
echo "</tr>";
echo "<tr height='10' bgcolor='#F7F7F7'><td colspan='6'></td></tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Current Situation of the Construction</span></td><td colspan='4'>";
echo "<textarea name='txtprojectsituation' id='txtprojectsituation' style='width:400px;height:60px;'>$txtprojectsituation </textarea></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Iron Name Used</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectiron' id='txtprojectiron' value='$txtprojectiron' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Competitor Name</span></td><td colspan='4'>";
echo "<input type='text' name='txtprojectcompetitor' id='txtprojectcompetitor' value='$txtprojectcompetitor' style='width:400px;'></td><td></td>";			
echo "</tr>";
echo "<tr height='30' bgcolor='#F7F7F7'><td><span class='style5'>Related Project</span></td><td colspan='4'>";
echo "<select name='txtprojectparent' id='txtprojectparent' style='width:200px;'>";
echo "<option value=''></option>";
$queryparent = "select customerproject_id,customerproject_desc from customer_project 
				where customer_code='$PCustomerCode' and if( '$customerproject_id' ='',1=1,customerproject_id!='$customerproject_id')";
$resparent = mysql_query($queryparent,$connection);
while($rwparent = mysql_fetch_row($resparent)){
	echo "<option value='$rwparent[0]' ".($txtprojectparent==$rwparent[0]?'selected':'')." >$rwparent[1]</option>";
}	
echo "</select></td><td></td>";			
echo "</tr>";
echo "<tr height='10' bgcolor='#F7F7F7'><td colspan='6'></td></tr>";
echo"<tr bgcolor='#DDDDDD'><td colspan='6' align='center'><button type='button' name='btnProject' id='btnProject' onclick=\"SubmitProject(); return false;\" title='Submit'>
<span><span>Submit</span></span></button>
<button type='button' name='btnCancel4' id='btnCancel4' onclick=\"cancelProject(); return false;\" title='Cancel'>
<span><span>Cancel</span></span></button></td></tr>";

echo"<tr><td colspan='6' align='center'><table border=0 width='750px'><col width=30><col width=30><col width=150><col width=150><col width=150><col width=120><col width=120>";
echo "<tr bgcolor='#E5E5E5'><td></td><td></td><td align='center'><span class='style4'>Description</span></td>
<td align='center'><span class='style4'>Address</span></td><td align='center'><span class='style4'>Contact</span></td>
<td align='center'><span class='style4'>Consultant</span></td><td align='center'><span class='style4'>Related Project</span></td></tr>";
$queryproject = "select p1.customerproject_id,p1.customerproject_desc, p1.customerproject_address, p1.customerproject_contact,
				p1.customerproject_consultantname, p2.customerproject_desc
					from customer_project p1
					left join customer_project p2 on p2.customerproject_id = p1.customerproject_parent
					where p1.customer_code = '$PCustomerCode' "; 
$resproject = mysql_query($queryproject,$connection);

$totalrows3 = mysql_num_rows($resproject);

		
//$queryproject = $queryproject." limit ".$startrange3.",".$perpage3;
//$resproject = mysql_query($queryproject,$connection); echo $queryproject;
$ct=0;
while($rowproject = mysql_fetch_row($resproject)){
	$ct+=1;
		if($ct%2==0)
	 		$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
	if( $customerproject_id == $rowproject[0]) {$Color = "style='background-color:#1e87a5;'";$classt='style111';}	
	else $classt='style5';
	echo"<tr $Color>";
	echo " <td align='center' valign='center'><span class=$classt><img src='img/edit.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"UpdateProject('".$rowproject[0]."')\" title='Edit Record'  ></span></td>";
	echo " <td align='center' valign='center'><span class=$classt><img src='img/c_delete.png'  onMouseOver=\"style.cursor='pointer'\" onclick=\"deleteProject('$rowproject[0]');\" title='Delete Record'  ></span></td>";
	echo"  <td align='left'><span class=$classt>$rowproject[1]</span></td>";
	echo"  <td align='left'><span class=$classt>$rowproject[2]</span></td>";
	echo"  <td align='left'><span class=$classt>$rowproject[3]</span></td>";
	echo"  <td align='left'><span class=$classt>$rowproject[4]</span></td>";
	echo"  <td align='left'><span class=$classt>$rowproject[5]</span></td>";
	echo"</tr>";
}
echo "</table></td></tr>";	
echo"<tr><td colspan='6'>&nbsp;</td></tr>
	 <tr height='30'><td colspan=6><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>";
		
$diff4= $startrange4 - $perpage4;
		
if (($diff4) >= 0 ){
	$prvstartrange4 = $startrange4 - $perpage4;
	echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=SetPrvPage4('".$prvstartrange4."','".$perpage4."','Projects')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='150' align='center'>";
		
if ($startrange4 <= $totalrows4){
	$startrange4 = $startrange4 + $perpage4;
	if  ($startrange4 < $totalrows4)
		echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=SetNextPage4('".$startrange4."','".$perpage4."','Projects')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='170'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";




print <<<HERE
  </table></td><td id='search-content3' ></td></tr>
  <tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:600px;' valign='top'>
HERE;
		//include("toolbar.php");
		echo"</td>
		<td id='search-bottom3' style='height:34px; width:31px;'>";

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

$tabs->end();
}
$tabs->run();


if($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}


 

/* if (! empty( $_POST['PCustomerCode']) )
{
 

	$query = "select * from customer where customer_code = " .$_POST['PCustomerCode'] ;
	$result = mysql_query($query , $connection) or die (mysql_error());
	while ($extractresult = mysql_fetch_array($result))
	{
		   extract($extractresult);
	}
 
} */

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

HERE;
?>