(function(window){if(!ts.section)
ts.section={};ts.section.search={termEid:null,startDate:null,searchText:null,instructorEid:null,sessionEid:null,searchType:null,prepList:function(){$('.sectionGlyph').each(function(idx){$(this).addClass('alternatingItem'+idx%2);});},setListMsg:function(){var termEid="null";if($('#ddlTerms').val()!="00000000-0000-0000-0000-000000000000")
termEid=$('#ddlTerms').val();var startDateSendString="null";if(termEid=="null"){var startDate=$('#SelectedDate').val();if(startDate!=""){var startDateSplited=startDate.split('/');startDateSendString=startDateSplited[0]+","+startDateSplited[1]+","+startDateSplited[2];}}
var url='/Academics/FinalizeRegistrations/Search/Instructors/'+termEid+'/'+startDateSendString;ts.ajax.send({url:url,contentType:"application/json; charset=utf-8",dataType:"json",successHandler:function(data){var ddlVal=$('#ddlInstructors').val();$("#ddlInstructors").get()[0].length=0;$.each(data.Instructors,function(val,item){$('#ddlInstructors').append($('').val(item.Eid).html(item.Name));});$('#ddlInstructors').val(ddlVal);},errorHandler:function(result){ts.msg.sendError('An error occurred performing the operation.');ts.msg.sendMsg('sysWarning','unknown error ts ajax: '+result.responseText);}});},markAllFinal:function(){var url='/Academics/FinalizeRegistrations/Search/MarkAllFinal/'+ts.section.search.termEid+'/'+ts.section.search.startDate
+'/'+ts.section.search.searchType+'/'+ts.section.search.searchText+'/'+ts.section.search.instructorEid+'/'+
ts.section.search.sessionEid;ts.ajax.send({url:url,contentType:"application/json; charset=utf-8",dataType:"json",successHandler:function(result){ts.ajax.handleResult(result);if(result.State==0){ts.section.search.search(true);ts.msg.sendInfo('The selected sections were successfully finalized');}else{if(result.Messages.length>0)
ts.msg.sendError(result.Messages[0].Message);}},errorHandler:function(result){ts.msg.sendError('An error occurred performing the operation.');ts.msg.sendMsg('sysWarning','unknown error ts ajax: '+result.responseText);}});},search:function(resetSort){if(resetSort){$('#selectedSortColumn').val('SectionDates');$('#IsAscending').val('false');}
ts.msg.sendInfo('Searching for sections...');ts.list.applyFilter('section',function(config){ts.msg.sendInfo('Found '+config.totalRecordCount+' sections that match your search');ts.section.search.setListMsg();});ts.section.search.termEid=($('#ddlTerms').val()!="00000000-0000-0000-0000-000000000000")?$('#ddlTerms').val():"null";ts.section.search.startDate="null";if(ts.section.search.termEid=="null"){ts.section.search.startDate=$('#SelectedDate').val();if(ts.section.search.startDate!=""){var startDateSplited=ts.section.search.startDate.split('/');ts.section.search.startDate=startDateSplited[0]+","+startDateSplited[1]+","+startDateSplited[2];}
else
ts.section.search.startDate="null";}
ts.section.search.searchText=$('#txtSearch').val()!=""?$('#txtSearch').val():"null";ts.section.search.instructorEid=($('#ddlInstructors').val()!="00000000-0000-0000-0000-000000000000")?$('#ddlInstructors').val():"null";ts.section.search.sessionEid=($('#ddlSessions').val()!="00000000-0000-0000-0000-000000000000")?$('#ddlSessions').val():"null";ts.section.search.searchType=$('#ddlSearchTypes').val()!=""?$('#ddlSearchTypes').val():"null";},init:function(){ts.section.search.handleSuggestions(false);ts.section.search.prepList();ts.section.search.setListMsg();if($("#ddlSessions").get(0).options.length<2)
$("#ddlSessions").hide();$('#findForm').submit(function(){$('#searchLink').click();return false;});$('#searchLink').click(function(){ts.section.search.resetFilters();ts.section.search.search(true);});$('#ddlInstructors').change(function(){ts.section.search.search(true);});$('#ddlSessions').change(function(){ts.section.search.search(true);});$('#txtSearch').keydown(function(e){if(e.keyCode==13){ts.section.search.resetFilters();ts.section.search.search(true);}});$('#markAllFinal').click(function(){if(confirm('Are you sure you want to finalize all the enrolled student/s from all of the selected sections?')){if(($('.sectionGlyph').length!=0))
ts.section.search.markAllFinal();else
ts.msg.sendInfo('There are no selected sections for finalizing. Please search for sections first.');}});$('.sectionGlyph').live('click',function(e){e.stopImmediatePropagation();if($(this).attr('ts-canfinalize')=='True'){ts.msg.sendInfo('Redirecting .. please wait');document.location='/Academics/FinalizeRegistrations/'+$(this).attr('ts-id');}
else
ts.msg.sendInfo('Can not proceed to the section finalizer roster because the section does not have enrolled students for finalizing.');});$('#SelectedDate').datepicker();$('#ddlTerms').change(function(){ts.section.search.handleSuggestions(true);});$('#ddlSearchTypes').change(function(){ts.section.search.handleSuggestions(false);});$('#SelectedDate').change(function(){ts.section.search.handleSuggestions(false);});$('#SessionName').live('click',function(){ts.section.search.setSorting('SessionName');});$('#CourseTitle').live('click',function(){ts.section.search.setSorting('CourseTitle');});$('#SectionCode').live('click',function(){ts.section.search.setSorting('SectionCode');});$('#CallNumber').live('click',function(){ts.section.search.setSorting('CallNumber');});$('#SectionDates').live('click',function(){ts.section.search.setSorting('SectionDates');});$('#Instructors').live('click',function(){ts.section.search.setSorting('Instructors');});$('#StudentsEnrolled').live('click',function(){ts.section.search.setSorting('StudentsEnrolled');});$('#NotFinalized').live('click',function(){ts.section.search.setSorting('NotFinalized');});},fillSessions:function(termEid){var url='/Academics/FinalizeRegistrations/Search/Sessions/'+termEid;ts.ajax.send({url:url,contentType:"application/json; charset=utf-8",dataType:"json",successHandler:function(data){$("#ddlSessions").show();$("#ddlSessions").get(0).options.length=0;$("#ddlSessions").get(0).options[0]=new Option("Select All Sessions","00000000-0000-0000-0000-000000000000");$.each(data.Sessions,function(val,item){$('#ddlSessions').append($('').val(item.Eid).html(item.Name));});if($("#ddlSessions").get(0).options.length==1)
$("#ddlSessions").hide();},errorHandler:function(result){ts.msg.sendError('An error occurred performing the operation.');ts.msg.sendMsg('sysWarning','unknown error ts ajax: '+result.responseText);}});},handleSuggestions:function(isTermChanged){var searchType=$('#ddlSearchTypes').val();var termEid="null";if($('#ddlTerms').val()!="00000000-0000-0000-0000-000000000000")
termEid=$('#ddlTerms').val();var startDateSendString="null";if(termEid=="null"){var startDate=$('#SelectedDate').val();if(startDate!=""){var startDateSplited=startDate.split('/');startDateSendString=startDateSplited[0]+","+startDateSplited[1]+","+startDateSplited[2];}}
var url='/Academics/FinalizeRegistrations/Search/Suggestions/'+termEid+'/'+startDateSendString+'/'+searchType;ts.ajax.send({url:url,contentType:"application/json; charset=utf-8",dataType:"json",successHandler:function(msg){var data=msg.SectionSearchSuggestions;$('#txtSearch').flushCache();for(var i=0;i