$(document).ready(function(){
        $(".showFilter").fieldtag();
		$("#contact").validate({
		realTime: false,
		messages: {
                zip: "Please enter your zip code <br />",
                name: "Please enter your name <br />",
                address: "Please enter your address <br />",
                city: "Please enter your city <br />",
                state: "Please enter your state <br />",
                phone: "Please enter your phone <br />",
                comments: "Please enter additional comments <br />",
                email: {
                    required:"Please enter your email <br />",
                    email:"Please enter a valid email address <br />",
                }
        },
		"invalidHandler": function(){
            $("#name").fieldtag({standardText: "Name" });
			$("#email").fieldtag({standardText: "Email" });
			$("#address").fieldtag({standardText: "Address" });
			$("#city").fieldtag({standardText: "City" });
			$("#state").fieldtag({standardText: "State" });
			$("#zip").fieldtag({standardText: "Zip Code" });
			$("#phone").fieldtag({standardText: "Phone" });
			$("#comments").fieldtag({standardText: "Comments" });
        },
		"submitHandler": function(form) {
            $.ajax({
                type: "POST",
                url: 'ajax/contact.form.php',
                code: '#txtCode' ,
                data: $(form).serialize() ,
                success: function (data){
                    if( data == 'OK' ) {
                        showPopUp( 'Your Message was succesfully sent!', 'Contact Form' );
						$('#contact').resetForm();
               			$(".showFilter").fieldtag();
                    } else {
						showPopUp( 'There was an error sending your message, please try again', 'Contact Form' );
                    }
				}
            });
		},
        errorPlacement: function(error, element) {
            error.appendTo($("#dialog"));
        },
        showErrors: function(errorMap, errorList){
            this.defaultShowErrors();
            $("#dialog").dialog('open');            
        }
    });

		$( "#dialog" ).dialog({
			title: false,
			autoOpen: false,
			resizable: false,
			height:300,
			modal: true,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function(event, ui){
            $("#dialog").html("");    
        	}
		});
		function showPopUp( msg, title )
		{
			$("#dialog").html( msg );    
			$( "#dialog" ).dialog({
				title: title,
				autoOpen: false,
				resizable: false,
				height:300,
				modal: true,
				buttons: {
					Ok: function() {
						$( this ).dialog( "close" );
					}
				},
				close: function(event, ui){
					$("#dialog").html("");    
				}
			});    
			$("#dialog").dialog( 'open' );
		}
});
