/* Functions that handle preload. */
//v3.0
function MM_preloadImages()
{
	var d = document;
	if( d.images )
	{
		if( !d.MM_p )
			d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for( i=0; i < a.length; i++ )
		{
			if( a[i].indexOf( "#" ) != 0 )
			{
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}

/* Functions that swaps images. */
//v4.01
function MM_findObj( n, d )
{
	var p, i, x;
	if( !d )
	d = document;
	if( ( p = n.indexOf( "?" ) ) > 0 && parent.frames.length )
	{
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring( 0, p);
	}
	if( !(x = d[n]) && d.all )
		x = d.all[n];
	for( i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for( i = 0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj( n, d.layers[i].document );
	if( !x && d.getElementById )
		x = d.getElementById( n );
	return x;
}

//v3.0
function MM_swapImage()
{
	var i ,j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for( i=0; i < (a.length - 2); i +=3 )
	{
		if( (x = MM_findObj( a[i] ) ) != null )
		{
			document.MM_sr[j++] = x;
			if( !x.oSrc )
				x.oSrc = x.src;
			x.src = a[i+2];
		}
	}
}

//v3.0
function MM_swapImgRestore()
{
	var i, x, a = document.MM_sr;
	for( i = 0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ )
	{
		x.src = x.oSrc;
	}
}

function switchPanel()
{
	// find cookie's value
	var arg = "panel=";
	var value = "";
	var argLength = arg.length;
	var cookiesLength = document.cookie.length;
	var expires = new Date();
	expires.setMonth( expires.getMonth() + 1 );
	var i = 0;
	while( i <= cookiesLength )
	{
		var j = i + argLength;
		if( document.cookie.substring( i, j ) == arg )
		{
			var endStr = document.cookie.indexOf( ";", j );
			if( endStr == -1 )
			{
				endStr = document.cookie.length;
			}
			// value found
			value = document.cookie.substring( j, endStr );
			// switch cookie's value
			if( value == "xslt" )
			{
				document.cookie = "panel=svg; path=/; expires=" + expires.toUTCString();
			}
			else if( value == "svg" )
			{
				document.cookie = "panel=xslt; path=/; expires=" + expires.toUTCString();
			}
			else
			{
				// set to default
				document.cookie = "panel=xslt; path=/; expires=" + expires.toUTCString();
			}
			break;
		}
		i = document.cookie.indexOf( ";", i ) + 1;
		// value not found
		if( i == 0 )
		{
			// set to default
			document.cookie = "panel=xslt; path=/; expires=" + expires.toUTCString();
			break;
		}
	}

	// refresh browser
	window.location.reload( true );
}

function getTarget( event )
{
	var target = event.target;
	if( target == null )
	{
		target = event.srcElement;
	}

	return target;
}

function clearTextBox( textbox, text )
{
	if( textbox.value == text )
	{
		textbox.value = '';
		textbox.style.color = 'black';
	}
}

function resetTextBox( textbox, text )
{
	if( textbox.value == '' )
	{
		textbox.value = text;
	}
}

function viewImage( url, width, height )
{
  	// correct for over-sized images
  	if( width / height > 1 )
  	{
		if( width > 640 )
		{
			width =  640;
		}
		if( height > 480 )
		{
			height =  480;
		}
  	}
  	else
  	{
  		if( width > 480 )
		{
			width =  480;
		}
		if( height > 640 )
		{
			height =  640;
		}
  	}

  	var windowFeatures = "width=" + width + ",height=" + height + ",toolbar=no,location=no";
	var imageWindow = window.open( url, null, windowFeatures );
}

function currentPage()
{
	var page;
	var dirs = window.location.pathname.split( '/' );

	if( dirs.length == 2 )
	{
		page = "home";
	}
	else
	{
		var i = 1; // dirs.length - 2;
		page = dirs[i];
	}

	return page;
}

function svg()
{
	var svgDoc = document.embeds["SVGtoScale"].getSVGDocument();
}

