﻿//========================================================
//  Custom QTip Error Class
//========================================================
$.fn.qtip.styles.error = { // Last part is the name of the style
    name: 'red' // Inherit the rest of the attributes from the preset blue style
};

//========================================================
//  Custom QTip Classes For Listings
//========================================================
$.fn.qtip.styles.listingSave = { // Last part is the name of the style
   name: 'blue' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.listingSaved = { // Last part is the name of the style
   background: '#C2D979',
   color: 'darkgreen',
   border: {
      color: '#A2D959'
   },
   name: 'blue' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.listingRemove = { // Last part is the name of the style
   background: '#E5F6FE',
   color: '#99B7F5',
   border: {
      color: '#99B7F5'
   },
   name: 'red' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.listingRemoved = { // Last part is the name of the style
   name: 'red' // Inherit the rest of the attributes from the preset blue style
};


//========================================================
//  Custom QTip Classes For Searches
//========================================================
$.fn.qtip.styles.searchSave = { // Last part is the name of the style
    name: 'blue' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.searchSaved = { // Last part is the name of the style
    background: '#C2D979',
    color: 'darkgreen',
    border: {
        color: '#A2D959'
    },
    name: 'blue' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.searchRemove = { // Last part is the name of the style
    background: '#E5F6FE',
    color: '#99B7F5',
    border: {
        color: '#99B7F5'
    },
    name: 'red' // Inherit the rest of the attributes from the preset blue style
};

$.fn.qtip.styles.searchRemoved = { // Last part is the name of the style
    name: 'red' // Inherit the rest of the attributes from the preset blue style
};





$(function() {
    ReloadSavedListings();
});



//========================================================
//  Reload Saved Listings from database
//========================================================
var SavedListings = null;
function ReloadSavedListings() {
    
    if (CacheObject == null ||
        CacheObject.ListingIds == null) {
        return;
    }

    var querystring = "action=GetSavedItems";
    querystring += "&ListingIds=" + escape(CacheObject.ListingIds.join(","));

    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;
    //add a timestamp to the call, to prevent caching
    var currentTime = new Date();
    var timestamp = { ts: currentTime.getTime() };
    
    SavedListings = null;
    
    $.get(URL, timestamp, function(data) {
        try {
            SavedListings = data;

            //update icons for saved listings
            RefreshSavedListingsIcons();

            //display private notes, on details page only
            if (IsDetailsPage()) {
                RefreshPrivatePhotos();
                RefreshPrivateNotes();
            }
            else {
                ReplaceThumbWithPrivatePhoto();
            }
        }
        catch (err) {
            alert("err:" + err.message);
        }
    });
}



//========================================================
//  Update Icons for saved listings
//========================================================
function RefreshSavedListingsIcons() {
    
    if (SavedListings == null) {
        return;
    }
    
    // create an array with the saved listings
    var SavedListingIds = new Array();
    $(SavedListings).find("callstring").each(function() {
        SavedListingIds.push($(this).text());
    });
    
    for (var x = 0; x < CacheObject.ListingIds.length; x++) {

        var LID = CacheObject.ListingIds[x];
        var IsSavedListing = (jQuery.inArray(LID, SavedListingIds) > -1);

        ChangeListingSaveIcon(LID, IsSavedListing);
    }
}


//========================================================
//  Save Listing
//========================================================
function SaveListing(CallString)
{
    var LastAction = String.format("SaveListing(\"{0}\");", CallString);
    AppendLastActionCookie(LastAction);

    var EntryType = "listing";
    var Channel = $("#Channel").val(); //from the listing result page

    var querystring = "type=SaveItem";
    querystring += "&entrytype=" + escape(EntryType);
    querystring += "&channel=" + escape(Channel);
    querystring += "&callstring=" + escape(CallString);

    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemDialog.aspx?" + querystring;

    ShowDialog(URL, 0, 0, VerifySaveEntryForm);
        
}

function SubmitSaveListing(CallString)
{    
    var querystring  = "";
        querystring += "entrytype=listing";
        querystring += "&channel=" + escape($("#Channel").val());
        querystring += "&callstring=" + escape(CallString);
        querystring += "&openhousealert=" + $('input[name=se_openhousealert]').is(':checked');
        querystring += "&pricereductionalert=" + $('input[name=se_pricereductionalert]').is(':checked');
        querystring += "&enablealerts=" + $('input[name=se_enable_email_alert]').is(':checked');
        querystring += "&action=save";


    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") 
    {
        CloseDialog();
        
        // trigger the Save event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.Save);
        
        ChangeListingSaveIcon(CallString, true);

        //clear tooltip
        if (typeof $("#folico-" + CallString).data('qtip') == 'object') {
            $("#folico-" + CallString).qtip("destroy");
            
        }
        ShowToolTip("#folico-" + CallString, 'listingSaved', CreateToolTipContent('listingSaved','Listing Saved'));
        window.setTimeout(function() {
            ReloadSavedListings();
            RemoveAction(String.format("SaveListing(\"{0}\");", CallString));
            ExecuteLastAction();
        }, 2000);
    }
    else if(response == "login") 
    {
        Login();
    }
    else {
        DisplayModalError(response);
    }     
}



//========================================================
//  Edit Listing
//========================================================
function EditListing(CallString) {
    var LastAction = String.format("EditListing(\"{0}\");", CallString);
    BuildLastActionCookie(LastAction);

    var EntryType = "listing";
    var Channel = $("#Channel").val(); //from the listing result page

    var querystring = "type=ModifyItem";
    querystring += "&entrytype=" + escape(EntryType);
    querystring += "&callstring=" + escape(CallString);

    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemDialog.aspx?" + querystring;

    ShowDialog(URL, 0, 0, VerifySaveEntryForm);

}

function SubmitEditListing(CallString) {
    var querystring = "";
    querystring += "entrytype=listing";
    querystring += "&callstring=" + escape(CallString);
    querystring += "&openhousealert=" + $('input[name=se_openhousealert]').is(':checked');
    querystring += "&pricereductionalert=" + $('input[name=se_pricereductionalert]').is(':checked');
    querystring += "&enablealerts=" + $('input[name=se_enable_email_alert]').is(':checked');
    querystring += "&action=edit";


    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") {
        CloseDialog();

        // trigger the EditListing event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.Edit);
        
        ChangeListingSaveIcon(CallString, true);

        //clear tooltip
        if (typeof $("#folico-" + CallString).data('qtip') == 'object') {
            $("#folico-" + CallString).qtip("destroy");
        }
        
        ShowToolTip("#editico-" + CallString, 'listingSaved', CreateToolTipContent('listingSaved', 'Listing Updated'));
        window.setTimeout(function() {
            ReloadSavedListings();
        }, 2000);
    }
    else if (response == "login") {
        Login();
    }
    else {
        DisplayModalError(response);
    }
}




//========================================================
//  Delete Listing
//========================================================
function DeleteListing(CallString) 
{
    var LastAction = String.format("DeleteListing(\"{0}\");", CallString);
    BuildLastActionCookie(LastAction);
    
    var querystring  = "action=delete";
    querystring += "&EntryType=listing";
    querystring += "&CallString=" + escape(CallString);


    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") {
        ClearLastActionCookie();

        // trigger the DeleteListing event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.Delete);

        if (IsSavedListingsResult()) {
            var SEOQuery = NormalizeSEOQuery(CacheObject.SEOQuery).toLowerCase();
            if ($('#expired-' + CallString).length) 
            {
                //clear tooltip
                if (typeof $("#expired-" + CallString).data('qtip') == 'object') {
                    $("#expired-" + CallString).qtip("destroy");
                }
                
                //reload expired listings list
                ReloadExpiredList(SEOQuery);
            }
            else 
            {
                //clear tooltip
                if (typeof $("#folico-" + CallString).data('qtip') == 'object') {
                    $("#folico-" + CallString).qtip("destroy");
                }

                //reload result list
                ReloadList(SEOQuery);
            }
        }
        else {
            ChangeListingSaveIcon(CallString, false);

            //clear tooltip
            if (typeof $("#folico-" + CallString).data('qtip') == 'object') {
                $("#folico-" + CallString).qtip("destroy");
            }
            
            ShowToolTip("#folico-" + CallString, 'listingRemoved', CreateToolTipContent('listingRemoved','Listing Removed'));
            window.setTimeout(function() {
                ReloadSavedListings();
            }, 2000);
        }
        
    }
    else if(response == "login") 
    {
        Login();
    }
    else {
        ShowToolTip("#folico-" + CallString, 'error', CreateToolTipContent('error',response));
    }  
}




//========================================================
//
//        PRIVATE NOTES
//
//========================================================
function RefreshPrivateNotes() {
    
    if ($(SavedListings).find("savedlisting").length == 0) {
        $('#saved_notes_data').hide();
        $('#saved_notes_data').html = "";
        return;
    }

    // create an array with the saved listings
    $(SavedListings).find("savedlisting").each(function() {
        RefreshPrivateNote (this);
    });
}

function RefreshPrivateNote(SavedListing) {
    var overlay = $("<div id='saved-notes-overlay'></div>");
    $('#saved_notes_data').append(overlay);
    overlay.css({ height: $('#saved_notes_data').height(), width: $('#saved_notes_data').width() });
    
    var listingId = $(SavedListing).find("callstring").text();
    var URL = "/Reno/MyPortfolio/NotesPhotos/PrivateNotes.aspx?ListingId=" + escape(listingId);

    $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            overlay.remove();
            $.log("Json Error Message: error(" + errorThrown + ") \"" + textStatus + "\"");
        },
        success: function(response) {

            if (response.trim() != "") {
                $('#saved_notes_data').html(response);
                $('#saved_notes_data').show();
            }
            else {
                $('#saved_notes_data').html("");
                $('#saved_notes_data').hide();
            }
        }
    });
}


