//this file contains graphical interface elements for ie

function button(jscriptname, htmlobj, action, cursor, enabled) {

	//alert('test');
  //object for managing buttons easily
	var dnimg = "";
	var dimimg = "";
	this.img = htmlobj;

	if(htmlobj.name)
		this.name = htmlobj.name;
	else if(htmlobj.id)
		this.name = htmlobj.id;
	else
		this.name = "error";

	// alternate states //
	this.upimg = new Image();
	this.dnimg = new Image();
	this.dimimg = new Image();
	this.hlimg = new Image();

	this.upimg.src = this.img.src;
	this.dnimg.src = this.img.src.replace("up","ro");
	this.dimimg.src = this.img.src.replace("up","da");
	//this.hlimg.src = this.img.src.replace("up","hl");
	////

	this.action = action;
	this.jscriptname = jscriptname;

	if(cursor)
		this.cursor = cursor;
	else
		this.cursor = "hand";

	if(enabled)
		this.enable();
	else
		this.disable();
		
	this.img.onclick= new Function(this.jscriptname + ".click();");
	this.img.onmouseover= new Function(this.jscriptname + ".mouseover();");
	this.img.onmouseout= new Function(this.jscriptname + ".mouseout();");
}

button.prototype.enable = _enable;
button.prototype.disable = _disable;
button.prototype.highlight = _highlight;
button.prototype.unhighlight = _unhighlight;
button.prototype.mouseover = _mouseover;
button.prototype.mouseout = _mouseout;
button.prototype.click = _click;

function _enable() {
	this.img.src = this.upimg.src;
	this.img.style.cursor = this.cursor;
	var temp = this.img.alt.lastIndexOf(" (disabled)", this.img.alt.length);
	if(temp != -1)
		this.img.alt = this.img.alt.replace(" (disabled)", "");
	this.enabled = true;	
}

function _disable() {
	this.img.src = this.dimimg.src;
	this.img.style.cursor = "default";
	var temp = this.img.alt.lastIndexOf(" (disabled)", this.img.alt.length);
	if(temp == -1)
		this.img.alt = this.img.alt + " (disabled)";
	this.enabled = false;
}

function _highlight() {
	this.img.src = this.hlimg.src;
	this.highlighted = true;
}

function _unhighlight() {
	this.img.src = this.upimg.src;
	this.highlighted = false;
}

function _mouseover() {
	if(this.enabled && !this.highlighted)
		this.img.src = this.dnimg.src;
}

function _mouseout() {
	if(this.enabled && !this.highlighted)
	  	this.img.src = this.upimg.src;
}

function _click() {
	if(this.enabled)
		eval(this.action);	
}
