



function ComponentMenu(node, parameters) {
ComponentMenu.baseConstructor.call(this);
}
Cls.inherit(ComponentMenu, Object, {
});

function ComponentTopMenuMenu() {
ComponentTopMenuMenu.baseConstructor.apply(this, arguments);
}
Cls.inherit(ComponentTopMenuMenu, ComponentMenu, {
});

function ComponentSideMenuMenu() {
ComponentSideMenuMenu.baseConstructor.apply(this, arguments);
}
Cls.inherit(ComponentSideMenuMenu, ComponentMenu, {
});



function Transition() {
Transition.baseConstructor.call(this);
this.setFrames(10);
this.setTimeout(20);
this.setHandles([]);
this._calculateFraction = function(frame) {
return frame / this.getFrames();
}.bind(this);
}
Cls.inherit(Transition, Object, {
cancel: function() {
this.getHandles().each(clearTimeout);
this.setHandles([]);
},
run: function() {
this.cancel();
this.doOnStart();
this.doOnFrame(0, this._calculateFraction(0));
this.setupTimeout();
},
timeoutStep: function(frame) {
this.doOnFrame(frame, this._calculateFraction(frame));
if (frame >= this.getFrames()) {
this.doOnComplete();
};
},
setupTimeout: function() {
for (var i = 1; i <= this.getFrames(); i++) {
this.getHandles().push(setTimeout(function(i) { 
return function() { 
this.timeoutStep(i); 
}.bind(this) 
}.bind(this)(i), i * this.getTimeout()));
};
}
});
Cls.property(Transition, "frames");
Cls.property(Transition, "timeout");
Cls.property(Transition, "handles");
Cls.event(Transition, "complete");
Cls.event(Transition, "start");
Cls.event(Transition, "frame");




Cls.inherit(TransitionSequence, Transition, {
add: function(t) {
this._transitions.push(t);
return t;
},
run: function(t) {
var f = function(transitions) {
if (transitions.length) {
transitions[0].onComplete(function() { f(transitions.slice(1)); });
transitions[0].run();
};
};
f(this._transitions);
}
});
function TransitionSequence() {
TransitionSequence.baseConstructor.call(this);
this._transitions = [];
}




Cls.inherit(TransitionComposite, Transition, {
add: function(t) {
this._transitions.push(t);
return t;
}
});
function TransitionComposite() {
TransitionComposite.baseConstructor.call(this);
this._transitions = [];
this.onFrame(function(frame, fraction) {
this._transitions.each(function(t) {
t.doOnFrame(frame, fraction);
});
}.bind(this));
}


Cls.inherit(TransitionTop, Transition);
function TransitionTop(object, start, stop) {
TransitionTop.baseConstructor.call(this);
this.onFrame(function(frame, fraction) {
object.style.top = (start + (stop - start) * fraction).toString() + "px";
});
}


var Opacity = new Object();
Opacity.set = function(object, opacity) {
if (System.isIE(0, 9)) {
object.style.filter = sprintf("progid:DXImageTransform.Microsoft.Alpha(opacity=%s)", Math.round(opacity*100));
} else {
object.style.opacity = opacity;
};
}



Cls.inherit(TransitionOpacity, Transition);
function TransitionOpacity(object, startOpacity, stopOpacity) {
TransitionOpacity.baseConstructor.call(this);
this.onFrame(function(frame, fraction) {
Opacity.set(object, startOpacity + (stopOpacity - startOpacity) * fraction);
});
if (stopOpacity == 1 || stopOpacity == 0) {
this.onComplete(function() {
object.style.filter = "";
});
};
}



function FeatureInputHelpValue(element, text) {





if (element.value != "" && text) {
return;
};
page.addInputFeature(this);
this._cleared = false;
this._restored = false;
this._element = element;
this._text = text || element.value;
this._type = element.type;
var _this = this;
addEvent(element, "focus", function(e) { _this.onFocus(e); });
addEvent(element, "blur", function(e) { _this.onBlur(e); });

ac(this._element, "help");
this._element.value = this._text;
}
Cls.inherit(FeatureInputHelpValue, Object, {
restore: function() {
if (!this._cleared && this._restored) {
this._restored = false;
if (this._element.value != "") {
this._cleared = true;
} else {
this._element.value = this._text;
ac(this._element, "help");
};
};
},
cleanup: function() {
if (!this._cleared) {
this._restored = true;
this._element.value = "";
rc(this._element, "help");
};
},
onBlur: function(e) {
this.restore();
},
onFocus: function(e) {
if (!this._cleared) {
if (this._element.value != this._text) {
this._cleared = true;
rc(this._element, "help");
};
};
this.cleanup();
},
onSubmit: function(e) {



this.onBlur();
if (!this._cleared) {
this._element.value = "";
rc(this._element, "help");
};
},
filterValue: function(value) {
if (!this._cleared &&
this._element.className.match("help")) {
return "";
};
return value;
},
resetValue: function(value) {
this._cleared = false;
this._element.value = this._text;
ac(this._element, "help");
}
})




Cls.inherit(FeaturePasswordHelpValue, Object);
function FeaturePasswordHelpValue(element, text) {
this._cleared = false;
this._element = element;
this._text = text || element.value;
this._overlay = this.createOverlay(element, this._text);
this._type = element.type;
var _this = this;
addEvent(element, "focus", function(e) { _this.onFocus(e); });
addEvent(element, "keydown", function(e) { _this.onKeyDown(e); });
addEvent(element, "blur", function(e) { _this.onBlur(e); });

setTimeout(function() { element.value = ""; }, 50);
}
FeaturePasswordHelpValue.prototype.createOverlay = function(element, text) {
var overlay = document.createElement("div");
overlay.className = "overlay_help";
overlay.style.position = "absolute";
overlay.style.top = (element.offsetTop + 1).toString() + "px";
overlay.style.left = (element.offsetLeft + 1).toString() + "px";
overlay.style.width = (element.offsetWidth - 6).toString() + "px";
overlay.style.height = (element.offsetHeight - 6).toString() + "px";

["font", "font-family", "font-size", "font-weight", "margin", "padding", "padding-left", "padding-top", "line-height"].each(function(property) {
var value = getElementComputedStyle(element, property);
try {
overlay.style[propertyCssToPropertyDom(property)] = value;
} catch (e) {

};
});  
overlay.appendChild(document.createTextNode(text));
element.offsetParent.appendChild(overlay);
var _this = this;
addEvent(overlay, "click", function(e) { _this.onOverlayClick(e); });
return overlay;
}
FeaturePasswordHelpValue.prototype.hideOverlay = function() {
this._overlay.style.display = "none";
}
FeaturePasswordHelpValue.prototype.showOverlay = function() {
this._overlay.style.display = "block";
}

