function deselect() {
	var current_domain = document.domain;
	
	Cookie.write('selectedMenu', '', {domain: current_domain, duration: 1, path: '/'});
	Cookie.write('selectedSubMenu', '', {domain: current_domain, duration: 1, path: '/'});
}

function setSelectedMenu(obj, _header) {
	Cookie.dispose('selectedSubMenu');
	Cookie.dispose('selectedMenu');
	
	var current_domain = document.domain;
	
	if (_header != '') {
		Cookie.write('selectedMenu', obj.innerHTML, {domain: current_domain, duration: 1, path: '/'});
		Cookie.write('selectedSubMenu', '', {domain: current_domain, duration: 1, path: '/'});
	} else {
		Cookie.write('selectedSubMenu', obj.innerHTML, {domain: current_domain, duration: 1, path: '/'});
		Cookie.write('selectedMenu', $(obj).getParent().getParent().getParent().getElement('a').innerHTML, {domain: current_domain, duration: 1, path: '/'});
	}
	
}

var menu=function(){
  
	var t=15,z=50,s=6,a;
	function dd(){
    this.n='menu'; this.h=[]; this.c=[]
  }
  
	dd.prototype.init=function(p,c){
		a=c; var w=$(p), s=w.getElements('ul'), l=s.length, i=0;
		for(i;i<l;i++){
      
			var h=s[i].getParent(); this.h[i]=h; this.c[i]=s[i];
      h.rel=i
			
			
      
      
			if (Cookie.read('selectedMenu') == h.getElement('a').innerHTML) {
				
				h.addEvents({
	        'mouseenter': function(num){
	          menu.st(this,true);
	        }
	      });
				h.fireEvent('mouseenter');
			} else {
				h.addEvents({
	        'mouseenter': function(num){
	          menu.st(this,true);
	        },
	        'mouseleave': function(num){
							menu.st(this);
	        }
	      });
			}
			
			//h.onmouseover=new Function('menu.st('+i+',true)');
			//h.onmouseout=new Function('menu.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
    x=x.rel;
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
    

		if(f){
      clearInterval(c.t); c.style.overflow='hidden';
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{
      
      make_transition=1;
      
      if(c.className=='four no_drop'){
        make_transition=0;
      }
      
      if(c.className=='three no_drop'){
        make_transition=0;
      }
      if(c.className=='two no_drop'){
        //console.log(c);
        make_transition=0
      }
      if(c.className=='one'){
        if(getElement('ul').className=='two no_drop'){
          make_transition=0  
        }
      }
      if(make_transition==1){
        clearInterval(c.t); c.style.overflow='hidden';
        p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)
      }
      
    }
	}
  
	function sl(c,f){
		var h=c.offsetHeight;
    
		if((h<=2&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
      {
			  clearInterval(c.t); return
      }
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; 
    
    c.style.filter='alpha(opacity='+(o*100)+')';
    e=0;
      
      if(h+(d*f)==1){
        c.style.height='0px';
        e=1;
      }      
      if(h+(d*f)==2){
        c.style.height='0px';
        e=1;
      }      
      if(h+(d*f)==3){
        c.style.height='1px';
        e=1;
      }      
      if(h+(d*f)==4){
        c.style.height='2px';
        e=1;
      }      
      if(h+(d*f)==5){
        c.style.height='3px';
        e=1;
      }      
      if(h+(d*f)==6){
        c.style.height='5px';
        e=1;
      }
      if(h+(d*f)==7){
        c.style.height='6px';
        e=1;
      }
      if(h+(d*f)==8){
        c.style.height='7px';
        e=1;
      }
      if(h+(d*f)==9){
        c.style.height='8px';
        e=1;
      }
      if(h+(d*f)==10){
        c.style.height='9px';
        e=1;
      }
      if(e==0){
        c.style.height=h+(d*f)+'px';
      }
	}
	return{dd:dd}
}();


function submit_form() {
	
	var form_elems = new Array();
	
  vars = '';
	var i = 0;
  $$('form input').each(function(el) {
		form_elems[i] = el;
		i++;
    vars = vars+el.name+'='+el.value+'&';
  });
  
	vars = vars + 'message=' + $('bemerkung').value;
	
	var selects = $$('form select').get('value').toString().split(',');
	
	vars = vars+ '&erreichbarkeit=' + selects[0] + '&anfrage=' + selects[1];
	
	var j = 0;
	var errors = new Array();
	
	if ( (form_elems[0].name == 'vorname') && (form_elems[0].value == '') ) {
		errors[j] = 'Vorname Feld ist zwingend erforderlich';
		j++;	
	}
	
	if ( (form_elems[1].name == 'nachname') && (form_elems[1].value == '') ) {
		errors[j] = 'Nachname Feld ist zwingend erforderlich';
		j++;	
	}
	
	if ( (form_elems[6].name == 'email') && (form_elems[6].value == '') ) {
		errors[j] = 'E-mail Feld ist zwingend erforderlich';
		j++;	
	}
	
	if (typeof(errors[0]) != 'undefined') {
		alert(errors.join("\n"));
		return false;
	}
  var req = new Request({
    url: BASE_URL + 'sendmail.php',
    method: 'post',
    noCache: true,
    onSuccess: function(text) {
			/*
			$('bemerkung').value = '';
			$$('.contact_form form input').each(function(el) {
				if (el.type != 'submit') {
					if (el.type == 'radio') {
						el.checked = false;
					} else {
						el.value = '';
					}
				}
			});
			*/
			alert('Vielen Dank. Ihre Nachricht wurde erfolgreich gesendet.');
    }
  });
  req.send(vars);
}

