//Prototype Window Handling Extension
//requires Webtoolkit Base64

var Popup = Class.create({
	initialize: function(options) {
		this.options = {
			url: '',
			name: '',
			channelmode: 'no',
			directories: 'yes',
			fullscreen: 'no',
			height: '600',
			left: '',
			location: 'yes',
			menubar: 'yes',
			resizable: 'yes',
			scrollbars: 'yes',
			status: 'yes',
			titlebar: 'yes',
			toolbar: 'yes',
			top: '',
			width: '800',
			centered: 'yes'
		}
		Object.extend(this.options, options || {});
		if(this.options.top == '' && this.options.left == '' && this.options.centered == 'yes') {
			this.options.top = (document.viewport.getHeight() / 2) - (this.options.height / 2);
			this.options.left = (document.viewport.getWidth() / 2) - (this.options.width / 2);
		}
		this.param_string = 'channelmode='+this.options.channelmode+',directories='+this.options.directories+',fullscreen='+this.options.fullscreen+',height='+this.options.height+',left='+this.options.left+',location='+this.options.location+',menubar='+this.options.menubar+',resizable='+this.options.resizable+',scrollbars='+this.options.scrollbars+',status='+this.options.status+',titlebar='+this.options.titlebar+',toolbar='+this.options.toolbar+',top='+this.options.top+',width='+this.options.width;
		this.popupWindow = window.open(this.options.url, this.options.name, this.param_string);
		this.popupWindow.focus();
	},
	write: function(text, options) {
		this.options = {
			focus: false,
			base64: false
		}
		this.text = text;
		Object.extend(this.options, options || {});
		if(this.options.base64) {
			this.popupWindow.document.write(Base64.decode(this.text));
		} else {
			this.popupWindow.document.write(this.text);
		}
		if(this.options.focus) {
			this.popupWindow.focus();
		}
		this.popupWindow.document.close();
	},
	print: function() {
		this.popupWindow.print();
	},
	close: function() {
		this.popupWindow.close();
	}
});
//new Popup({url:'http://www.yahoo.com/'});