FeaturePasswordHelpValue.prototype.onBlur = function(e) {
if (!this._cleared) {
if (this._element.value != '') {
this._cleared = true;
} else {
this.showOverlay();
};
};
}
FeaturePasswordHelpValue.prototype.onFocus = function(e) {
this.hideOverlay();
}
FeaturePasswordHelpValue.prototype.onKeyDown = function(e) {
this.hideOverlay();
}
FeaturePasswordHelpValue.prototype.onOverlayClick = function(e) {
this.hideOverlay();
this._element.focus();
}






function Checkbox(input) {
this.setInput(input);
this.init();
}
Cls.inherit(Checkbox, Object, {
init: function() {
this.setControl({
wrapper: $E("span", "rp_checkbox")
});

this.getInput().parentNode.insertBefore(this.getControl().wrapper, this.getInput());

this.getInput().style.display = "none";

Evt.add(this.getControl().wrapper, "click", this.onClick.bind(this));

if (this.getInput().checked) { 
ac(this.getControl().wrapper, "checked"); 
};
},
onClick: function(e) {
tc(this.getControl().wrapper, "checked");
this.getInput().checked = hasClass(this.getControl().wrapper, "checked");
},
uncheck: function() {
rc(this.getControl().wrapper, "checked");
this.getInput().checked = false;
}
});
Cls.property(Checkbox, "input");
Cls.property(Checkbox, "control");
Cls.event(Checkbox, "change");










function LoginForm() {
LoginForm.baseConstructor.call();
}
Cls.inherit(LoginForm, Object, {
CHOICES_TOP: -40,
LOGIN_TOP: 0,
INVISIBLE_TOP: -70,
bind: function() {
if (!$("login_form")) { return; };
new FeatureInputHelpValue($("login_form_login"), "email");
new FeaturePasswordHelpValue($("login_form_password"), "пароль");
new Checkbox($$("#login_form .remember input"));

Evt.add($$("#layout_header .user .info .login"), "click", function(e) {
var tr = new TransitionSequence();
tr.add(new TransitionTop(this.getForm(), this.CHOICES_TOP, this.INVISIBLE_TOP))
.onComplete(function() {
this.showLogin();
}.bind(this));
tr.add(new TransitionTop(this.getForm(), this.INVISIBLE_TOP, this.LOGIN_TOP));
tr.run();
}.bind(this).stopEvent());
},
showLogin: function() {
var form = this.getForm();
form.down(".form").style.visibility = "visible";
form.down(".info").style.visibility = "hidden";
ac(form, "user_login");
rc(form, "user_info");

var b = form.down(".boundary");
rc(b, "boundary"); ac(b, "boundary");
},
showInfo: function() {
var form = this.getForm();
form.down(".info").style.visibility = "visible";
form.down(".form").style.visibility = "hidden";
ac(form, "user_info");
rc(form, "user_login");
},
getForm: function() {
return $$("#layout_header .user");
}
});
function getSrcElement(e) {
return e.target || e.srcElement;
}



Array.prototype.findFirst = function(predicate) {
for (var i = 0; i < this.length; i++) {
var item = this[i];
if (predicate(item)) {
return item;
};
};
return null;
}
function contains(r, p) {
return r.left <= p.x && 
r.right >= p.x &&
r.top <= p.y &&
r.bottom >= p.y;
}

function getRect(element) {
return {
left: getLeft(element),
right: getRight(element),
top: getTop(element),
bottom: getBottom(element)
};
}

function DropTarget(element) {
this._element = element;
}
Cls.inherit(DropTarget, Object, {
});
Cls.event(DropTarget, "out");
Cls.event(DropTarget, "over");
Cls.event(DropTarget, "drop");














function FeatureDraggable(element, handles, options) {
FeatureDraggable.baseConstructor.call(this);
options = options || {};
handles = handles || [element];
this.doTrackDrag = options.track;

this._updatePos = options.updatePos == "no" ? false : true;
this._customData = {};
this.LEFT_MARGIN = -268;
this.TOP_MARGIN = -308;
this._element = element;
this._trackHandler = this.trackDrag.bind(this);
this._endHandler = this.endDrag.bind(this);
this._selectionHandler = function(e) { if (!this._dragging) { return; }; e.stop(); }.bind(this);
this._curx = 0;
this._cury = 0;
this._posx = 0;
this._posy = 0;
this._dragging = false;
this._targets = [];
Evt.add(document.body, "mousemove", this._trackHandler);
Evt.add(document.body, "mouseup", this._endHandler);

Evt.add(document.body, ["drag", "selectstart"], this._selectionHandler); 
this._handles = handles;
this._downHandler = this.onMouseDown.bind(this);
this._handles.each(function(handle) {
ac(handle, "drag_handle");
Evt.add(handle, "mousedown", this._downHandler);
}.bind(this));
this.setEnabled(true);
}
Cls.inherit(FeatureDraggable, Object, {
onMouseDown: function(e) {
if (!this.getEnabled()) {
return;
};

var target = getSrcElement(e);
if (["input", "textarea", "button"].indexOf(target.tagName.toLowerCase()) != -1) {
return;
};
this.startDrag(e); 
cancelBubble(e);
},
addDropTargets: function(targets) {
this._targets = this._targets.concat(targets);
return this;
},
endDrag: function(e) {
if (!this._dragging) { return; };
rc(this._element, "dragging");
this._dragging = false;
var cur = getPosition(e);
this._targets.each(function(t) { t.doOnOut() });
var hoveredTarget = this._targets.findFirst(function(t) {
return contains(getRect(t._element), cur);
});
if (hoveredTarget) { hoveredTarget.doOnDrop(); };
this.doOnEnd(e, cur);
},
isDragging: function() {
return this._dragging;
},
startDrag: function(e) {
this._customData = {};
this._dragging = true;
ac(this._element, "dragging");
if (getElementComputedStyle(this._element, "position") == "absolute") {
this._posx = getLeft(this._element) - getLeftParent(this._element)
this._posy = getTop(this._element) - getTopParent(this._element);
} else {
this._posx = 0;
this._posy = 0;
};
if (this._updatePos) {
this._element.style.left = (this._posx).toString() + "px";
this._element.style.top = (this._posy).toString() + "px";
};
var pos = getPosition(e);
this._curx = pos.x;
this._cury = pos.y;
cancelEvent(e);
this.doOnStart(e);
},
trackDrag: function(e) {
if (!this._dragging) { return; };
var cur = getPosition(e);
var pos = {
x: this._posx + (cur.x - this._curx),
y: this._posy + (cur.y - this._cury)
};
if (this.doTrackDrag) {
pos = this.doTrackDrag(e, pos, { x: this._posx, y: this._posy }, this._customData);
};
this.doOnTrack(e, cur, pos, this._customData);
this._targets.each(function(t) { t.doOnOut() });
var hoveredTarget = this._targets.findFirst(function(t) {
return contains(getRect(t._element), cur);
});
if (hoveredTarget) { hoveredTarget.doOnOver(); };
if (this._updatePos) {
this._element.style.left = pos.x.toString() + "px";
this._element.style.top = pos.y.toString() + "px";
};
},
enable: function() {
this._handles.each(function(handle) {
ac(handle, "drag_handle");
});
this.setEnabled(true);
},
disable: function() {
this._handles.each(function(handle) {
rc(handle, "drag_handle");
});
this.setEnabled(false);
}
});
Cls.property(FeatureDraggable, "enabled");
Cls.event(FeatureDraggable, "track");
Cls.event(FeatureDraggable, "start");
Cls.event(FeatureDraggable, "end");
function RangeRestriction(min, max) {
this._min = min;
this._max = max;
}
RangeRestriction.prototype.apply = function(value) {
if (value < this._min) {
return this._min;
};
if (value > this._max) {
return this._max;
};
return value;
}


