﻿function clearForm(){
	        document.forms[0].reset();
	        document.getElementById("CommentLabel").style.color='black';
	        document.getElementById("EmailLabel").style.color='black';
}
	    
$(document).ready(function() {
	$("#FeedbackLink").fancybox({
		'titleShow'     : 'false',
		'autoDimensions': 'false',
		'height'        : '800',
		'width'         : '800',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'padding'       : '0',
		'onStart'       : function(){
		    $("#CommentErrorImg").hide();
            $("#EmailErrorImg").hide();
		},
		'onClosed'      : function() {
            $("#CommentErrorImg").hide();
            $("#EmailErrorImg").hide();
        }
	});
	
	$("#FeedbackForm").bind("submit", function() {
        if ($("#comment").val().length < 1) {	                
            document.getElementById("CommentLabel").style.color='red';
            $("#CommentErrorImg").show();
            $.fancybox.resize();
            return false;
        }
        else {
            document.getElementById("CommentLabel").style.color='black';
            $("#CommentErrorImg").hide();
        }
        var emailFilter = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        if (!(emailFilter.test($("#email").val()))) { 
            document.getElementById("EmailLabel").style.color='red';
            $("#EmailErrorImg").show();
            $.fancybox.resize();
            return false;
        }
        else {
            document.getElementById("EmailLabel").style.color='black';
            $("#EmailErrorImg").hide();
        }

        $.fancybox.showActivity();
        $.ajax({
            type: "POST",
            cache: false,
            url: "FormHandler.aspx",
            data: $(this).serializeArray(),
            success: function(data) {
	            $.fancybox(data);
            }
        });
        
        return false;
    });
});
