// Allows multiple functions to load

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Simple hide/show function
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }


// Opens PDF links in new windows

function doPopups()
{
 if (!document.getElementsByTagName) return false;
 var links = document.getElementsByTagName("a");
 for (var i=0; i < links.length; i++) {
  if (links[i].href.indexOf('.pdf') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars');
     return false;
    }
    links[i].title += "(This PDF opens in a new window)";
  }
  if (links[i].href.indexOf('.doc') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars');
     return false;
    }
    links[i].title += "(This Word Doc opens in a new window)";
  }
  if (links[i].href.indexOf('.ppt') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars');
     return false;
    }
    links[i].title += "(This Powerpoint opens in a new window)";
  }
  if (links[i].href.indexOf('.xls') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars');
     return false;
    }
    links[i].title += "(This Spreadsheet opens in a new window)";
  }
  if (links[i].href.indexOf('.com') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars,menubar,location,toolbar,directories,status');
     return false;
    }
    links[i].title += "(This website opens in a new window)";
  }
  if (links[i].href.indexOf('v.uk') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars,menubar,location,toolbar,directories,status');
     return false;
    }
    links[i].title += "(This website opens in a new window)";
  }
  if (links[i].href.indexOf('rewardinglearning.org.uk') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars,menubar,location,toolbar,directories,status');
     return false;
    }
    links[i].title += "(This website opens in a new window)";
  }
  if (links[i].href.indexOf('.net') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars,menubar,location,toolbar,directories,status');
     return false;
    }
    links[i].title += "(This website opens in a new window)";
  }
  if (links[i].href.indexOf('ccea.org.uk') !== -1) {
   links[i].onclick =
    function() {
     window.open(this.href,'popper','resizable,scrollbars,menubar,location,toolbar,directories,status');
     return false;
    }
    links[i].title += "(This website opens in a new window)";
  }
  
 }
}

// Turns e-mail addresses into mailtos

function changeMail() {
 if (!document.getElementsByTagName) return false;
 var span = document.getElementsByTagName("span");
 for (var i=0; i < span.length; i++) {
  if (span[i].className.match('email')) {
   var innerspan = span[i].getElementsByTagName("span")[0].firstChild.nodeValue;
   span[i].innerHTML = "<a href='mailto:"+innerspan+"@webcredible.co.uk'>"+innerspan+"@webcredible.co.uk"
  }
 }
}


addLoadEvent(doPopups);
addLoadEvent(changeMail);



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