function TrackInside(container, object) {
TrackInside.baseConstructor.call(this);
this.setContainer(container);
this.setObject(object);
}
Cls.inherit(TrackInside, Object, {
doTrack: function(e, pos, cur, customData) {
var rX = new RangeRestriction(0, this.getContainer().offsetWidth - this.getObject().offsetWidth);
pos.x = rX.apply(pos.x);
var rY = new RangeRestriction(0, this.getContainer().offsetHeight - this.getObject().offsetHeight);
pos.y = rY.apply(pos.y);
return pos;    
},
makeTracker: function() {
return this.doTrack.bind(this);
}
});
Cls.property(TrackInside, "container");
Cls.property(TrackInside, "object");


function TrackVertical(object) {
TrackVertical.baseConstructor.call(this);
this.setObject(object);
this.setX(object.offsetLeft);
}
Cls.inherit(TrackVertical, Object, {
doTrack: function(e, pos, cur, customData) {
pos.x = this.getX();
return pos;    
},
makeTracker: function() {
return this.doTrack.bind(this);
}
});
Cls.property(TrackVertical, "object");
Cls.property(TrackVertical, "x");







function Scrollbar(scrollable, scrollbar) {
Scrollbar.baseConstructor.call(this);
this.setHideIfNotNeeded(true);
if (!scrollbar) {
scrollbar = $E("div", "scrollbar");
scrollable.parentNode.appendChild(scrollbar);
};
this.SCROLL_STEP = 10;
this.SCROLL_STEPS = 5;
this.SCROLL_TIMEOUT = 50;
this.setScrollable(scrollable);
this.setVisible(true);
this.scrollbar   = scrollbar;
scrollbar.innerHTML = "<div class=\"top_arrow\">&nbsp;</div><div class=\"scroller\"><div class=\"scroller_top\"></div><div class=\"scroller_middle\"></div><div class=\"scroller_bottom\"></div></div><div class=\"bottom_arrow\">&nbsp;</div>";
this.topArrow    = scrollbar.childNodes[0];
this.scroller    = scrollbar.childNodes[1];
this.bottomArrow = scrollbar.childNodes[2];
this.indicatorTop     = this.scroller.childNodes[0];
this.indicator        = this.scroller.childNodes[1];
this.indicatorBottom  = this.scroller.childNodes[2];
this.scrollTimeout = null;

Evt.add(this.topArrow, "mousedown", function() { 
this.startScrollUp(); 
}.bind(this));
Evt.add(this.topArrow, ["mouseout", "mouseup"], function(e) { 
this.stopScrollUp(); 
}.bind(this));

Evt.add(this.bottomArrow, "mousedown", function() { 
this.startScrollDown(); 
}.bind(this));
Evt.add(this.bottomArrow, ["mouseout", "mouseup"], function() { 
this.stopScrollDown(); 
}.bind(this));

Evt.add(this.scrollbar, "mousedown", function(e) { 
this.doScrollTo(e);
}.bind(this));

Evt.add([this.scrollbar, 
this.getScrollable()], "mousewheel", function(e) { 
this.onWheel(e); 
}.bind(this));
this.update();
var offset = 0;
var insideTracker = new TrackInside(this.scrollbar, this.scroller).makeTracker();
var verticalTracker = new TrackVertical(this.scroller).makeTracker();
var draggable = new FeatureDraggable(this.scroller, null, { track: function(e, pos, cur, customData) {
pos = insideTracker(e, pos, cur, customData);
pos = verticalTracker(e, pos, cur, customData);
return pos;
}})
.onStart(function(e) {
offset = getTop(this.scroller) + this.scroller.clientHeight / 2 - getPosition(e).y;
}.bind(this))
.onTrack(function(e, cur, pos, cdata) {
this.getScrollable().scrollTop = this.calculateScrollablePosition(getPosition(e).y + offset);
this.doOnScroll();
}.bind(this));
}
Cls.inherit(Scrollbar, Object, {
onWheel: function(e) {
if (!this.getVisible()) {
return;
};
e.stop();
var delta = e.wheelDelta || - e.detail * 40;
this.smoothScroll(this.getScrollable().scrollTop - this.SCROLL_STEP * delta / 30);
},
getVisibleFraction: function() {
return this.getScrollable().clientHeight / this.getScrollable().scrollHeight;
},
getAboveFraction: function() {
return this.getScrollable().scrollTop / this.getScrollable().scrollHeight;
},
startScrollUp: function() {
this.doScrollUp();
this.scrollUpTimeout = setTimeout(function() { this.startScrollUp(); }.bind(this), this.SCROLL_TIMEOUT);  
},
stopScrollUp: function() {
if (this.scrollUpTimeout) { 
clearTimeout(this.scrollUpTimeout);
};
},
startScrollDown: function() {
this.doScrollDown();
this.scrollDownTimeout = setTimeout(function() { this.startScrollDown(); }.bind(this), this.SCROLL_TIMEOUT);  
},
stopScrollDown: function() {
if (this.scrollDownTimeout) { 
clearTimeout(this.scrollDownTimeout);
};
},
getFreeScrollHeight: function() {
var lostHeight = 
this.indicatorTop.clientHeight + 
this.indicatorBottom.clientHeight + 
this.topArrow.clientHeight + 
this.bottomArrow.clientHeight;
var result = this.scrollbar.clientHeight - lostHeight;

if (result < 0) {
return 0;
};
return result;
},
doScrollUp: function() {
this.smoothScroll(this.getScrollable().scrollTop - this.SCROLL_STEP);
},
doScrollDown: function() {
this.smoothScroll(this.getScrollable().scrollTop + this.SCROLL_STEP);
},
calculateScrollablePosition: function(mouseY) {
var offsetY = getTop(this.scrollbar);
var newFractionCenter = (mouseY - offsetY) / this.scrollbar.clientHeight;
var newFractionAbove = this.normalizeAboveFraction(newFractionCenter - this.getVisibleFraction() / 2);
return this.getScrollable().scrollHeight * newFractionAbove;
},
doScrollTo: function(e) {
this.smoothScroll(this.calculateScrollablePosition(getPosition(e).y));
},
normalizeAboveFraction: function(fraction) {
var visibleFraction = this.getVisibleFraction();
if (fraction + visibleFraction > 1) {
fraction = 1 - visibleFraction;
};
if (fraction < 0) {
fraction = 0;
};
return fraction;
},
update: function() {
this.updateIndicatorPosition();
this.updateIndicatorSize();

if (this.getHideIfNotNeeded() && this.getVisibleFraction() >= 1) {
this.hide();
} else {
this.show();
};
},
updateIndicatorPosition: function() {
var fractionAbove = this.normalizeAboveFraction(this.getAboveFraction());
var height = this.getFreeScrollHeight() * fractionAbove;
this.scroller.style.top = height + "px";
},
updateIndicatorSize: function() {
var visibleFraction = this.getVisibleFraction();
if (visibleFraction > 1) {
visibleFraction = 1;
};
this.indicator.style.height = this.getFreeScrollHeight() * visibleFraction + "px";;
},
smoothScroll: function(pos) {
if (this.scrollTimeout) { 
clearTimeout(this.scrollTimeout);
};
this.doSmoothScrollStep(pos, this.SCROLL_STEPS);
},
doSmoothScrollStep: function(pos, steps) {
if (steps == 0) {
this.getScrollable().scrollTop = pos;
this.updateIndicatorPosition();  
} else {
this.getScrollable().scrollTop = (pos + this.getScrollable().scrollTop) / 2;
this.updateIndicatorPosition();  
this.scrollTimeout = setTimeout(function() { this.doSmoothScrollStep(pos, steps-1); }.bind(this), this.SCROLL_TIMEOUT);
};
this.doOnScroll();
},
hide: function() {
this.scrollbar.style.display = "none";
this.setVisible(false);
return this;
},
show: function() {
this.scrollbar.style.display = "";
this.setVisible(true);
return this;
}
});
Cls.property(Scrollbar, "hideIfNotNeeded");
Cls.property(Scrollbar, "scrollable");
Cls.property(Scrollbar, "visible");
Cls.event(Scrollbar, "scroll");




