
function setLink(data) {
    var obj = jQuery.parseJSON(data);
    for (i = 0; i < obj.agents.length; i++) {
        $("#a_" + obj.agents[i].accountid).children().children(".beta").children(".name").after("<p><a href=\"http://property.email4property.co.uk/estate-agents/" + obj.agents[i].haid + "/" + obj.agents[i].hbid + "/" + obj.agents[i].type + "\">View Property Listings</a></p>");
    }
}


function getPropUrl() {

    var ids = [];
    var hids = [];
    var xcoord = CheckXYlength($('#TownXY').val().split(",")[0]);
    var ycoord = CheckXYlength($('#TownXY').val().split(",")[1]);
    var LtLngArr = OSGridToLatLong(xcoord, ycoord).split(',');

    var NExcoord = NECoord(($('#TownXY').val().split(",")[0]));
    var NEycoord = NECoord(($('#TownXY').val().split(",")[1]));
    var LtLngNEArr = OSGridToLatLong(NExcoord, NEycoord).split(',');

    var SWxcoord = SWCoord(($('#TownXY').val().split(",")[0]));
    var SWycoord = SWCoord(($('#TownXY').val().split(",")[1]));
    var LtLngSWArr = OSGridToLatLong(SWxcoord, SWycoord).split(',');



    $("#agents_listing").find('li').each(function (i, el) {
        var t = $("#" + this.id).children().children(".alpha").children(".type").text() == "Lettings" ? "lettings" : "sales";
        ids.push(this.id.replace("a_", "") + "-" + t);
    })

    //post data to proxy
    $.ajax({
        type: 'POST',
        url: '/ajax/getHomeflowBranchData.aspx?sw_lat=' + jQuery.trim(LtLngSWArr[0]) + '&sw_lng=' + jQuery.trim(LtLngSWArr[1]) + '&ne_lat=' + jQuery.trim(LtLngNEArr[0]) + '&ne_lng=' + jQuery.trim(LtLngNEArr[1]) + '&ids=' + ids,
        data: "",
        success: setLink,
        dataType: 'json;',
        contentType: "application/json"
    });
}
