// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
  var n = document.getElementById(i);
  n.style[p] = v;
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
  var n = document.getElementById(i);
  var s = eval("n.style." + p);

  // try inline
  if((s != "") && (s != null)) {
    return s;
  }

  // try currentStyle
  if(n.currentStyle) {
    var s = eval("n.currentStyle." + p);
    if((s != "") && (s != null)) {
      return s;
    }
  }
  
  // try styleSheets
  var sheets = document.styleSheets;
  if(sheets.length > 0) {
    // loop over each sheet
    for(var x = 0; x < sheets.length; x++) {
      // grab stylesheet rules
      var rules = sheets[x].cssRules;
      if(rules.length > 0) {
	// check each rule
	for(var y = 0; y < rules.length; y++) {
	  var z = rules[y].style;
	  // selectorText broken in NS 6/Mozilla: see
	  // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
	  ugly_selectorText_workaround();
	  if(allStyleRules) {
	    if(allStyleRules[y] == i) {
	      return z[p];
	    }
	  } else {
	    // use the native selectorText and style stuff
	    if(((z[p] != "") && (z[p] != null)) ||
	       (rules[y].selectorText == i)) {
	      return z[p];
	    }
	  }
	}
      }
    }
  }
  return null;
}


// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

function setDisplayStyleByClass(t,c,v){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
				  node.style.display = v;
				}
			}
		}
	}
}

function getDisplayStyleByClass(t,c){
	 var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
				        var theStyle = node.style.display;
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}
	}
   return null;	
}

function getStyleByClass(t,c,p){
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
                var theStyle = eval('node.style.' + p);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					if((theStyle != "") && (theStyle != null)) {
						return theStyle;
					}
				}
			}
		}
	}
   return null;	
}


function toggleDisplay(c) {
    var sty = getStyleById(c, 'display');
    if (sty == null) 
	offDisplay(c);
    else if (sty == 'none') 
	onDisplay(c);
    else {
	offDisplay(c);
    }
}

function offDisplay(c) {
       setStyleById(c, 'display', 'none');
}

function onDisplay(c) {
    if (ie)
        setStyleById(c, 'display', 'block');
    else        
        setStyleById(c, 'display', 'table-row-group');
}

