﻿/*	
*/
var global = new Object();

function attachPopUps () {
    var as = document.getElementsByTagName('a');
    for (var i in as)
    {
        if (as[i].id == 'popup')
        {
            YAHOO.util.Event.addListener(as[i],'click',open_popup);
        }
        if (as[i].href && as[i].href.indexOf('attach=1') != -1)
        {
            YAHOO.util.Event.addListener(as[i],'click',open_popup);
        }
        if (as[i].href && as[i].href.indexOf('standard_attach') != -1)
        {
            YAHOO.util.Event.addListener(as[i],'click',open_popup);
        }
        if (as[i].className == 'popup_link')
        {
            YAHOO.util.Event.addListener(as[i],'click',open_popup2);
        }
    }
}

function check_kontakt_form (e) {
	
    	YAHOO.util.Event.preventDefault(e);
    	
   		var error = '';
			var copy = false;
			
			if (document.getElementById("partner").value == "") {
				document.getElementById("partnerd").className = "error";
				var error = true;	
			}
			else {
				document.getElementById("partnerd").className = "description";
			}
			
			if (document.getElementById("phone").value == "") {
				document.getElementById("phoned").className = "error";
				var error = true;	
			}
			else {
				document.getElementById("phoned").className = "description";
			}
			
			if (document.getElementById("email").value == "") {
				document.getElementById("emaild").className = "error";
				var error = true;	
			}
			else {
				document.getElementById("emaild").className = "description";
			}
			
			if (document.getElementById("message").value == "") {
				document.getElementById("messaged").className = "error";
				var error = true;	
			}
			else {
				document.getElementById("messaged").className = "description";
			}
			
			if (document.getElementById("copy").value == "on") {
				copy = true;
			}
			
			if (error != '') {
			    alert ("Please fill in all mandatory fields.");
			}
			else {
        		jQuery("#dialog-modal").dialog({
        			resizable: false,
        			width: 460,
        			height: 85,
        			modal: true
        		});
				this.submit();
			}
} 

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function check_download_form(e) {
	
		YAHOO.util.Event.preventDefault(e);
		var error = false;
		
		if (document.getElementById("email").value == "") {
			document.getElementById("mail").className = "error";
			var error = true;
		}
		else {
			document.getElementById("mail").className = "description";
		}
		
		if (/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/.test(document.getElementById("email").value) == false) {
			document.getElementById("mail").className = "error";
			var error = true;	
		}
		else {
			document.getElementById("mail").className = "description";
		}
		
		if (trim ( document.getElementById("pw").value ) == "") {
			document.getElementById("pwd").className = "error";
			var error = true;	
		}
		else {
			document.getElementById("pwd").className = "description";
		}
		
		if (trim ( document.getElementById("check_pw").value ) == "") {
			document.getElementById("check_pwd").className = "error";
			var error = true;	
		}
		else {
			document.getElementById("check_pwd").className = "description";
		}
		
		if (document.getElementById("pw").value != "" && document.getElementById("check_pw").value != "") {
			if (document.getElementById("pw").value != document.getElementById("check_pw").value) {
				alert ("The entered passwords differ.\nPlease enter your passwords one more time.");
				document.getElementById("check_pwd").className = "error";
				document.getElementById("pwd").className = "error";
				var error = true;	
			}	
		}
				
		if (document.getElementById("brandmaker").value == "Sonstiges") {
			if (trim ( document.getElementById("sonstiges").value ) == "") {
				document.getElementById("sonst").className = "error";
				var error = true;	
			}
		}
		
		if (error != '') {
			alert ("Please fill in all madatory fields.");
		}
		else {
	        jQuery("#dialog-modal").dialog({
    			resizable: false,
    			width: 460,
    			height: 85,
    			modal: true
    		});
			document.forms[0].submit();
		}
}


YAHOO.util.Event.addListener(window,'load',attachPopUps);
YAHOO.util.Event.addListener('form_kontakt','submit',check_kontakt_form);
YAHOO.util.Event.addListener('form_download','submit',check_download_form);

function open_popup (e) 
{
    YAHOO.util.Event.preventDefault(e);
   	window.open(this.href, 'popup', 'width=960, height=660, scrollbars=no, location=no, menubar=no, toolbar=no, resizable=no');
    return false;
}

function open_popup2 (e) 
{
    var popup = { width:0,height:0 };
    if (this.href.indexOf('workspace') > -1) {
	popup.width = 1280;
	popup.height = 1024;
    }
    else {
	popup.width = 1024;
	popup.height = 768;
    }
    YAHOO.util.Event.preventDefault(e);
    var popup2 = window.open(this.href, 'popup2', 'width='+popup.width+', height='+popup.height+', scrollbars=yes, location=yes, menubar=yes, toolbar=yes, resizable=yes');
    return false;
}