function OffersScroller() {
OffersScroller.baseConstructor.call();
}
Cls.inherit(OffersScroller, Object, {
onOfferBlockDataFetched: function(response) {
var parts = $A(response.param.parts.part);
this.updateOfferBlock(parts);
},
updateOfferBlock: function(parts) {
if (parts.length == 0) {
RPC.call("offer.random", {}, 
this.onOfferBlockDataFetched.bind(this));
return;
};
var part = parts[0];
var offers = $$("#layout_header .offers ul");
var newItem = offers.insertBefore($E("li", "item0"), offers.firstChild);
newItem.appendChild($E("a", "", part.name, { href: part.links.view }))
.appendChild(document.createTextNode(", " + part.price + " руб."));
var itemHeight = newItem.clientHeight;
offers.style.top = (-itemHeight) + "px";
new TransitionTop(offers, -itemHeight, 0)
.onComplete(function() {
$A(offers.childNodes).each(function(node, index) {
if (index >= window.m.MINIBANNER_SIZE) {
node.parentNode.removeChild(node);
} else {
node.className = "item" + (index + 1);
};
});
})
.run();
setTimeout(this.updateOfferBlock.bind(this, parts.slice(1)),
window.m.MINIBANNER_REFRESH_SECONDS * 1000);
},
start: function() {
this.updateOfferBlock([]);
return this;
}
});


function AnchorTopLeft(node) {
AnchorTopLeft.baseConstructor.call(this, node);
}
Cls.inherit(AnchorTopLeft, Anchor, {
getX: function() {
return getLeft(this.getNode());
},
getY: function() {
return getTop(this.getNode());
}
});



function GenericCatalogPopup() {
GenericCatalogPopup.baseConstructor.call(this);
this.setContent($E("div", "content"));
this.setNode($E("div", this.getPopupClass()));
this.getNode().id = this.getPopupId();
this.getNode().appendChild(this.getContent());
var boundary = this.getNode().appendChild($E("div", "boundary"));
boundary.appendChild($E("div", "ul"));
boundary.appendChild($E("div", "ur"));
boundary.appendChild($E("div", "bl"));
boundary.appendChild($E("div", "br"));
this.onSetup(function() {
this.getPopup().appendChild(this.getNode());
}.bind(this));
}
Cls.inherit(GenericCatalogPopup, PopupSlice, { 
})
Cls.property(GenericCatalogPopup, "node");
Cls.property(GenericCatalogPopup, "content");





function GenericCatalogInfoPopup() {
GenericCatalogInfoPopup.baseConstructor.call(this);
}
Cls.inherit(GenericCatalogInfoPopup, GenericCatalogPopup, { 
onDataLoaded: function(response) {
this.getContent().innerHTML = response.param.rawHtml;
Evt.add(this.getContent().down(".close"), "click", this.hide.bind(this));

if (System.isOpera) {
var boundary = $(this.getPopupId()).down(".boundary");
var ul = boundary.down(".ul")
ul.style.height = (ul.offsetParent.clientHeight - parseInt(getElementComputedStyle(ul, "bottom"))) + "px";
var ur = boundary.down(".ur");
ur.style.height = (ul.offsetParent.clientHeight - parseInt(getElementComputedStyle(ul, "bottom"))) + "px";
};
this.doOnLoaded(response);
},
load: function() {
this.getContent().clear().appendChild($E("div", "ajax_loading"));
RPC.call(this.getRpcCall(), 
this.getRpcParameters(),
this.onDataLoaded.bind(this));
}
})
Cls.event(GenericCatalogInfoPopup, "loaded");






