arrayButtonImages = new Array(100)
buttoncount = 0

function button(image_normal1,image_normal2,image_normal3,image_hover1,image_hover2,image_hover3,image_active1,image_active2,image_active3)
{
	this.image_normal1 = new Image()
	this.image_normal1.src = image_normal1
	this.image_normal2 = new Image()
	this.image_normal2.src = image_normal2
	this.image_normal3 = new Image()
	this.image_normal3.src = image_normal3

	if (image_hover1 == "") {
		this.image_hover1 = this.image_normal1
		this.image_hover2 = this.image_normal2
		this.image_hover3 = this.image_normal3
	} else {
		this.image_hover1 = new Image()
		this.image_hover1.src = image_hover1
		this.image_hover2 = new Image()
		this.image_hover2.src = image_hover2
		this.image_hover3 = new Image()
		this.image_hover3.src = image_hover3
	}

	if (image_active1 == "") {
		this.image_active1 = this.image_hover1
		this.image_active2 = this.image_hover2
		this.image_active3 = this.image_hover3
	} else {
		this.image_active1 = new Image()
		this.image_active1.src = image_active1
		this.image_active2 = new Image()
		this.image_active2.src = image_active2
		this.image_active3 = new Image()
		this.image_active3.src = image_active3
	}
}

function AddButtonImages(image_normal1,image_normal2,image_normal3,image_hover1,image_hover2,image_hover3,image_active1,image_active2,image_active3)
{
	mybutton = new button(image_normal1,image_normal2,image_normal3,image_hover1,image_hover2,image_hover3,image_active1,image_active2,image_active3)
	arrayButtonImages[buttoncount] = mybutton;
	buttoncount = buttoncount + 1;
	return (buttoncount-1)
}

function ChangeButtonState(img1, img2, img3, nButton, nState)
{
	if (nState == 0) {
		img1.src = arrayButtonImages[nButton].image_normal1.src
		img2.src = arrayButtonImages[nButton].image_normal2.src
		img3.src = arrayButtonImages[nButton].image_normal3.src
	} else if (nState == 1) {
		img1.src = arrayButtonImages[nButton].image_hover1.src
		img2.src = arrayButtonImages[nButton].image_hover2.src
		img3.src = arrayButtonImages[nButton].image_hover3.src
	} else if (nState == 2) {
		img1.src = arrayButtonImages[nButton].image_active1.src
		img2.src = arrayButtonImages[nButton].image_active2.src
		img3.src = arrayButtonImages[nButton].image_active3.src
	}
}

function ChangeLocation(url, newWindow)
{
	if (newWindow == "_new") {
		window.open(url)
	} else {
		document.location.href=url
	}
}

function CreateButton(
					image_normal1,image_normal2,image_normal3,image_hover1,image_hover2,image_hover3,image_active1,image_active2,image_active3
					,text,hovertext,target,openwhere
					,x,y,width,height,xTextPos
					,fontface,fontsize,color,bold,italic,underline,hrzalignment,bPreview
) 
{      
	n = AddButtonImages(image_normal1,image_normal2,image_normal3,image_hover1,image_hover2,image_hover3,image_active1,image_active2,image_active3)

	sHtml ="<div style=\"Position:absolute; top:" + y + "px; left:" + x + "px;\">\n"
 	 sHtml+="<table onmousedown=\"ChangeButtonState(img"+n+"1, img"+n+"2, img"+n+"3, "+n+", 2)\" onmouseover=\"ChangeButtonState(img"+n+"1, img"+n+"2, img"+n+"3, "+n+", 1)\" "
         sHtml+="onmouseout=\"ChangeButtonState(img"+n+"1, img"+n+"2, img"+n+"3, "+n+", 0)\""

	
	sHtml+="  style=\"cursor:pointer\" cellspacing=0 cellpadding=0 "

	if (!bPreview)
         sHtml+="onclick=\"ChangeLocation('"+target+"', '"+openwhere+"')\" border=0><tr><td>\n"
        else
         sHtml+="onclick=\"alert('"+target+"')\" border=0><tr><td>\n"

	  sHtml+="<div style=\"Position:absolute; top:0px; left:0px;\">\n"
	   sHtml+="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>\n"
	    sHtml+="<td><img id=img"+n+"1 src=\""+image_normal1+"\"></td>\n"
	    sHtml+="<td><img id=img"+n+"2 src=\""+image_normal2+"\" width=\""+(width-2*xTextPos)+"\" height=\""+height+"\"></td>\n"
	    sHtml+="<td><img id=img"+n+"3 src=\""+image_normal3+"\"></td>\n"
	   sHtml+="</tr></table>\n"
	  sHtml+="</div>\n"
	  sHtml+="<div style=\"Position:absolute; top:0px; left:0px; width:"+width+"px;\">\n"
	   sHtml+="<table height=\""+height+"\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\""
      sHtml+="font-family: "+fontface+"; font-size: "+fontsize+"px; color:"+color+";"
      if (bold == 1) {
       sHtml+=" font-weight: 700;"
      }
      if (italic == 1) {
       sHtml+=" font-style: italic;"
      }
      if (underline == 1) {
       sHtml+=" text-decoration: underline;"
      }
	   sHtml+="\"><tr>"
	   sHtml+="<td width=\""+xTextPos+"\"></td>\n"
	   sHtml+="<td valign=\"middle\" align=\""+hrzalignment+"\" width=\""+(width-2*xTextPos)+"\">"+text+"</td>\n"
	   sHtml+="<td width=\""+xTextPos+"\"></td>\n"
      sHtml+="</tr></table>\n"
	  sHtml+="</div>\n"


	 if (hovertext != text) {
	  sHtml+="<div style=\"Position:absolute; top:0px; left:0px; height:"+height+"px; width:"+width+"px;\">\n"
           sHtml+="<img alt=\""+hovertext+"\" height=\""+height+"\" width=\""+width+"\" src=\"blank.png\">";
	  sHtml+="</div>"
	 }


     sHtml+="</td></tr></table>\n"
    sHtml+="</div>\n"

	document.write(sHtml)
}
