var popupPageMask					= null;
var responseContainer				= null;
var contentDiv						= null;
var loadingContent					= "<table border='0' width='100%' height='100%'><tr><td align='center' valign='center'><img src='/images/icons/ajaxLoadAnimation3.gif' border='0' width='32' height='32' /></td></tr></table>";
var handleDialogClose				= null;
var videoCommentDialogRedirect		= null;
var xx_dialog						= null;
var xx_dialogWidth					= 0;
var xx_dialogHeight					= 0;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doAjaxPopup(id, popupObj, url, width, height) {

	if (popupPageMask == null) {
	popupPageMask					= document.createElement('DIV');
	popupPageMask.style.display		= 'none';
	popupPageMask.id				= 'popupPageMask';
	document.body.appendChild(popupPageMask);
	popupPageMask.style.position	= 'absolute';
	}

// POSITION OUTER DIALOG
popupObj.style.display				= 'none';
popupObj.style.position				= 'absolute';
popupObj.id							= id;
document.body.appendChild(popupObj);

xx_dialogWidth						= width;
xx_dialogHeight						= height;
xx_dialog							= popupObj;	

showPageMask(true);

// POSITION INNER DIALOG
contentDiv 							= document.createElement('DIV'); /* Create tooltip content div */
contentDiv.id 						= id + "_content";
contentDiv.style.width				= width + 'px';
contentDiv.style.height				= height + 'px';
popupObj.appendChild(contentDiv);

// CENTER THE DIALOG WITHIN THE CURRENT WINDOW
centerDialogWithinView(width,height);

popupObj.style.display				= 'block';		// SHOW OUR DIALOG

showLoadingMessage();
getAjaxContent(url);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ajax_popup_handle_resize() {
	if (popupPageMask == null) {
	return;
	}
showPageMask(true);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showPageMask(showHide) {
var sw								= document.body.parentNode.scrollWidth;
var sh								= document.body.parentNode.scrollHeight;
	if (document.body.scrollHeight) {
	sh								= (document.body.scrollHeight > sh) ? document.body.scrollHeight : sh;
	sw								= (document.body.scrollWidth > sw) ? document.body.scrollWidth : sw;
	}
popupPageMask.style.width			= sw + 'px';
popupPageMask.style.height			= sh + 'px';
popupPageMask.style.left			= '0px';
popupPageMask.style.top				= '0px';
popupPageMask.style.display			= (showHide) ? 'block' : 'none';
//document.body.style.overflow		= (showHide) ? 'hidden' : 'auto';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function closeAjaxDialog() {
	if (handleDialogClose == null) {
	alert('Developer Error!  handleDialogClose callback undefined!');
	} else {
	eval(handleDialogClose)();
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function closeAjaxPopup(popupObj) {
popupObj.style.display				= 'none';
showPageMask(false);
document.body.removeChild(popupObj);
document.body.removeChild(popupPageMask);
popupPageMask						= null;
responseContainer					= null;
contentDiv							= null;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function centerDialogWithinView(width,height) {
var objWidth						= width;				// width of dialog
var objHeight						= height;				// height of dialog

var sw								= getViewportWidth();
var sh								= getViewportHeight();
var scrollX							= getScrollPositionX();
var scrollY							= getScrollPositionY();
	
var centerL							= (sw >> 1) - (objWidth >> 1);
centerL								= (centerL < 0) ? 0 : centerL;	
var centerT							= (sh >> 1) - (objHeight >> 1);
centerT								= (centerT < 0) ? 0 : centerT;

// ADD ANY SCROLLING INPUTS TO THE MIX TO CENTER IT WITHIN SCROLLED VIEW
centerL								+= scrollX;
centerT								+= scrollY;
centerT								-= 15;					// hardcoded visual adjustment since they eye really doesn't think it's centered vertically otherwise

xx_dialog.style.left				= centerL + 'px';
xx_dialog.style.top 				= centerT + 'px';
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showLoadingMessage() {
// DISPLAY A LOADING MESSAGE WHILE WE WAIT!
	if (responseContainer != null) {
	contentDiv.removeChild(responseContainer);
	responseContainer				= null;
	}
responseContainer					= document.createElement('DIV');
responseContainer.id				= 'popupLoadingMessage';
contentDiv.appendChild(responseContainer);
responseContainer.innerHTML			= "<div style='margin-top: 70px; height: 220px;'>" + loadingContent + "</div>";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getViewportWidth() {
var viewportwidth					= -1;	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
	viewportwidth 					= window.innerWidth;
	} // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
	viewportwidth					= document.documentElement.clientWidth;
	}// older versions of IE
	else {
	viewportwidth 					= document.getElementsByTagName('body')[0].clientWidth;
	}
return viewportwidth;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getViewportHeight() {
var viewportheight					= -1;	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerHeight != 'undefined') {
	viewportheight 					= window.innerHeight;
	} // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
	viewportheight					= document.documentElement.clientHeight;
	}// older versions of IE
	else {
	viewportheight 					= document.getElementsByTagName('body')[0].clientHeight;
	}
return viewportheight;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getScrollPositionX() {
var ox								= (document.body.parentNode.scrollLeft) ? document.body.parentNode.scrollLeft : -1;
	if (ox == -1) {
	ox								= (window.pageXOffset) ? window.pageXOffset : -1;
	}
return ox;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getScrollPositionY() {
var oy								= (document.body.parentNode.scrollTop) ? document.body.parentNode.scrollTop : -1;
	if (oy == -1) {
	oy								= (window.pageYOffset) ? window.pageYOffset : -1;
	}
return oy;
}
