Shops = Array();
Sparten = Array();
Sort = 0;
Label = 1;
Verweis = 2;
Bild = 3;
Branchen = 4; 
Info = 5;

/* Neues Shopfenster öffnen */
function OpenWind(ShopId) {
  Adresse="http://" +Shops[ShopId][Verweis]	
  MeinFenster = window.open(Adresse, "Zweitfenster");
  MeinFenster.focus();
}

/* Initialisierungs-Routine */
function Init() {
  ShopMenuFill();
  Sparten.sort();
  AreaMenuFill();
}

/* Gruppen Menu fuellen */
function AreaMenuFill() {
 for (var i = 0; i < Sparten.length; i++) {
   NeuerEintrag = new Option(Sparten[i][0],i, false, true);
   document.SelectAreaShop.Area.options[document.SelectAreaShop.Area.length] = NeuerEintrag;
   }
 document.SelectAreaShop.Area.selectedIndex = 0;
}

/* shop Menu fuellen */
function ShopMenuFill() {
 SortKeyMake();
 Shops.sort();
 for (var i = 0; i < Shops.length; i++) {
   NeuerEintrag = new Option(Shops[i][Label],i, false, true);
   document.SelectAreaShop.Shop.options[document.SelectAreaShop.Shop.length] = NeuerEintrag;
   }
 document.SelectAreaShop.Shop.selectedIndex = 0;
}
/* Sortierschlüssel für Labels erstellen */
function SortKeyMake() {
 for (var i = 0; i < Shops.length; i++) {
  Kurz = new String(Shops[i][Label].substring(0,4));  
  Kurz = new String(Kurz.toLowerCase());
  Shops[i][Sort] = Kurz;
  }
}
/* Shops-Direkt wurde gewählt */
function ShopSelected(Nr) {
 if (Nr != "") {
  OpenWind (Nr)
  }
 SelectAreaShop.Shop.selectedIndex = 0;
}

/* Sparte wurde ausgewählt */
function AreaSelected(Nr) {
 if (Nr != "") {
   Abteilung.innerHTML = Sparten[Nr][0];
   ShopsSortiert.innerHTML = AnbieterZeilen(Nr);
  }
 SelectAreaShop.Area.selectedIndex = 0;
}

/* Tabelle mit Shops für ausgewählte Sparte zusammenstellen */
function AnbieterZeilen(BitNr) {
 Counter = 0;
 Mask = Sparten[BitNr][1];
 
 Collection = '<table align="center" width="780" border="2" cellspacing="2" cellpadding="5"  bgcolor="#ffffff">';

 for (var i = 0; i < Shops.length; i++) {
  Filter = Shops[i][Branchen];
   if (0 == (Filter & Mask)) {
    if ((Counter % 2) == 0)  Collection = Collection  + '<tr>';
    ShopImage = '<img src="shopsimages/' + Shops[i][Bild] + '" border="0">';
    ShopLink = '<td><a href="http://' + Shops[i][Verweis] + '" target="_blank">' + ShopImage + '</a></td>';
    ShopInfo ='<td bgcolor="#ffffff"><b>' +Shops[i][Label] + '</b><br>' +Shops[i][Info] + '</td>';
    Collection = Collection + ShopLink + ShopInfo;
    if ((Counter % 2) == 1)  Collection = Collection  + '</tr>';
  Counter = Counter + 1;
  }
 }
 Collection = Collection  + "</table>";
 return Collection;
}

