// dropdown select location change

function selsub(Url) {
  Url=document.subsites.sites[document.subsites.sites.selectedIndex].value;
  document.location = Url;
}

function openExternalLink(href, target) {
  var newwin = window.open('util/exit-notice.html?url=' + encodeURIComponent(href) + '&target=' + encodeURIComponent(target),'openlink','width=330,height=160,screenX=100,screenY=100,top=100,left=100,resizable=yes,toolbar=no,scrollbars=no')
  newwin.focus();
}

function openExternalLinkNZ(href, target) {
  var newwin = window.open('util/exit-notice-nz.html?url=' + encodeURIComponent(href) + '&target=' + encodeURIComponent(target),'openlink','width=330,height=160,screenX=100,screenY=100,top=100,left=100,resizable=yes,toolbar=no,scrollbars=no')
  newwin.focus();
}

function setupExternalLinks() {
	var links = document.getElementsByTagName('a');
	for (var i = links.length; i != 0; i--) {
    	var a = links[i-1];
    	if (!a.href) continue;

		// check if NZ products pages
		

		if (a.href.indexOf('http') != -1 &&
            a.href.indexOf(window.location.hostname) == -1 &&
      		!excludeUrl(a.href)
        ) {
        	
        	if (a.href.indexOf('www.medsafe.govt.nz') != -1) {
        		a.onclick = function() {
					openExternalLinkNZ(this.href, this.target);
					return false;
				}
        	}
        	else {
	      		a.onclick = function() {
					openExternalLink(this.href, this.target);
					return false;
				}
			}
		}
  	}
}

function excludeUrl(url){
  var excludeUrls = Array(
              );

  for(var l = 0; l < excludeUrls.length; l++){
    if(url.indexOf(excludeUrls[l]) == 0){
      return true;
    }
  }

  return false;
}