function toggleMap()
{
    var map = document.getElementById("repMap");
    var loc = document.getElementById("dealerLocations");

    if (map.style.display == "none")
    {
        map.style.display = "inline";
        loc.style.width = "150px";
    }
    else
    {
        map.style.display = "none";
        loc.style.width = "95%";
    }
}

function loadDealers(state, intl)
{
    if (state != '')
    {
        if (intl == true)
        {
            $('#dealerCountry').val(state);
            type = 'country';
        }
        else
        {
            $('#dealerState').val(state);
            type = 'state';
        }

        $.ajax({'url': locatorPrefix + type + '/' + state + '/',
                'type': 'POST',
                'data': {},
                'dataType': 'json',
                'success': showResults});
    }
}

function searchZip()
{
    var zip = document.getElementById("searchField").value;
    var radius = document.getElementById("searchRadius").value;

    if (zip != '')
    {
        $.ajax({'url': locatorPrefix + 'radius/' + zip + '/' + radius + '/',
                'type': 'POST',
                'data': {},
                'dataType': 'json',
                'success': showResults});
    }
}

function showResults(json)
{
    output = '';
    $('#dealerProgress').html('');
    if (json.locations.length == 0)
    {
        output = '<p>No locations</p>';
    }
    else
    {
        for (var i = 0; i < json.locations.length; i++)
        {
            if (i % 2 == 0) { output += '</tr><tr>'; }
            output += json.locations[i].replace('<div>Approx <strong></strong> miles away</div>', '');
        }
    }

    $('#dealerLocations').html('<table class="dealerResults"><tr>' + output + '</tr></table>');
}