function display_content () 
{		
		var link_middle = document.getElementById("navigation");
		var inhalt = document.getElementById("inhalt");
		var inhalt_text = document.getElementById("inhalt_text_vis");

		var max_height = 615; //660px-20px-15px-10px;
		
		var count = 0;				
		var Knoten = document.getElementById("navigation").firstChild;
		while (Knoten != null) 
		{
			if (Knoten.id != null) 
		  {
		  	if (Knoten.id.length != 0) {
		  	 count++;
		  	 }
		  }
		  Knoten = Knoten.nextSibling;  
		}
		
		for (var i = 0; i < count; i++) 
		{
			if (document.getElementById("link"+[i]) != '') 
			{	
				if (document.getElementById("link"+[i]).className == "link_active") 
				{
						document.getElementById("scrollbar1").style.visibility = "hidden";
						if (document.getElementById("scrollbar3") != null)
						{
								document.getElementById("scrollbar3").style.visibility = "hidden";
						}
						
						//if link is already active, the sliding should be prevented
						if (document.getElementById("middle"+[i]).style.width < "600")
						{
						    var myFx = new Fx.Style("middle"+[i], 'width').start(185,633);
						}
						document.getElementById("inhalt").style.display = "";
						document.getElementById("middle"+[i]).style.background = "#F29400";
						var top = document.getElementById("link"+[i]).offsetTop;
						var left = document.getElementById("link"+[i]).offsetLeft;
														
						top = top + 133 + 43 + 6;
						left = left + 205;

						inhalt.style.top = top+"px";
						inhalt.style.left = left+"px";
						
						var content_height = inhalt_text.offsetHeight+3;
						
						var space = max_height - top; //height for inhalt element
						var space2 = space - 5; //height for text element
						var space3 = space2 - 17; //height for scrollbar
						var space4 = space3 - 13 - 13 - 2; //height for scroller inside scrollbar
						
						// if content is larger than the content area (popup size - header), the content should be cut off
						// and should additionaly be scrollable
						if (content_height > space) 
						{
								document.getElementById("inhalt").style.height = space+"px";
								document.getElementById("inhalt_text").style.height = space2+"px";
								// activate scrollbars
								dw_showLayers("scrollbar1");
  							document.getElementById("scrollbar1").style.height = space3+"px";
  							document.getElementById("track1").style.height = space4+"px";
								document.getElementById("inhalt_bottom").style.top = document.getElementById("inhalt").offsetTop + space + 20 +"px";
								initScrollLayers();

						}
						else 
						{
								document.getElementById("inhalt").style.height = content_height+"px";
								document.getElementById("inhalt_text").style.height = content_height+"px";
								document.getElementById("inhalt_bottom").style.top = document.getElementById("inhalt").offsetTop + content_height + 20 + "px";
						}
					}
				}
			}
			
			if (document.getElementById("impressum_content") != null)
			{
					initScrollLayers2();
			}
			if (document.getElementById("aktion_content") != null)
			{
					initScrollLayers4();
			}			
			if (document.getElementById("video_content") != null)
			{
					videocontent_vis_height = document.getElementById("videocontent_vis").offsetHeight;
					videocontent_height = document.getElementById("videocontent").offsetHeight;
					if (videocontent_vis_height > videocontent_height)
					{
							// activate scrollbars
							dw_showLayers("scrollbar3");
							initScrollLayers3();
					}
			}

}
    	
function mouse_over (value) 
{
		var count = 0;
		var value = parseInt(value);					
		var Knoten = document.getElementById("navigation").firstChild;
		
		while (Knoten != null) 
		{
			if (Knoten.id != null) 
		  {
		  	 count++;
		  }
		  Knoten = Knoten.nextSibling;  
		}

		if (document.getElementById("link"+value) != null) 
		{
			var div_element = document.getElementById("link"+value);
			
			for (var i = 0; i < count; i++) 
			{
					if (document.getElementById("link"+[i]) != null) 
					{
							if (document.getElementById("link"+[i]).className != "link_active") 
							{
									if (document.getElementById("link"+[i]).id == document.getElementById("link"+value).id) 
									{
										document.getElementById("link"+[i]).className = "link_hover";
									}
									else 
									{
										if (document.getElementById("link"+[i]).className == "link_hover") 
										{
											document.getElementById("link"+[i]).className = "link";
										}
										document.getElementById("link"+[i]).className = "link";
									}
							}
					}
			 }
		}
}
    	