function GuiInplaceEdit(eText) {
GuiInplaceEdit.baseConstructor.call(this);
this._eText = eText;
this._eInput = document.createElement("input");
this._eInput.className = "text rp-inplace";
this._initialValue = null;
this._completedHandlers = [];
this.setup();
}
Cls.inherit(GuiInplaceEdit, Object, {
getElement: function() {
return this._eText;
},
getInput: function() {
return this._eInput;
},
setup: function() {
var _this = this;
var inp = this.getInput();
var el = this.getElement();
inp.setAttribute("type", "text");
inp.value = el.innerHTML;  
var baseWidth = el.offsetWidth.toString() + "px";

this._initialValue = inp.value;
var parent = el.parentNode;
parent.replaceChild(inp, el);
if (getElementComputedStyle(inp, "position") == "static") {
inp.style.width = baseWidth;
};
textBoxSelect(inp, 0, inp.value.length);
inp.focus();
Evt.add(this._eInput, "blur", this.onBlur.bind(this)); 
Evt.add(this._eInput, "keydown", this.onKeyDown.bind(this)); 
},
cancel: function(move) {
var parent = this.getInput().parentNode;
if (parent) {
parent.replaceChild(this.getElement(), this.getInput());
};
this.getElement().innerHTML = this._initialValue;
},
save: function(move) {
var value = this.getInput().value;
var parent = this.getInput().parentNode;
parent.replaceChild(this.getElement(), this.getInput());
this.doOnComplete(value, { changed: (value != this._initialValue), move: move });
},
onBlur: function(e) {
this.save(null);
},
onKeyDown: function(e) {
var _this = this;
var key = e.charCode || e.keyCode;
if (key == Keys.ARROW_UP ||
key == Keys.TAB && e.shiftKey) {
e.stop();
this.save("prev");
return;
};
if (key == Keys.ENTER ||
key == Keys.TAB ||
key == Keys.ARROW_DOWN) {
e.stop();
this.save("next");
return;
};
if (key == Keys.ESCAPE) {
e.stop();
this.cancel(null);
return;
};
}
});
Cls.event(GuiInplaceEdit, "complete");





function GuiInplaceEditRpc(element, saveCall, rpcParams) {
GuiInplaceEditRpc.baseConstructor.call(this);
this._editable = element;
this._saveCall = saveCall;
this._rpcParams = rpcParams;
this.setup();
this.onSave(function(value) {
ac(this._editable, "saving");
}.bind(this));
this.onSaved(function(response) {
rc(this._editable, "saving");
this._editable.innerHTML = response.param.value;
}.bind(this));
this.onSaveFailed(function(originalValue, response) {
rc(this._editable, "saving");
this._editable.innerHTML = originalValue; 
alert(response.getMessage());
}.bind(this));
}
Cls.inherit(GuiInplaceEditRpc, Object, {
setup: function() {
Evt.add(this._editable, "click", this.focus.bind(this).stopEvent());
},
focus: function() {
new GuiInplaceEdit(this._editable).
onComplete(function(value, state) {
if (state.changed) {
var rpcParams = this._rpcParams;
rpcParams.value = value;
var originalValue = this._editable.innerHTML;
this._editable.clear().appendChild(document.createTextNode(value));
this.doOnSave(value);
RPC.call(this._saveCall, rpcParams, 
this.doOnSaved.bind(this), 
this.doOnSaveFailed.bind(this, originalValue));
};
switch (state.move) {
case "next":
if (this.getNext()) { this.getNext().focus(); };
break;
case "prev":
if (this.getPrev()) { this.getPrev().focus(); };
break;
};
}.bind(this));
}
});
Cls.event(GuiInplaceEditRpc, "save");
Cls.event(GuiInplaceEditRpc, "saved");
Cls.event(GuiInplaceEditRpc, "saveFailed");
Cls.property(GuiInplaceEditRpc, "next");
Cls.property(GuiInplaceEditRpc, "prev");




function PopupCart() {
PopupCart.baseConstructor.call(this);
this.onShow(function() {
this.load();
new AnchorTopLeft($$("#layout_sidebar .cart")).offset(47, 15).topRight(this.getPopup());
}.bind(this));
this.onLoaded(function(response) {
Selector.find(".quantity", this.getContent()).each(function(node, index) {
Evt.add(node, "click", this.onQuantityEdit.bind(this, node, response.param.items[index].partId).stopEvent());
}.bind(this));
Selector.find(".remove", this.getContent()).each(function(node, index) {
Evt.add(node, "click", this.onQuantityRemove.bind(this, node, response.param.items[index].partId).stopEvent());
}.bind(this));
}.bind(this));
}
Cls.inherit(PopupCart, GenericCatalogInfoPopup, {
onQuantityRemove: function(node, partId) {
if (!confirm("Удалить эту строку?")) {
return;
};
RPC.call("cart.update", { part_id: partId, value: 0 },
this.onQuantityUpdated.bind(this, node));
},
onQuantityEdit: function(node, partId) {
var editor = new GuiInplaceEditRpc(node.down(".value"), "cart.update", { part_id: partId });
editor.onSaved(this.onQuantityUpdated.bind(this, node));
},
onQuantityUpdated: function(node, response) {

$$("#layout_sidebar .cart .quantity").innerHTML = response.param.rawHtml;    

if (0 == response.param.value) {
var tr = node.up("tr");
tr.parentNode.removeChild(tr);
};
},
getPopupClass: function() {
return "white_popup_right";
},
getPopupId: function() {
return "popup_cart";
},
getRpcCall: function() {
return "cart.contents";
},
getRpcParameters: function() {
return {  };
}
});






page.c.onload(function(env) {
Links.baseUrl = window.m.BASE_URL;

env.popupCart = new PopupCart();
Evt.add($$("#layout_sidebar .cart"), "click", function(e) {
env.popupCart.show();
}.stopEvent());

page.m.offerScroller = new OffersScroller().start();

var scrollbar = new Scrollbar($$("#layout_content .scrollable .scrollable_content"));
Evt.add(window, "resize", scrollbar.update.bind(scrollbar).debounce(200));  
});






page.c.onload(function(env) {

new LoginForm().bind();

new FeatureInputHelpValue($("layout_sidebar").down(".quicksearch .text"));

var offersTitle = $("layout_header").down(".offers .title");
setInterval(function() {
var t = new TransitionSequence();
t.add(new TransitionOpacity(offersTitle, 1, 0));
t.add(new TransitionOpacity(offersTitle, 0, 1));
t.run();
}, 2000);
});




