

function GetRandomColorPalette()
{
	var pallettes = new Array();
	pallettes[0] = 'google_color_border = "FF4500"; google_color_bg = "FFEBCD"; google_color_link = "DE7008"; google_color_url = "E0AD12"; google_color_text = "8B4513";';
	pallettes[1] = 'google_color_border = "B0E0E6"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_url = "336699"; google_color_text = "333333";';

	var index = new Number;
	index = ( ( pallettes.length )  * (Math.random()));
	index = Math.round(index);
	eval( pallettes[index]);
}

/*
Detect screen width
*/

function screenWidth()
{
	var width;
	width = 0;
	if(screen.width)
	{
		width = screen.width;
	}
	return width;
}

/*
Cookie handler functions
*/

function setCookie( name, value, expires, path, domain, secure  )
{
	var expString = ((expires == null )?'':("; expires=" + expires.toGMTString()));
	var pathString = ((path == null)?'':("; path=" + path));
	var domainString = ((domain == null)?'':("; domain=" + domain));
	var secureString = ((secure == null)?'':("; secure=" + secure));
	document.cookie = name + '=' + escape(value) + expString + pathString + domainString + secureString;
}

function setTempCookie( name, value )
{
	document.cookie = name + "=" + escape(value);
}

function deleteCookie( name )
{
	var Day = 1000 * 60 * 60 * 24;
	var expDate = new Date();
	expDate.setTime( expDate.getTime - Day );
	document.cookie = name + "=null; expires="+ expDate.toGMTString();
}

function getCookie( name )
{
	var value = null;
	var myCookie = " " + document.cookie + ";";
	var searchname = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchname);
	var endOfCookie;
	if( startOfCookie != -1 )
	{
		startOfCookie += searchname.length ;
		endOfCookie = myCookie.indexOf(";", startOfCookie );
		value = unescape(myCookie.substring(startOfCookie, endOfCookie ));
	}
	return value;
}



/*
makes fonts bigger/smaller
*/
function adjustFontSize( amountChange, save )
{

	var adjustment = new Number( amountChange );
	var num_sheets = document.styleSheets.length;
	if(save)
	{
		var expires = new Date();
		var oneYear = ( 1000 * 60 * 60 * 24 * 365 );
		var gmtDate = ( expires.getTime() + oneYear );
		expires = new Date( gmtDate );

		var stored_adjust = new Number( getCookie( "fontAdjust" ));
		if( stored_adjust )
		{
			stored_adjust = ( stored_adjust + adjustment ) ;
			setCookie( 'fontAdjust', stored_adjust, expires );			
		} else {
			setCookie( 'fontAdjust', adjustment, expires );			
		}
	}
	for( var  j = 0; j < num_sheets; j++)
	{

// are there rules ?
		if( document.styleSheets[j].rules )
		{
			if( document.styleSheets[j].rules.length )
			{
				var num_rules = document.styleSheets[j].rules.length;
				for( var  k = 0; k < num_rules ; k++)
				{
					if(	document.styleSheets[j].rules[k].style.fontSize)
					{
						var fontsize = document.styleSheets[j].rules[k].style.fontSize;
						var length = document.styleSheets[j].rules[k].style.fontSize.length ;
						var font_num = new Number(fontsize.substr( 0, length - 2 ));
						var font_unit = fontsize.substr( length - 2, length - 1 );
	
						font_num = font_num + adjustment;
						document.styleSheets[j].rules[k].style.fontSize = font_num + font_unit;
					}
					
				}
			}
		}
//is it netscape ?
		if( document.styleSheets[j].imports )
		{
			if( document.styleSheets[j].imports.length )
			{
				var num_imports = document.styleSheets[j].imports.length;
				for( var  i = 0; i < num_imports ; i++)
				{
					var num_rules = document.styleSheets[j].imports[i].rules.length;
					for( var  k = 0; k < num_rules ; k++)
					{
						if(	document.styleSheets[j].imports[i].rules[k].style.fontSize)
						{
							var fontsize = document.styleSheets[j].imports[i].rules[k].style.fontSize;
							var length = document.styleSheets[j].imports[i].rules[k].style.fontSize.length ;
							var font_num = new Number(fontsize.substr( 0, length - 2 ));
							var font_unit = fontsize.substr( length - 2, length - 1 );
	
							font_num = font_num + ( adjustment ) ;
							document.styleSheets[j].imports[i].rules[k].style.fontSize = font_num + font_unit;
						}
						
					}
				}
			
			}
		}
	}
}


