
var PageSize = 30;//每页计数
var CurrentPage = 1; //当前页
var agentMemberID = 0;
var period = '';
var active = -1;
var status = 1;
var sort = 2;

//列表查询条件
var search_urldata = 'type=ajax&Action=GetList&PageSize='+PageSize+'&Page='+CurrentPage + '&sort=' + sort;

function setList(){
	var pageWidth=$('#popupContact').width()-20;
	$(".sub_container_content").css("width",pageWidth);
	$(".sub_container_listhead").css("width",pageWidth);
	$(".llist").css("width",pageWidth);
	var c1_width = pageWidth*0.05+"px";
	var c2_width = pageWidth*0.25+"px";
	var c3_width = pageWidth*0.25+"px";
	var c4_width = pageWidth*0.15+"px";
	var c5_width = pageWidth*0.15+"px";
	var c6_width = pageWidth*0.15+"px";
	$('.c1').css("width",c1_width);
	$('.c2').css("width",c2_width);
	$('.c3').css("width",c3_width);
	$('.c4').css("width",c4_width);
	$('.c5').css("width",c5_width);	
	$('.c6').css("width",c6_width);	
}

$(document).ready(function(){
    //loading
    $('#loadingContainer').ajaxStart(function(){$(this).show();}).ajaxStop(function(){$(this).hide();});	

	if($.browser.mozilla){setInterval(setList,1000);}
	setInterval(function(){
        $('div.sub_container_page').css('top',$(window.parent.frames.right).height()-$('div.sub_container_page').height()-2); //设置底部分页区域的位置
        $('div.sub_container_content').css('height',$(window.parent.frames.right).height()-$('div.sub_container_title').height()-$('div.sub_container_operation').height()-$('div.sub_container_listhead').height()-$('div.sub_container_page').height()-10); //设置内容区域的高度
    },1000);

    $('input[@name=chkAll]').click(function(){$('input[@name=chkItem]').attr('checked',$(this).attr('checked'));});//全选

    BindList();
    
    $('#btnSearch').click(function(){
        CurrentPage = 1;
        BindList();
    });
    
    $('#btnDelete').click(function(){
        var ids = '';
        $('input[@name=chkItem][@checked]').each(function(){ids += $(this).val() + ',';});
        if(ids != ''){ids = ids.substring(0,ids.length-1);Delete(ids)}else{alert('请先选择要删除的视频');};
    });
    
});    

//绑定数据
function BindList(){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'Video.aspx?NoCopyRight=1&type=ajax&Action=GetList',
        data:'Keyword=' + escape($('#txtkeyword').val()) + '&CatIDs=' + $('#ddlCategory').val() + '&SrcType=' + $('#ddlType').val() + '&Status=' + $('#ddlStatus').val() + '&Page=' + CurrentPage + '&PageSize=' + PageSize,
        cache:false,
        success:function(msg){
            $('input[@name=chkAll]').attr('checked','');
            $('tr:gt(0)','#datas').remove();
            var data = msg.Video;
            $.each(data,function(i,n){
                var row = $('#template').clone();
                row.show().mouseover(function(){$(this).addClass('on')}).mouseout(function(){$(this).removeClass('on')}); //将复制的行显示出来并添加样式
                row.find('#checkbox').html('<input type="checkbox" name="chkItem" value="' + n.VideoID + '" />');//checkbox
                row.find('#Name').html('<a href="' + ShopFolder + 'videos/video-' + n.VideoID + '.' + extend + '" target="_blank">' + n.VideoName + '</a>');
                row.find('#Category').html($.trim($('#ddlCategory option[@value=' + n.CategoryID + ']').text().replace('├','')));
                row.find('#SrcType').html(n.SrcType == '0' ? '本地' : '网络');
                row.find('#FileName').html(n.SrcType == '0' ? n.FileName : '');
                row.find('#Url').html(n.SrcType == '1' ? n.Url : '');
                row.find('#Status')
                    .html( '<img src="../images/publish_' + n.Status + '.png" border="0" status="' + n.Status + '" />')
                    .find('img')
                    .click(function(){
                        var objImg = $(this);
                        var newstatus = (objImg.attr('status') == '1' ? '0' : '1');
                        $.ajax({
                            url:'Video.aspx?type=ajax&Action=ChangeStatus&IDs=' + n.VideoID + '&status=' + newstatus,
                            cache:false,
                            success:function(result){
                                if(result > 0){
                                    objImg.attr('src','../images/publish_' + newstatus + '.png');
                                };
                            },
                            error:function(){alert('error')}
                        });
                    });
                row.find('#Modify').html('<span class="hand">修改</span>').click(function(){ShowModify(n.VideoID);});
                row.find('#Delete').html('<span class="hand">删除</span>').click(function(){if(confirm('确定删除此视频吗?')){if(Delete(n.VideoID) > 0){row.remove();};}});
                
				row.attr("id","ready_" + n.ProductID);//改变绑定好数据的行的id
				row.appendTo("#datas");//添加到模板的容器中
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "MsgList.aspx",//[url]
               {style:pagerStyle,mark:"pageDataList1Mark",
               totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 没有记录",preWord:"上一页",nextWord:"下一页",
               onclick:"CurrentPage={pageindex};BindList();return false;"}//[attr]
            );
        },//end success
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!');}else{alert(textStatus)};}
    });//end ajax
};//end funciton

//点击修改,显示修改商品的页面
function ShowModify(id){
    $('#frmModify').attr('src','VideoAdd.aspx?NoCopyRight=1&vid=' + id +'&ran='+Math.random()).css('height',$(window).height()).show().siblings().hide();
}

function Delete(ids){
    var result = 0;
    $.ajax({
        url:'Video.aspx?NoCopyRight=1&type=ajax&Action=Delete&IDs='+ids,
        cache:false,
        async:false,
        success:function(data){
            if(!checkLoginStatus(data)){return false;};
            if(data > 0){BindList();};
            result = data;
        },
        error:function(){alert('error');}
    });
    return result;
};

function checkLoginStatus(data){
    var result = true;
    if(data.indexOf('<!DOCTYPE') != -1){
        result = false;
        alert('身份已过期,请重新登陆!');
    };
    return result;
};

