// JavaScript Document
$(document).ready(function(){
	var f = function(date){
		var day = date.substr(0,2),
			month = date.substr(3,2),
			year = date.substr(6),
			jsDate = new Date(year, month-1, day),
			selDay = jsDate.getDay() == 0 ? 6 : jsDate.getDay()-1;

		if ((new Date()).getTime()/1000 - jsDate.getTime()/1000 < 7*24*3600){
			selDay = selDay - (new Date()).getDay();
			if (selDay < 0) {
				selDay = 7 + selDay;					
			}
		}
		if (!$(this).parent().find('a.calendarIcon').hasClass('href_action')){
			loadStripe(year + '-' + month + '-' + day, selDay, 0);
			$("a.calendarIcon").click();
			return false;
		} else {
			var categoriesSegments = category_aliace;
			if (typeof subcategory_aliace != 'undefined'){
				categoriesSegments += '/' + subcategory_aliace;
			}
			location.href = 'http://'+portalSection + mainDomain + categoriesSegments + '/'+day + '-' + month + '-' + year;
		}
	}

	var old_datepicker =  $.fn.datepicker;
	$.fn.datepicker = function(options){
		return old_datepicker.apply(this, [options]);
	};
   	$("#datepicker").datepicker({'minDate': '-4m', 'maxDate': '0', 'onSelect': f});

});