//========================================================
//  Cancel Note
//========================================================
function CancelNote() {
    $("#new_note_wrapper").hide();
    $(".edit-note").hide();
    $(".saved_note a").show();
    $("#addNoteBtn").show();
}




//========================================================
//  Save Private Note
//========================================================

// Show Add Private Note Box
function AddNote(NoteId) {
    // close any other opened for edit notes
    CancelNote();

    $("#addNoteBtn").hide();

    // make sure the new note template is empty
    $('#new_note_content').val("");

    $("#new_note_wrapper").show();
}


function SaveNote(CallString, Title) {
    //remove special characters from title
    Title = Title.replace(/[^a-zA-Z 0-9]+/g, '');

    var LastAction = String.format("SaveNote(\"{0}\", \"{1}\");", CallString, Title);
    BuildLastActionCookie(LastAction);

    var querystring = "CallString=" + escape(CallString);
    querystring += "&title=" + escape(Title.trim());
    querystring += "&EntryType=listing";
    querystring += "&action=savenote";


    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;
    
    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") {
        ClearLastActionCookie();
        
        // trigger the SaveNote event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.SaveNote);
        
        CancelNote();
        ReloadSavedListings();
    }
    else if (response == "login") {
        Login();
    }
    else if (response == "savelisting") {
        SaveListing(CallString);
    }
    else {
        ClearLastActionCookie();
        alert(response);
    }
}