function PopupPhoto() {
PopupPhoto.baseConstructor.call(this);
this.setContent($E("div", "content"));
this.setNode($E("div", this.getPopupClass()));
this.getNode().id = this.getPopupId();
this.getNode().appendChild(this.getContent());
var boundary = this.getNode().appendChild($E("div", "boundary"));
boundary.appendChild($E("div", "ul"));
boundary.appendChild($E("div", "ur"));
boundary.appendChild($E("div", "bl"));
boundary.appendChild($E("div", "br"));
this.onSetup(function() {
this.getPopup().appendChild(this.getNode());
}.bind(this));
this.onShow(function() {
this.load();
center(this.getPopup());
}.bind(this));
this.onLoaded(this.onPhotoLoaded.bind(this));
this.setCurrentPhoto(0);
this.setPhotos([]);
}
Cls.inherit(PopupPhoto, PopupOverlay, {  
onDataLoaded: function(response) {
this.getContent().innerHTML = response.param.rawHtml;
Evt.add(this.getContent().down(".close"), "click", this.hide.bind(this));
this.doOnLoaded(response);
},
load: function() {
this.getContent().innerHTML = "";
this.getContent().appendChild($E("div", "ajax_loading"));
RPC.call(this.getRpcCall(), 
this.getRpcParameters(),
this.onDataLoaded.bind(this));
},
getPopupClass: function() {
return "white_popup";
},
getPopupId: function() {
return "popup_photo";
},
getRpcCall: function() {
return "photo.info";
},
getRpcParameters: function() {
return { id: this.getPartId() };
},
showPhoto: function(index) {
var photo = this.getPhotos()[index];
var img = $$("img.photo", this.getContent());
img.src = Links.uploaded_file(photo.photo);
img.width = photo.width;
img.height = photo.height;
center(this.getContent().parentNode);
Evt.add(img, "load", function() { center(this.getContent().parentNode); }.bind(this));
},
updatePhotoLinks: function() {
addRemoveClass($$("span.next", this.getContent()), "disabled", this.getCurrentPhoto() >= this.getPhotos().length - 1);
addRemoveClass($$("span.prev", this.getContent()), "disabled", this.getCurrentPhoto() <= 0);
},
onPhotoLoaded: function(response) {
center(this.getPopup());

this.setCurrentPhoto(0);

this.setPhotos($A(response.param.photos.photo));
this.updatePhotoLinks();

Evt.add($$("span.next", this.getContent()), "click", function(e) { 
if (this.getCurrentPhoto() >= this.getPhotos().length - 1) {
return;
};
this.setCurrentPhoto(this.getCurrentPhoto() + 1);
this.showPhoto(this.getCurrentPhoto());
this.updatePhotoLinks();
}.bind(this).stopEvent());

Evt.add($$("span.prev", this.getContent()), "click", function(e) { 
if (this.getCurrentPhoto() <= 0) { return; };
this.setCurrentPhoto(this.getCurrentPhoto() - 1);
this.showPhoto(this.getCurrentPhoto());
this.updatePhotoLinks();
}.bind(this).stopEvent());
}
});
Cls.property(PopupPhoto, "partId");
Cls.property(PopupPhoto, "currentPhoto");
Cls.property(PopupPhoto, "photos");
Cls.property(PopupPhoto, "node");
Cls.property(PopupPhoto, "content");
Cls.event(PopupPhoto, "loaded");



function PopupCartQuantity(anchor) {
PopupCartQuantity.baseConstructor.call(this);
var content = $("popup_cart_quantity_internals");
content.css({
"visibility": "",
"position": "static"
});
this.getContent().appendChild(content);
Evt.add(this.getContent().down(".button"), "click", this.onOk.bind(this));
Evt.add(this.getContent().down(".close"), "click", this.hide.bind(this));

this.inputQuantity = this.getContent().down(".text");
Bind.addElement(this.inputQuantity, Keys.ESCAPE, this.hide.bind(this));
Bind.addElement(this.inputQuantity, Keys.ENTER, this.onOk.bind(this));
this.onShow(function() {
new AnchorBottomCenter(this.getAnchorGetter()()).offset(30, -15).topRight(this.getPopup());
this.inputQuantity.value = "1";
this.inputQuantity.focus();
textBoxSelect(this.inputQuantity, 0, 1);
}.bind(this));
}
Cls.inherit(PopupCartQuantity, GenericCatalogPopup, {
getPopupClass: function() {
return "white_popup_right";
},
getPopupId: function() {
return "popup_cart_quantity";
},
onCartInfoLoaded: function(response) {

$$("#layout_sidebar div.cart span.quantity").innerHTML = response.param.rawHtml;    
},
onCartInfoFailed: function(response) {
switch (response._code) {
case 0: // Превышен размер корзины
case 1: // Отрицательное количество
case 2:
alert(response._message);
break;
};
},
onOk: function(e) {
this.hide();
RPC.call("cart.add", { id: this.getPartId(), quantity: this.inputQuantity.value },
this.onCartInfoLoaded.bind(this), 
this.onCartInfoFailed.bind(this));
}
});
Cls.property(PopupCartQuantity, "partId");
Cls.property(PopupCartQuantity, "anchorGetter");







