/**
     * generates a row for use in tax settings tables
     *
     * @param string specifies mode of row to generate. Options: rates, bands
     * @param string the key number for the row
     * @param array tax rate settings (used keys: rate, name, country_code, region_code, shipping, index, row_class)
     * */
    function wpsc_build_taxes_row($row_mode = 'rates', $row_key = 0, $tax_rate = false)
    {
        $defaults = array('rate' => null, 'name' => null, 'country_code' => null, 'region_code' => null, 'shipping' => null, 'index' => null, 'row_class' => null);
        $tax_rate = array_merge($defaults, (array) $tax_rate);
        $countries = $this->wpec_taxes->wpec_taxes_get_countries();
        if (!empty($tax_rate['country_code']) && $tax_rate['country_code'] != 'all-markets') {
            $selected_country = array('isocode' => $tax_rate['country_code'], 'country' => wpsc_get_country($tax_rate['country_code']));
        } else {
            $selected_country = array('isocode' => 'all-markets', 'country' => __('All Markets', 'wpsc'));
        }
        ob_start();
        ?>
		<tr id='wpsc-taxes-<?php 
        esc_attr_e($row_mode);
        ?>
-row-<?php 
        esc_attr_e($row_key);
        ?>
' data-row-key="<?php 
        esc_attr_e($row_key);
        ?>
" class='wpsc-tax-<?php 
        esc_attr_e($row_mode);
        ?>
-row <?php 
        esc_attr_e($tax_rate['row_class']);
        ?>
'>

			<?php 
        if ($row_mode == 'bands') {
            // BAND NAME
            ?>
				<td>
					<input type='hidden' id='band-index-<?php 
            esc_attr_e($row_key);
            ?>
' name="wpsc_options[wpec_taxes_bands][<?php 
            esc_attr_e($row_key);
            ?>
][index]" value="<?php 
            esc_attr_e($row_key);
            ?>
" />
					<input id='band-name-<?php 
            esc_attr_e($row_key);
            ?>
' name="wpsc_options[wpec_taxes_bands][<?php 
            esc_attr_e($row_key);
            ?>
][name]" class='taxes-band' type='text' value='<?php 
            esc_attr_e($tax_rate['name']);
            ?>
' />
				</td>
			<?php 
        }
        ?>

			<td>
				<?php 
        // MARKET COUNTRY SELECT
        echo $this->wpec_taxes_build_select_options($countries, 'isocode', 'country', $selected_country, array('id' => $row_mode . "-country-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][country_code]", 'class' => 'wpsc-taxes-country-drop-down', 'data-row-key' => $row_key, 'data-row-mode' => $row_mode));
        // MARKET REGION SELECT
        if (!empty($tax_rate['region_code'])) {
            $regions = $this->wpec_taxes->wpec_taxes_get_regions($tax_rate['country_code']);
            if (!empty($regions)) {
                if ($tax_rate['region_code'] == 'all-markets') {
                    $region_name = 'All Markets';
                } else {
                    $region = new WPSC_Region($tax_rate['country_code'], $tax_rate['region_code']);
                    $region_name = $region->get_name();
                }
                echo $this->wpec_taxes_build_select_options($regions, 'region_code', 'name', array('region_code' => $tax_rate['region_code'], 'name' => $region_name), array('id' => $row_mode . "-region-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][region_code]", 'class' => 'wpsc-taxes-region-drop-down'));
            }
        }
        // if
        ?>
				<img src="<?php 
        echo esc_url(wpsc_get_ajax_spinner());
        ?>
" class="ajax-feedback" title="" alt="" />
			</td>


			<td><?php 
        // TAX RATE
        ?>
				<input type='text' size='3' id="<?php 
        esc_attr_e($row_mode);
        ?>
-rate-<?php 
        esc_attr_e($row_key);
        ?>
" name="wpsc_options[wpec_taxes_<?php 
        esc_attr_e($row_mode);
        ?>
][<?php 
        esc_attr_e($row_key);
        ?>
][rate]" class="taxes-<?php 
        esc_attr_e($row_mode);
        ?>
" value="<?php 
        esc_attr_e($tax_rate['rate']);
        ?>
" /> %
			</td>

			<?php 
        if ($row_mode == 'rates') {
            // TAX SHIPPING ?
            ?>
				<td>
					<label>
						<input type='checkbox' id="shipping-<?php 
            esc_attr_e($row_key);
            ?>
" name="wpsc_options[wpec_taxes_<?php 
            esc_attr_e($row_mode);
            ?>
][<?php 
            esc_attr_e($row_key);
            ?>
][shipping]" class="taxes-<?php 
            esc_attr_e($row_mode);
            ?>
" <?php 
            checked($tax_rate['shipping'] == 1);
            ?>
 />
						<?php 
            _e('Apply to Shipping', 'wpsc');
            ?>
					</label>
				</td>
			<?php 
        }
        ?>

			<?php 
        // ACTIONS
        ?>
			<td>
				<a tabindex="-1" title="<?php 
        _e('Delete Field', 'wpsc');
        ?>
" class="button-secondary wpsc-button-round wpsc-button-minus wpsc-taxes-<?php 
        esc_attr_e($row_mode);
        ?>
-delete" id="wpsc-taxes-<?php 
        esc_attr_e($row_mode);
        ?>
-delete-<?php 
        esc_attr_e($row_key);
        ?>
" href="#"><?php 
        echo _x('&ndash;', 'delete item', 'wpsc');
        ?>
</a>
				<a tabindex="-1" title="<?php 
        _e('Add Field', 'wpsc');
        ?>
" class="button-secondary wpsc-button-round wpsc-button-plus wpsc-taxes-<?php 
        esc_attr_e($row_mode);
        ?>
-add" href="#"><?php 
        echo _x('+', 'add item', 'wpsc');
        ?>
</a>
			</td>

		</tr>
		<?php 
        return ob_get_clean();
    }
function wpsc_get_region($region_id)
{
    $country_id = WPSC_Countries::get_country_id_by_region_id($region_id);
    $wpsc_region = new WPSC_Region($country_id, $region_id);
    return $wpsc_region->get_name();
}