function WAF_BB(element){
    if(element==null){
         this.MouseUp = function(){}
         this.MouseDown = function(){}
         this.MouseOut = function(){}
         this.LinkClick = function(){}
    }else{
        var id;
        if(element.tagName=="a"){
            id = element.parent.parent.parent.id;
            alert(id);
        }else{
            id = element.id;
        }
        if(id==null) return new WAF_BB();
        id = id.replace("_Outer","");
        var t = window[id];
        if(t == null) {
            var scr = document.getElementById(id+"_Script").innerHTML;
            eval(scr); 
            return eval(id);
        }
         return t;
    }
}

function WAF_BaseButton(id, styleClassId, clientScript, stayClicked){
    var isPressedOnce = false;
    function callScript(){
         if(stayClicked && isPressedOnce) return;
        eval(clientScript);isPressedOnce=true;   
    }
    function showPressed(){setStyle("MouseDown");}
    function showNormal(){setStyle("");}
    this.KeyPressed = function(){
        //WAF.Trace("KeyPressed");
        showPressed();
        callScript();
        if(!stayClicked) window.setTimeout(function(){showNormal();},800);
    }
    this.LinkClick = function(){
        if(new Date()-lastMouseUp < 200) return;
        //WAF.Trace("LinkClick");
        callScript();
        if(currentModeString==""){
            showPressed();
            if(!stayClicked) window.setTimeout(function(){showNormal();},100);
        }else{
            if(!stayClicked) showNormal();
        }
    }
    this.MouseDown = function(){
        //WAF.Trace("MouseDown");
        if(document.getElementById("WAF")!=null) WAF.DisableSelect();
        showPressed();
    }
    this.MouseOut = function(){
        //WAF.Trace("MouseOut");
        if(!stayClicked || !isPressedOnce) showNormal();
    }
    var lastMouseUp;
    this.MouseUp = function(){
        // WAF.Trace("MouseUp");
        lastMouseUp = new Date();
        callScript();
        if(!stayClicked) showNormal();
    }
    var currentModeString = "";
    function setStyle(modeString){
        var element = document.getElementById(id+"_Outer");
        element.className = styleClassId+modeString+'_Outer WAF_Button';
        element.childNodes[0].className=styleClassId+modeString+'_Right';
        element.childNodes[0].childNodes[0].className=styleClassId+modeString+'_Left';
        element.childNodes[0].childNodes[0].childNodes[0].className=styleClassId+modeString+'_Text';
        currentModeString = modeString;
    }
}




function WAF_BaseButtonMouseDown(t, styleClassId){
    if(WAF != null) WAF.DisableSelect();
    t.className = styleClassId+'MouseDown_Outer';
    t.childNodes[0].className=styleClassId+'MouseDown_Right';
    t.childNodes[0].childNodes[0].className=styleClassId+'MouseDown_Left';
    t.childNodes[0].childNodes[0].childNodes[0].className=styleClassId+'MouseDown_Text';
}
function WAF_BaseButtonMouseUp(t, styleClassId){
    t.className=styleClassId+'_Outer';
    t.childNodes[0].className=styleClassId+'_Right';
    t.childNodes[0].childNodes[0].className=styleClassId+'_Left';
    t.childNodes[0].childNodes[0].childNodes[0].className=styleClassId+'_Text';
}

