function setVendor( vendor )
{
  target = document.forms['newItem'].elements['vendor'].options;
  target[0] = new Option(vendor, vendor, true);
}

function setAttrib( attribute )
{  
  target = document.forms['newItem'].elements['attributes[]'].options;
  attributeCount = target.length;
  for (var i=0; i < attributeCount; i++) {
  
    if (target[i].value == attribute) {
      alert('Das Attribut "'+target[i].value+'" ist schon ausgewählt!');
      return;
    }
  }
  target[attributeCount] = new Option(attribute, attribute, true);
}

function deleteAttrib( index )
{
  if( index < 0 ) return;
  document.forms['newItem'].elements['attributes[]'].options[index] = null;
}

function selectAllAttributes()
{
  target = document.forms['newItem'].elements['attributes[]'].options;
  attributeCount = target.length;
  for (var i=0; i < attributeCount; i++)
  {
    target[i].selected = true;
  }
}

function doSelectedAction()
{
  options = document.forms['compareItems'].elements['actionSelector'].options;
  selectedIndex = document.forms['compareItems'].elements['actionSelector'].selectedIndex;
  if(!options || !selectedIndex || !compareAllURL) return;
  if(selectedIndex == 1) selectAllItems();
  if(selectedIndex == 2) window.open(compareAllURL, "Vergleich", "screenX=100,left=100,screenY=50,top=50,width=800,height=520,resizable=yes,titlebar=no,scrollbars=yes");
}

function selectAllItems()
{
  target = document.forms['compareItems'].elements;
  for(i=0; i < target.length; i++)
  {
    if(target[i].type != 'checkbox') continue;
    target[i].checked =(target[i].checked == 1)? 0:1;
  }
}

function showBigPicture( imageURL )
{
  if( typeof(imageURL) == "undefined" ) return false;
  preLoad = new Image();
  preLoad.src = imageURL;
  bigPic = window.open("", "Bild", "screenX=100,left=100,screenY=50,top=50,resizable=yes,titlebar=no");
  bigPic.document.writeln('<html>');
  bigPic.document.writeln('<link title="3 Columns" href="/templates/css/default.css" type="text/css" rel="stylesheet">');
  bigPic.document.writeln('<script type="text/javascript">');
  bigPic.document.writeln('function resize(){');
  bigPic.document.writeln('  if (!document.images[0].width) return false;');
  bigPic.document.writeln('  width  = document.images[0].width;');
  bigPic.document.writeln('  height = document.images[0].height;');
  bigPic.document.writeln('  width  =(navigator.appName == \'Netscape\')? width+10:width+20;');
  bigPic.document.writeln('  height =(navigator.appName == \'Netscape\')? height+50:height+55;');
  bigPic.document.writeln('  window.resizeTo(width, height);');
  bigPic.document.writeln('}');
  bigPic.document.writeln('<\/script>');
  bigPic.document.writeln('<style type="text/css">');
  bigPic.document.writeln('body html{');
  bigPic.document.writeln('  margin:0;padding:0;');
  bigPic.document.writeln('}');
  bigPic.document.writeln('<\/style>');
  bigPic.document.writeln('<body>');
  bigPic.document.writeln('<img onclick="resize()" src="'+imageURL+'"><div style="text-align: right">Herstellerbild<\/div>');
  bigPic.document.writeln('<script type="text/javascript">resize()<\/script>');
  bigPic.document.writeln('<\/body><\/html>');
}

function openSideBySideComparison()
{
  items  = document.forms['compareItems'].elements;
  params = '';
  itemCount = 0;
  for( i = 0, n = items.length; i < n; i++)
  {
    if( items[i].name.indexOf('compareIt') != -1 && items[i].checked == true)
    {
       separator =( params == '' )? '?':'&';
       params += separator + 'items[]=' + items[i].value;
       itemCount++;
    }
  }
  if( itemCount < 1 ) return;
  if( itemCount < 2 )
  {
    alert('Für einen sinnvollen Produktvergleich, müssen Sie mehr als nur ein Produkt auswählen!');
    return;
  }
  sideBySideComparison = window.open("/index.php"+params, "Vergleich", "screenX=100,left=100,screenY=50,top=50,width=800,height=520,resizable=yes,titlebar=no,scrollbars=yes");
}

function voteItem( choice, itemId )
{
  document.forms['voting'].elements['choice'].value = choice;
  document.forms['voting'].elements['key'].value = itemId;
  document.forms['voting'].submit();
}

/**
* Used in administration
*/
function hideNeedlessVendors( except )
{
  obj =( document.all )? document.all.tags("dd"):
                         document.getElementsByTagName("dd");

  //show all first
  for (i = 0; i < obj.length; i++) {
    obj[i].style.display = "block";
  }
  
  for (i = 0; i < obj.length; i++) {
    if( typeof(obj[i].className) != "undefined" 
    && obj[i].className != "" 
    && obj[i].className != except )
    {
      obj[i].style.display = "none";
    }
  }
}


function choose(container){
  if(container=="ebay") { 
    document.getElementById("as24").style.display="none";
    document.getElementById("ebay").style.display="block";
  }else if(container=="as24"){
    document.getElementById("as24").style.display="block";
    document.getElementById("ebay").style.display="none";
  }
  return false;
}
