﻿function updateShortlist(propertyId, container, image, headline){

    $.ajax({
        type: 'POST',
        url: '/svc/shortlistService.asmx/SaveProperty',
        data: "{'propertyId':" + propertyId + " }",
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(result) {
            if (result.d) result = result.d;
            returnData(result, container, image, headline);
        }
    });
}

function returnData(result,container,image,headline){
    
    if (result != 0) {
        var jContainer = $(container);
     
        jContainer.empty();
        if (image != '') {
          jContainer.append("<img src='" + image + "' class='button' alt='This property is already in your shortlist' />");
        }
        else {
           jContainer.append('<span title="This property is already in your shortlist">Saved Property</span>');
        }
        $(headline).html(result + ' saved properties');
    } else {
        alert("Maximum number of saved properties reached. Please login to save more property");
    }
}

