$(document).ready(function(){
	
	
	
	
		// Dialog			
				$('#dialog').dialog({
					autoOpen: false,
					width: 600,
					buttons: {
						"Schließen": function() { 
							$(this).dialog("close"); 
						} 
					}
				});
				
			$('#dialog2').dialog({
					autoOpen: false,
					width: 300,
					buttons: {
						"Schließen": function() { 
							$(this).dialog("close"); 
						} 
					}
				});
				
				// Dialog Link
				$('#dialog_link').click(function(){
					$('#dialog').dialog('open');
					return false;
				});
				
				//hover states on the static widgets
				$('#dialog_link, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); }, 
					function() { $(this).removeClass('ui-state-hover'); }
				);
	
	
	


  $('.contactForm').submit( function(){
 
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('email');
		var vorname = document.getElementById('vorname');
		var name = document.getElementById('name');
		// required fields
		if (!filter.test(email.value)) {$('#email').addClass('error');} else {$('#email').removeClass('error');}	
		if (document.cform.name.value == "") { $('#name').addClass('error');} else {$('#name').removeClass('error');}	
		if (document.cform.vorname.value == "") { $('#vorname').addClass('error');} else {$('#vorname').removeClass('error');}
		// check fields
		if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.vorname.value == "")){return false;} 
		
		
		if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.vorname.value != "")) {		
			$.post('mail.php',
			{
				vorname: $('#vorname').val(), 
				strabe: $('#strabe').val(), 
				nr: $('#nr').val(), 
				email: $('#email').val(), 
				name: $('#name').val(), 
				ort: $('#ort').val(), 
				plz: $('#plz').val(), 
				telefon: $('#telefon').val()
			},
			function(data){$('#dialog2').empty().html(data).dialog('open')});
			$("input").val("");
			return false;
		} 
  });
  
	
});

