function FormValidation(FormName) {
    var RegularExpression = new RegExp(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/);
    var Passed = true
    var HTML = "<ul>";
    $('#ValidationContainer').hide();
    $(FormName).each(function(index) {
        if (this.id == "Email") {
            if (!RegularExpression.test($(this).val())) {
                $(this).addClass("FailedValidation"); Passed = false;
                HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                $('#ValidationContainer').fadeIn();
            }
            else { $(this).removeClass("FailedValidation"); }
        }
        else if (this.id == "Name") {
            if ($(this).val() == "") {
                $(this).addClass("FailedValidation"); Passed = false;
                HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                $('#ValidationContainer').fadeIn();
            }
            else { $(this).removeClass("FailedValidation"); }
        }
        else if (this.id == "Comments") {
            if ($(this).val() == "") {
                $('#TextAreaContainer').addClass("FailedValidation"); Passed = false;
                HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                $('#ValidationContainer').fadeIn();
            }
            else { $('#TextAreaContainer').removeClass("FailedValidation"); }
        }
        else
        { }
        $(this).change(function() {

            if (this.id == "Email") {
                if (!RegularExpression.test($(this).val())) {
                    $(this).addClass("FailedValidation"); Passed = false;
                    HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                    $('#ValidationContainer').fadeIn();
                }
                else { $(this).removeClass("FailedValidation"); }
            }
            else if (this.id == "Name") {
                if ($(this).val() == "") {
                    $(this).addClass("FailedValidation"); Passed = false;
                    HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                    $('#ValidationContainer').fadeIn();
                }
                else { $(this).removeClass("FailedValidation"); }
            }
            else if (this.id == "Comments") {
                if ($(this).val() == "") {
                    $('#TextAreaContainer').addClass("FailedValidation"); Passed = false;
                    HTML = HTML + '<li>' + $(this).attr('title') + '</li>';
                    $('#ValidationContainer').fadeIn();
                }
                else { $('#TextAreaContainer').removeClass("FailedValidation"); }
            }
            else
            { }

        });
    });
    HTML = HTML + '</ul>';
    $('#ValidationMessages').html(HTML);
    return Passed;
}


function AddComment() {
    if (!FormValidation(".GBFormRequired")) { return false; }
    var FormData = $('#GBForm').serialize();

    $.ajax({
        type: "POST", cache: false,
        url: "/Guestbook/Send", dataType: "json", data: FormData,
        //async: false, 
        success: function (gb) {
            //alert(gb.Name); alert(gb.Biz); alert(gb.Email); alert(gb.Comments);
            if (gb.Success == true) {
                $('#GBThanksDiv').hide();
                $('#GBName').html(gb.Name);
                $('#GBThanksDiv').fadeIn();
            } else {
                $('#ValidationMessages').html("<ul><li>Sorry, there has been an error, please try again or email your comments ("+ gb.Message + ").<li></ul>");
                $('#ValidationContainer').show();
            }
        }//, complete: function (gb) { alert(gb); }
    })
}



$(document).ready(function() {
    $(".PopUp").colorbox({
        opacity: 0.4, open: false,
        cache: false,
        overlayClose: false, close: 'close',
        initialWidth: '300px',
        initialHeight: '300px',
        width: '450px',
        height: '460px'
    });

    $(".Residential").colorbox({
        opacity: 0.4, open: false,
        cache: false,
        overlayClose: true, close: 'close',
        initialWidth: '300px',
        initialHeight: '300px',
        width: '450px',
        height: '535px'
    });
    


    $(".map").colorbox({
        opacity: 0.4, overlayClose: true, close: 'close',
        initialWidth: '300px', initialHeight: '300px', cache: false,
        width: '700px',
        height: '480px'
    });

    $(".Gallery").colorbox({ opacity: 0.4, initialWidth: '300px', initialHeight: '300px', cache: false,
        width: '700px', height: '480px'
    });

    $().bind('cbox_complete', function() {
        $('#ValidationContainer, #GBThanksDiv').corner().hide();
        $('.ResidentialImage').corner();
    });


});
