
function buttonUp(name){
		//document.getElementById(name).src= ctx()+'/images/buttons/'+removeTail(name)+'Up.gif';

        var images = document.getElementsByTagName('img');

        for (var i = 0; i < images.length; i++)
           if (images[i].id==name)
				images[i].src= getImagePath(images[i].src)+removeTail(name)+'Up.gif';
           
}

function buttonDown(name){
		//document.getElementById(name).src= ctx()+'/images/buttons/'+removeTail(name)+'Down.gif';

        var images = document.getElementsByTagName('img');

        for (var i = 0; i < images.length; i++)
           if (images[i].id==name)
				images[i].src= getImagePath(images[i].src)+removeTail(name)+'Down.gif';
}

function buttonOut(name){
		//document.getElementById(name).src= ctx()+'/images/buttons/'+removeTail(name)+'.gif';
        var images = document.getElementsByTagName('img');

        for (var i = 0; i < images.length; i++)
           if (images[i].id==name)
				images[i].src= getImagePath(images[i].src)+removeTail(name)+'.gif';
}

function removeTail(buttonName){

	// removes a numeric tail on the button name, 
	// which is used to have multiple instances of a button with the same image

    var numericChars = "0123456789_";
	    
	while(numericChars.indexOf(buttonName.charAt(buttonName.length-1))!=-1){
		buttonName = buttonName.substr(0,buttonName.length-1);
	}
	
	return buttonName;
}

function getImagePath(fullPath){
	return fullPath.substring(0,fullPath.lastIndexOf('/')+1);
}

function createButton(name,title,onclick,href){
	var html = "";
	html += "<a id='b_"+name+"' name='"+name+"' onMouseOver='buttonUp(this.name);' onMouseOut='buttonOut(this.name);' onMouseDown='buttonDown(this.name);' ";
	if(onclick)
		html += "onclick='eval(\""+onclick+"\")' ";
	if(href)
		html += "href='"+href+"' ";
	html +=	"title='"+title+"' ><img id='"+name+"' src='"+ctx()+"/images/squareButtons/"+removeTail(name)+".gif'/></a>";
	return html;
}

function createCancelButton(){
	return createButton("cancel3",Labels.cancel,"hideDialog();");
}
