function menuButtonBehaviour(btn,menuDivID)
{
var menuDIV = document.getElementById(menuDivID);
if (menuDIV != null)
{
setButtonsInRef(menuDIV,btn,true);
}
btn.style.color = "#aaaaaa";
countClicks++;
var onclickEvt = btn.attributes['onclick'].value;
var arrOnclickEv;
var onclickExecute = "";
arrOnclickEv = onclickEvt.split(";");
var blnEncountered = false;
for (i=0;i<arrOnclickEv.length;i++)
{
if (arrOnclickEv[i].indexOf("return menuButtonBehaviour(this") >= 0)
{
blnEncountered = true;
}
if (blnEncountered == true && arrOnclickEv[i].indexOf("return menuButtonBehaviour(this") < 0)
{
if (arrOnclickEv[i].indexOf("return") >= 0)
{
if(eval(arrOnclickEv[i].replace("return ","")) == false)
{
countClicks--;
btn.style.color = "";
btn.disabled = false;
//Enable the other buttons again, no postback
if (menuDIV != null)
setButtonsInRef(menuDIV,btn,false);
return false;
}
}
else if (trim(arrOnclickEv[i]) != '')
{
onclickExecute = onclickExecute + ";" + arrOnclickEv[i];
}
}
}
var blnValidate;
if (trim(onclickExecute) != '')
{
onclickExecute = onclickExecute + ";";
blnValidate = eval(onclickExecute);
}
else
{
blnValidate = true;
}
if (onclickEvt != "")
{
if(blnValidate && countClicks>1){
btn.disabled = true;
return false;
//Enable the other buttons again, no postback
if (menuDIV != null)
setButtonsInRef(menuDIV,btn,false);
}
else if (!blnValidate)
{
//Enable the other buttons again, no postback
if (menuDIV != null)
setButtonsInRef(menuDIV,btn,false);
countClicks--;
btn.style.color = "";
btn.disabled = false;
}
}
else
{
if(countClicks>1){
if (menuDIV != null)
setButtonsInRef(menuDIV,btn,false);
btn.disabled = true;
return false;
}
}
}
//All childnodes in the ref node will be looped, all input types will be disabled/enabled except for 'thisBtn'
function setButtonsInRef(ref,thisBtn,disableButtons)
{
if (ref != null && ref.childNodes != null)
{
for (var i = 0;i < ref.childNodes.length; i++)
{
var child = ref.childNodes[i];
if ((child.nodeType == 1) && (child.id != thisBtn.id) && (child.tagName == "INPUT") && (child.id.indexOf("txtTarget") < 0))
{
child.disabled = disableButtons;
}
else
{
setButtonsInRef(child,thisBtn,disableButtons);
}
}
}
}