/*
  This script file contains utilities for working with DHTML layers and CSS2 properties
  for richer client-side GUI. 
  
  Depends on inclusion of events.js script for event handling
    
  For more details please contact Eric Wright - eric.b.wright@verizon.com or eric@rapidsynergy.com
  
*/


var _isCSS, _isW3C, _isIE4up, _isNN4;

/** Must invoke after document is fully loaded */
function browserSniff() {
  //alert("sniff sniff");  
  _isCSS = isDefined("document.body") && isDefined("document.body.style");
  _isW3C = _isCSS && isDefined("document.getElementById");
  _isIE4up = _isCSS && isDefined("document.all");
  _isNN4 = isDefined("document.layers");
  
  /* uncomment to debug * /
  var msg = "";
  msg += ("isCSS: " + _isCSS + "\n");
  msg += ("isW3C: " + _isW3C + "\n");
  msg += ("isIE4up: " + _isCSS + "\n");
  msg += ("isNN4: " + _isNN4 + "\n");
  alert(msg);
  //*/
}

addEventHandler("window", "onload", browserSniff);

/** Accepts name of obj and returns boolean whether exists */
function isDefined(obj) {  
  if (!eval(obj))
    return false;
  else 
    return typeof eval(obj) != "undefined";    
}

function getObject(obj) {
  if (typeof obj == "string") {
    if (document.getElementById)
      return document.getElementById(obj);
    else if (document.all) 
      return document.all(obj);
  } 
  
  return obj; //passthru
}

function canAnimate(obj) {  
  try {
    return (obj.filters[0] && typeof obj.filters[0] != "undefined");
  } catch (e) {
    return false;
  }
}

function prepareAnimate(obj) {
  try {
    if (canAnimate(obj)) 
      obj.filters[0].Apply();
  } catch (e) {
    //abort animate attempt
  }
}

function doAnimate(obj) {
  try {
    if (canAnimate(obj)) 
      obj.filters[0].Play();
  } catch (e) {
    //abort animate attempt
  }
}

function hideObj(obj) {      
  setStyleProperty(obj, "visibility", "hidden");
}  

function showObj(obj) {
  setStyleProperty(obj, "visibility", "visible");  
}

function displayBlockElement(obj, visible) {
	setStyleProperty(obj, "display", (visible) ? "block" : "none");	
}

function setStyleProperty(obj, prop, val) {
  obj = getObject(obj);  
  if (_isW3C || _isIE4up)
    eval("obj.style." + prop + " = \"" + val + "\";");
  //alert(eval("obj.style." + prop + " = '" + val + "'"));
}

function getStyleProperty(obj, prop) {
  obj = getObject(obj);  
  if (_isW3C || _isIE4up)
    return eval("obj.style." + prop);
  else
    return "";
}
