// (c) 2007 KystAtlas AS (Hans Martin Mohn)

function gtBeButton(element,image_down,image_active,tooltip,action,disabled,disabled_tip)
{if(typeof(element.m_image_up)!="undefined")
return;addGTHandlers(element);element.style.cursor=(disabled)?"auto":"pointer";element.replaceTooltipText=function(replacement_array)
{var title=this.title;for(var i=0;i<replacement_array.length;i+=2)
title=title.replace(new RegExp(replacement_array[i],"g"),replacement_array[i+1]);this.title=title;};element.setTooltipReplacements=function(replacement_array)
{this.m_replacement_array=replacement_array;this.replaceTooltipText(this.m_replacement_array);};element.setDisabled=function(val,explanation)
{this.m_disabled=val;if(val)
this.m_explanation=explanation;else
this.m_explanation="";this.showButtonDisabled(this.m_disabled||this.m_busy);this.setTooltipToShow();this.style.cursor=(this.m_disabled)?"default":"pointer";};element.setBusy=function(val)
{this.m_busy=val;this.showButtonDisabled(this.m_disabled||this.m_busy);};element.setTooltipToShow=function btnSetTooltipToShow()
{if(this.m_disabled&&this.m_explanation)
this.title=this.m_tooltip+" ("+this.m_explanation+")";else if(!this.m_disabled)
this.title=this.m_tooltip;if(this.m_replacement_array)
this.replaceTooltipText(this.m_replacement_array);};element.showButtonDisabled=function(disabled)
{var transparency=(disabled)?0.5:0.0;gtSetTransparent(this,transparency);this.style.backgroundColor=(disabled)?"#ccc":"";};element.doAction=function btnDoAction()
{eval(this.m_action+(this.m_action_has_parameters?",":"")+this.m_button_down+")");};element.gtMouseDown=function(evt)
{if(this.m_disabled||this.m_busy||this.m_button_down)
return false;this.m_button_down=true;this.src=this.m_image_down;gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseUp=function(evt)
{if(this.m_disabled||this.m_busy)
return false;if(this.m_button_down)
this.doAction();this.m_button_down=false;this.src=this.m_image_active?this.m_image_active:this.m_image_up;gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseOver=function(evt)
{if(this.m_disabled||this.m_busy)
return false;if(this.m_image_active&&!this.m_button_down)
this.src=this.m_image_active;gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtMouseOut=function(evt)
{if(this.m_image_active!==null)
this.src=(this.m_button_down)?this.m_image_down:this.m_image_up;gtCancelBubble(evt);return gtPreventDefault(evt);};element.gtDragStart=function(evt)
{gtCancelBubble(evt);return gtPreventDefault(evt);};element.changeImages=function btnChangeImages(up,down,active,tooltip)
{this.m_tooltip=tooltip;this.m_image_up=this.m_img_path+up;this.m_image_down=this.m_img_path+down;this.m_image_active=(active)?this.m_img_path+active:null;this.src=this.m_image_up;this.setTooltipToShow();};element.decodeActionString=function()
{var b_par=this.m_action.lastIndexOf("(");var e_par=this.m_action.lastIndexOf(")");if(b_par>0&&e_par>0)
{if(e_par-b_par>1)
this.m_action_has_parameters=true;else
this.m_action_has_parameters=false;element.m_action=element.m_action.substring(0,e_par);}};var slash_pos=element.src.lastIndexOf("/");element.m_img_path=(slash_pos<0)?"":element.src.substr(0,slash_pos+1);element.m_image_up=element.src;element.m_button_down=false;element.m_disabled=false;element.m_busy=false;element.m_action=action;element.m_tooltip=tooltip;element.m_replacement_array=null;element.title=tooltip;element.m_image_down=element.m_img_path+image_down;if(image_active!==null)
element.m_image_active=element.m_img_path+image_active;else
element.m_image_active=null;if(typeof(disabled)!="undefined")
element.setDisabled(disabled,disabled_tip);element.decodeActionString();}