/* Autor: Adrian Zenteno Lara */
/* $Id: functions.js,v 1.24 2002/05/24 09:28:14 loic1 Exp $ */
/**
 * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
 * This function is called while clicking links
 *
 * @param   object   the link
 * @param   object   the sql query to submit
 *
 * @return  boolean  whether to run the query or not
 */
function confirmLink(theLink)
{
    var confirmMsg  = 'Continue Logout?';
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg);  //+ ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
} // end of the 'confirmLink()' function

function valConfirmLink(theLink,intFormId,confirmMsg,TypeLink)
{
    // or browser is Opera (crappy js implementation)
    if (typeof(window.opera) != 'undefined') { return true; }
    var is_confirmed = true;
	switch(intFormId)
	{
	 case 4:
	 var PrevdocEnt=document.insertForm.PrevdocEnt.value;
	 if(PrevdocEnt)
	 {
	  window.alert(confirmMsg);
	  is_confirmed = false;
	 }
	 break;
	 case 411:
	 var PrevBillEnt = document.insertForm.PrevBillEnt.value;
	 if(PrevBillEnt)
	 {
	  window.alert(confirmMsg);
	  is_confirmed = false;
	 }
	 break;
	 default:break;
	}
	switch(TypeLink)
	{
	 case 1:break;
	 case 2:break;
	 case 3://LOGOUT
	 if(is_confirmed)
	 {
	  is_confirmed = confirm('Continue Logout?');
	  if (is_confirmed) { theLink.href += '&is_js_confirmed=1'; }
	 }
	 break;
	 default:break;
	}
    return is_confirmed;
} // end of the 'valConfirmLink()' function


function strDefaultStatus() {
 window.defaultStatus = "::TRACOMS::";
}

function confirmUrl(theLink,Msg)
{
    var confirmMsg  = Msg;
    // Confirmation is not required in the configuration file
    // or browser is Opera (crappy js implementation)
    if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
        return true;
    }
    var is_confirmed = confirm(confirmMsg);  //+ ' :\n' + theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&is_js_confirmed=1';
    }
    return is_confirmed;
} // end of the 'confirmUrl()' function

function launchWindow(url, features) 
{
  window.open(url, "_blank", features);
}

function strStatus() {
 window.status = "::TRACOMS::";
}

function load()
{
window.status = "Technosoft Inc. Mexico"
}

function setMenuFocus() {
        document.pageMenu.pageMenuOpc.focus();
        return;
}

