function initAjax()
{
  //function to create and return a XMPHTTP object
  var ajaxRequest;
    ajaxRequest = false;
    try
    {
        // create Opera 8.0+/Firefox/Safari XMPHTTP object
        ajaxRequest = new XMLHttpRequest();
        return ajaxRequest;
    }
    catch (e)
    {
        // try creating IE object if above fails
        try
        {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            return ajaxRequest;
        }
        catch (e)
        {
            try
            {
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                //browser doesn't support ajax
                return false;
            }
        }
    }
    return;
}

function showSendDiv() {
  if (document.getElementById("hcSendToFriendConfDiv")) {
    document.getElementById("hcSendToFriendConfDiv").style.display = 'none';
  }
  if (document.getElementById("hcSendToFriendFormDiv")) {
    document.getElementById("hcSendToFriendFormDiv").style.display = 'block';
  }

  if (document.getElementById("hcSendToFriendPanel")) {
    document.getElementById("hcSendToFriendPanel").style.display = 'block';
    document.getElementById("hcSendToFriendTheirEmail").focus();
  }
}

function hideSendDiv() {
  if (document.getElementById("hcSendToFriendPanel")) {
    document.getElementById("hcSendToFriendPanel").style.display = 'none';
  }
}

function sendMessage() {
  ajaxRequest = initAjax();
  if (ajaxRequest == false) {
    //fail gracefully
    OpenWindow("/emailtoafriend.php?Page=/",500,200);
    return;
  }
  ajaxRequest.onreadystatechange = function() {
    if(ajaxRequest.readyState == 4) {
      if (document.getElementById("hcSendToFriendFormDiv")) {
        document.getElementById("hcSendToFriendFormDiv").style.display = 'none';
      }
      if (document.getElementById("hcSendToFriendConfDiv")) {
        document.getElementById("hcSendToFriendConfDiv").style.display = 'block';
      }
    }
  }
  var url = "/index.php?SendToAFriend=1&Message="+escape(document.getElementById("hcSendToFriendMsg").value)+"&EmailAddress="+escape(document.getElementById("hcSendToFriendTheirEmail").value)+"&YourName="+escape(document.getElementById("hcSendToFriendTheirName").value);
  ajaxRequest.open("GET", url, true);
  ajaxRequest.send(null);
}
