var current = null;
var nOffestX = 0;
var nOffestY = 0;

var bIE = false;

function init()
{
	
	document.onmousedown = startDrag;
	document.onmouseup = endDrag;	
	if ((parseInt(navigator.appVersion) >= 4) && (navigator.appName.indexOf("Microsoft") != -1)) 
	{
		// MSIE 4.x oder hoeher
		bIE = true;
	}
	
	document.getElementById("ifrmContainer").style.top = '60px';
	document.getElementById("ifrmContainer").style.left = '110px';
	
	document.getElementById("ifrmWindow").style.top = '90px';
	document.getElementById("ifrmWindow").style.left = '120px';
}


function startDrag (e) 
{
	if (bIE) var obj = window.event.srcElement;
	else var obj = e.target;
	
	if  (obj.id == 'ifrmContainer')
	{
		current = obj;
				
		nLeft = parseInt(document.getElementById("ifrmWindow").style.left.split('px')[0]);
		nTop =  parseInt(document.getElementById("ifrmWindow").style.top.split('px')[0]);
		
		if (bIE) 
		{
			nOffestX = window.event.clientX - nLeft;
			nOffestY = window.event.clientY - nTop;
		}
		else
		{
			nOffestX = e.clientX - nLeft;
			nOffestY = e.clientY - nTop;
		}

		if (!bIE) document.captureEvents (Event.MOUSEMOVE);
		document.onmousemove = drag;
		return false;
	}
	
	// Benutzer hat auf kein Objekt geklickt
	current = null;
	return false;
}


function drag (e) 
{
	if (current != null) 
	{
		
		var nX = 0;
		var nY = 0;
		
		if (bIE) 
		{
			nX = window.event.clientX;
			nY = window.event.clientY;
		}
		else
		{
			nX = parseInt (e.clientX);
			nY = parseInt (e.clientY);
		}
		
		document.getElementById("ifrmContainer").style.top = (nY - nOffestY - 30) + 'px';
		document.getElementById("ifrmContainer").style.left = (nX - nOffestX -10) + 'px';
			
		document.getElementById("ifrmWindow").style.top = (nY - nOffestY) + 'px';
		document.getElementById("ifrmWindow").style.left = (nX - nOffestX) + 'px';
	}  
	return false;
}


function endDrag (e) 
{
	if (!bIE) document.releaseEvents (Event.MOUSEMOVE);
	document.onmousemove = null;
	current = null;
  
	return false;
}


function showFrame ()
{
	init();
	document.getElementsByName('EditEvent')[0].className = "ifrm show"; 
	document.getElementById("ifrmContainer").className = "show";
}


function hideFrameAndReload(Day)
{
	//zum aktuellen tag scrollen, indem der Tag als startdatum gewaelt wird
	var aDay = Day.split('.');
	document.ReloadPage.Day.value = aDay[0];
	document.ReloadPage.Month.value = aDay[1];
	document.ReloadPage.Year.value = aDay[2];
	
	document.getElementsByName('EditEvent')[0].className = "ifrm hide"; 
	document.getElementById("ifrmContainer").className = "hide";
	document.ReloadPage.submit();
}	


function hideFrame()
{
	document.getElementsByName('EditEvent')[0].className = "ifrm hide"; 
	document.getElementById("ifrmContainer").className = "hide";
	document.blankPage.submit();
}	

function openEvent (nPageID) 
{
	document.editBookingForm.action = "Page" + nPageID + ".page";
	document.editBookingForm.submit();
	showFrame();
}
