var	moz = 0;
var	ie = document.all;
if( !ie )
	moz = (!document.all) && document.getElementById;


String.prototype.trim = function()
{
	return( this.replace(/^\s+/, '').replace(/\s+$/, '') );
}

function setnewname( o, oid )
{
	var fn = o.value;
	if( fn == "" )
		document.getElementById( oid ).value = '';
	else
	{
		var filename = fn.match(/[\/|\\]([^\\\/]+)$/);
		if( filename == null )
			filename = fn; //opera...
		else
			filename = filename[ 1 ];
		document.getElementById( oid ).value = filename;
	}
}

function showgalpic( p, c )
{
	fadeobj = document.getElementById( 'bgfade' );

	if( ie )
	{
		fadeobj.style.width = document.body.clientWidth;
		fadeobj.style.height = document.body.clientHeight;
	}
	else
	{
		fadeobj.style.width = document.width + "px";
		fadeobj.style.height = document.height + "px";
	}
	fadeobj.style.display = 'block';
	imgwidth = 700;
	imgheight = 650;
	pictureobj = document.getElementById( 'bigpicture' );
	if( ie )
	{
		if( document.documentElement )
		{
			sctop = document.documentElement.scrollTop;
			scleft = document.documentElement.scrollLeft;
			clheight = document.documentElement.clientHeight;
			clwidth = document.documentElement.clientWidth;
		}
		else
		{
			sctop = document.body.scrollTop;
			scleft = document.body.scrollLeft;
			clheight = document.body.clientHeight;
			clwidth = document.body.clientWidth;
		}
	}
	pgyoffset = moz ? parseInt( pageYOffset ) : parseInt( sctop );
	horzpos = moz ? pageXOffset + window.innerWidth / 2 - imgwidth / 2 : scleft + clwidth / 2 - imgwidth / 2;
	vertpos = moz ? pgyoffset + window.innerHeight / 2 - imgheight / 2 : pgyoffset + clheight / 2 - imgheight / 2;
	vertpos = Math.max( pgyoffset, vertpos );

	pictureobj.style.left = horzpos + "px";
	pictureobj.style.top = vertpos + "px";
	pictureobj.style.width = 750 + "px";
	var psrc = "p/" + currmenu + "/big/" + p;
	if( parseInt( p ) != NaN )
		psrc = "./getpic.php?pid=" + p;
	psrc = "./getpic.php?pid=0";
	s = "<table cellpadding=0 cellspacing=0 bordercolor=#bbc1c1 border=1 frame=border rules=none style='width:750px;height:600px;' align=center>";
	s += "<tr><td></td><td align=center class=curgaltitle>" + gn + "</td><td align=right><a href='javascript:hidebigpicture();'>";
	s += "<img border=0 src='g/x.gif' onmouseover='this.src=\"g/x_mo.gif\";' onmouseout='this.src=\"g/x.gif\";'></a>";
	s += "</td></tr><tr><td align=center valign=center colspan=10 width=750 height=450>";
	s += "<a href='javascript:hidebigpicture();'><img id=mainpic border=0 src='g/loading.gif'></a></td></tr>";
	s += "<tr><td><a href='javascript:prevpic(" + (p-1) + ");'><img border=0 src='g/l.gif' onmouseover='this.src=\"g/l_mo.gif\";' onmouseout='this.src=\"g/l.gif\";'></a></td>";
	s += "<td width=80% align=center style='font-size:14px;font-family:arial;'><b>" + comms[p] + "</b></td><td align=right><a href='javascript:nextpic(" + (p+1) + ");'><img border=0 src='g/r.gif' onmouseover='this.src=\"g/r_mo.gif\";' onmouseout='this.src=\"g/r.gif\";'></a></td></tr></table>";
	pictureobj.innerHTML = s;
	mp = document.getElementById( 'mainpic' );
	if( mp )
		mp.src = "./getpic.php?pid=" + ids[p];
	
	pictureobj.style.display = "block";
	pictureobj.style.zIndex = 1000;
}