//========================================================
//  Edit Private Note
//========================================================
function EditNote(NoteId) {
    // close any other opened notes for edit
    CancelNote();
    
    // copy the note text into the designated textarea
    var currentNoteText = $("#note_text" + NoteId).text();
    $("#edit_note_content" + NoteId).val(currentNoteText);
    
    //hide note text and open up the editing container
    $("#note_text" + NoteId).hide();
    $("#saved_note_wrapper" + NoteId).show();
}

function UpdateNote(CallString, NoteId, Title) {

    var LastAction = String.format("EditNote(\"{0}\", \"{1}\", \"{2}\");", CallString, NoteId, Title);
    BuildLastActionCookie(LastAction);

   
    var querystring = "callstring=" + escape(CallString);;
    querystring += "&noteid=" + escape(NoteId);
    querystring += "&title=" + escape(Title.trim());
    querystring += "&EntryType=listing";
    querystring += "&action=editNote";


    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            ClearLastActionCookie();
            $.log("Json Error Message: error(" + errorThrown + ") \"" + textStatus + "\"");
        },
        success: function(response) {

            if (response == "success") {
                ClearLastActionCookie();

                // trigger the EditNote event, for the registered controls to update themselves
                $.event.trigger(RenoEvent.EditNote);

                
                ReloadSavedListings();
            }
            else if (response == "login") {
                Login();
            }
            else {
                ClearLastActionCookie();
                alert(response);
            }
        }
    });
}

