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 order_by_normal() {

  var section = document.getElementById('section').value;
  
  window.location = 'index.php?view=section&section=' + section + '&order=' + this.value; return true;

}

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 viewHome() {
  window.location = 'index.php?view=home';
}

function category_over() {
  var newID = this.id + '_hover';
  document.getElementById(newID).style.backgroundImage = 'url(images/template/category_hover.gif)';
  this.style.cursor = 'pointer';
}

function category_out() {
  var newID = this.id + '_hover';
  document.getElementById(newID).style.backgroundImage = 'url(images/template/category_inactive.gif)';
} 

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('banner_logo')) {
    document.getElementById('banner_logo').onclick = viewHome;
  }
  
  if(document.getElementById('home_product_table')) {
    
    var divs = document.getElementsByTagName("div");
    for (var i=0; i<divs.length; i++) {
      var div = divs[i]; 
      var newID = div.getAttribute('id')+"_hover";
      if(document.getElementById(newID)) {
        div.onmouseover = category_over;
        div.onmouseout = category_out;
      }
    }    
  }
  
}

window.onload = initForm;