var d=new Date();

var month=new Array(12);
month[0]="01";
month[1]="02";
month[2]="03";
month[3]="04";
month[4]="05";
month[5]="06";
month[6]="07";
month[7]="08";
month[8]="09";
month[9]="10";
month[10]="11";
month[11]="12";

var this_month = month[d.getMonth()];

var this_year = d.getFullYear();

var this_date = d.getDate();
if (this_date < 10) {
  this_date = "0" + this_date;
}

var todays_date = ~~(this_year + this_month + this_date);

function display() {
   displayTier("Tier1");
   displayTier("Tier2");
   displayTier("Tier3", 4, "Tier_3_divider");
}

function checkPromoExpiration(promos) {
    var good_promos = [];
    
    for (var idx = 0; idx < promos.length; idx++) {
        var promo      = promos[idx];
        var start_date = ~~promo.getAttribute("start_date");
        var end_date   = ~~promo.getAttribute("end_date");
        var name       = promo.getAttribute("name");

        if (start_date == 0 && end_date == 0) {
            promo.style.display = "inline";
            good_promos.push(promo);
        } else if (todays_date > end_date) {
            promo.style.display = "none";
        } else if (start_date > todays_date) {
            promo.style.display = "none";
        } else {
            promo.style.display = "inline";
            good_promos.push(promo);
        }
    }

    return good_promos;
}


function displayTier(tier,item_limit,divider_div) {
   checkPromoExpiration(getDivsByName(tier));
}

function getDivsByName(name) {
   var divs = document.getElementsByTagName("div");
   var div_cnt = divs.length;
   var name_cnt = 0;
   var name_divs = new Array();
   var cnt;
   for ( cnt=0 ; cnt < div_cnt ; cnt++ ) {
      var this_name = divs[cnt].getAttribute("name");
      if (this_name == name) {
            name_divs[name_cnt] = divs[cnt];
	    name_cnt++;
      }
   }
   return name_divs;
}
