/*site zIndex composition

60-70		= bubble
80			= Alpha black layer
90			= tools (cjack, etc)
94, 95, 96	= clownie (goodie, card, goodie)
100			= the header
105			= help
110			= popup windows

*/

	var g_ar_viewer = new Array();
	var gWidthBody = 1004;
	function openViewer(width, height, url, id, title,  extra_html){

		SetAlphaPanel(50);
		showSelect('hidden');

		if(extra_html == undefined)
			extra_html = '';


		var d =  gById(id);

		if(d == null){

			d = document.createElement("DIV");
			d.style.cssText = 'position:absolute;';
			d.id = id;
			d.style.zIndex = 110;

		}


		d.style.left = (WindowSize('width')-width)/2 + 'px'; //todo, half screen

		var top = (((WindowSize('height')-height)/2)+WindowScroll('top'));

		if(top < document.documentElement.scrollTop)
			d.style.top = WindowScroll('top') + 'px';
		else
			d.style.top  = top + 'px';

		d.style.border = '1px black solid';

		d.innerHTML =	'<table class="tableList" style="width:' + width + 'px;">' +
							'<tr class="head2">' +
								'<td style="text-align:left;">' + title + '</td>' +
								'<td style="text-align:right;"><a href="javascript:closeViewer(\'' + id + '\');">X</a></td>' +
							'</tr>' +
						'</table>' +
						'<iframe frameborder="0" style="width:' + width + 'px;height:' + height + 'px;" src=' + url +' ></iframe>' + 	
						extra_html;		

		document.body.appendChild(d);

		if( !g_ar_viewer.ar_find(id))
			g_ar_viewer[g_ar_viewer.length] = id;

	}



	function openViewer2(width, height, url, id, title,  extra_html){

		SetAlphaPanel(50);
		showSelect('hidden');

		if(extra_html == undefined)
			extra_html = '';

		var d =  gById(id);

		if(d == null){

			d 					= document.createElement("DIV");
			d.style.cssText 	= 'position:absolute;';
			d.id 				= id;
			d.style.zIndex 		= 110;

		}

		//add 40 to width, (padding of the window 
		//add 50 to height in top position calculation (because of the window title)
		
		
		width+=40;

		d.style.left = (WindowSize('width')-width)/2 + 'px'; //todo, half screen

		var top = (((WindowSize('height')-(height+50))/2)+WindowScroll('top'));

		if(top < document.documentElement.scrollTop)
			d.style.top = WindowScroll('top') + 'px';
		else
			d.style.top  = top + 'px';

		(extra_html != '') ? extra_height = 40 : extra_height = 0; //ok, this is reallly nasty patched
		

		d.style.width	= width  + 24 + 'px';	

		d.innerHTML =	'<div class="sidebox" style="width:' + (width)+ 'px;">' +
		'<div class="boxhead"><div class="boxhead2"><h2>' + _L(title) +
		'<div style="float:right;"  onclick="javascript:closeViewer(\'' + id + '\');" class="x_close">x</div>' + 
		'</h2></div></div>'  +
		'<div class="boxbody"><div class="boxbody2" style="height:' + (height+extra_height) + 'px;">' +
		'<iframe frameborder="0" style="width:' + (width-40) + 'px;height:' + height + 'px;" src=' + url +' ></iframe>' + extra_html +
		'</div></div></div>';


		document.body.appendChild(d);

		if( !g_ar_viewer.ar_find(id))
			g_ar_viewer[g_ar_viewer.length] = id;

	}




	function closeViewer(id, bRemoveObj){

		if(bRemoveObj == undefined)
			bRemoveObj = true;
		
		if(!g_ar_viewer.ar_find(id))
			return;
			
		g_ar_viewer.ar_remove(id);

		if(g_ar_viewer.length==0){
			SetAlphaPanel(0);
			showSelect('visible');
		}

		if(bRemoveObj == true)
			document.body.removeChild(gById(id));

	}


	