/* Funktionen fuer Schmidt-kupplung */

var init_done = false; // Zeigt an, ob onLoad bereits erreicht wurde

var zeige_ignore = 0;
var zeige_id = 0;

function zeige(id){
	  // alert("id = " + id + "\nzeige_ignore = " + zeige_ignore );
	  var obj = null;
	  
	  if (id!=0)
	  {
	  	  // Klick auf selben Link wird ggf. ignoriert
     	  if (zeige_ignore == id) {
     	  	// alert("Nichts anzeigen");
     	  	return;
     	  }
        if (obj=document.getElementById("content_"+id)) {
            obj.style.display = "block";
            zeige_ignore = id;
        }
    }
    else
  	{

        for (var i=1; i<50;i++){
          if (obj = document.getElementById("content_"+i)){
            obj.style.display = "none";
          }
        } 
    }
    zeige_id = id;
    
    if (id != 0){
        if (is_gecko || is_safari || is_khtml){
            document.addEventListener("click", retardAus, false);
            
        }
        if (is_ie){
            document.attachEvent("onclick",retardAus);
            
        }
    }
    else {
        if (is_gecko || is_safari || is_khtml){
            document.removeEventListener("click", retardAus, false);
            
        }
        if (is_ie){
            document.detachEvent("onclick",retardAus);
            
        }
    }
}

function unignore()
{
	zeige_ignore = zeige_id;
}

function retardAus()
{
	aus();
	window.setTimeout("unignore()", 100);
}

function aus(){
    zeige(0);
}



function __init(){
	  var obj;
    if (is_ie){
        window.attachEvent("onscroll", verschiebe);
        window.attachEvent("onresize", verschiebe);
    }
    //preloadImages('/dna_images/tmpl_schmidt-kupplung_css/images/pfeil.gif','/dna_images/tmpl_schmidt-kupplung_css/images/pfeil_a.gif');
    if (obj = document.getElementById('footwrap')) {
    	if (is_ie) {
    		obj.style.position = 'absolute';
    		obj.style.bottom = '0px';
    	}
    }
    setDefaults();
    init_done = true;
}

function verschiebe(){
    //alert("test");
    var obj;
    obj = document.getElementById("footwrap");
    obj.style.top = (document.body.scrollTop + document.body.clientHeight - 22) +"px";
}





/* Mouseovers fuer Schmidt-kupplung */

var sichtbar ="";

// MOUSEOVERS

var menu_obj = null;
var timer;
var menu_active = new Array();
var original = new Array();

function getUL (obj){
    var chlds = obj.childNodes;
    for (var i=0; i<chlds.length;i++){
        if (chlds[i].nodeType == 1){
            if (chlds[i].nodeName.toLowerCase() == "ul"){
                return chlds[i];
            }
            var ret = getUL(chlds[i]);
            if (ret){
                return ret;
            }
        }
    }
    return false;
}

function setDefaults(verbose)
{
  lis = document.getElementsByTagName("li");
  for (var i=0;i<lis.length;i++)
  {
  	// Gehört dieses LI überhaupt dazu?
    if (lis[i].parentNode.id.indexOf('main-navigation') != -1)
    {
      if (lis[i].className.indexOf('folder') != -1)
      {
       	var ul = getUL(lis[i]);
     	  var ul_class = '';
     	  var ul_display = 'none';
       	if (ul)
       	{
     	    var ul_class = ul.className;
    	    if (ul_class.indexOf(' active') != -1)
    	    {
    		    ul_display = 'block';
    	    }
    	  }
        original.push(new Array(lis[i], lis[i].className, ul, ul_class, ul_display));
      }
    }
  }
  
  if (verbose)
  {
    var output = 'SetDefaults\n\n';
    for (var k=0; k<original.length; k++)
    {
  	  output += '['+k+'] ';
  	  for (var kk=0; kk<original[k].length; kk++)
  	  {
  		  output += '{'+kk+'}' + original[k][kk] + ' ';
  	  }
  	  output += '\n';
    }
    alert(output);
  }
  
  
}

function restoreAllDefaults()
{
	for (var i=0; i<original.length; i++)
	{
		original[i][0].className = original[i][1];
		if (original[i][2])
		{
			original[i][2].className = original[i][3];
		  original[i][2].style.display = original[i][4];
		}
	}
}

function restoreDefaults(elem)
{
	for (var i=0; i<original.length; i++)
	{
		if (original[i][0] == elem)
		{
  	 	original[i][0].className = original[i][1];
  		if (original[i][2])
	  	{
	  	  original[i][2].className = original[i][3];
  		  original[i][2].style.display = original[i][4];
  	  }
  		return true;
  	}
  }
}

function menu_on(elem)
{
	if (!init_done) return;
	var ul = getUL(elem);
	elem.className = 'folder active';
	if (ul)
	{
	  ul.style.display = 'block';
	}
	
	// Alle anderen Elemente ausblenden
	for (var i=0; i<original.length; i++)
	{
		if (original[i][0] != elem)
		{
		  original[i][0].className = 'folder';
		  if (original[i][2])
		  {
		    original[i][2].className = 'subnavlist';
		    original[i][2].style.display = 'none';
		  }
		}
  }
	
	// alert("menu_on: " + ul);
	window.clearTimeout(timer);
}
			
function menu_kill()
{
  restoreAllDefaults();
}

