/*
function setForm() {
	var selectCollection = document.getElementsByTagName( 'select' );
	for ( var i = 0; i < selectCollection.length; i++ ) {
		selectReplacement( selectCollection[ i ] );
	}
}

myWindow.doAddOnloadListener( setForm );

function selectReplacement( obj ) {
	var ul = document.createElement( 'ul' );
	var optionCollection = obj.options;
	var selectedOption = 0;

	ul.className = 'select-replacement';

	if ( window.attachEvent ) {
		ul.onmouseover = function() {
			ul.className += ' selHover';
		}
		ul.onmouseout = function() {
			ul.className = ul.className.replace( new RegExp( " selHover\\b" ), '' );
		}
	}

	for ( var i = 0; i < optionCollection.length; i++ ) {
		if ( optionCollection[ i ].selected ) {
			selectedOption = i;
			break;
		}
	}

	for ( var i = 0; i < optionCollection.length; i++ ) {
		var li = document.createElement( 'li' );
		var text = document.createTextNode( optionCollection[ i ].text );
		li.appendChild( text );
		li.selIndex = optionCollection[ i ].index;
		li.selectID = obj.id;
		li.onclick = function() {
			setVal( this.selectID, this.selIndex );
			selectMe( this );
		}

		if ( i == selectedOption ) {
			li.className = 'selected';
		}
		if ( window.attachEvent ) {
			li.onmouseover = function() {
				this.className += ' selHover';
			}
			li.onmouseout = function() {
				this.className = this.className.replace( new RegExp( " selHover\\b" ), '' );
			}
		}
		ul.appendChild( li );
	}
	obj.parentNode.appendChild( ul );
}

function selectMe( obj ) {
	var liCollection = obj.parentNode.getElementsByTagName( 'li' );
	for ( var i = 0; i < liCollection.length; i++ ) {
		if ( liCollection[ i ] != obj ) {
			liCollection[ i ].className = '';
		} 
		else { 
			liCollection[ i ].className = 'selected';
		}
	}
}

function setVal( objID, selIndex ) {
	var obj = document.getElementById( objID );
	obj.selectedIndex = selIndex;
}
*/

function selectReplacement( obj ) {
	obj.className += ' replaced';
	var ul = document.createElement( 'ul' );
	ul.className = 'select-replacement';
	var opts = obj.options;
	for ( var i=0; i < opts.length; i++ ) {
		var selectedOpt;
		if ( opts[i].selected ) {
			selectedOpt = i;
			break;
		} else {
			selectedOpt = 0;
		}
	}
	for ( var i = 0 ; i < opts.length; i++ ) {
		var li = document.createElement( 'li' );
		var txt = document.createTextNode( opts[ i ].text );
		li.appendChild( txt );
		li.selIndex = opts[ i ].index;
		li.selectID = obj.id;
		li.onclick = function() {
			selectMe( this );
		}
		if ( i == selectedOpt ) {
			li.className = 'selected';
			li.onclick = function() {
				this.parentNode.className += ' selectOpen';
				this.onclick = function() {
					selectMe( this );
				}
			}
		}
		if ( window.attachEvent ) {
			li.onmouseover = function() {
				this.className += ' hover';
			}
			li.onmouseout = function() {
				this.className = this.className.replace( new RegExp( " hover\\b" ), '' );
			}
		}
		ul.appendChild( li );
	}
	obj.parentNode.insertBefore( ul, obj );
}

function selectMe( obj ) {
	var lis = obj.parentNode.getElementsByTagName( 'li' );
	for ( var i = 0; i < lis.length; i++ ) {
		if ( lis[ i ] != obj ) {
			lis[ i ].className = '';
			lis[ i ].onclick = function() {
				selectMe( this );
			}
		} else {
			setVal( obj.selectID, obj.selIndex );
			obj.className = 'selected';
			obj.parentNode.className = obj.parentNode.className.replace( new RegExp( " selectOpen\\b" ), '' );
			obj.onclick = function() {
				obj.parentNode.className += ' selectOpen';
				this.onclick = function() {
					selectMe( this );
				}
			}
		}
	}
}

function setVal( objID, val ) {
	var obj = document.getElementById( objID );
	obj.selectedIndex = val;
}

function setForm() {
  var s = document.getElementsByTagName( 'select' );
  for ( var i = 0; i < s.length; i++ ) {
	  selectReplacement( s[ i ] );
	}
}

myWindow.doAddOnloadListener( setForm );