//========================================================
//  Delete Private Note
//========================================================
function DeleteNote(CallString, NoteId) {
    var LastAction = String.format("DeleteNote(\"{0}\", \"{1}\");", CallString, NoteId);
    BuildLastActionCookie(LastAction);

    var querystring = "action=deletenote";
    querystring += "&CallString=" + escape(CallString);
    querystring += "&NoteId=" + escape(NoteId);
    querystring += "&EntryType=listing";
    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") {
        ClearLastActionCookie();

        // trigger the DeleteNote event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.DeleteNote);
        
        ReloadSavedListings();
    }
    else if (response == "login") {
        Login();
    }
    else {
        ClearLastActionCookie();
        alert(response);
    }  
}



//========================================================
//
//        PRIVATE PHOTOS
//
//========================================================

//object used for enabling multi-file uploads
var MultiFileSelector = null;

function RefreshPrivatePhotos() {

    if ($(SavedListings).find("savedlisting").length == 0) {

        if (typeof (detailPageCarousel) !== 'undefined') {
            detailPageCarousel.clearAllPrivateImages();
        }
        
        return;
    }

    // create an array with the saved listings
    $(SavedListings).find("savedlisting").each(function() {
        var idlisting = $(this).find("callstring").text();
        var images = new Array();

        $(this).find("privatephotos privateitem").each(function() {
            var imageUrl = $(this).find("url").text();
            if (imageUrl != "") {
                images.push(imageUrl);
            }
        });

        // images are returned in the order they have been created
        images.reverse();

        AddToCarousel(images, idlisting);
    });
}


//========================================================
//  Replace the thumbnail image with the latest private photo
//========================================================
function ReplaceThumbWithPrivatePhoto() {
    return;
//    if ($(SavedListings).find("savedlisting").length == 0) {
//        return;
//    }

//    // iterate through each saved listing
//    $(SavedListings).find("savedlisting").each(function() {

//        // photos are retrieved in chronological order, so take the most recent one
//        var imageUrl = $(this).find("privatephotos privateitem url:last").text();

//        if (imageUrl != "") {

//            //identify the listing in the search results page
//            var idlisting = $(this).find("callstring").text();
//            $("#THUM-" + idlisting).attr("src", imageUrl);
//        }
//    });
}


//========================================================
//  Cancel Upload
//========================================================
function CancelUpload() {
    $(".uploadBox").hide();
    $(".uploadBox input:file").remove();
    $("#selectedFiles").html("");
    $("#uploadForm #loading").hide();
    $("#addPhotosBtn").show();
}




//========================================================
//  Save Private Photos
//========================================================

// Show Add Private Photo Box
function AddPhotos() {
    CancelUpload();

    if (MultiFileSelector == null) {
        // Create an instance of the multiSelector class, pass it the output target and the max number of files
        var MultiFileSelector = new MultiSelector(document.getElementById('selectedFiles'), 3);

        $("#uploadForm").prepend('<input type="file" id="fileUploadElement">');
        MultiFileSelector.addElement(document.getElementById('fileUploadElement'));
    }
    else {
        MultiFileSelector.reset();
    }

    $("#addPhotosBtn").hide();

    // clear all input type="file" controls
    MultiFileSelector.reset();
    
    // dynamically create a new input type=file control

    $(".uploadBox").show();
}




