/* Feedback-Slider (c) 2010 under CCL
Gordon Rockott *** www.rockott.com ***
*/

$(document).ready(function(){

$('body').append('<div id="contactForm"><div id="contact_button" title="Senden Sie uns Ihr Feedback"><div id="close" title="Schliessen"><img src="/feedback/close.png" width="24" height="24" alt="Schliessen"></div></div><div id="contact_Form"><div id="contact_in">Ihre Nachricht an uns:<br><br><form name="feedback" id="feedback" method="post" action="/feedback/mail.php"><div><label for="name">Name:</label> <input id="sname" name="sname" type="text" value="" /></div><div><label for="email">E-Mail:</label> <input id="email" name="email" type="text" value="" /></div><div><label for="comment">Nachricht:</label> <textarea name="comment" id="comment"></textarea></div><div><input type="submit" name="submit" value="Senden"></div></form><div id="erg"></div></div></div></div>');

$("#contact_button").toggle(function() {
				$(this).animate({"marginLeft": "-2px"}, "fast"); 
				$('#contact_Form').animate({"width": "0px"}, "fast").hide(); 
				 $('#feedback').hide();
				 $('#contact_in').hide();
				$('#feedback').clearForm();
				 $('#erg').html('');
				$(this).animate({"marginLeft": "299px"}, "slow"); 
				$('#contact_Form').animate({"width": "300px"}, "slow", function(){
				$('#contact_in').show();
				$('#feedback').slideDown();
				$('#contact_button #close').show();
				}).show();
			}, 
			function() {
			$('#contact_button #close').hide();
				$('#feedback').slideUp('slow', function() {
				$('#erg').html('');
				$('#contact_in').hide();
				$('#feedback').clearForm();
				$('#contact_Form').animate({"width": "0px"}, "fast").hide(); 
				$('#contact_button').animate({"marginLeft": "-2px"}, "fast").animate({"marginLeft": "0px"}, "slow"); 
})
});


 $('#feedback').ajaxForm({

	beforeSubmit: validate,
			type : 'POST',
			url : 'feedback/mail.php',
			dataType : 'json',
			data : {
			uri : window.location.pathname
			},
			success : function(data){
		$('#feedback').hide(0);
		$('#erg').hide(0);
		$('#erg').removeClass().addClass((data.error === true) ? 'untouched' : 'field_ok').text(data.msg).show(500);
		if (data.error === true){
					$('#feedback').show(500);}
		else{
		$('#feedback').clearForm();
		$('#erg').hide(0);
		}
		
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$('#erg').removeClass().addClass('error').text('Fehler!').show(500);
				$('#feedback').show(500);
			}
		});

function validate(formData, jqForm, options) { 

    var form = jqForm[0]; 
    if (!form.sname.value) { 
	$('#sname').addClass('untouched');
        $('#erg').html('Bitte f&uuml;llen Sie die erforderlichen Felder aus!'); 
        return false; 
    } 
	 if (form.sname.value) {$('#sname').removeClass().addClass('field_ok');}
	 
	if (!form.email.value) { 
	$('#email').addClass('untouched');
        $('#erg').html('Bitte f&uuml;llen Sie die erforderlichen Felder aus!'); 
        return false; 
    } 
	 if (form.email.value) {$('#email').removeClass().addClass('field_ok');}
	 
	 
	 if (!form.comment.value) { 
	$('#comment').addClass('untouched');
        $('#erg').html('Bitte f&uuml;llen Sie die erforderlichen Felder aus!'); 
        return false; 
    } 
	 if (form.comment.value) {$('#comment').removeClass().addClass('field_ok');}
	 
    $('#erg').html('Ihre Eingaben werden verarbeitet'); 
}
 
});  