function menu_off(elem)
{
	menu_obj = elem;
  timer = window.setTimeout('menu_kill()',500);
	// alert("menu_off: " + timer);
}


/* funktionen fuer die Tabellen */

function table_init(id){
    document.getElementById("table_" + id).style.display ="block";
    document.getElementById("table2_" + id).style.display ="none";
    table = document.getElementById(id);
    if (is_ie){
        table.attachEvent("onscroll", tabellenscroll);
        //table.attachEvent("onresize", verschiebe);
    }
    if (is_gecko || is_safari || is_khtml){
        table.addEventListener("scroll", tabellenscroll, false);
            
    }
}

function tabellenscroll(aEvent){
     
    myEvent = aEvent ? aEvent : window.event;
    if (is_gecko || is_safari || is_khtml){
        //var target = myEvent.target;
		var target = this;
    }
    if (is_ie){
        var target = myEvent.srcElement;
    }
    
    while (target.id == ""){
        target = target.parentNode;
    }
    var id = target.id;
    //alert(this.id);
    var spalte = document.getElementById("spalte_" + id);
    spalte.scrollLeft = target.scrollLeft;
    var zeile = document.getElementById("zeile_" + id);
    zeile.scrollTop = target.scrollTop;
}


/* swapHubUrl tauscht das Bild der Nabenform aus */

function swapHub(imgPath, imgFile, imgText)
{
	var elem;
	// alert("swap image to " + imgUrl);
	if (imgFile != '')
	{
		imgUrl = imgPath + 'images/mouseover/' + imgFile;
		var hub_ = new Image();
		hub_.src= imgUrl;
		
		// Bilder ersetzen
		if (elem = document.getElementById('hubImg'))
		{
			elem.src = hub_.src;
		}
		
		// Bildunterschrift ersetzen
		if (elem = document.getElementById('hubTxt').firstChild)
		{
			elem.nodeValue = imgText + ' ';
			// elem.nodeValue = hub.src;
	  }
  }
	return true;
}


function updateHub(quelle)
{
	var elem = document.getElementById('bigimage');
	var img1 = document.getElementById('bigHub');
	var img2 = quelle;
	var img3 = document.getElementById('hubImg');
	//alert ("kleines Bild: " + img2.width + "grosses Bild: " + img1.width);
	if (elem && img1 && img2 && img3)
	{
		elem.style.left = img2.width - img1.width + 'px';
		//alert (elem.style.left);
                elem.style.top = Math.max(img3.height, img2.height) - img1.height + 'px';
	}
	
}	


function showHub(quelle)
{
	// IE-Bug: erst DIV sichtbar machen, dann verschieben. Ansonsten erscheint das Bild nicht an der richtigen Stelle!
	var elem;
	if (elem = document.getElementById('bigimage'))
	{
		elem.style.display = 'block';
	
	}

	
	updateHub(quelle);
	return true;
}

function hideHub()
{
  var elem;
	if (elem = document.getElementById('bigimage'))
	{
		elem.style.display = 'none';
	}
	return true;
}

var bsp_ignore = false;

function zeigeBsp(id){
	  var obj =null;
	  
	  if (id)
	  {
  	  if (bsp_ignore) return;
		  if (obj = document.getElementById("bestellbeispiel"))
      {
        obj.style.display = "block";
        bsp_ignore = true;
      }
     
    }
    else
  	{
		  if (obj = document.getElementById("bestellbeispiel"))
      {
        obj.style.display = "none";
      }
    }
    
    if (id != 0){
        if (is_gecko || is_safari || is_khtml){
            document.addEventListener("click", retardAusBsp, false);
            
        }
        if (is_ie){
            document.attachEvent("onclick",retardAusBsp);
        }
    }
    else {
        if (is_gecko || is_safari || is_khtml){
            document.removeEventListener("click", retardAusBsp, false);
        }
        if (is_ie){
            document.detachEvent("onclick",retardAusBsp);
        }
    }
}

function unignoreBsp()
{
	bsp_ignore = false;
}

function retardAusBsp() 
{
  ausBsp();
	window.setTimeout("unignoreBsp()", 100);
}
	
function ausBsp(){
	zeigeBsp(0);
}

function anBsp(){
  zeigeBsp(1);
}




/* POPUP-FENSTER */

var popup_width = 600;
var popup_height = 620;
var popup_top = 50;
var popup_left = 50;

function tdcalc_popup() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/tdcalc.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}
function loewe_popup() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/ah_loewe.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}
function cf_popup() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/ah_cf.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}
function legende_cf() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_cf.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_sf() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_sf.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_sk() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_sk.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_loewe() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_loewe.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function tdcalc_popup_en() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/tdcalc_en.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}
function loewe_popup_en() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/ah_loewe_en.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}     
function cf_popup_en() {
  var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/ah_cf_en.html", "tdcalcWnd", "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=no, scrollbars=no");
}    
function legende_cf_en() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_cf_en.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_sf_en() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_sf_en.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_sk_en() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_sk_en.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
function legende_loewe_en() {
	var app = window.open("/dna_images/tmpl_schmidt-kupplung_css/tools/legende_loewe_en.html", "legendeWnd",  "width="+popup_width+", height="+popup_height+", top="+popup_top+", left="+popup_left+", location=no, toolbar=no, resizable=yes, scrollbars=yes");
}
