// global variables
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;
var DimmerHeight = 100;

function buildDimmerDiv()
{
    document.write('<div id="dimmer" class="dimmer" style="width:100%;height:100%;"></div>');
    //document.write('<div id="dimmer" class="dimmer" style="width:100%;height:' + DimmerHeight +'px"></div>');
}

function displayFloatingDiv(divId, title, titleicon, closebutton, width, height, left, top) 
{
	DivID = divId;
	if (title == "")
	{
		addTitle = "&nbsp;";
	}
	else
	{
		if (titleicon == "")
		{
			addTitle = '<table height=100% border=0 cellpadding=0 cellspacing=0><tr><td><span style="padding-left:5px;font-family:verdana;font-size:12px;">' + title + '</span></td></tr></table>';
		}
		else
		{
			addTitle = '<table height=100% border=0 cellpadding=0 cellspacing=0><tr><td style="padding-left:3px;"><img src=/popup/title_icon_' + titleicon + '.gif></td><td><span style="padding-left:5px;font-family:verdana;font-size:12px;">' + title + '</span></td></tr></table>';
		}
	}

	document.getElementById('dimmer').style.visibility = "visible";

    document.getElementById(divId).style.width = width + 'px';
    document.getElementById(divId).style.height = height + 'px';
    document.getElementById(divId).style.left = left + 'px';
    document.getElementById(divId).style.top = top + 'px';
	
	var addHeader;
	var addFooter;
	//var intbottomheight;
	var strclosebutton;
	//intbottomheight = 7;
	if (closebutton == "2")
	{
		strclosebutton = "2";
	}
	else
	{
		strclosebutton = "";
	}	
	//if (originalDivHTML == "")
	    originalDivHTML = document.getElementById(divId).innerHTML;

	addHeader = '<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=25><td width=7><img src=/popup/sq_top_left.gif></td><td background=/popup/sq_top_center.gif><table width=100% height=100% border=0 cellpadding=0 cellspacing=0><tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;font-family:verdana;font-size:12px;">' + addTitle + '</td><td width=26 align=right style="padding-top:1px;"><a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);"><img onmouseover="this.src=\'/popup/sq_close' + strclosebutton + '_on.gif\';" onmouseout="this.src=\'/popup/sq_close' + strclosebutton + '_off.gif\';" src=/popup/sq_close' + strclosebutton + '_off.gif border=0></a></td><tr></table></td><td width=7><img src=/popup/sq_top_right.gif></td></tr></table>';
	addSubHeader = '<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=' + (height - 25 - 7) + '><td width=7 background=/popup/sq_middle_left.gif></td><td align=center>';
	addSubFooter = '</td><td width=7 background=/popup/sq_middle_right.gif></td></tr></table>';
	addFooter = '<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=7><td width=7><img src=/popup/sq_bottom_left.gif></td><td background=/popup/sq_bottom_center.gif><img src=/popup/spacer.gif></td><td width=7><img src=/popup/sq_bottom_right.gif></td></tr></table>';

    // add to your div an header	
	document.getElementById(divId).innerHTML = addHeader + addSubHeader + originalDivHTML + addSubFooter + addFooter;

	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.visibility = "visible";
}

function hiddenFloatingDiv(divId) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById('dimmer').style.visibility = 'hidden';
	DivID = "";
}

function MouseDown(e) 
{
    if (over)
    {
        if (isMozilla) {
            objDiv = document.getElementById(DivID);
            X = e.layerX;
            Y = e.layerY;
            return false;
        }
        else {
            objDiv = document.getElementById(DivID);
            objDiv = objDiv.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}

function MouseMove(e) 
{
    if (objDiv) {
        if (isMozilla) {
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else 
        {
            objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
}

function MouseUp() 
{
    objDiv = null;
}

function init()
{
    // check browser
    isMozilla = (document.all) ? 0 : 1;

    if (isMozilla) 
    {
        document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
    }

    document.onmousedown = MouseDown;
    document.onmousemove = MouseMove;
    document.onmouseup = MouseUp;

    // add the div
    // used to dim the page
	buildDimmerDiv();
}
// call init
init();
