//initialization, browser, os detection
var d, dom, ie, ienu, ie4, ie5, ie5x, ie6, moz, moz_rv, moz_rv_sub, mac, win, old, lin, 
ie5mac, ie5xwin, op, opnu, op4, op5, op6, op7;

d=document;
n=navigator;
nav=n.appVersion;
nan=n.appName;
nua=n.userAgent;
win=(nav.indexOf('Win')!=-1);
mac=(nav.indexOf('Mac')!=-1);
lin=(nua.indexOf('Linux')!=-1);
// begin primary dom/ns4 test
// this is the most important test on the page
if ( !document.layers )
{
	dom = ( d.getElementById ) ? document.getElementById : false;
}
else { 
	dom = false; 
}
// end main dom/ns4 test
old=(nav.substring(0,1)<4);
op=(nua.indexOf('Opera')!=-1);
moz=(nua.indexOf('Gecko')!=-1);
ie=(d.all&&!op);
if (op){
	op_pos=nua.indexOf('Opera');
	opnu=nua.substr((op_pos+6),4);
	op5=(opnu.substring(0,1)==5);
	op6=(opnu.substring(0,1)==6);
	op7=(opnu.substring(0,1)==7);
}
else if (moz){
	rv_pos=nua.indexOf('rv');
	moz_rv=nua.substr((rv_pos+3),3);
	moz_rv_sub=nua.substr((rv_pos+7),1);
	if(moz_rv_sub==' '||isNaN(moz_rv_sub)){moz_rv_sub='';}
	moz_rv=moz_rv+moz_rv_sub;
}
else if (ie){
	ie_pos=nua.indexOf('MSIE');
	ienu=nua.substr((ie_pos+5),3);
	ie4=(!dom);
	ie5=(ienu.substring(0,1)==5);
	ie6=(ienu.substring(0,1)==6);
}
else {}
/*ie5x tests only for functionavlity. dom or ie5x would be default settings. 
Opera will register true in this test if set to identify as IE 5*/
ie5x=(d.all&&dom);
ie5mac=(mac&&ie5);
ie5xwin=(win&&ie5x);

/********************************************
Write out CSS link to onoff div CSS
********************************************/
function css_override( spare )
{
	if ( dom )
	{
		if ( ie || op || ( moz && moz_rv < 1.3 ) )
		{
			document.write( '<link rel="stylesheet" type="text/css" href="/css/pwt_override.css" />' );
		}
		else
		{
			var csslink = document.createElementNS("http://www.w3.org/1999/xhtml","link");
			csslink.setAttribute("rel", "stylesheet");
			csslink.setAttribute("type", "text/css");
			csslink.setAttribute("href", "/css/pwt_override.css");
			csslink.setAttribute("media", "screen");
			document.getElementsByTagName("head")[0].appendChild(csslink);
		}
		
		/*
		if ( (ie5xwin || ie4) && !op)
		{
			document.write('<style type="text/css">a.mainNav1, a.subnavLink, a.subnavLink:visited{width:100%;}' +
			'#index #c6, #index #c8 {left:27px;}#c6, #c8 {left:20px;}</style>');
		} 
		*/
	}
	else
	{
		document.write('<style type="text/css">#block {display:none;}</style>');
	}
	if ( dom && spare == 'index' )
	{
		//alert('index');
		for ( i=1; i<8 ; i++ )
		{
			elementid = 'onoff' + i;
			document.getElementById( elementid ).style.display = 'none';
		}
		document.getElementById( 'onoff0' ).style.display = 'block';
	}
}
/********************************************
Show hide / DropMenu functions
********************************************/
// initialize variables
var count_div_ids = 15;// this is max number of ids for either dropmenus or onoff items
var timerID = null;
var timerOn = false;
var timecount = 350;// Change this to the time delay that you want
var drop_id = 'dropMenu';// this needs to be global for setTimeout

