﻿window.onload = doOnLoad;

function doOnLoad()
{
    FillRandProd();
}

function FillRandProd()
{
    var ProductAds = document.getElementById('randprodv1_ProductList');

    if (ProductAds != null)
    {
        var Container = document.getElementById('ProductListContainer');
        if (Container != null)
        {
            var ContainerHeight = Container.clientHeight;
            var ProductAdsHeight = ProductAds.clientHeight;

            var ProdList = document.getElementById('RandProd');
            if (ProdList != null)
            {
                var spaceRemaining = ContainerHeight - ProductAdsHeight;
                var AdCount = 1
                while (spaceRemaining > ProductAdsHeight)
                {
                    var newElement = ProductAds.cloneNode(true);
                    newElement.id = newElement.id + '_' + AdCount;

                    ProdList.appendChild(newElement);
                    spaceRemaining = spaceRemaining - ProductAdsHeight;
                    AdCount += 1;
                }
            }
        }
    }
}

