// JavaScript Document
YAHOO.namespace('coindustry.dom');

function changeSelectHidden(select_name) 
{
	var selectPrimaryBox = document.getElementById(select_name);
	var selectPrimaryBoxIndex = selectPrimaryBox.selectedIndex;
	var selectPrimaryBoxValue = selectPrimaryBox.options[selectPrimaryBoxIndex].value;
	
	for (option in selectPrimaryBox.options)
	{
		var secondayBox = document.getElementById(select_name + '_' + option);
		YAHOO.util.Dom.addClass(secondayBox, 'hidden');
	}
	
	var selectSecondaryBox = document.getElementById(select_name + '_' + selectPrimaryBoxValue);
	YAHOO.util.Dom.removeClass(selectSecondaryBox, 'hidden');
}

function changeSelectOther(select_name, secondary_prefix, other_name)
{
	var selectPrimaryBox = document.getElementById(select_name);
	var selectPrimaryBoxIndex = selectPrimaryBox.selectedIndex;
	var selectPrimaryBoxValue = selectPrimaryBox.options[selectPrimaryBoxIndex].value;

	var selectSecondaryBox = document.getElementById(secondary_prefix + '_' + selectPrimaryBoxValue);
	var selectSecondaryBoxIndex = -1;
	var selectSecondaryBoxValue = "";
	if (selectSecondaryBox)
	{
		selectSecondaryBoxIndex = selectSecondaryBox.selectedIndex;
		selectSecondaryBoxValue = selectSecondaryBox.options[selectSecondaryBoxIndex].value;
	}
	
	var other = document.getElementById(other_name);
	other.value = selectSecondaryBoxValue;
}

YAHOO.coindustry.dom.init = function()
{
	YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('select_primary','select'), 'change', selectChangePrimary);
	YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('select_other','select'), 'change', selectChangeOther);
	
	function selectChangePrimary(e)
	{
		changeSelectHidden('coindustry');
		changeSelectOther('coindustry', 'cosubindustry', primary_industry_fieldname);
	}
	
	function selectChangeOther(e)
	{
		changeSelectOther('coindustry', 'cosubindustry', primary_industry_fieldname);
	}
};

YAHOO.util.Event.addListener(window, 'load', function() { YAHOO.coindustry.dom.init(); });

