///////////////////////////////////////////////////////////////////////////////////////////////////
function sideswitch(to_side_name)
{	
//alert("sideswitch:"+from_side_name+"->"+to_side_name);
	if( from_side_name == to_side_name)
		return;//do nothing if active one hit

//FIRST set up sidebar from cookies if any by calling restore_<which>()
//(in case, say, changed but not applied)
	var restorefunc = "restore_" + to_side_name;
	if( self.restorefunc)
		eval(restorefunc + "()");


//HIGHLIGHT NEW TAB, IF THERE IS ONE (none for prefs,print)
	var to_tabid = "tab_"+to_side_name;
	var to_tab = document.getElementById( to_tabid);
	if( to_tab != null)
	{
		//to tab is brighter & has no onclick
		to_tab.style.color = "#052254";
		to_tab.style.background = "url(IGISimages/tab_1.gif)";
	}
//	else		alert("sideswitch: no elem with ID: "+to_tabid);

// DIM OLD TAB if was one
	var from_tab_id = "tab_"+from_side_name;
	//alert("sideswitch:"+from_side_name+": "+from_tab_id+"->"+to_tabid);
	var from_tab = document.getElementById( from_tab_id);
	if( from_side_name != "none" && from_tab != null)//was not first time, not a tab
	{
		//from-tab darkens & gets a click to its sidebar
		from_tab.style.color = "#43639B";
		from_tab.style.background = "url(IGISimages/tab_0.gif)";
	}

//if from print, hide stuff covering map
//NAH, do it always, will show cover after
//if( to_side_name != "print" && to_side_name != "help")//TODO: generalize
	hide_cover_map_div();
//if to print, show preview
	if( to_side_name == "print")
		printPreview();

	if( to_side_name == "help")
		showHelp();

	if( to_side_name == "admin")
		showAdmin();


//SHOW NEW SIDEBAR//FOOTBUTS
	var to_side_id = "side_"+to_side_name;
	var to_side_div = document.getElementById( to_side_id);
//alert("sideswitch:"+to_side_id+"-display="+to_side_div.style.display);
	to_side_div.style.display = "inline";

//FOOTER BUTTONS - separate so it does not scroll w/sidebar & can be half outside
	to_foot_id = "foot_"+to_side_name;
	to_foot_div = document.getElementById( to_foot_id);
	if( to_foot_div != null)
		to_foot_div.style.display = "inline";

//HIDE OLD SIDEBAR//FOOT
	if( from_side_name !="none")
	{
		var from_div = document.getElementById( "side_"+from_side_name);
//alert(from_side_name);
		if( from_div != null)
		{
			from_div.style.display = "none";
			foot_div = document.getElementById( "foot_"+from_side_name);
			if( foot_div != null)
				foot_div.style.display = "none";
		}
	}

/*NOT?
	from_div.visibility = "hidden";
	to_side_div.visibility  = "visible";
*/

	//save it in the form input for reloading state
//alert( "formval=document.forms[0]." + idname + ".value=" + display_style + ";");
	eval( "document.forms[0].whichTab.value='" + to_side_name + "';" );
	from_side_name = to_side_name;
}

function	show_cover_map_div()
//don't need to turn on/off the map if z-order < cover (?)
{
//	alert("show_cover_map_div");
	coverdiv = document.getElementById( "covermap");
	coverdiv.style.display = "inline";
}

function	hide_cover_map_div()
{
//	alert("hide_cover_map_div");
//don't need to turn on/off the map if z-order < cover (?)
//	mapdiv = document.getElementById( "map");
//	mapdiv.style.display = "none";
	coverdiv = document.getElementById( "covermap");
	coverdiv.style.display = "none";
}

///////////////////////////////////////////////////////////////////////////////////////
//show/hides thing w/given ID; sets cookie WITH SAME NAME
function setViz(idname, display_style)//inline or none
{
//REFMAP SHOWS BEFORE THIS: then vanishes if off-set div display style directly instead
// alert("setViz:"+idname+"="+display_style);
/*	var elem = null;
	elem = document.getElementById(idname);
	if(elem==null)
	{
		alert("setViz: no elem with ID: "+idname);
		return;
	}
	elem.style.display = display_style;//inline/none
*/
	elem = document.getElementById(idname);
	if( elem == null)
		return;//may be remmed, etc
	var style = elem.style;
	style.display = display_style;//why does this work? copied the var!
//"setting a prop that has only a getter": document.getElementById(idname).style = display_style;

	//save it in the form input for reloading state
//alert( "formval=document.forms[0]." + idname + ".value=" + display_style + ";");
//	eval( "document.forms[0]." + idname + ".value='" + display_style + "';" );//DOES NOT SURVIVE RELOAD: thus cookies

//COOKIE IT here for now
	setCookie( idname, display_style, 365);
}

///////////////////////////////////////////////////////////////////////////////////////
//show/hides thing w/given ID using value from input w/same name
function setVizOnLoad(idname)//inline or none
{
//COOKIE WAY
	value = getCookie( idname);
	if(value == "")
		value="inline";
	setViz( idname, value);

//FORM INPUT WAY
// eval( "setViz( idname, document.forms[0]." + idname + ".value);")
}

///////////////////////////////////////////////////////////////////////////////////////
//toggles visbility of the thing; cookies it
function toggleViz(idname)
{
//alert("toggleViz:"+idname);
	var display = document.getElementById(idname).style.display;
	if( display == "" || display == "inline")
		display = "none";
	else
		display = "inline";
	setViz(idname, display);
}

////////////////////////////////////////////////////////////////////////////////////////
function toggleLayer(whichLayer)
{
	if (document.getElementById)//the hell? 
	{
		var style2 = document.getElementById(whichLayer).style;
//alert("toggleLayer: getElementById, disp="+style2.display);
		style2.display = style2.display? "":"none";//the fuck
	}
	else if (document.all)
	{
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
	else if (document.layers)
	{
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"none";
	}
}

function toggleText(targetId)
{
	
	if (document.getElementById)
	{		
		document.getElementById('infolink1').style.display = "none";
		document.getElementById('infolink2').style.display = "none";
		var style2 = document.getElementById(targetId).style;	
		//style2.display = style2.display? "none":"block";
		style2.display = "block";
	}
	else if (document.all)
	{
		document.all['infolink1'].style.display = "none";
		document.all['infolink2'].style.display = "none";
		var style2 = document.all[targetId].style;
		//style2.display = style2.display? "none":"block";
		style2.display = "block";
	}
	else if (document.layers)
	{
		document.layers['infolink1'].style.display = "none";
		document.layers['infolink2'].style.display = "none";
		var style2 = document.layers[targetId].style;
		//style2.display = style2.display? "none":"block";
		style2.display = "block";
	}

}

function setDisplay(div,setting) 
{
	if (document.getElementById)
		document.getElementById(div).style.display = setting;
}


