// BuildIt.js - JavaScript General Functions Library

//alert("BuildIt");

var CloseMsg = 'Click here to close this window';
var TitleMsg = document.title;
var Pass = 1;

window.status = TitleMsg;

// ----------------------------------------------------------
// Displays a message & allows an exit from this code
// inputs:  Message text to display.
// outputs: Displays the message & waits for user input.
// 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); // Go back, and if you won't
    javascript:history.Go(-1); // then Error Die & go back!
  }
}

function S1() {
   window.status = TitleMsg;
}

function S2() {
  window.status='Return to previous page.';
  return true;
}

function S3() {
  window.status='View our previous on-line Newsletter.';
  return true;
}




// ---------------------------------------------------------------------
// Adds needed html to any file needed an e-mail link to the Prayer List
// ---------------------------------------------------------------------
function Prayer() {
   document.write("Click here to: ");
   
   // Phil Karras
   BuildIt('prayer', 'emmaus', 'wv', 2); // pk010

   document.write(" our Prayer Request Servant<br/>");
   
} // end of function: Prayer()




// ---------------------------------------------------------------------
// Adds needed html to any file needed an e-mail link to the Community LD
// ---------------------------------------------------------------------
function CommunityLD() {
   document.write("Click here to: ");
   
   // Phil Karras
   BuildIt('cld', 'emmaus', 'wv', 2); // pk010

   document.write(" our Community Lay Director<br/>");
   
} // end of function: CommunityLD()




// ---------------------------------------------------------------------
// Adds needed html to any file needed an e-mail link to the Information
// ---------------------------------------------------------------------
function Info() {
   document.write("Click here to: ");
   
   // Phil Karras
   BuildIt('info', 'emmaus', 'wv', 2); // pk010

   document.write(" our Information servant<br/><br/>");
   
} // end of function: Info()




// ---------------------------------------------------------------------
// Adds needed html to any file needed an e-mail link to the webmaster
// ---------------------------------------------------------------------
function WebMaster() {
   document.write("Click here to: ");
   
   // Phil Karras
   BuildIt('thewebguy', 'emmaus', 'wv', 2); // pk010

   document.write(" our WebMaster<br/>");
   
} // end of function: WebMaster()




// -------------------------------------------------------------------
// 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|
//                     a    b  c  d
//
// 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()




// -------------------------------------------------------------------
// 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 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 +=  '">[Email]</a>';

   document.write(Stng);
   //alert(Stng);

} // end of: BuildIt(PgDat)



// -------------------------------------------------------
// This function correctly gets the last update date for 
// both IE & NS browsers.
//
// inputs:  none
// outputs: none
// actions: Save correct date & year in global vars
// returns: none
// -------------------------------------------------------
var LastUpdate = ""; // These need to be global Or, placed 
var Year = "";       // in your HTML <head><script> section
function GetLastUpDate() {

   var Dt = document.lastModified; // added 01/15/2003
   //alert("Dt = "+Dt);
   var D1 = new Date(Dt);
   //alert("D1 = "+D1); // looks correct on my HD, not on the site?

   Dms = D1.getTime(); // works, gets milli seconds
   //alert("D(ms) is: "+Dms);
   
   
   //st = D1.toLocalString(); // not a function?
   //st = Dms.toLocalString(); // not a function?
   //st = toLocalString(Dms); // not defined?
   //st = toLocalString(D1); // not defined?
   
   //Date.UTC(Dms).toLocalString(); // not a function?
   //toLocalString(Date.UTC(Dms)); // not defined?
   
   //Date.UTC(Dms); // This works? but I can't get anything out of it but NaN?
   //getTimeZoneOffset(Date.UTC(Dms)); // not defined
   //Date.UTC(Dms).getTimeZoneOffset(); // not a function
   
   //alert("here");
   
   
   var Dt02;
   var pnt = Dt.lastIndexOf(" "); // find the last space

   // ----------------------------------------------------
   // Netscape also seems to use the UTC time, +4 hrs!?!
   // Mozilla & Firefox do as well.
   // ----------------------------------------------------
   if(Dt.length > 25) { // Needed to get to correct version for NetScape 7.0
      //document.location.href="indexNS.html";
   }

   Dt02 = Dt.substring(0, pnt); // chop off everything after last space
   if(!Pass) {
     Dt02 = Dt; // Use everything!
   }
   
   // ----------------------------------------------------
   // If there was a "GTM" at the end of the original time,
   // then we also need to still remove the hrs:mins:sec
   // So, once again remove all past new last space
   // ----------------------------------------------------
   if(Dt.lastIndexOf("GMT") != -1) { // Got GMT!
      //alert("3. Date Time: "+Dt);
      pnt = Dt02.lastIndexOf(" ");

      LastUpdate = Dt02.substring(0, pnt);
      Year = LastUpdate.substring(LastUpdate.length-4, LastUpdate.length);
   }
   else {
      LastUpdate = Dt02;
      Year = LastUpdate.substring(LastUpdate.length-4);
   }
   // -------------------------------------------------------


}



function Check() {

}
