var Cal = new Object;

Cal.renderField = function(id,val,hideImg,addClass,hoverClass) {
	if(!addClass) { var addClass = ''; }
	
	var div = id+'_div';
	if(!val) { var val = ''; }
	
	if(!hideImg) {
		var img = '<img src="/public/images/admin/ico/calendar.png" alt="kalendarz" class="cal" />';
	} else {
		var img = '';
	}
	
	var html = '<a href="javascript:void(0);" class="cal" id="'+id+'_a">'
				+'<input type="text" name="'+id+'" id="'+id+'" value="'+val+'" onfocus="this.blur();" class="cal '+addClass+'" validate="required" failure="Proszę podać datę" />'
				+img
				+'</a>';
			
	$(div).innerHTML = html;
	
	if(hoverClass) {
		$(id).onmouseover = function() { this.addClassName(hoverClass); }
		$(id).onmouseout = function() { this.removeClassName(hoverClass); }
	}
	
	var dateStatusP = function(dt) {
		now = new Date();
						
		if(dt >= now) {
			return false; 
		} else {
			return true;
		}
	}
			
	var onClose = function(calendar) {
		calendar.hide();
	}
	
	var onUpdate = function(cal) {
		if(cal.dateClicked) {
			Reservation.updateRes();
		}
	}
					
	 Calendar.setup(
	    {
	      inputField  : id,         // ID of the input field
	      ifFormat    : "%Y-%m-%d",    // the date format
	      button      : id+"_a", // ID of the button
		  dateStatusFunc : dateStatusP,
		  onClose : onClose,
		  onUpdate : onUpdate
	    }
	 );
	
}
