
//Buttons:
//Button(Img, Act, W, H, Toggle)
//Button_Disable(B, Dis)

var _But_Count=0;

function Button(Img, Act, W, H, Toggle, Pref){
var Text, On, Id;

Id=(Pref ? Pref+'_Button' : 'Button_'+(_But_Count)); _But_Count++;
if (!W) W=16; if (!H) H=16;
On='="Button_Mouse(this, event, '+Act+(Toggle ? ', 1' : '')+')"';

Text='<IMG Id='+Id+' SRC="'+Img+'" '+
	'Style="border:2px outset white;width:'+W+'px;height:'+
	(H+(Op ? 2 : 0))+';background-color:black;"'+
	' OnMouseDown'+On+' OnMouseUp'+On+'>';

D.write(Text); return D.getElementById(Id);
}

function Button_Disable(B, Dis){
var Val;

if (Dis==null) Dis=true; Val=(Dis ? '1' : '');
if (B.getAttribute('disabled')==Val) return;
B.setAttribute('disabled', Val);
if (!Op && !Gec) B.style.filter=(Dis ? 'gray(), Alpha(opacity=60)' : '');
else B.style.backgroundColor=(Dis ? 'gray' : 'black');
}

function Button_Mouse(o, e, Act, Toggle){
var Up;

if (o.getAttribute('disabled') || e.button!=(!Gec ? 1 : 0)) return;
Up=(e.type=='mouseup');

if (!Up){
	if (Toggle && o.style.borderTopStyle=='inset') Up=true;
	}
else if (Toggle) return;

Button_Toggle(o, Up);

if (Up || Toggle){
	EventInit(e); Act(Up);
	}
}

function Button_Toggle(o, Up){
var Cfg=[['inset', '1px', '1px'], ['outset', '0px', '2px']], Data, St=o.style;

Data=Cfg[!Up ? 0 : 1]; St.borderStyle=Data[0];
St.marginLeft=Data[1]; St.marginTop=Data[1];
St.borderBottomWidth=Data[2];	St.borderRightWidth=Data[2];
}