﻿$(function() {
    $('#slideshow').cycle({
        fx: 'fade',
        timeout: 7000,
        speed: 3000
    });

    $("#phone").mask("(999) 999-9999? x99999");

    $("#contact").validationEngine({
        ajaxSubmit: true,
        ajaxSubmitFile: "/Ajax/QuickQuote.aspx",
        ajaxSubmitMessage: "Success",
        success: function() {
            $("#fname").val('');
            $("#lname").val('');
            $("#email").val('');
            $("#phone").val('');
            $("#loanType").val('');
            $("#credithist").val('');
            var googleConversion = $('<img />').attr('src', 'http://www.googleadservices.com/pagead/conversion/1061728261/?label=6I_QCLvHxgEQheCi-gM&amp;guid=ON&amp;script=0');
            showSuccess('Thank You', 'Your information has been successfully submitted. A representative will be in contact with your shortly.');
        },
        failure: function() {
            hideStatus();
            //showError();
        }
    });

    $("#status_dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        height: 200,
        resizable: false
    });

    $("#success_dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        height: 200,
        resizable: false,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });

    $("#error_dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        modal: true,
        height: 200,
        resizable: false,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
            }
        }
    });
});

function showStatus(title, message) {
    if (title != null && title != '')
        $("#status_dialog").attr({ 'title': title });

    if (message != null && message != '')
        $("#status_dialog_message").html(message);

    $("#status_dialog").css({ 'visibility': 'visible' });
    $("#status_dialog").dialog('open');
}

function hideStatus() {
    $("#status_dialog").dialog('close');
}

function showSuccess(title, message) {
    hideStatus();
    
    if (title != null && title != '')
        $("#success_dialog").attr({ 'title': title });

    if (message != null && message != '')
        $("#success_dialog_message").html(message);

    $("#success_dialog").css({ 'visibility': 'visible' });
    $("#success_dialog").dialog('open');
}

function showError(title, message) {
    hideStatus();

    if (title != null && title != '')
        $("#error_dialog").attr({ 'title': title });

    if (message != null && message != '')
        $("#error_dialog_message").html(message);

    $("#error_dialog").css({ 'visibility': 'visible' });
    $("#error_dialog").dialog('open');
}