var pWindow = {
	windows: {},
	openWindow: function(name, params) {
		var defaultParams = {
			className:			'softhis',
			title:				'',
			width:				300,
			height:				200,
			resizable: 			false,
			minimizable: 		false,
			maximizable:		false,
			destroyOnClose: 	true, 
			recenterAuto:		true,
			showEffect: 		Effect.Appear,
			hideEffect: 		Effect.Fade,
			showEffectOptions:	{duration: 0.2},
			hideEffectOptions:	{duration: 0.2},
			zIndex:				20,
			ajaxUrl: 			null,
			ajaxPost:				null
			
		};
		Object.extend(defaultParams, params || {});	
		if (this.windows[name]!=null) {
			
			
			this.windows[name].destroy();
			delete this.windows[name];
			
			//console.debug('Window '+name+' already opened');
			//return false;
		}
		
		
		//console.debug(defaultParams);
		this.windows[name] = new Window(defaultParams);
		
		onSuccessFunction = function(json,transport) {
		    	results = transport.responseText.split('|**|');
			 	this.windows[name].getContent().update(results[0]);
				if(results[1])eval(results[1]);
				this.windows[name].showCenter();
		};
		
		if (defaultParams.ajaxUrl!=null) {
			softAjax.getView(defaultParams.ajaxUrl, defaultParams.ajaxUrl, {
				lock: true,
				query: defaultParams.ajaxPost,
				onSuccess : onSuccessFunction.bind(this)
			});
		 }
		
		this.windows[name].windowName = name;
		this.windows[name].setZIndex(defaultParams.zIndex);
		onCloseFunc = function(win) {
			//console.debug(this);
			delete this.windows[name];
			return true;
		}
		this.windows[name].setCloseCallback(onCloseFunc.bind(this));
		if(!this.ajaxUrl)this.windows[name].showCenter();
	}
}

//pWindow.openWindow('test');
