/*******************************************************************
file: utils.js
developer: Bob Lewis
date: 29May06; modified on 15Sep07
description: originally used with Restoration Review;
             adapted to this site--Unity-In-Diversity.Org;
functions:   encode_email(toWhom, address);
             Dec2Hex(Dec);
             clientSideInclude(id, url);
             getElementStyle(elemID, IEStyleProp, CSSStyleProp);
             inspect_element_properties(element);                        
********************************************************************/
//alert("utils.js");

function encode_email(toWhom,address)
{
txt =   ''
var theAddress = address.replace(/@/, "@@");
for (j=0; j<address.length; j++)
  {
    txt += '%' + Dec2Hex(address.charCodeAt(j))
  }
txt = '<a href = \"mailto:' + txt + '\?subject=Restoration Review">' + 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;
}

//copied from: http://www.boutell.com/newfaq/creating/include.html
//see: http://msdn2.microsoft.com/en-us/library/ms534369.aspx
//see also: http://msdn2.microsoft.com/en-us/library/ms535874.aspx
function clientSideInclude(id, url) 
{
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) 
    {
      try 
        {
          req = new XMLHttpRequest();
        } 
      catch (e) 
        {
          req = false;
        }
    } 
  else if (window.ActiveXObject) 
    {
      // For Internet Explorer on Windows
      try 
        {
          req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
      catch (e) 
        {
          try 
            {
              req = new ActiveXObject("Microsoft.XMLHTTP");
            } 
          catch (e) 
            {
              req = false;
            }
         }
    }
 var element = document.getElementById(id);
 if(!element) 
   {
     alert("Bad id " + id + 
     "passed to clientSideInclude." +
     "You need a div or span element " +
     "with this id in your page.");
     return;
   }
 if (req) 
   {
     // Synchronous request, wait till we have it all
     req.open('GET', url, false);
     req.send(null);
     element.innerHTML = req.responseText;

   } 
 else 
   {
     element.innerHTML =
     "Sorry, your browser does not support " +
     "XMLHTTPRequest objects. This page requires " +
     "Internet Explorer 5 or better for Windows, " +
     "or Firefox for any system, or Safari. Other " +
     "compatible browsers may also exist.";
   }
}

//taken from JavaScript & DHTML Cookbook
//http://www.oreillynet.com/pub/a/javascript/excerpt/JSDHTMLCkbk_chap5/index5.html
function getElementStyle(elemID, IEStyleProp, CSSStyleProp) 
{
  var elem = document.getElementById(elemID);
  if (elem.currentStyle) 
    {
      return elem.currentStyle[IEStyleProp];
    } 
  else if (window.getComputedStyle) 
    {
      var compStyle = window.getComputedStyle(elem, "");
      return compStyle.getPropertyValue(CSSStyleProp);
    }
  return "";
}

//modified from: http://developer.apple.com/internet/webcontent/dom2ii.html
function inspect_element_properties(element)
{
  var str = "";
  var counter = 0;
  for (var i in element)
  {
    str += i + ": " + element.getAttribute(i) + "       ";
    if(counter == 5)
      {
        str += "\n";
        counter = 0;
      }      
    counter++;
  }
  return str;
}

function roll_over(obj,num)
{
  if(num == 1)
    {
      obj.style.textDecoration='underline';
    }
  if(num == 0)  
    {
      obj.style.textDecoration='none';
    }
}