function showpic( p, c )
{
	fadeobj = document.getElementById( 'bgfade' );

	if( ie )
	{
		fadeobj.style.width = document.body.clientWidth;
		fadeobj.style.height = document.body.clientHeight;
	}
	else
	{
		fadeobj.style.width = document.width + "px";
		fadeobj.style.height = document.height + "px";
	}
	fadeobj.style.display = 'block';
	imgwidth = 700;
	imgheight = 600;
	pictureobj = document.getElementById( 'bigpicture' );
	if( ie )
	{
		if( document.documentElement )
		{
			sctop = document.documentElement.scrollTop;
			scleft = document.documentElement.scrollLeft;
			clheight = document.documentElement.clientHeight;
			clwidth = document.documentElement.clientWidth;
		}
		else
		{
			sctop = document.body.scrollTop;
			scleft = document.body.scrollLeft;
			clheight = document.body.clientHeight;
			clwidth = document.body.clientWidth;
		}
	}
	pgyoffset = moz ? parseInt( pageYOffset ) : parseInt( sctop );
	horzpos = moz ? pageXOffset + window.innerWidth / 2 - imgwidth / 2 : scleft + clwidth / 2 - imgwidth / 2;
	vertpos = moz ? pgyoffset + window.innerHeight / 2 - imgheight / 2 : pgyoffset + clheight / 2 - imgheight / 2;
	vertpos = Math.max( pgyoffset, vertpos );

	pictureobj.style.left = horzpos + "px";
	pictureobj.style.top = vertpos + "px";
	pictureobj.style.width = 750 + "px";
	s = "<table cellpadding=0 cellspacing=0 bordercolor=#bbc1c1 border=1 frame=border rules=none style='width:750px;height:600px;' align=center>";
	s += "<tr><td></td><td></td><td align=right><a href='javascript:hidebigpicture();'>";
	s += "<img border=0 src='g/x.gif' onmouseover='this.src=\"g/x_mo.gif\";' onmouseout='this.src=\"g/x.gif\";'></a></td></tr>";
	s += "<tr><td align=center valign=middle colspan=10 width=750 height=600>";
	s += "<a href='javascript:hidebigpicture();'><img id=mainpic border=0 src='g/loading.gif'></a><br><br></td></tr></table>";
	pictureobj.innerHTML = s;
	mp = document.getElementById( 'mainpic' );
	if( mp )
		mp.src = "./getpic.php?pid=" + p;
	
	pictureobj.style.display = "block";
	pictureobj.style.zIndex = 1000;
}

function nextpic(p)
{
	if( p >= ids.length )
		p = 0;
	showgalpic( p );
}
function prevpic(p)
{
	if( p < 0 )
		p = ids.length-1;
	showgalpic( p );
}

function hidebigpicture()
{
	pictureobj = document.getElementById( 'bigpicture' );
	pictureobj.style.display = "none";
	fadeobj = document.getElementById( 'bgfade' );
	fadeobj.style.display = 'none';
}

function setCookie( name, value )
{
	if(name != '')
		document.cookie = name + '=' + value;
}

function getCookie( name )
{
	if(name == '')
		return('');

	name_index = document.cookie.indexOf(name + '=');

	if(name_index == -1)
		return('');

	cookie_value = document.cookie.substr(name_index + name.length + 1, document.cookie.length);
	end_of_cookie = cookie_value.indexOf(';');
	if(end_of_cookie != -1)
		cookie_value = cookie_value.substr(0, end_of_cookie);
	space = cookie_value.indexOf('+');
	while(space != -1)
	{
		cookie_value = cookie_value.substr(0, space) + ' ' + cookie_value.substr(space + 1, cookie_value.length);
		space = cookie_value.indexOf('+');
	}
	return(cookie_value);
}

function clearCookie(name)
{
	expires = new Date();
	expires.setYear(expires.getYear() - 1);
	document.cookie = name + '=null' + '; expires=' + expires;
}

function clearCookies()
{
	Cookies = document.cookie;
	Cookie = Cookies;
	expires = new Date();
	expires.setYear(expires.getYear() - 1);

	while(Cookie.length > 0)
	{
		Cookie = Cookies.substr(0, Cookies.indexOf(';'));
		Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);

		if(Cookie != '')
 			document.cookie = Cookie + '; expires=' + expires;
		else
 			document.cookie = Cookies + '; expires=' + expires;
	}
}

