// Requires script.aculo.us & Prototype Libraries

/*Object.extend(String.prototype, {
	  
		isAlphanumeric : function (){ 
			return this.match(/^([a-zA-Z0-9]+)$/);
		},
		isEmail : function (){ 
			var rx = new RegExp(/^([a-zA-Z0-9._+-]+)@([a-zA-Z0-9.-]+)\.[a-zA-Z]{2,4}$/);
			var matches = rx.exec(this); 
			return (matches != null && this == matches[0]);	
		},
		isURL : function(){ 
			var rx = new RegExp("((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp|magnet|ed2k|svn)://)?([\\w-]+\\.)+[\\w-]+(/[\\w-\\+ ./?%:&=#\\[\\]]*)?"); 
			var matches = rx.exec(this); 
			return (matches != null && this == matches[0]);	
		}
})*/

var Window = Class.create({
	initialize : function(content, options){
		if( Object.isString(content) ){
			this.content = content;
		}
		this.options = Object.extend({
			effect : '',
			title : '',
			classname:'window'
		}, options || { });
		
		
		this.build();
	},
	build:function(){
		var d = document.body.getDimensions();
		
		this.overlay = $( document.createElement('div') );
		this.overlay.setStyle({
			position : 'absolute',
			height   : d.height+'px',
			width    : d.width+'px',
			top      : '0px',
			left     : '0px',
			opacity  : '0.8',
			backgroundColor : '#fff',
			display : 'none',
			zIndex : '99998'
		})
		document.body.appendChild( this.overlay );
		
		var WindowPane, WindowBody, markup;
		
		/*Top/Title Markup*/
		markup = (this.options.title) ? '<div class="top alt">' : '<div class="top">';
		markup += '<div class="ltop"></div><div class="rtop"></div>'
		markup += (this.options.title) ? '<h4>'+this.options.title+'</h4></div>' : '</div>';
		
		/*Body Markup*/
		markup += '<div class="body"><div class="lbody"></div><div class="rbody" ></div><div class="bodyContent"></div>'
		markup += '<div class="controls"><input type="button" class="button ok" value="Ok" /></div></div>';
		
		/*Footer Markup*/
		markup += '<div class="bottom"><div class="lbottom"></div><div class="rbottom"></div></div>'
		
		WindowPane = $( document.createElement('div') );
		WindowPane.addClassName(this.options.classname);
		WindowPane.update( markup );
		WindowPane.hide();
		
		document.body.appendChild( WindowPane );

		var ok_button = $( WindowPane.select(".button.ok")[0] );
		ok_button.observe('click', this.close.bindAsEventListener(this) );

		WindowBody = $( WindowPane.select(".bodyContent")[0] );
		WindowBody.update( this.content );
		

		this.WindowPane = WindowPane;
		this.overlay.show();
		WindowPane.show();

	},
	close:function(){
		var WindowPane = this.WindowPane;
		this.overlay.remove();
		WindowPane.fade({afterFinish:function(){ WindowPane.remove() } });

	}
});


