// POPUP functions --------------------------------------------------------------
var Popup = {
	CWind: [],
	no_of_children: 0,
	current_child: 0,
		
	createPopup: function (url, wname, popW, popH) {
			var	w = window.screen.width;
   			var	h = window.screen.height;
   			var scrollbar_display = ((popW > w) || (popH > h)) ? 1 : 0;
   		
   		// If scrollbars are to be displayed, increase width of window by standard V-Scrollbar width
   		if (scrollbar_display) { popW = popW + 16; }
   			
   		// If popup Height or Width is greater than screen resolution, then constrain it to the screen
   		if (popW > w) { popW = w; }
   		if (popH > h) { popH = (h - (28 + 24)); } // Adjust for taskbar/titlebar also (estimated heights)
   								
			var leftPos = ((w - popW)/2);
			var topPos = ((h - popH)/2);
					
		this.no_of_children++;
		this.current_child = this.no_of_children;
		
		this.CWind[this.current_child] = window.open('', wname + this.current_child, 'width=' + popW + ', height=' + popH + ' ,top=' + topPos + ', left=' + leftPos + 'resizable=0, scrollbars=' + scrollbar_display);
		
		// Fill in HTML & Styles				
		this.CWind[this.current_child].document.write('<html><head>');
		this.CWind[this.current_child].document.write('<style type="text\/css">');
		this.CWind[this.current_child].document.write('html { margin: 0px !important; padding: 0px !important; }');
		this.CWind[this.current_child].document.write('body { margin: 0px !important; padding: 0px !important; }');
		this.CWind[this.current_child].document.write('img { margin: 0px; border: none; }');
		this.CWind[this.current_child].document.write('<\/style>');
		
		// Add in no right click script
			var head_node = this.CWind[this.current_child].document.getElementsByTagName("head")[0];
			var script_node = this.CWind[this.current_child].document.createElement('script');
			
		script_node.type = 'text/javascript';
		script_node.src = '/javascript/norclick.js';
		head_node.appendChild(script_node);
		
		// Make IMG tag & Close out HTML
		this.CWind[this.current_child].document.write('<\/head><body>');
		this.CWind[this.current_child].document.write('<img src="' + url + '"><br><\/body><\/html>');
		
		if (window.focus) { this.CWind[this.current_child].focus(); }
	},
	
	closePopup: function (window_id) {
		if (this.CWind[window_id]) {
		
			if (window_id != this.no_of_children) {
				for (var ndx = window_id; ndx == this.no_of_children - 1; ndx++) {
						this.CWind[ndx] = this.CWind[ndx + 1];
				 		this.CWind[ndx].my_window_id = ndx;
				}

					this.CWind.splice(this.no_of_children, 1);
			} else {
					this.CWind.splice(this.no_of_children, 1);
			}
									
			this.no_of_children--;
		}			
	}
};