function CA(isOnload)
{
 var trk=0;
 for (var i=0;i<insertForm.elements.length;i++)
 {
  var e = insertForm.elements[i];
  if ((e.name != 'allbox') && (e.type=='checkbox'))
  {
   if (isOnload != 1)
   {
    trk++;
    e.checked = insertForm.allbox.checked;
   }
   else
   {
    e.tabIndex = i;
    if (folderID != "")
    e.parentElement.parentElement.children[2].children[0].tabIndex = i;
   }
  }
 }
}

		
function formatCurrency(num) 
{
 num = num.toString().replace(/\$|\,/g,'');
 if(isNaN(num))
 num = "0";
 sign = (num == (num = Math.abs(num)));
 num = Math.floor(num*100+0.50000000001);
 cents = num%100;
 num = Math.floor(num/100).toString();
 if(cents<10)
 cents = "0" + cents;
 for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
 num = num.substring(0,num.length-(4*i+3))+','+
 num.substring(num.length-(4*i+3));
 return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function ResetCalcDocEntry()
{
 parent.main.insertForm.NumPages.value = "0";//1
 parent.main.insertForm.RecFee.value="0";
 parent.main.insertForm.tmpAddtnlPgs.value="0";
 parent.main.insertForm.pstFee.value="0";
 parent.main.insertForm.trnsTax.value="0";
 parent.main.insertForm.addtnlFee.value="0";
 parent.main.insertForm.pnlFee.value="0";
 parent.main.insertForm.amtDue.value="0";
 parent.main.insertForm.bgBook.value="";
 parent.main.insertForm.bpgBook.value="";
 parent.main.insertForm.endBook.value="";
 parent.main.insertForm.tmpEpgBook.value="";
 parent.main.insertForm.payAmt1.value="0";
 parent.main.insertForm.payAmt2.value="0";
 parent.main.insertForm.payAmt3.value="0";
 parent.main.insertForm.payAmt4.value="0";
 parent.main.insertForm.amtRecd.value="0";
 parent.main.insertForm.ChangeField.value="0";
 parent.main.insertForm.ChangeDue.value="0";
 parent.main.insertForm.valuationAmt.value="0";
 parent.main.insertForm.CC1.value="";
 parent.main.insertForm.CC2.value="";
 parent.main.insertForm.CC3.value="";
 parent.main.insertForm.CC4.value="";
}

function ResetCalcDocEntryMPOFF()
{
 var varZero                               = "0";
 var varOne                                = "0";//1
 var varNull                               = "";
 parent.main.insertForm.NumPages.value     = varOne;
 parent.main.insertForm.RecFee.value       = varZero;
 parent.main.insertForm.tmpAddtnlPgs.value = varZero;
 parent.main.insertForm.pstFee.value       = varZero;
 parent.main.insertForm.trnsTax.value      = varZero;
 parent.main.insertForm.addtnlFee.value    = varZero;
 parent.main.insertForm.pnlFee.value       = varZero;
 parent.main.insertForm.amtDue.value       = varZero;
 parent.main.insertForm.bgBook.value       = varNull;
 parent.main.insertForm.bpgBook.value      = varNull;
 parent.main.insertForm.endBook.value      = varNull;
 parent.main.insertForm.tmpEpgBook.value   = varNull;
}

function ResetDoctoType(formId)
{
 if(isNaN(formId))
 {
  parent.main.insertForm.DoctoTypeId.value = "";
  parent.main.insertForm.DoctoTypeName.value = "";
 }
}

function ResetValuation()
{
 var NumPages;
 var formId;
 formId = document.insertForm.f.value;
 if(formId==338) { NumPages = 1; } //Assign File No. form
 else if(formId==349) { NumPages = 1; } //MVLS/UCC Terminations form
 else NumPages=0;
 //
 parent.main.insertForm.NumPages.value = NumPages;//1
 parent.main.insertForm.RecFee.value="0";
 parent.main.insertForm.tmpAddtnlPgs.value="0";
 parent.main.insertForm.addtnlPgs.value="0";
 parent.main.insertForm.showAddtnlPgs.value="0";
 parent.main.insertForm.pstFee.value="0";
 parent.main.insertForm.trnsTax.value="0";
 parent.main.insertForm.valuationAmt.value="0";
 parent.main.insertForm.addtnlFee.value="0";
 parent.main.insertForm.pnlFee.value="0";
 parent.main.insertForm.amtDue.value="0";
 parent.main.insertForm.bgBook.value="";
 parent.main.insertForm.bpgBook.value="";
 parent.main.insertForm.endBook.value="";
 parent.main.insertForm.tmpEpgBook.value="";
 parent.main.insertForm.epgBook.value="";
 parent.main.insertForm.showNEXTFILENUMBER.value="";
}

function ResetPayment()
{
 parent.main.insertForm.payAmt1.value="0";
 parent.main.insertForm.payAmt2.value="0";
 parent.main.insertForm.payAmt3.value="0";
 parent.main.insertForm.payAmt4.value="0";
 parent.main.insertForm.amtRecd.value="0";
 parent.main.insertForm.ChangeField.value="0";
 parent.main.insertForm.ChangeDue.value="0";
 parent.main.insertForm.CC1.value="";
 parent.main.insertForm.CC2.value="";
 parent.main.insertForm.CC3.value="";
 parent.main.insertForm.CC4.value="";
}

 function roundTrnsTax(valuation)
 {
  var ndec, nint, nrest;
  nint = Math.floor(valuation);
  ndec = valuation - nint;
  if(ndec==0) {}
  else if((ndec<0.5)) {valuation = nint + 0.5;}
  else if(ndec==0.5){}
  else if(ndec>0.5) 
  {
   nrest = 1 - ndec; 
   valuation = valuation + nrest;
  } 
  return valuation;
 }
 
 function checkDeedValuation()
 {
  var valuationAmt = document.insertForm.valuationAmt.value;
  var doctoType  = document.insertForm.DoctoTypeId.value;
  var frmName = document.insertForm.frmName.value;
  if((valuationAmt<=0) && (doctoType=='DEED'))  
  {
   alert('Enter Deed Valuation');   
   if(frmName!='EDIT') { document.insertForm.valuationAmt.focus(); }
  }
 }

function CheckValuationAmt(chrgTTax, doctoFrm)
{
 var valuationAmt = document.insertForm.valuationAmt.value;
 valuationAmt = money_to_numeric(valuationAmt, 1);
 valuationAmt = eval(valuationAmt);
  
 var flgVoid = document.insertForm.flgVoid.value;
 var trnsTax = eval(0);
 var Zerovalue = '0';
 if(chrgTTax=='Y')
 {
  if(isNaN(valuationAmt) || (valuationAmt<0)) 
  { 
   alert('Invalid value'); 
   document.insertForm.valuationAmt.value = Zerovalue; 
   document.insertForm.trnsTax.value = Zerovalue;
   document.insertForm.valuationAmt.focus();
  }
  else
  {
   trnsTax = eval(valuationAmt/1000);
   trnsTax = roundTrnsTax(trnsTax);
   document.insertForm.trnsTax.value = trnsTax;
   switch(doctoFrm)
   {
    case 0:CalcDocEntry(0);break;
    case 1:CalcDocEntryMPOFF();break;
	default :break;
   }
  }
 }
 else 
 { 
  if(isNaN(valuationAmt) || (valuationAmt!=0))
  {
   alert('Cannot change theed deed valuation'); 
   document.insertForm.trnsTax.value = Zerovalue;
   document.insertForm.valuationAmt.value= Zerovalue;
  }
 }
 //
   if(!flgVoid) { checkDeedValuation(); }
}

 function checkAddnlFee(doctoFrm)
 {
  AddnlFee = document.insertForm.addtnlFee.value;
  var Zerovalue = '0';
  if(isNaN(AddnlFee) || (AddnlFee<0)) 
  { 
   alert('Invalid value'); 
   document.insertForm.addtnlFee.value= Zerovalue; 
   document.insertForm.addtnlFee.focus();
  }
  if(!AddnlFee) { document.insertForm.addtnlFee.value= Zerovalue; }
  //
  switch(doctoFrm)
  {
   case 0: CalcDocEntry(0);break;
   case 1: CalcDocEntryMPOFF();break;
  }
 }
 
 function checkPenaltyFee(doctoFrm)
 {
  pnlFee = document.insertForm.pnlFee.value;
  var Zerovalue = '0';
  if(isNaN(pnlFee) || (pnlFee<0)) 
  { 
   alert('Invalid value'); 
   document.insertForm.pnlFee.value= Zerovalue; 
   document.insertForm.pnlFee.focus();
  }
  if(!pnlFee) { document.insertForm.pnlFee.value= Zerovalue;  }
  //
  switch(doctoFrm)
  {
   case 0: CalcDocEntry(0);break;
   case 1: CalcDocEntryMPOFF();break;
  }
 }
 
 function checkPaymentAmt(doctoFrm,nPayment)
 {
  var PaymentAmt;
  var Zerovalue = '0';
  var flgGoToAddnlFee = 0;
  document.insertForm.flgGoToAddnlFee.value = flgGoToAddnlFee;
  switch(nPayment)
  {
   case 1: PaymentAmt = document.insertForm.payAmt1.value; break;
   case 2: PaymentAmt = document.insertForm.payAmt2.value; break;
   case 3: PaymentAmt = document.insertForm.payAmt3.value; break;
   case 4: PaymentAmt = document.insertForm.payAmt4.value; break;
  }
  if(isNaN(PaymentAmt) || (PaymentAmt<0))
  { 
   alert('Invalid value'); 
   switch(nPayment)
   {
    case 1: document.insertForm.payAmt1.value= Zerovalue; break;
    case 2: document.insertForm.payAmt2.value= Zerovalue; break;
    case 3: document.insertForm.payAmt3.value= Zerovalue; break;
    case 4: document.insertForm.payAmt4.value= Zerovalue; break;
   }
  }
  if(!PaymentAmt)
  { 
   switch(nPayment)
   {
    case 1: document.insertForm.payAmt1.value= Zerovalue; break;
    case 2: document.insertForm.payAmt2.value= Zerovalue; break;
    case 3: document.insertForm.payAmt3.value= Zerovalue; break;
    case 4: document.insertForm.payAmt4.value= Zerovalue; break;
   }
  }
  //
  switch(doctoFrm)
  {
   case 0: CalcDocEntry(0);break;
   case 1: CalcDocEntryMPOFF();break;
  }
 }

 function checkTransferTax(chrgTTax,doctoFrm)
 {
  var trnsTax = document.insertForm.trnsTax.value;
  var Zerovalue = '0';
  if(isNaN(trnsTax) || (trnsTax<0)) 
  { 
   alert('Invalid value'); 
   document.insertForm.trnsTax.value= Zerovalue; 
   document.insertForm.trnsTax.focus();
  }
  else
  {
   if(chrgTTax=='Y') 
   { 
    switch(doctoFrm)
	{
	 case 0: CalcDocEntry(0);break;
	 case 1: CalcDocEntryMPOFF();break;
	}
   }
   else 
   { 
    alert('Impossible change Transfer Tax value'); 
    document.insertForm.trnsTax.value = Zerovalue;
    document.insertForm.valuationAmt.value = Zerovalue;
   }
  }
 }

function NumOfPages()
{
 var RcdCh       = document.insertForm.RcdCh.value;
 var DoctoTypeId = document.insertForm.DoctoTypeId.value;
 var NumOfPages =  document.insertForm.NumPages.value; 
 var doctoIndexClass = eval(document.insertForm.doctoIndexClass.value);
 var BeginPg     = eval(document.insertForm.bpgBook.value);
 var resetNumPages = '1';
 var flgGo='OK';
 if(RcdCh && DoctoTypeId)
 {
  if(doctoIndexClass==20)
  {
   if(NumOfPages>1 || NumOfPages<1) 
   {
    document.insertForm.NumPages.value = resetNumPages;
	document.insertForm.tmpEpgBook.value = BeginPg;
    alert('Number of pages can not be greater than 1');
   }
  }
  else
  { if(NumOfPages>30) { alert('Number of pages is greater than 30'); } }
  document.insertForm.flgGoToAddnlFee.value = flgGo; 
 }
} 

 function checkPaymentTypeEdit()
 {
  var pmtType = document.insertForm.pmtType.value;
  if(pmtType != 0 && pmtType != 2)//Check type && MC/VISA
  {
   //20050519-azlara-bug 3826-cambio de nombre para hiddear al darle click, btnContinueEdit
   document.insertForm.btnSave.focus();
  }
 }
 
 function checkPaymentType()
 {
  var pmtType = document.insertForm.pmtType.value;
  if(pmtType != 0 && pmtType != 2)//Check type && MC/VISA
  {
   document.insertForm.btnSave.focus();
  }
 }
 
 function checkDue()
 {
  var changeDue = document.insertForm.ChangeDue.value;
  if(changeDue<=0) { document.insertForm.btnSave.focus(); }
 }
 
 function checkDueMPOFF()
 {
  var changeDue = document.insertForm.ChangeDue.value;
  if(changeDue<=0) { document.insertForm.btnPayoffDocuments.focus(); }
 }
 
function CalcDocEntry(ShowBook)
{
 var NumOfPages, AddtnlPages, PostageFee;
 var TransferTax, AddnlFee, PenaltyFee, AmountDue;
 var BeginBk, BeginPg, EndingBk, EndingPg;
 var PaymentAmt1, PaymentAmt2, PaymentAmt3, PaymentAmt4;
 var AmountRecd, Change, RecordingFee;
 var tmpAmtDue, tmpAmtRecd, tmpChangeField, tmpEndingPg, tmpAddtnlPgs, showAddtnlPgs, maxPgs, newEndPg, tmpChangeDue;
 var valZero = '0';
 var valNull = '';
 var flgKeepPages;
 var intFormId, flagGo;
 intFormId = document.insertForm.f.value;
 flagGo=0;
 var RcdCh       = document.insertForm.RcdCh.value;
 var DoctoTypeId = document.insertForm.DoctoTypeId.value;
 var frmName = document.insertForm.frmName.value;
 NumOfPages      = document.insertForm.NumPages.value;
 if(isNaN(NumOfPages)||!NumOfPages) { NumOfPages=0; }
 var doctoIndexClass = eval(document.insertForm.doctoIndexClass.value); 
 RecordingFee= eval(document.insertForm.RecFee.value);
 AddtnlPages = eval(document.insertForm.tmpAddtnlPgs.value);
 PostageFee  = eval(document.insertForm.pstFee.value);
 TransferTax = eval(document.insertForm.trnsTax.value);
 if(isNaN(TransferTax)) { TransferTax=eval(0); }
 AddnlFee    = eval(document.insertForm.addtnlFee.value);
 PenaltyFee  = eval(document.insertForm.pnlFee.value);
 AmountDue   = eval(document.insertForm.amtDue.value);
 BeginBk     = eval(document.insertForm.bgBook.value);
 BeginPg     = eval(document.insertForm.bpgBook.value);
 var resetEndingPg = BeginPg; 
 EndingBk    = eval(document.insertForm.endBook.value);
 EndingPg    = eval(document.insertForm.tmpEpgBook.value);
 PaymentAmt1 = eval(document.insertForm.payAmt1.value);
 if(isNaN(PaymentAmt1)) { PaymentAmt1 = eval(0); }
 PaymentAmt2 = eval(document.insertForm.payAmt2.value);
 if(isNaN(PaymentAmt2)) { PaymentAmt2 = eval(0); }
 PaymentAmt3 = eval(document.insertForm.payAmt3.value);
 if(isNaN(PaymentAmt3)) { PaymentAmt3 = eval(0); }
 PaymentAmt4 = eval(document.insertForm.payAmt4.value);
 if(isNaN(PaymentAmt4)) { PaymentAmt4 = eval(0); }
 AmountRecd  = eval(document.insertForm.amtRecd.value);
 Change      = eval(document.insertForm.ChangeField.value);
 maxPgs      = eval(document.insertForm.maxPgs.value);
 flgKeepPages = eval(document.insertForm.flgKeepPages.value);
 showAddtnlPgs = eval("0");
 var flgVoid = document.insertForm.flgVoid.value;
 var flgGoToAddnlFee = document.insertForm.flgGoToAddnlFee.value; 
 //
 //window.alert('1)Amt Due = '+AmountDue+ ' frmName:'+frmName);
 //operations
  if(RcdCh && DoctoTypeId)
  {
   if(!flgVoid)
   {
     NumOfPages = eval(NumOfPages);
	 if(NumOfPages<=0)
	 {
	  alert ('Cannot have 0 pages in a document');
      NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages;//1
	  document.insertForm.fullName2.focus();
	 }
	 else
	 {
	  flagGo=1;
	     if(NumOfPages<=3) { tmpAddtnlPgs=0; }
         else 
		 { 
		  if(frmName=='EDIT') 
		  {
		   if(AddtnlPages<=0) { tmpAddtnlPgs = AddtnlPages * (NumOfPages - 3); }
		   else {  tmpAddtnlPgs = AddtnlPages; }
		  }
		  else { tmpAddtnlPgs = AddtnlPages * (NumOfPages - 3); }
		 }
         document.insertForm.addtnlPgs.value = tmpAddtnlPgs;
         document.insertForm.showAddtnlPgs.value = tmpAddtnlPgs;
         if(tmpAddtnlPgs<0)  document.insertForm.showAddtnlPgs.value = showAddtnlPgs;
         
         tmpAmtDue = PenaltyFee + AddnlFee + TransferTax + PostageFee + tmpAddtnlPgs + RecordingFee;
//		 tmpAmtDue = round(tmpAmtDue,2);
		 tmpAmtDue = tmpAmtDue.toFixed(2);
         document.insertForm.amtDue.value = tmpAmtDue;
		 
         //window.alert('2)Amt Due('+tmpAmtDue+')= PenaltyFee('+PenaltyFee+') + AddnlFee('+AddnlFee+') + TransferTax('+TransferTax+') + PostageFee('+PostageFee+') + tmpAddtnlPgs('+tmpAddtnlPgs+') + RecordingFee('+RecordingFee+')');
		 
         tmpAmtRecd = PaymentAmt1 + PaymentAmt2 + PaymentAmt3 + PaymentAmt4;
         document.insertForm.amtRecd.value = eval(format_number(tmpAmtRecd,2));//eval(tmpAmtRecd);

         tmpChangeField = tmpAmtRecd - tmpAmtDue;
         if(tmpChangeField<0) 
         {
          tmpChangeField='';
          document.insertForm.ChangeField.value = tmpChangeField;
         }
         else
         {
          document.insertForm.ChangeField.value =  eval(format_number(tmpChangeField,2));
         }
		 //
		 if(tmpAmtDue == tmpAmtRecd) 
		  {
		   tmpChangeField='0'; 
		   tmpChangeDue='0';
           document.insertForm.ChangeField.value = eval(tmpChangeField);
           document.insertForm.ChangeDue.value = eval(tmpChangeDue);
		   if(intFormId == 5) checkPaymentTypeEdit();
		   else checkPaymentType();
		  }
         else if(tmpAmtRecd<tmpAmtDue) 
		  {
		   tmpChangeField='0';
		   tmpChangeDue = tmpAmtDue - tmpAmtRecd;
           document.insertForm.ChangeField.value = eval(format_number(tmpChangeField,2));//eval(tmpChangeField);
           document.insertForm.ChangeDue.value = eval(format_number(tmpChangeDue,2));//eval(tmpChangeDue);
		  }
         else if(tmpAmtRecd>=tmpAmtDue) 
		  {
		   tmpChangeField= tmpAmtRecd - tmpAmtDue; 
		   tmpChangeDue='0';
           document.insertForm.ChangeField.value = eval(format_number(tmpChangeField,2));//eval(tmpChangeField);
           document.insertForm.ChangeDue.value = eval(format_number(tmpChangeDue,2));//eval(tmpChangeDue);
		   if(intFormId == 5) checkPaymentTypeEdit();
		   else checkPaymentType();
		  }
		 else 
		  {
		   tmpChangeDue='';
           //document.insertForm.ChangeField.value = eval(tmpChangeField);
           document.insertForm.ChangeDue.value = tmpChangeDue;
		  }
         //
		if(flgKeepPages) 
		{ 
		 //window.alert('keep original pages'); 
		}
		else
		{
		 if(frmName=='EDIT') { tmpEndingPg = EndingPg; }
		 else { tmpEndingPg = EndingPg + NumOfPages - 1; } //added - 1 
         if(tmpEndingPg > maxPgs)
         {
    	  //if(ShowBook){ alert('Beginning new Book'); }
          //newEndPg = BeginBk + 1;
          //document.insertForm.endBook.value = eval(newEndPg);
          //newEndPg = tmpEndingPg - maxPgs;
          document.insertForm.epgBook.value = eval(tmpEndingPg);  //newEndPg
         }
         else
         {
		  //20050425-azlara-bug 3798
		  if(isNaN(BeginBk))
		  {
           alert ('Check document type');
	       document.insertForm.DoctoTypeId.focus();
		  }
		  else
		  {
           document.insertForm.endBook.value = eval(BeginBk);
           document.insertForm.epgBook.value = eval(tmpEndingPg);
		  }
		  //
         }
		}
		 //
		 if(doctoIndexClass==20)
		 {
          document.insertForm.epgBook.value = eval(resetEndingPg);
		  document.insertForm.CC1.value = valNull;
          document.insertForm.CC2.value = valNull;
          document.insertForm.CC3.value = valNull;
          document.insertForm.CC4.value = valNull;
          document.insertForm.payAmt1.value = valZero;
          document.insertForm.payAmt2.value = valZero;
          document.insertForm.payAmt3.value = valZero;
          document.insertForm.payAmt4.value = valZero;
          document.insertForm.ChangeDue.value = AmountDue;
          document.insertForm.ChangeField.value = valZero;
		  document.insertForm.amtRecd.value = valZero;
		 }
		 //
	     if(((DoctoTypeId=='COPIES') || (DoctoTypeId=='DELQTAX')))
		  { if(flgGoToAddnlFee=='OK') { document.insertForm.addtnlFee.focus(); } }//window.alert('flgon='+flgGoToAddnlFee);
		 //
		 document.insertForm.flgGoToAddnlFee.value = showAddtnlPgs; //bug 2624, dont jump in payment section
		 //window.alert('flgoff='+showAddtnlPgs);
		 if((intFormId=='349')&&(flagGo==1)) { document.insertForm.btnSave.focus(); }
	  }//else if(NumPages>0)
	}//if void  
  }
  else { NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages; } //1
}


 function submitNextMultiDoctoEntryFrm()
 {
  var NumOfPages  = eval(document.insertForm.NumPages.value);
  if(isNaN(NumOfPages)) { NumOfPages=eval(0); }
  var RcdCh= document.insertForm.RcdCh.value;
  var DoctoTypeId= document.insertForm.DoctoTypeId.value;
  var valuationAmt = document.insertForm.valuationAmt.value;  
  if(isNaN(valuationAmt)) { valuationAmt=eval(0); }
  var sendDocto = document.insertForm.sendDocto.value;
  //20050517-bug 3826-azlara-si se daba click varias veces en el boton de next docto, se incrementaba el num pages y el receipt no
  var PrevdocEnt=document.insertForm.PrevdocEnt.value;
  //
  var Answer, id, formId, doctoNumber;
  if(sendDocto && (NumOfPages<=0))// && RcdCh && DoctoTypeId
  { 
   alert('Cannot have 0 pages in a document'); 
   NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages;//1
   document.insertForm.NumPages.focus();   
  }
  else if(sendDocto && (valuationAmt<=0) && (DoctoTypeId=='DEED'))  
  {
   alert('Enter Deed Valuation');   
   document.insertForm.valuationAmt.focus();
  }
  else
  {
   id = document.insertForm.id.value;
   formId = document.insertForm.formId.value;
   document.insertForm.dt.value=document.insertForm.DoctoTypeId.value;
   document.insertForm.opc.value=document.insertForm.np.value;
    if(PrevdocEnt) 
	{
	 document.insertForm.btnNextDocument.disabled=true;
	 document.insertForm.btnPayoffDocuments.disabled=true;
	}
   document.insertForm.submit();
  }
 }

 function submitSingleDoctoEntryFrm()
 {  
  var RcdCh       = document.insertForm.RcdCh.value;
  var DoctoTypeId = document.insertForm.DoctoTypeId.value;  
  var PaymentType1= eval(document.insertForm.payType1.value);
  var PaymentType2= eval(document.insertForm.payType2.value);
  var PaymentType3= eval(document.insertForm.payType3.value);
  var PaymentType4= eval(document.insertForm.payType4.value);
  var PaymentAmt1 = eval(document.insertForm.payAmt1.value);
  if(isNaN(PaymentAmt1)) { PaymentAmt1=eval(0); }
  var PaymentAmt2 = eval(document.insertForm.payAmt2.value);
  if(isNaN(PaymentAmt2)) { PaymentAmt2=eval(0); }
  var PaymentAmt3 = eval(document.insertForm.payAmt3.value);
  if(isNaN(PaymentAmt3)) { PaymentAmt3=eval(0); }
  var PaymentAmt4 = eval(document.insertForm.payAmt4.value);
  if(isNaN(PaymentAmt4)) { PaymentAmt4=eval(0); }
  var AmountDue   = eval(document.insertForm.amtDue.value);
  var AmountRecd  = eval(document.insertForm.amtRecd.value);  
  var change      = eval(document.insertForm.ChangeField.value);
  var NumOfPages  = document.insertForm.NumPages.value;
  if(isNaN(NumOfPages)||NumOfPages<0) { NumOfPages=eval(0); }
  var doctoIndexClass  = eval(document.insertForm.doctoIndexClass.value);
  var valuationAmt = document.insertForm.valuationAmt.value;  
  if(isNaN(valuationAmt)) { valuationAmt=eval(0); }
  var confirmMsg  = 'Change amount is over $50, Okay?';
  var TotaPaymentAmt, CreditCarType, continueSubmit, ExemptType;
  TotalPaymentAmt = PaymentAmt1+ PaymentAmt2 + PaymentAmt3 + PaymentAmt4; 
  CreditCarType = '2';
  ARType = '3';    
  ExemptType   =  '4';
  var lastName2 = document.insertForm.lastName2.value;
  var flgVoid = document.insertForm.flgVoid.value;
		
  if(RcdCh && DoctoTypeId)
  {
   if(NumOfPages<=0)
   {
    alert('Cannot have 0 pages in a document'); 
    NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages;//1
    document.insertForm.NumPages.focus();     
   }
   else
   {
      if(PaymentType1==CreditCarType || PaymentType2==CreditCarType || PaymentType3==CreditCarType || PaymentType4==CreditCarType)
      {
       if(AmountRecd > AmountDue)
       {
        alert('No change can be returned if payment is made by Visa/MC');
       }
       else { continueSubmit='OK'; }
      }
      else { continueSubmit='OK'; }
      
      if(continueSubmit)
      {
       if(
	      //(TotalPaymentAmt < AmountDue) && //20050426-problema con el redondeo
		  (AmountRecd < AmountDue) && 
	      (PaymentType1!=ExemptType && PaymentType2!=ExemptType && PaymentType3!=ExemptType && PaymentType4!=ExemptType) && 
	      (PaymentType1!=ARType && PaymentType2!=ARType && PaymentType3!=ARType && PaymentType4!=ARType) && 
		  (doctoIndexClass!=20)
		 )
	   { alert('Not enough money has been paid'); }
       else
       {
	    if(NumOfPages<=0) 
		{ 
		 alert('Cannot have 0 pages in a document'); 
         NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages;		 //1
		}
		else
		{
		 if((valuationAmt<=0) && (DoctoTypeId=='DEED') && !flgVoid)  
         {
          alert('Enter Deed Valuation');   
          document.insertForm.valuationAmt.focus();
         }
         else if(change>50)
         {
           var is_confirmed = confirm(confirmMsg);	
           if (is_confirmed) 
           {
		    //20050425-azlara-bug 3798-
		    var valEndBook= document.insertForm.endBook.value;
		    if(isNaN(valEndBook)||(valEndBook<0)||(valEndBook=='')) 
			{
		     alert('Check document type');   
		     document.insertForm.DoctoTypeId.focus();
			}
			else
			{
             document.insertForm.dt.value=document.insertForm.DoctoTypeId.value;
     	     document.insertForm.opc.value=document.insertForm.np.value;
     	     document.insertForm.submit();
			}
			//
           }
		 }
         else
         {
		  //20050425-azlara-bug 3798-
		  var valEndBook= document.insertForm.endBook.value;
		  if(isNaN(valEndBook)||(valEndBook<0)||(valEndBook=='')) 
		  {
		   alert('Check document type');   
		   document.insertForm.DoctoTypeId.focus();
		  }
		  else
		  {
           document.insertForm.dt.value=document.insertForm.DoctoTypeId.value;
           document.insertForm.opc.value=document.insertForm.np.value;
		   //20050519-azlara-bug 3826 - si se clickea varias veces, se incrementa el feefile.receipt_no
		   document.insertForm.btnSave.disabled=true;
		   document.insertForm.btnReset.disabled=true;
		   //
           document.insertForm.submit();
		  }
		  //
         }		
		}
       }   
      }     
   }   
  }
  else { alert('Invalid Fee entry, please fill the document'); document.insertForm.clerkId.focus(); }
 }

 function PaymentType(Type)
 {
  var ZeroValue = eval(0);
  var confirmMsg= 'Okay to exempt from payment?';
  switch(Type)
  {
   case '4': //exempt type
   var is_confirmed = confirm(confirmMsg);	
   if (is_confirmed) 
   {
    document.insertForm.payAmt1.value = ZeroValue;
    document.insertForm.payAmt2.value = ZeroValue;
    document.insertForm.payAmt3.value = ZeroValue;
    document.insertForm.payAmt4.value = ZeroValue;
	CalcDocEntry();
   }
   break;
   default: break;
  }
 }
 
 function PaymentTypeB(Type, LocId, DoctoTypeId)
 {
  var ZeroValue = eval(0);
  var confirmMsg= 'Okay to exempt from payment?';
  var flgGoToAddnlFee = 0;
  document.insertForm.flgGoToAddnlFee.value= flgGoToAddnlFee;
  //
  if(Type && LocId && DoctoTypeId)
  {
      switch(Type)
      {
       case '4': //exempt type
       var is_confirmed = confirm(confirmMsg);	
       if (is_confirmed) 
       {
        document.insertForm.payAmt1.value = ZeroValue;
        document.insertForm.payAmt2.value = ZeroValue;
        document.insertForm.payAmt3.value = ZeroValue;
        document.insertForm.payAmt4.value = ZeroValue;
    	CalcDocEntry();
       }
       break;
       default: break;
      }  
  }
 } 
 
 function VoidDoctoEntryB()
 {
  var doctoNumber  = document.insertForm.doctoNumber.value;  
  var confirmMsg   = 'Void this document?';
  var lastName2    = 'VOID - VOID - VOID - VOID';
  var frstName2    = ' - VOID - VOID';
  var mdlName      = '';
  var ZeroValue = '0';
  var valNull ='';
  var valOne = '1';
  if(doctoNumber)
  {
   var is_confirmed = confirm(confirmMsg);	
   if (is_confirmed) 
   {
    document.insertForm.lastName2.value     = lastName2;
    document.insertForm.firstName2.value    = frstName2;
    document.insertForm.midlName2.value     = mdlName;
    document.insertForm.fullName2.value     = lastName2+frstName2;
    document.insertForm.lastName1.value     = lastName2;
    document.insertForm.firstName1.value    = frstName2;
    document.insertForm.midlName1.value     = mdlName;
    document.insertForm.fullName1.value     = lastName2+frstName2;
    document.insertForm.payAmt1.value       = ZeroValue;
    document.insertForm.payAmt2.value       = ZeroValue;
    document.insertForm.payAmt3.value       = ZeroValue;
    document.insertForm.payAmt4.value       = ZeroValue;
	document.insertForm.amtRecd.value       = ZeroValue;
    document.insertForm.ChangeField.value   = ZeroValue;
    document.insertForm.ChangeDue.value     = ZeroValue;
    document.insertForm.CC1.value           = valNull;
    document.insertForm.CC2.value           = valNull;
    document.insertForm.CC3.value           = valNull;
    document.insertForm.CC4.value           = valNull;
	//Bug 3017 
//    document.insertForm.epgBook.value       = ZeroValue;
//    document.insertForm.tmpEpgBook.value    = ZeroValue;
//    document.insertForm.endBook.value       = ZeroValue;
//    document.insertForm.bpgBook.value       = ZeroValue;
//    document.insertForm.bgBook.value        = ZeroValue;
//    document.insertForm.NumPages.value      = valOne;
//
    document.insertForm.amtDue.value        = ZeroValue;
    document.insertForm.pnlFee.value        = ZeroValue;
    document.insertForm.OrgPnlFee.value     = ZeroValue;
    document.insertForm.addtnlFee.value     = ZeroValue;
    document.insertForm.trnsTax.value       = ZeroValue;
    document.insertForm.pstFee.value        = ZeroValue;
    document.insertForm.tmpAddtnlPgs.value  = ZeroValue;
    document.insertForm.addtnlPgs.value     = ZeroValue;
    document.insertForm.showAddtnlPgs.value = ZeroValue;
    document.insertForm.RecFee.value        = ZeroValue;
    document.insertForm.valuationAmt.value  = ZeroValue;
	document.insertForm.flgVoid.value       = valOne;
    submitSingleDoctoEntryFrm();
   }  
  }
 }  

 function PaymentTypeMPOFF(Type)
 {
  var ZeroValue = eval(0);
  var confirmMsg= 'Okay to exempt from payment?';
  switch(Type)
  {
   case '4': //exempt type
   var is_confirmed = confirm(confirmMsg);	
   if (is_confirmed) 
   {
    document.insertForm.payAmt1.value = ZeroValue;
    document.insertForm.payAmt2.value = ZeroValue;
    document.insertForm.payAmt3.value = ZeroValue;
    document.insertForm.payAmt4.value = ZeroValue;
	document.insertForm.amtRecd.value = ZeroValue;
    tmpChangeField='';
    document.insertForm.ChangeField.value = tmpChangeField;	
   }
   break;
   default: break;
  }
 } 

function CalcDocEntryMPOFF()
{
 var NumOfPages, AddtnlPages, PostageFee;
 var TransferTax, AddnlFee, PenaltyFee, AmountDue;
 var BeginBk, BeginPg, EndingBk, EndingPg;
 var PaymentAmt1, PaymentAmt2, PaymentAmt3, PaymentAmt4;
 var AmountRecd, Change, RecordingFee, RcdCh, DoctoTypeId;
 var tmpAmtDue, tmpAmtRecd, tmpChangeField, tmpEndingPg, tmpAddtnlPgs, showAddtnlPgs, maxPgs, newEndPg;
 var CheckStamp;
 
 RcdCh       = document.insertForm.RcdCh.value;
 DoctoTypeId = document.insertForm.DoctoTypeId.value;
 NumOfPages  = document.insertForm.NumPages.value;
 if(isNaN(NumOfPages)||!NumOfPages) { NumOfPages=0; }
 RecordingFee= eval(document.insertForm.RecFee.value);
 AddtnlPages = eval(document.insertForm.tmpAddtnlPgs.value);
 PostageFee  = eval(document.insertForm.pstFee.value);
 TransferTax = eval(document.insertForm.trnsTax.value);
 if(isNaN(TransferTax)) { TransferTax=eval(0); }
 AddnlFee    = eval(document.insertForm.addtnlFee.value);
 PenaltyFee  = eval(document.insertForm.pnlFee.value);
 AmountDue   = eval(document.insertForm.amtDue.value);
 BeginBk     = eval(document.insertForm.bgBook.value);
 BeginPg     = eval(document.insertForm.bpgBook.value);
 EndingBk    = eval(document.insertForm.endBook.value);
 EndingPg    = eval(document.insertForm.tmpEpgBook.value);
 var resetEndingPg = BeginPg; 
 maxPgs      = eval(document.insertForm.maxPgs.value);
 var doctoIndexClass = eval(document.insertForm.doctoIndexClass.value);
 showAddtnlPgs = eval("0");
 var flgGoToAddnlFee = document.insertForm.flgGoToAddnlFee.value;  
 //operations
 if(RcdCh && DoctoTypeId)
 {
  NumOfPages = eval(NumOfPages);
  if(NumOfPages<=0)
  {
   alert ('Cannot have 0 pages in a document');
   NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages;//1
   document.insertForm.fullName2.focus();
  }
  else
  {
      if(NumOfPages<=3) { tmpAddtnlPgs = 0; }
      else { tmpAddtnlPgs = AddtnlPages * (NumOfPages - 3); }
      document.insertForm.addtnlPgs.value = tmpAddtnlPgs;
      document.insertForm.showAddtnlPgs.value = tmpAddtnlPgs;
      if(tmpAddtnlPgs<0)  document.insertForm.showAddtnlPgs.value = showAddtnlPgs;
     
      tmpAmtDue = PenaltyFee + AddnlFee + TransferTax + PostageFee + tmpAddtnlPgs + RecordingFee;
      document.insertForm.amtDue.value = format_number(tmpAmtDue,2);//tmpAmtDue
    
      tmpEndingPg = EndingPg + NumOfPages - 1; //added -1
      if(tmpEndingPg > maxPgs)
      {
       //alert('Beginning new Book');
       //newEndPg = BeginBk + 1;
       //document.insertForm.endBook.value = eval(newEndPg);
       //newEndPg = tmpEndingPg - maxPgs;
       document.insertForm.epgBook.value = eval(tmpEndingPg);  //newEndPg
      }
      else
      {
	   //20050425-azlara-bug 3798
	   if(isNaN(BeginBk))
	   {
	    alert ('Check document type');
	    document.insertForm.DoctoTypeId.focus();
	   }
	   else
       { 
	    document.insertForm.endBook.value = eval(BeginBk);
        document.insertForm.epgBook.value = eval(tmpEndingPg);
	   }
	   //
      }  
	  if(doctoIndexClass==20)
	  {
       document.insertForm.epgBook.value = eval(resetEndingPg);
	  }
	  //
	  if((DoctoTypeId=='COPIES') || (DoctoTypeId=='DELQTAX'))
	   { if(flgGoToAddnlFee=='OK') { document.insertForm.addtnlFee.focus(); } }
	  document.insertForm.flgGoToAddnlFee.value = showAddtnlPgs; //bug 2624, dont jump in payment section
  }
 }
 else { NumOfPages='0'; document.insertForm.NumPages.value=NumOfPages; }//1
}

 function submitMultDoctoEntryFrm()
 {
  var Id= document.insertForm.id.value;
  var formId= document.insertForm.formId.value;
  var PayType1= eval(document.insertForm.payType1.value);
  var PayType2= eval(document.insertForm.payType2.value);
  var PayType3= eval(document.insertForm.payType3.value);
  var PayType4= eval(document.insertForm.payType4.value);
  var PaymentAmt1 = eval(document.insertForm.payAmt1.value);//alert(PaymentAmt1);
  var PaymentAmt2 = eval(document.insertForm.payAmt2.value);//alert(PaymentAmt2);
  var PaymentAmt3 = eval(document.insertForm.payAmt3.value);//alert(PaymentAmt3);
  var PaymentAmt4 = eval(document.insertForm.payAmt4.value);//alert(PaymentAmt4);
  var ClerkId = document.insertForm.clerkId.value;
//  var DocType = document.insertForm.DoctoTypeId.value;
  
  var CC1= document.insertForm.CC1.value;
  var CC2= document.insertForm.CC2.value;
  var CC3= document.insertForm.CC3.value;
  var CC4= document.insertForm.CC4.value;
  
  var AmountDue   = eval(document.insertForm.amtDue.value);//alert(AmountDue);
  var AmountRecd  = eval(document.insertForm.amtRecd.value);  //alert(AmountRecd);
  var change      = eval(document.insertForm.ChangeField.value);
  var doctoIndexClass  = eval(document.insertForm.doctoIndexClass.value);
  var confirmMsg  = 'Change amount is over $50, Okay?';
  var TotaPaymentAmt, CreditCarType, continueSubmit, ExemptType, makeReceipt;
  //20050322- habia problemas con el redondeo
  //TotalPaymentAmt = PaymentAmt1 + PaymentAmt2  + PaymentAmt3 + PaymentAmt4; 
  //20050426-formula no sirve para redondear, comentado
  TotalPaymentAmt = (Math.round(PaymentAmt1 *100)*0.01) + (Math.round(PaymentAmt2 *100)*0.01) + (Math.round(PaymentAmt3 *100)*0.01) + (Math.round(PaymentAmt4 *100)*0.01); 
  //
  //alert('TotalPaymentAmt  -- ='+TotalPaymentAmt);
  CreditCarType='2';
  ARType = '3';    
  ExemptType='4';
    
	  if(PayType1==CreditCarType || PayType2==CreditCarType || PayType3==CreditCarType || PayType4==CreditCarType)
      {
       if(AmountRecd > AmountDue)
       {
        alert('No change can be returned if payment is made by Visa/MC');
       }
       else { continueSubmit='OK'; }
      }
      else { continueSubmit='OK'; }
      
      if(continueSubmit)
      {
	   //alert('TotalPaymentAmt|'+TotalPaymentAmt+'< AmountDue|'+AmountDue);
	   //alert('AmtRecd|'+AmountRecd+'< AmountDue|'+AmountDue);
       if(
	      //(TotalPaymentAmt < AmountDue) //20050426-problema con redondeo
		  (AmountRecd < AmountDue)  && 
		  (PayType1!=ExemptType && PayType2!=ExemptType && PayType3!=ExemptType && PayType4!=ExemptType)  && 
	      (PayType1!=ARType && PayType2!=ARType && PayType3!=ARType && PayType4!=ARType) && 
		  (doctoIndexClass!=20)
		 )
	   { alert('Not enough money has been paid'); }
       else
       {
	    if(doctoIndexClass==20) { change=0; } //chattel document
        if(change>50)
        {
         var is_confirmed = confirm(confirmMsg);	
         if (is_confirmed) { document.insertForm.submit(); makeReceipt='OK'; }
        }
        else { document.insertForm.submit(); makeReceipt='OK'; }
       }
      }
	  
	  if(makeReceipt)// && DocType != 'MARR' && DocType != 'MARRIAGE'
	  {
		window.open('346_B1.php?id='+Id+'&formId='+formId+'&AmtDue='+AmountDue+'&AmtRcd='+AmountRecd+'&change='+change+'&payType1='+PayType1+'&payAmt1='+PaymentAmt1+'&payType2='+PayType2+'&payAmt2='+PaymentAmt2+'&payType3='+PayType3+'&payAmt3='+PaymentAmt3+'&payType4='+PayType4+'&payAmt4='+PaymentAmt4+'&chkNo1='+CC1+'&chkNo2='+CC2+'&chkNo3='+CC3+'&chkNo4='+CC4+'&clkId='+ClerkId,'FinalReport','width=200,height=200');
	  }
 }

 function checkPaymentAmtMPOF(nPayment)
 {
  var PaymentAmt;
  var Zerovalue = '0';
  switch(nPayment)
  {
   case 1: PaymentAmt = document.insertForm.payAmt1.value; break;
   case 2: PaymentAmt = document.insertForm.payAmt2.value; break;
   case 3: PaymentAmt = document.insertForm.payAmt3.value; break;
   case 4: PaymentAmt = document.insertForm.payAmt4.value; break;
  }
//  alert('PaymentAmt = ' + PaymentAmt);
  if(isNaN(PaymentAmt) || (PaymentAmt<0))
  { 
   alert('Invalid value'); 
   switch(nPayment)
   {
    case 1: document.insertForm.payAmt1.value= Zerovalue; break;
    case 2: document.insertForm.payAmt2.value= Zerovalue; break;
    case 3: document.insertForm.payAmt3.value= Zerovalue; break;
    case 4: document.insertForm.payAmt4.value= Zerovalue; break;
   }
  }
  if(!PaymentAmt)
  {
   switch(nPayment)
   {
    case 1: document.insertForm.payAmt1.value= Zerovalue; break;
    case 2: document.insertForm.payAmt2.value= Zerovalue; break;
    case 3: document.insertForm.payAmt3.value= Zerovalue; break;
    case 4: document.insertForm.payAmt4.value= Zerovalue; break;
   }
  }//if(!PaymentAmt)
  else
  {
  	PaymentAmt = format_number(PaymentAmt,2);
   switch(nPayment)
   {
    case 1: document.insertForm.payAmt1.value= PaymentAmt; break;
    case 2: document.insertForm.payAmt2.value= PaymentAmt; break;
    case 3: document.insertForm.payAmt3.value= PaymentAmt; break;
    case 4: document.insertForm.payAmt4.value= PaymentAmt; break;
   }
  }//else
 }

 
function CalcMultiPayAmt()
{
 var valZero = '0';
 AmountDue   = eval(document.insertForm.amtDue.value);
 PaymentAmt1 = eval(document.insertForm.payAmt1.value);
 PaymentAmt2 = eval(document.insertForm.payAmt2.value);
 PaymentAmt3 = eval(document.insertForm.payAmt3.value);
 PaymentAmt4 = eval(document.insertForm.payAmt4.value);
 AmountRecd  = eval(document.insertForm.amtRecd.value);
 Change      = eval(document.insertForm.ChangeField.value);
 var doctoIndexClass  = eval(document.insertForm.doctoIndexClass.value); 
 var tmpChangeDue, tmpChangeField;
 showAddtnlPgs = eval("0");
 
 if(doctoIndexClass==20)  //chattel document
 {
  document.insertForm.payAmt1.value = valZero;
  document.insertForm.payAmt2.value = valZero;
  document.insertForm.payAmt3.value = valZero;
  document.insertForm.payAmt4.value = valZero;
  document.insertForm.amtRecd.value = valZero;
  document.insertForm.ChangeField.value = valZero;
 }
 else
 {
     //operations
     tmpAmtRecd = PaymentAmt1 + PaymentAmt2 + PaymentAmt3 + PaymentAmt4;
     document.insertForm.amtRecd.value = eval(format_number(tmpAmtRecd,2));//eval(tmpAmtRecd);
    
     tmpChangeField = tmpAmtRecd - AmountDue;
	 tmpChangeField = format_number(tmpChangeField,2);
//	 alert('tmpChangeField = ' + tmpChangeField);
     if(tmpChangeField<0) 
     {
      tmpChangeField='';
      document.insertForm.ChangeField.value = tmpChangeField;
     }
     else
     {
//	 	alert('tmpChangeField mayor que cero = '+tmpChangeField);
      document.insertForm.ChangeField.value = eval(format_number(tmpChangeField,2));//eval(tmpChangeField); 
//	  var AAA = document.insertForm.ChangeField.value;
//	 	alert('tmpChangeField mayor que cero = '+AAA);
     }
	 //
    if(AmountDue == tmpAmtRecd) 
    {
     tmpChangeField='0'; 
     tmpChangeDue='0';
     document.insertForm.ChangeField.value = eval(tmpChangeField);
     document.insertForm.ChangeDue.value = eval(tmpChangeDue);
    }
    else if(tmpAmtRecd<AmountDue) 
    {
     tmpChangeField='0';
     tmpChangeDue = AmountDue - tmpAmtRecd;
     document.insertForm.ChangeField.value = eval(tmpChangeField);
     document.insertForm.ChangeDue.value = eval(format_number(tmpChangeDue,2));//eval(tmpChangeDue);
    }
    else if(tmpAmtRecd>=AmountDue)
    {
     tmpChangeField= tmpAmtRecd - AmountDue;
     tmpChangeDue='0';
     document.insertForm.ChangeField.value = eval(format_number(tmpChangeField,2));//eval(tmpChangeField);
     document.insertForm.ChangeDue.value = eval(tmpChangeDue);
    }
    else 
    {
     tmpChangeDue='';
     document.insertForm.ChangeDue.value = tmpChangeDue;
    }
 }
}
 
 
/*
* Revision 1.4
* Author: LeAnn Roberts
* Date: September, 2003
* Note: Modified the if logic: Math.pow()
* return number with decimals, ejem 1000.00
*/
function format_number(pnumber,decimals) 
{  
  if (isNaN(pnumber)) { return 0};
  if (pnumber=='') { return 0};
  if(pnumber <= 0.001) pnumber = 0;
  //alert('VALIDANDO = ' + pnumber);
  
  var IsNegative=(parseInt(pnumber)<0); 
  if(IsNegative)pnumber=-pnumber; 

  var snum = new String(pnumber);  
  var sec = snum.split('.');  
  var whole = parseInt(sec[0]);  
  var result = '';  
  var flgRoundDecimal=1;
  var len_1,len_2,len_3;
  
  if(sec.length > 1)
  {  
   var dec = new String(sec[1]);  
   //window.alert('1) whole='+whole+' dec='+dec);
   var len_1 = dec.length;
   //
   //----added, 20040629 - azlara----
   if(dec.length>1&&(dec<10))
   {
    flgRoundDecimal=0;
   };
   //window.alert('1.0) flgRoundDecimal = '+flgRoundDecimal);
   //--------------------------------
   
   numdecs = dec.length-decimals-1;
   //window.alert('2.0) numdecs='+numdecs);
   numToPow = parseInt(numdecs);
   //window.alert('2.1) numToPow='+numToPow);
   dec = eval(dec*1);
   //window.alert('2.1.0) dec='+dec);
   ndec = parseInt(dec); 
   //window.alert('2.2) ndec='+ndec);
  //------added 20040805 - msilva -----
   len_2 = ndec+'';
   len_3 = len_2.length;
   //window.alert('2.2.1) len_1='+len_1);
   //window.alert('2.2.2) len_3='+len_3);
   if(len_1 > len_3) flgRoundDecimal=0;
   //window.alert('1.2) flgRoundDecimal = '+flgRoundDecimal);
  //-----------------------------------
   numToPow = Math.pow(10,numToPow); 
   //window.alert('2.3) numToPow='+numToPow);
   dec = ndec/numToPow; 
   //window.alert('2.4) dec='+ndec+'/'+numToPow);
   //dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimals-1)); 
   //despues de esta operacion, si dec=.01, devuelve 1, y luego se concatena como si fuera .10, q esta mal
   //
   //window.alert('2) whole='+whole+' dec='+dec);
   dec = Math.round(dec); 
   //window.alert('3.0) whole='+whole+' dec='+dec);
   dec = parseInt(dec)/10; 
   //window.alert('3) whole='+whole+' dec='+dec);
   //
   if(IsNegative) 
   { 
	var x = 0-dec; 
	x = Math.round(x); 
	dec = - x; 
   } 
   else 
   { 
	dec = Math.round(dec); 
   } 
   //window.alert('4) whole='+whole+' dec='+dec);
	/* 
	* If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
	* then we need to add 1 to the 'whole' and set the dec to 0. 
	*/ 
   if(dec==Math.pow(10, parseInt(decimals)))
   { 
	whole+=1; 
	dec="0"; 
    //window.alert('5) whole='+whole+' dec='+dec);
   } 
   //----------added - 20040629 - azlara--------------
   if(flgRoundDecimal==0) 
   {
	 dec = '0'+ dec; 
     //window.alert('6) whole='+whole+' dec= '+dec);
   }
   //------------------------------------------------
   dec = String(whole) + "." + String(dec);  
   var dot = dec.indexOf('.');  
   if(dot == -1)
   {  
      dec += '.';  
      dot = dec.indexOf('.');  
   } 
   var l=parseInt(dot)+parseInt(decimals); 
    while(dec.length <= l) 
	{
	 dec += '0'; 
	 //window.alert('7) whole='+whole+' dec= '+dec);
	}  
    result = dec;  
  }
  else
  {  
    var dot;  
    var dec = new String(whole);  
    dec += '.';  
    dot = dec.indexOf('.');  
    var l=parseInt(dot)+parseInt(decimals); 
    while(dec.length <= l) 
	{
	 dec += '0'; 
	 //window.alert('8) whole='+whole+' dec= '+dec);
	}  
    result = dec;  
  }  
  if(IsNegative)result="-"+result; 
  //
  //window.alert('10)result= '+result);
  //
  return result;  
}  


function format_number_original(pnumber,decimals) 
{  
  if (isNaN(pnumber)) { return 0};  
  if (pnumber=='') { return 0};  
   
  var IsNegative=(parseInt(pnumber)<0); 
  if(IsNegative)pnumber=-pnumber; 

  var snum = new String(pnumber);  
  var sec = snum.split('.');  
  var whole = parseInt(sec[0]);  
  var result = '';  
  if(sec.length > 1)
  {  
   var dec = new String(sec[1]);  
   //window.alert('1)whole='+whole+' dec='+dec);
   dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimals-1)); 
   //despues de esta operacion, si dec=.01, devuelve 1, y luego se concatena como si fuera .10, q esta mal
   //window.alert('2)whole='+whole+' dec='+dec);
   Math.round(dec); 
   dec = parseInt(dec)/10; 
   //window.alert('3)whole='+whole+' dec='+dec);
   //
   if(IsNegative) 
   { 
	var x = 0-dec; 
	x = Math.round(x); 
	dec = - x; 
   } 
   else 
   { 
	dec = Math.round(dec); 
   } 
	/* 
	* If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
	* then we need to add 1 to the 'whole' and set the dec to 0. 
	*/ 
   if(dec==Math.pow(10, parseInt(decimals)))
   { 
	whole+=1; 
	dec="0"; 
   } 

   dec = String(whole) + "." + String(dec);  
   var dot = dec.indexOf('.');  
   if(dot == -1)
   {  
      dec += '.';  
      dot = dec.indexOf('.');  
   } 
   var l=parseInt(dot)+parseInt(decimals); 
    while(dec.length <= l) { dec += '0'; }  
    result = dec;  
  }
  else
  {  
    var dot;  
    var dec = new String(whole);  
    dec += '.';  
    dot = dec.indexOf('.');  
    var l=parseInt(dot)+parseInt(decimals); 
    while(dec.length <= l) { dec += '0'; }  
    result = dec;  
  }  
  if(IsNegative)result="-"+result; 
  return result;  
}  



