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 showBigPicture( imageURL )
{
  if( typeof(imageURL) == "undefined" ) return false;
  
  bigPic = window.open("", "Bild", "screenX=100,left=100,screenY=50,top=50,resizable=yes,titlebar=no");
  bigPic.writeln('<html><body><img src="'+imageURL+'"><div>Bild vom Hersteller<\/div><\/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";
    }
  }
}

