var tdobj={},year,month,weekds='',xiuobj={},nowday;
function getxiu(){
	var url = js.getajaxurl('getxiu',mode,dir,{y1:year,m1:month});
	$.get(url,function(da){backset(da);});
}
function backset(da){
	var a = js.decode(da),i,a1,d;
	for(i=0;i<a.length;i++){
		if(tdobj[a[i].date]){
			tdobj[a[i].date].style.backgroundColor='#C9E283';
			xiuobj[a[i].date]=true;
		}
	}
}
function aetall(){
	var url = js.getajaxurl('setallxiu',mode,dir,{y1:year,m1:month});
	js.msg('wait','设置中...');
	$.post(url,{s:weekds},function(da){
		js.msg('success','设置成功');
		backset(da);
	});
}
function changexiuft(lx){
	var url = js.getajaxurl('changexiu',mode,dir,{day:nowday,lx:lx});
	$.get(url);
	if(lx==0){
		tdobj[nowday].style.backgroundColor='#C9E283';
		xiuobj[nowday] = true;
	}
	if(lx==1){
		tdobj[nowday].style.backgroundColor='';
		xiuobj[nowday] = false;
	}
}


var omenu=Ext.create('Ext.menu.Menu',{
	items:[{
		text:'设置为休息日',id:'setxiu_'+rand+'',disabled:true,handler:function(){changexiuft(0)}
	},'-',{
		text:'取消休息日',id:'qxxiu_'+rand+'',disabled:true,handler:function(){changexiuft(1)}
	}]
});
var panel={
	xtype:'calendarpanel',textvalign:'top',
	renderer:function(tad, ars, y, m){
		var s= '<div style="line-height:20px;text-align:left">&nbsp;'+ars.d+' <span style="font-size:11px;color:'+ars.color+'">'+ars.jieri+'</span> </div>';
		s+='<div></div>';
		var day = ''+y+'-'+m+'-'+xy10(ars.d)+'';
		tdobj[day] = tad;
		if(ars.week=='六' || ars.week=='日')weekds+=','+day;
		return s;
	},
	beforechangemonth:function(){
		weekds='';
		tdobj={};
		xiuobj={};
	},
	changemonth:function(o,y,m){
		year=y;
		month=m;
		weekds = weekds.substr(1);
		getxiu();
	},
	bbar:[{
		xtype:'tbtext',text:'<div style="height:16px;width:16px;background:#C9E283;overflow:hidden"></div>'
	},{
		text:'休息日'
	},'-',{
		text:'设置本月周六周日为休息日',icon:gicons('cog'),handler:function(){aetall()}
	}],
	click:function(day, o, e){
		omenu.showAt([e.clientX,e.clientY]);
		nowday = day;
		var bo = false;
		if(xiuobj[day])bo=true;
		if(!bo){
			getcmp('setxiu_'+rand+'').setDisabled(false);
			getcmp('qxxiu_'+rand+'').setDisabled(true);
		}else{
			getcmp('setxiu_'+rand+'').setDisabled(true);
			getcmp('qxxiu_'+rand+'').setDisabled(false);
		}
	}
};
return {
	panel:panel
};