/*
 * ExpressionEngine - by EllisLab
 *
 * @package		ExpressionEngine
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2003 - 2011, EllisLab, Inc.
 * @license		http://expressionengine.com/user_guide/license.html
 * @link		http://expressionengine.com
 * @since		Version 2.0
 * @filesource
 */

$(document).ready(function(){function w(a){h[a]===void 0&&(a=0);jQuery.each(h[a],function(a,p){switch(a){case "categories":$("select#f_cat_id").empty().append(p);break;case "statuses":$("select#f_status").empty().append(p)}})}function i(){if($("#custom_date_start").val()!="yyyy-mm-dd"&&$("#custom_date_end").val()!="yyyy-mm-dd")focus_number=$("#date_range").children().length,$("#date_range").append('<option id="custom_date_option">'+$("#custom_date_start").val()+" to "+$("#custom_date_end").val()+
"</option>"),document.getElementById("date_range").options[focus_number].selected=!0,$("#custom_date_picker").slideUp("fast"),oTable.fnDraw()}function q(a,b,e){for(var c=0,g=a.length;c<g;c++)if(a[c].name==b)a[c].value=e}function k(a,b){for(var e=0,c=a.length;e<c;e++)if(a[e].name==b)return a[e].value;return null}$(".paginationLinks .first").hide();$(".paginationLinks .previous").hide();$(".toggle_all").toggle(function(){$("input.toggle").each(function(){this.checked=!0})},function(){$("input.toggle").each(function(){this.checked=
!1})});$("#custom_date_start_span").datepicker({dateFormat:"yy-mm-dd",prevText:"<<",nextText:">>",onSelect:function(a){$("#custom_date_start").val(a);i()}});$("#custom_date_end_span").datepicker({dateFormat:"yy-mm-dd",prevText:"<<",nextText:">>",onSelect:function(a){$("#custom_date_end").val(a);i()}});$("#custom_date_start, #custom_date_end").focus(function(){$(this).val()=="yyyy-mm-dd"&&$(this).val("")});$("#custom_date_start, #custom_date_end").keypress(function(){$(this).val().length>=9&&i()});
var h=EE.edit.channelInfo,x=RegExp("!-!","g"),y=(new Date).getTime();(function(){jQuery.each(h,function(a,b){jQuery.each(b,function(b,c){var g=new String;jQuery.each(c,function(a,b){g+='<option value="'+b[0]+'">'+b[1].replace(x,String.fromCharCode(160))+"</option>"});h[a][b]=g})})})();$("#f_channel_id").change(function(){w(this.value)});$("#date_range").change(function(){$("#date_range").val()=="custom_date"?($("#custom_date_start").val("yyyy-mm-dd"),$("#custom_date_end").val("yyyy-mm-dd"),$("#custom_date_option").remove(),
$("#custom_date_picker").slideDown("fast")):$("#custom_date_picker").hide()});$("#entries_form").submit(function(){if(!$("input:checkbox",this).is(":checked"))return $.ee_notice(EE.lang.selection_required,{type:"error"}),!1});var a={iCacheLower:-1};EE.edit.tableColumns==9?(MyCols=[null,null,{bSortable:!1},null,null,null,null,null,{bSortable:!1}],MySortCol=5):(MyCols=[null,null,{bSortable:!1},null,null,null,null,{bSortable:!1}],MySortCol=4);oTable=$("#entries_form .mainTable").dataTable({sPaginationType:"full_numbers",
bLengthChange:!1,aaSorting:[[MySortCol,"desc"]],bFilter:!1,sWrapper:!1,sInfo:!1,bAutoWidth:!1,iDisplayLength:+EE.edit.perPage,aoColumns:MyCols,oLanguage:{sZeroRecords:EE.lang.noEntries,oPaginate:{sFirst:'<img src="'+EE.edit.themeUrl+'images/pagination_first_button.gif" width="13" height="13" alt="&lt; &lt;" />',sPrevious:'<img src="'+EE.edit.themeUrl+'images/pagination_prev_button.gif" width="13" height="13" alt="&lt; &lt;" />',sNext:'<img src="'+EE.edit.themeUrl+'images/pagination_next_button.gif" width="13" height="13" alt="&lt; &lt;" />',
sLast:'<img src="'+EE.edit.themeUrl+'images/pagination_last_button.gif" width="13" height="13" alt="&lt; &lt;" />'}},bProcessing:!0,bServerSide:!0,sAjaxSource:EE.BASE+"&C=content_edit&M=edit_ajax_filter&time="+y,fnServerData:function(h,b,e){function c(){if($(r).data("user_data")=="n")return"";return r.value}var g=+EE.edit.pipe,l=!1,i=k(b,"sEcho"),d=k(b,"iDisplayStart"),j=k(b,"iDisplayLength"),f=d+j,r=document.getElementById("keywords"),s=document.getElementById("f_status"),n=document.getElementById("f_channel_id"),
t=document.getElementById("f_cat_id"),o=document.getElementById("f_search_in"),u=document.getElementById("date_range"),v=document.getElementById("f_perpage"),m;m="&ajax=true&keywords="+c()+"&channel_id="+n.value;if(o.value=="comments")window.location=EE.BASE+"&C=content_edit&M=view_comments"+m;b.push({name:"keywords",value:c()},{name:"status",value:s.value},{name:"channel_id",value:n.value},{name:"cat_id",value:t.value},{name:"search_in",value:o.value},{name:"date_range",value:u.value},{name:"per_page",
value:v.value});a.iDisplayStart=d;if(a.iCacheLower<0||d<a.iCacheLower||f>a.iCacheUpper)l=!0;if(a.lastRequest&&!l){f=0;for(m=b.length;f<m;f++)if(b[f].name!="iDisplayStart"&&b[f].name!="iDisplayLength"&&b[f].name!="sEcho"&&b[f].value!=a.lastRequest[f].value){l=!0;break}}a.lastRequest=b.slice();l?(d<a.iCacheLower&&(d-=j*(g-1),d<0&&(d=0)),a.iCacheLower=d,a.iCacheUpper=d+j*g,a.iDisplayLength=k(b,"iDisplayLength"),q(b,"iDisplayStart",d),q(b,"iDisplayLength",j*g),b.push({name:"keywords",value:c()},{name:"status",
value:s.value},{name:"channel_id",value:n.value},{name:"cat_id",value:t.value},{name:"search_in",value:o.value},{name:"date_range",value:u.value},{name:"per_page",value:v.value}),$.getJSON(h,b,function(b){a.lastJson=jQuery.extend(!0,{},b);a.iCacheLower!=a.iDisplayStart&&b.aaData.splice(0,a.iDisplayStart-a.iCacheLower);b.aaData.splice(a.iDisplayLength,b.aaData.length);e(b)})):(json=jQuery.extend(!0,{},a.lastJson),json.sEcho=i,json.aaData.splice(0,d-a.iCacheLower),json.aaData.splice(j,json.aaData.length),
e(json))}});$("#keywords").keyup(function(){oTable.fnDraw()});$("select#f_channel_id").change(function(){oTable.fnDraw()});$("select#f_cat_id").change(function(){oTable.fnDraw()});$("select#f_status").change(function(){oTable.fnDraw()});$("select#f_search_in").change(function(){oTable.fnDraw()});$("select#date_range").change(function(){oTable.fnDraw()});$("select#f_perpage").change(function(){oTable.fnDraw()})});
