/******************************************************************************
* Filename    : JS_FUNCS.JS
* Filelocation: \hnaweb\
* Author      :  
* Created     :  
* Description :

* Progmmr Note:  THIS WAS "HelpScript.inc, but now includes all .js funcs
*
*            CH3.a TMA        04/02/2003 04/02/2003  ADDED Poorman douglas item
******************************************************************************/

function helpWindow(helppage)
{
  HelpWin = window.open('help/'+helppage, 'bookwin', 'width=700,height=400,scrollbars=yes')
  HelpWin.focus()
}

function focusfld(gofld)
//var gofld
{
gofld.focus()
}

function jscheckdate(obj)
{

  //if (arguments[0].value.substring(2,3) == '.') { arguments[0].value.substring(2,3)= "/" }
  //if (arguments[0].value.substring(5,6) == '.') { arguments[0].value.substring(5,6)= "/" }

  var eightdig = /^\d{8}$/
  var obj;

  fldobj=arguments[0];

  fldobj.value = stripCharString(fldobj.value," ");

  if(fldobj.value.length == 0) { 
  return true }


  fldobj.value = fldobj.value.replace(".","/") 
  fldobj.value = fldobj.value.replace(".","/") 

  var err = 0
  var datestring = ""
  var msg = "Invalid Date Format "

 // var withslashes= /^\d{1,2}\/{1}\d{1,2}\/{1}+\d{4}$/
 // alert(withslashes.test(fldobj.value)) 

  if (eightdig.test(fldobj.value)) 
  {
   fldobj.value = reformatdate (fldobj.value)   
  }
  else 
  {  
   //err = 1  // then just let this drop thru, if not 8 numbers. the user should have entered properly, and we will see later in code.
  }

  datestring = fldobj.value
  var valid = "0123456789/"
  
  var ok = "yes"
  var temp;


  if (!allowInString(datestring,"/0123456789"))
  {    err = 1  // invalid characters in date
  } else 
  {

    for (var i=0; i< datestring.length; i++) 
    {
     temp = "" + datestring.substring(i,i+1)
       
     if (valid.indexOf(temp)=="-1") {
        err = 1 
        break;
       }

     // Is The Date 10 Characters 
     if(datestring.length != 10) {
        err=2;
        break;
        }
   
     b = datestring.substring(0,2)  // month
     c = datestring.substring(2,3)  // '/'
     d = datestring.substring(3,5)  // day
     e = datestring.substring(5,6)  // '/'
     f = datestring.substring(6,10) // year

      // Check For Correct Delimiters

     if (c != '/' ) {
      err=4;
      break;
     }

     if (e != '/') {
      err=6;
      break;
     }

    // Month Range 
      if (b<1 || b>12) {
       err=3;
       break;
      }

    // Day Range
      if (d<1 || d>31) {
       err=5;
       break;
      }

    // Year Range

      if (f<1900 || f> 2100) {
       err=7;
       break;
      }

    // April / June / Sept / Nov  -  Only 30 Days In Month
      if (b==4 || b == 6 || b == 9 || b == 11) 
      {
        if (d==31) {
         err=8;
         break;
        }
      }

     // February
        if (b==2)
        {
          var g=parseInt(f/4)
          if (isNaN(g)) { 
           err=9;
           break;
          }
          if (d>29) {
           err=10;
           break;
          }
          if (d==29 && ((f/4)!=parseInt(f/4))) {
           err=11;
           break;
          }
        }

      }
 
}

  if (err==1  || err==4 ||err == 6 )
  {
    alert("Invalid Date format - ("+ err+ ") "+ fldobj.value+", it should be MM/DD/YYYY")
    obj.focus()
    obj.select()
    return false;
  } else 
    {

    if (err ==2) 
      {
        validate_date(obj, "Entered date ")
      } else 
        {

        if (err!=0)
          {
            alert("Invalid Date - " + fldobj.value)
              obj.select()
              obj.focus()
            return false;
          }
        }
    } 

return true
}

function logout()
{
 mf = document.forms[0]
 mf.action = "logout.asp"  
 mf.submit()
}

function reformatdate (sdate)
{   return (reformat (sdate, "", 2, "/", 2, "/", 4))
}

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


