/*****************************************************************************
file: init.js
developer: Bob Lewis
date: 01Jul06
description: logic for initialization function for stone-campbell.org home page;
******************************************************************************/
//alert("garrett.js");

/******** retrieve date and count from get_count.asp *************************
When the application loads, the init function checks the vCount variable;
if it is null, the Microsoft.XMLHTTP is called to load the new visitor count 
from count_lg; the value is inserted (after the page loads) into the 'num'
span element;
******************************************************************************/
var d=new Date();
var theYear = d.getYear();
var theDate = d.getDate();
var tmpMonth = d.getMonth();
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var dateToday = months[tmpMonth]+" "+theDate+", "+theYear;

function init()
{
  makeRequest('/counter/visitor_count.php?count_sc.txt');
}

function encode_email(toWhom,address)
{
txt =   ''
var theAddress = address.replace(/@/, "@@");
address = address.replace(/@@/, "@");
for (j=0; j<address.length; j++)
  {
    txt += '%' + Dec2Hex(address.charCodeAt(j))
  }

var tmpStr = "id='get_mail'";
txt = '<a '+tmpStr+' href = \"mailto:' + txt + '\?subject=Stone-Campbell">' + toWhom + '<' + '/a>'
return txt;
}

//following function found at: http://www.computerhope.com/j13.htm
function Dec2Hex (Dec) 
{
  var hexChars = "0123456789ABCDEF";
  var a = Dec % 16;
  var b = (Dec - a)/16;
  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  return hex;
}

function get_email()
{
 //in the html file no email address appears until the user
 //clicks on the get_email() link, which appears as a person's name,
 //in this case, Leroy Garrett;
 //when the user clicks get_email, this function encode an address 
 //with @@, then displays the string in an 'email' span;
 //then the 'old_email' span is hidden;
 var str= encode_email('Bob Lewis','info@@stone-campbell.org');
 document.all.email.innerHTML = str;
 document.all.old_mail.style.display = "none"; 
 document.all.get_mail.click(); 
}