//convert Money to numeric: 1,000.00 -> 1000.00
//parameters: number, 0 int/ 1 float
function money_to_numeric(_numString, _NumType)
{
  var _returnValue="";
  var _array=_numString.split(""); /* make each character be in its own array slot */
  for(var i=0; i< _array.length;i++)
  {
    /* if the character is not a $ or a space or a comma then take it */
    if(_array[i].search(/[$ ,]/) == -1)
	{
	  /* this uses strings addition to catinate the value together */
	  /* the first value in an addition equation sets the type of opperation - here it is a string */
      _returnValue += _array[i].toString();
	}
  }
  /* this converts it to an integer */
  if(_NumType==0){ return(parseInt(_returnValue)); }
  else { return(parseFloat(_returnValue)); }
}

//ejem: 1000.00 ->1,000.00
function numeric_to_money(_v)
{
  var _dollars=parseInt(_v);
  var _cents=parseInt((_v-_dollars)*100);
  var _negative=_dollars<0;
  if(_negative){_dollars=-_dollars;_cents=-_cents;}
  while(_cents.toString().length<2)_cents="0"+_cents;
  var _dA=_dollars.toString().split("");
  var _d="";
  for(var i=_dA.length-1;i>=0;i--)
  {
    var _comma="";
	if((_dA.length-i)%3==0 && i!=0)_comma=",";
    _d=_comma+_dA[i]+_d;
  }
  var _neg_sign=_negative?"-":"";
  var _result=_neg_sign+_d;//+"."+_cents //  var _result="$"+_neg_sign+_d+"."+_cents;
  return _result;
}


