﻿(function($) {
    $.fn.vAlign = function() {
        return this.each(function() {
            $this = $(this);
            var ah = $this.height();
            var ph = $this.parent().height();
            var mh = (ph - ah) / 2;
            mh = mh - 4;
            $this.css('margin-top', mh);
        });
    }
})(jQuery);

(function($) {
    $.fn.PrintPage = function() {
        return this.each(function() {
            window.print();
            var settings = {
                tl: { radius: 10 },
                tr: { radius: 10 },
                bl: { radius: 10 },
                br: { radius: 10 },
                antiAlias: true
            }

            curvyCorners(settings, "#headerLogin");

            return false;
        });
    }
})(jQuery);

$(function() {
    $("#headerLogin").vAlign();
    $(".printButton").live("click", function() {
        $(this).PrintPage()
    });
});

$(document).ready(function() {
    /* Event handler for radio buttons on the "Expression of interest" page.  Only selecting "Other" makes
    the text box enabled*/
    $("#departmentTypeSelection input[type=radio]").click(function() {

        if ($(this).val() == 6) {
            $("#departmentTypeSelection input[type=text]").attr('disabled', false);
        }
        else {
            $("#departmentTypeSelection input[type=text]").attr('disabled', true);
        }
    });

    $(".divPrintMessage").dialog({
        modal: true,
        draggable: false,
        autoOpen: false,
        closeOnEscape: false,
        title: "Generating PDF",
        resizable: false,
        width: 500,
        open: function() {
            $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();
        }
    });
});

function ShowPrintMessage(website) {
    $(".divPrintMessage").dialog('open');

    var dn = new AjaxDownload(website);
    dn.EnableTrace(true);
    dn.add_onEndDownload(EndDownload);
    dn.Download();

    function EndDownload() {
        $(".divPrintMessage").dialog('close');
    }
}

function RadioButtonClientValidate(source, args) {
    var yesRadioButtonId = args.Value;
    var groupName = $("#" + yesRadioButtonId).attr('name');

    var selector = "input[name=" + groupName + "]:checked";
    var checkedCount = $(selector).length;

    if (checkedCount > 0) {
        args.IsValid = true;
        $('#AccreditationCheclistValidationSummary').hide();
    }
    else {
        args.IsValid = false;
        $('#AccreditationCheclistValidationSummary').show();
    }
}

function ValidateOtherTextbox(source, args) {
    var selectedValue = $("#departmentTypeSelection input[type=radio]:checked").val();

    if (selectedValue === "6") {
        if (args.Value === "") {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
        }
    }
    else {
        args.IsValid = true;
    }
}

function formatJSONDate(jsonDate) {
    var date = eval(jsonDate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    return dateFormat(date, "dd/mm/yyyy");
}

//// General purpse DOM Ready function
//$(function() {
//    $('h3 a').click(function() {
//        $('html, body').animate({ scrollTop: 0 }, 'slow');
//        return false;
//    });
//});




