window.addEvent('domready', function(){
	
	/* FUNCTIONS */
	
	// Style setzen
	function SetStyle(Element, valid){
		if(valid){
			Element.style.backgroundColor='#FFFFFF';
			Element.style.color='#4D610C';
		}else{
			Element.style.backgroundColor='#F89E00';
			Element.style.color='#FFF';
		}
	}
	
	/* ENDE */
	
	/* SLIDER */
	var ContactInfo = new Fx.Slide('ContactInfo').hide();
	ContactInfo.element.style.display='block';
	
	var ContactForm = new Fx.Slide('ContactForm');
		
	/* ENDE */
	
	/* AJAX */
	var AjaxSendContact = new CJAjax(CJPath + 'help/ajax/',
	{
		OnComplete: function(Output){		
			try{
				if(Output == 'ERROR'){
					throw new Exception();
				}
				
				if(Output!=1){
					ContactForm.stop();
					ContactForm.slideIn();
					ContactInfo.element.innerHTML='Ups, da gabs ein Problem... Du kannst uns auch direkt eine E-Mail an support@cachejudge.com schicken...';
					ContactInfo.slideIn();
				}
			}catch(e){}
		}
	});
	AjaxSendContact.AddParameter('call', 'SendSupportMail');
	AjaxSendContact.AddParameter('message', '');
	AjaxSendContact.AddParameter('name', '');
						
	/* ENDE */
	
	
	/* EVENTS */
	
	$('ContactSend').addEvent('click', function(){
		var f = false;
		
		if($('ContactEmail').value.length<6){
			SetStyle($('ContactEmail'), false);
			f = true;
		}else{
			SetStyle($('ContactEmail'), true);
		}
		if($('ContactText').value.length<=3){
			SetStyle($('ContactText'), false);
			f = true;
		}else{
			SetStyle($('ContactText'), true);
		}
		
		if(f){
			ContactInfo.element.innerHTML = 'Bitte trag mindestens deine E-Mail-Adresse und deine Nachricht ein!';
			if(!ContactInfo.open){
				ContactInfo.slideIn();
			}
		}else{

			AjaxSendContact.EditParameter('message', $('ContactText').value);
			AjaxSendContact.EditParameter('email', $('ContactEmail').value);
			AjaxSendContact.EditParameter('name', $('ContactName').value);
			AjaxSendContact.CallFull();
			
			ContactForm.slideOut();
			ContactInfo.element.innerHTML = 'Danke für deine Nachricht. Wir werden uns schnellstmöglich darum kümmern.';
			ContactInfo.slideIn();
		}
		
	});
	
	
	
	

});