function TotalValue()
{
 var LandValue, ImprvValue, TotalValue;
 LandValue  = document.insertForm.pvaLVal.value;
 ImprvValue = document.insertForm.pvaImVal.value;
 if(!LandValue) LandValue=0;
 if(!ImprvValue) ImprvValue=0;
 var tmpLndVal= money_to_numeric(LandValue,0);
 var tmpImprVal=money_to_numeric(ImprvValue,0);
 TotalValue = parseFloat(tmpImprVal) + parseFloat(tmpLndVal);
 TotalValue = numeric_to_money(TotalValue);//(format_number(TotalValue,1));
 LandValue = numeric_to_money(tmpLndVal);
 ImprvValue = numeric_to_money(tmpImprVal);
 document.insertForm.pvaLVal.value = LandValue; 
 document.insertForm.pvaImVal.value = ImprvValue; 
 document.insertForm.pvaTVal.value = TotalValue; 
}

 function fcnCollectionPeriod_Original()
 {
  var txBillNo,txTaxYr;
  txBillNo =eval(document.insertForm.txBillNo.value);
  txTaxYr =eval(document.insertForm.txTaxYr.value);
  var paymentPeriod=document.insertForm.paymentPeriod.value;
  var txCollectionPeriod=document.insertForm.txCollectionPeriod.value;
  var chngPeriod='';
  var amountDue = eval(document.insertForm.txAmountDue.value);
  var txBalanceDue = eval(document.insertForm.txBalanceDue.value);
  var txTotalRecd = eval(document.insertForm.txTotalRecd.value);
  var txSheriffsFee = 0;
  var txChangeBalDue = 0;
  var intZero = 0;
  var strZero= '0.00';
  var txAmount1 = document.insertForm.txAmount1.value; //Paid by 1
  var txAmount2 = document.insertForm.txAmount2.value;
  var txAmount3 = document.insertForm.txAmount3.value;
  var PaidBeforeSale = document.insertForm.PaidBeforeSale.value;
  if(paymentPeriod && txCollectionPeriod)
  {
   if(paymentPeriod!=txCollectionPeriod) 
   {
    alert('Payment Period changed, please enter comment');
    document.insertForm.txComment.focus();
    chngPeriod='OK';
    document.insertForm.chngPeriod.value=chngPeriod;
	if(txCollectionPeriod<'04')
	{
     document.insertForm.txBalanceDue.value = amountDue;
	 txSheriffsFee = '0.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else {txChangeBalDue='0.00';document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 //
	 switch(txCollectionPeriod)
	 {
	  case '01':
	  document.insertForm.txAmountDue.value = txAmount1;
	  document.insertForm.txBalanceDue.value = txAmount1;
	  //txChangeBalDueStart = eval(0-txAmount1);
	  break;
	  case '02':
	  document.insertForm.txAmountDue.value = txAmount2;
	  document.insertForm.txBalanceDue.value = txAmount2;
	  //txChangeBalDueStart = eval(0-txAmount2);
	  break;
	  case '03':
	  document.insertForm.txAmountDue.value = txAmount3;
	  document.insertForm.txBalanceDue.value = txAmount3;
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  default:break;
	 }
	 document.insertForm.txCheckAmt.value= strZero;
	 document.insertForm.txCashAmt.value = strZero;
	 document.insertForm.txTotalRecd.value=intZero;
	 document.insertForm.txChangeBalDue.value = strZero;
	}
	else
	{
	 txSheriffsFee = 8;
	 txBalanceDue = amountDue+txSheriffsFee;
	 document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	 txSheriffsFee = '8.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else {txChangeBalDue='0.00';document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	}
   }
   else if((txCollectionPeriod=='04') && (paymentPeriod==txCollectionPeriod))
   {
	txSheriffsFee = 8;
	txBalanceDue = amountDue+txSheriffsFee;
	document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	txSheriffsFee = '8.00';
	document.insertForm.txSheriffsFee.value= txSheriffsFee;
	txChangeBalDue = txTotalRecd - txBalanceDue;
	if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	else {txChangeBalDue='0.00';document.insertForm.txChangeBalDue.value= txChangeBalDue;}
    chngPeriod='';document.insertForm.chngPeriod.value=chngPeriod;
   }
   else {chngPeriod='';document.insertForm.chngPeriod.value=chngPeriod;}
  }
 }
 
 function calcTaxPaymentSheriffFee()
 {
  var txAmountDue,txBalanceDue,txSheriffsFee,txTotalRecd, txChangeBalDue,txAmountDue,OrgAmountDue,txAmountToPaid;
  //txAmountDue = eval(document.insertForm.txAmountDue.value);
  txSheriffsFee = document.insertForm.txSheriffsFee.value; 
  txSheriffsFee = money_to_numeric(txSheriffsFee, 1);
  txSheriffsFee = eval(txSheriffsFee);
  //
  txTotalRecd = document.insertForm.txTotalRecd.value;
  txTotalRecd = money_to_numeric(txTotalRecd, 1);
  txTotalRecd = eval(txTotalRecd);
  //
  txAmountDue = document.insertForm.txAmountDue.value; 
  txAmountDue = money_to_numeric(txAmountDue, 1);
  txAmountDue = eval(txAmountDue);
  //
  OrgAmountDue = document.insertForm.OrgAmountDue.value;
  OrgAmountDue = money_to_numeric(OrgAmountDue, 1);
  OrgAmountDue = eval(OrgAmountDue);
  //
  OrgTxSheriffsFee = document.insertForm.OrgTxSheriffsFee.value;
  OrgTxSheriffsFee = money_to_numeric(OrgTxSheriffsFee, 1);
  OrgTxSheriffsFee = eval(OrgTxSheriffsFee);
  //
  var strZero = '0.00';
  //txBalanceDue = eval(document.insertForm.txBalanceDue.value);
  //
  txAmountToPaid = eval(OrgAmountDue) - eval(OrgTxSheriffsFee);
  txAmountDue = eval(txAmountToPaid) + eval(txSheriffsFee);
  txAmountDue = format_number(txAmountDue,2);
  document.insertForm.txAmountDue.value = txAmountDue;
  //
  txBalanceDue = eval(txAmountToPaid) + eval(txSheriffsFee) - eval(txTotalRecd);
  //window.alert(txBalanceDue+' = txAmountToPaid + txSheriffsFee - txTotalRecd: '+txAmountToPaid+'+'+txSheriffsFee+'-'+txTotalRecd);
  //
  if(txBalanceDue<0)
  {
   txBalanceDue = eval(txBalanceDue) * eval(-1);
   txChangeBalDue = format_number(txBalanceDue,2);
   document.insertForm.txChangeBalDue.value = txChangeBalDue;
   txBalanceDue=strZero;
  }
  else 
  {
   document.insertForm.txChangeBalDue.value = strZero; 
  }
  txBalanceDue = format_number(txBalanceDue,2);
  document.insertForm.txBalanceDue.value = txBalanceDue;
  //
  //txSheriffsFee = format_number(txSheriffsFee,2);
  //document.insertForm.txSheriffsFee.value = txSheriffsFee;
 }
 
 function calcTaxPaymentSheriffAdvFee()
 {
  var txAmountDue,txBalanceDue,txSheriffsFee,txTotalRecd, txChangeBalDue,txAmountDue,OrgAmountDue,txAmountToPaid,txAdvFee;
  //
  txAdvFee = document.insertForm.txAdvFee.value;
  txAdvFee = money_to_numeric(txAdvFee, 1);
  txAdvFee = eval(txAdvFee);
  //
  txShffFee = document.insertForm.txShffFee.value;
  txShffFee = money_to_numeric(txShffFee, 1);
  txShffFee = eval(txShffFee);
  //
  //txAmountDue = eval(document.insertForm.txAmountDue.value);
  txSheriffsFee = document.insertForm.txSheriffsFee.value; 
  txSheriffsFee = money_to_numeric(txSheriffsFee, 1);
  txSheriffsFee = eval(txSheriffsFee);
  //
  txTotalRecd = document.insertForm.txTotalRecd.value;
  txTotalRecd = money_to_numeric(txTotalRecd, 1);
  txTotalRecd = eval(txTotalRecd);
  //
  txAmountDue = document.insertForm.txAmountDue.value; 
  txAmountDue = money_to_numeric(txAmountDue, 1);
  txAmountDue = eval(txAmountDue);
  //
  OrgAmountDue = document.insertForm.OrgAmountDue.value;
  OrgAmountDue = money_to_numeric(OrgAmountDue, 1);
  OrgAmountDue = eval(OrgAmountDue);
  //
  OrgTxSheriffsFee = document.insertForm.OrgTxSheriffsFee.value;
  OrgTxSheriffsFee = money_to_numeric(OrgTxSheriffsFee, 1);
  OrgTxSheriffsFee = eval(OrgTxSheriffsFee);
  //
  var strZero = '0.00';
  //txBalanceDue = eval(document.insertForm.txBalanceDue.value);
  //
  txAmountToPaid = eval(OrgAmountDue) - eval(OrgTxSheriffsFee);
  txAmountDue = eval(txAmountToPaid) + eval(txShffFee) + eval(txAdvFee);//txAmountDue = eval(txAmountToPaid) + eval(txSheriffsFee);
  txAmountDue = format_number(txAmountDue,2);
  document.insertForm.txAmountDue.value = txAmountDue;
  //
  txBalanceDue = eval(txAmountToPaid) + eval(txShffFee) + eval(txAdvFee) - eval(txTotalRecd);//txBalanceDue = eval(txAmountToPaid) + eval(txSheriffsFee) - eval(txTotalRecd);
  //window.alert(txBalanceDue+' = txAmountToPaid + txSheriffsFee - txTotalRecd: '+txAmountToPaid+'+'+txSheriffsFee+'-'+txTotalRecd);
  //
  if(txBalanceDue<0)
  {
   txBalanceDue = eval(txBalanceDue) * eval(-1);
   txChangeBalDue = format_number(txBalanceDue,2);
   document.insertForm.txChangeBalDue.value = txChangeBalDue;
   txBalanceDue=strZero;
  }
  else 
  {
   document.insertForm.txChangeBalDue.value = strZero; 
  }
  txBalanceDue = format_number(txBalanceDue,2);
  document.insertForm.txBalanceDue.value = txBalanceDue;
  //
  //txSheriffsFee = format_number(txSheriffsFee,2);
  //document.insertForm.txSheriffsFee.value = txSheriffsFee;
 }

 function TaxPaymentShffFee()
 {
  var txBillNo,txTaxYr,txShffFee,txSheriffFeeByPeriod;
  txShffFee = document.insertForm.txShffFee.value;
  if(isNaN(txShffFee)||!txShffFee) { txShffFee='0.00'; }
  txShffFee = eval(txShffFee);
  txSheriffFeeByPeriod = eval(document.insertForm.txSheriffFeeByPeriod.value);
  //
  var intZero = 0;
  var strZero= '0.00';
  //
  if(isNaN(txShffFee))
  {
   window.alert('Sheriff Fee Invalid');
   document.insertForm.txShffFee.value=strZero;
   calcTaxPaymentSheriffAdvFee();
  }
  else if((txShffFee=='')||(txShffFee<0))
  {
   if(txShffFee!=0) window.alert('Sheriff Fee Invalid');
   document.insertForm.txShffFee.value=strZero;
   calcTaxPaymentSheriffAdvFee();
  }
  else
  {
   if((txShffFee>=0)&&(txShffFee<=txSheriffFeeByPeriod))
   {
    calcTaxPaymentSheriffAdvFee();
   }
   else
   {
    strMsg = 'Sheriff Fee value out of range';
    if(txSheriffFeeByPeriod>0) strMsg+= ', select a value between 0 and '+txSheriffFeeByPeriod;
    window.alert(strMsg);
	document.insertForm.txShffFee.value=strZero;
	calcTaxPaymentSheriffAdvFee();
   }
  }
 }
  
 function TaxPaymentAdvFee()
 {
  var txBillNo,txTaxYr,txAdvFee,txAdvFeeByPeriod;
  txAdvFee = document.insertForm.txAdvFee.value;
  if(isNaN(txAdvFee)||!txAdvFee) { txAdvFee='0.00'; }
  txAdvFee = eval(txAdvFee);
  txAdvFeeByPeriod = eval(document.insertForm.txAdvFeeByPeriod.value);
//  window.alert('txAdvFeeByPeriod='+txAdvFeeByPeriod);
  var intZero = 0;
  var strZero= '0.00';
  //
  if(isNaN(txAdvFee))
  {
   window.alert('Advertising Fee Invalid');
   document.insertForm.txAdvFee.value=strZero;
   calcTaxPaymentSheriffAdvFee();
  }
  else if((txAdvFee=='')||(txAdvFee<0))
  {
   if(txAdvFee!=0) window.alert('Advertising Fee Invalid');
   document.insertForm.txAdvFee.value=strZero;
   calcTaxPaymentSheriffAdvFee();
  }
  else
  {
   if((txAdvFee>=0)&&(txAdvFee<=txAdvFeeByPeriod))
   {
    calcTaxPaymentSheriffAdvFee();
   }
   else
   {
    strMsg = 'Advertising Fee value out of range';
    if(txAdvFeeByPeriod>0) strMsg+= ', select a value between 0 and '+txAdvFeeByPeriod;
    window.alert(strMsg);
	document.insertForm.txAdvFee.value=strZero;
	calcTaxPaymentSheriffAdvFee();
   }
  }
 }
 
 function TaxPaymentSheriffFee()
 {
  var txBillNo,txTaxYr,OrgTxSheriffsFee,txBalanceDue,txSheriffsFee;
  txBalanceDue = document.insertForm.txBalanceDue.value;
  txBalanceDue = money_to_numeric(txBalanceDue, 1);
  txBalanceDue = eval(txBalanceDue);
  txSheriffsFee = document.insertForm.txSheriffsFee.value;
  if(isNaN(txSheriffsFee)||!txSheriffsFee) { txSheriffsFee='0.00'; }
  txSheriffsFee = eval(txSheriffsFee);
  OrgTxSheriffsFee = eval(document.insertForm.OrgTxSheriffsFee.value);
  var intZero = 0;
  var strZero= '0.00';
  //
  if(isNaN(txSheriffsFee))
  {
   window.alert('Sheriff Fee Invalid');
   document.insertForm.txSheriffsFee.value=strZero;
   calcTaxPaymentSheriffFee();
  }
  else if((txSheriffsFee=='')||(txSheriffsFee<0))
  {
   if(txSheriffsFee!=0) window.alert('Sheriff Fee Invalid');
   document.insertForm.txSheriffsFee.value=strZero;
   calcTaxPaymentSheriffFee();
  }
  else
  {
   if((txSheriffsFee>=0)&&(txSheriffsFee<=OrgTxSheriffsFee))
   {
    calcTaxPaymentSheriffFee();
   }
   else
   {
    strMsg = 'Sheriff Fee value out of range';
    if(OrgTxSheriffsFee>0) strMsg+= ', select a value between 0 and '+OrgTxSheriffsFee;
    window.alert(strMsg);
	document.insertForm.txSheriffsFee.value=strZero;
	calcTaxPaymentSheriffFee();
   }
  }
 }

 function fcnCollectionPeriod(flgShowAlertComments)
 {
  var txBillNo,txTaxYr;
  txBillNo =eval(document.insertForm.txBillNo.value);
  txTaxYr =eval(document.insertForm.txTaxYr.value);
  var paymentPeriod=document.insertForm.paymentPeriod.value;
  var txCollectionPeriod=document.insertForm.txCollectionPeriod.value;
  var chngPeriod='';

  //problemas con las comas resuelto, ejem :
  //si se hace eval de (1,655.06) hay error
  var amountDue = document.insertForm.txAmountDue.value;
  amountDue = money_to_numeric(amountDue, 1);
  amountDue = eval(amountDue);
  
  var txBalanceDue = document.insertForm.txBalanceDue.value;
  txBalanceDue = money_to_numeric(txBalanceDue, 1);
  txBalanceDue = eval(txBalanceDue);
  
  var txTotalRecd = document.insertForm.txTotalRecd.value;
  txTotalRecd =money_to_numeric(txTotalRecd, 1);
  txTotalRecd = eval(txTotalRecd);
  
  var txSheriffsFee = 0;
  var txChangeBalDue = 0;
  var intZero = 0;
  var txAmountDueWithNoSheriffFee=0;
  var strZero= '0.00';
  var txAmount1 = document.insertForm.txAmount1.value; //Paid by 1
  var txAmount2 = document.insertForm.txAmount2.value;
  var txAmount3 = document.insertForm.txAmount3.value;
  var PaidBeforeSale = document.insertForm.PaidBeforeSale.value;
  PaidBeforeSale =money_to_numeric(PaidBeforeSale, 1);
  
  
  var ORG_RC_ADVERTISE_FEE = document.insertForm.ORG_RC_ADVERTISE_FEE.value;
  var ORG_RC_SHERIFFS_FEE = document.insertForm.ORG_RC_SHERIFFS_FEE.value;
 //
  var txSheriffFeeByPeriod='0.00';//20040727-azlara-bug3043
  var txAdvFeeByPeriod='0.00';//20040727-azlara-bug3043
  document.insertForm.txSheriffFeeByPeriod.value= txSheriffFeeByPeriod;//20070727-azlara-bug3043
  document.insertForm.txAdvFeeByPeriod.value= txAdvFeeByPeriod;//20070727-azlara-bug3043
  document.insertForm.txShffFee.value= strZero;//20070727-azlara-bug3043
  document.insertForm.txAdvFee.value= strZero;//20070727-azlara-bug3043
 //
 
 if(txTaxYr>=2004)
 {
  //
  var txRealFirstPenalty2PeriodAmt = document.insertForm.txRealFirstPenalty2PeriodAmt.value;
  if(paymentPeriod && txCollectionPeriod)
  {
   //window.alert('paymentPeriod='+paymentPeriod+' txCollectionPeriod='+txCollectionPeriod);
   if(paymentPeriod!=txCollectionPeriod)
   {
    //window.alert('periodos diferentes');
    if(flgShowAlertComments==1) alert('Payment Period changed, please enter comment');
    document.insertForm.txComment.focus();
    chngPeriod='OK';
    document.insertForm.chngPeriod.value=chngPeriod;
	if(txCollectionPeriod<'05')
	{
     document.insertForm.txBalanceDue.value = amountDue;
	 txSheriffsFee = '0.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else {txChangeBalDue='0.00';document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 //
	 switch(txCollectionPeriod)
	 {
	  case '01':
	  document.insertForm.txAmountDue.value = txAmount1;
	  document.insertForm.txBalanceDue.value = txAmount1;
	  document.insertForm.OrgAmountDue.value = txAmount1;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount1;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount1);
	  break;
	  case '02':
	  document.insertForm.txAmountDue.value = txAmount2;
	  document.insertForm.txBalanceDue.value = txAmount2;
  	  document.insertForm.OrgAmountDue.value = txAmount2;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount2;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount2);
	  break;
	  case '03':
	  document.insertForm.txAmountDue.value = txAmount3;
	  document.insertForm.txBalanceDue.value = txAmount3;
  	  document.insertForm.OrgAmountDue.value = txAmount3;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount3;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  case '04':
	  document.insertForm.txAmountDue.value = txRealFirstPenalty2PeriodAmt;
	  document.insertForm.txBalanceDue.value = txRealFirstPenalty2PeriodAmt;
  	  document.insertForm.OrgAmountDue.value = txRealFirstPenalty2PeriodAmt;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txRealFirstPenalty2PeriodAmt;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  default:break;
	 }
	 document.insertForm.txCheckAmt.value= strZero;
	 document.insertForm.txCashAmt.value = strZero;
	 document.insertForm.txTotalRecd.value=intZero;
	 document.insertForm.txChangeBalDue.value = strZero;
	}
	else //period>=5
	{
	 amountDue = PaidBeforeSale;
	 document.insertForm.OrgAmountDue.value = amountDue;//bug 2871
	 //txSheriffsFee = 8;
	 txSheriffsFee = eval(ORG_RC_ADVERTISE_FEE) + eval(ORG_RC_SHERIFFS_FEE);
	 txBalanceDue = eval(amountDue);//+eval(txSheriffsFee);//bug 2871
	 document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	 //txSheriffsFee = '8.00';
	 txSheriffsFee = format_number(txSheriffsFee,2);
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 document.insertForm.txAmountDue.value = amountDue;
	 txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);
	 txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);//20041101-azlara-redondear amt due
 	 //window.alert('txAmountDueWithNoSheriffFee='+txAmountDueWithNoSheriffFee);
 	 document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
  	 document.insertForm.txShffFee.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	 document.insertForm.txAdvFee.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
  	 document.insertForm.txSheriffFeeByPeriod.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	 document.insertForm.txAdvFeeByPeriod.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else 
	 {
	  txChangeBalDue='0.00';
	  document.insertForm.txChangeBalDue.value= txChangeBalDue;
	  document.insertForm.txBalanceDue.value = txBalanceDue;
	 }
	}
   }
   else if((txCollectionPeriod=='05') && (paymentPeriod==txCollectionPeriod))
   {
    //window.alert('periodo 05 y paymentPeriod==txCollectionPeriod');
    amountDue = PaidBeforeSale;
    document.insertForm.OrgAmountDue.value = amountDue;//bug 2871
	//txSheriffsFee = 8;
	txSheriffsFee = eval(ORG_RC_ADVERTISE_FEE) + eval(ORG_RC_SHERIFFS_FEE);
	txBalanceDue = eval(amountDue);//+eval(txSheriffsFee);//bug 2871
	document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	//txSheriffsFee = '8.00';
	txSheriffsFee = format_number(txSheriffsFee,2);
	document.insertForm.txSheriffsFee.value= txSheriffsFee;
	document.insertForm.txAmountDue.value = amountDue;
	txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);//20041101-azlara-redondear amt due
	txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);
    document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
	//window.alert('amountDue('+amountDue+') - txSheriffsFee('+txSheriffsFee);
  	document.insertForm.txShffFee.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	document.insertForm.txAdvFee.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
  	document.insertForm.txSheriffFeeByPeriod.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	document.insertForm.txAdvFeeByPeriod.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
	txChangeBalDue = txTotalRecd - txBalanceDue;
	if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	else { txChangeBalDue='0.00'; document.insertForm.txChangeBalDue.value= txChangeBalDue; }
    chngPeriod='';document.insertForm.chngPeriod.value=chngPeriod;
   }
   else 
   {
    //window.alert('Periodos iguales<5');
    chngPeriod='';
	document.insertForm.chngPeriod.value=chngPeriod;
	//20041025-azlara-bug
	if(paymentPeriod!=txCollectionPeriod)
	{
     if(flgShowAlertComments==1) alert('Payment Period changed, please enter comment');
     document.insertForm.txComment.focus();
     chngPeriod='OK';
     document.insertForm.chngPeriod.value=chngPeriod;
	}
	//
	if(txCollectionPeriod<'05')
	{
     document.insertForm.txBalanceDue.value = amountDue;
	 txSheriffsFee = '0.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else {txChangeBalDue='0.00';document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 //
	 switch(txCollectionPeriod)
	 {
	  case '01':
	  document.insertForm.txAmountDue.value = txAmount1;
	  document.insertForm.txBalanceDue.value = txAmount1;
	  document.insertForm.OrgAmountDue.value = txAmount1;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount1;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount1);
	  break;
	  case '02':
	  document.insertForm.txAmountDue.value = txAmount2;
	  document.insertForm.txBalanceDue.value = txAmount2;
  	  document.insertForm.OrgAmountDue.value = txAmount2;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount2;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount2);
	  break;
	  case '03':
	  document.insertForm.txAmountDue.value = txAmount3;
	  document.insertForm.txBalanceDue.value = txAmount3;
  	  document.insertForm.OrgAmountDue.value = txAmount3;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount3;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  case '04':
	  document.insertForm.txAmountDue.value = txRealFirstPenalty2PeriodAmt;
	  document.insertForm.txBalanceDue.value = txRealFirstPenalty2PeriodAmt;
  	  document.insertForm.OrgAmountDue.value = txRealFirstPenalty2PeriodAmt;
   	  document.insertForm.txAmountDueWithNoSheriffFee.value = txRealFirstPenalty2PeriodAmt;//20040726 - azlara - bug 3034
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  default:break;
	 }
	 document.insertForm.txCheckAmt.value= strZero;
	 document.insertForm.txCashAmt.value = strZero;
	 document.insertForm.txTotalRecd.value=intZero;
	 document.insertForm.txChangeBalDue.value = strZero;
	}
	//-----
   }
  }
  document.insertForm.OrgTxSheriffsFee.value = txSheriffsFee;//bug 2871
 }
 else //tax year<2004
 {
  if(paymentPeriod && txCollectionPeriod)
  {
   if(paymentPeriod!=txCollectionPeriod) 
   {
    if(flgShowAlertComments==1) alert('Payment Period changed, please enter comment');
    document.insertForm.txComment.focus();
    chngPeriod='OK';
    document.insertForm.chngPeriod.value=chngPeriod;
	if(txCollectionPeriod<'04')
	{
     document.insertForm.txBalanceDue.value = amountDue;
	 txSheriffsFee = '0.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);//20041101-azlara-redondear amt due
	 txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);
  	 document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else 
	 {
	  txChangeBalDue='0.00';
	  document.insertForm.txChangeBalDue.value= txChangeBalDue;
	  document.insertForm.txBalanceDue.value = txBalanceDue;
	 }
	 //
	 switch(txCollectionPeriod)
	 {
	  case '01':
	  document.insertForm.txAmountDue.value = txAmount1;
	  document.insertForm.txBalanceDue.value = txAmount1;
	  document.insertForm.OrgAmountDue.value = txAmount1;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount1;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount1);
	  break;
	  case '02':
	  document.insertForm.txAmountDue.value = txAmount2;
	  document.insertForm.txBalanceDue.value = txAmount2;
	  document.insertForm.OrgAmountDue.value = txAmount2;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount2;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount2);
	  break;
	  case '03':
	  document.insertForm.txAmountDue.value = txAmount3;
	  document.insertForm.txBalanceDue.value = txAmount3;
	  document.insertForm.OrgAmountDue.value = txAmount3;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount3;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  default:break;
	 }
	 document.insertForm.txCheckAmt.value= strZero;
	 document.insertForm.txCashAmt.value = strZero;
	 document.insertForm.txTotalRecd.value=intZero;
	 document.insertForm.txChangeBalDue.value = strZero;
	}
	else
	{
	 amountDue = PaidBeforeSale;
	 document.insertForm.OrgAmountDue.value = amountDue;
	 //window.alert('1-amountDue:'+amountDue);
	 //txSheriffsFee = 8;
	 txSheriffsFee = eval(ORG_RC_ADVERTISE_FEE) + eval(ORG_RC_SHERIFFS_FEE);
	 txBalanceDue = eval(amountDue);//+eval(txSheriffsFee);//bug 2871
	 document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	 //txSheriffsFee = '8.00';
	 txSheriffsFee = format_number(txSheriffsFee,2);
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 document.insertForm.txAmountDue.value = amountDue;
	 txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);//20041101-azlara-redondear amt due
	 txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);
  	 document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
  	 document.insertForm.txShffFee.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	 document.insertForm.txAdvFee.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
  	 document.insertForm.txSheriffFeeByPeriod.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	 document.insertForm.txAdvFeeByPeriod.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else 
	 {
	  txChangeBalDue='0.00';
	  document.insertForm.txChangeBalDue.value= txChangeBalDue;
	  document.insertForm.txBalanceDue.value = txBalanceDue;
	 }
	}
    document.insertForm.OrgTxSheriffsFee.value = txSheriffsFee;//bug 2871
   }//
   else if((txCollectionPeriod=='04') && (paymentPeriod==txCollectionPeriod))
   {
    amountDue = PaidBeforeSale;
	document.insertForm.OrgAmountDue.value = amountDue;
	//txSheriffsFee = 8;
	txSheriffsFee = eval(ORG_RC_ADVERTISE_FEE) + eval(ORG_RC_SHERIFFS_FEE);
	txBalanceDue = eval(amountDue);//+eval(txSheriffsFee);//bug 2871
	document.insertForm.txBalanceDue.value = eval(txBalanceDue);
	//txSheriffsFee = '8.00';
	txSheriffsFee = format_number(txSheriffsFee,2);
	document.insertForm.txSheriffsFee.value= txSheriffsFee;
	document.insertForm.txAmountDue.value = amountDue;
	txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);//20041101-azlara-redondear amt due
	txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);
	document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
	document.insertForm.txShffFee.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	document.insertForm.txAdvFee.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
  	document.insertForm.txSheriffFeeByPeriod.value= format_number(ORG_RC_SHERIFFS_FEE,2);//20070727-azlara-bug3043
 	document.insertForm.txAdvFeeByPeriod.value= format_number(ORG_RC_ADVERTISE_FEE,2);//20070727-azlara-bug3043
	txChangeBalDue = txTotalRecd - txBalanceDue;
	//window.alert('2-amountDue:'+amountDue+'| txTotalRecd:'+txTotalRecd+' |txBalanceDue: '+txBalanceDue+' | txChangeBalDue:'+txChangeBalDue);
	if(txChangeBalDue>0) 
	{
	 document.insertForm.txChangeBalDue.value= txChangeBalDue;
	 //window.alert('2a)txChangeBalDue:'+txChangeBalDue);
	}
	else 
	{
	 txChangeBalDue='0.00';
	 document.insertForm.txChangeBalDue.value= txChangeBalDue;
	 document.insertForm.txBalanceDue.value = txBalanceDue;
	 //window.alert('2b)txBalanceDue:'+txBalanceDue);
	}
    chngPeriod='';document.insertForm.chngPeriod.value=chngPeriod;
   }
   else 
   {
    chngPeriod='';
	document.insertForm.chngPeriod.value=chngPeriod;
	//20041025-azlara-bug 3156
	if(paymentPeriod!=txCollectionPeriod)
	{
     if(flgShowAlertComments==1) alert('Payment Period changed, please enter comment');
     document.insertForm.txComment.focus();
     chngPeriod='OK';
     document.insertForm.chngPeriod.value=chngPeriod;
	}
	if(txCollectionPeriod<'04')
	{
     document.insertForm.txBalanceDue.value = amountDue;
	 txSheriffsFee = '0.00';
	 document.insertForm.txSheriffsFee.value= txSheriffsFee;
	 txAmountDueWithNoSheriffFee = eval(amountDue-txSheriffsFee);//20041101-azlara-redondear amt due
	 txAmountDueWithNoSheriffFee = format_number(txAmountDueWithNoSheriffFee,2);
  	 document.insertForm.txAmountDueWithNoSheriffFee.value = txAmountDueWithNoSheriffFee;//eval(amountDue-txSheriffsFee);//20040726 - azlara - bug 3034
	 txChangeBalDue = txTotalRecd - txBalanceDue;
	 if(txChangeBalDue>0) {document.insertForm.txChangeBalDue.value= txChangeBalDue;}
	 else 
	 {
	  txChangeBalDue='0.00';
	  document.insertForm.txChangeBalDue.value= txChangeBalDue;
	  document.insertForm.txBalanceDue.value = txBalanceDue;
	 }
	 //
	 switch(txCollectionPeriod)
	 {
	  case '01':
	  document.insertForm.txAmountDue.value = txAmount1;
	  document.insertForm.txBalanceDue.value = txAmount1;
	  document.insertForm.OrgAmountDue.value = txAmount1;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount1;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount1);
	  break;
	  case '02':
	  document.insertForm.txAmountDue.value = txAmount2;
	  document.insertForm.txBalanceDue.value = txAmount2;
	  document.insertForm.OrgAmountDue.value = txAmount2;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount2;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount2);
	  break;
	  case '03':
	  document.insertForm.txAmountDue.value = txAmount3;
	  document.insertForm.txBalanceDue.value = txAmount3;
	  document.insertForm.OrgAmountDue.value = txAmount3;
      document.insertForm.txAmountDueWithNoSheriffFee.value = txAmount3;//20040726 - azlara - bug 3034	  
	  //txChangeBalDueStart = eval(0-txAmount3);
	  break;
	  default:break;
	 }
	 document.insertForm.txCheckAmt.value= strZero;
	 document.insertForm.txCashAmt.value = strZero;
	 document.insertForm.txTotalRecd.value=intZero;
	 document.insertForm.txChangeBalDue.value = strZero;
	}
	//--------
   }
   document.insertForm.OrgTxSheriffsFee.value = txSheriffsFee;//bug 2871
  }
 }
 }
 
 //20050121-azlara-bug 3524
 function CalcAmtDueAdjustOldDelqBill()
 {
  var REAL_SHERIFFS_FEES= parent.main.insertForm.DELQ_BILL_SHERIFF_FEE.value;
  REAL_SHERIFFS_FEES = money_to_numeric(REAL_SHERIFFS_FEES, 1);
  REAL_SHERIFFS_FEES = eval(REAL_SHERIFFS_FEES);
  if(isNaN(REAL_SHERIFFS_FEES))
  {
   window.alert('Invalid entry, try again');
   REAL_SHERIFFS_FEES=0;
   parent.main.insertForm.DELQ_BILL_SHERIFF_FEE.value = '0.00';
  }

  var REAL_ADVERTISING_FEES= parent.main.insertForm.DELQ_BILL_ADVERTISING_FEE.value;
  REAL_ADVERTISING_FEES = money_to_numeric(REAL_ADVERTISING_FEES, 1);
  REAL_ADVERTISING_FEES = eval(REAL_ADVERTISING_FEES);
  if(isNaN(REAL_ADVERTISING_FEES))
  {
   window.alert('Invalid entry, try again');
   REAL_ADVERTISING_FEES=0;
   parent.main.insertForm.DELQ_BILL_ADVERTISING_FEE.value = '0.00';
  }

  var REAL_DISTRAINT_FEE= parent.main.insertForm.DELQ_BILL_DISTRAINT.value;
  REAL_DISTRAINT_FEE = money_to_numeric(REAL_DISTRAINT_FEE, 1);
  REAL_DISTRAINT_FEE = eval(REAL_DISTRAINT_FEE);
  if(isNaN(REAL_DISTRAINT_FEE))
  {
   window.alert('Invalid entry, try again');
   REAL_DISTRAINT_FEE=0;
   parent.main.insertForm.DELQ_BILL_DISTRAINT.value = '0.00';
  }
  
  var REAL_ATTORNEY_FEE= parent.main.insertForm.DELQ_BILL_ATTORNEY_FEE.value;
  REAL_ATTORNEY_FEE = money_to_numeric(REAL_ATTORNEY_FEE, 1);
  REAL_ATTORNEY_FEE = eval(REAL_ATTORNEY_FEE);
  if(isNaN(REAL_ATTORNEY_FEE))
  {
   window.alert('Invalid entry, try again');
   REAL_ATTORNEY_FEE=0;
   parent.main.insertForm.DELQ_BILL_ATTORNEY_FEE.value = '0.00';
  }

  var REAL_SRV_NTC_AMT= parent.main.insertForm.DELQ_BILL_SERV_NOTICE.value;
  REAL_SRV_NTC_AMT = money_to_numeric(REAL_SRV_NTC_AMT, 1);
  REAL_SRV_NTC_AMT = eval(REAL_SRV_NTC_AMT);
  if(isNaN(REAL_SRV_NTC_AMT))
  {
   window.alert('Invalid entry, try again');
   REAL_SRV_NTC_AMT=0;
   parent.main.insertForm.DELQ_BILL_SERV_NOTICE.value = '0.00';
  }

  var REAL_CLERKS_FEE= parent.main.insertForm.DELQ_BILL_CLERK_FEE.value;
  REAL_CLERKS_FEE = money_to_numeric(REAL_CLERKS_FEE, 1);
  REAL_CLERKS_FEE = eval(REAL_CLERKS_FEE);
  if(isNaN(REAL_CLERKS_FEE))
  {
   window.alert('Invalid entry, try again');
   REAL_CLERKS_FEE=0;
   parent.main.insertForm.DELQ_BILL_CLERK_FEE.value = '0.00';
  }

  var REAL_PENALTY_AMOUNT_2= parent.main.insertForm.DELQ_BILL_PENALTY_10.value;
  REAL_PENALTY_AMOUNT_2 = money_to_numeric(REAL_PENALTY_AMOUNT_2, 1);
  REAL_PENALTY_AMOUNT_2 = eval(REAL_PENALTY_AMOUNT_2);
  if(isNaN(REAL_PENALTY_AMOUNT_2))
  {
   window.alert('Invalid entry, try again');
   REAL_PENALTY_AMOUNT_2=0;
   parent.main.insertForm.DELQ_BILL_PENALTY_10.value = '0.00';
  }

  var REAL_INTEREST_AMT= parent.main.insertForm.DELQ_BILL_INTEREST.value;
  REAL_INTEREST_AMT = money_to_numeric(REAL_INTEREST_AMT, 1);
  REAL_INTEREST_AMT = eval(REAL_INTEREST_AMT);
  if(isNaN(REAL_INTEREST_AMT))
  {
   window.alert('Invalid entry, try again');
   REAL_INTEREST_AMT=0;
   parent.main.insertForm.DELQ_BILL_INTEREST.value = '0.00';
  }

  var REAL_AMOUNT = parent.main.insertForm.DELQ_BILL_FACE_AMOUNT.value;
  REAL_AMOUNT = money_to_numeric(REAL_AMOUNT, 1);
  REAL_AMOUNT = eval(REAL_AMOUNT);
  if(isNaN(REAL_AMOUNT))
  {
   window.alert('Invalid entry, try again');
   REAL_AMOUNT=0;
   parent.main.insertForm.DELQ_BILL_FACE_AMOUNT.value = '0.00';
  }

  var billAmount;
//
  billAmount = eval(REAL_AMOUNT+REAL_SHERIFFS_FEES+REAL_ADVERTISING_FEES+REAL_DISTRAINT_FEE+REAL_ATTORNEY_FEE+REAL_SRV_NTC_AMT+REAL_CLERKS_FEE+REAL_PENALTY_AMOUNT_2+REAL_INTEREST_AMT);
  //alert('billAmount = ' + billAmount);
  billAmount = format_number(billAmount,2);
  parent.main.insertForm.txAmountDue2.value = billAmount;//eval(billAmount);
 }
 
 function CalcFaceBillAmount(Type)
 {
  var txTaxYr = document.insertForm.txTaxYr.value;
  var txBillNo = document.insertForm.txBillNo.value;
  //Face Amount
  var REAL_STATE_TAX= document.insertForm.REAL_STATE_TAX.value;
  REAL_STATE_TAX = money_to_numeric(REAL_STATE_TAX, 1);
  REAL_STATE_TAX = eval(REAL_STATE_TAX);

  var REAL_COUNTY_TAX = document.insertForm.REAL_COUNTY_TAX.value;
  REAL_COUNTY_TAX = money_to_numeric(REAL_COUNTY_TAX, 1);
  REAL_COUNTY_TAX = eval(REAL_COUNTY_TAX);

  var REAL_SCHOOL_TAX= document.insertForm.REAL_SCHOOL_TAX.value;
  REAL_SCHOOL_TAX = money_to_numeric(REAL_SCHOOL_TAX, 1);
  REAL_SCHOOL_TAX = eval(REAL_SCHOOL_TAX);

  var REAL_FIRE_TAX = document.insertForm.REAL_FIRE_TAX.value;
  REAL_FIRE_TAX = money_to_numeric(REAL_FIRE_TAX, 1);
  REAL_FIRE_TAX = eval(REAL_FIRE_TAX);

  var REAL_LIBRARY_TAX= document.insertForm.REAL_LIBRARY_TAX.value;
  REAL_LIBRARY_TAX = money_to_numeric(REAL_LIBRARY_TAX, 1);
  REAL_LIBRARY_TAX = eval(REAL_LIBRARY_TAX);

  var REAL_HEALTH_TAX= document.insertForm.REAL_HEALTH_TAX.value;
  REAL_HEALTH_TAX = money_to_numeric(REAL_HEALTH_TAX, 1);
  REAL_HEALTH_TAX = eval(REAL_HEALTH_TAX);

  var REAL_CNSRV_TAX= document.insertForm.REAL_CNSRV_TAX.value;
  REAL_CNSRV_TAX = money_to_numeric(REAL_CNSRV_TAX, 1);
  REAL_CNSRV_TAX = eval(REAL_CNSRV_TAX);

  var REAL_COOP_TAX= document.insertForm.REAL_COOP_TAX.value;
  REAL_COOP_TAX = money_to_numeric(REAL_COOP_TAX, 1);
  REAL_COOP_TAX = eval(REAL_COOP_TAX);

  var REAL_CH_TAX= document.insertForm.REAL_CH_TAX.value;
  REAL_CH_TAX = money_to_numeric(REAL_CH_TAX, 1);
  REAL_CH_TAX = eval(REAL_CH_TAX);

  //Bill Amount
  var REAL_SHERIFFS_FEES= document.insertForm.REAL_SHERIFFS_FEES.value;
  REAL_SHERIFFS_FEES = money_to_numeric(REAL_SHERIFFS_FEES, 1);
  REAL_SHERIFFS_FEES = eval(REAL_SHERIFFS_FEES);

  var REAL_ADVERTISING_FEES= document.insertForm.REAL_ADVERTISING_FEES.value;
  REAL_ADVERTISING_FEES = money_to_numeric(REAL_ADVERTISING_FEES, 1);
  REAL_ADVERTISING_FEES = eval(REAL_ADVERTISING_FEES);

  var REAL_DISTRAINT_FEE= document.insertForm.REAL_DISTRAINT_FEE.value;
  REAL_DISTRAINT_FEE = money_to_numeric(REAL_DISTRAINT_FEE, 1);
  REAL_DISTRAINT_FEE = eval(REAL_DISTRAINT_FEE);

  var REAL_ATTORNEY_FEE= document.insertForm.REAL_ATTORNEY_FEE.value;
  REAL_ATTORNEY_FEE = money_to_numeric(REAL_ATTORNEY_FEE, 1);
  REAL_ATTORNEY_FEE = eval(REAL_ATTORNEY_FEE);

  var REAL_SRV_NTC_AMT= document.insertForm.REAL_SRV_NTC_AMT.value;
  REAL_SRV_NTC_AMT = money_to_numeric(REAL_SRV_NTC_AMT, 1);
  REAL_SRV_NTC_AMT = eval(REAL_SRV_NTC_AMT);

  var REAL_CLERKS_FEE= document.insertForm.REAL_CLERKS_FEE.value;
  REAL_CLERKS_FEE = money_to_numeric(REAL_CLERKS_FEE, 1);
  REAL_CLERKS_FEE = eval(REAL_CLERKS_FEE);

  var REAL_PENALTY_AMOUNT_2= document.insertForm.REAL_PENALTY_AMOUNT_2.value;
  REAL_PENALTY_AMOUNT_2 = money_to_numeric(REAL_PENALTY_AMOUNT_2, 1);
  REAL_PENALTY_AMOUNT_2 = eval(REAL_PENALTY_AMOUNT_2);

  var REAL_INTEREST_AMT= document.insertForm.REAL_INTEREST_AMT.value;
  REAL_INTEREST_AMT = money_to_numeric(REAL_INTEREST_AMT, 1);
  REAL_INTEREST_AMT = eval(REAL_INTEREST_AMT);

  var REAL_AMOUNT = document.insertForm.REAL_AMOUNT.value;
  REAL_AMOUNT = money_to_numeric(REAL_AMOUNT, 1);
  REAL_AMOUNT = eval(REAL_AMOUNT);
  //
  var billAmount, REAL_AMOUNT1;
  //
  //operations
  //if(txTaxYr && txBillNo)
  //{
   switch(Type)
   {
    case 0: //Face Amount
		REAL_AMOUNT1 = eval(REAL_STATE_TAX+REAL_COUNTY_TAX+REAL_SCHOOL_TAX+REAL_LIBRARY_TAX+REAL_FIRE_TAX+REAL_HEALTH_TAX+REAL_CNSRV_TAX+REAL_COOP_TAX+REAL_CH_TAX);
		//REAL_AMOUNT = formatCurrency(REAL_AMOUNT);
		//alert('face amount = '+REAL_AMOUNT);
		document.insertForm.REAL_AMOUNT.value = eval(REAL_AMOUNT1);
	    break;
	case 1: //Bill Amount
		//REAL_AMOUNT+
		billAmount = eval(REAL_AMOUNT+REAL_SHERIFFS_FEES+REAL_ADVERTISING_FEES+REAL_DISTRAINT_FEE+REAL_ATTORNEY_FEE+REAL_SRV_NTC_AMT+REAL_CLERKS_FEE+REAL_PENALTY_AMOUNT_2+REAL_INTEREST_AMT);
		//alert('billAmount = ' + billAmount);
		billAmount = format_number(billAmount,2);
		document.insertForm.billAmount.value = eval(billAmount);
	    break;
	default: break;
   }
  //}
 }
 
 function CalcDelqAmountDue()
 {
  var DELQ_BILL_FACE_AMOUNT= eval(document.insertForm.DELQ_BILL_FACE_AMOUNT.value);
  var DELQ_BILL_PENALTY_10 = eval(document.insertForm.DELQ_BILL_PENALTY_10.value);
  var DELQ_BILL_INTEREST= eval(document.insertForm.DELQ_BILL_INTEREST.value);
  var DELQ_BILL_SHERIFF_FEE = eval(document.insertForm.DELQ_BILL_SHERIFF_FEE.value);
  var DELQ_BILL_ADVERTISING_FEE= eval(document.insertForm.DELQ_BILL_ADVERTISING_FEE.value);
  var DELQ_BILL_DISTRAINT= eval(document.insertForm.DELQ_BILL_DISTRAINT.value);
  var DELQ_BILL_CLERK_FEE= eval(document.insertForm.DELQ_BILL_CLERK_FEE.value);
  var DELQ_BILL_SERV_NOTICE= eval(document.insertForm.DELQ_BILL_SERV_NOTICE.value);
  var DELQ_BILL_ATTORNEY_FEE= eval(document.insertForm.DELQ_BILL_ATTORNEY_FEE.value);
  var txAmountDue;
  
  txAmountDue = eval(DELQ_BILL_FACE_AMOUNT+DELQ_BILL_PENALTY_10+DELQ_BILL_INTEREST+DELQ_BILL_SHERIFF_FEE+DELQ_BILL_ADVERTISING_FEE+DELQ_BILL_DISTRAINT+DELQ_BILL_CLERK_FEE+DELQ_BILL_SERV_NOTICE+DELQ_BILL_ATTORNEY_FEE);
  document.insertForm.txAmountDue.value = eval(txAmountDue);
 }
 
 function markAll(f,chkName)
 {
  var strLength=0;
  var nameChk='';
  for(i=0;i<f.elements.length;i++)
  {
   if(f.elements[i].type=='checkbox')
   {
    if(chkName)
	{
	 strLength = chkName.length;
     nameChk = f.elements[i].name;
	 if(nameChk.substring(0,strLength)==chkName)
	 { if(!f.elements[i].checked) f.elements[i].click(); }
	}
	else { if(!f.elements[i].checked) f.elements[i].click(); }
   }
  }
 }

