﻿$(function () {
    if ($(".adHead").length) {
        $(".adHead").parent().find(".ad").addClass("advert");
    }

    //get default school list
    getSchoolList();
    //get school list function
    $('input[type="radio"]').click(function () {
        getSchoolList();
    });

    $(".easy-select-box-disp").blur(function () {
        $(".easy-select-box ul").slideUp();
    });

    $(".easy-select-box-disp").click(function () {
        if ($(".easy-select-box ul").is(":hidden")) {
            $(".easy-select-box ul").slideDown();
        }
        else {
            $(".easy-select-box ul").slideUp();
        }
    });
    $(".easy-select-box-disp").blur(function () {
        $(".easy-select-box ul").slideUp();
    });

    //alphabetical search features
    var url = window.location.href;
    if (url.indexOf("FirmList") != -1) {
        $(".grdSearchResults td .A:first").before('<div class="alph"><h1>A-</h1></div>');
        $(".grdSearchResults td .B:first").before('<div class="alph"><h1>B-</h1></div>');
        $(".grdSearchResults td .C:first").before('<div class="alph"><h1>C-</h1></div>');
        $(".grdSearchResults td .D:first").before('<div class="alph"><h1>D-</h1></div>');
        $(".grdSearchResults td .E:first").before('<div class="alph"><h1>E-</h1></div>');
        $(".grdSearchResults td .F:first").before('<div class="alph"><h1>F-</h1></div>');
        $(".grdSearchResults td .G:first").before('<div class="alph"><h1>G-</h1></div>');
        $(".grdSearchResults td .H:first").before('<div class="alph"><h1>H-</h1></div>');
        $(".grdSearchResults td .I:first").before('<div class="alph"><h1>I-</h1></div>');
        $(".grdSearchResults td .J:first").before('<div class="alph"><h1>J-</h1></div>');
        $(".grdSearchResults td .K:first").before('<div class="alph"><h1>K-</h1></div>');
        $(".grdSearchResults td .L:first").before('<div class="alph"><h1>L-</h1></div>');
        $(".grdSearchResults td .M:first").before('<div class="alph"><h1>M-</h1></div>');
        $(".grdSearchResults td .N:first").before('<div class="alph"><h1>N-</h1></div>');
        $(".grdSearchResults td .O:first").before('<div class="alph"><h1>O-</h1></div>');
        $(".grdSearchResults td .P:first").before('<div class="alph"><h1>P-</h1></div>');
        $(".grdSearchResults td .Q:first").before('<div class="alph"><h1>Q-</h1></div>');
        $(".grdSearchResults td .R:first").before('<div class="alph"><h1>R-</h1></div>');
        $(".grdSearchResults td .S:first").before('<div class="alph"><h1>S-</h1></div>');
        $(".grdSearchResults td .T:first").before('<div class="alph"><h1>T-</h1></div>');
        $(".grdSearchResults td .U:first").before('<div class="alph"><h1>U-</h1></div>');
        $(".grdSearchResults td .V:first").before('<div class="alph"><h1>V-</h1></div>');
        $(".grdSearchResults td .W:first").before('<div class="alph"><h1>W-</h1></div>');
        $(".grdSearchResults td .X:first").before('<div class="alph"><h1>X-</h1></div>');
        $(".grdSearchResults td .Y:first").before('<div class="alph"><h1>Y-</h1></div>');
        $(".grdSearchResults td .Z:first").before('<div class="alph"><h1>Z-</h1></div>');
        $(".alph").next("div").css("border-top", "dotted 1px #e3e3e3");
        $(".alph").next("div").css("padding-top", "10px;");
        $(".alph:first").next("div").css("border-top", "none");
        $(".alph").next("div").css("padding-top", "10px");
        $(".alph").next("div").css("padding-bottom", "5px");
        var txt;
        txt = $(".a-z").html();
        $(".easy-select-box-disp").text(txt);
        //text transform
        Cufon.replace('h1')('.alph h1');
    } else if (url.indexOf("FirmSize") != -1) {
        $(".ResultsTitle").css("margin-left", "0");
        $(".grdSearchResults").css("margin-top", "10px");
        var txt;
        txt = $(".size").html();
        $(".easy-select-box-disp").text(txt);
    } else {
        $(".ResultsTitle").css("margin-left", "0");
        $(".grdSearchResults").css("margin-top", "10px");
        var txt;
        txt = $(".revenue").html();
        $(".easy-select-box-disp").text(txt);
    }

    //append a default value to dropdown
    function defaultItem(str) {
        str += "<option value='0' selected>" + str + "</option>";
        return str;
    }

    function getSchoolList() {
        $('input[type="radio"]').each(function () {
            var checked = $(this).attr('checked');
            if (checked) {
                var $check = $(this); //convert to object
                var radioType = $check.attr('name'); //
                //Check if radio name is lawschool
                if (radioType == "lawschool") {
                    //            var chapterIds = [];
                    //            chapterIds.push($("input[@name='lawschool']:checked").val());
                    var id = { "schoolType": $("input[@name='lawschool']:checked").val().toLowerCase() }
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "/Services/SearchService.asmx/GetSchools",
                        data: JSON.stringify(id),
                        dataType: "json",
                        success: function (response) {
                            var listItems = "";
                            for (var i = 0; i < response.d.length; i++) {
                                listItems += "<option value='" + response.d[i].Id + "'>" + response.d[i].Description + "</option>";
                               // alert(listItems);
                             }

                            $('.LawSchoolSearch').html("");
                            $(".BarristerSearch").prepend(defaultItem("By name"));
                            $(".LawSchoolSearch").prepend(defaultItem("By name"));
                            $('.LawSchoolSearch').append(listItems);
                            $('.lawschool .easy-select-box ul').css("height", "84px");
                        }
                    });
                }
            }


        });
    }
});

