<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
$dt=date('Y-m-d');
include("includes/top.php");
include("opendb.php");
include("test.php");
?>
<script>
var pc=[];
var pn=[];

function handleKeyUp(maxNumToShow)
{
    var selectObj, textObj, functionListLength;
    var i, searchPattern, numShown;

    // Set references to the form elements
    selectObj = document.forms[0].functionselect;
    textObj = document.forms[0].pcode;

    // Remember the function list length for loop speedup
    functionListLength = pc.length;

    // Set the search pattern depending
/*    if(document.forms[0].functionradio[0].checked == true)
    {
        searchPattern = "^"+textObj.value;
    }
    else
    {
        searchPattern = textObj.value;
    }
*/
        searchPattern = "^"+textObj.value;

    // Create a regulare expression
    re = new RegExp(searchPattern,"gi");
    // Clear the options list
    selectObj.length = 0;

    // Loop through the array and re-add matching options
    numShown = 0;
    for(i = 0; i < functionListLength; i++)
    {
        if(pc[i].search(re) != -1)
        {
            selectObj[numShown] = new Option(pc[i],pc[i]);
            numShown++;
        }
        // Stop when the number to show is reached
        if(numShown == maxNumToShow)
        {
            break;
        }
    }
    // When options list whittled to one, select that entry
    if(selectObj.length == 1)
    {
        selectObj.options[0].selected = true;
    }
}

// this function gets the selected value and loads the appropriate
// php reference page in the display frame
// it can be modified to perform whatever action is needed, or nothing
function handleSelectClick()
{
//    document.f1.pname.value=pn[document.f1.functionselect.selectedIndex];
    document.f1.pcode.value=document.f1.functionselect.value;

}

</script>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:steelblue;color:white}
</style>

<center>
<form name='f1' method='post' action='<?print $PHP_SELF?>' onSubmit="handleSelectClick();return true;">
<table>
<th colspan=4>SEARCH CUSTOMER</th>
<tr><td>Customer Name </td><td><input type="text" name="pcode" VALUE="<?print $pcode?>" style="font-size:10pt;width:34ex;"><br>

</td></tr>
<!-- <tr><td>Part Name </td>
    <td><input type=text name='pname' size=32></td></tr> -->
<th colspan=3><input type=submit value='Search' name='sea'>
</td></tr>
</table>
</form>
<?
$pcode=$_REQUEST['pcode'];
if(isset($_POST['sea']))
{
 $sql="select * from customer where cname like'%$pcode%' ";
 $re1=mysqli_query($db,$sql);
 print "<table border=1 width=70%><th>Customer Name <th>A/c Head<th>Branch";
 while($row=mysqli_fetch_array($re1))
 {
     $bname=getBranch($row['brcode'],$db);
   print "<tr><td>$row[cname] </td><td >$row[acname]</td><td >$bname</td></tr>";
 }
 print "</table><br>";





}// end if sea
function getBranch($cde,$db)
{
 $brre=mysqli_query($db,"select brname from branch where brcode='$cde'");
 $brrow=mysqli_fetch_row($brre);
 return $brrow[0];
}
?>
