// set the window width based on passed parameters
// currently sets width on page load [auto], writes function menu [page]
// sets cookies, either 'size' for horizontal or 'head' for vertical, no header
function set_size( which_value, element_id )
{
	//begin ns4 blocking
	if ( dom ) 
	{
		// begin real code
		var smll = '80', med = '90', full = '99.6', noHead = 'nohead', head = 'head';
		var size, b_change_width = false, b_change_height = false, b_show = false;
		message = "To store your preference, click 'OK'\n" +
					"To just use it on this page, click 'Cancel'\n" +
					"You can change your preferences anytime\n" +
					"by just clicking another item in the right side \n" +
					"'Site Features' bar, or just delete them.\n\n" +
					"You must refresh the page to see your\nnew preferences " +
					"listed in the right bar.";

		// run through the values the function can have, either numeric for width percents to be placed into
		//size cookie, or text, page, auto, head, nohead, delete 
		switch ( which_value )
		{
			case 'page':
				var hWidth = '<h4 class="right-bar">Display Width</h4>\n';
				var hHeight = '<h4 class="right-bar">Display Height</h4>\n';
				var pOpen = '<p class="right-bar">\n';
				var pClose = '</p>\n';
				var delete_prefs = '';
				var CSSclass = ' class="small"';
				var CSSid = ' class="small-active"';
				var item1, item2, item3, item4, item5;
				var id1 = CSSclass, id2 = CSSclass, id3 = CSSclass, id4 = CSSclass, id5 = CSSclass;
				// check to make sure the cookie is set, then run through the function menu variable assignments
				if ( ( Get_Cookie( 'size' ) != null ) || ( Get_Cookie( 'head' ) != null ) )
				{
					// delete prefs only filled if there was a cookie
					delete_prefs = '<h4 class="right-bar"></h4>' + pOpen + '<a href="#"' +
					'onclick="set_size( \'delete\', \'mainblock\' );"' +
					' class="small">Delete Preferences</a>' + pClose;
					whatsize = Get_Cookie( 'size' );
					b_header = Get_Cookie( 'head' );
					// check the variables to assign which will have the active css class attached
					if ( whatsize == full )
					{
						id1 = CSSid;
					}
					else if ( whatsize == med )
					{
						id2 = CSSid;
					}
					else if ( whatsize == smll )
					{
						id3 = CSSid;
					}
					if ( b_header == 'head' )
					{
						id4 = CSSid;
					}
					else if ( b_header == 'nohead' )
					{
						id5 = CSSid;
					}
				} 
				// pack the item arrays, using the above css class variable assignment
				item1 = '<a href="#" onclick="set_size( \'' + full + '\', \'mainblock\' );"' + id1 +
						'>Full Window</a><br />\n';
				item2 = '<a href="#" onclick="set_size( \'' + med + '\', \'mainblock\' );"' + id2 +
				'>Standard Size</a><br />\n';
				item3 = '<a href="#" onclick="set_size( \'' + smll + '\', \'mainblock\' );"' + id3 +
				'>Narrow View</a>\n';
				item4 = '<a href="#" onclick="set_size( \'' + head + '\', \'\' );"' + id4 +
				'>Full Page Header</a><br />\n';
				item5 = '<a href="#" onclick="set_size( \'' + noHead + '\', \'\' );"' + id5 +
				'>No Page Header</a>\n';
				//concatenate
				full_string = hWidth + pOpen + item1 + item2 + item3 + pClose + hHeight + pOpen + 
											item4 + item5 + pClose + delete_prefs;
				// write it out
				document.write(	full_string );
				//set booleans to protect against wrong function being called
				b_change_width = false;
				element_id = false;
				break;
			case '99.6':
				if ( confirm( message ) )
				{
					Set_Cookie('size', which_value , 365, '/', '', '');
				}
				size = which_value;
				b_change_width = true;
				break;
			case '90':
				if ( confirm( message ) )
				{
					Set_Cookie('size', which_value, 365, '/', '', '');
				}
				size = which_value;
				b_change_width = true;
				break;
			case '80':
				if ( confirm( message ) )
				{
					Set_Cookie('size', which_value, 365, '/', '', '');
				}
				size = which_value;
				b_change_width = true;
				break;
			case 'head':
				if ( confirm( message ) )
				{
					Set_Cookie('head', which_value, 365, '/', '', '');
				}
				b_change_height = true;
				b_show = true;
				break;
			case 'nohead':
				if ( confirm( message ) )
				{
					Set_Cookie('head', which_value, 365, '/', '', '');
				}
				b_change_height = true;
				b_show = false;
				break;
			case 'delete':
				Delete_Cookie('size', '/', '');
				Delete_Cookie('head', '/', '');
				alert('Your preferences\nhave been deleted');
				b_change_width = false;
				break;
			case 'auto':
				//auto sizing function, currently set to 860px
				// do not do this if there is a cookie
				if ( Get_Cookie( 'size' ) != null )
				{
					b_change_width = false;
					element_id = false;
					//alert ( 'cookie: ' + Get_Cookie( 'size' ));
					break;
				}
				// set the width or height, using method testing to avoid error
				else 
				{
					if ( document.documentElement.clientWidth )
					{
						size = ( document.documentElement.clientWidth < 1200 ) ? full : med;
					}
					else if ( document.body.clientWidth )
					{
						size = ( document.body.clientWidth < 1200 ) ? full : med;
					}
					else 
					{ 
						size = med;
					}
					b_change_width = true;
				}
				break;
			default:
				size = med;
				break;
		}
	}// end dom section
	
	// change the page width, check booleans to avoid error
	if ( dom )
	{
		if ( b_change_width && document.getElementById && element_id && size)
		{
			/* 
			size = size + '%'; 
			*/
			change_css( 'width', '', size, element_id );
		}
		//change the page height and get rid of/add header if needed
		//check booleans to avoid error
		if ( b_change_height  && document.getElementById )
		{
			change_css( 'header', b_show, '', '' );
		}
	}
	/* 
	else
	{
		browser_message = "We're Sorry, but your browser is too old to work on this site.\n" +
					"Please consider updating to a modern browser.\n" +
					"There are many good, free new ones, like Opera or Mozilla/ Firefox\n" +
					"Opera especially should run very well if you are using an old computer";
		if (!b_first)
		{
			alert(browser_message);
			b_first = true;
		}
		
	} 
	*/
}