//please wait message functions 
 function xoopsGetElementById(id) {

if (document.getElementById(id)) {
	return document.getElementById(id);
	} else if (document.all[id]) {
		return document.all[id];
		} else if (document.layers && document.layers[id]) {
			return (document.layers[id]);
			} else {
				return fake_element;
			}
}
function toggle_visibility(id, flag)  {

if (xoopsGetElementById(id)) {
	xoopsGetElementById(id).style.visibility = (flag) ? 'visible' : 'hidden';
	}
}

function showWaitMessage(PrintDiv) {
    if(PrintDiv==1) { document.write("<div id='waitDiv' style='position:absolute; left:40%; top:50%; visibility:hidden; text-align:center;'><table cellpadding='3' cellspacing='3' class='waitbox'><tr><td align='center'><b><big>Loading...</big></b><br><img src='imgs/await.gif' alt='please wait..'><br>Please Wait.</td></tr></table></div>"); }
	toggle_visibility('waitDiv', 1);
}

function hideWaitMessage() { toggle_visibility('waitDiv', 0); }

 function countChecked(f)
 {
 var countChk=0;
 var chkName='';
 for(i=0;i<f.elements.length;i++)
  {
   if(f.elements[i].type=='checkbox')
    {
	 chkName = f.elements[i].name;
	 if((chkName.substring(0,5)=='strdt') || (chkName.substring(0,2)=='dt'))
	 { if(f.elements[i].checked) { countChk++; } }
    }
  }
 return countChk;
 }


