// lib.js from: PKJA-LIB.JS    A library of useful JavaScript functions

// Copyright (c) Circle Software, Philip Karras 2000 - 2006, 01/20/2006

// Our soul waits for the Lord, he is our help and shield. Psalm 33:20

//alert("In lib.js");

// DeBug()       - Debugging for infinite & fast loops
// DeBugW()      - Displays large text as a new web-page
// BuildIt()     - to build e-mail address link
// BuildIt2()    - displays the e-mail address
// ChkContact    - Check the Contact Form inputs
// ChkQuote()    - Checks the Quote Form inputs
// ChkPassWrd()  - Asks for & checks the prompt entered password



// ----------------------------------------------------------
// Displays a message & allows an exit from this code
// inputs:  Message text to display
// outputs: Displays the message & wait for key inputs
// actions: Returns to this code, or to previous html page
// returns: none
// ----------------------------------------------------------
function DeBug(txt) {
  A=prompt(txt, "Continue/Exit == Enter/X-key.");
  if(A=="X" || A=="x") { // Go back to the LAST safe page!
    javascript:history.go(-1);
    //javascript:history.G0(-1); // May be needed to cause an ERROR
  }
}


// ----------------------------------------------------------
// Displays large text as a new web-page
// inputs:  Message text to be displayed
// outputs: Displays the text & waits to be close [X]
// actions: Returns to this code, or to previous html page
// returns: none
// ----------------------------------------------------------
function DeBugW(txt) {
   tmpw = window.open("", "tmp");
   tmpw.document.write(txt);
   tmpw.document.close();
}



function BuildIt(a, b, c, d) { // pk01

   var Stng = ""; // This line being built up

   Stng = '<a href="mailto:' + a  + "@" + c + b;
   switch (d/1) { // Make sure it's a number!
      case 0:
         Stng += ".com";
         break;
      case 1:
         Stng += ".net";
         break;
      case 2:
         Stng += ".org";
         break;
      case 3:
         Stng += ".gov";
         break;
      case 4:
         Stng += ".us";
         break;
      default:
         Stng += ".ccc";
   }
   Stng +=  '">[E-mail]</a>';

   document.write(Stng);
   //alert(Stng);

} // end of: BuildIt(PgDat)



// -------------------------------------------------------------------
// Parses all innerHTML sent to find E: & BuildIt and replace it with
// the actual email address.
// Form of the email address line is:
// Email line form: |ke3fl|hoo|ya|0|
//                     0    2  1  3
//
// inputs:  PgDat - the full html page
// outputs: none
// actions: email addresses are rebuilt and replace the email lines
// returns: The corrected full html page
// -------------------------------------------------------------------
function BuildIt2(a, b, c, d) { // pk01

   var Stng = ""; // This line being built up

   Stng = a  + "@" + c + b;
   switch (d/1) { // Make sure it's a number!
      case 0:
         Stng += ".com";
         break;
      case 1:
         Stng += ".net";
         break;
      case 2:
         Stng += ".org";
         break;
      case 3:
         Stng += ".gov";
         break;
      case 4:
         Stng += ".us";
         break;
      default:
         Stng += ".ccc";
   }

   //alert(Stng);
   document.write(Stng);

} // end of: BuildI2t()



// -------------------------------------------------------------------
// Checks the Contact Form input for Name, Phone & E-mail. If any are
// not present then the form can not be sent.
// Form of the email address line is:
// inputs:  none - values gotten from the form
// outputs: none
// actions: All required fields are filled = return true
// returns: true/false, false = do not submit required input field empty
// -------------------------------------------------------------------
function ChkContact() { // pk01
   var Rtn = true;
   
   //DeBug("Got to ChkContact");
   //alert("document.Contact.URname.value.length = " + document.Contact.URname.value.length);
   
   if(document.Contact.URname.value.length < 2) {
      Rtn = false;
      document.Contact.URname.focus(); // Go to the field for input
      alert("We need your name to send this form, please fill in your name.");
   }
   if(document.Contact.URemail.value.length < 6 && Rtn==true) {
      Rtn = false;
      document.Contact.URemail.focus(); // Go to the field for input
      alert("We need your e-mail address to send this form, please fill in your e-mail address.");
   }
   if(document.Contact.URphone.value.length < 10 && Rtn==true) {
      Rtn = false;
      document.Contact.URphone.focus(); // Go to the field for input
      alert("We need your full 10 digit phone number to send this form, please fill in your complete phone number.");
   }

   //alert("Rtn = " + Rtn);
   return Rtn;
} // >>>



// -------------------------------------------------------------------
// Checks the Quote Form input for Name, Phone & E-mail. If any are
// not present then the form can not be sent.
// Form of the email address line is:
// inputs:  none - values gotten from the form
// outputs: none
// actions: All required fields are filled = return true
// returns: true/false, false = do not submit required input field empty
// -------------------------------------------------------------------
function ChkQuote() { // pk01
   var Rtn = true;
   
   //DeBug("Got to ChkContact");
   //alert("document.Quote.URname.value.length = " + document.Quote.URname.value.length);
   
   if(document.Quote.URname.value.length < 2) {
      Rtn = false;
      document.Quote.URname.focus(); // Go to the field for input
      alert("We need your name to send this form, please fill in your name.");
   }
   if(document.Quote.URemail.value.length < 6 && Rtn==true) {
      Rtn = false;
      document.Quote.URemail.focus(); // Go to the field for input
      alert("We need your e-mail address to send this form, please fill in your e-mail address.");
   }
   if(document.Quote.URphone.value.length < 10 && Rtn==true) {
      Rtn = false;
      document.Quote.URphone.focus(); // Go to the field for input
      alert("We need your full 10 digit phone number to send this form, please fill in your complete phone number.");
   }

   //alert("Rtn = " + Rtn);
   return Rtn;
} 



// -------------------------------------------------------------------
// Gets the person's password & passes it on to the Perl program
// inputs:  the password
// outputs: none
// actions: updates the PassWrd field value
// returns: true/false, false = do not submit required input field empty
// -------------------------------------------------------------------
function ChkPassWrd() { // pk01
   var Rtn = true;
   var PW = document.edit.passwrd.value;
   
   //DeBug("Got to ChkPassWrd");
   //alert("document.edit.passwrd.value = " + document.edit.passwrd.value);
   
   PW = prompt("Enter your password & click");
   
   if(PW.length < 7) {
      Rtn = false;
      alert("The password you entered was not of the correct form.");
   }
   else {
   
      document.edit.passwrd.value = PW;
   }
   
   //alert("Password entered was: ["+document.edit.passwrd.value+"]"); // debugging test
   
   //return false;
   return Rtn;
}