function $(objID){  
    return document.getElementById(objID);  
} 
// As mentioned at http://en.wikipedia.org/wiki/XMLHttpRequest
if( !window.XMLHttpRequest ) XMLHttpRequest = function()
{
  try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
  try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
  try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
  try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
  throw new Error("Could not find an XMLHttpRequest alternative.")
};


// Makes an AJAX request to a local server function w/ optional arguments
//
// functionName: the name of the server's AJAX function to call
// opt_argv: an Array of arguments for the AJAX function
function Request(function_name, opt_argv) {

  // If optional arguments was not provided, create it as empty
  if (!opt_argv)
    opt_argv = new Array();
        
  // Find if the last arg is a callback function; save it
  var callback = null;
  var len = opt_argv.length;
  if (len > 0 && typeof opt_argv[len-1] == 'function') {
    callback = opt_argv[len-1];
    opt_argv.length--;
  }
  var async = (callback != null);
                         
  // Encode the arguments in to a URI
  var query = 'action=' + encodeURIComponent(function_name);
  for (var i = 0; i < opt_argv.length; i++) {
    var key = 'arg' + i;
    var val = JSON.stringify(opt_argv[i]);
    query += '&' + key + '=' + encodeURIComponent(val);
  }
  query += '&time=' + new Date().getTime(); // IE cache workaround

  // See http://en.wikipedia.org/wiki/XMLHttpRequest to make this cross-browser compatible
  var req = new XMLHttpRequest();

  // Create a 'GET' request w/ an optional callback handler 
  req.open('GET', '/rpc?' + query, async);
                                        
  if (async) {
    req.onreadystatechange = function() {
      if(req.readyState == 4 && req.status == 200) {
          var response = null;
          try {
            response = JSON.parse(req.responseText);
          } catch (e) {
            response = req.responseText;
          }
          callback(response);
      }
    }
  }
  // Make the actual request
  req.send(null);
}

function InstallFunction(obj, name) {
  obj[name] = function() { Request(name, arguments); }
}

function showPopover(popoverHtml) {
  var div = document.getElementById('newContact');
  div.style.display='block';
  userInfoDiv = document.getElementById('newContactDetails')
  userInfoDiv.innerHTML = popoverHtml;
  return false;
}

function hidePopover() {
  var div = document.getElementById('newContact');
  div.style.display='none';
  return false;
}

function block_hide(block_element, hide_element) {
     var element = document.getElementById(block_element);
     if (element) {
       element.style.display = 'block';
     } 
     var element = document.getElementById(hide_element);
     if (element) {
       element.style.display = 'none';
     } 
}

var InDiv = 0;
var InAvailable = 0;
function showSelectBox(elem)
{
        elm = document.getElementById(elem);
        elm.style.display = elm.style.display == 'block' ? 'none' : 'block';
}

function setInDiv(val)
{
        InDiv = val;
}
function setInAvailable(val)
{
        InAvailable = val;
}

function checkDiv(elem)
{
        elm = document.getElementById(elem);

        if(InDiv == 0 && !InAvailable)
                elm.style.display = 'none';
}
function womOn(){
  window.onload = womGo;
}
function womGo(){
  for(var i = 0;i < woms.length;i++)
    eval(woms[i]);
}
function womAdd(func){
  woms[woms.length] = func;
}
var woms = new Array();
