function validateQuickassignroute() {
    var himsValidator = [new hims_ctl_val("ctl00_CP_SearchBusRouteDropDownList", "BusRoute", "T", "", "", "", 20),
        new hims_ctl_val("ctl00_CP_OrganizationDropDownList", "Organization", "T", "", "", "", 20)];
    if (fnDoValidate(himsValidator))
        return true;
    else
        return false;
}


function GetPickupStudent() {
    var Pickup = 0;
    var busroute = $('#ctl00_CP_SearchBusRouteDropDownList').val();
    $('#ctl00_CP_BUsRouteDropDownList').val(busroute);
    getPickupList();

    if ($("#ctl00_CP_SearchPickupDropDownList").prop('selectedIndex') > 0) {
        Pickup = $('#ctl00_CP_SearchPickupDropDownList').val();
    }
    $.ajax({
        type: "POST",
        url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
        data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + Pickup + '","BusRouteId":"' + busroute + '"}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            var datas = $.parseJSON(data.d);
            if ($("#ctl00_CP_SearchPickupDropDownList").prop('selectedIndex') > 0) {
                Pickup = $('#ctl00_CP_SearchPickupDropDownList').val();
                $('#ctl00_CP_StudentPickupDropDownList').val(Pickup);

            }
            openpopup();
            if (datas.PickGrid != '') {
                $('#dvPickupGridDiv').html('');
                $('#dvPickupGridDiv').html(datas.PickGrid);
            }
            else {
                $('#dvPickupGridDiv').html('');
                $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
            }
        },
        error: function (xhr, status, error) {
            $('[id$=MainUpdateProgress]').hide();
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function LoadingMsg(msg1, msg2) {
    $('.hls-bg').show();
    $('#spnmain1msg').html(msg1);
    $('#spnmain2msg').html(msg2);
    $('#assignroute').show();
}
function CloseLoading() {
    $('.hls-bg').hide();
    $('#assignroute').hide();
}
function Closepopup() {
    $('.hls-bg').hide();
    $('#assignroute').hide();
}
function openpopup() {
    LoadingMsg('Loading Details', '<b>Please Wait ...</b>');
    window.setTimeout(function () {
        CloseLoading();
        $('.hls-bg').show();
        $('#assignroute').show();
    }, 500);
}
function DeleteStudentDetail(obj, sourceId) {
    if (confirm("Do you really want to delete?") == true) {
        $.ajax({
            type: "POST",
            url: "/Pages/Transport/QuickAssignRoute.aspx/DeleteStudentDetail",
            data: '{"SourceId":"' + sourceId + '"}',
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (data) {
                if (data.d = 1) {
                    GetPickupStudent();
                }
                else if (data.d = 0) {
                    alert('Error In Delete');
                }
            },
            error: function (xhr, status, error) {
                var err = eval("(" + xhr.responseText + ")");
                console.log(err.Message);
            }
        });
    }
}
function GetStudentPick(pickupid) {
    $('[id$=BUsRouteDropDownList]').val($('[id$=SearchBusRouteDropDownList]').val())
    getPickupList();

    $.ajax({
        type: "POST",
        url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
        data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + pickupid + '","BusRouteId":"' + $('[id$=SearchBusRouteDropDownList]').val() + '"}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            var datas = $.parseJSON(data.d);
            openpopup();
            $('#ctl00_CP_StudentPickupDropDownList').val(pickupid);
            if (datas.PickGrid != '') {
                $('#dvPickupGridDiv').html('');
                $('#dvPickupGridDiv').html(datas.PickGrid);
            }
            else {
                $('#dvPickupGridDiv').html("");
                $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
            }
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function getPickupList() {
    $.ajax
    ({
        url: "/Pages/Transport/QuickAssignRoute.aspx/GetpickDropDown",
        type: "POST",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        data: '{"BusId":"' + $('#ctl00_CP_BUsRouteDropDownList').find(":selected").val() + '"}',
        success: function (data) {
            var ddlCustomers = $("#ctl00_CP_StudentPickupDropDownList");
            ddlCustomers.empty().append('<option  value="0">- ALL - </option>');
            $.each(data.d, function () {
                ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text']));
            });
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function GetSearchPickupStudent() {
    var Pickup = 0;
    if ($("#ctl00_CP_BUsRouteDropDownList").prop('selectedIndex') <= 0) {
        alert("select Busroute");
        $('#dvPickupGridDiv').html('');
        return;
    }
    if ($("#ctl00_CP_StudentPickupDropDownList").prop('selectedIndex') > 0) {
        Pickup = $('[id$=StudentPickupDropDownList]').val();
    }
    var busroute = $('#ctl00_CP_BUsRouteDropDownList').val();
    $('#ctl00_CP_BUsRouteDropDownList').val(busroute);
    $.ajax({
        type: "POST",
        url: "/Pages/Transport/QuickAssignRoute.aspx/GetPickupStudent",
        data: '{"OrgId":"' + $('[id$=OrganizationDropDownList]').val() + '","Pickupid":"' + Pickup + '","BusRouteId":"' + busroute + '"}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            var datas = $.parseJSON(data.d);
            openpopup();
            if (datas.PickGrid != '') {
                $('#dvPickupGridDiv').html('');
                $('#dvPickupGridDiv').html(datas.PickGrid);
            }
            else {
                $('#dvPickupGridDiv').html('');
                $('#dvPickupGridDiv').html("<tr>No Records found !</tr>");
            }
        },
        error: function (xhr, status, error) {
            $('[id$=MainUpdateProgress]').hide();
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}