var currencyChanger = Class.create(); currencyChanger.prototype = { initialize: function(divId) { this.avCurrency = ['KZT', 'USD', 'EUR', 'RUB']; this.mainHolder = $(divId); this.currHolder = this.mainHolder.getElementsByTagName('div')[0]; this.switcher = this.mainHolder.getElementsByTagName('span')[0]; this.inEdit = false; this.radio = new Array(); this.currentCurrency = null; this.isNumeric = false; var currency_changer_object_copy = this; this.switcher.onclick = this.changeCurrency.bindAsEventListener(this); Event.observe(this.switcher, 'click', function(event){ currency_changer_object_copy.changeCurrency.bindAsEventListener(currency_changer_object_copy) ;}); Event.observe(this.switcher, 'mouseover', function(event){ currency_changer_object_copy.switcher.className = 'over';}); Event.observe(this.switcher, 'mouseout', function(event){ currency_changer_object_copy.switcher.className = 'out';}); }, changeCurrency: function() { if(this.inEdit) { this.currHolder.innerHTML = this.oldValue; this.inEdit = false; } else { this.currentCurrency = this.mainHolder.getElementsByTagName('div')[0].getElementsByTagName('span')[0].innerHTML; this.oldValue = this.currHolder.innerHTML; this.currHolder.innerHTML = ''; this.inEdit = true; var isRadio = false; for(var i=0; i') } else { this.radio[i] = document.createElement('input'); this.radio[i].name = 'currSwitcher'; this.radio[i].type = 'radio'; } this.radio[i].id = 'currency' + i; this.radio[i].value = this.avCurrency[i]; this.radio[i].style.verticalAlign = 'middle'; this.radio[i].style.borderColor = 'white'; this.radio[i].onclick = this.clearText.bindAsEventListener(this); if(this.currentCurrency == this.avCurrency[i]) { this.radio[i].checked = true; this.radio[i].defaultChecked = true; isRadio = true; } new_div.appendChild(this.radio[i]); var label = document.createElement('label'); label.htmlFor = this.radio[i].id; label.innerHTML = this.avCurrency[i]; label.style.cursor = 'pointer'; new_div.appendChild(label); Event.observe(this.radio[i], 'keypress', this.checkKey.bindAsEventListener(this)); } this.input = document.createElement('input'); this.input.type = 'text'; this.input.id = 'currText'; this.input.style.width = '30px'; this.input.style.textAlign = 'right'; this.input.onfocus = this.clearRadio.bindAsEventListener(this); this.currHolder.appendChild(this.input); if(!isRadio) { this.input.value = this.currentCurrency; this.input.focus(); } Event.observe(this.input, 'keypress', this.checkKey.bindAsEventListener(this)); var label = document.createElement('label'); label.htmlFor = this.input.id; label.innerHTML = 'Ваше значение: '; this.currHolder.insertBefore(label, this.input); var button = document.createElement('input'); button.type = 'button'; button.className = 'button'; button.value = 'Сохранить'; button.style.margin = '2px'; button.onclick = this.saveCurrency.bindAsEventListener(this); this.currHolder.appendChild(button); } }, checkKey: function(event) { var code = event.keyCode; if(code == Event.KEY_RETURN) { this.saveCurrency(); } }, saveCurrency: function() { this.currencyUserValue = null; this.isNumeric = false; for(var i=0; i