﻿var organizations = 
[
    { state: 'GA', association: 'Georgia Chess Association' },
    { state: 'KY', association: 'Kentucky Chess Association' },
    { state: 'NY', association: 'New York Chess Association' }
];

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

function addOption(selectbox, value, text )
{
	var optn = document.createElement("option");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

function fillSubCategory(sName, sObj)
{
    // sName is the name of the sub category drop down object.
    // sObj is the main driving drop down object reference. Not the name.
    
    var ele = document.getElementById(sName);
    
    var selected = sObj.options[sObj.selectedIndex].value;
   
    if ( ele !== null )
    {
        removeAllOptions(ele);
        
        addOption(ele, '', '--Choose Chess Association--');
        
        for ( var x=0; x < organizations.length; x++)
        {
            if ( organizations[x].state === selected )
            {
                addOption(ele, organizations[x].association, organizations[x].association);
            }
        }
    }
   
}
