﻿$(function () {
    $(".viewmoreinfo").click(function (event) {
        event.preventDefault();
        $("#msgBox").dialog("open");
        $("#contentFrame").load("/Insulin_more.htm");
    });

    $(".data_usage_info").click(function (event) {
        event.preventDefault();
        $("#msgBox").dialog("open");
        $("#contentFrame").html("<p>This data may be used by Virtual college and/or your employer to:"
        + "<ul><li>Track your training</li><li>Provide evidence of your training</li></ul>"
        + "There will be an option to opt out of this reporting during the registration process.");
    });

    $("#btnRegNow").click(function (event) {
        event.preventDefault();
        if (!$('input[class=chkaccept]').attr('checked')) {
            $("#msgBox").dialog("open");
            $("#contentFrame").html("Please tick the confirmation box above, to confirm you have read the learner statement.");
        }
        else {
            var qrStr = window.location.search;
            var spQrStr = qrStr.substring(1);
            var arrQrStr = new Array();
            // splits each of pair
            var arr = spQrStr.split('&');

            for (var i = 0; i < arr.length; i++) {
                // splits each of field-value pair
                var index = arr[i].indexOf('=');
                var key = arr[i].substring(0, index);
                var val = arr[i].substring(index + 1);

                //saves each of field-value pair in an array variable
                arrQrStr[key] = val;
            }
            //            //if wales
            //            if (arrQrStr["loc"] == "EEA7530D166B6279D2720929639973D1")
            //            window.location.href = "http://nhsdiabetes.vctms.co.uk/selfregistration.aspx?version=257";
            //            else//england, scotland, wales, or ni
            window.location.href = "org_select.aspx?loc=" + arrQrStr['loc'];
        }
    });

    $('select[name$="ddlOrganisation"]').change(function (event) {

        var SelfRegForm_Version = $(this).val();
        switch ($(this).val()) {
            case '20791': //NHS Organisations
                //SelfRegForm_Version = "";
                break;
            case '21252': //Non NHS Organisations
                break;
            case '21278': //NHS Outisde of the UK
                break;

            // ========== OLD DEPARTMENT STRUCTURE ======================                                            
            //                                           
            //            case '15477': //Acute Trusts                                            
            //                SelfRegForm_Version = "";                                            
            //                break;                                            
            //            case '15478': //Primary Care Trust                                            
            //                break;                                            
            //            case '15479': //Mental Health Trusts                                            
            //                break;                                            
            //            case '15480': //Ambulance Trusts                                            
            //                break;                                            
            //            case '15481': //Care Trusts                                            
            //                break;                                            
            //            case '15498': //Other                                            
            //                break;                                            
            //            case '19865': //Care Homes                                            
            //                break;                                            
            //            case '19977': //Private Healthcare                                            
            //                break;                                            
            //            case '19978': //Universities                                            
            //                break;                                            
            //            case '20040': //Hospices                                            
            //                break;                                            
            //            case '20242': //Aneurin Bevan Health Board                                            
            //                break;                                             
            //                                           
            // ========== OLD DEPARTMENT STRUCTURE ======================                                            

            default:
                break;
        }

        if (SelfRegForm_Version != "0") {
            // ============== Old Redirection ============================
            // $("#msgBoxLioading").dialog("open");
            // //window.location.href = "http://192.168.11.155:5001/selfregistration.aspx?version=" + SelfRegForm_Version;
            // window.location.href = "http://nhsdiabetes.vctms.co.uk/selfregistration.aspx?version=" + SelfRegForm_Version;
            // ============== Old Redirection ============================


            var qrStr = window.location.search;
            var spQrStr = qrStr.substring(1);
            var arrQrStr = new Array();
            // splits each of pair
            var arr = spQrStr.split('&');

            for (var i = 0; i < arr.length; i++) {
                // splits each of field-value pair
                var index = arr[i].indexOf('=');
                var key = arr[i].substring(0, index);
                var val = arr[i].substring(index + 1);

                // saves each of field-value pair in an array variable
                arrQrStr[key] = val;
            }
            //if ni or wales
            if ((arrQrStr["loc"] == "541899B3B32A1308698645CCDE7DB7BC") | (arrQrStr["loc"] == "EEA7530D166B6279D2720929639973D1"))
                window.location = "http://nhsdiabetes.vctms.co.uk/selfregistration.aspx?version=" + $(this).val();
            else//england or scotland
                window.location.href = "course_select.aspx?version=" + SelfRegForm_Version;
        }
    });

    function getVersion() {
        var qs = location.search.substr(location.search.indexOf("?") + 1);
        qs = qs.split("&");
        return qs;
    }

    $("#esrno").click(function (event) {
        event.preventDefault();
        $("#msgCodeDialog").dialog("open");
        $("#msgBoxContent").html("Your Electronic Staff Record (ESR) number (also known as your assignment number) contains a total of 11 digits. The first 3 are unique to your organisation and the next 8 are unique to you. Both numbers should appear on your payslip but may appear as 2 separate numbers, you will need to contact your HR/Local Workforce team if you are unable to locate these on your pay slip who should be able to provide the details for you. Please input the numbers with the 3 digits first immediately followed by the 8 digits. Do not leave a space in between.");
    });

    $("#orgcode").click(function (event) {
        event.preventDefault();
        $("#msgCodeDialog").dialog("open");
        $("#msgBoxContent").html("If your organisation appears in the drop down list on the Registration page, you are already registered with us, please contact your training department or course tutor for your code. If your organisation does not appear, congratulations you are the first learner from your organisation. Please contact us on <a href='mailto:info@healthcareea.co.uk'>info@healthcareea.co.uk</a> or call us on 01943-885086 to register your organisation.");
    });

    // Written to accommodate the addition of the course selection page
    $("#lb_continue").bind('click', function () {
        var courses = "";
        var hash = "";
        var SelfRegForm_Version = getVersion();

        if ($("#cb_Insulin").attr('checked') && $("#cb_IV").attr('checked')) {
            courses = "29589,29773";
            hash = "11BB3D7983854668168179EE6BFD1C82";
        }
        else if ($("#cb_Insulin").attr('checked')) {
            courses = "29589";
            hash = "CB36AF3131AA783905FA7F510698E9CE";
        }
        else if ($("#cb_IV").attr('checked')) {
            courses = "29773";
            hash = "FAABF1C1F629E5AB72FCC8F11B462DF5";
        }
        if (SelfRegForm_Version[0] == "version=2562") {
            $("#msgBoxLioading").dialog("open");
            //Non NHS scotland (they are the only ones that have courses to choose from)
            window.location.href = "http://nhsdiabetes.vctms.co.uk/selfregistration.aspx?" + SelfRegForm_Version[0];
        }
        else if ($("#cb_Insulin").attr('checked') || $("#cb_IV").attr('checked')) {
            $("#msgBoxLioading").dialog("open");
            //england or NHS Scotland scotland (they are the only ones that have courses to choose from)
            window.location.href = "http://nhsdiabetes.vctms.co.uk/selfregistration.aspx?" + SelfRegForm_Version[0] + "&alloc=" + courses + "&digest=" + hash;
        }
    });

    $(".hilite").mouseover(function (event) {
        $(this).addClass('hoveron');
    });

    $(".hilite").mouseout(function (event) {
        $(this).removeClass('hoveron');
    });

    $(".viewlargeimage").click(function (event) {
        event.preventDefault();
        $("#msgBoxFullScreen").dialog("open");
        $("#contentFrame").attr("src", "/Insulin_moreinfo.htm");
    });

    $(".showprofile").live("click", function (event) {
        event.preventDefault();
    });

    $(".hoverimage").click(function (event) {
        event.preventDefault();
    });
});
