$(document).ready(function(){
    $('#loadingContainer').ajaxStart(function()
    {
	    $(this).show();
	    $('#loadingbackground').show().css({"opacity": "0.5"});
	}).ajaxStop(function()
	{
	    $(this).hide();
	});
	
	
	if(getQueryStringRegExp('Action').replace('#','') != 'Modify' && getQueryStringRegExp('Action').replace('#','') != 'Add' )
    {
    
        setInterval(function(){
            $('div.sub_container_page').css('top',$(window.parent.frames.right).height()-$('div.sub_container_page').height()-2); //设置底部分页区域的位置
        },100);
    
        var search_urldata = 'type=ajax&Action=SearchActivityAjax&PageSize='+PageSize+'&Page='+CurrentPage;
        BindActivitys('PromotionActivity.aspx',search_urldata);//绑定数据        
        
        //--添加活动
        $('#btnAdd').click(function(){
            location.href="PromotionActivity.aspx?Action=Add";
        });
        
        //全选
        $('input[@name=chkAll]').click(function(){
            $('input[@name=chkItem]').attr('checked',$(this).attr('checked'));
        });
        
        
        //批量删除活动
        $('#btnDelete').click(function(){
            var activityIDs = '';
            $('input[@name=chkItem][@checked]').each(function(){
                activityIDs += $(this).val() + ',';
            });
            if(activityIDs != ''){
                activityIDs = activityIDs.substring(0,activityIDs.length-1);
                if(confirm('确定要删除选中的活动吗?删除将不可恢复'))
                {
					$.get('PromotionActivity.aspx?type=ajax&Action=DeletePromotionActivity&ActivityIDs=' + activityIDs);
                    location.href="PromotionActivity.aspx?Action=Manage";
                }
            }else{
                alert('请选择要删除的活动');
            }
        });
	}
	else
	{
	    $("#txtTimeBegin").datepicker();
	    $("#txtTimeEnd").datepicker();
	    $("#btnSave").click(function(){
	        if($.trim($("#txtPromotionActivityName").val()) == '')
	        {
	            alert('请输入促销活动名称');
	            return false;
	        }
	        if($.trim($("#txtTimeBegin").val()) == '')
	        {
	            alert('请输入活动开始时间');
	            return false;
	        }
	        if($.trim($("#txtTimeEnd").val()) == '')
	        {
	            alert('请输入活动结束时间');
	            return false;
	        }
	    });
	}
});