var page_date={
	init:function(){
		var direction=document.cookie.match(/(?=^|; |;)page_date_direction=([^;]*)/);if(direction!=null)direction=direction[1];
		
		var selector_previous=$$('.MonthSelectorLeft');
		var selector_next=$$('.MonthSelectorRight');
		if(selector_previous){
			var action=selector_previous[0].href.match(/'changemonth\|(\d+)\|(\d+)'\)/);
			page_date.year_previous=action[1];
			page_date.month_previous=action[2];
			selector_previous[0].href="#";
			selector_previous[0].observe("click",function(event){page_date.go(page_date.year_previous,page_date.month_previous,"back");Event.stop(event);});
		}
		if(selector_next){
			var action=selector_next[0].href.match(/'changemonth\|(\d+)\|(\d+)'\)/);
			page_date.year_next=action[1];
			page_date.month_next=action[2];
			selector_next[0].href="#";
			selector_next[0].observe("click",function(event){page_date.go(page_date.year_next,page_date.month_next,"forward");Event.stop(event);});
		}
		
		if($$('.elTagListingAvailablity .elNoneFound').length){
			if(!direction||direction=="forward"){
				if(page_date.year_next<2010)
					page_date.go(page_date.year_next,page_date.month_next,"forward");
			}else if(direction=="back"){
				if(page_date.year_previous>1970)
					page_date.go(page_date.year_previous,page_date.month_previous,"back");
			}
		}
	},
	go:function(year,month,direction){
		document.cookie="page_date_direction="+direction;
		__doPostBack($$(".elCalendar")[0].id.replace(/(^[^_]+)_dash/,'$1$$dash'),"changemonth|"+year+"|"+month);
	}
};

Event.observe(window,"load",page_date.init);