﻿function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}
$(function () {
    $('#slideshow').cycle({
        fx: 'fade',
        sync: true,
        speed: 700,
        timeout: 14000,
        pager: '#slidenav',
        before: function () {
            $('#caption').html(this.alt);
        }
    });
});
function hideLoading() {

    document.getElementById('divLoading').style.display = "none";
    document.getElementById('theframe').style.display = "block";

}

$(document).ready(function () {
    $('#slidenav').css('left', '470px');
    // validate the mortgage form when it is submitted
    $("#mortgage-form").validate({
        rules: {
            zipcode: {
                required: true,
                postalcode: true
            }
        },
        messages: {
            zipcode: ""
        }
    });

    //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");

    //dialog boxes for newsletter submit.
    $(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');
    };
});



