    function toggleBilling() {
        if($('sameAsBilling').checked)
            $('address-billing').addClassName('disabled');
        else
            $('address-billing').removeClassName('disabled');
                
        $('billing_address').disabled = $('sameAsBilling').checked;
        $('billing_city').disabled = $('sameAsBilling').checked;
        $('billing_state').disabled = $('sameAsBilling').checked;
        $('billing_country').disabled = $('sameAsBilling').checked;
        $('billing_zip').disabled = $('sameAsBilling').checked;
    }
    
    function showHideAffiliates(){ if($('#ca_affiliate').attr('checked') || $('#ca_affiliate').is('[type=hidden]')) $('#affiliate').fadeIn(); else $('#affiliate').fadeOut(); }

    var timeout = false;
    $('#ca_affiliate_partner').keyup(function()
    {
        clearTimeout(timeout);
        if($('#ca_affiliate_partner').val() != "")
        {
            $('#valid').css('color', '#00A4FF').text('Typing...');
            timeout = setTimeout(checkPartner, 750)
        }
        else
        {
            $('#valid').css('color', '#000').text('Start typing to check partner code');
        }
    });
    function checkPartner()
    {
        if($('#ca_affiliate_partner').val().match("[^0-9a-zA-Z]"))
        {
            $('#valid').css('color', 'red').text('You are using a character that isn\'t allowed');
        }
        else
        {
            $('#valid').css('color', 'orange').text('Checking partner code...');
            $('#valid_load').load(site_url('action/partner/' + $('#ca_affiliate_partner').val()));        
        }
    }
    
    function checkCountry()
    {
        if($('#ca_affiliate_country').find(':selected').attr('class') == "other")
            $('#country_alert').fadeIn();
        else
            $('#country_alert').fadeOut();
    }
    
    $(document).ready(function(){
      $('#ca_affiliate').change(showHideAffiliates);
      showHideAffiliates();
      if($('#ca_affiliate_partner').val() != "") checkPartner();
      if($('#ca_affiliate_partner').attr('readonly')) $('#ca_affiliate_partner').css('color', '#999');
      $('#ca_affiliate_country').change(checkCountry);
      checkCountry();
    });
    
    
    
