// *******************************************************
// * SimpleButton
// *******************************************************
var SimpleButton = Class.create({
initialize: function(elControl) {
	this.elControl = $(elControl);
	this.ID_ = this.elControl.readAttribute('id');
	this.elControl.JSControl=this;

	var visibility=this.elControl.readAttribute('visibility');
	if(!visibility || visibility=='yes') this.disabled=false;
	else this.disabled=true;
	if(this.elControl.readAttribute('disabled')) {
		this.disabled=true;
	}
	
	this.elControl.observe('focus', this.OnFocus.bind(this, true));
	this.elControl.observe('blur', this.OnFocus.bind(this, false));

	this.elControl.observe('click', this.DoClick.bind(this));
	this.elControl.observe('keyup', this.OnKeyUp.bind(this));

},
OnFocus: function(focus, evt) {
	if (focus) this.elControl.addClassName('FocusedButton');
	else this.elControl.removeClassName('FocusedButton');
},
OnKeyUp: function(evt) {
	var event = Event.extend(evt || window.event);
	if(this.disabled) return;
	if (evt.altKey || evt.ctrlKey) return;

	var key = event.keyCode;
	if (key == 13 || key == 32) this.OnClick(); else return;
	StopEvent(event);
	return false;
},
DoClick: function(evt) {
	if(this.disabled) return;
	this.elControl.focus();
	this.OnClick(evt);
},
OnClick: function() {
	new AEvent("CLICK", {}, this);
},

SetValue: function() { },
//Value: function() { return null; },
Attribute: function(sName) {
	return this.elControl.readAttribute(sName);
},
SetAttribute: function(sName, sValue) {
	if (sName == "visibility") {
		sName = "disabled";
		sValue = (sValue == "vo" ? "yes" : "no");
	}

	if(sName=='disabled') {
		if(sValue=='disabled' || sValue=='yes') {
			this.elControl.writeAttribute("disabled", "disabled");
			this.elControl.addClassName('DisabledButton');
			this.elControl.removeClassName('EnabledButton');
			this.elControl.tabIndex=-1; // Chrome bug workaround
			this.disabled=true;
		}
		else {
			this.elControl.writeAttribute("disabled", false);
			this.elControl.removeClassName('DisabledButton');
			this.elControl.addClassName('EnabledButton');
			this.elControl.tabIndex=this.tabIndex;  // Chrome bug workaround
			this.disabled=false;
		}
	}
	else this.elControl.writeAttribute(sName, sValue);
},

SetTabOrder: function(nTabBase) {
	this.tabIndex=nTabBase;
	if(!this.disabled) this.elControl.tabIndex=this.tabIndex;
	else this.elControl.tabIndex=-1;
	return ++nTabBase;
},

ID: function() { return this.ID_; }
});


// *******************************************************
// * AButton
// * This is a SimpleButton that has no default action
// *******************************************************
var AButton = Class.create(SimpleButton, {
});


// *******************************************************
// * SimpleLink
// *******************************************************
var SimpleLink = Class.create({

initialize: function(elLink) {
	this.elControl = $(elControl);
	this.ID_ = this.elControl.readAttribute('id');
	this.elControl.JSControl=this;
	
	this.elControl.observe('click', this.OnClick.bind(this));
},
	
OnClick: function() {
	new AEvent("CLICK", {}, this);
},

SetValue: function() { },
Value: function() { return null; },

SetAttribute: function(sName, sValue) {
	// that was very BAD line:
	//this.elControl.writeAttribute(sName, sValue);
},

SetTabOrder: function(nTabBase) {
	this.elControl.tabIndex=nTabBase;
	return ++nTabBase;
},

ID: function() { return this.ID_; }
});