/*
Main showHide control function, needs the item id and number, like dropMenu + 2
these will be either conctatenated or used directly for other functions called
*/
function showHide( menuID, menuNumber )
{
	if ( dom )
	{
		full_ID = menuID + menuNumber;
		hideAll( menuID );
		showElement ( full_ID, menuID );
		if ( menuID == 'dropMenu' )
		{
			stopTime();
		}
	}
}
/*
Toggles the element visibility/display to visible/block 
*/
function showElement( full_ID, menuID ) { 
	if ( dom ) 
	{ 
		if ( document.getElementById( full_ID )	)// test to make sure element id exists
		{
			if ( menuID == 'dropMenu' )
			{
				document.getElementById( full_ID ).style.visibility="visible"; 
			}
			else 
			{
				document.getElementById( full_ID ).style.display="block"; 
				document.getElementById( full_ID ).style.top="0"; 
			}
		} 
	}
} 

/* 
The hideElement function is almost identical to the showElement function in it’s working, 
except that it changes the visibility/display property to hidden/none. 
*/
function hideElement( full_item_id, menuID ) { 
	if ( dom ) 
	{ 
		if ( document.getElementById( full_item_id )	)// test to make sure element id exists
		{
			if ( menuID == 'dropMenu' )
			{
				document.getElementById( full_item_id ).style.visibility="hidden"; 
			}
			else
			{
				document.getElementById( full_item_id ).style.display="none"; 
			}
		}
	} 
} 

/* 
This function allows us to hide every element used the menu system at one time. This means 
that we can make sure that all elements are turned off, before making the appropriate element 
visible. All you need to do is call the hideElement function for each element used in your 
menu system. 
*/
function hideAll( menuID ) 
{ 
	if ( dom ) 
	{ 
		for (i = 0; i < count_div_ids ; i++)
		{
			full_item_id = menuID + i;
			if ( document.getElementById( full_item_id )	)// test to make sure element id exists
			{
				hideElement( full_item_id, menuID );
			}
		}
	}
} 

/* 
This function starts the timer to hide every layer. We use this function to turn 
all elements off, if the user has moused away from them for more than out timecount 
value (set at 350 miliseconds in the global variable section) 
*/
function startTime() 
{ 
	if ( dom ) 
	{ 
		if (timerOn == false ) 
		{ 
			//note: the drop_id has to be either global or a hardcoded value in the settimeout function.
			timerID = setTimeout( "hideAll( drop_id )" , timecount); 
			timerOn = true; 
		}
	} 
} 

/* 
Similarly, the stopTime function stops the timer altogether. 
*/
function stopTime() 
{ 
	if (timerOn) 
	{ 
		clearTimeout(timerID); 
		timerID = null; 
		timerOn = false; 
	} 
} 

/******************************
no junk mail  
******************************/
function no_junk(name, domain, css_class, subject, text) 
{
	/* 
	if ( moz )
	{
			var maillink = document.createElementNS("http://www.w3.org/1999/xhtml","a");
			maillink.setAttribute("href", "mailto:" + name + '@' + domain );
			document.getElementsById("email-address").appendChild(maillink);
	}
	else
	{ 
	*/
		if (text)// do this first to avoid putting query string into printname
		{
			printname = text;
		}
		else 
		{
			printname = name + '&#064;' + domain;
		}
		if (subject)
		{
			domain += '?subject=' + subject;
		}
		if (css_class)
		{
			css_class += ' class="' + css_class + '\"';
		}
		
		email = '<a href=\"mailto:' + name + '&#064;' + domain + '\"' + css_class + '\>' + printname + '<\/a>';
		document.write(email);
	/* 
	} 
	*/
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//needed to get off page to pass xhtml 1 strict
function client_data(info)
{
	if (info == 'width')
	{
		width_height_html = '<h5>Current Screen Resolution</h5>';
		width = (screen.availWidth)?screen.availWidth:'';
		height = (screen.availHeight)?screen.availHeight:'';
		width_height_html += '<p>' + width + " x " +
			height + " pixels</p>";
		(width && height)?d.write(width_height_html):'';
	}
	else if (info == 'js' )
	{
		d.write('<p>Javascript is enabled.</p>');
	}
	else if ( info == 'cookies' )
	{
		string = '<h5>Cookies</h5><p>';
		Set_Cookie ( 'cookie_test', 'true', '', '/', '', '' );
		if ( Get_Cookie( 'cookie_test' ) )
		{
			//value = Get_Cookie( 'cookie_test' );
			string += ' Cookies are enabled</p>';
		}
		else {
			string += 'Cookies are disabled</p>';
		}
		d.write( string );
	}
}