


var TipBox=Class.create();

TipBox.prototype=
{

initialize: function(msg, _options)
{

this.options=
{
delay:0,
elementName:"dd"

}.extend(_options ||
{});
this.using=false;
this.removed=false;
this.text="";
this.box=document.createElementWithText(this.options.elementName,msg);
Element.addClassName(this.box,"tipBox");
this.spanClose=$se("span");
this.spanClose.innerHTML="<img src='img/imgClose.gif' alt='' title='Close'/>";
this.spanClose.className="close";
this.spanClose.onclick=this.hide.bind(this);
this.spanInfo=$se("span");
this.spanInfo.className="info";
this.box.appendChild(this.spanInfo);
this.box.appendChild(this.spanClose);
this.timeOutPtr=0;
if(this.options.padding)this.box.style.padding=this.options.padding;
if(this.options.color)this.box.style.color=this.options.color;
if(this.options.backgroundColor)this.box.style.backgroundColor=this.options.bgColor;
if(this.options.borderWidth)this.box.style.borderWidth="1px";
if(this.options.borderStyle)this.box.style.borderStyle="solid";
if(this.options.borderColor)this.box.style.borderColor=this.options.borderColor;
if(this.options.marginTop)this.box.style.marginTop=this.options.marginTop;
if(this.options.marginRight)this.box.style.marginRight=this.options.marginRight;
if(this.options.marginLeft)this.box.style.marginLeft=this.options.marginLeft;
if(this.options.marginBottom)this.box.style.marginBottom=this.options.marginBottom;
if(this.options.textAlign)this.box.style.textAlign=this.options.textAlign;
this.hide();
if(this.options.delay>0)

{
this.timeOutPtr=window.setTimeout(this.hide,this.options.delay*1000);
}
},

setText:function(msg,noCloseButton)
{
this.text=msg;
this.spanInfo.innerHTML=msg;

if(noCloseButton)
{
if(this.box.childNodes.length>1)this.spanClose=this.box.removeChild(this.spanClose);

}else
{
this.box.appendChild(this.spanClose);
}
},

removeAfterSeconds:function(delay)
{

if(!this.removed)
{
if(this.timeOutPtr)window.clearTimeout(this.timeOutPtr);
this.timeOutPtr=window.setTimeout(this.remove.bind(this),delay*1000);
}
},

hideAfterSeconds:function(delay)
{

if(this.using)
{
if(this.timeOutPtr)window.clearTimeout(this.timeOutPtr);
this.timeOutPtr=window.setTimeout(this.hide.bind(this),delay*1000);
}
},
remove:function()

{
this.removed=true;
Element.remove(this.box);
},

show:function()
{
this.using=true;
Element.show(this.box);
},

hide:function()
{
this.using=false;
Element.hide(this.box);
},

clearDelay:function()
{
if(this.timeOutPtr)window.clearTimeout(this.timeOutPtr);
},

toggleText:function(msg,delay)
{
this.box.innerHTML=msg;
window.setTimeout(this.recoverText.bind(this),delay*1000);
},

recoverText:function()
{
this.box.innerHTML=this.text;
}
}
