// (c) Alex Bokov 2009


function open_window(imgfile,id) 
{
	xposition = (screen.width - 800) / 2;	// default initial position
	yposition = (screen.height - 600) / 2;	// assuming image size 800x600

	args = "resizable=yes,width=800,height=600,screenx="+xposition+",screeny="+yposition+",left="+xposition+",top="+yposition;
	win=window.open('','',args);

	win.document.writeln( "<html>" );
	win.document.writeln( "<head>" );
	win.document.writeln( "	<script type=text/javascript>	" );
	win.document.writeln( "		var	width	= 800;	" );
	win.document.writeln( "		var	height	= 600;	" );
	win.document.writeln( "	function resize()		" );
	win.document.writeln( "	{				" );
	win.document.writeln( "		setTimeout('resize();',100);	" );
	win.document.writeln( "		if ( x.width != document.body.clientWidth || x.height != document.body.clientHeight )	" );
	win.document.writeln( "		{											" );
	win.document.writeln( "			width = width + ( x.width - document.body.clientWidth );			" );
	win.document.writeln( "			height = height + ( x.height  - document.body.clientHeight  );			" );
	win.document.writeln( "			window.resizeTo( width, height );						" ); 
	win.document.writeln( "		}											" );
	win.document.writeln( "		window.moveTo((screen.width-width)/2,(screen.height-height)/2);				" );					
	win.document.writeln( "	}				" );
	win.document.writeln( "	</script>			" );
	win.document.writeln( "</head>" );
	win.document.writeln( "<body bgcolor=#666666 topmargin=0 leftmargin=0 >" );
	win.document.writeln( "	<img id='x' name='x' src='"+imgfile+"' onload='javascript:resize();'  >" );
	win.document.writeln( "</body>" ); 
	win.document.writeln( "</html>" ); 

	dummyimage = new Image();
	dummyimage.src = "openwindow.php?id="+id;
}

function open_window_large(imgfile) 
{
	open_window( imgfile.replace( '.jpg', '-large.jpg' ) );
}

function leadingzero( number )
{
	result = number;
	if ( result.length < 2 ) result = '0'+result;
	if ( result.length < 3 ) result = '0'+result;
	if ( result.length < 4 ) result = '0'+result;
	if ( result.length < 5 ) result = '0'+result;

	alert( result );

	return result;
}

function chim(name,image) { document.images[name].src = image; }

function preloadImages() {
	var d=document; 
	if(d.images){ 
		if(!d.p) d.p=new Array();
		var i,j=d.p.length,a=preloadImages.arguments; 
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}
	}
}

function preload_buttons() {
	preloadImages('button-about-x.gif', 'button-art-x.gif','button-art-art.gif','button-art-art-x.gif','button-art-gra.gif','button-art-gra-x.gif',
		'button-art-maps.gif','button-art-maps-x.gif','button-books-x.gif','button-bo-bo.gif','button-bo-bo-x.gif','button-bo-si.gif','button-bo-si-x.gif',
		'button-china-for.gif','button-china-for-x.gif','button-china-rus.gif','button-china-rus-x.gif',
		'button-collect-coins.gif','button-collect-coins-x.gif','button-collect-easter.gif','button-collect-easter-x.gif',
		'button-collect-other.gif','button-collect-other-x.gif','button-collect-toys.gif','button-collect-toys-x.gif','button-consult-x.gif',
		'button-east-x.gif','button-furn-furn.gif','button-furn-furn-x.gif','button-furn-int.gif','button-furn-int-x.gif',
		'button-icons-x.gif','button-order-x.gif','button-others-x.gif','button-ot-ot.gif','button-ot-ot-x.gif','button-ot-sam.gif','button-ot-sam-x.gif',
		'button-ot-tex.gif','button-ot-tex-x.gif','button-ot-tech.gif','button-ot-tech-x.gif','button-ot-glass.gif','button-ot-glass-x.gif',
		'button-presents-x.gif','button-scu-x.gif','button-scu-bro.gif','button-scu-bro-x.gif','button-scu-chi.gif','button-scu-chi-x.gif',
		'button-scu-iron.gif','button-scu-iron-x.gif','button-scu-mar.gif','button-scu-mar-x.gif','button-scu-shpi.gif','button-scu-shpi-x.gif',
		'button-silver-x.gif','button-juwillery-x.gif' );
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


