
//  E Filing 
//
// This file contains the Java Script Functions for Electronic Filing. The functions where created by
// 3GI-MAXIMUS on 08/2000
// 
// History:  
//  08/22/2000 RJB Inital Intergration to E Filing Prototype.
//  09/05/2000 CGH Replaced ref to PROVIDER_PASSAGE w/ literal CSP Name
//		   in getcertid()
//  08/15/2002 MBA Added the NoEdit function. Used for the E-filing Case
//                 Initiation process. TPR 24207.
//
function do_all()
{
    var res;

    res = Signer.SignFile( document.sign.file.value );
    var dres = Signer.GetLastErr();

//    alert('Sign Returned: ' + res + ' and error was ' + dres);

    res = Signer.GetCertID();
    var dres = Signer.GetLastErr();

//    alert('GetCertID Returned: ' + res + ' and error was ' + dres);

    document.sign.certid.value = res;

    Signer.CleanUp();

    return false;
}
function signfile()
{
    var res;

    res = Signer.SignFile( document.sign.file.value );
    var dres = Signer.GetLastErr();

    alert('Sign Returned: ' + res + ' and error was ' + dres);

    return false;

}
function getcertid()
{
    var res;

    //cgh @ 09/05/2000 - Replaced PROVIDER_PASSAGE w/ literal CSP Name
    res = Signer.GetCertID("Passage Enhanced Cryptographic Provider");
    var dres = Signer.GetLastErr();

    alert('GetCertID Returned: ' + res + ' and error was ' + dres);

    document.sign.certid.value = res;

    return false;
}
function cleanup()
{
    Signer.CleanUp();

    return false;
}

// CRTV Sign File
//
// The purpose of this funcation is sign the containted in 
// the signed file HTML field.  This is part of the efiling 
// prototype.
//
// History
//	08/22/2000 RJB Prototype for EFiling..
// 	09/05/2000 CGH Replaced ref to PROVIDER_PASSAGE w/ literal CSP Name
//	   	       in SignFile()
//	12/20/2000 CGH Replaced hardcoded CSP w/ parameter
//	06/22/2001 CGH Included check to ensure docket code on form before continuing
//	01/22/2002 CGH Included check for digital signature flag (tpr 27065)
function sign_crtv() {

   var docfil  = "";
   var msg     = "";
   var res;
   var csp     = "";
   var dkt_cd  = "";
   var dig_sig = "";

   docfil  = document.forms[0].elements["SIGNED_FILE_PATH.EFQUE.ECRTV"].value
   csp     = document.forms[0].elements["CSP.EFQUE.ECRTV"].value
   dkt_cd  = document.forms[0].elements["DKT_CD.EFQUE.ECRTV"].value  
   dig_sig = document.forms[0].elements["DIG_SIG.EFQUE.ECRTV"].value
     
   if (docfil != "" && dkt_cd != "" & dig_sig == "1") {
       
     //cgh @ 09/05/2000 - Replaced PROVIDER_PASSAGE w/ literal CSP Name
     //cgh @ 10/17/2000 - Included new parameter to control cert selection
     //cgh @ 12/20/2000 - Replaced hardcoded CSP w/ passed parameter
     res = Signer.SignFile( docfil, csp, 0);
     
     var dres = Signer.GetLastErr();

     // Check for errors
     if (dres != "0") {
        alert('Sign Returned: ' + res + ' and error was ' + dres);
        document.forms[0].elements["SIGN_ERROR.EFQUE.ECRTV"].value = "1";
        return false;
     }
     
     
     // Display Signed File Path
     msg  = 'Public Access Electronic Filing\n\n'
     msg += '_________________________________________________________ \n\n'
     msg += 'Digitally Signed File. \n\n'
     msg +=  '\n' 
     msg +=  res
     msg +=  '\n'
     msg += '_________________________________________________________ \n\n'

     alert(msg);

     // Display Signed File
     //document.forms[0].elements["SIGNED_FILE.EQUEUE.E_FILING"].value = res

     document.forms[0].elements["SIGN_ERROR.EFQUE.ECRTV"].value = "0";
     
     
     // Submit Form 
     document.forms[0].submit();
     
     // Restore original file
     //Signer.CleanUpFile(docfil);
     
     return true;
     
     
    }
    
    
}

// Get Certificate Information
//
// This function retrieves identification information from the
// certificate. 
//
// Currently this function just displays the public key information onto
// the HTML form.
//
// History
// 	08/24/2000 RJB Initial Prototyp.
//  	09/05/2000 CGH Replaced ref to PROVIDER_PASSAGE w/ literal CSP Name
//	 	       in GetCertID()
//	12/20/2000 CGH Replaced hardcoded CSP w/ passed parameter
//
function cert_info_crtv() {
    
    
    var res;   
    var attid;
    var csp    = "";
 
    emid = document.forms[0].elements["EMAIL_ID.PROFILE.CRTV"].value 
    csp  = document.forms[0].elements["CSP.PROFILE.CRTV"].value

        
    // Already Set Get Out..
    if (emid != "") return false;
    
      
    //cgh @ 09/05/2000 - Replaced PROVIDER_PASSAGE w/ literal CSP Name
    //res = Signer.GetCertID("Passage Enhanced Cryptographic Provider");
    res = Signer.GetCertID(csp);    
    var dres = Signer.GetLastErr();

     // Check for errors
     if (dres != "0") {

        alert('GetCertID Returned: ' + res + ' and error was ' + dres);
        return false;
     }

    // Map Atty ID information to display fields
    attid = res.split(",");

    document.forms[0].elements["CARD_ID.PROFILE.CRTV"].value = attid[0];
    document.forms[0].elements["EMAIL_ID.PROFILE.CRTV"].value = attid[1];
    
    return true;

}


