// Declared Variables

var submtcnt = 0;
var action_focus = 1;



// Function Mouse Over
//
// Purpose is to set the mouse pointer and change color of menu item.
// 
// Parameters
//    Object Name, Color nbr.
//
// History:
// 07/15/99 initial development.

function mOvr(src,clrOver) { 
 if (!src.contains(event.fromElement)) { 
     src.style.cursor = 'hand'; 
     src.bgColor      = clrOver;
 }
}

// Function Mouse Out
//
// Purpose is to set the mouse pointer to default and change color of menu item to default.
// 
// Parameters
//    Object Name, Color nbr.
//
// History:
// 07/15/99 initial development.
 
function mOut(src,clrIn) { 
 if (!src.contains(event.toElement)) { 
     src.style.cursor = 'default';
     src.bgColor      = clrIn; 
 }
}

// Function Begin Date
// Checks the date format of the search begin date on FORM forms[1]. The function is 
// callled from the onblur event.
// Format: MM/DD/YYYY. 
//  
// History:
// 07/15/99 RJB initial development.
// 08/26/99 RJB removed begin and end date compare.
// 09/02/99 RJB default 0 for day and month format.

function begindate() {

 curdate    = new Date();
 var err    = 0;
 var valchr = "0123456789/";
 var tmp    = "";
 var i;

 dt = document.forms[0].elements["SRCH_BEGIN_DT.PROFILE.CRTV"].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) return true  // No Date entered

// Added Zeros Month and Day
 if (dt.substring(1, 2) == '/') dt = '0' + dt 
 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) {
   // Error message, set field focus
   msg  = 'PUBLIC ACCESS \n\n'
   msg += '_________________________________________________________ \n\n'
   msg += 'Search Begin Date is invalid. Format: MM/DD/YYYY \n'
   msg += '_________________________________________________________ \n\n'
   alert(msg);
   document.forms[0].elements["SRCH_BEGIN_DT.PROFILE.CRTV"].focus()
   return false
 }
   // Set field with format
  document.forms[0].elements["SRCH_BEGIN_DT.PROFILE.CRTV"].value = dt

  return true

}

// Function End Date
// Checks the date format of the search begin date on FORM forms[0]. The function is 
// callled from the onblur event.
// Format: MM/DD/YYYY. 
// 
// History:
// 07/15/99 RJB initial development.
// 08/26/99 RJB removed begin and end date compare.
// 09/02/99 RJB default 0 for day and month format.

function enddate() {

 curdate    = new Date();
 var err    = 0
 var valchr = "0123456789/";
 var tmp    = "";
 var i;

 dt = document.forms[0].elements["SRCH_END_DT.PROFILE.CRTV"].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) return true  // No Date entered

// Added Zeros Month and Day
 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) {
   // Error message, set field focus

   msg  = 'PUBLIC ACCESS \n\n'
   msg += '_________________________________________________________ \n\n'
   msg += 'Search End Date is invalid. Format: MM/DD/YYYY \n'
   msg += '_________________________________________________________ '
   alert (msg)
   document.forms[0].elements["SRCH_END_DT.PROFILE.CRTV"].focus()
   return false
 }
   // Set field with format
 document.forms[0].elements["SRCH_END_DT.PROFILE.CRTV"].value = dt

}

// 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:
// 07/15/99 initial development.
// 09/02/99 RJB default 0 for day and month format.

function datefmt(src,fldmsg) {

 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) return true  // No Date entered

// Added Zeros Month and Day
 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) {
   // Error message, set field focus
   msg  = 'PUBLIC ACCESS \n\n'
   msg += '_________________________________________________________ \n\n'
   msg += fldmsg + ' is invalid. Format: MM/DD/YYYY \n'
   msg += '_________________________________________________________ \n\n'
   alert(msg);

   src.focus()
   return false
 }
   // Set field with format
  src.value = dt

  return true
}

// Alert Message Display
//
// Purpose is to display the text in the alert msg hidden field.  This function is called
// from the onload event of the page.
//
// Parameters
//    N/A
//
// History:
// 08/06/99 initial development.
// 08/29/2002 SLH TPR 29604.  Changed title from "Alert/Warrant WARNING" to "ATTENTION"

function AlertMsg() { 

 var altmsg = "";

 altmsg = document.forms[0].elements["ALERT_MSG.PROFILE.CRTV"].value

 if (altmsg != "") {

   msg  = 'Public Access \n\n'
   msg += '_________________________________________________________ \n\n'
   msg += 'ATTENTION \n\n'
   msg += altmsg + '\n'
   msg += '_________________________________________________________ \n\n'

   alert(msg);

   // Displayed Clear the Thing....
   document.forms[0].elements["ALERT_MSG.PROFILE.CRTV"].value = ""
 }


}