// for the drop down menu

function toggleMenu( ref )
{
	var displayStatus;
	if( document.getElementById(ref).style.display == 'inline' )
	{
		displayStatus = 'none';
	} else {
		displayStatus = 'inline';
	}
	document.getElementById(ref).style.display = displayStatus;
}


function hideDisplay( ref )
{
  	element = document.getElementById(ref);
	element.style.display = 'none'; 

	iframe = element.previousSibling;
	iframe.style.display = 'none';
}

function showDisplay( ref )
{
  	element = document.getElementById(ref);
	iframe = element.previousSibling;

 
	element.style.display = 'inline'; 

	iframe.style.height = element.offsetHeight;
	iframe.style.width = element.offsetWidth;

	iframe.style.top = element.style.top;
	iframe.style.left = element.style.left;

	iframe.style.display = 'inline';
}



/* 
display or hide a box
*/

function toggleDisplay( ref, saveSetting )
{
	var displayStatus;
	if( document.getElementById(ref).style.display == 'inline' )
	{
		displayStatus = 'none';
	} else {
		displayStatus = 'inline';
	}

	document.getElementById(ref).style.display = displayStatus;
	if( saveSetting )
	{
		var sBoxDisplayStatus = getCookie( 'boxDisplayStatus' );
		if( sBoxDisplayStatus )
		{
			var boxDisplayStatus = sBoxDisplayStatus.split(",");
			var was_found = 0;
			for( var i = 0; i < boxDisplayStatus.length; i++)
			{
				pattern = new RegExp( ref );
				if( boxDisplayStatus[i].match( pattern ) )
				{
					boxDisplayStatus[i] = ref + ':' + displayStatus;
					was_found = 1;
					break;
				}
			}
			if((was_found != 1))
			{
				boxDisplayStatus[ boxDisplayStatus.length ] = ref + ':' + displayStatus;	
			}
			sBoxDisplayStatus = boxDisplayStatus.toString();
		} else {
			var boxDisplayStatus = new Array( ref + ':' + displayStatus );
			sBoxDisplayStatus = boxDisplayStatus.toString();
		}  

		oneYear = 1000 * 60 * 60 * 24 * 365;
		expires = new Date();
		var gmtDate = expires.getTime();
		expires = new Date( gmtDate + oneYear) ;
		setCookie( 'boxDisplayStatus', sBoxDisplayStatus, expires );
	}
}

/*
get get cities
*/

function getCities( state_id )
{
	var state_id =  state_id.value;
	var url = 'http://virginiabeats.net/library/getcities.php?state=' + state_id;
	document.getElementById('myframe').src = url;
}




/*
reload the current page
*/

function reloadPage()
{
	self.location.href = self.location.href;
}

/*
set up function for a page load
*/

function pageLoad( page )
{
	document.favicon = "http://virginiabeats.net/favicon.ico";
	var fontadjust = getCookie('fontAdjust');
	if( fontadjust )
	{
		adjustFontSize( fontadjust, 0 );		
	}
	var boxDisplayStatus = getCookie('boxDisplayStatus');
	if( boxDisplayStatus )
	{
		var boxSettings = boxDisplayStatus.split(',');
		for( var jjj = 0; jjj < boxSettings.length; jjj++)
		{
			var settings = boxSettings[jjj].split(':');
			changeStyle( settings[0], 'display', settings[1], '#'  );
		}
	}

// set up screen width
/*
	if( screenWidth() )
	{
		var width;
		width = screenWidth();
		if( width > 1000 )
		{
			changeStyle( 'pagetable', 'width', '100%', '#'  );
			changeStyle( 'header', 'width', '100%', ''  );
			changeStyle( 'wholepage', 'width', '100%', '#'  );
			changeStyle( 'body', 'width', '100%', '#'  );
			changeStyle( 'content', 'width', '80%', '#'  );
			changeStyle( 'sidebar', 'width', '19%', '#'  );


		} else {

// set google parameters based on screen width

		}
	}
	
*/
	var theBgColor = getCookie('theBgColor');
	if( theBgColor )
	{
		colorChange(  theBgColor, window.document );
	}
//	GetRandomColorPalette();
}



