﻿$(document).ready(function(){
    RandomAD("IndexEliteCorporationList",false);
    RandomAD("EliteCorporationList",true);
});

function RandomAD(id,AdsTop)
{
    if ($("#"+id)!=undefined)
    {
        var theAds=new Array();
        var endAds=new Array();
        var endAdsCount=0;
        var shu=0;
        $("#"+id).children().each(function(i){
            if (AdsTop && $(this).html().indexOf("ADAffiliation")!=-1)
            {
                endAds[endAdsCount++]=$(this);
            }
            else
                theAds[++shu]=$(this);
        });

        var adshu=shu+1
        
        var idx;
        var ballball = new Array(shu);
        ballball = Quickpick(shu,adshu);
      
        $("#"+id).html("");
      
        for(idx = 1; idx < adshu; idx++){
            $("#"+id).append(theAds[ballball[idx]]);;
        }
        
        if (AdsTop)
        {
            for (var i=0;i<endAdsCount;i++)
                $("#"+id).append(endAds[i]);
        }
    }
}

function Quickpick(shu,adshu)
{
    var ball;
    for( ball = 1; ball < adshu; ball++)
    {
        this[ball] = parseInt(Math.random() * shu + 1);
        for(var list = 0; list < ball; list++)
        {
            if(this[list] == this[ball])
            {
                list = ball;
                ball--;
            }
        }
    }
    return this;
}
