<script>
    function toggledisablestate()
    {
        if(document.forms['addrule'].elements['state'].disabled){
            document.forms['addrule'].elements['state'].disabled = false;
            document.forms['addrule'].elements['state'].value = '';
        }else{
            document.forms['addrule'].elements['state'].disabled = true;
            document.forms['addrule'].elements['state'].value = lang('All States');
        }
        
        return false;
    }
    
    function togglecompound()
    {
        if(document.forms['addrule'].elements['level'].value == 1){
            document.forms['addrule'].elements['compound'].disabled = true;
            document.forms['addrule'].elements['compound'].value = 0;
            document.getElementById('trCompound').style.display = 'none';
        }else{
            document.forms['addrule'].elements['compound'].disabled = false;
            document.getElementById('trCompound').style.display = '';
        }
        
        return false;
    }
    
    function toggledisableall(check_checkbox, default_country_code)
    {
        if(check_checkbox){
            document.forms['addrule'].elements['allcountries'].checked = true;
        }
        
        if(document.forms['addrule'].elements['allcountries'].checked){
            document.forms['addrule'].elements['state'].disabled = true;
            document.forms['addrule'].elements['state'].value = lang('All States');
        }else{
            document.forms['addrule'].elements['state'].disabled = false;
            document.forms['addrule'].elements['state'].value = '';
        }
        
        if(document.forms['addrule'].elements['countrycode'].disabled){
            document.forms['addrule'].elements['countrycode'].disabled = false;
            document.forms['addrule'].elements['countrycode'].value = default_country_code;
        }else{
            document.forms['addrule'].elements['countrycode'].disabled = true;
            document.forms['addrule'].elements['countrycode'].value = '_ALL';
        }
        
        if(document.forms['addrule'].elements['all'].disabled){
            document.forms['addrule'].elements['all'].disabled = false;
            document.forms['addrule'].elements['all'].checked = false;
        }else{
            document.forms['addrule'].elements['all'].disabled = true;
            document.forms['addrule'].elements['all'].checked = true;
        }
        
        return false;
    }
</script>

<div id="profile_topcontent" style="padding-bottom:0px;">
    <div class="linkbackbanner" style="width:160px">
        <a href="index.php?fuse=admin&view=TaxOverview"><strong>← [l]Back[/l]</strong><em>[l]Taxes[/l]</em></a>
    </div>
    <br/>
</div>

<form name="addrule" action="index.php?fuse=admin&action=AddTaxRules" method="POST">
    <table>
        <tr>
            <td>
                [l]Country[/l]:&nbsp;&nbsp;
            </td>
            <td>
                <select name=countrycode onChange="if (this.value == '_ALL') toggledisableall(true, '{defaultCountry}');">
                    <option value="_ALL">
                        [l]ALL COUNTRIES[/l]
                    </option>
                    
                    <!-- BEGIN DYNAMIC BLOCK: country -->
                    <option value="{countryCode}" {countrySelected}>
                        {countryName}
                    </option>
                    <!-- END DYNAMIC BLOCK: country -->
                </select>
                <input type="checkbox" style="position:relative; left:2px; top:5px" name="allcountries" onClick="toggledisableall(false, '{defaultCountry}');"\>
                [l]All[/l]
            </td>
        </tr>
        <tr>
            <td>
                [l]State[/l]:
            </td>
            <td>
                <input type=text name=state>
                <input type="checkbox" style="position:relative; left:2px; top:5px" name="all" onClick='toggledisablestate();';>
                [l]All[/l]
                <input type="hidden" name="r_state" value='[l]State must be added[/l]'>
            </td>
        </tr>
        <tr>
            <td>
                [l]Tax Name[/l]:
            </td>
            <td>
                <input type="text" name="name"/>
                <input type="hidden" name="r_name" value='[l]Tax name must be added[/l]' />
            </td>
        </tr>
        <tr>
            <td>
                [l]Tax Level[/l]:
            </td>
            <td>
                <select name="level" onChange="togglecompound();">
                    <option value="1">
                        1
                    </option>
                    <option value="2">
                        2
                    </option>s
                </select>
            </td>
        </tr>
        <tr id="trCompound" style="display:none">
            <td>
                [l]Compound[/l]:
            </td>
            <td>
                <select name="compound">
                    <option value="0">
                        [l]No[/l]
                    </option>
                    <option value="1">
                        [l]Yes[/l]
                    </option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                [l]Use VAT[/l]:
            </td>
            <td>
                <select name="vat">
                    <option value="0">
                        [l]No[/l]
                    </option>
                    <option value="1">
                        [l]Yes[/l]
                    </option>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                [l]Tax[/l]:
            </td>
            <td>
                <input type="text" name="tax" size="6" />
                <strong>
                    %
                </strong>
                <input type="hidden" name="r_tax" value='[l]Tax rate must be added[/l]' />
                <input type="hidden" name="i_tax" value='[l]Tax rate must be a valid number[/l]'>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right">
                <input type="submit" class="button_large" value="[l]Add Tax Rule[/l]" onClick='check(form,form.elements.length);return false;'>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right">
                [l]Insert more[/l]
                <input type="checkbox" name="addanother" style="position:relative; left:2px; top:5px">
            </td>
        </tr>
    </table>
</form>
