<?php

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

include("config.inc.php");
include("Functions_Sales.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";
		}}
}	


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


$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"];} 

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

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

	if(vFrm=='1'){
		opener.document.retailpay.txtRetCustomerCode.value = value1;
		opener.document.retailpay.txtRetCustomerName.value = value2;
		opener.document.retailpay.txtRetRemark.value = value3;
		opener.document.retailpay.txtRetCustomerName.focus();
		opener.document.retailpay.submit();
	}
	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();
		
	}
	
	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;
	
	x.PActionMode.value='';
	x.PCustomerCode.value='';
	
	x.txtCode.value='';
	x.txtName.value='';
	x.txtPhone1.value='';
	x.txtPhone2.value='';
	x.txtEmail.value='';
	x.txtAddress.value='';
	
	x.submit();
}
function SubmitForm()
{	

  //document.search.keyword.value='';
  document.form1.action='list_customers.php?startrange=0';
  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() {
	var x = document.form1;
	var result = CheckFields();
	
	vFrm  = document.form1.frm.value;
	vtxtId = document.form1.txtId.value;
	
	if (result == 1) {
		x.PActionMode.value='Submit';
		document.form1.action='list_customers_Actions.php?frm='+vFrm+'&txtId='+vtxtId;
		document.form1.submit();
	}
}

function UpdateRecord(CustomerCode) {
	var x = document.form1;
	
	x.PActionMode.value='Edit';
	x.PCustomerCode.value=CustomerCode;
	x.submit();

}

function CheckFields(){
  
    var x = document.form1;
	
	var vCode = x.txtCode.value;
	var vName = x.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 OpenKeyboard(field){
	VirtualKeyboard.attachInput(field);
	VirtualKeyboard.open(field,'td');
}
</script>



</head>

<body>
<form id="form1" name="form1" method="post" action="">
<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'>
			
			

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

$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 ($PCustomerCode != '') {
		$sub_query = " Select Customer_Code, Customer_Name, Customer_Telephone1, Customer_Telephone2, Customer_Email, Customer_Address, customer_special  ".
					 " From Customer ".
					 " Where Customer_Code = '".$PCustomerCode."'";
					 
		$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 = $sub_result[5];
		$txtCustomerSpecial = $sub_result[5];
		
		$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='680' border='0' cellspacing='1' align='left'>";
	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'  /></td>";
	
	if($PLedgerNo!='' and $txtPhone1=='' and $fromcallerid==1)
		$txtPhone1 = $PLedgerNo;
		
	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'  />
			 </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'  /></td>";
	echo"	</tr>";
	echo"	<tr bgcolor='#F7F7F7'>";
	echo"	  <td width='100'><span class='style5'>Address</span></td>";
	echo"	  <td width='500'>
	
	
	<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>
";
				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' colspan='3'><span class='style4'>Search by <br> Code / Name</span></td>
		  <td bgcolor='#DDDDDD' colspan='2'><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 bgcolor='#E5E5E5'>
      <td width='20'>&nbsp;</td>
	  <td width='20'>&nbsp;</td>
      <td width='80'><span class='style4'>Code </span></td>
      <td width='250'><span class='style4'>Name </span></td>
	  <td width='150'><span class='style4'>Phone #</span></td>
    </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 ".
			" From Customer ".
			" Where (Customer.Customer_Code like '%".$PLedgerNo."%' or Customer.Customer_Name like '%".$PLedgerNo."%' or Customer.Customer_Telephone1 like '%".$PLedgerNo."%' ) ".
			" Order By Lpad(Customer.Customer_Code,10,'0') desc";
		
//echo $sub_query;
$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);

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

	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');\" title='Select 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>";
	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'>";
		
$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();


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



$tabs->run();


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


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

HERE;
?>