/*
Set the background color
*/

function colorChange( colorCell, win, save )
{
	win.body.style.backgroundColor = colorCell;

	if( save )
	{
		var expires = new Date();
		
		var oneYear = ( 1000 * 60 * 60 * 24 * 3610 );
		var gmtDate = ( expires.getTime() + oneYear );
		expires = new Date( gmtDate );
		setCookie( "theBgColor", colorCell, expires, '/' );			
	}
}

/*
Changes color of object 
*/

function swapBgColor( item, color )
{
	item.style.backgroundColor = color;
}








function changeStyle( selector, setting, value, type )
{
// crappy way to do this but there is no way to directly access a css rule by the selector text
	if( type )
	{
		
	} else {
		type = '';
	}

	var num_sheets = document.styleSheets.length;
	var command = new String('');

	selector = type + selector ;
	var Styles = new Array();

	Styles = getStylesBySelector( selector );
//	alert( "Styles length is " + Styles.length );
	var styleToMod;

	while( styleToMod = Styles.pop() )
	{
//		alert( styleToMod.selectorText );
		eval( "styleToMod.style." + setting + "='" + value + "';" );
	}
	

}



function swapButtonIcons( imageId )
{
	if( document.getElementById(imageId).src.match( /dropdown_icon_down/ ) )
	{
		document.getElementById(imageId).src = "http://virginiabeats.net/templates/blueSilver/images/dropdown_icon.gif";
	} else {
		document.getElementById(imageId).src = "http://virginiabeats.net/templates/blueSilver/images/dropdown_icon_down.gif";
	}
}


function swapImage( imgRef, location )
{
	imgRef.src = location;
}






// return all referenceces to a stylesheet matching a given name

function getStylesBySelector( selectorText )
{
	var num_sheets = document.styleSheets.length;
	var matchingRules = new Array();
	var regexp = new RegExp( selectorText );



	for( var  j = 0; j < num_sheets; j++)
	{

// are there rules ?
		if( document.styleSheets[j] )
		{
			var Rules;
			if( document.styleSheets[j].rules )
			{
				Rules = document.styleSheets[j].rules;
			} else {
				if( document.styleSheets[j].cssRules )
				{
					Rules = document.styleSheets[j].cssRules;
				}
    			}

			var num_rules = Rules.length;
			for( var  k = 0; k < num_rules ; k++)
			{
//				alert( Rules[k].selectorText );
// test if rule matches
				if( Rules[k].selectorText )
				{
					if( Rules[k].selectorText.match( regexp ) )
					{
// save reference to rule for pass back to calling function
						matchingRules.push( Rules[k] ) ;
					}
				}
				
			}
		}
//is it netscape ?
		if( document.styleSheets[j].imports )
		{
// iterate through imports
			if( document.styleSheets[j].imports.length )
			{
				var num_imports = document.styleSheets[j].imports.length;
				for( var  i = 0; i < num_imports ; i++)
				{
					var num_rules = document.styleSheets[j].imports[i].rules.length;
					for( var  k = 0; k < num_rules ; k++)
					{
						if(	document.styleSheets[j].imports[i].rules[k].selectorText.match( regexp ) )
						{
							matchingRules.push( document.styleSheets[j].imports[i].rules[k] );
						}
						
					}
				}
			
			}
		}
	}
	return matchingRules;
}












/*
Macromedia crap unfuggled
*/

function MM_findObj(n, d) { //v4.01
	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;
}

function MM_swapImage() { //v3.0
	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];
	}
}

function MM_swapImgRestore() { //v3.0
  	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 MM_preloadImages() { //v3.0
 	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];}
	}
}


function a()
{
	var newWindow = window.open( "library/picker.html", "g", "height=200, width=200, scrollbars" ); 
	newWindow.opener = window;
}
