﻿var LightboxForm={
	_getFormIframe:function (name) {
		// TODO Config.Url
		var iframe=new IFrame({
			src:"FormGenerator/FormLoader.aspx?Form="+name,
			allowTransparency:true,
			frameBorder:0,
			scrolling:"no",
			onload:function () {
				var lastX,lastY;
				var func=function () {
					if (!this || !this.getDocument) return LightboxForm._adjustSizesInterval=$clear(LightboxForm._adjustSizesInterval);
					var x=this.getDocument().getScrollSize().x,
						y=this.getDocument().getScrollSize().y;
					iframe.setStyles({width:x,height:y});
					// re position the lightbox if iframe grows
					if (x!=lastX || y!=lastY) Lightbox.adjustPositions();
					lastX=x;
					lastY=y;
				}.bind(this); // this == iframe.contentWindow
				LightboxForm._adjustSizesInterval=func.periodical(500);
			}
		});
		return iframe;
	},
	show:function (name) {
		var lb=new SiteLightbox(LightboxForm._getFormIframe(name));
		lb.addEvent("onAfterHide",function () {
			LightboxForm._adjustSizesInterval=$clear(LightboxForm._adjustSizesInterval);
		});
		lb.show();
		
	}
};