page.c.onload(function(env) {
env.popupPhoto = new PopupPhoto();
env.popupCartQuantity = new PopupCartQuantity();
env.popupCartQuantity.setAnchorGetter(function() {
return $("layout_content").down(".stock .cart");
}.bind(env.popupCartQuantity));
var carsContent = $$("div.cars .scrollable_content");
if (carsContent) {
env.carsScrollbar = new Scrollbar(carsContent);
};
var agregatesContent = $$("div.agregates .scrollable_content");
if (agregatesContent) {
env.agregatesScrollbar = new Scrollbar(agregatesContent);
};
env.oemsScrollbar = new Scrollbar($$("div.oem .scrollable_content"));

Evt.add($$("div.controls span.photo_wrapper"), "click", function(e) {
env.popupPhoto.setPartId(window.m.part.id).show();
}.stopEvent());

Evt.add($$("div.controls span.cart_wrapper"), "click", function(e) {
env.popupCartQuantity.setPartId(window.m.part.id).show();
}.stopEvent());

env.onListLoaded = function(list, link, scrollbar, response) {
list.clear();
$A(response.param).each(function(item) {
list.appendChild($E("li", "", item.name));
});
link.parentNode.removeChild(link);
scrollbar.update();
};
env.c.onOemsLoaded = function(e, response) {
var list = $$("div.oem ul");
list.innerHTML = "";
$A(response.param).each(function(oem) {
var no = document.createElement("strong");
no.id = "oem_" + oem.id;
no.innerHTML = oem.raw_orig_no;
var li = document.createElement("li");
li.appendChild(no);;
list.appendChild(li);
});
var link = $$("div.oem a");
if (link) { 
link.parentNode.removeChild(link);
};
env.oemsScrollbar.update();
};
page.events.bind("oems-loaded", env.c.onOemsLoaded);
env.c.onLoadCars = function() {
RPC.call("applications.cars", { part_id: window.m.part.id }, 
env.onListLoaded.bind(null, $$("div.cars ul"), $$("div.cars a"), env.carsScrollbar));
};
env.c.onLoadAgregates = function() {
RPC.call("applications.agregates", { part_id: window.m.part.id }, 
env.onListLoaded.bind(null, $$("div.agregates ul"), $$("div.agregates a"), env.agregatesScrollbar));
};
env.c.onLoadOems = function(e) {
RPC.call("part.oems", { part_id: window.m.part.id },
function(response) { page.events.fire("oems-loaded", response); });
};
Evt.add($$("div.cars a"), "click", env.c.onLoadCars.stopEvent());
Evt.add($$("div.oem a"), "click", env.c.onLoadOems.stopEvent());
Evt.add($$("div.agregates a"), "click", env.c.onLoadAgregates.stopEvent());
});
var I18N = new Object();
I18N.strings = {};
function _(string) {
return I18N.strings[string] || string;
}
Lang = {
NOMINATIVE: 1,
getWordForm: function(word, value, wordCase) {

if (value == 1) {
return word;
};

var last = word[word.length - 1];
var suffix2 = word.substr(word.length - 2, 2);
if (suffix2 == "ay") { // e.g. day, gay
return word + "s";
};
if (suffix2[1] == "y") {
return word.substr(0, word.length - 1) + "ies";   
};
if (suffix2[1] == "h") {
return word + "es";
};
return word + "s";
}
}


I18N.strings["Delete this item?"] = "Удалить эту запись?";
I18N.strings["Value does not look like valid email address"] = "Это не адрес e-mail!";
XMLRPC._ajaxErrorHandler = function(text) {
return true;
}
page.c.onload(function(env) {
});











function FormControl(id, initialValue, validators, filters) {
FormControl.baseConstructor.call(this);
this.id = id;
this.initialValue = initialValue;
this.validators = validators;
this.filters = filters;
this._features = [];
}
Cls.inherit(FormControl, Object, {
addFeature: function(feature) {
this._features.push(feature);
return this;
},
validate: function() {

if (!$(this.id)) { return true; };
var oldValue = this.getValue();
this.setValue(this.filter(oldValue));
var errors = this.validators
.map(function(validator) { return validator() })
.flatten()
.filter(function(status) { return status.message != null });
this.setValue(oldValue);
return errors;
},
filter: function(value) {
return this.filters.reduce(function(value, f) { return f.apply(value); }, value);
},
getId: function() { return this.id; },
getName: function() {
return $(this.id) ? $(this.id).name : null;
},
getValue: function() {
var value = $(this.id) ? $(this.id).value : null;
this._features.each(function(feature) {
value = feature.filterValue(value);
});
return value;
},
resetValue: function() {
var el = $(this.id);
el.value = "";
this._features.each(function(feature) {
feature.resetValue(el);
});
},
setValue: function(value) {
if ($(this.id)) {
$(this.id).value = value;
};
}
})






var Validators = {
POPUP_BOTTOM: 0,
POPUP_TOP: 1,
POPUP_LEFT: 2,
POPUP_RIGHT: 3,
errorPopup: null,
hideCallback: null,
offsetX: 3,
offsetY: 3,
timeout: 3000
};
Validators.handleError = function(element, text) {
this.showErrorPopup(element, text);
}
Validators.showErrorPopup = function(element, text) {
try {
element.focus();
textBoxSelect(element, 0, element.value.length);
} catch (e) {


};
Validators.showErrorPopupNoSelect(element, text);
}
Validators.getErrorPopup = function() {
if (this.errorPopup == null) {
this.errorPopup = this.createErrorPopup();
};
return this.errorPopup;
}
Validators.getErrorPopupContent = function() {
if (this.errorPopup == null) {
this.errorPopup = this.createErrorPopup();
};
return this.errorPopup;
}
Validators.createErrorPopup = function() {
var errorPopup = document.createElement("div");
errorPopup.className = "errorpopup";
document.body.appendChild(errorPopup);
addEvent(errorPopup, "click", function(e) { Validators.hideErrorPopup(); });
return errorPopup;
}
Validators.hideErrorPopup = function() {
if (this.hideCallback != null) {
clearTimeout(this.hideCallback);
this.hideCallback = null;
};
this.doHideErrorPopup();
}
Validators.doHideErrorPopup = function() {
this.getErrorPopup().style.visibility = "hidden";
}
Validators.showErrorPopupNoSelect = function(element, text) { 

this.hideErrorPopup();
try {
element.focus();
} catch (e) {

};
this.updateErrorPopup(text);
this.positionErrorPopup(element);
this.displayErrorPopup();
if (this.timeout) {
this.hideCallback = setTimeout(function() { Validators.hideCallback = null; Validators.hideErrorPopup(); }, this.timeout);
};
};
Validators.displayErrorPopup = function() {
var error_item = this.getErrorPopup();
error_item.style.visibility = "visible";
}
Validators.updateErrorPopup = function(text) {
var error_item = this.getErrorPopupContent();
error_item.innerHTML = text + "<div class='comment'>" + _("Click to Close the Window") + "</div>";
}
Validators.positionErrorPopup = function(element) {
this.doPositionErrorPopup(element, this.getErrorPopup());
} 
Validators.doPositionErrorPopup = function(element, error_item) {
error_item.style.position = "absolute";

var popupBase = element;
if (getElementComputedStyle(popupBase, "display") == "none") {
popupBase = $(element.id + "___Frame");
};

var popupPosition = this.POPUP_BOTTOM;
var top;
var left;
switch (popupPosition) {
case this.POPUP_TOP:
left = getLeft(popupBase) + this.offsetX;
top = (getTop(popupBase) - error_item.clientHeight - this.offsetY);
break;
case this.POPUP_BOTTOM:
left = getLeft(popupBase) + this.offsetX;
top = getBottom(popupBase) + this.offsetY;
break;
case this.POPUP_LEFT:
top  = getTop(popupBase);
left = getLeft(popupBase) - 150 - this.offsetX;
break;
case this.POPUP_RIGHT:
top  = getTop(popupBase);
left = getRight(popupBase) + this.offsetX;
break;
};
if (top < 0) { top = 0; };

if (left + 150 > document.body.clientWidth) {
left = document.body.clientWidth - 150;
};
if (left < 0) { left = 0; };
error_item.style.left = left.toString() + "px";
error_item.style.top  = top.toString() + "px";
}