function mouse_out (value) 
{
		var div_element = document.getElementById("link"+value);
		
		if (document.getElementById("link"+value).className != "link_active") 
		{
			document.getElementById("link"+value).className = "link";
		}
}
    	
    	
function activate_link(value) 
{
		var count = 0;
		var value = parseInt(value);					
		var Knoten = document.getElementById("navigation").firstChild;
		
		while (Knoten != null) 
		{
			if (Knoten.id != null) 
		  {
		  	 count++;
		  }
		  Knoten = Knoten.nextSibling;  
		}

		if (document.getElementById("inhalt") != null) 
		{
			document.getElementById("inhalt").style.display = "none";
			document.getElementById("inhalt_bottom").style.display = "none";
			var div_element = document.getElementById("link"+value);
			
			for (var i = 0; i < count; i++) 
			{
			    if (document.getElementById("link"+[i]) != null) {
					if (document.getElementById("link"+[i]).id == document.getElementById("link"+value).id) 
					{
						document.getElementById("link"+[i]).className = "link_active";
					}
					else 
					{
						if (document.getElementById("link"+[i]).className == "link_active") 
						{
							document.getElementById("link"+[i]).className = "link";
							var myFx = new Fx.Style("middle"+[i], 'width').set(185);
							document.getElementById("middle"+[i]).style.background = "#9C9C9C";		
						}
						document.getElementById("link"+[i]).className = "link";
						var myFx = new Fx.Style("middle"+[i], 'width').set(185);
						document.getElementById("middle"+[i]).style.background = "#9C9C9C";		
					}
			    }
			}
	 }
}

function kostenlos_hover ()
{
		if (document.getElementById("kostenlos_bg").className == "kostenlos")
		{
				document.getElementById("kostenlos_bg").className = "kostenlos_hover";
		}
}	

function kostenlos_unhover ()
{
		if (document.getElementById("kostenlos_bg").className == "kostenlos_hover")
		{
				document.getElementById("kostenlos_bg").className = "kostenlos";
		}
}

function ansehen_hover ()
{
		if (document.getElementById("ansehen_bg").className == "ansehen")
		{
				document.getElementById("ansehen_bg").className = "ansehen_hover";
		}
}
function ansehen_unhover ()
{
		if (document.getElementById("ansehen_bg").className == "ansehen_hover")
		{
				document.getElementById("ansehen_bg").className = "ansehen";
		}
}
    	
/*************************************************************************
  This code is from Dynamic Web Coding at www.dyn-web.com
  Copyright 2001-4 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function initScrollLayers() 
{
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
      var wndo1 = new dw_scrollObj('inhalt_text', 'inhalt_text_vis', null);
			
  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
      wndo1.setUpScrollbar("dragBar1", "track1", "v", 0, 1);
  // Read instructions if your scrolling layers are inside tables 
}

function initScrollLayers2() 
{
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
			var wndo2 = new dw_scrollObj('impressum_text', 'impressum_text_vis', null);
			
  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
			wndo2.setUpScrollbar("dragBar2", "track2", "v", 0, 1);
  // Read instructions if your scrolling layers are inside tables 
}

function initScrollLayers3() 
{
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
			var wndo3 = new dw_scrollObj('videocontent', 'videocontent_vis', null);
			
  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
			wndo3.setUpScrollbar("dragBar3", "track3", "v", 0, 1);
  // Read instructions if your scrolling layers are inside tables 
}

function initScrollLayers4() 
{
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content (table?)
			var wndo4 = new dw_scrollObj('aktion_text', 'aktion_text_vis', null);
			
  // arguments: dragBar id, track id, axis ("v" or "h"), x offset, y offset
  // (x/y offsets of dragBar in track)
			wndo4.setUpScrollbar("dragBar4", "track4", "v", 0, 1);
  // Read instructions if your scrolling layers are inside tables 
}

function dw_showLayers() 
{
  if ( document.getElementById ) 
  {
    var lyr, i;
    for (i=0; arguments[i]; i++) 
    {
      lyr = document.getElementById( arguments[i] );
      lyr.style.visibility = "visible";
    }
  }
}

function toggle_dropdown(event) {
   	   	 
	   	event = event || window.event
	  	var clickedElem = event.target || event.srcElement
 			
 			/* //closing all other ExpandNodes when clicking on one
	    var ul_len = document.getElementsByTagName("li").length;
		  for (var i = 0; i < ul_len; i++)
		  {
		  		if (document.getElementsByTagName("li")[i].className == 'ExpandOpen' && document.getElementsByTagName("li")[i] != clickedElem.parentNode)
		  		{
		  				document.getElementsByTagName("li")[i].className = 'ExpandClosed';
		  		}	
		  }
		 */
		 
		 if (!hasClass(clickedElem, 'Expand_1')) 
		 {
		      return 
		 }
 
    	var node = clickedElem.parentNode
			var root = clickedElem.parentNode.parentNode;
			var children = root.childNodes;
			for(var i = 0;i<children.length;i++){
			if (hasClass(children[i], 'ExpandOpen' ) && children[i]!=node) {		
			var re =  /(^|\s)(ExpandOpen|ExpandClosed)(\s|$)/
			children[i].className = children[i].className.replace(re, '$1'+'ExpandClosed'+'$3')
		}
	}
	
    if (hasClass(node, 'ExpandLeaf')) {
        return 
    }
 
    var newClass = hasClass(node, 'ExpandOpen') ? 'ExpandClosed' : 'ExpandOpen'
    
    var re =  /(^|\s)(ExpandOpen|ExpandClosed)(\s|$)/
    node.className = node.className.replace(re, '$1'+newClass+'$3')
}
 
 function hasClass(elem, className) {
    return new RegExp("(^|\\s)"+className+"(\\s|$)").test(elem.className)
}
