// common layout function

var grabmeWin = null;

function toggle( par_id )
{
	if (document.getElementById)
	{
		target = document.getElementById( par_id );
		if (target.style.display == "none")	{ target.style.display = ""; target.innerHTML.display = ""; }
		else { target.style.display = "none"; target.innerHTML.display = "none"; }
	}
}


/* new toggle; with changing images/buttons */
function toggle2( par_id, img_id, up_arrow, down_arrow )
{
	if (document.getElementById)
	{
		par_target = document.getElementById( par_id );
		img_target = document.getElementById( img_id );
		if (par_target.style.display == "none")
		{
			par_target.style.display = "";
			par_target.innerHTML.display = "";
			if(img_target) { img_target.src= down_arrow; }
		}
		else
		{
			par_target.style.display = "none";
			par_target.innerHTML.display = "none";
			if(img_target) { img_target.src= up_arrow; }
		}
	}
}



function popUrl(id,URL)	// pop up a web page by URL
{
	window.open(URL, id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=400,left = 440,top = 200');
}
function popHtml(id,contents)	// pop up the content passed into the js method
{
	var grabWin = window.open("", id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=300,left = 440,top = 200');
	grabWin.document.writeln(contents);
}
function popID(id,before,after)	// pop up contents of specified div by ID
{
	// grabmeWin is a global variable declared outside of this routine
	if (document.getElementById)
	{
		if( grabmeWin  ) { grabmeWin.close(); }	// if a grabme window is already open, close it to replace it with this new one

		var inIdDiv = document.getElementById(id).innerHTML;
		var copyBox = '<form><textarea rows="10" cols="60">' + inIdDiv + after + '</textarea></form>';
		var winId = 'win_' + id;
		grabmeWin = window.open("", winId, 'toolbar=0,location=0,statusbar=0,menubar=0,scrollbars=1,resizable=1,width=600,height=300,left=100,top=100');
		grabmeWin.document.writeln(before,copyBox);
		grabmeWin.focus()	// useful if an alert box stole focus, e.g.
	}
}

// recursive function call that performs a color fade
function DoFade(colorId, targetId)
{
	var FadeInterval = 600;
	var FadeSteps = new Array();
		FadeSteps[1] = "ff";
		FadeSteps[2] = "ee";
		FadeSteps[3] = "dd";
		FadeSteps[4] = "cc";
		FadeSteps[5] = "bb";
		FadeSteps[6] = "aa";
		FadeSteps[7] = "99";
	if (colorId >= 1)
	{
		document.getElementById(targetId).style.backgroundColor = "#ffff" + FadeSteps[colorId];
        if (colorId==1) { document.getElementById(targetId).style.backgroundColor = "transparent"; }	// if last color, set to transparent
        colorId--;
        setTimeout("DoFade("+colorId+",'"+targetId+"')", FadeInterval);		// wait, and fade another shade
	}
}
function show_tab(scenario)
{
    var tab;
    var i = 1;
	while (tab = document.getElementById('tab' + i))
	{
        if (i == scenario)	{ tab.style.display = 'block'; }
        else				{ tab.style.display = 'none'; }
        i++;
    }
	var content;
    i = 1;
	while (content = document.getElementById('content' + i))
	{
		if (i == scenario)	{ content.style.display = 'block'; }
        else				{ content.style.display = 'none'; }
        i++;
    }
}
function detect_tab(url)
{
	if (! url)	{ url = window.location + ''; }		// URL as string
	var regexp = /#(.+)$/
	var prepostanchor = url.split('#');
	var tab;
	if( prepostanchor.length > 1 )	{ tab = prepostanchor.pop(); }
	if( (tab !=2) && (tab !=3) && (tab !=4) && (tab !=5) && (tab !=6) )	{ return 1;}	// bogus tab; set default
	return tab;
}

