function ModelWindow() {
	ModelWindow.ID = "_TGG_ModelWindow";

	// Flag for WidgetManager.Browser.Opera web browser
	ModelWindow.Browser = new Object();
	ModelWindow.Browser.IE = navigator.userAgent.toLowerCase().indexOf('msie') >= 0 ? true : false;
	ModelWindow.Browser.Opera = navigator.userAgent.toLowerCase().indexOf('opera') >= 0 ? true : false;
	ModelWindow.Browser.Mozilla = navigator.userAgent.toLowerCase().indexOf('firefox') >= 0 ? true : false;
	ModelWindow.Browser.Netscape = navigator.userAgent.toLowerCase().indexOf('netscape') >= 0 ? true : false;
	ModelWindow.Browser.Safari = (navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && navigator.userAgent.toLowerCase().indexOf('chrome') == -1) ? true : false;
	ModelWindow.Browser.Chrome = (navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && navigator.userAgent.toLowerCase().indexOf('chrome') >= 0) ? true : false;

	// Value for Model Window's height and width
	ModelWindow.Height = 200;
	ModelWindow.Width = 200;

	// Value for scroll height & width of the page
	ModelWindow.ScrollWidth = document.body.scrollWidth;
	ModelWindow.ScrollHeight = document.body.scrollHeight;

	ModelWindow.ScrollLeft = typeof (window.pageXOffset) == "number" ? window.pageXOffset : (document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft);
	ModelWindow.ScrollTop = typeof (window.pageYOffset) == "number" ? window.pageYOffset : (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop);

	// Value for browser height & width of the page
	ModelWindow.ClientWidth = (self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth));
	ModelWindow.ClientHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);

	// Model window layer
	ModelWindow.ModelWindowLayer = null;

	// IFrame window container
	ModelWindow.IFrameContainer = null;

	// Model window page url
	ModelWindow.Url = null;

	// Model window url frame
	ModelWindow.Frame = null;

	// Model window url frame
	ModelWindow.HasIFrame = true;

	// Model window url frame
	ModelWindow.IgnoreValidation = false;

	// Model window call back function
	ModelWindow.CallBackFunction = null;

	// Time to fade the window
	ModelWindow.TimeToFade = 600.0;

	// Loader Image Url
	ModelWindow.LoaderImage = null;
	ModelWindow.LoaderImageUrl = "http://www.thegoodguide.com/App_Themes/TGG_Theme/Img/ajax-loader.gif";

	// Set controls visibility
	ModelWindow.SetControlsVisibility = function(isVisible) {
		//Hide all drop down tags
		var dropDownCtrl = document.getElementsByTagName("SELECT");
		var nLength = dropDownCtrl.length;
		for (var nCnt = 0; nCnt < nLength; nCnt++) {
			dropDownCtrl[nCnt].style.visibility = isVisible == false ? "hidden" : "visible";
		}
		dropDownCtrl = null;

		//Hide all embed tags
		var embedCtrl = document.getElementsByTagName("EMBED");
		nLength = embedCtrl.length;
		for (var nCnt = 0; nCnt < nLength; nCnt++) {
			embedCtrl[nCnt].style.visibility = isVisible == false ? "hidden" : "visible";
		}
		embedCtrl = null;

		//Hide all drop down tags
		var objectCtrl = document.getElementsByTagName("OBJECT");
		nLength = objectCtrl.length;
		for (var nCnt = 0; nCnt < nLength; nCnt++) {
			objectCtrl[nCnt].style.visibility = isVisible == false ? "hidden" : "visible";
		}
		objectCtrl = null;
	};

	// Scroll class
	ModelWindow.Scroller = function() {
		// Initalise scroll class
		ModelWindow.Scroller.Init = function() {
			if (document.layers)
			{ ModelWindow.IFrameContainer.style = ModelWindow.IFrameContainer; }
			ModelWindow.IFrameContainer.X = ModelWindow.StartX;
			ModelWindow.IFrameContainer.Y = ModelWindow.StartY;
			ModelWindow.Scroller.PersistPosition();
			new ModelWindow.Scroller.Layer();
			ModelWindow.Scroller.Layer.Refresh();
		};

		// Validation IE compact window validation
		ModelWindow.Scroller.IECompact = function() {
			return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
		};

		// Set position of IFrame container window
		ModelWindow.Scroller.SetPosition = function(x, y) {
			ModelWindow.IFrameContainer.style.top = ((ModelWindow.ClientHeight - (ModelWindow.Height + 100)) / 1) + "px";
			ModelWindow.IFrameContainer.style.left = x + "px";
		};

		// Persist position of IFrame container window
		ModelWindow.Scroller.PersistPosition = function() {
			if (ModelWindow.Browser.IE) {
				if (ModelWindow.IFrameContainer)
				{ ModelWindow.IFrameContainer.Y += (ModelWindow.Scroller.IECompact().scrollTop + ModelWindow.StartY - ModelWindow.IFrameContainer.Y) / 8; }
			}
			else {
				if (ModelWindow.IFrameContainer)
				{ ModelWindow.IFrameContainer.Y += (ModelWindow.Scroller.IECompact().scrollTop + ModelWindow.StartY - ModelWindow.IFrameContainer.Y) / 8; }
			}

			if (ModelWindow.IFrameContainer) {
				ModelWindow.Scroller.SetPosition(ModelWindow.IFrameContainer.X, ModelWindow.IFrameContainer.Y);
			}
		};

		// Refresh height of opaque layer
		ModelWindow.Scroller.Layer = function() {
			ModelWindow.Scroller.Layer.Refresh = function() {
				// Value for scroll height & width of the page
				ModelWindow.ScrollWidth = document.body ? document.body.scrollWidth : 0;
				ModelWindow.ScrollHeight = document.body ? document.body.scrollHeight : 0;

				ModelWindow.ScrollLeft = typeof (window.pageXOffset) == "number" ? window.pageXOffset : (document.body ? (document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft) : 0);
				ModelWindow.ScrollTop = typeof (window.pageYOffset) == "number" ? window.pageYOffset : (document.body ? (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) : 0);

				// Value for browser height & width of the page
				ModelWindow.ClientWidth = self.innerWidth || (document.documentElement.clientWidth || (document.body ? document.body.clientWidth : 0));
				ModelWindow.ClientHeight = self.innerHeight || (document.documentElement.clientHeight || (document.body ? document.body.clientHeight : 0));
				ModelWindow.ModelWindowLayer.style.width = (ModelWindow.ScrollHeight > ModelWindow.ClientHeight ? (ModelWindow.ClientWidth - (ModelWindow.Browser.IE ? 0 : 17)) : ModelWindow.ClientWidth) + "px";
				ModelWindow.ModelWindowLayer.style.height = (ModelWindow.ScrollHeight > ModelWindow.ClientHeight ? ModelWindow.ScrollHeight : ModelWindow.ClientHeight) + "px";
			};
		};
	};

	// Render Model window
	ModelWindow.Render = function() {
		try {
			// Hide all drop down tags
			ModelWindow.SetControlsVisibility(false);

			// Value for layer window's start X and Y position
			ModelWindow.StartX = (ModelWindow.ClientWidth - ModelWindow.Width) / 2 - 20;
			ModelWindow.StartY = 30;

			// Create opaque layer
			ModelWindow.ModelWindowLayer = document.createElement("DIV");
			ModelWindow.ModelWindowLayer.style.cssText = "display:block; position:fixed; background:#F0F0F0; opacity:0; filter:alpha(opacity=0); left:0px; top:0px";
			ModelWindow.ModelWindowLayer.style.zIndex = 100001;
			ModelWindow.ModelWindowLayer.style.width = (ModelWindow.ScrollHeight > ModelWindow.ClientHeight ? (ModelWindow.ClientWidth - (ModelWindow.Browser.IE ? 0 : 17)) : ModelWindow.ClientWidth) + "px";
			ModelWindow.ModelWindowLayer.style.height = (ModelWindow.ScrollHeight > ModelWindow.ClientHeight ? ModelWindow.ScrollHeight : ModelWindow.ClientHeight) + "px";
			document.body.appendChild(ModelWindow.ModelWindowLayer);

			// Fadein opaque layer
			ModelWindow.Fade();

			// Check where contains iframe or not
			if (ModelWindow.HasIFrame) {
				ModelWindow.IFrameContainer = document.createElement("DIV");
				ModelWindow.IFrameContainer.className = "DvMnPopup";
				ModelWindow.IFrameContainer.style.cssText = "display:block; position:fixed; opacity:1.0; width:" + ModelWindow.Width + "px;";
				ModelWindow.IFrameContainer.style.zIndex = 100002;
				document.body.appendChild(ModelWindow.IFrameContainer);

				// Set loader image
				ModelWindow.LoaderImage = document.createElement("IMG");
				ModelWindow.LoaderImage.setAttribute("src", ModelWindow.LoaderImageUrl);
				ModelWindow.LoaderImage.setAttribute("style", "border:0px; padding-top:10px;");

				var dvPopHeader = document.createElement("DIV");
				dvPopHeader.className = "DvPopHeader";
				dvPopHeader.appendChild(ModelWindow.LoaderImage);
				ModelWindow.IFrameContainer.appendChild(dvPopHeader);

				var dvLft1401 = document.createElement("DIV");
				dvLft1401.className = "DvLft1401";
				dvPopHeader.appendChild(dvLft1401);

				var PopUpClose = document.createElement("DIV");
				PopUpClose.className = "PopUpClose";
				dvPopHeader.appendChild(PopUpClose);

				var dvCloseBtn = document.createElement("DIV");
				PopUpClose.appendChild(dvCloseBtn);

				var lnkCloseBtn = document.createElement("A");
				lnkCloseBtn.className = "CloseBtn";
				lnkCloseBtn.style.cursor = "pointer";
				lnkCloseBtn.setAttribute("title", "Close");
				lnkCloseBtn.onclick = ModelWindow.Close;
				dvCloseBtn.appendChild(lnkCloseBtn);

////				var newLine = document.createElement("BR");
////				newLine.setAttribute("clear", "all");
////				dvCloseBtn.appendChild(newLine);

////				newLine = document.createElement("BR");
////				newLine.setAttribute("clear", "all");
////				dvPopHeader.appendChild(newLine);

////				var grayLineTop3 = document.createElement("DIV");
////				grayLineTop3.className = "GrayLineTop3";
////				dvPopHeader.appendChild(grayLineTop3);

				var dvPopMiddle = document.createElement("DIV");
				dvPopMiddle.className = "DvPopMiddle";
				ModelWindow.IFrameContainer.appendChild(dvPopMiddle);

				ModelWindow.Frame = document.createElement("IFRAME");
				ModelWindow.Frame.className = "PopupFrame";
				ModelWindow.Frame.frameBorder = "no";
				ModelWindow.Frame.scrolling = "auto";
				ModelWindow.Frame.height = ModelWindow.Height + (ModelWindow.Browser.IE ? 35 : 40) + "px";
				//ModelWindow.Frame.height = "500px";
				ModelWindow.Frame.style.display = "none";
				dvPopMiddle.appendChild(ModelWindow.Frame);
				ModelWindow.Frame.setAttribute("src", ModelWindow.Url);
				if (ModelWindow.Browser.IE)
					ModelWindow.Frame.onreadystatechange = function() { if (ModelWindow.Frame.readyState == "complete") ModelWindow.FrameOnLoad(); }
				else
					ModelWindow.Frame.onload = ModelWindow.FrameOnLoad;
			}
			else {
				var loaderSpan = document.createElement("span");
				loaderSpan.innerHTML = "<br/><b><font face='arial' size='2' color='black'>Please wait while loading... </font></b>";

				ModelWindow.IFrameContainer = document.createElement("DIV");
				ModelWindow.IFrameContainer.style.cssText = "display:block; position:fixed; opacity:1.0; width:" + LayerLoader.Width + "px;";
				ModelWindow.IFrameContainer.appendChild(loaderImg);
				ModelWindow.IFrameContainer.appendChild(loaderSpan);
				ModelWindow.IFrameContainer.style.zIndex = 100002;
				document.body.appendChild(ModelWindow.IFrameContainer);

				loaderImg = null;
				loaderSpan = null;
			}

			// Initialise scroller class
			new ModelWindow.Scroller();
			ModelWindow.Scroller.Init();
		}
		catch (e)
		{ }
		finally {
			dvPopHeader = null;
			dvLft1401 = null;
			dvLogo2 = null;
			PopUpClose = null;
			dvCloseBtn = null;
			lnkCloseBtn = null;
			newLine = null;
			grayLineTop3 = null;
			dvPopMiddle = null;
		}
	};

	ModelWindow.FrameOnLoad = function() {
		if (ModelWindow.LoaderImage)
			ModelWindow.LoaderImage.style.display = "none";
		if (ModelWindow.Frame)
			ModelWindow.Frame.style.display = "";
	};

	// Show model window
	ModelWindow.Show = function() {
		ModelWindow.ModelWindowLayer.style.display = "";
	};

	// Hide model window
	ModelWindow.Hide = function() {
		ModelWindow.ModelWindowLayer.style.display = "none";
	};

	ModelWindow.Close = function() {
		// Fadeout opaque layer
		ModelWindow.Fade();
	};

	// Close model window
	ModelWindow.AnimateFadeClose = function() {
		
		// Destroy model window
		ModelWindow.Destroy();

		if (ModelWindow.CallBackFunction)
		{ ModelWindow.CallBackFunction(); }

		ModelWindow.CallBackFunction = null;
	};

	ModelWindow.Fade = function() {
		if (!ModelWindow.ModelWindowLayer)
			return;

		if (!ModelWindow.ModelWindowLayer.FadeState)
			ModelWindow.ModelWindowLayer.FadeState = -2;

		if (ModelWindow.ModelWindowLayer.FadeState == 1 || ModelWindow.ModelWindowLayer.FadeState == -1) {
			ModelWindow.ModelWindowLayer.FadeState = ModelWindow.ModelWindowLayer.FadeState == 1 ? -1 : 1;
			ModelWindow.ModelWindowLayer.FadeTimeLeft = ModelWindow.TimeToFade - ModelWindow.ModelWindowLayer.FadeTimeLeft;
		} else {
			ModelWindow.ModelWindowLayer.FadeState = ModelWindow.ModelWindowLayer.FadeState == 2 ? -1 : 1;
			ModelWindow.ModelWindowLayer.FadeTimeLeft = ModelWindow.TimeToFade;
			setTimeout("ModelWindow.AnimateFade(" + new Date().getTime() + ")", 10);
		}
	};

	ModelWindow.AnimateFade = function(lastTick) {
		if (!ModelWindow.ModelWindowLayer)
			return;

		var curTick = new Date().getTime();
		var elapsedTicks = curTick - lastTick;
		if (ModelWindow.ModelWindowLayer.FadeTimeLeft <= elapsedTicks) {
			ModelWindow.ModelWindowLayer.style.opacity = ModelWindow.ModelWindowLayer.FadeState == 1 ? '0.7' : '0';
			ModelWindow.ModelWindowLayer.style.filter = 'alpha(opacity = ' + (ModelWindow.ModelWindowLayer.FadeState == 1 ? '70' : '0') + ')';
			ModelWindow.ModelWindowLayer.FadeState = ModelWindow.ModelWindowLayer.FadeState == 1 ? 2 : -2;
			if (parseFloat(ModelWindow.ModelWindowLayer.style.opacity) < 0.7)
				ModelWindow.AnimateFadeClose();
			return;
		}

		ModelWindow.ModelWindowLayer.FadeTimeLeft -= elapsedTicks;
		var newOpVal = ModelWindow.ModelWindowLayer.FadeTimeLeft / ModelWindow.TimeToFade;
		if (ModelWindow.ModelWindowLayer.FadeState == 1)
			newOpVal = 0.7 - newOpVal;
		ModelWindow.ModelWindowLayer.style.opacity = newOpVal;
		ModelWindow.ModelWindowLayer.style.filter = 'alpha(opacity = ' + (newOpVal * 70) + ')';
		setTimeout("ModelWindow.AnimateFade(" + curTick + ")", 10);
	};

	// Destroy model window
	ModelWindow.Destroy = function() {
		// Show all drop down tags
		ModelWindow.SetControlsVisibility(true);

		// Remove all objects		
		document.body.removeChild(ModelWindow.IFrameContainer);
		document.body.removeChild(ModelWindow.ModelWindowLayer);

		// Nullify all variables
		ModelWindow.ID = null;
		ModelWindow.StartX = null;
		ModelWindow.StartY = null;
		ModelWindow.Height = null;
		ModelWindow.Width = null;
		ModelWindow.ScrollHeight = null;
		ModelWindow.ScrollWidth = null;
		ModelWindow.ClientHeight = null;
		ModelWindow.ClientWidth = null;
		ModelWindow.ModelWindowLayer = null;
		ModelWindow.IFrameContainer = null;
		ModelWindow.Url = null;
		ModelWindow.Frame = null;
	};
}