// CRTV Cleanup File
//
// The purpose of this function is to clean up the recently signed file
// Cleanup removes the signed file and renames the original file (*_orig)
// to its original name
//
// History
//	01/02/2001 CGH Original
//	01/22/2002 CGH Modified to only execute cleanup if docfil contains value
//		       to support signature and non-signature e-filings (tpr 27065)
function sign_cleanup_crtv() {
   var dres;
   var docfil = "";

   docfil = document.forms[0].elements["FILE_PATH.PROFILE.CRTV"].value;
   //alert(docfil);
   
   if (docfil != "") 
   {
      Signer.CleanUpFile(docfil);
      dres = Signer.GetLastErr();
   }
}

// Format SSN
//
// This function checks the format of the SSN number entered. This to 
// verify that a valid ssn is entered for searching and case init.
//
//  Parameters
//    Object Pointer for ssn.
//
//  History
//    01/29/2002 SLH Mostly copied from ep.js

function CheckSSN(src, DisFld) {

ssn = src.value;  // Value of SSN

if (ssn.length < 1) {
    if(DisFld != ""){
       document.forms[0].elements[DisFld].src = "../images/messages/blankimage.gif";}
    return false;
}

var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
var numDashes = ssn.split('-').length - 1;

  if (matchArr == null || numDashes == 1) {
     if(DisFld == ""){
        msg  = 'E Filing \n\n'
        msg += '_________________________________________________________ \n\n'
        msg += ' SSN is Invalid. Must be 9 digits format: NNN-NN-NNNN.    \n'
        msg += '_________________________________________________________ \n\n'
        alert(msg);
     }
     else{
        document.forms[0].elements[DisFld].src = "../images/messages/InvSSN.gif";
     }     
     src.focus();
     return false;
  }
  else{
    if(DisFld != "")
       document.forms[0].elements[DisFld].src = "../images/messages/blankimage.gif";
  }
  

  if (parseInt(matchArr[1],10)==0) {
       if(DisFld == ""){
        msg  = 'E Filing \n\n'
        msg += '_________________________________________________________ \n\n'
        msg += ' SSN is Invalid. Can not start with 000.                  \n'
        msg += '_________________________________________________________ \n\n'
        alert(msg);
     }
     else{
        document.forms[0].elements[DisFld].src = "../images/messages/InvSSNZero.gif";
     }
     src.focus()
     return false;   
  }
  else{
    if(DisFld != "")
         document.forms[0].elements[DisFld].src = "../images/messages/blankimage.gif";
  }
  
 // Format SSN Number Entered.
 if (ssn.substring(3, 4) != '-') {
    ssn = ssn.substring(0, 3) + '-' + ssn.substring(3, 12)
 }

 if (ssn.substring(6,7) != '-') {
   ssn = ssn.substring(0, 6) + '-' + ssn.substring(6, 12)
 }

 // Format Number
 src.value = ssn;

 return true;    
  
}


// Date Format 
// Checks the date of the date object passed.
// callled from the onblur event.
// Format: MM/DD/YYYY. 
//  
// Parameter 
//    object name, display name
//
// History:
// 01/29/02 Mostly copied from ep.js


