// @id $Id: ni_scripts.js,v 1.7 2007/01/15 09:59:33 jan Exp $
// Copyright (c) NEW IMAGE GmbH <www.n-image.de>
// 
// @desc: allgemeine Scripts 


function popWindow(src, title, params){ // V1.0 25.01.2005
	var win = window.open(src, title, params);
	win.focus();
}

 // 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(tag,attrib, avalue) { // V1.0 02.02.2005
    // obtain a reference to the desired table
    // if no such table exists, abort
    var tables = document.getElementsByTagName(tag);
    for (var r = 0; r < tables.length; r++){
    	// workaround: getAttribute is kaputt in IE6, see function hasClass()
    	if (tables[r].getAttributeNode(attrib) != null) {
         	if (tables[r].getAttributeNode(attrib).value == avalue){
    			var myTable = tables[r];
	    		// stripe it!
	    		stripeIt(myTable);
    		}
     	}
    	if (tables[r].getAttributeNode(attrib).value == avalue){
    		myTable = tables[r];
    		// stripe it!
    		stripeIt(myTable);
    		
    	}
    }
  }
 
 function stripeIt(table){ // V1.0 02.02.2005
     // 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 evenClass = arguments[1] ? arguments[1] : "even";
    var oddClass = arguments[2] ? arguments[2] : "odd";
 
 	// 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];
            if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
              mytd.className = even ? evenClass : oddClass;
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
	}
 }




var et_toggleElements = [];

/* Initialisation */
function et_init() {
    var i, link, id, target, first;
    first = true;
    for (i = 0; (link = document.links[i]); i++) {
        if (/\btoggle\b/.exec(link.className)) {
            id = link.href.split('#')[1];
            target = document.getElementById(id);
            et_toggleElements[et_toggleElements.length] = target;
            if (first) {
                first = false;
                target.style.display = 'block';
            } else {
                target.style.display = 'none';
            }
            link.onclick = et_toggle;
        }
    }
}

function et_toggle(e) {
	
    /* Adapted from http://www.quirksmode.org/js/events_properties.html */
    if (typeof e == 'undefined') {
        e = window.event;
    }
    var source;
    if (typeof e.target != 'undefined') {
        source = e.target;
    } else if (typeof e.srcElement != 'undefined') {
        source = e.srcElement;
    } else {
        return true;
    }
    /* For most browsers, targ would now be a link element; Safari however
       returns a text node so we need to check the node type to make sure */
    if (source.nodeType == 3) {
        source = source.parentNode;
    }
    var id = source.href.split('#')[1];
    var elem;
    for (var i = 0; (elem = et_toggleElements[i]); i++) {
        if (elem.id != id) {
            elem.style.display = 'none';
        } else {
            elem.style.display = 'block';
        }
       
    }

    return false;
}

/* Thanks to Scott Andrew */
function addEvent(obj, evType, fn){
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
	    return false;
    }
}

/* Functions to execute upon load */


window.onload = function(){
	//et_init();
	stripe("table","class","zebra");
}