
function positioningPopup(popupId) {

	var $popup = jQuery.noConflict();

	if (popupId != null && popupId != undefined) {
		var innerTable = findPopupInnerTable(popupId);
		positioningPopupWithInnerTable(popupId, innerTable);
	}
}

function positioningPopupWithInnerTable(popupId, innerTable) {

	var $popup = jQuery.noConflict();

	if (innerTable != null && innerTable != undefined) {
		
		var popupHeight = parseInt(innerTable.css('height'));
		var popupWidth = parseInt(innerTable.css('width'));
		var windowHeight = $popup(window).height();
		var windowWidth = $popup(window).width();

		var scrollTop = $popup(window).scrollTop();
		var scrollLeft = $popup(window).scrollLeft();
		
		var left = ((windowWidth / 2) - (popupWidth / 2)) + scrollLeft + "px";
		
		var divTop;

		if(windowHeight < popupHeight)
			divTop = (scrollTop + 15) +  "px";
		else
			divTop = Math.abs((windowHeight - popupHeight) / 2) + scrollTop	+ "px";

		var popupDiv = $popup('.rich-mp-container');

		if (popupDiv != null && popupDiv != undefined) {
			popupDiv.css( {	'top' : divTop,	'position' : 'absolute', 'left' : left	});
		}
	}
}

function resizePopup(popupId, newWidth, newHeight) {

	var $popup = jQuery.noConflict();

	if (popupId != null && popupId != undefined) {

		var innerTable = findPopupInnerTable(popupId);
		
		if (innerTable != null && innerTable != undefined) {

			var popupDivModalContent = innerTable.find('div .modalContent');

			if (popupDivModalContent != null && popupDivModalContent != undefined) {
				if (newWidth != null)
					popupDivModalContent.css( {	'width' : newWidth });
				if (newHeight != null)
					popupDivModalContent.css( { 'height' : newHeight });
			}
			
			positioningPopupWithInnerTable(popupId, innerTable);
		}
	}
}

function findPopupInnerTable(popupId) {
	
	var $popup = jQuery.noConflict();
	
	if (popupId == null || popupId == undefined) {
		return null;
	}
	
	return $popup("div[id$=" + popupId + "ShadowDiv]");
}

