var RowSelectUid;
function SearchGrid_onRequestEnd(e) {
    if (e.type == "read") {
        var offsetMiliseconds = new Date().getTimezoneOffset() * 60000;
        var gyms = e.response.Data;
        if (gyms != undefined && gyms != null) {
            for (var i = 0; i < gyms.length; i++) {
                if (gyms[i].EFF_DATE_SORT != null && gyms[i].EFF_DATE_SORT != undefined) {
                    gyms[i].EFF_DATE_SORT = gyms[i].EFF_DATE_SORT.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
             );
                }
                if (gyms[i].EXP_DATE_SORT != null && gyms[i].EXP_DATE_SORT != undefined) {
                    gyms[i].EXP_DATE_SORT = gyms[i].EXP_DATE_SORT.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
             );
                }
                if (gyms[i].EFF_DT_SORT != null && gyms[i].EFF_DT_SORT != undefined) {
                    gyms[i].EFF_DT_SORT = gyms[i].EFF_DT_SORT.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
             );
                }
                if (gyms[i].EXP_DT_SORT != null && gyms[i].EXP_DT_SORT != undefined) {
                    gyms[i].EXP_DT_SORT = gyms[i].EXP_DT_SORT.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
             );
                }
                if (gyms[i].UPLOAD_STAMP_SORT != null && gyms[i].UPLOAD_STAMP_SORT != undefined) {
                    gyms[i].UPLOAD_STAMP_SORT = gyms[i].UPLOAD_STAMP_SORT.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
             );
                }
//                if (gyms[i].ADMISSION_DATE_VIEW != null && gyms[i].ADMISSION_DATE_VIEW != undefined) {
//                    gyms[i].ADMISSION_DATE_VIEW = gyms[i].ADMISSION_DATE_VIEW.replace(/\d+/,
//                function (n) { return parseInt(n) + offsetMiliseconds }
//             );
//                }
            }
        }
    }

}
Grid_onDataBound = function (e) { alert("in onDataBound!!!"); InitGridSelection(e.sender, RowSelectUid); }
Grid_OnRowSelectUID = function (e) { var data = this.dataItem(this.select()); RowSelectUid = data.id; alert("in onRowSelect!!!") }
InitGridSelection = function (objGrid, strData) {
    var data = objGrid.dataSource.view();
    $.each(data, function (i, row) {
        if (row.DEL_FLG == "Y") $('tr[data-uid="' + row.uid + '"]').addClass("softDelete");
        if ($('tr[data-uid="' + row.uid + '"]').length > 0) {
            if (row.id == strData) $('tr[data-uid="' + row.uid + '"]').addClass('k-state-selected');
            else $('tr[data-uid="' + row.uid + '"]').removeClass('k-state-selected');
        }
    });
}

FormSubmit = function () {
    //$("#SaveAndSearchForm").submit();
    //var grid = $("#StudentsGrid").data("kendoGrid"); grid.dataSource.read();
}
function error_handler_VSP(e) {
    if (e.errors) {
        var message = "Errors:\n";
        $.each(e.errors, function (key, value) {
            if ('errors' in value) { $.each(value.errors, function () { message += this + "\n"; }); ; }
        });
        alert(message); 
//        ResetCtrls(); DisableEnableToolBtns('', false); originalData = null;
    }
}
discardChanges = function () {
    //    var grid = "";
    //    if (formName == 'VspLcnMst') grid = $("#ExcelPortMstGrid").data('kendoGrid');
    //    else if (formName == 'VspLcnDist') grid = $("#ExcelPortDistGrid").data('kendoGrid');
    //    else if (formName == 'VspCnlMst') grid = $("#ExcelCnlMstGrid").data('kendoGrid');
    //    else if (formName == 'VSLHire') grid = $("#VSLHireExcelGrid").data('kendoGrid');
    //    else if (formName == 'PortCharge') grid = $("#PortChargeExcelGrid").data('kendoGrid');
    //    else if (formName == 'SF') grid = $("#SFExcelGrid").data('kendoGrid');
    //    else if (formName == 'Cons') grid = $("#ConsExcelGrid").data('kendoGrid');
    //    else if (formName == 'Type') grid = $("#TypeExcelGrid").data('kendoGrid');
    //    else if (formName == 'VspCnlCost') grid = $("#ExcelCnlCostGrid").data('kendoGrid');
    //    if (originalData == null) grid.dataSource.data([]); else grid.dataSource.data(originalData);
    alert("Inside discard changes!!!");
}

SaveChanges = function () {
    alert("Inside save changes!!!");
}
EnableDisableCtrls = function (enable) {
    try {
        $('#SaveAndSearchForm').find($(":input")).each(function () {
            if (enable) {
                $(this).removeAttr('disabled');
            }
            else {
                $(this).attr('disabled','disabled');
            }
        });

    } catch (Exception) {

    }
 }
DisableEnableDropDowns = function (objFormName, strDropDowns, enable) {
    try {
        var dropdowns = strDropDowns.split(',');
        $('#' + objFormName).find(':input').each(function () {
            if (this.type == 'text') { if ($.inArray(this.name, dropdowns) != -1) { combo = $("#" + this.name).data('kendoDropDownList'); if (enable) combo.enable(true); else combo.enable(false); } }
        });
    } catch (Exception) { }
}

DisableEnableDatePicker = function (objFormName, strDatePickers, enable) {
    try {
        var datePickers = strDatePickers.split(',');
        $('#' + objFormName).find($(':input')).each(function () {
            if ($.inArray(this.name, datePickers) != -1) {
                datePicker = $("#" + this.name).data('kendoDatePicker');
                if (enable) {
                    datePicker.readonly(false);
                    if ($("#" + this.name + '_IMG') != undefined) $("#" + this.name + '_IMG').show(); //Give the corresponding image name = datepicker name + "_IMG"                        
                }
                else {
                    if ($("#" + this.name + '_IMG') != undefined) $("#" + this.name + '_IMG').hide(); datePicker.readonly();
                }
            }
        });
    } catch (Exception) { }
}

DisableAllFields = function (objForm) { $('#' + objForm + ' input[type="text"],textarea').each(function () { $(this).attr("disabled", "disabled"); }); $('#' + objForm + ' input[type="checkbox"]').each(function () { $(this).attr("disabled", "disabled"); }); $('#' + objForm + ' input[type="radio"]').each(function () { $(this).attr("disabled", "disabled"); }); }
EnableAllFields = function (objForm) { $('#' + objForm + ' input[type="text"],textarea').each(function () { $(this).removeAttr("disabled"); }); $('#' + objForm + ' input[type="checkbox"]').each(function () { $(this).removeAttr("disabled"); }); $('#' + objForm + ' input[type="radio"]').each(function () { $(this).removeAttr("disabled"); }); }

SubmissionCompletedFunc = function () {
    var comboObj = $("#BRANCH").data("kendoDropdownList");
    comboObj.dataSource.read();
}

FillDropDown = function () {
    showCtrlLoader('dvShowResult');
    $.post("../Home/GetBranchNames", {}, function (response) {
        // var retJson = $.parseJSON(response);
        var comboObj = $("#BRANCH").data("kendoDropDownList");
        comboObj.setDataSource(response);
        //hideCtrlLoader('BRANCH');
    });

}
showCtrlLoader = function (ctrl) { $("#" + ctrl).addClass("k-loading"); }
hideCtrlLoader = function (ctrl) { $("#" + ctrl).removeClass("k-loading"); }

openCal = function () {

    var datepicker = $("#ADMISSION_DATE_VIEW").data("kendoDatePicker");
    datepicker.open();
}