var iFrameInitialX = 0;
var iFrameInitialY = 0;
var moveTheFrame = false;

function dragTheFrame(e)
{
	if(!moveTheFrame)
	{
		return;
	}
	
	if (!e) var e = window.event;
	var isLeftButtonPressed = false;
	if( navigator.appName.indexOf("Netscape") != -1 )
	{
		// do not require a check as it is working perfectly
		// also in netscape, onmousemove we cannot find whether the button is pressed or not
		isLeftButtonPressed = true;
	}
	else
	{
		if(e.button == 1)
		{
			isLeftButtonPressed = true;
		}
	}
	if(isLeftButtonPressed)
	{
		parent.moveIFrame(frameName, getCoordinate(e, "x") - iFrameInitialX, getCoordinate(e, "y") - iFrameInitialY);
	}
	else
	{
		moveTheFrame = false;
	}
}
function getCoordinate(e, whichCoordinate)
{

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	else
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	// posx and posy contain the mouse position relative to the document
	if(whichCoordinate == "x" || whichCoordinate == "X")
	{
		return posx;
	}
	else
	{
		return posy;
	}
}

function moveIFrame(frameName, x, y)
{
	var frameObj = document.getElementById(frameName);
	var currentLeft = frameObj.style.left;
	var currentTop  = frameObj.style.top;
	currentLeft = currentLeft.substring(0, currentLeft.length - 2);
	currentTop  = currentTop.substring(0, currentTop.length - 2);

	var modifiedLeft = eval(currentLeft) + x;
	var modifiedTop  = eval(currentTop) + y;
	
	if(frameName != 'divCalendar')
	{
		var frameWidth  = frameObj.style.width;
		frameWidth = frameWidth.substring(0, frameWidth.length - 2);
		if(modifiedLeft < 0)
		{
			modifiedLeft = 0;
		}
		if(modifiedTop < 0)
		{
			modifiedTop = 0;
		}

		var frameWidth  = frameObj.style.width;
		var frameHeight  = frameObj.style.height;
		frameWidth = frameWidth.substring(0, frameWidth.length - 2);
		frameHeight = frameHeight.substring(0, frameHeight.length - 2);
		
		if( (modifiedLeft + eval(frameWidth)) > document.body.clientWidth)
		{
			modifiedLeft = currentLeft;	
		}
		if( (modifiedTop + eval(frameHeight)) > document.body.clientHeight)
		{
			modifiedTop = currentTop;
		}
	}
	frameObj.style.left = modifiedLeft;
	frameObj.style.top  = modifiedTop;
	/*document.getElementById('DivShow').style.left = modifiedLeft;
	document.getElementById('DivShow').style.top = modifiedTop;*/
}

objWhichSupportsIFrameMovement.onmouseover = function(e)
{
	objWhichSupportsIFrameMovement.style.cursor="move";
}

objWhichSupportsIFrameMovement.onmousedown = function(e)
{
	//objWhichSupportsIFrameMovement.style.cursor="move";
	if (!e) var e = window.event;
	var isLeftButtonPressed = false;
	if( navigator.appName.indexOf("Netscape") != -1 )
	{
		if(e.which == 1)
		{
			isLeftButtonPressed = true;
		}
	}
	else
	{
		if(e.button == 1)
		{
			isLeftButtonPressed = true;
		}
	}
	
	if(isLeftButtonPressed)
	{
		iFrameInitialX = getCoordinate(e, "x");
		iFrameInitialY = getCoordinate(e, "y");	
		moveTheFrame = true;
	}
	else
	{
		moveTheFrame = false;
	}
}


document.onmousemove = dragTheFrame;
document.onmouseup = function(){moveTheFrame = false;};