﻿
$(document).ready(function () {
    //remove target attribute if webkit browser - webkit (chrome, safari) forms will not submit with target attribute.
    if (is_webkit) {
        $('#buyrealestate-form-1').removeAttr('target');
        $('#buyrealestate-form-2').removeAttr('target');
    };

    //Postal code method - not included in validation plugin.
    jQuery.validator.addMethod("postalcode", function (postalcode, element) {
        return this.optional(element) || postalcode.match(/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXYabceghjklmnpstvxy]{1}\d{1}[A-Za-z]{1} ?\d{1}[A-Za-z]{1}\d{1})$/);
    }, "Please specify a valid postal/zip code");

    // validate the top buyrealestate form when it is submitted
    $('#buyrealestate-form-1').validate({
        rules: {
            zipcode: {
                required: true,
                postalcode: true
            }
        },
        submitHandler: function (form) {
            leadFormSubmit();
        }

    });
    // validate the bottom buyrealestate form when it is submitted
    $('#buyrealestate-form-2').validate({
        rules: {
            zipcode: {
                required: true,
                postalcode: true
            }
        },
        submitHandler: function (form) {
            leadFormSubmit();
        }

    });
    $(function () {
        $("#dialog").dialog({
            autoOpen: false,
            modal: true
        });
        $("#dialog-2").dialog({
            autoOpen: false,
            modal: true
        });
    });
    var myErrorcode = gup('errorcode');
    if (myErrorcode == '0') {
        $("#dialog").dialog('open');
    };
    if (myErrorcode == '2') {
        $("#dialog-2").dialog('open');
    };
});

