


var iframeObj;

function initiate()
{
	iframeObj = document.createElement("iframe");
	iframeObj.setAttribute("id", "popupContainer");
	iframeObj.style.width = "700px";
	iframeObj.style.height = "530px";
	iframeObj.style.display = "none";
	iframeObj.style.border = "0px";
	iframeObj.style.position = "absolute";
	iframeObj.style.zIndex = 100;
	document.body.appendChild(iframeObj);
}

function popup(url)
{
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	
	Element.setHeight('overlay', pageSize[1]);
	Element.setWidth('overlay', pageSize[0]);
	$("popupContainer").style.left = ((pageSize[2] == 0 ? pageSize[0] : pageSize[2])-700)/2 + pageScroll[0];
	$("popupContainer").style.top = ((pageSize[3] == 0 ? pageSize[1] : pageSize[3])-530)/2 + pageScroll[1];
	
	new Effect.Appear($("overlay"), {from: 0, to: 0.8, duration:0.3});
	new Effect.Appear($("popupContainer"), {from: 0, to: 1});
	
	$("popupContainer").src = url+(url.indexOf("?")==-1 ? "?" : "&")+"popup=1";
	$("popupContainer").setAttribute("border", 0);
	$("popupContainer").setAttribute("frameBorder", 0);
}

function divPopup(obj, width, height)
{
	var pageSize = getPageSize();
	var pageScroll = getPageScroll();
	
	width = width ? width : 700;
	height = height ? height : 530;

	Element.setHeight('overlay', pageSize[1]);
	Element.setWidth('overlay', pageSize[0]);
	$(obj).style.left = ((pageSize[2] == 0 ? pageSize[0] : pageSize[2])-width)/2 + pageScroll[0];
	$(obj).style.top = ((pageSize[3] == 0 ? pageSize[1] : pageSize[3])-height)/2 + pageScroll[1];
	$(obj).style.width = width+"px";
	$(obj).style.height = height+"px";

	new Effect.Appear($("overlay"), {from: 0, to: 0.8, duration:0.3});
	new Effect.Appear($(obj), {from: 0, to: 1.0, duration:0.3});
}

function hidePopup()
{
	new Effect.Fade($("popupContainer"), {duration: 0.3});
	new Effect.Fade($("overlay"), {duration: 0.3});
	if ($("proforma_div"))
		new Effect.Fade($("proforma_div"), {duration: 0.3});
	if ($("frontpage_div"))
		new Effect.Fade($("frontpage_div"), {duration: 0.3});
}

function getOffset(obj)
{
	if (obj.getBoundingClientRect)
	{
		var rect = obj.getBoundingClientRect();

		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);

		if (document.documentElement.dir == 'rtl')
		{
			scrollLeft = scrollLeft + document.documentElement.clientWidth - document.documentElement.scrollWidth;
		}

		return { 'left' : rect.left + scrollLeft, 'top' : rect.top + scrollTop };
	}

	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;

	while ((obj = obj.offsetParent) != null)
	{
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}

	return { 'left' : left_offset, 'top' : top_offset };
}

function getDimension(obj)
{
	return { 'width' : obj.offsetWidth, 'height' : obj.offsetHeight };
}

String.prototype.replaceAll = function(str, replace)
{
	text = this;
	while (text.indexOf(str) != -1)
		text = text.replace(str, replace);
	return text;
}

String.prototype.trim = function()
{
	text = this;
	return text.replace(/^\s+/, "").replace(/\s+$/, "");
}








var dragID = null;
function startDrag(id)
{
	dragID = id;
	$("thumbnailDiv").style.display = "block";
	$("thumbnailDiv").src = "frontend_"+id;
	document.body.onmousemove = function(e)
	{
		if (typeof e != "undefined")
		{
			xcoord = e.pageX + 15;
			ycoord = e.pageY + 15;
			
		} else if (typeof window.event != "undefined")
		{
			var scr = getPageScroll();
			xcoord = scr[0] + event.clientX;
			ycoord = scr[1] + event.clientY;
		}
		$("thumbnailDiv").style.left = xcoord;
		$("thumbnailDiv").style.top = ycoord;
	}
}

function stopDrag()
{
	
	dragID = null;
	$("thumbnailDiv").style.display = "none";
	$("thumbnailDiv").src = "images/loading.gif";
	document.body.onmousemove = null;
}
