/*** 
 * Rudy Bartel (Oct 14, 2008)
 * Change all 'visibility' to 'display' because visibility:hidden keeps the item in view in IE7 (although not visible) 
 * so it blocks mouse clicks on items underneath.
 */

var IE5=(document.getElementById && document.all)? true : false;
var W3C=(document.getElementById)? true: false;
var currIDb=null, currIDs=null, xoff=0, yoff=0; zctr=0; totz=0;

function trackmouse(evt){
    if((currIDb!=null) && (currIDs!=null)){
            var x=(IE5)? event.clientX+document.body.scrollLeft : evt.pageX;
            var y=(IE5)? event.clientY+document.body.scrollTop : evt.pageY;
                    currIDb.style.left=x+xoff+'px';
                    currIDs.style.left=x+xoff+10+'px';
                    currIDb.style.top=y+yoff+'px';
                    currIDs.style.top=y+yoff+10+'px';
            return false;
    }
}

function stopdrag(){
        currIDb=null;
        currIDs=null;
        NS6bugfix();
}

function grab_id(evt){
        xoff=parseInt(this.IDb.style.left)-((IE5)? event.clientX+document.body.scrollLeft : evt.pageX);
        yoff=parseInt(this.IDb.style.top)-((IE5)? event.clientY+document.body.scrollTop : evt.pageY);
        currIDb=this.IDb;
        currIDs=this.IDs;
}

function NS6bugfix(){
        /*if(!IE5){
                self.resizeBy(0,1);
                self.resizeBy(0,-1);
        }   */
}

function incrzindex(){
        zctr=zctr+2;
        this.subb.style.zIndex=zctr;
        this.subs.style.zIndex=zctr-1;
}
function HoonConfig(width, height, x , y , isdraggable, boxcolor, barcolor, shadowcolor, textcolor, textptsize, textfamily, path)
{
    this.width = width;
    this.height = height;
    this.x = x;
    this.y = y;
    this.isdraggable = isdraggable;
    this.boxcolor = boxcolor;
    this.barcolor = barcolor;
    this.shadowcolor = shadowcolor;
    this.textcolor = textcolor;
    this.textptsize = textptsize;
    this.textfamily = textfamily;
    this.titlewidth = width-22;

    if(path){
        this.path = path;
    }else{
        this.path = null;
    }
}
function HoonPopup(id, title, HoonConfig )
{
    this.id = id;
    this.title = title;
    this.HoonConfig = HoonConfig;
    
    this.Init = Init;
    this.ShowLayer = ShowLayer;
    this.HideLayer = HideLayer;
}
function Init( ){
    if(W3C){
        content = document.getElementById(this.id).innerHTML;
        document.getElementById(this.id).innerHTML = "";
        zctr+=2;
        totz=zctr;
        var txt='';
        txt += '<div id="'+this.id+'_s" style="position:absolute; left:'+(this.HoonConfig.x+7)+'px; top:'+(this.HoonConfig.y+7)+'px; width:'+this.HoonConfig.width+'px; height:'+this.HoonConfig.height+'px; display:none"> </div>';
        txt += '<div id="'+this.id+'_b" style="border:outset '+this.HoonConfig.barcolor+' 2px; position:absolute; left:'+this.HoonConfig.x+'px; top:'+this.HoonConfig.y+'px; width:'+this.HoonConfig.width+'px; overflow:hidden; height:'+this.HoonConfig.height+'px; background-color:'+this.HoonConfig.boxcolor+'; display:none">';
        txt += '<div style="width:'+this.HoonConfig.width+'px; height:22px; padding:0px;">';
        txt += '<table border="0" cellpadding="0" cellspacing="0" border="0" width="'+(IE5? this.HoonConfig.width-4 : this.HoonConfig.width)+'" style="background-color:'+this.HoonConfig.barcolor+';" height="23px">';
        txt += '<tr>';
        txt += '<td width="'+ this.HoonConfig.titlewidth +'">';
        txt += '<div id="'+this.id+'_h" style="width:'+this.HoonConfig.titlewidth+'px; height:14px; font: bold 12px Tahoma; cursor:move; color:'+this.HoonConfig.textcolor+'">&nbsp;&nbsp;'+this.title+'</div>';
        txt += '</td>';
        txt += '<td align="right" style="padding-right:5px;" valign="middle">';
        txt += '<a onmousedown="document.getElementById(\''+this.id+'_s\').style.display=\'none\'; document.getElementById(\''+this.id+'_b\').style.display=\'none\';return false">';
        if(this.HoonConfig.path){
            txt += '<img src="'+this.HoonConfig.path+'/images/close5.gif" border="0" style="cursor:hand"></a>';
        }else{
            txt += '<img src="../images/close5.gif" border="0" style="cursor:hand"></a>';
        }
        txt += '</td>';
        txt += '</tr>';
        txt += '<tr><td colspan="2" bgcolor="#999999" height="1px"></td></tr>';
        txt += '</table>';
        txt += '</div>';
        txt += '<div id="'+this.id+'_ov" width:'+this.HoonConfig.width+'px; align="center" style="margin:5px; color:'+this.HoonConfig.textcolor+'; font:'+this.HoonConfig.textptsize+'pt '+this.HoonConfig.textfamily+';">'+content+'</div>';
        txt += '</div>';
        document.write(txt);
        this.IDh=document.getElementById(this.id+'_h');
        this.IDh.IDb=document.getElementById(this.id+'_b');
        this.IDh.IDs=document.getElementById(this.id+'_s');
        this.IDh.IDb.subs=this.IDh.IDs;
        this.IDh.IDb.subb=this.IDh.IDb;
        this.IDh.IDb.IDov=document.getElementById(this.id+'_ov');
        if(IE5){
                this.IDh.IDb.IDov.style.width=this.HoonConfig.width-6;
                this.IDh.IDb.IDov.style.height=this.HoonConfig.height-22;
                this.IDh.IDb.IDov.style.scrollbarBaseColor=this.HoonConfig.boxcolor;
                this.IDh.IDb.IDov.style.overflow="auto";
        }
        else{
                this.IDh.IDs.style.MozOpacity=.5;
        }
        this.IDh.IDb.onmousedown=incrzindex;
        if(this.HoonConfig.isdraggable){
                this.IDh.onmousedown=grab_id;
                this.IDh.onmouseup=stopdrag;
        }
    }
}

if(W3C)document.onmousemove=trackmouse;
if(!IE5 && W3C)window.onload=NS6bugfix;

function ShowLayer(){
    // FireFox : stopPropagation()
    //window.event.cancelBubble = true;

	/* 
	Change to fix the vertical position to account for scrolling 
	Rudy Bartel (Sep 25, 2008)
	 */
	document.getElementById(this.id+'_s').style.top = ( this.HoonConfig.y + document.documentElement.scrollTop ) + "px";
	document.getElementById(this.id+'_b').style.top = ( this.HoonConfig.y + document.documentElement.scrollTop ) + "px";
	
	document.getElementById(this.id+'_s').style.display=''; 
    document.getElementById(this.id+'_b').style.display='';    
}

function HideLayer(){
	document.getElementById(this.id+'_s').style.display='none'; 
    document.getElementById(this.id+'_b').style.display='none';
}
