var currow=0;
var lastrow=0;
var negIndx=0;
var earIndx=0;
var earlier= new Array(1);
var negative= new Array(1);
var earpos=0;
var negpos=0;
var ctrlear="";
var ctrlneg="";
function InitPage()
{
$('form tbody.scrollContent tr').hover(function () {
$(this).addClass('rowhover');
}, function () {
$(this).removeClass('rowhover');
});
$('form tbody.scrollContent tr').click(function () {
currow=$(this).index();
GetRowData(this);
});
}
function ResetRow()
{
currow=0;
lastrow=$('#casetable tr').length-1;
}
function GetRowData(SelectedRow)
{
var rowId=$(SelectedRow).attr('id');
QueryStr="rand="+Math.round(Math.random()*4+1)+"&uuid="+$("#"+rowId+"uuid").val();
OpenMatrixDialog("dedupefound?"+QueryStr,"Dedupe Details").then(function(retVal) {
if(retVal==1)
{
$(SelectedRow).remove();
lastrow=currow-1;
changeRow();
}
});
}
function keyListen(param1,param2,e) {
var keycode = e.keyCode;
if(keycode==13)
{
GetRowData($('tr:eq('+currow+')', $("#casetable")));
}
else
{
if(keycode==40)
{
currow=currow+1;
if(currow>=$('#casetable tr').length){currow=1;lastrow=$('#casetable tr').length-1;}
changeRow();
}
if(keycode==38)
{
currow=currow-1;
if(currow<=0){currow=$('#casetable tr').length-1;lastrow=1;}
changeRow();
}
}
}
function changeRow()
{
$('tr:eq('+currow+')', $("#casetable")).addClass('rowhover');
$('tr:eq('+lastrow+')', $("#casetable")).removeClass('rowhover');
$('tr:eq('+currow+')', $("#casetable")).focus();
lastrow=currow;
}
function callkeydownhandler(evnt) {
var ev = evnt;
keyListen('','',ev);
}
window.document.addEventListener("keydown", callkeydownhandler, false);
function FindMatchedRecords(uuid)
{
$("#efoundon").html("Loading
");
$("#nfoundon").html("Loading
");
RunAjax("GET","deduperecords","uuid="+uuid,1);
}
function AfterResponse(response,oprID)
{
if(oprID==1)
{
negIndx=0;
earIndx=0;
if(response.trim()!='')
{
var rows=response.split(RowDelim);
for(rindx=0;rindx("+(earIndx==0 ? "No" : earIndx)+" Match Found)");
$("#nfound").html("("+(negIndx==0 ? "No" : negIndx)+" Match Found)");
FillDetails(1);
FillDetails(2);
}
}
function findRecord(arrOpr,opr)
{
tempPos= opr==1 ? earpos:negpos;
maxLen= opr==1 ? earIndx-1:negIndx-1;
if(arrOpr==1) tempPos=0;
if(arrOpr==2)
{
if(tempPos>0) tempPos=tempPos-1;
else return false;
}
if(arrOpr==3)
{
if(tempPos 0)
{
var addropt=MatchWith(earlier[earpos][1],'ear');
MatchFoundOn(earlier[earpos][2],'ear');
$("#earname").val(earlier[earpos][6]);
$("#eardob").val(earlier[earpos][7]);
if(addropt==1)
{
$("#earaddress").val(earlier[earpos][8]+" "+earlier[earpos][9]+" "+earlier[earpos][10]);
}
else if(addropt==2)
{
$("#earaddress").val(earlier[earpos][14]+" "+earlier[earpos][15]+" "+earlier[earpos][16]);
}
else if(addropt==3)
{
addr=earlier[earpos][8].trim()!='' ? ('Residence Address: '+earlier[earpos][8]+" "+earlier[earpos][9]+" "+earlier[earpos][10]):'';
addr=(addr.length > 0 ? addr+'\n\n':'')+(earlier[earpos][14].trim()!='' ? ('Office Address: '+earlier[earpos][14]+" "+earlier[earpos][15]+" "+earlier[earpos][16]):'');
$("#earaddress").val(addr);
}
$("#earrphone").val(earlier[earpos][11]);
$("#earophone").val(earlier[earpos][12]);
$("#earmobile").val(earlier[earpos][13]);
$("#efoundon").html("Match Found On : "+earlier[earpos][1]+"");
$("#efound").html("("+(Number(earpos)+1)+" / "+ earIndx+" Match Found)");
//$("#ecurrecord").html("Current Record : "+(Number(earpos)+1)+"");
}
else
{
$("#efoundon").html("No Match Found");
}
}
else if(opr==2)
{
if(negIndx > 0)
{
var addropt=MatchWith(negative[negpos][1],'neg');
MatchFoundOn(negative[negpos][1],'neg');
$("#negname").val(negative[negpos][6]);
$("#negdob").val(negative[negpos][7]);
if(addropt==1)
{
$("#negaddress").val(negative[negpos][8]+" "+negative[negpos][9]+" "+negative[negpos][10]);
}
else if(addropt==2)
{
$("#negaddress").val(negative[negpos][14]+" "+negative[negpos][15]+" "+negative[negpos][16]);
}
else if(addropt==3)
{
addr=negative[negpos][8].trim()!='' ? ('Residence Address: '+negative[negpos][8]+" "+negative[negpos][9]+" "+negative[negpos][10]):'';
addr=(addr.length > 0 ? addr+'\n\n':'')+(negative[negpos][14].trim()!='' ? ('Office Address: '+negative[negpos][14]+" "+negative[negpos][15]+" "+negative[negpos][16]):'');
$("#negaddress").val(addr);
}
$("#negrphone").val(negative[negpos][11]);
$("#negophone").val(negative[negpos][12]);
$("#negmobile").val(negative[negpos][13]);
$("#nfoundon").html("Match Found On : "+negative[negpos][1]+"");
$("#nfound").html("("+(Number(negpos)+1)+" / "+negIndx+" Match Found)");
//$("#efound").html("Current Record : "+(Number(negpos)+1)+"");
}
else
{
$("#nfoundon").html("No Match Found");
}
}
}
function MatchFoundOn(MatchFoundOn,Opr)
{
if(MatchFoundOn.search("MATCH WITH SAME RESIDENCE ADDRESS") > -1)
{
Opr=="ear" ? ctrlear=ctrlear+",resiaddress" : ctrlneg=ctrlneg+",resiaddress";
$("#resiaddress").addClass(Opr+"match");
}
if(MatchFoundOn.search("MATCH WITH SAME OFFICE ADDRESS") > -1)
{
Opr=="ear" ? ctrlear=ctrlear+",offaddress" : ctrlneg=ctrlneg+",offaddress";
$("#offaddress").addClass(Opr+"match");
}
if(MatchFoundOn.search("MATCH WITH SAME RESIDENCE PHONE") > -1)
{
Opr=="ear" ? ctrlear=ctrlear+",rphone" : ctrlneg=ctrlneg+",rphone";
$("#rphone").addClass(Opr+"match");
}
if(MatchFoundOn.search("MATCH WITH SAME OFFICE PHONE") > -1)
{
Opr=="ear" ? ctrlear=ctrlear+",ophone" : ctrlneg=ctrlneg+",ophone";
$("#ophone").addClass(Opr+"match");
}
if(MatchFoundOn.search("MATCH WITH SAME MOBILE PHONE NUMBER") > -1)
{
Opr=="ear" ? ctrlear=ctrlear+",mobile" : ctrlneg=ctrlneg+",mobile";
$("#mobile").addClass(Opr+"match");
}
}
function MatchWith(MatchWith,Opr)
{
resetMarking(Opr);
Opr=="ear" ? ctrlear="" : ctrlneg="";
if(MatchWith=="RESIDENCE ADDRESS")
{
temp=Opr+"address";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"address").addClass(Opr+"match");
return 1;
}
if(MatchWith=="OFFICE ADDRESS")
{
temp=Opr+"address";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"address").addClass(Opr+"match");
return 2;
}
if(MatchWith=="RESIDENCE PHONE")
{
temp=Opr+"rphone";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"rphone").addClass(Opr+"match");
return 1;
}
if(MatchWith=="OFFICE PHONE")
{
temp=Opr+"ophone";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"ophone").addClass(Opr+"match");
return 2;
}
if(MatchWith=="MOBILE NUMBER")
{
temp=Opr+"mobile";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"mobile").addClass(Opr+"match");
return 3;
}
if(MatchWith=="NAME AND DOB")
{
temp="name,"+Opr+"name,dob,"+Opr+"dob";
Opr=="ear" ? ctrlear=temp : ctrlneg=temp;
$("#"+Opr+"name").addClass(Opr+"match");
$("#name").addClass(Opr+"match");
$("#"+Opr+"dob").addClass(Opr+"match");
$("#dob").addClass(Opr+"match");
return 3;
}
}
function resetMarking(Opr)
{
var ctrls=null;
if(ctrlear.length!="" && Opr=="ear")
{
ctrls=ctrlear.split(",");
}
if(ctrlneg.length!="" && Opr=="neg")
{
ctrls=ctrlneg.split(",");
}
if(ctrls!=null)
{
for(i=0;i 0)
{
val= val.trim()=='' ? '':val+"\n\n";
$("#"+elemId).val(val+""+earlier[earpos][2]);
findRecord(3,Opr);
}
else if(Opr==2 && negIndx > 0)
{
val= val.trim()=='' ? '':val+"\n\n";
$("#"+elemId).val(val+""+negative[negpos][2]);
findRecord(3,Opr);
}
else
{
CallMessage('DEDDO:info:No match found.',3000,200,300);
}
}
function editRemarks(elmId,Opr)
{
if(confirm("Are you sure to remove current record remarks?"))
{
var rem=$("#"+elmId).val();
if(Opr==1 && rem.length > 0)
{
rem=rem.replace(earlier[earpos][2],"");
}
else if(Opr==2 && rem.length > 0)
{
rem=rem.replace(negative[negpos][2],"");
}
$("#"+elmId).val(rem);
}
}
function InitSendDedupe()
{
if($("#casetobesend >tbody >tr").length<1)
{
$("#btngenreport").hide();
}
$('form tbody.scrollContent tr').hover(function () {
$(this).addClass('rowhover');
}, function () {
$(this).removeClass('rowhover');
});
$('form tbody.scrollContent tr').click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
checkList('chkrow','selall');
});
}
function ValidateSendDedupe(formname)
{
setHFList("casetobesend");
var uuids=$("#hfdelstat").val();
if(uuids=='')
{
CallMessage('BKLIST:error:Please select atleast one case to start report generation process.',3000,200,300);
return false;
}
else
{
SubmitForm('senddedreports', '_parent', formname);
}
}