	var Popup = {};
	
	
	/* Use the code below on any pgeMain.php to Activate Popup IE Fix, this is used to hide all select inputs when the popup is displayed.
	<!--[if lt IE 7.]>
		<script type="text/javascript">
			Popup.IEFix = 1;
		</script>
	<![endif]-->  
	 */
	
	Popup.IEFix = null;
	
	Popup.Storage = {
		Active : null,
		ContentById: null,
		OverlayOpacity: 0.6
	}
	
	Popup.Settings = {
		PrefixId : {
			BodyContent : 'body_content',
			OverBodyContent : 'OverPageContent',
			PopupId : 'PopupContainer',
			ContentId : 'PopupContent'
		},
		CssClass : {
			PopupClass : 'c_popup',
			ShowOverBody : 'OverPageContent',
			IESelectMenuClass : 'IESelectMenuHidden'
		} 
	}


	Popup.ShowContentById = function(ObjElementId) {
		var PopupContent = $(Popup.Settings.PrefixId.ContentId);
		var	ContentById = $(ObjElementId);
	
		if(ContentById){
			PopupContent.update(ContentById.innerHTML);
			//will also use ObjElementId as CSS class
			Popup.Show(ObjElementId);
			Popup.Storage.ContentById = ObjElementId;
			Element.update(ContentById, '');
			Popup.UpdatePosition();
		}else{
			return;
		}
	}
	
	Popup.ReplaceContent = function(){
		var PopupContent = $(Popup.Settings.PrefixId.ContentId);
		var	ContentById = $(Popup.Storage.ContentById);
		if(PopupContent && ContentById){
			ContentById.update(PopupContent.innerHTML);
			PopupContent.update('');
		}else{
			return;
		}
	}
	
	Popup.AjaxShowContent = function(ObjHTML, AltCss) {
		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		var PopupContent = $(Popup.Settings.PrefixId.ContentId);
		
		if (Popup.Storage.Active == null) {
			Popup.Show(AltCss);
		}
		
		if (AltCss) {
			PopupContainer.className = Popup.Settings.CssClass.PopupClass;
			PopupContainer.addClassName(AltCss);
		}
		if(ObjHTML){
			PopupContent.update(ObjHTML);
			Popup.UpdatePosition();
		}else{
			return;
		}
	}
	
	Popup.Show = function(styleClass){
		var OverBodyContainer = $(Popup.Settings.PrefixId.OverBodyContent);
		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		if (PopupContainer) {
			if (styleClass) {
				PopupContainer.className = Popup.Settings.CssClass.PopupClass;
				PopupContainer.addClassName(styleClass);
			}
			if (Popup.Storage.Active == null) {
				Popup.Storage.Active = 1;
				PopupContainer.style.display = 'block';
				if (OverBodyContainer) {
					OverBodyContainer.addClassName(Popup.Settings.CssClass.ShowOverBody);
					$(OverBodyContainer).setStyle({opacity: Popup.Storage.OverlayOpacity});
					BodyHeight = document.body.clientHeight;
					OverBodyContainer.style.height = BodyHeight + 'px';
					OverBodyContainer.style.display = 'block';
				}
				Popup.SelectInputEIFix(0);
			}
		}
		else {
			return;
		}
		
	}
	
	Popup.Hide = function(styleClass){
		var OverBodyContainer = $(Popup.Settings.PrefixId.OverBodyContent);
		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		if(PopupContainer){
			if (styleClass) {
				PopupContainer.removeClassName(styleClass);
			}
			PopupContainer.style.display = 'none';
			
			if (OverBodyContainer) {
				OverBodyContainer.removeClassName(Popup.Settings.CssClass.ShowOverBody);
				OverBodyContainer.style.display = 'none';
			}
			if (Popup.Storage.ContentById != null){
				Popup.ReplaceContent(Popup.Storage.ContentById);
			}
			Popup.SelectInputEIFix(1);
			Popup.Storage.Active = null;
			Popup.Storage.ContentById = null;
		}else{
			return;
		}
	}
	
	Popup.Loader = function()
	{
		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		var PopupContent = $(Popup.Settings.PrefixId.ContentId);
		if (Popup.Storage.Active == null) {
			Popup.Show();
		}
		
		if(PopupContent){
			PopupContent.update("<center><img src='/assets/images/icons/ajax-loader.gif'></center>");
			Popup.UpdatePosition();
		}
	}
	
	
	
	
	Popup.SelectInputEIFix = function(Visible){
		
		var SearchContainer = $('main');
		
		if (Popup.IEFix != null) {
			if (Visible == 0) { //add class to hide select inputs in ie_fix.css
				FoundElements = SearchContainer.descendants();
				FoundElements.each(function(childElem){
					if (childElem.tagName.toLowerCase() == "select") {
						childElem.addClassName(Popup.Settings.CssClass.IESelectMenuClass);
					}
					
				});
			}
			
			if (Visible == 1) {//remove class to hide select inputs in ie_fix.css
				FoundElements = SearchContainer.descendants();
				FoundElements.each(function(childElem){
					if (childElem.tagName.toLowerCase() == "select") {
						childElem.removeClassName(Popup.Settings.CssClass.IESelectMenuClass);
					}
				});
			}
		}else{
			return;
		}
		
	}
	
	
	Popup.UpdatePosition = function() {

		var PopupContainer = $(Popup.Settings.PrefixId.PopupId);
		
		var xPopup = Element.getWidth(PopupContainer);
		var yPopup = Element.getHeight(PopupContainer);
		
		aOffsetSizes = document.viewport.getScrollOffsets();
		
		var xScroll = aOffsetSizes[0];
		var yScroll = aOffsetSizes[1];
		
		var xSize = Popup.getWindowWidth();
		var ySize = Popup.getWindowHeight();
		
		var iPositionLeft = Math.round(xSize/2)+xScroll-Math.round(xPopup/2);
		var iPositionTop  = Math.round(ySize/2)+yScroll-Math.round(yPopup/2);
			
		PopupContainer.style.position = 'absolute';
		PopupContainer.style.top = iPositionTop+'px';
		PopupContainer.style.left = iPositionLeft+'px';
	}
	
	Popup.getWindowHeight = function() {

		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number') {
			windowHeight = window.innerHeight;
		}
		else {
			if (document.documentElement && document.documentElement.clientHeight) {
				windowHeight = document.documentElement.clientHeight;
			}
			else {
				if (document.body && document.body.clientHeight) {
					windowHeight = document.body.clientHeight;
				}
			}
		}
		return windowHeight; 
	}
	
	Popup.getWindowWidth = function() {

		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number') {
			windowWidth = window.innerWidth;
		}
		else {
			if (document.documentElement && document.documentElement.clientWidth) {
				windowWidth = document.documentElement.clientWidth;
			}
			else {
				if (document.body && document.body.clientWidth) {
					windowWidth = document.body.clientWidth;
				}
			}
		}
		return windowWidth;
	}

	

	
