//
// global variables
//
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;


//
function displayFloatingDiv(divId, title, width, height, left, top, ID) 
{

	DivID = divId;
	if (typeof document.body.style.maxHeight === "undefined") 
    {   //if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) 
		{   //iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div>");
			//$("#TB_overlay").click(tb_remove);
		}
	}
	else
	{   //all others
	 
		if(document.getElementById("TB_overlay") === null)
		{ 
		    $("body").append("<div id='TB_overlay'></div>");
			//$("#TB_overlay").click(tb_remove);
			
		}
	}

    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;
	
	if (originalDivHTML == "")
	    originalDivHTML = document.getElementById(divId).innerHTML;
	
	//this example allows user to move the msg box around
	//addHeader = '<table style="width:' + width + 'px" class="floatingHeader">' +
	//            '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">' + title + '</td>' + 
	//            '<td style="width:18px" align="right"><a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);">' + 
	//            '<img align="absmiddle" alt="Close..." title="Close..." src="../enterprise/images/btn_close.gif" border="0"></a>' + 
	//            '<a class="whitelink" href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);">' + 
	//            'Close</a></td></tr></table>';
	
	addHeader = '<table style="width:' + width + 'px" class="floatingHeader">' +
	            '<tr><td>' + title + '</td>' + 
	            '<td style="width:18px" align="right"><a href="javascript:hiddenFloatingDiv(\'' + divId + '\');void(0);">' + 
	            '<img align="absmiddle" alt="Close..." title="Close..." src="/enterprise/images/btn_close.gif" border="0"></a>' + 
	            '</td></tr></table>';
	            
	addFooter = '<table style="width:' + width + 'px" class="floatingFooter" >' +
	            '<tr><td>&nbsp;</td></tr></table>';
	

    // add to your div an header	
	document.getElementById(divId).innerHTML = addHeader + originalDivHTML + addFooter;
	document.getElementById("ctl00_ContentPlaceHolder1_txtID").value = ID;
	document.getElementById("ctl00_ContentPlaceHolder1_lblID").innerHTML = ID;
	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';
	DivID = "";
    tb_remove();
}

function tb_remove() {
	$("#TB_overlay").unbind();
	$('#TB_overlay,#TB_HideSelect').remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "760px"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	return false;
}


//
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;

}

// call init
init();
