var stuff = new (function () {
    var self = this;

    this.clearValue = function (field) {
        field.value = "";
        field.onclick = function () {};
    }

    this.unitByValue = new (function () {
        this.getUnit = function (value, units) {
            var unit = units["_" + value];
            return unit || unit + 1 ? unit : units.d;
        }
    })();

    this.DaysLeftCounter = function () {
        var targetDate = new Date(2005, 0, 1),
            infoString = "{value}{unit}",
            units = {
            d: ""
            };

        this.getDaysLeft = function () {
            var currDate = new Date(),
                timeSpan = Math.ceil((targetDate - currDate) / 86400000);

            return timeSpan <= 0 ? "" : infoString.split("{value}").join(timeSpan).split("{unit}").join(self.unitByValue.getUnit(timeSpan, units));
        }

        this.getInfoString = function () {
            return infoString;
        }
        this.setInfoString = function (newInfoString) {
            return infoString = newInfoString;
        }

        this.getTargetDate = function () {
            with (targetDate) {
                return {
                    year: getFullYear(),
                    month: getMonth(),
                    date: getDate()
                };
            }
        }
        this.setTargetData = function (newTargetDate) {
            return targetDate = new Date(newTargetDate.year, newTargetDate.month, newTargetDate.date);
        }

        this.getUnits = function () {
            return units;
        }
        this.setUnits = function (newUnits) {
            return units = newUnits;
        }
    }

  this.openCenteredWindow = function (link, width, height, scrollbars, resizable) {
    scrollbars = "scrollbars=" + (scrollbars == "scrollbars" ? "1" : "0");
    resizable = "resizable=" + (resizable == "resizable" && window.resizeTo ? "1" : "0");

    var maxWidth = Math.round(screen.width),
        maxHeight = Math.round(screen.height),
        windowLeft = Math.round((screen.width - width)/2),
        windowTop = Math.round((screen.height - height)/2);

    width = width > maxWidth ? maxWidth : width;
    height = height > maxHeight ? maxHeight : height;

    var windowParams = "menubar=0," + scrollbars + ",titlebar=1," + resizable + ",width=" + (width+20) + ",height=" + (height+25) + ",left=" + windowLeft + ",top=" + windowTop + ",screenX=" + windowLeft + ",screenY=" + windowTop + ",status=0",
        currWindow = window.open(link.href, link.target, windowParams);

    if (currWindow._alreadyOpened) {
      currWindow.close();
      currWindow = null;
      currWindow = window.open(link.href, link.target, windowParams);
    }
    currWindow._alreadyOpened = true;

    currWindow.focus();

    return currWindow;
  }
});