function fncKeyStop() 
{
 if (window.event.ctrlKey) 
 {
  if (window.event.keyCode == 67 || window.event.keyCode == 86 || window.event.keyCode ==88) 
  { 
   //Do nothing if Contol x, c, v (copy functions)
  }
  else 
  {
   event.keyCode = 0;
   event.returnValue = false;
  }
 }
 //Cancel F5 and F11
 if (window.event.keyCode == 122 || window.event.keyCode == 116) 
 {
  window.event.keyCode = 0;
  event.returnValue = false;
 }
 if (window.event.altKey) 
 {
  //Cancel right arrow, left arror, and home key
  if (window.event.keyCode == 36 || window.event.keyCode == 39 || window.event.keyCode == 37) 
   {
   //For some reason putting the alert in cancels the keystroke
   alert('(c) TRACOMS 2004');
   window.event.keyCode = 0;
   event.returnValue = false;
  }
 }
}

//20051011-azlara-bug 3778
function sendTrnsct(DocType,RemoteIPAddr)//DocType: S=Single, M=Multiple
{
 var sessionId = document.insertForm.id.value;
 var formId= document.insertForm.f.value;
 var payType1 = document.insertForm.payType1.value;
 var PAmount1= eval(document.insertForm.payAmt1.value);
 var amtDue = eval(document.insertForm.amtDue.value);
 var cCard1 = document.insertForm.CC1.value;
 var docNumber='';
 switch(DocType)
 {
  case 'S'://Single document
  docNumber = document.insertForm.doctoNumber.value;
  break;
  case 'M'://Multi fee entry documents
  docNumber = document.insertForm.strNumDocuments.value;
  break;
  default:break;
 }
 if(payType1=='2')
 {
  if(isNaN(PAmount1)) { window.alert('Transaction can not be processed'); }
  else if(isNaN(amtDue)) { window.alert('Transaction can not be processed'); }
  else if(PAmount1>amtDue) { window.alert('No change can be returned if payment is made by Credit Card'); }
  else if(PAmount1<amtDue) { window.alert('Not enough money has been paid'); }
  else if(sessionId&&formId)
  {
   window.open('https://payments.verisign.com/payflowlink?LOGIN=Ts05MxQ72DnP953L7&PARTNER=VeriSign&AMOUNT='+amtDue+'&TYPE=S&CUSTID='+sessionId+'&ECHODATA=True&USER1='+formId+'&USER2='+RemoteIPAddr+'&CARDNUM='+cCard1+'&DESCRIPTION='+docNumber, 'TRACOMS_Online_Credit_Card_Transactions', 'width=500,height=500,scrollbars=yes,resizable=yes');
  }
  else window.alert('Transaction can not be processed, try again.');
 }
}
//

 var message="(c) TRACOMS 2005";
 ///////////////////////////////////
 function clickIE4()
 {
	if (event.button==2)
	{
		alert(message);
		return false;
	}
 }

 function clickNS4(e)
 {
	if(document.layers || document.getElementById && !document.all)
	{
		if(e.which == 2 || e.which == 3)
		{
			alert(message);
			return false;
		}
	}
 }

 //please wait message
 var fake_element; 
 
 function StatusMouseDown(flag)
 {
	if(flag)
	{
		if (document.layers)
		{
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown=clickNS4;
		}
		else if (document.all && !document.getElementById)
		{
			document.onmousedown = clickIE4;
		} 
		document.oncontextmenu = new Function("return false")
	} 
 }
  
 function changeBgColor(color,id) { document.getElementById(id).style.background=color; }

