// JavaScript Document

var document_divs = document.getElementsByTagName( "DIV" );
var dropdown_boxes = [];
var option_id = 1;

for( var i = 0; i < document_divs.length; i++ )
{
	if( document_divs[ i ].className == "dropdown_holder" )
		dropdown_boxes[ dropdown_boxes.length ] = document_divs[ i ];
	
	if( document_divs[ i ].className == "dropdown_options" )
	{
		document_divs[ i ].style.display = "none";
		document_divs[ i ].id = "dropdown_id_" + option_id;
		option_id++;
	}
}

for( var i = 0; i < dropdown_boxes.length; i++ )
{
	var current_selection = dropdown_boxes[ i ].parentNode.getElementsByTagName( "INPUT" )[ 0 ].value;
	
	dropdown_boxes[ i ].onclick = function()
	{				
		var doc_divs = this.parentNode.getElementsByTagName( "DIV" );
		var style = ( doc_divs[ 3 ].style.display == "none" ? "block" : "none" );
		doc_divs[ 3 ].style.display = style;
		
		if( style == "block" )
		{
			/*
			var rows = doc_divs[ 3 ].getElementsByTagName( "DIV" );
			for( var x = 0; x < rows.length; x++ )
			{
				alert( rows[ x ].id );
				if( rows[ x ].id == dropdown_boxes[ i ].getElementsByTagName( "INPUT" )[ 0 ].value )
					rows[ x ].style.backgroundColor = "#eaf3ff"
				else
					rows[ x ].style.backgroundColor = "#FFF";
			}
			*/
			var document_divs = document.getElementsByTagName( "DIV" );
			var dropdown_boxes = [];
			
			for( var i = 0; i < document_divs.length; i++ )
				if( document_divs[ i ].className == "dropdown_options" )
					if( document_divs[ i ].id != doc_divs[ 3 ].id )
						document_divs[ i ].style.display = "none";

		}
	}
	
	var container_divs = dropdown_boxes[ i ].parentNode.getElementsByTagName( "DIV" );
	var option_divs = container_divs[ 3 ].getElementsByTagName( "DIV" );
	for( var n = 0; n < option_divs.length; n++ )
	{
		if( option_divs[ n ].id == current_selection )
		{
			option_divs[ n ].parentNode.parentNode.getElementsByTagName( "DIV" )[ 1 ].innerHTML = option_divs[ n ].innerHTML;
		}
		
		option_divs[ n ].onclick = function()
		{
			this.parentNode.style.display = "none";
			this.parentNode.parentNode.getElementsByTagName( "DIV" )[ 1 ].innerHTML = this.innerHTML;
			this.parentNode.parentNode.getElementsByTagName( "DIV" )[ 1 ].title = this.innerHTML;
			this.parentNode.parentNode.getElementsByTagName( "INPUT" )[ 0 ].value = this.id;
			
			if( this.title == 'update_assoc' )
			{
				var the_id = this.parentNode.id;
				the_id = +the_id.substr( the_id.length-1 ) + 1;
				
				update_assoc( "dropdown_id_" + the_id, this.id, (the_id == 2 ? 'search_text' : 'search_text_form' ) )
				
				document.getElementById( "dropdown_id_" + the_id ).parentNode.getElementsByTagName( "DIV" )[ 1 ].innerHTML = "Please Choose";
				document.getElementById( "dropdown_id_" + the_id ).parentNode.getElementsByTagName( "DIV" )[ 1 ].title = "Please Choose";
				document.getElementById( "dropdown_id_" + the_id ).parentNode.getElementsByTagName( "INPUT" )[ 0 ].value = 0;
			}
		}
	}
}
