$(document).ready(function(){
	$('input#id_country').change(function(){
		updateState( 'id_state' );
		updateState( 'bid_state' );
		updateState( 'sid_state' );
	});
	updateState( 'id_state' );
	updateState( 'bid_state' );
	updateState( 'sid_state' );
});

function updateState( fieldName )
{
	$('select#' + fieldName + ' option:not(:first-child)').remove();
	var states = countries[$('input#id_country').val()]; // changed from select to input
	if( typeof(states) != 'undefined' )
	{
		for (indexState in states)
		{
			//ie bug fix
			if (indexState != 'indexOf')
				$('select#' + fieldName ).append('<option value="'+indexState+'"'+ (idSelectedCountry == indexState ? ' selected="selected' : '') + '">'+states[indexState]+'</option>');
		}
		//$('p.id_state:hidden').slideDown('slow');
	}
	/*
	else {
		$('p.id_state').slideUp('fast');
	}
	*/
}
