var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;

function buildDimmerDiv()
{
    document.write('<div id="dimmer" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}

function newxmlHttp(){
	try {
	xmlHttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
	alert("Sorry, your browser is not currently supported. I suggest using Mozilla Firefox");
	}
}

function popup(id, type, table, date){
	newxmlHttp();
	var linkText='';var file='';
	if(type=='event')file='caladmin.php';
	else if(type=='workout')file='workadmin.php';
	else if((type=='e')||(type=='w'))file='popupd.php';
	linkText='?table='+table;
	if(id > 0)linkText = linkText + '&'+type+'id=' + id;
	else linkText = linkText + '&startdate=' + date;
	var url = file+linkText;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=displaycode;
	xmlHttp.send(null);
	if((type!='e')&&(type!='w'))document.getElementById('dimmer').style.visibility = "visible";
}function displaycode(){
	if (xmlHttp.readyState==4){
	if (xmlHttp.status==200){
	code = document.getElementById('add');
	code.innerHTML = xmlHttp.responseText;
	}else{
	alert("Problem retrieving data:" + xmlHttp.statusText)
}}}function displayCalendar(){
	if (xmlHttp.readyState==4){
	if (xmlHttp.status==200){
	calendar = document.getElementById('calendar');
	calendar.innerHTML = xmlHttp.responseText;
	}else{
	alert("Problem retrieving data:" + xmlHttp.statusText)
}}}
function displayFloatingDiv(divId, title, html, width, height, left, top) 
{
	DivID = divId;
    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;	
	addHeader = '<table bgcolor="#CCDDCC" style="background:url(images/bg/navbg1.png) repeat-x top; color:#fff; font-weight:bold; width:' +
	width+'px; text-align:left;"><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 style="color:#fff;" href="javascript:hiddenFloatingDiv(\''+divId+'\');void(0);"> X </a></td></tr></table>'+html;
    // add to your div an header	
	document.getElementById(divId).innerHTML = addHeader;
	document.getElementById(divId).style.visibility = "visible";
}

function hiddenFloatingDiv(divId) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';
	DivID = "";
	document.getElementById('dimmer').style.visibility = 'hidden';
}

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()
{
    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();