// used by above function, this just switches the document style id's back and forth
function change_css( which_stuff, b_show, size, element_id )
{
	// begin ns protection
	if (dom)
	{
		if ( which_stuff == 'header' )
		{
			var topPos = '11%', heightPos = '88.6%', height2Pos = '97%', top2Pos = '2%';
			var visibilityOnOff = 'visible';
			var displayOnOff = 'block';
			if ( !b_show )
			{
				// the '2' items are the center iframe container height and top position
				topPos = '0%';
				top2Pos = '0%';
				heightPos = '99.6%';
				height2Pos = '99.6%';
				visibilityOnOff = 'hidden';
				displayOnOff = 'none'
			}
			//top nav on /off switches
			document.getElementById('header').style.display = displayOnOff;
			document.getElementById('float-header3a').style.visibility = visibilityOnOff;
			document.getElementById('row1-c1').style.visibility = visibilityOnOff;
			document.getElementById('row1-b1').style.visibility = visibilityOnOff;
			document.getElementById('row2-b1').style.visibility = visibilityOnOff;
			// this is for pre 7 op and pre 1 moz
			if ( document.getElementById('topflashEmbed') )
			{
				document.getElementById('topflashEmbed').style.visibility = visibilityOnOff;
			}
			if ( document.getElementById('topflash') )
			{
				document.getElementById('topflash').style.visibility = visibilityOnOff;
			}
			if ( ie )
			{
				
			}
			//browser_css( 'height', '');
			//row 3 raise/lower switches
			
			
			/* 
			document.getElementById('row3-a1').style.top = topPos;
			document.getElementById('row3-a1').style.height = heightPos;
			document.getElementById('row3-b1').style.top = topPos;
			document.getElementById('row3-b1').style.height = heightPos;
			document.getElementById('row3-c1').style.top = topPos;
			document.getElementById('row3-c1').style.height = heightPos;
			//row 3 raise/lower switches - this has a different value than the rest
			document.getElementById('row3-b2').style.top = top2Pos;
			document.getElementById('row3-b2').style.height = height2Pos;  
			*/
		}
		else if ( which_stuff == 'width' )
		{
			size = parseInt(size);
			if ( ie && win && (nu < 6) )
			{
				margin = (100 - size)/2;
				size = size + margin;
			}
			else
			{
				margin = (100 - size)/2;
			}
			margin = ( margin < 1 ) ? 0 : margin;
			margin += '%';
			size = size + '%';

			document.getElementById(element_id).style.width = size;
			//document.getElementById(element_id).style.marginLeft = margin; 
		}
		// Opera 6 doesn't adjust properly, so give a message to user
		if ( op && nu < 7 )
		{
			var first, second;
			opmoz = 'You must refresh your page to \nsee the new preferences due to an Opera 6 bug.\n' +
			'Please consider upgrading to Opera 7, \nthat\'s a much better browser, and less buggy';
			alert( opmoz );
		}
	}
}

function run_clock() {
	if (dom)
	{
		var da, day, mon, year, h, m, s, the_time, ampm, tzo;

		da = new Date();
		tzo = da.getTimezoneOffset()/60;
		day = da.getDay();
		day = a_days[day]; //uses fact that days are 0-3x, as is day array
		dofm = da.getDate();
		mon = da.getMonth();
		mon = a_months[mon];//uses fact that months are 0-11, as is array index
		//year = da.getFullYear();
		//year = year.toString();//necessary if you want to use the substr method to get 2 digit year number
		//year = year.substr(2,2);
		h = da.getHours();
		m = da.getMinutes();
		s = da.getSeconds();

		(m < 10) ? m = "0" + m: '';
		(s < 10) ? s = "0" + s: '';
		
		if (h >= 12)
		{
			if (h == 12)
			{
				ampm = 'PM';
			}
			else if (h == 24)
			{
				ampm = 'AM';
				h = '00';
			}
			else {
				h -= 12;
				ampm = 'PM'
			}
		}
		else 
		{
			ampm = 'AM';
		}
		
		/*da = da.toLocaleString(); this is not being used now, no cross browser control of time formatting */

		the_time = h + ":" + m + ":" + s + ' ' + ampm + '<br \/>\n' + day + ", " + mon  + " " + dofm;

		d.getElementById("digitalClock").innerHTML = the_time;
		window.setTimeout("run_clock();", 100);
	}
}