function Upload() {
    var LastAction = String.format("Upload();");
    BuildLastActionCookie(LastAction);

    // listing id
    var CallString = $("#uploadForm #CallString").val();
    $("#loading")
		.ajaxStart(function() {
		    $(this).show();
		})
		.ajaxComplete(function() {
		    $(this).hide();
		});

		$.ajaxFileUpload
		(
			{
			    url: '/reno/myportfolio/notesphotos/uploadphoto.aspx?CallString=' + escape(CallString),
			    secureuri: false,
			    formElementId: 'uploadForm',
			    dataType: 'xml',
			    success: function(data, status) {
			        if ((typeof (data.error) == 'undefined') && (data.error != '')) {
			            var response = "" + data + "";
			            var status = $(response).find("status:first").text();

			            if (status == "success") {
			                DisplayPhotosInCarousel(response);
			                ClearLastActionCookie();
			                CancelUpload();

			                // trigger the SavePhoto event, for the registered controls to update themselves
			                $.event.trigger(RenoEvent.SavePhoto);

			            }
			            else if (status == "login") {
			                Login();
			            }
			            else if (status == "savelisting") {
			                //SaveListing(CallString);
			                alert("Listing needs to be saved first!");
			            }
			            else {
			                alert("err: " + status);
			                ClearLastActionCookie();
			                CancelUpload();
			            }

			        } else {
			            alert("data.msg: " + data.msg);
			        }
			    },
			    error: function(data, status, e) {
			        ClearLastActionCookie();
			        alert('data: ' + data + '; status: ' + status + '; e: ' + e);
			    }
			}
		)

    return false;
}


//========================================================
//  Checks to see if there valid photos to pe added into
//  the listing detail carousel, and adds them
//========================================================
function DisplayPhotosInCarousel(xml) {

    var idlisting = $(xml).find("idlisting").text();
    var errorMessage = "";

    var newDetailsPhotoArr = new Array();
    $(xml).find("photo").each(function() {
        var photoStatus = $(this).find('status').text();
        if (photoStatus == "success") {
            newDetailsPhotoArr.push($(this).find('url').text());
        }
        else {
            errorMessage += "File: " + $(this).find('file').text() + "\n";
            errorMessage += "Reason: " + photoStatus + "\n\n";
        }
    });

    newDetailsPhotoArr.reverse(); 
    AddToCarousel(newDetailsPhotoArr, idlisting);

    if (errorMessage != "") {
        alert("Some files could not be uploaded: \n\n" + errorMessage);
    }
}

function AddToCarousel(images, idlisting) {
    if (typeof (detailPageCarousel) === 'undefined' || images.length == 0) {
        return;
    }
    
    detailPageCarousel.prependImages(images, idlisting);

    //copy all existing images in detailsPhotoArr into a temp array
    for (i = 0; i < detailsPhotoArr.length; i++) {
        images.push(detailsPhotoArr[i]);
    }

    //rebuild detailsPhotoArr
    detailsPhotoArr = images;

    if (detailsPhotoArr.length >= 1) {
        $('.carousel .thumbs').show();
        $('.carousel .previous').show();
        $('.carousel .next').show();
        detailPageCarousel.refreshDeleteButtons();
    }
    else {
        $('.carousel .thumbs').hide();
        $('.carousel .previous').hide();
        $('.carousel .next').hide();
    }
}


