function externalLinks() {

  if (!document.getElementsByTagName) {
  
    return; 
    
  } else {
  
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i]; 
      var relvalue = anchor.getAttribute("rel");

      if (anchor.getAttribute("href")) { 
        var external = /external/;
        var relvalue = anchor.getAttribute("rel");
        if (external.test(relvalue)) { 
          anchor.target = "_blank"; 
        }
      }
    }
  }
}

function redirectMan() {

  var man = document.getElementById('manufacturer_select');
  man = man.options[man.selectedIndex].value;    

  window.location = 'index.php?view=manufacturer&manufacturer=' + man; return true;

}

function order_by_normal() {

  var section = document.getElementById('section').value;
  
  window.location = 'index.php?view=section&section=' + section + '&order=' + this.value; return true;

}

function order_by_offers() {
  
  window.location = 'index.php?view=offers&order=' + this.value; return true;

} 

function order_by_man() {

  var section = document.getElementById('section').value;
  var manufacturer = document.getElementById('manufacturer').value;
  
  window.location = 'index.php?view=section&section=' + section + '&manufacturer=' + manufacturer +'&order=' + this.value; return true;

}

function initForm() {

  document.getElementById('manufacturer_select').onchange = redirectMan;
  externalLinks();
  
  if(document.getElementById('mode_1')) {
    document.getElementById('order_by').onchange = order_by_normal;    
  }
  
  if(document.getElementById('mode_2')) {
    document.getElementById('order_by').onchange = order_by_man;    
  }
  
  if(document.getElementById('offers')) {
    document.getElementById('order_by').onchange = order_by_offers;    
  }

}

window.onload = initForm;