//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup 
function loadPopup(idToShow)
{  
	//loads popup only if it is disabled  
	if(popupStatus==0)
	{  
		jQuery("#response").html(""); 
		jQuery("#popUpFormBackground,#page").css({  
		"opacity": "0.6",
		"filter": "alpha(opacity=60)"
		});  		
		jQuery("#popUpFormBackground").fadeIn("slow");  
		jQuery(idToShow).fadeIn("slow");	
		
		popupStatus = 1;  
	}  
}  


//disabling popup 
function disablePopup(idToDisable)
{	
	//check for dynamic iframe and remove if exists
	jQuery("#dynamicIFrame").remove();
	jQuery("#popUpFormBackground").fadeOut("slow");  
	jQuery(idToDisable).fadeOut("slow");  
	jQuery("#page").css({"opacity": "1.0","filter": "alpha(opacity=100)"});
	popupStatus = 0;	  
}  


//center popup
function centerPopup(idToCenter)
{  
	var winSize = getWindowSize();
	var scrollAmt = getScrollXY();
		
	//request data for centering  
	var windowWidth = screen.width;  
	var windowHeight = screen.height;  
	var popupHeight = jQuery(idToCenter).height();  
	var popupWidth = jQuery(idToCenter).width();  
	//centering  
	jQuery(idToCenter).css({  
	"position": "absolute",  
	"top": (winSize[1]/2)+(scrollAmt[1]-(popupHeight/2)),  
	"left": (winSize[0]/2)+(scrollAmt[0]-(popupWidth/2))  
	});  
	//only need force for IE6  
	  
	jQuery("#popUpFormBackground").css({  
	"height": windowHeight  
	}); 		  
}  


//update div layer with an iframe and passed in html content
function createFrame(popUpId,contentContainerId,title,htmlContent,width,height,scroll)
{
	var htmlContent = Base64.decode(htmlContent);	
	var mainContainer = document.getElementById(popUpId);
	var mainTitle = document.getElementById("popUpGenericTitle");	
	var contentContainer = document.getElementById(contentContainerId);	
	
	if (mainContainer)
		mainContainer.style.width = width + "px";
	
	if (mainTitle)
		mainTitle.innerHTML = title;
		
	if (contentContainer)
	{ 		
		var myFrame = document.createElement("iframe");
		myFrame.id = "dynamicIFrame";
		myFrame.width = width;
		myFrame.height = height;
		myFrame.frameBorder = 0;
		myFrame.scrolling = scroll;
		
		contentContainer.style.width = width + "px";
		contentContainer.style.height = height + "px";
		contentContainer.appendChild(myFrame);
		
		var doc = myFrame.document;
		if(myFrame.contentDocument)
		    // Firefox, Opera
			doc = myFrame.contentDocument;
		else if(myFrame.contentWindow)
			// Internet Explorer
			doc = myFrame.contentWindow.document;			 
					
		doc.open();
		doc.write(htmlContent);
		doc.close();			
		
		hideSelect();
		centerPopup('#'+popUpId);
		loadPopup('#'+popUpId);			
	}
}