// JS-LIB.JS         A library of useful JavaScript functions

// -------------------------------------------------------------------
// These functions hide or display an element.
// -------------------------------------------------------------------
imgout=new Image(9,9);
imgin=new Image(9,9);

imgout.src="./images/u.gif";
imgin.src="./images/d.gif";

/* switch expand/collapse icons */
function swIcon(imagename,objectsrc)
{
    if(document.images)
    {
        document.images[imagename].src=eval(objectsrc+".src");
    }
}

/* show/hide element */
function shoh(id)
{
    if(document.getElementById) // DOM3 = IE5, NS6
    {
        if(document.getElementById(id).style.display == "none")
        {
            document.getElementById(id).style.display = 'block';
            swIcon(("img"+id),'imgin');         
        }
        else
        {
            swIcon(("img"+id),'imgout');
            document.getElementById(id).style.display = 'none';         
        }   
    }
    else
    {
        if(document.layers)
        {
            if(document.id.display == "none")
            {
                document.id.display = 'block';
                swIcon(("img"+id),'imgin');
            }
            else
            {
                swIcon(("img"+id),'imgout');    
                document.id.display = 'none';
            }
        }
        else
        {
            if(document.all.id.style.visibility == "none")
            {
                document.all.id.style.display = 'block';
            }
            else
            {
                swIcon(("img"+id),'imgout');
                document.all.id.style.display = 'none';
            }
        }
    }
}

// -------------------------------------------------------------------
// This function displays an alert message
// inputs: the message
// output: Displays the message in an alert window
// Action: Waits for a click of the mouse
// return: nothing
// -------------------------------------------------------------------
function Message(msg) {
   alert (msg);
}

// -------------------------------------------------------------------
// This function displays an alert ERROR * message * ERROR
// inputs: the message
// output: Displays the message in an alert window
// Action: Waits for a click of the mouse
// return: nothing
// -------------------------------------------------------------------
function Error(msg) {
   alert ("ERROR * "+msg+" * ERROR");
}

// -------------------------------------------------------------------
// This function swaps a multi-part strings parts & sends it back
// inputs: a multi part string
// output: nothing
// Action: none
// return: a reverse order multi part string
// -------------------------------------------------------------------
function SwapStr(instr) {
   var outstr;
   var tmpstr;
   var partstr;
   var mmax, max, i;

   partstr = instr.split(" "); // Split string apart on a space
   max = partstr.length; // Get the # of parts
   mmax = max/2;         // Get the # of swaps
   for(i=0; i<mmax; ++i) { // actual swapping code
      tmpstr = partstr[i];           // Put lowest part in tmp
      partstr[i] = partstr[max-i-1]; // put highest part in lowest part
      partstr[max-i-1] = tmpstr;     // put lowest part in highest part
   }
   outstr = partstr.join(" "); // put the reversed string back together

   return (outstr);
}

// -------------------------------------------------------------------
// This function Checks a string for a char
// inputs: a string and a char
// output: nothing
// Action: none
// return: (0/1) = Char (Not found / Found) in string
// -------------------------------------------------------------------
function ChkChar(instr, inchar) {

   Rtn = 0;
   atPos = instr.indexOf(inchar, 1);
   if(atPos > 0)
      Rtn = 1;

   return Rtn;
}

// -------------------------------------------------------------------
// This function Prints a string as a "level" html <h> headder
// inputs: Title, level of headder, "c" == to center it.
// output: none or can return html header as a string
// Action: Prints the headder or none
//
// If we use the printing of the headder string the call must be:
// Call: AddHead("Title Goes Here", 1, "c");
//
// If we use the return of the headder string the call must be:
// Call: document.write(AddHead("Title Goes Here", 1, "c"));
// -------------------------------------------------------------------
function AddHead(text, level, cnt) {
   var c1 = "", c2 = "";

   if(cnt == "c") {
      c1 = "<center>";
      c2 = "</center>";
   }
   html = "H" + level;
   start = c1 + "<" + html + ">";
   stop = c2 + "</" + html + ">";

   document.write(start + text + stop); // call: AddHead("...)

   return; // (start+text+stop); // Call: doc.write(AddHead("...))
}

// -------------------------------------------------------------------
// This function Checks an input to see if it IS a number
// inputs: a string
// output: nothing
// Action: none
// return: (0/1) = (Not a number / Is a number)
// -------------------------------------------------------------------
function IsNum(Vnum) {
   return (!isNaN(Vnum));
}

// -------------------------------------------------------------------
// This function Starts the e-mail <a href= tag
// inputs: two email address strings
// output: nothing
// Action: none
// return: complete email html line
// -------------------------------------------------------------------
function MailMe(prompt, add1, add2, subject) {
   var atsign = "@";
   var dotcom = ".net";
   var Mail2 = "\"mailto:";//HA@HA.HA.nothing.here.com!
   var Subj = "?subject=" + subject + "\"";
   var Ovr = " onMouseOver=\"window.status='" + prompt + "'; return true;\"";
   var Out = " onMouseOut=\"window.status=''\"";
// window.alert("<a href="+Mail2+add1+atsign+add2+dotcom+Subj+Ovr+Out+">");
   return(document.write("<a href=",Mail2+add1+atsign+add2+dotcom+Subj+Ovr+Out, ">"));
}

// -------------------------------------------------------------------
// This function Ends the e-mail <a href= tag
// inputs: none
// output: nothing
// Action: none
// return: end of email html line
// -------------------------------------------------------------------
function MailEnd() {
   return(document.write("</a>"));
}

// -------------------------------------------------------------------
// This function puts together two strings into an email address
// inputs: two email address strings
// output: nothing
// Action: none
// return: complete email html line
// -------------------------------------------------------------------
function MailTxt(add1, add2) {
   var atsign = "@";
   var dotcom = ".net";
   return(document.write(add1+atsign+add2+dotcom));
}

// -------------------------------------------------------------------
// This function builds a formatted date string.
// inputs: format string
// output: nothing
// Action: none
// return: formatted date string
// -------------------------------------------------------------------
function showDate() {
   var t=new Date(),a=showDate.arguments,str="",i,a1;
   var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
   var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thu','Friday','Fri','Saturday','Sat');

   for(i=0;i<a.length;i++){
      a1=a[i].charAt(1);
      switch (a[i].charAt(0)) {
      case "M":
         if((Number(a1)==3) && ((t.getMonth()+1)<10))
            str+="0";
         str+=(Number(a1)>1) ? t.getMonth()+1 : month[t.getMonth()*2+Number(a1)];
         break;
      case "D":
         if((Number(a1)==1) && (t.getDate()<10))
            str+="0";
            str+=t.getDate();
         break;
      case "Y":
         str+=(a1=='0') ? t.getFullYear() : t.getFullYear().toString().substring(2);
         break;
      case "W":
         str+=tday[t.getDay()*2+Number(a1)];
         break;
      default:
         str+=unescape(a[i]);
      }
   }
   return str;
}

function showDateLong() {
    return document.write(showDate("W0","%20","M0","%20","D0",",%20","Y0"));
}

// -------------------------------------------------------------------
// This function opens a pop-up window.
// inputs: URL
// output: nothing
// Action: none
// return: nothing
// -------------------------------------------------------------------
function popUp(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=480,height=300');");
}
function popUpLg(URL) {
   day = new Date();
   id = day.getTime();
   eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=620,height=460');");
}
