/*****************************************************************************
file: garrett.js
developer: Bob Lewis
date: 01Jul06
description: logic for initialization function for leroygarret.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 serverloc;
if(location.href.indexOf("localhost") > -1)
  {
    serverloc = "local";
  }
else
  {
    serverloc = "remote";
  }

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()
{
  if(serverloc == "remote")
    {
      makeRequest('http://www.leroygarrett.org/counter/visitor_count.php?count_lg.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'";


//added on 13Jun07
if(arguments[2])
  {
    if(arguments[2] > 1) //added on 21Sep08
      {
        txt = '<a style=\"font-size:8pt\" '+tmpStr+' href = \"mailto:' + txt + '\?subject=Please add me to your Soldier On! mailing list">' + toWhom + '<' + '/a>'
      }    
    else
      {
        txt = '<a style=\"font-size:8pt\" '+tmpStr+' href = \"mailto:' + txt + '\?subject=Leroy Garrett Web site">' + toWhom + '<' + '/a>'
      }
  }
else
  {
    txt = '<a style=\"font-size:8pt\" '+tmpStr+' href = \"mailto:' + txt + '\?subject=Restoration Review, Attn: Bob Lewis">' + 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('Leroy Garrett','info@@leroygarrett.org');
 var str= encode_email('Leroy Garrett','leroygarrett@verizon.net');
 document.all.email.innerHTML = str;
 document.all.old_mail.style.display = "none"; 
 //document.all.get_mail.click(); 
}
