//------------------------------------------------------
// VARS
//------------------------------------------------------

var popupWindowStatus = 0;

//------------------------------------------------------
// POPUP
//------------------------------------------------------

function loadPopupWindow(TUrl, TWidth, THeight)
{
	$(".TAjaxForm .Content").height(THeight);
	$(".TAjaxForm .Content").width(TWidth);
	
	centerPopupWindow();
	
	addPopupContent(TUrl);
	
	showPopupWindow();
}

function showPopupWindow()
{
	if(popupWindowStatus == 0)
	{
		$(".TAjaxForm .Bg").css({"opacity": "0.7"});
		$(".TAjaxForm .Bg").fadeIn("fast");
		
		$(".TAjaxForm .Content").fadeIn("fast");
		
		popupWindowStatus = 1;
	}
}

function centerPopupWindow()
{
	var windowWidth 	= document.documentElement.clientWidth;   
	var windowHeight 	= document.documentElement.clientHeight;   
	var popupHeight 	= $(".TAjaxForm .Content").height();   
	var popupWidth 		= $(".TAjaxForm .Content").width(); 
	
	$(".TAjaxForm .Content").css({"position": "absolute",   "top": windowHeight/2-popupHeight/2,   "left": windowWidth/2-popupWidth/2});
}

function addPopupContent(TUrl)
{
	var obj = new ajax();
	obj.open("GET", TUrl, true);
	obj.onreadystatechange = handlehttpResponse;
	obj.send(null);
		
	function handlehttpResponse() 
	{
		if (obj.readyState == 4) 
		{
			//document.getElementById('TAjaxForm').innerHTML = obj.responseText;
			$(".TAjaxForm .Content").html(obj.responseText);
		}
	}
}

function hidePopupWindow()
{
	if(popupWindowStatus == 1)
	{
		$(".TAjaxForm .Bg").fadeOut("fast");  
		$(".TAjaxForm .Content").fadeOut("fast"); 
		popupWindowStatus = 0;
	}
}