/*
	Singleton для работы с интервалами дат
*/
var datepickerRange = {
  startDate:null, 
  endDate:null, 
  currentDate:new Date(), 
  selectCount:0,
	
  checkDays: function(){
    var self = this;
    if(this.startDate && this.endDate){
      $("#hcdatepicker").oneTime(1, function() {
        $('td>a.ui-state-default').each(function (i) {
          self.checkDay(this, i);
        });
      });
    }
  },
	
  checkDay: function(elem, currentPos){
    var currentDay=currentPos+1;
    var currentDate = new Date(this.currentDate.getFullYear(), 
    this.currentDate.getMonth(), currentDay);
    if(currentDate.getTime() >= this.startDate.getTime() &&
    currentDate.getTime() <= this.endDate.getTime()){
      $(elem).addClass('ui-state-active').removeClass('ui-state-highlight');	
    }
  },
	
  getSelectedDate: function(inst){
    return new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay);
  }
};

$(function() {
	$(".button, .big-button, .pager a.prev, .pager a.next").mousedown(function() {
		$(this).addClass("pushed");
	});
	$(".button, .big-button, .pager a.prev, .pager a.next").mouseup(function() {
		$(this).removeClass("pushed");
	});
	$(".button, .big-button, .pager a.prev, .pager a.next").mouseout(function() {
		$(this).removeClass("pushed");
	});
	
	$("#hbf-tabs .tabs a").click(function() {
		$("#hbf-tabs .t-item").show();
		$(this).parents(".t-item").hide();
		if ($(this).attr('id') == 'oneway') {
			$('#oneway_check').val(1);
		} else {
			$('#oneway_check').val(0);
		}
	});
	
	var checkinValueStart = null;
	var checkinValueEnd = null;
	var checkinValueCurrent = new Date();
	
	$(".cdatepicker").datepicker({
		minDate: 0,
		numberOfMonths: 2,
		buttonText: '',
		dateFormat: "dd.mm.yy",
		showOn: "both",
		buttonImage: "/i/ico_date.gif",
		buttonImageOnly: true,
		beforeShow: function(input, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
					
					var today = new Date();
					$(".cdatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = today.getDate() + i;
					    var currentDate = new Date(checkinValueCurrent.getFullYear(), checkinValueCurrent.getMonth(), currentDay);
					    
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
					    }
		        });
		      });
				}
		},
		onChangeMonthYear: function(year, month, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
					
					var today = new Date();
					$(".cdatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = today.getDate() + i;
					    var currentDate = new Date(checkinValueCurrent.getFullYear(), checkinValueCurrent.getMonth(), currentDay);
					    
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
					    }
		        });
		      });
				}
		},
		onSelect: function(selectedDate, instance) {
			switch(instance.id) {
				case 'pickupDateTime':
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
					$('#searchBoxContainer_Checkout').datepicker("option", "defaultDate", date );

					checkinValueStart = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
				case 'returnDateTime':
					checkinValueEnd = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
			}
			
			if (checkinValueStart && checkinValueEnd) {
				if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {

					var tmp = checkinValueEnd;
	        checkinValueEnd = checkinValueStart;
	        checkinValueStart = checkinValueEnd;
					
	        $('#pickupDateTime').datepicker("setDate", checkinValueStart);
	        $('#returnDateTime').datepicker("setDate", checkinValueEnd);
				}
			}
		}
	});
	
	$(".ddatepicker").datepicker({
		minDate: 0,
		numberOfMonths: 2,
		buttonText: '',
		dateFormat: "dd.mm.yy",
		showOn: "both",
		buttonImage: "/i/ico_date.gif",
		buttonImageOnly: true,
		beforeShow: function(input, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
					
					var today = new Date();
					$(".ddatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = today.getDate() + i;
					    var currentDate = new Date(checkinValueCurrent.getFullYear(), checkinValueCurrent.getMonth(), currentDay);
					    
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
					    }
		        });
		      });
				}
		},
		onChangeMonthYear: function(year, month, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
					
					var today = new Date();
					$(".ddatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = today.getDate() + i;
					    var currentDate = new Date(checkinValueCurrent.getFullYear(), checkinValueCurrent.getMonth(), currentDay);
					    
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
					    }
		        });
		      });
				}
		},
		onSelect: function(selectedDate, instance) {
			switch(instance.id) {
				case 'dDate':
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
					$('#searchBoxContainer_Checkout').datepicker("option", "defaultDate", date );

					checkinValueStart = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
				case 'rDate':
				
					checkinValueEnd = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
			}
			
			if (checkinValueStart && checkinValueEnd) {
				if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {

					var tmp = checkinValueEnd;
	        checkinValueEnd = checkinValueStart;
	        checkinValueStart = checkinValueEnd;
					
	        $('#dDate').datepicker("setDate", checkinValueStart);
	        $('#rDate').datepicker("setDate", checkinValueEnd);
				}
			}
		}
	});
	
	$(".hcdatepicker").datepicker({
		minDate: 0,
		numberOfMonths: 2,
		buttonText: '',
		dateFormat: "dd.mm.yy",
		showOn: "both",
		buttonImage: "/i/ico_date.gif",
		buttonImageOnly: true,
		beforeShow: function(input, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
//				console.debug('Start: ' + checkinValueStart);
//				console.debug('End: ' + checkinValueEnd);
//				console.debug('Current: ' + checkinValueCurrent);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
						
					var today = new Date();
					$(".hcdatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = today.getDate() + i;
					    var currentDate = new Date(checkinValueStart.getFullYear(), checkinValueStart.getMonth(), currentDay);

//					    console.debug(currentDate + ' | ' + currentDate.getTime());
							
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
//					console.debug('currentDay: ' + currentDay + '; ' + 'currentDate: ' + currentDate);
//					console.debug('checkinValueStart: ' + checkinValueStart + '; ' + 'checkinValueEnd: ' + checkinValueEnd);
//		    	console.debug(currentDate.getTime() + ' ; ' + checkinValueStart.getTime() + ' ; ' + currentDate.getTime() + ' ; ' + checkinValueEnd.getTime() );
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
//					console.debug('==========================');
					    }
		        });
		      });
				}
		},
		onChangeMonthYear: function(year, month, instance) {
				checkinValueCurrent = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				
//				console.debug('Start: ' + checkinValueStart);
//				console.debug('End: ' + checkinValueEnd);
				console.debug('Selected: ' + instance.selectedYear +' | '+ instance.selectedMonth +' | '+ instance.selectedDay);
				
				if (checkinValueStart && checkinValueEnd) {
					if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {
						var tmp = checkinValueEnd;
		        checkinValueEnd = checkinValueStart;
		        checkinValueStart = checkinValueEnd;	
					}
					
					var today = new Date();
					$(".hcdatepicker").oneTime(1, function() {
		        $('td>a.ui-state-default').each(function (i) {
		          var currentDay = checkinValueCurrent.getDate() + i;
		          
		          if (checkinValueStart.getMonth() == checkinValueEnd.getMonth()) {
					    	var currentDate = new Date(checkinValueStart.getFullYear(), (checkinValueStart.getMonth() - 1), currentDay);
		          } else {
		          	var currentDate = new Date(checkinValueStart.getFullYear(), (checkinValueEnd.getMonth() - 1), currentDay);
		          }
					    
					    console.debug('i: ' + i + '; currentDay: ' + currentDay + '; currentDate: ' + currentDate + ' | ' + currentDate.getTime());
//					    console.debug('Current: ' + checkinValueCurrent);
//					    console.debug('Start: ' + checkinValueStart + ' | ' + checkinValueStart.getTime());
//							console.debug('End: ' + checkinValueEnd + ' | ' + checkinValueEnd.getTime());
					    
					    if( (currentDate.getTime() >= checkinValueStart.getTime()) && (currentDate.getTime() <= checkinValueEnd.getTime()) ){
					    	console.debug('Apply');
					      $(this).addClass('ui-state-active').removeClass('ui-state-highlight');	
					    }
					    console.debug('======================');
		        });
		      });
				}
		},
		onSelect: function(selectedDate, instance) {
			switch(instance.id) {
				case 'searchBoxContainer_Checkin':
					$('#searchBoxContainer_CheckinValue').val(selectedDate);
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
					$('#searchBoxContainer_Checkout').datepicker("option", "defaultDate", date );
					
					checkinValueStart = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
				case 'searchBoxContainer_Checkout':
					$('#searchBoxContainer_CheckoutValue').val(selectedDate);
					
					checkinValueEnd = new Date(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
				break;
			}
			
			if (checkinValueStart && checkinValueEnd) {
				if(checkinValueStart.getTime() > checkinValueEnd.getTime()) {

					var tmp = checkinValueEnd;
	        checkinValueEnd = checkinValueStart;
	        checkinValueStart = checkinValueEnd;
					
	        $('#searchBoxContainer_Checkin').datepicker("setDate", checkinValueStart);
	        $('#searchBoxContainer_Checkout').datepicker("setDate", checkinValueEnd);
				}
			}
			
		}
	});
	
	$("#tabs li a").click(function() {
		if (!$(this.parentNode).hasClass("act")) {
			$("#tabs li").removeClass("act");
			$(this.parentNode).addClass("act");
		}
		
		var selected = $(this.parentNode).attr('id');
		if (selected == 'dest_block') {
				$('#destOrHotel_dest_block').show();
				$('#destOrHotel_hotel_block').hide();
				$('#hotelSearchRadio').attr("checked","");
				$('#citySearchRadio').attr("checked","checked");
		}
		if (selected == 'hotel_block') {
				$('#destOrHotel_dest_block').hide();
				$('#destOrHotel_hotel_block').show();
				$('#citySearchRadio').attr("checked","");
				$('#hotelSearchRadio').attr("checked","checked");
		}
		
	});
	
	$(".i-ddl .down, .i-ddl em").click(function() {
		var list = $(".list", this.parentNode);
		if (list.is(":visible")) {
			list.hide();
			$(this.parentNode.parentNode).css("z-index", 1);
		}
		else {
			list.show();
			$(this.parentNode.parentNode).css("z-index", 99);
		}
	});
	$(".i-ddl .list li").click(function() {
		$(this).parents(".i-ddl").find("em").text($(this).text());
		$(this).parents(".list").hide();
	});
	$(".i-ddl").each(function() {
		var a = $(".down", this).get(0);
		var em = $("em", this).get(0);
		var ddl = this;
		
		addEvent(document, 'click', function(event){
			var event = event || window.event;
			var t = event.target || event.srcElement;
			
			if (t != a && t != em && !isChildNode(ddl, t)) {
				$(".list", ddl).hide();
				$(ddl).css("z-index", 1);
			}
		});
	});
	
	$(".cbx i, .cbx label").click(function() {
		var id = $("label", this.parentNode).attr("for");
		
		if ($(this.parentNode).hasClass("checked")) {
			$(this.parentNode).removeClass("checked");
			$("#" + id).removeClass("i-pas");
			$("#" + id).parents(".item").find(".lbl").removeClass("l-pas");	
		}
		else {
			$(this.parentNode).addClass("checked");
			$("#" + id).addClass("i-pas");
			$("#" + id).parents(".item").find(".lbl").addClass("l-pas");
		}
	})
	
	$(".btn-camera").click(showPopup);
	$("#overlay, #pop-close").click(hidePopup);
	
});

