var PageIndex = 1;
$(document).ready(function () {
    BindEventFeedbackList();
});
function BindEventFeedbackList() {
    $('[id$=MainUpdateProgress]').show();
    $.ajax({
        type: "POST",
        url: "/Pages/Activity/EventFeedback.aspx/BindEventFeedbackList",
        data: '',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            var datas = $.parseJSON(data.d);
            if (datas.Grid != '' && datas.Grid != undefined) {
                $('#tblList').html('');
                $('#trHeader').html('');
                $('#EventListGridDiv').show();
                $('#trHeader').html(datas.Header);
                $('#tblList').html(datas.Grid);
                $('#pagging').html(datas.Paging);
                $('#NameLabel').html(datas.Name);
                $('#AcademicIdLabel').html(datas.AcademicId);
                $('#DepartmentLabel').html(datas.DepartmentName);
                $('#ClassDivisionLabel').html(datas.DivisionClass);
                $('#EventTypeLabel').html(datas.EventType);
                $('#EventLabel').html(datas.Event);
                window.setTimeout(function () { $('[id$=MainUpdateProgress]').hide(); }, 300);
            }
            else {                
                $('#trHeader').html("<tr><td colspan='37'>No Records found !</td></tr>");
                $('#tblList').html("");
                $('[id$=MainUpdateProgress]').hide();
            }
        },
        error: function (xhr, status, error) {
            $('[id$=MainUpdateProgress]').hide();
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function SaveValues() {
    var IsTrackChk = 0;
    if ($('#IsTrackChk').is(':checked')) { IsTrackChk = 1; }
    $.ajax({
        type: "POST",
        url: "/Pages/Activity/EventFeedback.aspx/SaveDatas",
        data: '{"sfeedback":"' + $('#SchoolFeedbacktxtarea').val() + '","pfeedback":"' + $('#ParentFeedbacktxtarea').val() + '","sAction":"' + $('#SchoolActiontxtarea').val() + '","pAction":"' + $('#ParentActiontxtarea').val() + '","istrack":"' + IsTrackChk + '"}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            if (data.d > 0) {
                BindEventFeedbackList();
                alert('Updated Successfully !');
            }
            else {
                alert('Error');
            }
        },
        error: function (xhr, status, error) {
            $('[id$=MainUpdateProgress]').hide();
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function BindEventDropDown(etypeid, escheid) {
    $.ajax({
        type: "POST",
        url: "/Pages/Activity/EventFeedback.aspx/BindDropDown",
        data: '{"etyp":"' + etypeid + '"}',
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (data) {
            var datas = $.parseJSON(data.d);
            $('#ctl00_CP_EventDropdownlist').html('');
            $('#ctl00_CP_EventDropdownlist').append($("<option></option>").val("-1").html("- Select -"));
            $.each(datas, function (idx, dt) {
                $('#ctl00_CP_EventDropdownlist').append($("<option></option>").val(dt.Id).html(dt.Title));
            });
            window.setTimeout(function () { $('#ctl00_CP_EventDropdownlist').val(escheid); }, 400);
        },
        error: function (xhr, status, error) {
            $('[id$=MainUpdateProgress]').hide();
            var err = eval("(" + xhr.responseText + ")");
            console.log(err.Message);
        }
    });
}
function BindValues(obj, etypeid, escheid) {
    $('#ctl00_CP_hdneventtypeid').val(etypeid);
    $('#ctl00_CP_hdneventscheduleid').val(escheid);
    $('#ctl00_CP_hdnschoolfeedbackarea').val($(obj).parent('td').parent('tr').find('td.feedschool').html());
    $('#ctl00_CP_hdnparentfeedbackarea').val($(obj).parent('td').parent('tr').find('td.feedparent').html());
    $('#ctl00_CP_hdnschoolactionarea').val($(obj).parent('td').parent('tr').find('td.actsch').html());
    $('#ctl00_CP_hdnparentactionarea').val($(obj).parent('td').parent('tr').find('td.actparent').html());
    $('#ctl00_CP_hdnchk1').val($(obj).parent('td').parent('tr').attr('attrisp'));
    $('#ctl00_CP_hdnchk2').val($(obj).parent('td').parent('tr').attr('attrmp'));
    $('#ctl00_CP_hdnchk3').val($(obj).parent('td').parent('tr').attr('attrfp'));
    $('#ctl00_CP_hdnchk4').val($(obj).parent('td').parent('tr').attr('attrgp'));
    $('#ctl00_CP_hdnchk5').val($(obj).parent('td').parent('tr').attr('attrtr'));    
    $('#ctl00_CP_btnBind').click();
}
function fnValidateEventFeedbackMaster() {            
	var himsValidator = [
		new hims_ctl_val('ctl00_CP_EventTypeDropdownlist', "EventType", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_EventDropdownlist', "Event", "T", "", "", "", 20),
		new hims_ctl_val('ctl00_CP_StudentIdNoTextBox', "IdNo", "T", "", "", "", 20)];
	if (fnDoValidate(himsValidator))
		return true;
	else
		return false;
}