//========================================================
//  Delete Private Photo
//========================================================
function DeletePhoto(CallString, PhotoUrl) {
    var LastAction = String.format("DeletePhoto(\"{0}\", \"{1}\");", CallString, PhotoUrl);
    BuildLastActionCookie(LastAction);

    var querystring = "action=deletephoto";
    querystring += "&CallString=" + escape(CallString);
    querystring += "&PhotoUrl=" + escape(PhotoUrl);
    querystring += "&EntryType=listing";
    var URL = "/Reno/MyPortfolio/AjaxCalls/SavedItemAction.aspx?" + querystring;

    var response = $.ajax({
        type: "GET",
        url: URL,
        data: "{}",
        async: false
    }).responseText;

    if (response == "success") {
        ClearLastActionCookie();

        // trigger the DeletePhoto event, for the registered controls to update themselves
        $.event.trigger(RenoEvent.DeletePhoto);

        if (typeof (detailPageCarousel) !== 'undefined') {
            detailPageCarousel.removeImage(PhotoUrl);

            //refresh detailsPhotoArr
            detailsPhotoArr = new Array();
            detailPageCarousel.$images.each(function(n) {
                detailsPhotoArr.push($(this).attr("alt"));
            });
            
            
            if (detailsPhotoArr.length >= 1) {
                $('.carousel .thumbs').show();
                $('.carousel .previous').show();
                $('.carousel .next').show();
                detailPageCarousel.refreshDeleteButtons();
            }
            else {
                $('.carousel .thumbs').hide();
                $('.carousel .previous').hide();
                $('.carousel .next').hide();
            }
        }
    }
    else if (response == "login") {
        Login();
    }
    else {
        ClearLastActionCookie();
        alert(response);
    }
}



//========================================================
//  Show Icon Tooltip, after a Save or Delete Operation
//========================================================
function ShowToolTip(selector, styleName, content) {
    var tooltipObj = $(selector).qtip({
        style: { 
            name: styleName,
            tip: 'bottomLeft'
        },
        content: content,
        position: {
            corner: {
                target: 'topRight',
                tooltip: 'bottomLeft'
            }
        },
        show: { 
            when: { event: 'opentooltip' },
            ready: true,
            solo: true
        },
        hide: { when: { event: 'closetooltip' } }
        });

        $(selector).trigger("opentooltip");
        
        window.setTimeout(function() {
            $(selector).trigger("closetooltip");
        }, 3500);
}

function CreateToolTipContent(styleName, content) {
    return '<div class="icon-img ' + styleName + '">' + content + '</div>';
}



//========================================================
//  ChangeListingSaveIcon
//  Change the 'folder' icon for a listing, based on the
//  listing's saved status
//========================================================
function ChangeListingSaveIcon(LID, IsSavedListing) {

    //qtip might not have been defined for this icon
    if (typeof $("#folico-" + LID).data('qtip') == 'object') {
        $("#folico-" + LID).qtip("destroy");
    }

    if (IsSavedListing) {
        $("#folico-" + LID).removeClass('folder');
        $("#folico-" + LID).addClass('remove_folder');
        $("#folico-" + LID).attr("href", "javascript:DeleteListing('" + LID + "')");
        $("#folico-" + LID).attr("title", "Remove Saved Listing");
        BuildIconToolTip("#folico-" + LID, 'listingRemove');
        $("#editli-" + LID).removeClass('none');
    }
    else {
        $("#folico-" + LID).removeClass('remove_folder');
        $("#folico-" + LID).addClass('folder');
        $("#folico-" + LID).attr("href", "javascript:SaveListing('" + LID + "')");
        $("#folico-" + LID).attr("title", "Save Listing");
        BuildIconToolTip("#folico-" + LID, 'listingSave');
        $("#editli-" + LID).addClass('none');
    }
}

//========================================================
//  Utilities For Creating Icon Tool Tips
//========================================================
$(function() {
    SetIconToolTips();
});

function SetIconToolTips() {
    BuildIconToolTip(".icon-img[title!='']");
}

function BuildIconToolTip(selector, styleName) {
    if (styleName == null) {
        styleName = 'blue';
    }

    $(selector).qtip({
        style: {
            name: styleName,
            tip: 'bottomLeft'
        },
        /*  content: content, // automatically uses title */
        position: {
            corner: {
                target: 'topRight',
                tooltip: 'bottomLeft'
            }
        },
        show: {
            delay: 100,
            when: { event: 'mouseover' }
        }
    });
}