function datefmt(src, fldmsg, DisFld) {
 curdate    = new Date();
 var err    = 0
 var valchr = "0123456789/";
 var tmp    = "";
 var i;

 dt = src.value  // Get Date value

 // Check for valid characters Numeric or forward slash
 for (i=0; i < dt.length; i++) {
     tmp = "" + dt.substring(i, i+1);
     if (valchr.indexOf(tmp) == "-1") err = 1;
 }

 if (dt.length < 1){
   if (DisFld != "")
    document.forms[0].elements[DisFld].src = "../images/messages/blankimage.gif";
   return true  // No Date entered
}

// Added Zeros Month and Day
 if (dt.substring(2, 3) != '/')  {
   if (dt.substring(1, 2) == '/') dt = '0' + dt  // Add zero to month
   if ((dt.length == 5) || (dt.length == 3)) dt = '0' + dt  // Add zero to month
 }
 
 if (dt.substring(4, 5) == '/') {
    dt = dt.substring(0,3) + '0' + dt.substring(3,10)  // Add zero to day
 }

 if (dt.length < 4) err=1

 if (dt.substring(2, 3) != '/') {
   dt = dt.substring(0, 2) + '/' + dt.substring(2, 10)
 }

 if (dt.substring(5,6) != '/') {
   dt = dt.substring(0, 5) + '/' + dt.substring(5, 10)
 }

 // Default year and or Century
 fyy = curdate.getFullYear();
 // Year and Century
 if (dt.length == 6) {
    dt = dt + fyy.toString();
 } 
 // Century
 if (dt.length == 8) {
    cen = fyy.toString(); 
    cen = cen.substring(0, 2)
    dt  = dt.substring(0, 6) + cen + dt.substring(6, 8)
 }

 // must be 10 now..
 if (dt.length != 10) err=1

 mm  = dt.substring(0, 2) // month
 dd  = dt.substring(3, 5) // day
 cc  = dt.substring(6, 8) // Century
 yy  = dt.substring(8, 10) // year

 if (mm.length == 1) mm = '0' + mm
 if (dd.length == 1) dd = '0' + dd

 if (mm < 1 || mm > 12) err = 1

 if (dd < 1 || dd > 31) err = 1

 if (yy < 0 || yy > 99) err = 1

 if (mm == 4 || mm == 6 || mm == 9 || mm == 11){
   if (dd == 31) err=1
 }

 if (mm == 2){
   var g=parseInt(yy / 4)
   if (isNaN(g)) {
     err=1
   }
   if (dd > 29) err=1
   if (dd == 29 && ((yy / 4)!=parseInt(yy / 4))) err=1
 }

 if (err==1) {
    if (DisFld == ""){
     // Error message, set field focus
     msg  = 'E Filing \n\n'
     msg += '_________________________________________________________ \n\n'
     msg += fldmsg + ' is invalid. Format: MM/DD/YYYY \n'
     msg += '_________________________________________________________ \n\n'
     alert(msg);
   }
   else
     document.forms[0].elements[DisFld].src = "../images/messages/InvDate.gif";
   src.focus();
   return false;
 }
 else{
   if (DisFld != "")
     document.forms[0].elements[DisFld].src = "../images/messages/blankimage.gif";
 } 
 
 
 // Set field with format
  src.value = dt

  return true
}

// Change a Button's Text Value
//
// SLH 02/14/2002
//
//  
function button_text(BtnFld, Text) {
 if (document.forms[0].elements["MODE.DUMMY.ECRTV"].value != "") {
     // Change Message 
    document.forms[0].elements[BtnFld].value = Text;
    
    //document.forms[0].elements["PARTIES_BTN.PROFILE.CRTV"].type = "hidden";
    
    
 }
  return;
   
   
}

// Display No-Edit message. Applicable for "autodkts", and also during the case
// Initiation process in E-Filing.
//
// 08/15/2002 MBA TPR 24207
//
//  
// Display No-Edit message. Applicable for dockets added on Docket Entry when 
// SUPPRESS_DATE_EDIT syspar is setup and flagged in CourtView.
//
// 01/26/2006  WCS  TPR 86738
//
function NoEdit(src, fldmsg, DisFld)  {

   if (fldmsg == "Filed Date" || fldmsg == "Docket Entry")
   {

      // Used in the Docket Page (EFLW7133)
      if ((document.forms[0].elements["AUTODKT_FLG.DOCKETS.ECRTV"].value != "") ||
          ((fldmsg == "Filed Date") && 
           (document.forms[0].elements["SUPPRESS_DATE_EDIT.DOCKETS.ECRTV"].value != "")))
      {
         msg  = 'E Filing \n\n'
         msg += '__________________________________ \n\n'
         msg += fldmsg + ' is a view-only field.\n'
         msg += '__________________________________ \n\n'
         alert(msg); 
         src.value = document.forms[0].elements[DisFld].value
      }
      
      if ((fldmsg == "Docket Entry") && 
          (document.forms[0].elements["SUPPRESS_DATE_EDIT.DOCKETS.ECRTV"].value != "")) {
           
           curDate = new Date();
					 curYear = curDate.getFullYear();
					 curMonth = curDate.getMonth()+1;
					 curDay= curDate.getDate();
					 today = curMonth+"/"+curDay+"/"+curYear;
           document.forms[0].elements["DATE.DOCKETS.ECRTV"].value = today;
           document.forms[0].elements["DKT_DT.DUMMY.ECRTV"].value = today;
      }
   }   
   
   else
   {
      // Used in the Case Init Page (EFLW0051)
      if (document.forms[0].elements[DisFld].value == "" && src.value != "")
      {
         msg  = 'E Filing \n\n'
         msg += '__________________________________ \n\n'
         msg += fldmsg + ' is a view-only field.\n'
         msg += '__________________________________ \n\n'
         alert(msg); 
         src.value = ""
      }
   
   }
   
   
   return;
   
}

function verifyImagEnabled() {
  //WCS  TPR86746  2/28/2006
  //If the IMG_DKTS_ONLY syspar was setup then IMG_DKTS_ONLY.DUMMY will be set to 1.
  //This is to determine if the Submit Document field and Browse button
  //will be available when a Docket Entry is selected on EFLW7133.
	if (document.forms[0].elements["IMG_DKTS_ONLY.DUMMY.ECRTV"].value == "1") {
     clickIt();	
	}
}
