//		eBay prototype extensions
////////////////////////////////////
//
//		extra prototype functions for community
//		author: Helmut Ebritsch
//	    date: 05.07.2006
//	    last modified: 05.07.2006
//
//

/**
 * (c)2007 I-D Media
 *
 * object  : popUpWindow
 * author  : $Author$
 * created : 01.02.2007
 * version : $Revision$
 *
 */

/**
* @author gfischer
*/

var openPopUpWindow = Class.create();

openPopUpWindow.prototype = {

 	contentWin:null,
	contentUrl:null,

	initialize:function() {
		Windows.closeAll();
		modalWindowHideDisturbingElements();
	},

	display:function(title,winUrl, width, height, windowId) {
		if (typeof windowId == 'undefined') {
			windowId = "id_" + new Date().getTime();
		}
		var url = winUrl;
		this.contentWin = new Window(windowId,
		/*className: "default",*/
		{	className: "ebay",
			width:width,
			height:height,
			minimizable: false,
			maximizable: false,
			resizable: false,
			showEffect:  Element.show,
			hideEffect:  Element.hide,
			title: title,
			url: url,
			draggable: false,
			wiredDrag: false,
			onload: function() {

				/**
				 * @author fhoffmann
				 *
				 * this is a fix, to show the login site not in the lightbox window.
				 * before an form submitted, an ajax call check on status = user is logged in
				 * if not, the loginwindow is showing in the parent window. after the login, the main
				 * site is showing and not the site from lightbox window. (this was a bug)
				 * at the moment only forms supported.
				 *
				 * @todo: check all lightboxes, how the forms are submitted. the right way must be the "form onsubmit"
				 * any helper function to submit a form onclich is not useful for this procedure
				 *
				 * the function is not in use yet !!
				 */
				return;

				if (!parent)
					return;

				// the fixed iframe name
				var id = windowId + "_content";

				var iframe = window.frames[id];
				var forms = Element.getElementsBySelector(iframe.document, "form");

				forms.each(function(form) {

					form.observe("submit", function(e) {

						if (SessionHelper.isEbayUserLoggedIn() == false) {
							Event.stop(e);

							var referer = encodeURIComponent(parent.location.pathname + parent.location.search);

							parent.location.replace("/forcedLogin.htm?targetUrl=" + referer);
						}
					});
				});
			}
		});
		this.contentWin.setDestroyOnClose();
		this.contentWin.setZIndex(1000);
		this.contentWin.showCenter(true);
		return windowId;
	},

	getWindow:function() {
		return this.contentWin;
	},

	setWindowUrl:function(winUrl) {
		this.contentUrl = cms_contextPath + winUrl;
	},

	removeWindow:function() {
		this.contentWin = null;
	}
};