$(document).ready(function()
{
    $("#enter").validate(
        {
            submitHandler: function(form)
            {
                $("#res_country").empty();
                $("#res_city").empty();
                $("#res_lat").empty();
                $("#res_lng").empty();
                $("#res_isp").empty();
                $("#res_countrycode").empty();
                $("#res_zip").empty();
                $("#res_organisation").empty();
                $("#output").text('');

                $.getJSON("inc/geoip_json.php", { adr: $("#host").val() }, function(json)
                {
                    $("#res_city").text(json.city);
                    $("#res_country").text(json.country);
                    $("#res_lat").text(json.lat);
                    $("#res_lng").text(json.lng);
                    $("#res_isp").text(json.isp);
                    $("#res_organisation").text(json.organisation);
                    $("#res_zip").text(json.zip);
                    $("res_countrycode").text(json.country_code);
                    $("#gmap").attr("src", "http://maps.google.com/staticmap?center="+json.lat+","+json.lng+"&zoom=8&size=760x210&markers="+json.lat+","+json.lng+",red&key=ABQIAAAA6Ny0koaq37RGot9LPKIyFxR6zEGq7RIjm2j2wcK8ksKyeZbTHRR0VknF-BQYAHGO7yGr2nSEGFyXVA");
                });
            },
            focusInvalid: false,
            focusCleanup: true,
            rules:
            {
                adr:
                {
                    required: true,
                    minlength: 4,
                    maxlength: 239
                }
            },
            messages:
            {
                adr:
                {
                    required: "Enter the ip or domain",
                    minlength: "Minimal length for domain is 4",
                    maxlength: "Maximum length is 239"
                }
            },
            errorPlacement: function(error, element)
            {
                $("#output").empty();
                error.appendTo($("#output"));
            }
        });
});
