var _is_last = 0;
var _last_kat = "";

function toggle() {

  var toggleSource = arguments[0];
  var letzter = arguments[1];
  var artikelId = arguments[2];
  var farbe = arguments[3];

  if (arguments[4]) {
    var row = document.getElementById("_" + artikelId + "_" + arguments[4]);
    _last_kat = arguments[4];
    var kategorieId = arguments[4];
  } else {
    var row = document.getElementById("_" + artikelId);
    _last_kat = "";
    var kategorieId = "";
  }

  if (!row)
    return;

  var details = document.getElementById("detail" + row.id);
  if (details != null) {
    if ("hide" == row.details)   {
      row.details = "show";
      if (document.all != null) {
        details.style.display="inline";      
      } else {
        details.style.display="table-row";
      }
      toggleSource.innerHTML = '<img src="picsgen/minus.gif" border="0" width="23" height="20" alt="Detail-Infos ausblenden">';
      price_cell = document.getElementById("_" +artikelId+"_price");
      price_cell.className = 'prod_p_sel';
		
		/* activate details > 2 time */
		for ( n = 0; n < row.getElementsByTagName("td").length; n++ )
		{
			row.getElementsByTagName("td")[n].style.borderTop = '1px solid #8B0000';
		}
		row.getElementsByTagName("td")[0].style.borderLeft = '1px solid #8B0000';
		row.getElementsByTagName("td")[row.getElementsByTagName("td").length - 1].style.borderRight = '2px solid #8B0000';
		
    } else {
      row.details = "hide";
      details.style.display = "none";
      toggleSource.innerHTML = '<img src="picsgen/plus.gif" width="23" height="20" border="0" alt="Detail-Infos">';
      price_cell = document.getElementById("_" +artikelId+"_price");
      price_cell.className = 'prod_p';

		/* deactivate details */
		for ( n = 1; n < row.getElementsByTagName("td").length; n++ )
		{
			row.getElementsByTagName("td")[n].style.borderTop = '#E7E7E7 outset 2px';
		}
		row.getElementsByTagName("td")[0].style.borderTop = '#CCCCCC outset 2px';
		row.getElementsByTagName("td")[0].style.borderLeft = '#CCCCCC outset 2px';
		row.getElementsByTagName("td")[row.getElementsByTagName("td").length - 1].style.borderRight = '#47494B inset 2px';
    }
  
  } else {
    row.color = row.style.backgroundColor;
    rpc(artikelId, letzter, kategorieId, arguments[5]);
  }

}

function rpc (artikelId, letzter, kategorieId, nocomp) {

  _is_last = letzter;  
  var tunnel = document.getElementById("tunnel");
  if (!tunnel)  {
    tunnel = document.createElement("div");
    tunnel.id = "tunnel";
    tunnel.innerHTML =
    '<form name=sender target=receiver method=post>' +
      '<input type=hidden name=artikelId>' +
      '<input type=hidden name=kategorieId>' +
      '<input type=hidden name=nocomp>' +
    '</form>' +
    '<iframe name=receiver style="visibility:hidden"></iframe>';
    document.body.appendChild(tunnel);
  }
  
  var f = document.getElementsByName("sender")[0];
  f.artikelId.value = artikelId;
  f.kategorieId.value = kategorieId;
  f.nocomp.value = (nocomp) ? 1 : 0;
  f.action = "details.php?" + php_sessionid;

  f.submit();
}

/*
function onReturn(data) {

  var row = (_last_kat) ? "_" + data.artikelId + "_" + _last_kat : "_" + data.artikelId;
  if (!(row = document.getElementById(row)))
    return;

  var spacer = document.createElement('td');
  spacer.className = 'prod_a';
  spacer.width = "3";
  spacer.innerHTML = '&nbsp;';
  addLastStyle(spacer);
    
  var bild  = document.createElement('td');
  bild.className = 'prodp_d';
  //bild.style.backgroundColor = row.color;
  bild.style.backgroundColor = '#FFFFFF';
  bild.style.padding = '0px';
  bild.innerHTML = data.bild + "<br>Symbolfoto";
  addLastStyle(bild);
  
  var text  = document.createElement('td');
  text.className = 'prodp_a';
  text.valign = 'top';
  text.style.backgroundColor = row.color;
  text.style.borderLeft = '#cccccc outset 2px';
  text.width = "275";
  text.colSpan = "2";
  text.innerHTML = data.text;
  addLastStyle(text);
  
  var extra = document.createElement('td');
  extra.colSpan = "3";
  extra.className = 'prodp_i';
  extra.style.backgroundColor = row.color;
  extra.style.verticalAlign = 'text-top';
  extra.valign = 'top';
  extra.innerHTML = data.extra;
  addLastStyle(extra);
  
  var zeile = document.createElement('tr');
  zeile.id = 'detail' + row.id;
  zeile.appendChild(spacer);
  //zeile.appendChild(bild); tm071006
  zeile.appendChild(text);
  zeile.appendChild(extra);
  
  row.parentNode.insertBefore(zeile, row.nextSibling);
  
  sign_cell = document.getElementById("_" + data.artikelId);
  sign_cell.innerHTML = '<img src="picsgen/minus.gif" border="0" width="23" height="20" alt="Detail-Infos ausblenden">';
  price_cell = document.getElementById("_" + data.artikelId+"_price");
  price_cell.className = 'prod_sel';
  
  row.details = "show";
}
*/

function addLastStyle(obj) {
  if (_is_last) {
    obj.style.borderBottom = "#e70505 inset 2px";
    obj.borderBottom = "#e70505 inset 2px";
  }
}