﻿function RecordViewedListing()
{		   
    if (__ListingID)
    {
        var isPresent = false;
        var cookieValue = getCookie('ViewedListings');
        if (cookieValue)  
        {           
            var cookieValueArray = cookieValue.split(',');
            for (var i = 0; i < cookieValueArray.length; i++)
            {
                if (cookieValueArray[i] == __ListingID)
                    isPresent = true;
            }
            if (!isPresent)
            {
                if (cookieValueArray.length >= 5)
                    cookieValueArray.shift();
                cookieValueArray[cookieValueArray.length] = __ListingID;
                cookieValue = cookieValueArray.join(',');
            }
        } 
        else
           cookieValue = __ListingID;
           
        if (!isPresent)
            setCookie('ViewedListings', cookieValue, new Date(9999, 12, 31), '/');   
    }
}

RecordViewedListing();