// JavaScript Document

var x,y;
var pick = false;
$(document).mousemove(function(e)
{
	x = e.pageX;
	y = e.pageY;
}); 

function Popup(type,url,title,height,width,closeEventName)
{
	var titleBg;
	var contentBg;
	
	title = (title==""?"&nbsp;":title);
	
	//Create popup background
	$("body").css("overflow","hidden");
	html = "<div id='popupBg' style='position:absolute;left:0px;top:"+$(window).scrollTop()+"px;width:"+$(window).width()+"px;height:"+$(window).height()+"px;z-index:998'></div>";
	$("body").append(html);
	//-----------------------

	//Create popup HTML
	html = "<div id='popup'>";
	//html += "<div id='title'><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td>" + title;
	//html += "</td>"
	//html += "<td width='1%'><div class='btnClosePopup' title='Close'>X</div></td>";
	//html += "</tr></table></div>";
	html += "<div id='content'></div>";
	html += "</div>";
	
	//Create popup div in DOM
	$("body").append(html);
	//-----------------------
	
	if(type.toLowerCase() == "iframe")
	{
		$("#popup #content").html("<iframe name='ifrm_popup' id='ifrm_popup' scrolling='auto' width='"+width+"' height='"+(height)+"' src='"+url+"' frameborder='0'></iframe>");
	}
	else
	{
		if(type.toLowerCase() == "ajax")
		{
			$.ajax(
			{
				url: url,
				async: true,
				cache: true,
				error: function(){alert("Error in loading ajax popup content")},
				beforeSend: function(){},
				success: function(responseText)
				{
					$("#popup #content").html(responseText);
				},
				complete: function(){}
			});	
		}
	}
	//Set height/width and position of the popup
	$("#popup").css("height",height + "px");
	$("#popup").css("width",width + "px");
	
	$("#popup").css("left",($(document).width()/2) - ((width/2)) + "px");
	$("#popup").css("top",$(window).scrollTop()+50);
	//---------------------------
	
	//Add Drag Effect to Popup
	/*$("#popup").draggable(
	{
		containment: "#popupBg",
		scrollSensitivity: 0,
		revert: false,
		cursor: "default"
	});*/
	//------------------------
	
	//Close Popup
	$("#popup #title .btnClosePopup").click(function()
	{
		top.closePopup(closeEventName);
	});
	//-----------
}

function closePopup(closeEventName)
{ 	
	$("#popupBg").remove();
	$("#popup").remove();
	if(closeEventName)
	{
		window[closeEventName]();
	}
}
