// copyright (c) 1999  L. David Baron
// based on original by Chris Wilson

function selectStyleSheet( selector )
{
	var i;
 	var title = selector.options[ selector.selectedIndex ].text;

	for ( i = 0; i < document.styleSheets.length; i++ )
	{
		if ( document.styleSheets[ i ].title == title )
			document.styleSheets[ i ].disabled = false;
		else if ( document.styleSheets[ i ].title != "" )
			document.styleSheets[ i ].disabled = true;
	}
}


function UpdateSSList( selector )
{

	function AddIfUnique( ss )
	{
		var i, opt;

		for ( i = 0; i < selector.length; i++ )
		{
			if ( selector.options[i].text == ss.title )
				return;
		}

		opt = document.createElement("OPTION");
		opt.text = ss.title;
		// this is according to DOM-Level-1, I think:
		// selector.add( opt , selector.options[ selector.length - 1] );
		// this is nonstandard: 
		selector.add( opt , selector.length );
		if ( ! ss.disabled )  // only one unique title may be enabled 
			selector.selectedIndex = selector.length - 1;
	}
	
	
	function AddNone()
	{

	    var opt;

		opt = document.createElement("OPTION");
		opt.text = "--NONE--";
		selector.add( opt , 0 );
		selector.selectedIndex = 0;
		
	}
	

	var j;

	selector.options.length = 0; // nonstandard
	AddNone();
	for ( j = 0; j < document.styleSheets.length; j++ )
	{
		if ( document.styleSheets[ j ].title != "" )
			AddIfUnique( document.styleSheets[j] );
	}
}

