// JavaScript for opening external links in XHTML document

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

prepPDF = function() {
  var pageHasPDFs = false;
  var mainContent = document.getElementById("contentMain");
  var links = mainContent.getElementsByTagName("a");
  for (i=0; i<links.length; i++) {
    var currentLink = links[i];
    var images = currentLink.getElementsByTagName("img");
    /*Check if the link is an image (we don't want icons next to images) and that ".pdf" appears in the link href.*/
    if (images.length == 0 && currentLink.href.indexOf('.pdf') != -1) {
      var curClass = currentLink.getAttribute("class");
      if (curClass != null) { currentLink.className = curClass + " pdf"; }
      else { currentLink.className = "pdf"; }
	  
	  var curTitle = currentLink.getAttribute("title");
	  currentLink.title = curTitle+" [PDF]";
      pageHasPDFs = true;
    }
  }
/*If any a's had classes of "pdf" applied, then add the text to let the user go to Adobe's site for Reader.
  if (pageHasPDFs==true) {
    var para = document.createElement("p");
    para.innerHTML = "This page has links to PDF files. In order to view these files, you will need to visit Adobe's     website download their free <a href=\"http://www.adobe.com\">PDF Reader.</a>";
    mainContent.appendChild(para);
  }*/
}

function flashLocationLink(city){
	var locLink = "";
	if(city == "Chester"){
		locLink = "/Templates/Locations.aspx?id=220&LocType=Gamma";
	}
	else if(city == "Coventry"){
		locLink = "/Templates/Locations.aspx?id=210&LocType=EO";
	}
	else if(city == "ElPaso"){
		locLink = "/Templates/Locations.aspx?id=228&LocType=EO";
	}
	else if(city == "GrandPrairie"){
		locLink = "/Templates/Locations.aspx?id=230&LocType=EO";
	}
	else if(city == "Groveport"){
		locLink = "/Templates/Locations.aspx?id=182&LocType=Gamma";
	}
	else if(city == "Libertyville1"){
		locLink = "/Templates/Locations.aspx?id=202&LocType=Gamma";
	}
	else if(city == "Libertyville2"){
		locLink = "/Templates/Locations.aspx?id=204&LocType=E-beam";
	}
	else if(city == "Minneapolis"){
		locLink = "/Templates/Locations.aspx?id=214&LocType=EO";
	}
	else if(city == "MortonGrove"){
		locLink = "/Templates/Locations.aspx?id=206&LocType=Gamma";
	}
	else if(city == "Nogales"){
		locLink = "/Templates/Locations.aspx?id=180&LocType=EO";
	}
	else if(city == "Northborough"){
		locLink = "/Templates/Locations.aspx?id=212&LocType=EO";
	}
	else if(city == "Ontario"){
		locLink = "/Templates/Locations.aspx?id=200&LocType=Gamma";
	}
	else if(city == "SanDiego"){
		locLink = "/Templates/Locations.aspx?id=198&LocType=EO";
	}
	else if(city == "Sandy"){
		locLink = "/Templates/Locations.aspx?id=232&LocType=Gamma";
	}
	else if(city == "SouthPlainfield"){
		locLink = "/Templates/Locations.aspx?id=218&LocType=EO";
	}
	else if(city == "Spartanburg"){
		locLink = "/Templates/Locations.aspx?id=196&LocType=EO";
	}
	else if(city == "VegaAlta"){
		locLink = "/Templates/Locations.aspx?id=224&LocType=Gamma";
	}
	else if(city == "Waukegan"){
		locLink = "/Templates/Locations.aspx?id=208&LocType=EO";
	}
	else if(city == "Whippany"){
		locLink = "/Templates/Locations.aspx?id=216&LocType=Gamma";
	}
	else if(city == "Whitby"){
		locLink = "/Templates/Locations.aspx?id=222&LocType=Gamma";
	}
	else{
		locLink = "/About/Locations.html";
	}
	alert("JavaLink")
	window.location = locLink;
}

function FlashMaps() {
	if(document.getElementById("TechTeamMap") != null){
		var FO = { movie:"/flash/TechTeamMap.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent" };
		UFO.create(FO, "TechTeamMap");
	}
	if(document.getElementById("QualityMap") != null){
		var FO = { movie:"/flash/QualityMap.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent" };
		UFO.create(FO, "QualityMap");
	}
}

function locationFlash() {
	if(document.getElementById("flashMapInt") != null){
		if(document.getElementById("flashMapInt").className == 'Gamma'){
			var FO = { movie:"/flash/SterisLocMap.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent", flashvars:"showSet=Gamma" };
			UFO.create(FO, "flashMapInt");
		}
		else if(document.getElementById("flashMapInt").className == 'EO'){
			var FO = { movie:"/flash/SterisLocMap.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent", flashvars:"showSet=EO" };
			UFO.create(FO, "flashMapInt");
		}
		else if(document.getElementById("flashMapInt").className == 'Ebeam'){
			var FO = { movie:"/flash/SterisLocMap.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent", flashvars:"showSet=Ebeam" };
			UFO.create(FO, "flashMapInt");
		}
		else{
			var FO = { movie:"/flash/SterisLocMapAll.swf", width:"400", height:"198", majorversion:"8", build:"0", wmode:"transparent" };
			UFO.create(FO, "flashMapInt");
		}
	}
}

function cleanMainNav(){
	el = document.getElementById("navMain").getElementsByTagName("UL")
	for(x = 0; x < el.length; x++){
		newEl = el[x].getElementsByTagName("LI");
		newEl[newEl.length - 1].className += " lastNavItem";
	}
}

// JavaScript for suckerfish drop-downs <http://www.htmldog.com/articles/suckerfish/>
sfHover = function() {
	var sfEls = document.getElementById("navMain").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

// JavaScript for loading above functions into the page
var PageInitializer = {
    start : function(){
        PageInitializer.addLoadEvent(function(){
            //Add Functions Here
			externalLinks();
			sfHover();
			cleanMainNav();
		 	locationFlash();
			prepPDF();
			FlashMaps();
        });
    },
    addLoadEvent:function(f){var w=window;var o=w.onload;if(typeof w.onload!='function'){w.onload=f;}else{w.onload=function(){o();f();}}}
}
PageInitializer.start();