function checkEmail(obj)
{
if (isEmail(obj))
  {
  return true;
  }
else
  {
  obj.focus()
  obj.select()
  alert('Invalid Email address, the format should be ??@??.???')
  return false;
  }
}

// function isEmail implemented using regular expressions:
// total lines of code to examine string = 1, plus 1 above to define expression

function isEmail(s)
{ 
  var reEmail = /^.+\@.+\..+$/
  if (s.value.length == 0) 
   {
      return true
   }
  else 
   {
      if (checkBadChars(s))
      {
       return reEmail.test(s.value)
      }
   }
}


function checkBadChars(obj)
{
if (isBadChars(obj))
  {
  return true;
  }
else
  {
  obj.focus()
  obj.select()
  alert('Invalid character(s) entered,\n\nPlease do not use any of the following characters:\n\n  "  <  ý ü' )
  return false;
  }
}

// function isEmail implemented using regular expressions:
// total lines of code to examine string = 1, plus 1 above to define expression

function isBadChars(s)
{ 
  var badChars = /[<"ýü]/
  if (s.value.length == 0) 
   {
    return true
   }
  else 
   {
     if (badChars.test(s.value))
      {return false}
     else {return true}
   }
}

/******************************************************************************
* from Filename    : ValidateTel.inc 
* Filelocation: \hnaweb\
* Author      :  
* Created     :  
* Description :
* Progmmr Note:  
*
******************************************************************************/

function jschecktel(obj)
{
  telobj=arguments[0]
  telno = telobj.value
  var err = 0
  mf = document.forms[0]

  var tendig = /^\d{10}$/
  if (telno.length == 12)
  
  {
    if (isNaN(telno.charAt(0))) err = 1
    if (isNaN(telno.charAt(1))) err = 1
    if (isNaN(telno.charAt(2))) err = 1
    if ((telno.charAt(3) != "-") & (telno.charAt(3) != " ")) err = 1
    if (isNaN(telno.charAt(4))) err = 1   
    if (isNaN(telno.charAt(5))) err = 1
    if (isNaN(telno.charAt(6))) err = 1
    if ((telno.charAt(7) != "-") & (telno.charAt(7) != " ")) err = 1   
    if (isNaN(telno.charAt(8))) err = 1
    if (isNaN(telno.charAt(9))) err = 1
    if (isNaN(telno.charAt(10))) err = 1
    if (isNaN(telno.charAt(11))) err = 1
  }
  else 
  {
    if (tendig.test(telobj.value)) 
    {
     telobj.value = reformatUSPhone(telobj.value)    
    }
    else 
    {  
     err = 1
    }
  }

  if (err == "1" && telno.length > 0)
  {
     
    alert("Format Of Telephone Number Incorrect - 999-999-9999")
    telobj.select()
    return false
  }
}

// takes USPhone, a string of 10 digits
// and reformats as 123-456-789

function reformatUSPhone (USPhone)
{   return (reformat (USPhone, "", 3, "-", 3, "-", 4))
}

function reformat (s)
{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


/******************************************************************************
* Filename    : ValidateSSN.js
* Filelocation: \hnaweb\
* Author      :  
* Created     :  
* Description :

* Progmmr Note: This (.js setup ) was done this way to make it a simpler change from what it was before to now have the helpscript in a .js file.  
*               I only had to save the HelpScript.inc as HelpScript.js, and put 1 line of javascript here to make the change to  
*               the entire system. 
*

*
* Change log  :  
*                              CHANGE   IMPLEMENT  
*       rel  chg  PROGRAMMER    DATE       DATE    CHANGE DESCRIPTION
*       ---  ---  ---------- ---------- ---------- ------------------
*  
*PGMCHG R2.A CHx  xxxx       xx/xx/xxxx xx/xx/xxx1 
*
*
******************************************************************************/


function jscheckssn(obj)
{
  ssnobj=arguments[0]
  ssnno = ssnobj.value
  var err = 0
  mf = document.forms[0]
  var ninedig = /^\d{9}$/

  if (ninedig.test(ssnobj.value)) 
  {
   obj.value = reformatssn(ssnobj.value);
  }
  else 
  {  
   //err = 1  // then just let this drop thru, if not 9 numbers. the user should have entered properly, and we will see later in code.
  }

  if (ssnno.length == 11)
  {
    if (isNaN(ssnno.charAt(0))) err = 1
    if (isNaN(ssnno.charAt(1))) err = 1
    if (isNaN(ssnno.charAt(2))) err = 1
    if (ssnno.charAt(3) != "-") err = 1
    if (isNaN(ssnno.charAt(4))) err = 1   
    if (isNaN(ssnno.charAt(5))) err = 1
    if (ssnno.charAt(6) != "-") err = 1   
    if (isNaN(ssnno.charAt(7))) err = 1
    if (isNaN(ssnno.charAt(8))) err = 1
    if (isNaN(ssnno.charAt(9))) err = 1
    if (isNaN(ssnno.charAt(10))) err = 1
  }
  if (ssnno.length == 9)
  {
    if (isNaN(ssnno.charAt(0))) err = 1
    if (isNaN(ssnno.charAt(1))) err = 1
    if (isNaN(ssnno.charAt(2))) err = 1
    if (isNaN(ssnno.charAt(3))) err = 1   
    if (isNaN(ssnno.charAt(4))) err = 1
    if (isNaN(ssnno.charAt(5))) err = 1
    if (isNaN(ssnno.charAt(6))) err = 1
    if (isNaN(ssnno.charAt(7))) err = 1
    if (isNaN(ssnno.charAt(8))) err = 1
  }
  if (ssnno.length != 9) 
  {
    if (ssnno.length != 11) err = 1
  }
  if (err == "1")
  {
    if (ssnno != "")
    {
      alert("Social Security Number Must be 9 Numeric Characters With or Without Dashes.\nAllowable Formats are  123-45-6789  or  123456789\n\nFor Newborns Less Then 6 Months Old Use - 000-00-0000")
      ssnobj.focus() 
      ssnobj.select()
    
      return false
    }
  }
}

function reformatssn(ssn)
{   return (reformat (ssn, "", 3, "-", 2, "-", 4))
}
//NOT SURE WHY TWO VALIDATE ROUTINES
function jschecknormalssn(obj)
{
  ssnobj=arguments[0]
  ssnno = ssnobj.value
  var err = 0
  mf = document.forms[0]
  if (ssnno.length == 11)
  {
    if (isNaN(ssnno.charAt(0))) err = 1
    if (isNaN(ssnno.charAt(1))) err = 1
    if (isNaN(ssnno.charAt(2))) err = 1
    if (ssnno.charAt(3) != "-") err = 1
    if (isNaN(ssnno.charAt(4))) err = 1   
    if (isNaN(ssnno.charAt(5))) err = 1
    if (ssnno.charAt(6) != "-") err = 1   
    if (isNaN(ssnno.charAt(7))) err = 1
    if (isNaN(ssnno.charAt(8))) err = 1
    if (isNaN(ssnno.charAt(9))) err = 1
    if (isNaN(ssnno.charAt(10))) err = 1
  }
  if (ssnno.length == 9)
  {
    if (isNaN(ssnno.charAt(0))) err = 1
    if (isNaN(ssnno.charAt(1))) err = 1
    if (isNaN(ssnno.charAt(2))) err = 1
    if (isNaN(ssnno.charAt(3))) err = 1   
    if (isNaN(ssnno.charAt(4))) err = 1
    if (isNaN(ssnno.charAt(5))) err = 1
    if (isNaN(ssnno.charAt(6))) err = 1
    if (isNaN(ssnno.charAt(7))) err = 1
    if (isNaN(ssnno.charAt(8))) err = 1
  }
  if (ssnno.length != 9) 
  {
    if (ssnno.length != 11) err = 1
  }
  if (err == "1")
  {
    if (ssnno != "")
    {
      alert("Social Security Number Must be 9 Numeric Characters With or Without Dashes.\n\nAllowable Formats are  123-45-6789  or  123456789")
      ssnobj.select()
      return false
    }
  }
}

//' Filename    : ValidateCommon.js
//' Filelocation: \hnaweb\
//' Author      :  
//' Created     :  
//' Description : 
//'
//' Progmmr Note: 
//'
//' Change log  :  
//'                              CHANGE   IMPLEMENT  
//'       rel  chg  PROGRAMMER    DATE       DATE    CHANGE DESCRIPTION
//'       ---  ---  ---------- ---------- ---------- ------------------
//'  
//'PGMCHG Rx.x CHx  xxxx       xx/xx/xxxx xx/xx/xxxx 
//'


function checkmoney(obj)
{
if (obj.value > "")
{
 var number = /^\d{1,7}\.{1}\d{2}$/
 if (number.test(obj.value))
 {
  return true
 } else {
  alert('Entry must be numeric containing two decimal places (#####.##)')
  obj.focus()
  obj.select()
  return false
 }
}
 return true
}

function checkinteger(obj)
{
 var number = /\D/
 if (number.test(obj.value))
 {
  alert('Entry must be a whole number')
  obj.focus()
  obj.select()
  return false
 } else {
  return true
 }
}

function checklen(obj,maxlen) 
{
if (obj.value.length > maxlen) 
  {
    alert("Entry must be less then "+maxlen+" characters long, you have entered "+obj.value.length+".") ;
    obj.focus();
    //obj.select()
    return false;
  }
  //    alert("you have entered: "+obj.value.length+".") ;

return true
}

function popUp(url,v_width) {
 
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
self.name = "mainWin"; 
sealWin.focus()
}

function popUp_2(url) {
 
sealWin = window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=600');
sealWin.focus()}


function adobedownload()
{
  adobewin = window.open("http://www.adobe.com/products/acrobat/readstep.html")
  return
}

function openpdf(file)
{
  var file
  adobewin = window.open(file)
  return
}


function displayLocation() {
  var str = "";
  str += "X=" + window.event.clientX;
  str += ", ";
  str += "Y=" + window.event.clientY;
  window.status = str; // display in status bar
}
 //document.onmousemove = displayLocation;


function checksize()
{
  if (navigator.appName =='Netscape') 
  {
  w=window.innerWidth
  h=window.innerHeight
  }else{
  w=document.body.clientWidth
  h=document.body.clientHeight
  }
//alert(h)
  if (w > 800 ){
  window.resizeTo(800,1000);
   }
}

function jscheckzip(obj)
{
  zipobj  =arguments[0]
  var err = 0
  var msg = "Invalid ZIP Code Format"
  zipstring = zipobj.value
  mf = document.forms[0]
  ziplen = zipstring.length
  if (ziplen != 5 && zipstring != "")
  {
   alert("You Must Enter A 5 Digit Zip Code")
   zipobj.focus()
   zipobj.select()
   return false
  } else
  {
    if (isNaN(zipstring))
    {
     alert("You Must Enter A Numeric Zip Code")
     zipobj.focus()
     zipobj.select()
     return false
    }
  }
}


function jscheckzip4(obj)
{
  zipobj=arguments[0]
  var err = 0
  var msg = "Invalid ZIP Code Format"
  zipstring = zipobj.value
  mf = document.forms[0]
  if (zipstring == "")
  {
   alert("Please enter A Zip Code")
   zipobj.select()
   return false
  }
  ziplen = zipstring.length
  if (ziplen != 4 && zipstring != "")
  {
   alert("You Must Enter A 4 Digit Zip Code")
   zipobj.select()
   return false
  }
  if (isNaN(zipstring))
  {
   alert("You Must Enter A Numeric Zip Code")
   zipobj.select()
   return false
  }
}


var xpdfWin 
function xgetpdf(file)
{  
var file
 alert("This function requires Adobe Acrobat Reader. If you need to download this software please click on the icon shown on the page.")
 if (null==pdfWin || pdfWin.closed) {pdfWin=window.open(file,'','width=,height=500,status=1,statusbar=1,location=1,locationbar=1,toolbar=1,menubar=1,scrollbars,resizable')};pdfWin.focus()

}

function getpdf(file)
{
  pdfWin = window.open(file, 'bookwin2', 'width=800,height=500,scrollbars=yes,scrollbars,resizable')
  pdfWin.focus()
}

// this really just reformats, and is based on code from (Tom Wittbrodt Copyright (c) 1998, 1999) which I Tom Auriemma changed/fixed (a lot) to to suit our needs. 
// this total date routine now handles almost any situation.
function validate_date(date_field, desc) 
{
  if (!date_field.value)  
          return true;
  var date_is_bad = 0;  
  var in_date = stripCharString(date_field.value," ");
  var date_is_bad = 0;  
  if (!allowInString(in_date,"/0123456789"))
      date_is_bad = 1; // invalid characters in date

  if (!date_is_bad) 
   { 
    var date_pieces = new Array();
    date_pieces = in_date.split("/");

    if (date_pieces.length == 2) 
    {
        var d       = new Date();
        in_date     = in_date + "/" + get_full_year(d);
        date_pieces = in_date.split("/");
    }

    if (date_pieces.length != 3 || parseInt(date_pieces[0],10) < 1 || parseInt(date_pieces[0],10) > 12 
                                || parseInt(date_pieces[1],10) < 1 || parseInt(date_pieces[1],10) > 31 
                                || (date_pieces[2].length != 2 && date_pieces[2].length != 4)) 
    {
        date_is_bad = 6;  // date is not in format of m[m]/d[d]/yy[yy]
    }

    if (date_is_bad) 
    {
            alert(desc + " must be in the format of: \nmm/dd/yy, mm/dd/yyyy, m/d/yy or mm.dd.yy ect... ");
            date_field.focus();
            return (false);
    }
  }

  var ms = Date.parse(in_date);
  var d  = new Date();
  d.setTime(ms);

  var return_date  = d.toLocaleString();
  var return_month = parseInt(d.getMonth() + 1).toString();
  return_month     = (return_month.length==1 ? "0" : "") + return_month; 
  var return_date  =  parseInt(d.getDate()).toString();
  return_date      = (return_date.length==1 ? "0" : "") + return_date; 

  if  (date_pieces[2].length == 4)
  {
     return_date      = return_month + "/" + return_date + "/" + d.getFullYear();
  } else 
  {       
     return_date      = return_month + "/" + return_date + "/" + get_full_year(d);
  } 
  date_field.value = return_date;



return true;
}       // normalize the year to yyyy

function get_full_year(d) 
{
 var y = ""
 if (d.getFullYear() != null)
 {
  y = d.getFullYear();
  if (y < 1913) y+= 100;		
 } else
 {	
  y = d.getYear();
  if (y > 13  && y < 100) y += 1900;
  if (y < 1000) y += 2000;
 }
return y;
}
// The following functions were written by Gordon McComb
// More information can be found here: http://www.javaworld.com/javaworld/jw-02-1997/jw-02-javascript.html

function stripCharString (InString, CharString)  
{
 var OutString="";
   for (var Count=0; Count < InString.length; Count++)  {
        var TempChar=InString.substring (Count, Count+1);
      var Strip = false;
      for (var Countx = 0; Countx < CharString.length; Countx++) {
        var StripThis = CharString.substring(Countx, Countx+1)
         if (TempChar == StripThis) {
                Strip = true;
            break;
         }
      }
      if (!Strip)
        OutString=OutString+TempChar;
   }
return (OutString);
}
function allowInString (InString, RefString)  
{
       if(InString.length==0) return (false);
   for (var Count=0; Count < InString.length; Count++)  {
        var TempChar= InString.substring (Count, Count+1);
      if (RefString.indexOf (TempChar, 0)==-1)  
        return (false);
   }
return (true);
}

function opencertdetails()
{ thewindow = window.open('http://www.claredi.com/public/certdetails.php?username=pauldrago','windowname', config='height=400,width=450,' +'toolbar=no,menubar=no,' + 'scrollbars=yes,resizable=yes,' + 'location=no,directories=no,status=yes');}
//*            CH3.a TMA        04/02/2003 04/02/2003  ADDED Poorman douglas item
function PDopenwindow(destination,doc_width,doc_height) 
{
var doc_width 
var doc_height
var destination 
//destination = "PDwindow.asp"
   PDWindow=window.open(destination,'PD1','toolbar=yes,location=no,directories=no,menubar=yes,scrollbars=yes,status=no,resizable=1,width='+doc_width+',height='+doc_height);
   PDWindow.focus();
}

// End script hiding --></script>

