/* Javascript mit Komortfunktionen */
/* Javascript mit Komortfunktionen */
var debug = 0;

var re = new RegExp ('( |\n|\r|\t)', 'gi') ;

function checkChars(flexID, txtId, targetInput, maxChars){
	if (document.getElementById){
		var txt 		= document.getElementById(txtId + flexID);
		var plaintxt	= txt.value.replace(re,"");
		var counter 	= document.getElementById(targetInput + flexID);
		var spaces 		= txt.value.length - plaintxt.length;
		if (counter.value) { counter.value 	=	maxChars - txt.value.length; }
		else {counter.innerHTML 	=	maxChars - plaintxt.length; }
		if (plaintxt.length > maxChars){ 
			txt.value = txt.value.substring(0, maxChars+spaces);
		}
	}
}

function _check2000Chars(flexID){
	checkChars(flexID, 'nachricht', 'count', 2000);
}

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;
      }
	}
 }

function setHandler( tagType, clsName, eventType, func ){
  var elements = document.getElementsByTagName( tagType );
  for( var t = 0; t < elements.length; t++ ){
      if( elements[t].className.indexOf( clsName ) >= 0 ){
          eval( "elements[t]." + eventType + " = " + func );
      }
  }
}
	
/** Aktuelle Seite markieren
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function RR_activatePageLink(){
	var ilink;
	var wlink			= window.location.href;
	var txtlinks = document.getElementsByTagName("li");
	for (var i=0; i<txtlinks.length; i++){
			if (txtlinks[i].className == "txt"){
				ilink = txtlinks[i].firstChild.getAttribute('href');
				if (wlink.indexOf(ilink) > -1){
					txtlinks[i].className = "active";
						txtlinks[i].setAttribute('active','true');
				}
			} else if (txtlinks[i].className == "img"){
				ilink = txtlinks[i].firstChild.getAttribute('href');
				if (wlink.indexOf(ilink) > -1){
					txtlinks[i].firstChild.className = "active";
					txtlinks[i].setAttribute('active','true');
				}
			}
	}
}

/** Textlink aktivieren
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function indtxt(){
	var lid = this.getAttribute('id');
	var txtlinks = document.getElementsByTagName("li");
	for (var i=0; i<txtlinks.length; i++){
		if (txtlinks[i].getAttribute('id') == "a"+lid){

			txtlinks[i].className = "active";
		} 
	}
}

/** Textlink deaktivieren (falls nicht aktuelle Seite)
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function deindtxt(){
	var txtlinks = document.getElementsByTagName("li");
	for (var i=0; i<txtlinks.length; i++){
			if (txtlinks[i].getAttribute('active') != 'true' && hasClass(txtlinks[i]) == "active"){
				txtlinks[i].className = "inactive";
			}
	}
}

/** Kartenlink aktivieren
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function indmap(){
	var lid = this.getAttribute('id').substr(1);
	var imglinks = document.getElementsByTagName("li");
	for (var i=0; i<imglinks.length; i++){
		if (imglinks[i].getAttribute('id') == lid){
				imglinks[i].firstChild.className = "active";
		} 
	}
}

/** Kartenlink deaktivieren (falls nicht aktuelle Seite)
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function deindmap(){
	var imglinks = document.getElementsByTagName("li");
	for (var i=0; i<imglinks.length; i++){
				if (imglinks[i].getAttribute('active') != 'true' && hasClass(imglinks[i]) != null){
						imglinks[i].firstChild.className = "inactive";
				}
	}
}

/** Handler zuweisen
 * @package: rathausrundgang
 * @author: NEW IMAGE GmbH <moder@n-image.com>
 * @date: 08/11/2005
 */
function RR_initHandlers(){
	setHandler( 'li', 'img', 'onmouseover', 'indtxt' );
	setHandler( 'li', 'img', 'onmouseout', 'deindtxt' );
 	setHandler( 'li', 'txt', 'onmouseover', 'indmap' );
 	setHandler( 'li', 'txt', 'onmouseout', 'deindmap' );
}