// Init Search Page
//
// Purpose is to perform any initialization to the search page.  Currently
// this function just set the initial field focus.
// 
// Parameters
//    Start Field.
//
// History:
// 05/12/00 initial development.

 function initpage(intfld) { 
 
   // Set Field focus if passed and not hidden.
   if (intfld != "" && document.forms[0].elements[intfld].type != "hidden") {
      document.forms[0].elements[intfld].focus()
   }
   
   return true;
   
}

// Digital Signature Place Holder
//
// The purpose of this funcation is to display a place holder
// message for the digital signature..
//
// History
// 06/21/2000 RJB Prototype for EFiling..
function sign_msg() {

   var filmsg = "";
   var msg    = "";
   
   filmsg = document.forms[0].elements["FILE_PATH.EQUEUE.E_FILING"].value

   if (filmsg != "") {
      msg  = 'Public Access \n\n'
      msg += '_________________________________________________________ \n\n'
      msg += 'Applying Digital Signature to attached file. \n\n'
      msg +=  '\n' 
      msg +=  document.forms[0].elements["FILE_PATH.EQUEUE.E_FILING"].value
      msg +=  '\n'
      msg += '_________________________________________________________ \n\n'

      alert(msg);
    }

}



function crtv_submit() {


 alert("Submit Function...");
 
 document.forms[0].submit();

}

// Search Criteria Submission Check
//
// This function checks to see if the search criteria 
// has already been submitted and displays an error message. The 
// button text is also changed.
//
// SLH 01/15/2002
//
function search_subchk() {

// Change Message
document.forms[0].elements["SEARCH_BUTTON.PAPROFILE.PAM"].value = "Searching"; 

// Submitted Search Criteria
if (submtcnt > 0)  {
  return false;
}
   
// Up count   
 submtcnt++;

 return true;
 
 
}



// Trim leading spaces from field
//
//
// SLH 04/18/2002
//
function trim_leading(field) {
  
  while (field.value.substring(0,1) == " ") {
  
     field.value = field.value.substring(1);
  
  }
   

  return true;
 
 
}


// Capitalize String
//
//
// SLH 07/11/2002
//
function CapString(field) {
    
  field.value = field.value.toUpperCase();  
 
  return true;
 
 
}


//Capturing Enter from Netscape
//Function is called from onKeyPress
//Netscape works differently from IE
//with reference to capturing Key Strokes
//TPR 44356
function NNEnterKey(thisOne) 
{

  if (thisOne.which == 13) {
      document.forms[0].elements["SEARCH_BUTTON.PAPROFILE.PAM"].click();
  }
  return true;
}



//Evaluate Key Stroke Entered
//If user clicked on 'Enter', bring focus to the Search Button
//SLH TPR 25592  07/19/2002
function onKeyPress () {

  var KeyEntercode;

  //Internet Explorer
  if (window.event){
    KeyEntercode = window.event.keyCode;
  }
   
  if (KeyEntercode == 13) {
     document.forms[0].elements["SEARCH_BUTTON.PAPROFILE.PAM"].focus(); 
  }

  return true;
}

// Force click on REFRESH_BTN 
// 4-26-05  MEM  Tpr 70060.
//function clickIt(elementId) {
//
//   if ((elementId == "") || (elementId == null)) {
//      document.getElementById("REFRESH_BTN.PROFILE.CRTV").click();
//   } else {
//      document.getElementById(elementId).click();
//   }     
//   
//}

// Force click on REFRESH_BTN.  If checkflag = 1, then only click
//  on button if jdg_dropdown field is null.
// 4-26-05  MEM  Tpr 70060.
function clickIt(elementId,checkflag) {


   if (checkflag == "1") {
      // Only click button if jdg_dropdown is null.
     var jdgChoice = document.getElementById("JDG_DROPDOWN.PROFILE.CRTV").selectedIndex;
     var jdgValue = document.getElementById("JDG_DROPDOWN.PROFILE.CRTV").options[jdgChoice].value;

     if ((jdgValue == "") || (jdgValue == null)) {
       if ((elementId == "") || (elementId == null)) {
         document.getElementById("REFRESH_BTN.PROFILE.CRTV").click();
       } else {
          document.getElementById(elementId).click();
         }      
     }
   } else {
       if ((elementId == "") || (elementId == null)) {
         document.getElementById("REFRESH_BTN.PROFILE.CRTV").click();
       } else {
           document.getElementById(elementId).click();
         }     
     }
}


/*
  * This function converts the text value into all uppercase.
  * onblur="allUpcase(this)"
  *
  * History:
  * 07/7/2005 RJB Initial Development.
  *
  */
function allUpcase (src) {
   if ((src != null) && (src.value != null) && (src.value.length > 0)) {
       src.value = src.value.toUpperCase();
   }
}

