<html>
<head>

<link rel="stylesheet" type="text/css" href="dbinvsty.css">
<script>
var aragents=new Array();
var arterrys=new Array();
var arreps=new Array();


function agentprf()
{
var httpr= new XMLHttpRequest();
httpr.onreadystatechange=function(){
if(httpr.readyState==4 && httpr.status==200){
var vl=httpr.responseText;

var tmp=vl.split("<td>");
for(cn=0;cn<tmp.length;cn++){
var tmpa=tmp[cn].split("###");
aragents[cn]=tmpa[0];
arterrys[cn]=tmpa[1];
}
}}
httpr.open("POST","agsch.php?actp=items&sprftypes=dsrsales",true);
httpr.send();
}


function agsrcs(pr)
{
//var keys=pr.keyCode;
var keys=window.event.keyCode;

var schtxt=document.getElementById("agn").value;
var schagents=document.getElementById("terlst");
var sz=0;
schagents.style.display="block";
schagents.size=10;

if(keys==40){
schagents.selectedIndex=0;
schagents.focus();}


if(keys==8 && document.getElementById("agn").length==0){
pr.preventDefault();}

if(keys==13){
schagents.style.display="none";
document.getElementById("terlst").focus();}

schagents.length=0;
var tmpa=schtxt.toLowerCase();

for(var cnt=0;cnt<arterrys.length;cnt++){
var tmpb=arterrys[cnt].toLowerCase();
var tmpd=aragents[cnt].toLowerCase();

var rsta=tmpb.indexOf(tmpa);
var rstb=tmpd.indexOf(tmpa);

if(rsta>=0 || rstb>=0 ){
sz++;
var options=document.createElement("option");
var stra=arterrys[cnt]+" - "+aragents[cnt];
options.text=stra;
schagents.add(options);}
}
alert(sz);
if(sz>10){
size=10;}
schagents.size=sz;
}



function selterr(pr)
{
//var keys=pr.keyCode;
var keys=window.event.keyCode;

var terlst=document.getElementById("terlst");
var vl=terlst.options[terlst.selectedIndex].value;
var dt=document.getElementById("agdetails");

if(keys==27){
terlst.style.display="none";
document.getElementById("agn").focus();
}


if(keys==8){
pr.preventDefault();
document.getElementById("agn").focus();
}

if(keys==13){
terlst.size=0;
terlst.style.display="none";
document.getElementById("mdiscounts").focus();
pr.preventDefault();
}

var str=vl.split(" - ");

for(var cnt=0;cnt<aragents.length;cnt++){
if(arterrys[cnt]==str[0] && aragents[cnt]==str[1]){
dt.rows[1].cells[1].innerHTML=aragents[cnt];
dt.rows[2].cells[1].innerHTML=arterrys[cnt];
}
}
}



function selterrclk(pr)
{
//var keys=pr.keyCode;
var keys=window.event.keyCode;
var terlst=document.getElementById("terlst");
var vl=terlst.options[terlst.selectedIndex].value;
var dt=document.getElementById("agdetails");
var sz=0;
var str=vl.split(" - ");
for(var cnt=0;cnt<aragents.length;cnt++){
if(arterrys[cnt]==str[0] && aragents[cnt]==str[1]){
dt.rows[1].cells[1].innerHTML=aragents[cnt];
dt.rows[2].cells[1].innerHTML=arterrys[cnt];
}
}
terlst.style.display="none";
document.getElementById("mdiscounts").focus();
}




function foutsagents()
{
//document.getElementById("schagents").style.display="none";
document.getElementById("schtxt").focus();
}



function agclicks()
{
var schagents=document.getElementById("schagents");
var schtxt=document.getElementById("schtxt");
var vl=schagents.options[schagents.selectedIndex].text;
schtxt.value=vl;
schagents.size=0;
//schagents.style.display="none";
schtxt.focus();
}
</script>
</head>

<body style="font-family:calibri;font-size:small" onload="agentprf()">
</body>
</html>

<?php
printf("<div id='dva'>");
printf("<div class='fts'><BR><BR>");
printf("<div><table id='agdetails' style='font-size:12;border:1px solid silver;width:100%%;background:#F2F2F2;'>");
printf("<tr class='cls'><td colspan='2' style='background:silver;'><b>Area details</b></td></tr>");
printf("<tr class='cls'><td>Agent</td><td></td></tr>");
printf("<tr class='cls'><td>Territory</td><td></td></tr>");
printf("</table></div>");


printf("<div class='mains'>");


printf("<div class='frc' id='frc' style='left:20%%;'>Territory</div><div class='frd' id='frd' style='left:26%%;'><input type='text class='ends' size=25 name='agn' id='agn' onkeyup=\"agsrcs(event)\" onclick=\"agsrcs(event)\"></div>");


printf("<div class='frca' id='frcs' style='left:26%%;'><select id='terlst' onchange=\"selterr(event)\" onkeydown=\"selterr(event)\" onclick=\"selterrclk(event)\" style='z-index:1;display:none;'><option>All</option></select></div></div>");


?>