
$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

function SubmitForm() 
{
	//Get the data from all the fields   
	var Name = $('#Name');   
	var Company = $('#Company');   
	var Request = $('#Request');   
	var Phone = $('#Phone'); 
	var Email = $('#Email');
	//var targetOffset = $('#Anmeldeformular').offset().top;
	
	//Simple validation to make sure user entered something   
	//If error found, add hightlight class to the text field   
	if (Name.val()=='') {   
		Name.addClass('highlight');  
		return false;   
	} else Name.removeClass('highlight');   
	          
	if (Company.val()=='') {   
		Company.addClass('highlight'); 	
		return false;   
		} else Company.removeClass('highlight');   
	        
	if (Phone.val()=='' && Email.val()=='') {   
		Phone.addClass('highlight'); 
		Email.addClass('highlight'); 
		return false;   
	} else {
		Phone.removeClass('highlight');  
		Email.removeClass('highlight'); 
	}
	
	if (Request.val()=='') {   
		Request.addClass('highlight');
		return false;   
	} else Request.removeClass('highlight');
	
	var dataString = $('#Contactform').serialize();
	//alert(dataString);
	$.ajax({  
		type: "POST",  
		url: "/includes/postForm.php",  
		data: dataString,  
		success: function(data, textStatus) { 
		  			$('#Formular').slideUp("normal");				   
					$("#Response").html(data);
					$("#Response").fadeIn("slow");	
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
		  			$('#Formular').slideUp("normal");
					$("#Response").html("<h3>Error sending contact request</h3>" + 
										textStatus + ": " + errorThrown + 
										"<br/>Please try again later.<br/>" + 
										XMLHttpRequest);
					$("#Response").fadeIn("slow");
		}
	});  
	return false;
	
	
	
}