function showHide(elem)
{
  var element = document.getElementById(elem);
  if(element.style.display == 'block' || element.style.display == '' )
    {
      element.style.display = 'none';
    }
  else
    {
      element.style.display = 'block';
    }
  return false;
}

/**
 * Toggle display between to elements
 */
function showHimHideMe(him, me) {
	var show = document.getElementById(him);
	var hide = document.getElementById(me);
	show.style.display = 'block';
	hide.style.display = 'none';
}
/**
 * Function for removing contents from an element.
 */
function removeContents(removediv)
{
  if(removediv=='calendarbody') { removediv = 'calendar'; }
  document.getElementById(removediv).innerHTML = '';
}

/**
 * Mutually exclusive showHide between different css classes who all share a common class.
 * Function is activated by an 'active' class. If this class is hidden the function makes
 * active class visible and all other classes who are also in shared class hidden.
 * (works like a file menu)
 */
function showHideOthers(parent, commonClass, activeClass) {
	var commonElms = document.getElementsByClassName(commonClass, parent);
	var activeElms = document.getElementsByClassName(activeClass, parent);
	if(Element.hasClassName(activeElms[0], 'displayblock')) {
		// Active class i visible, so just hide it
		for(var i = 0; i < activeElms.length; i++) {
			Element.removeClassName(activeElms[i], 'displayblock');
			Element.addClassName(activeElms[i], 'displayhidden');
		}			
	}
	else {
		// Hidden, so show active class and hide all other elements in commonClass except active
		for(var i = 0; i < commonElms.length; i++) {
			if(Element.hasClassName(commonElms[i], activeClass)) {
				Element.addClassName(commonElms[i], 'displayblock');
				Element.removeClassName(commonElms[i], 'displayhidden');			
			}
			else {
				Element.removeClassName(commonElms[i], 'displayblock');
				Element.addClassName(commonElms[i], 'displayhidden');			
			}
		}
	}	
}

function toggleImg(elem, id) {
	if(document.getElementById(id).style.display == 'none') {
		elem.src = elem.src.replace( /expand/, 'unexpand');
	} else {
		elem.src = elem.src.replace( /unexpand/, 'expand');
	}
}

/**
 * Modified function from suckerfish (http://www.htmldog.com/articles/suckerfish/hover/)
 * Now accepts parameters for dynamic css class, classname of table to stripe and rows to avoid striping
 */
sfHover = function(stripeClassName, hoverClass, avoidClassName) {
	var sfEls = document.getElementsByClassName(stripeClassName);
	for (var i=0; i<sfEls.length; i++) {
		var rows = sfEls[i].getElementsByTagName("TR");
		for(var j=0;j<rows.length;j++) {
			rows[j].onmouseover=function() {
				this.className+=" " + hoverClass;
			}
			rows[j].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" "+hoverClass+"\\b"), "");
			}
		}     
	} 
}

/**
 * Puts "zebra-stripes" on all tables of class tableClassName
 */
function zebraStripeRows(tableClassName) {
	if (!document.getElementsByTagName || !document.getElementsByClassName) return;
	var elems = document.getElementsByClassName(tableClassName);
	for(var i=0; i<elems.length;i++) {
		var tr = elems[i].getElementsByTagName('tr');
		for (var j=0;j<tr.length;j++) {
    		if (j%2) {
            	tr[j].className = 'tr_odd';
			}
			else
			{
				tr[j].className = 'tr_even';
			}
		}
	}
}

  // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#EDF3FE";
    var oddColor = arguments[2] ? arguments[2] : "#fff";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
