// checks the manufacturer's field value in the 'sell' form, if 'other' then show extra
// text field
function checkManufacturerField(el) {
   if(el.value == 'other')
      document.getElementById('other_field').style.display = 'block';
   else
      document.getElementById('other_field').style.display = 'none';
}
// selects an extra option in multiple select withouth disabling previous
function selectOption(elemSelect) {
   if(! elemSelect.arrChecked )
      elemSelect.arrChecked = new Array();
      
   // if value is already available -> remove
   if( hasValue(elemSelect.arrChecked, elemSelect.value) ) {
      removeItems(elemSelect.arrChecked, elemSelect.value);
   }
   else { // or add
      elemSelect.arrChecked[elemSelect.arrChecked.length] = elemSelect.value;
   }
   
   // loop through options, if in array then highlight
   for( var i=0; i<elemSelect.options.length; i++ ) {
      if( hasValue(elemSelect.arrChecked, elemSelect.options[i].value) ) {
         elemSelect.options[i].selected = true;
      }
      else {
         elemSelect.options[i].selected = false;
      }
   }
}

// arr has value 'value'?
function hasValue(arr, value) {
   for( var a=0; a<arr.length; a++ ) {
      if(arr[a] == value) {
         return true;
      }
   }
   return false;
}

// remove item from array
function removeItems(array, item) {
   var b = 0;
   while (b < array.length) {
      if (array[b] == item) {
         array.splice(b, 1);
      } else {
         b++;
      }
   }
   return array;
}

// show image in detail view
function showImage(url, id) {
   $('photo').src = url;
   
   var _i = 1;
   while($('img'+_i)) {
      $('img'+_i).className = '';
      _i++;
   }
   
   $('img' + id).className = 'imgBorder';
}