function showPopup() {
	$("#overlay, #popup").show();
}
function hidePopup() {
	$("#overlay, #popup").hide();
}

function setInpVal(a, fieldId) {
	document.getElementById(fieldId).value = a.innerHTML;
}

function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent)
		obj.attachEvent( "on"+type, fn );
}

function removeEvent(obj, type, fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(type, fn, false);
	else if (obj.detachEvent)
		obj.detachEvent( "on"+type, fn );
}

function isChildNode(elem, sell) {
	for (var childItem in elem.childNodes) {
		if (elem.childNodes[childItem].nodeType == 1) {
			if (elem.childNodes[childItem] == sell)
				return true;
			else if (isChildNode(elem.childNodes[childItem], sell))
				return true;
		}
	}
	return false;
}

/*
(function (a, d) {
    function k(o, q) {
        a.extend(o, q);
        for (var v in q) if (q[v] == null || q[v] == d) o[v] = q[v];
        return o
    }
    a.fn.datepicker = function (o) {
        if (!this.length) return this;
        if (!a.datepicker.initialized) {
            a(document).mousedown(a.datepicker._checkExternalClick).find("#hc_bodyElements").append(a.datepicker.dpDiv);
            a.datepicker.initialized = true
        }
        var q = Array.prototype.slice.call(arguments, 1);
        if (typeof o == "string" && (o == "isDisabled" || o == "getDate" || o == "widget")) return a.datepicker["_" + o + "Datepicker"].apply(a.datepicker, [this[0]].concat(q));
        if (o == "option" && arguments.length == 2 && typeof arguments[1] == "string") return a.datepicker["_" + o + "Datepicker"].apply(a.datepicker, [this[0]].concat(q));
        return this.each(function () {
            typeof o == "string" ? a.datepicker["_" + o + "Datepicker"].apply(a.datepicker, [this].concat(q)) : a.datepicker._attachDatepicker(this, o)
        })
    };
    a.datepicker._hideDatepicker = function (o) {
        var q = this._curInst;
        if (!(!q || o && q != a.data(o, PROP_NAME))) if (this._datepickerShowing) {
            o = this._get(q, "showAnim");
            var v = this._get(q, "duration"),
                y = function () {
                    a.datepicker._tidyDialog(q);
                    this._curInst = null
                };
            if (a.effects && a.effects[o]) q.dpDiv.hide(o, a.datepicker._get(q, "showOptions"), v, y);
            else q.dpDiv[o == "slideDown" ? "slideUp" : o == "fadeIn" ? "fadeOut" : "hide"](o ? v : null, y);
            o || y();
            a.datepicker._triggerOnClose(q);
            this._datepickerShowing = false;
            this._lastInput = null;
            if (this._inDialog) {
                this._dialogInput.css({
                    position: "absolute",
                    left: "0",
                    top: "-100px"
                });
                if (a.blockUI) {
                    a.unblockUI();
                    a("#hc_bodyElements").append(this.dpDiv)
                }
            }
            this._inDialog = false
        }
    };
    a.datepicker._showDatepicker = function (o) {
        o = o.target || o;
        if (o.nodeName.toLowerCase() != "input") o = a("input", o.parentNode)[0];
        if (!(a.datepicker._isDisabledDatepicker(o) || a.datepicker._lastInput == o)) {
            var q = a.datepicker._getInst(o);
            if (a.datepicker._curInst && a.datepicker._curInst != q) {
                a.datepicker._datepickerShowing && a.datepicker._triggerOnClose(a.datepicker._curInst);
                a.datepicker._curInst.dpDiv.stop(true, true)
            }
            var v = a.datepicker._get(q, "beforeShow");
            k(q.settings, v ? v.apply(o, [o, q]) : {});
            q.lastVal = null;
            a.datepicker._lastInput = o;
            a.datepicker._setDateFromField(q);
            if (a.datepicker._inDialog) o.value = "";
            if (!a.datepicker._pos) {
                a.datepicker._pos = a.datepicker._findPos(o);
                a.datepicker._pos[1] += o.offsetHeight
            }
            var y = false;
            a(o).parents().each(function () {
                y |= a(this).css("position") == "fixed";
                return !y
            });
            if (y) {
                a.datepicker._pos[0] -= document.documentElement.scrollLeft;
                a.datepicker._pos[1] -= a.browser.webkit ? document.body.scrollTop : document.documentElement.scrollTop
            }
            v = {
                left: a.datepicker._pos[0],
                top: a.datepicker._pos[1]
            };
            a.datepicker._pos = null;
            q.dpDiv.empty();
            q.dpDiv.css({
                position: "absolute",
                display: "block",
                top: "-1000px"
            });
            a.datepicker._updateDatepicker(q);
            v = a.datepicker._checkOffset(q, v, y);
            q.dpDiv.css({
                position: a.datepicker._inDialog && a.blockUI ? "static" : y ? "fixed" : "absolute",
                display: "none",
                left: v.left + "px",
                top: v.top + "px"
            });
            if (!q.inline) {
                v = a.datepicker._get(q, "showAnim");
                var g = a.datepicker._get(q, "duration"),
                    m = function () {
                        var r = q.dpDiv.find("iframe.ui-datepicker-cover");
                        if (r.length) {
                            var w = a.datepicker._getBorders(q.dpDiv);
                            r.css({
                                left: -w[0],
                                top: -w[1],
                                width: q.dpDiv.outerWidth(),
                                height: q.dpDiv.outerHeight()
                            })
                        }
                    };
                q.dpDiv.zIndex(a(o).zIndex() + 1);
                a.datepicker._datepickerShowing = true;
                if (a.effects && a.effects[v]) q.dpDiv.show(v, a.datepicker._get(q, "showOptions"), g, m);
                else q.dpDiv[v || "show"](v ? g : null, m);
                if (!v || !g) m();
                q.input.is(":visible") && !q.input.is(":disabled") && q.input.focus();
                a.datepicker._curInst = q
            }
        }
    }
})(jQuery);

EP.Translations = {
    strings: {},
    set: function (a, d) {
        if ($.isArray(a)) this.setMultiple(a);
        else this.strings[a] = d
    },
    setMultiple: function (a) {
        for (var d = a.length, k = 0; k < d; k++) {
            var o = a[k];
            this.set(o[0], o[1])
        }
    },
    get: function (a, d) {
        var k = this.strings[a];
        if (k != "") {
            typeof d != "undefined" && $.each(d, function (o, q) {
                k = k.replace(o, q)
            });
            return k
        } else return ""
    }
};

if (typeof EP == "undefined") var EP = {};

window.EP || (EP = {});
(function () {
    EP.SearchBox = {
        _defaultCheckinSelector: "#DateSelection_Checkin",
        _defaultCheckoutSelector: "#DateSelection_Checkout",
        _defaultCheckin: null,
        _defaultCheckout: null,
        setDefaults: function (a) {
            var d = EP.DateSelection;
            if (a.defaultCheckin) this._defaultCheckin = d.convertToDateObject(a.defaultCheckin);
            if (a.defaultCheckout) this._defaultCheckout = d.convertToDateObject(a.defaultCheckout);
        },
        SearchBoxInstance: function (a) {
            var d = EP.SearchBox,
                k = EP.DateSelection,
                o = a.find(d._defaultCheckinSelector);
            		a = a.find(d._defaultCheckoutSelector);
            var q = k.retrieveDateSelectInstance(o),
                v = k.retrieveDateSelectInstance(a);
            (function () {
                var y = d._defaultCheckin,
                    g = d._defaultCheckout;
                    
//                    console.debug(y);
//            				console.debug(g);
            
                if (y && g) if (!(y < k._minDate)) if (!(g > k._maxDate)) {
                    q.setSelectedDate(y);
                    q.setToDate(g);
                    v.setSelectedDate(g);
                    v.setFromDate(y)
                }
            })();
            q.setChangeCallback(function (y) {
                v.setFromDate(y);
                var g = v.getSelectedDate();
                if (!(g && g > y)) {
                    y = new Date(y.getTime());
                    g = y.getDate();
                    y.setDate(g + 1);
                    y > k._maxDate || v.setSelectedDate(y)
                }
            });
            v.setChangeCallback(function (y) {
                q.setToDate(y)
            })
        }
    }
})();

window.EP || (EP = {});
(function () {
    EP.DateSelection = {
        _currentServerTime: null,
        _currentCulture: "",
        _monthNames: [],
        _dayNames: [],
        _dayWrapperClass: "hc_f_cal_day",
        _monthWrapperClass: "hc_f_cal_month",
        _datepickerInputClass: "hcdatepicker",
        _datepickerImage: "/i/ico_date.gif",
        _maxMonthsToShow: 12,
        _minDate: null,
        _maxDate: null,
        _selectionInstances: [],
        init: function (a) {
            this._currentServerTime = new Date(a.getTime());
            a = $.datepicker.regional[this._currentCulture];
            this._monthNames = a.monthNames;
            this._dayNames = a.dayNamesShort;
            this.initMinMaxDates()
        },
        setCulture: function (a) {
            this._currentCulture = a
        },
        initMinMaxDates: function () {
            var a = this.retrieveMinValidDateServerBased(),
                d = this.addMonths(a, this._maxMonthsToShow),
                k = this.getDaysInMonth(d.getFullYear(), d.getMonth());
            d.setDate(k);
            this._minDate = a;
            this._maxDate = d
        },
        addDateSelectInstance: function (a, d) {
            this._selectionInstances.push([a, d])
        },
        findDateSelectInstance: function (a) {
            for (var d = this._selectionInstances, k = d.length, o = 0; o < k; o++) {
                var q = d[o];
                if (q[1] == a) return q[0]
            }
            return null
        },
        retrieveDateSelectInstance: function (a) {
//        		console.debug(a);
            a = a.find("." + this._datepickerInputClass);
//            console.debug(a);
            if (a.length > 0) return this.findDateSelectInstance(a[0]);
            return null
        },
        retrieveMinValidDateServerBased: function () {
            var a = new Date(this._currentServerTime.getTime());
            a.setMinutes(a.getMinutes() - 781);
            a.setMinutes(0);
            a.setHours(0);
            a.setSeconds(0);
            a.setMilliseconds(0);
            return a
        },
        retrieveMaxValidDateServerBased: function () {
            return this.addMonths(this.retrieveMinValidDateServerBased(), this._maxMonthsToShow)
        },
        addMonths: function (a, d) {
            a = new Date(a.getTime());
            var k = a.getDate();
            a.setMonth(a.getMonth() + d);
            if (k > a.getDate()) a = this.addDays(a, -a.getDate());
            return a
        },
        addDays: function (a, d) {
            a = new Date(a.getTime());
            a.setTime(a.getTime() + d * 864E5);
            return a
        },
        getDaysInMonth: function (a, d) {
            return 32 - this.daylightSavingAdjust(new Date(a, d, 32)).getDate()
        },
        daylightSavingAdjust: function (a) {
            if (!a) return null;
            a.setHours(a.getHours() > 12 ? a.getHours() + 2 : 0);
            return a
        },
        convertToDateObject: function (a) {
            return $.datepicker.parseDate("yy-mm-dd", a)
        },
        convertToDefaultStringFormat: function (a) {
            return $.datepicker.formatDate("yy-mm-dd", a)
        },
        isSameMonth: function (a, d) {
            if (a.getMonth() != d.getMonth()) return false;
            if (a.getFullYear() != d.getFullYear()) return false;
            return true
        },
        closeCurrentDatepickerInstance: function () {
            var a = $.datepicker._curInst;
            a && a.dpDiv[0].style.display == "block" && $(a.input[0]).next().click()
        },
        DateSelect: function (a, d) {
            function k(K) {
                if (K) W = true;
                X = K;
                da && da(K)
            }
            function o(K) {
                K = K || {};
                var D = X,
                    O = "",
                    I = H._dayNames,
                    ja = EP.Translations.get("DatedropdownDay"),
                    ka = D ? true : false,
                    f, fa, qa = new Date(H._minDate);
                if (ka) {
                    f = D.getDate();
                    fa = H.getDaysInMonth(D.getFullYear(), D.getMonth());
                    qa = new Date(D.getTime())
                } else {
                    f = null;
                    fa = 31
                }
                if (K.forceMonth) {
                    qa = new Date(K.forceMonth.getTime());
                    fa = H.getDaysInMonth(qa.getFullYear(), qa.getMonth());
                    ka = true
                }
                W || (O += '<option value="{2}" {1}>{0}</option>'.replace("{0}", ja).replace("{1}", f == null ? 'selected="selected"' : "").replace("{2}", "-1"));
                for (K = 1; K < fa + 1; K++) {
                    qa.setDate(K);
                    D = I[qa.getDay()];
                    O += '<option value="{2}" {1}>{0}</option>'.replace("{0}", ka ? D + " " + K : K).replace("{1}", K == f ? 'selected="selected"' : "").replace("{2}", K)
                }
                J.html(O)
            }
            function q() {
                var K =
                X,
                    D = H._minDate,
                    O = D.getMonth();
                D = D.getFullYear();
                var I = D.toString().substring(2),
                    ja = H._monthNames,
                    ka = H._maxMonthsToShow,
                    f = EP.Translations.get("DatedropdownMonthYearFormat"),
                    fa = EP.Translations.get("DatedropdownMonth"),
                    qa = K ? true : false,
                    va, za;
                if (qa) {
                    va = K.getMonth();
                    za = K.getFullYear()
                }
                K = "";
                var oa = 0;
                K = "";
                if (W) ba = true;
                else K += '<option value="{0}" {2}>{1}</option>'.replace("{0}", "-1").replace("{1}", fa).replace("{2}", qa ? "" : 'selected="selected"');
                for (; oa <= ka;) {
                    fa = f.replace("[InsertMonthName]", ja[O]).replace("[InsertShortYear]", I);
                    K += '<option value="{0}" {2}>{1}</option>'.replace("{1}", fa).replace("{0}", D + "-" + (O + 1)).replace("{2}", O == va && D == za ? 'selected="selected"' : "");
                    oa++;
                    O++;
                    if (O == 12) {
                        O = 0;
                        D++;
                        I = D.toString().substring(2)
                    }
                }
                U.html(K)
            }
            function v(K) {
                var D = U.val(),
                    O = J.val();
                if (K && ca && D == "-1") {
                    D = ca;
                    U.val(D)
                } else if (D == "-1") return;
                ca = D;
                K = D.split("-");
                K = new Date(K[0], K[1] - 1, 1);
                D = H.getDaysInMonth(K.getFullYear(), K.getMonth() - 1);
                if (O == "-1") o({
                    forceMonth: K
                });
                else {
                    O = parseInt(O, 10);
                    O > D && K.setDate(1);
                    K.setDate(O);
                    k(K);
                    o();
                    ba || q();
                    y()
                }
            }

            function y() {
                X && T.datepicker("setDate", X)
            }
            function g() {
                var K = T.datepicker("getDate");
                k(K);
                q();
                o()
            }
            function m(K, D) {
                D = D.getTime();
                K = K.getTime();
                if (D === K) return [true, "hc_cal_date_upper"];
                var O = X;
                if (!O) return [true, ""];
                O = O.getTime();
                if (D > O && K > O && K < D) return [true, "hc_cal_date_range"];
                return [true, ""]
            }
            function r(K, D) {
                D = D.getTime();
                K = K.getTime();
                if (D === K) return [true, "hc_cal_date_lower"];
                var O = X;
                if (!O) return [true, ""];
                O = O.getTime();
                if (D < O && K < O && K > D) return [true, "hc_cal_date_range"];
                return [true, ""]
            }
            function w(K, D, O) {
                var I = $(O.dpDiv[0]);
                H.isSameMonth(new Date, new Date(K, D - 1, 1)) ? window.setTimeout(function () {
                    I.find(".ui-datepicker-current").hide()
                }, 0) : window.setTimeout(function () {
                    I.find(".ui-datepicker-current").show()
                }, 0)
            }
            function A(K, D) {
                var O = $(D.dpDiv[0]);
                O.css("margin-top", $(K).next().height() + "px");
                window.setTimeout(function () {
                    O.css("z-index", 950);
                    P() || O.find(".ui-datepicker-current").hide()
                }, 1)
            }
            function P() {
                if (X == null) return false;
                if (H.isSameMonth(new Date, X)) return false;
                return true
            }
            d = d || {};
            var H = EP.DateSelection,
                J = $("span." + H._dayWrapperClass + " select", a),
                U = $("span." + H._monthWrapperClass + " select", a),
                T = $("." + H._datepickerInputClass, a),
                X;
            X = d.selectedDate ? H.convertToDateObject(d.selectedDate) : null;
            var Y = null,
                V = null,
                W = false,
                ba = false,
                ca = null,
                da = null;
            H.addDateSelectInstance(this, T[0]);
            q();
            o();
            (function () {
                T.datepicker({
                    showOn: "button",
                    buttonImage: H._datepickerImage,
                    buttonImageOnly: true,
                    changeMonth: true,
                    changeYear: true,
                    duration: "fast",
                    onSelect: g,
                    minDate: H._minDate,
                    maxDate: H._maxDate,
                    buttonText: "",
                    beforeShow: function (K, D) {
                        A(K, D)
                    },
                    onChangeMonthYear: function (K, D, O) {
                        w(K, D, O)
                    },
                    beforeShowDay: function (K) {
//                    	console.debug("Y: " + Y + " | V: " + V);
                        K = Y ? m(K, Y) : V ? r(K, V) : [true, ""];
                        return K
                    }
                })
            })();
            y();
            J.bind("change", function () {
//            	console.debug(1);
                v(true)
            });
            U.bind("change", function () {
//            	console.debug(2);
                v()
            });
            this.getSelectedDate = function () {
                return X
            };
            this.setSelectedDate = function (K) {
                k(K);
                q();
                o();
                y()
            };
            this.setToDate = function (K) {
                if (K) {
                    K = new Date(K.getTime());
                    K.setHours(0);
                    K.setMinutes(0);
                    K.setSeconds(0);
                    K.setMilliseconds(0);
                    Y = K
                } else Y = null
            };
            this.setFromDate = function (K) {
                if (K) {
                    K = new Date(K.getTime());
                    K.setHours(0);
                    K.setMinutes(0);
                    K.setSeconds(0);
                    K.setMilliseconds(0);
                    V = K
                } else V = null
            };
            this.setChangeCallback = function (K) {
                da = K
            }
        }
    }
})();
*/
