$(function() {
    var dialogObject = {
        bgiframe: true,
        autoOpen: false,
        width: 500,
        height: 400,
        modal: true,
        buttons: {
            Close: function() {
                $dialogCouplingForm.dialog('close');
            }
        }
    }

    var $dialogCouplingForm = $('#dialog').dialog(dialogObject);

    $('#coupling-form-image-link').click(function() {
        $dialogCouplingForm.dialog('open');
        return false;
    });
});




$(document).ready(function() {

    function processJson(objData) {

        var arrSuccessMessages = new Array();
        var arrErrorMessages = new Array();

        arrSuccessMessages = objData[0];
        arrErrorMessages = objData[1];

        //Are there any error messages?
        var intErrorMessages = arrErrorMessages.length;

        if (intErrorMessages > 0)
        {
            var strHtml = '';

            strHtml += '<ul>';

            for (var intIndex = 0; intIndex < intErrorMessages; intIndex++)
            {
                strHtml += '<li>' + arrErrorMessages[intIndex] + '</li>';
            }

            strHtml += '</ul>';

            $('#form-error-messages').html(strHtml);
        }
        else
        {
            $('#dialog').html('<p>Thank you for your enquiry.</p><p>Someone will be in touch as soon as possible.</p>');
        }
    }

    // bind form using ajaxForm
    $('#frmCoupling').ajaxForm({
        // dataType identifies the expected content type of the server response
        dataType:  'json',

        // success identifies the function to invoke when the server response
        // has been received
        success:   processJson
    });
});