Array.prototype.all = function(callback) {
if (!callback) { 
callback = function(a) { return a; }; 
};
return this.reduce(function(a, b) { return a && callback(b); }, true);
}


Object.prototype.keys = function() {
var result = [];
this.each(function(value, key) { 
result.push(key);
});
return result;
}








Validators.not_empty = function(elements, messages) {
var _t = this;

var result = elements.filter(function(el) { return el.type != "radio"; }).map(function(element) {
if (element.type == "checkbox" && element.checked ||
element.value != "") {
return {};
};
return {
node: element,
message: messages.value_missing
}
});
var invalidNonRadio = result.filter(function(status) { return status.message != null; });
if (invalidNonRadio.length > 0) {
return invalidNonRadio;
};

var radioStatus = {};
var radioNodes = {};
elements
.filter(function(el) { return el.type == "radio"; })
.map(function(el) {
radioStatus[el.name] = radioStatus[el.name] || (el.checked ? el : null);
radioNodes[el.name] = radioNodes[el.name] || el;
});
var invalidRadio = radioStatus.keys().map(function(key) {
if (!radioStatus[key]) {
return {
node: radioNodes[key],
message: messages.value_missing
};
};
return [];
});
return invalidRadio.filter(function(status) { return status.message != null; });
}





function $F(id) {
if ($(id)) {
if ($(id).getAttribute("multiple")) {
return $FM(id);
};
return $(id).value;
};

if ($(id + "_yy") && 
$(id + "_mm") && 
$(id + "_dd")) {
return $FD(id);
};

if ($(id + "_yes") &&
$(id + "_no")) {
return $(id + "_yes").checked;
};
return null;
}


function $FD(id) {
return sprintf("%s-%02s-%02s", $F(id + "_yy"), $F(id + "_mm"), $F(id + "_dd"));
}


function $FM(id) {
var result = [];
$A($(id).options).each(function(option) {
if (option.selected) {
result.push(option.value);
};
});
return result;
}

Array.prototype.forall = function(callback) {
return this.reduce(function(a,b) { return a && callback(b); }, true);
}













function InputForm() {
InputForm.baseConstructor.call(this);
this.setId(null);
this.setSubmitting(false);
this.setTarget(null);
this.setControls([]);
this._submits = [];
}
Cls.inherit(InputForm, Object, {
addControl: function(control) {
this.getControls().push(control);
},
getControl: function(id) {
return this.getControls().findFirst(function(control) {
return control.id == id;
});
},
getControlByName: function(name) {
return this.getControls().findFirst(function(control) {
return control.id == this.getId() + "_" + name;
}.bind(this));
},
beforeValidated: function(e) {
if (window.FCKeditorAPI) {
this.getControls().each(function(control) {
var editor = FCKeditorAPI.GetInstance(control.id);
if (editor) {
$(control.id).value = editor.GetXHTML(true);
};
});
}
},
isModified: function() {
var notModified = this.getControls().forall(function(control) { 
return control.initialValue == $F(control.id); 
});
return !notModified;
},
saveState: function() {
this.getControls().each(function(control) { 
control.initialValue = $F(control.id);
});
},
addSubmit: function(submit) {
if (!this._submits) { this._submits = []; };
this._submits.push(submit);
},
validate: function() {
var invalid_controls = this.getControls()
.map(function(control) { return { control: control, status: control.validate() }; })
.filter(function(control) { return control.status.length > 0; });
if (invalid_controls.length == 0) {
return null;
};
return invalid_controls[0];
},
setupEvents: function() {
this.getSubmits().each(function(submit) {
Evt.add($(submit.id), "click", function(e) {
this.setSubmit(submit);
}.bind(this));
}.bind(this));
Evt.add($(this.getId()), "submit", function(e) {
page._inputFeatures.each(function(feature) { feature.cleanup(); });
this.setSubmitting(true);
this.beforeValidated(e);

var badField = null;
var forceSend = false;
var status;

if (!this.getSubmit().bypassValidation) {
badField = this.validate();
};




if (!badField || forceSend) {

this.doOnValidated(e);
return;
};
cancelEvent(e);
this.setSubmitting(false);
page._inputFeatures.each(function(feature) { 
if (!badField || $(badField.control.id) !== feature._element) {
feature.restore();
};
});


var node = badField.status[0].node;
var watermarks = {};
var messages = badField.status
.filter(function(status) { return status.node == node; })
.reduce(function(passed, status) { 
if (!status.group) { passed.push(status); return passed; };
if (watermarks[status.group]) {
if (watermarks[status.group].value > status.priority) {
return passed;
};
passed[watermarks[status.group].index] = status;
watermarks[status.group].value = status.priority;
} else {
passed.push(status);
watermarks[status.group] = { 
value: status.priority,
index: passed.length - 1
};
};
return passed;
}, [])
.map(function(status) { return status.message; });

Validators.handleError(node, messages.join("<br/>"));
}.bind(this));
},
toHash: function() {
var result = this.getControls().reduce(function(result, control) { 
result[control.getName()] = control.getValue(); 
return result; 
}, {});

Selector.find("div.hidden input", $(this.getId())).each(function(input) {
result[input.name] = input.value;
});
return result;
},
noValidation: function(submitName) {
this._noValidation.push(submitName);
},
resolveId: function(id) {
if ($(id)) {
return { id: id, event: "change" };
};

if ($(id + "_yy") && 
$(id + "_mm") && 
$(id + "_dd")) {
return [{ id: (id + "_yy"), event: "change" }, 
{ id: (id + "_mm"), event: "change" },
{ id: (id + "_dd"), event: "change" }];
};

if ($(id + "_yes") &&
$(id + "_no")) {
return [{ id: (id + "_yes"), event: "click" },
{ id: (id + "_no"),  event: "click" }];
};
return null;
}
});
Cls.property(InputForm, "controls");
Cls.property(InputForm, "id");
Cls.property(InputForm, "submitting");
Cls.property(InputForm, "target");
Cls.property(InputForm, "submits");
Cls.property(InputForm, "submit");
Cls.event(InputForm, "validated");
Cls.event(InputForm, "targetLoaded");
