<!-- original script author www.utdc.vuw.ac.nz -->

var browserAgent, browserVersion, browserPlatform;
var browserUserAgent = navigator.userAgent;
var browserUserAgentLowerCase = browserUserAgent.toLowerCase();

browserAgent = "Unknown Browser";
browserVersion = "Unknown Version";
browserPlatform = "Unknown Platform";


if (browserUserAgentLowerCase.indexOf('safari') >= 0) {
  browserAgent = "Safari";
  browserVersion = browserUserAgent.substring(browserUserAgentLowerCase.indexOf('safari') + 7);
} else if (browserUserAgentLowerCase.indexOf('msie') >= 0) {
  browserAgent = "Internet Explorer";
  browserVersion = browserUserAgentLowerCase.split("msie");
  browserVersion = browserVersion[1].split(";");
  browserVersion = browserVersion[0];
} else if (browserUserAgentLowerCase.indexOf('firefox') >= 0) {
  browserAgent = "Firefox";
  browserVersion = browserUserAgent.substring(browserUserAgentLowerCase.indexOf('firefox') + 8);
} else if (navigator.appName=="Netscape") {
  browserAgent = "Netscape";
  browserVersion = navigator.appVersion;
}

if (browserUserAgentLowerCase.indexOf('linux') >= 0) browserPlatform = "Linux";
else if (browserUserAgentLowerCase.indexOf('x11') >= 0) browserPlatform = "Unix";
else if (browserUserAgentLowerCase.indexOf('macintosh') >= 0) {
  browserPlatform = "Macintosh";
} else if (browserUserAgentLowerCase.indexOf('windows') >= 0) {
  browserPlatform = "Windows";
}

//**************************************************** DONE **************************************************************//

function checkAdobeReader() {

 if (window.ActiveXObject) {  
     var control = null;  
     try {  
         // AcroPDF.PDF is used by version 7 and later  
        control = new ActiveXObject('AcroPDF.PDF');  
    } catch (e) {  
         // Do nothing  
     }  
     if (!control) {  
         try {  
             // PDF.PdfCtrl is used by version 6 and earlier  
             control = new ActiveXObject('PDF.PdfCtrl');  
         } catch (e) {  
             return;  
         }  
     }  
     if (control) {  
         document["readerImg"].src="./images/pass.gif";
     }  
 } else { 
      if(detectPlugin("Adobe Acrobat") || detectPlugin("Adobe PDF Plug-in"))
      {
         document["readerImg"].src="./images/pass.gif";
      }
      }
}

function checkFlash() {

    if (window.ActiveXObject) {  
       var control = null;  
        try {  
           control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');  
        } catch (e) {  
            return;  
        }  
       if (control) {  
           document["flashImg"].src="./images/pass.gif";
       }  
   } else {  
       if(detectPlugin("Shockwave Flash"))
      {
         document["flashImg"].src="./images/pass.gif";
      }
   }  
}

function checkShockwavePlayer() {
    if (window.ActiveXObject) {  
     var control = null;  
     try {  
         control = new ActiveXObject('SWCtl.SWCtl');  
     } catch (e) {  
         return;  
     }  
     if (control) {  
         document["swPlayerImg"].src="./images/pass.gif";
     }  
 } else {  
     // Check navigator.plugins for "Shockwave for Director"  
     if(detectPlugin("Shockwave for Director"))
      {
         document["swPlayerImg"].src="./images/pass.gif";
      }
 }  
}

function checkWindowsMedia() {
    if (window.ActiveXObject) {  
        var control = null;  
        try {  
            control = new ActiveXObject('WMPlayer.OCX');  
        } catch (e) {  
            return;  
       }  
       if (control) {  
           document["windowsMediaImg"].src="./images/pass.gif";
       }  
   } else {  
      if(detectPlugin("Windows Media"))
      {
         document["windowsMediaImg"].src="./images/pass.gif";
      }
   }  
}

function checkQuickTime() {
    if (window.ActiveXObject) {  
        var control = null;  
        try {  
            control = new ActiveXObject('QuickTime.QuickTime');  
        } catch (e) {  
            // Do nothing  
        }  
        
       if (control) {  
           document["quicktimeImg"].src="./images/pass.gif";
       }  
     
       try {  
           // This generates a user prompt in Internet Explorer 7  
           control = new ActiveXObject('QuickTimeCheckObject.QuickTimeCheck');  
       } catch (e) {  
           return;  
       }  
       if (control) {  
           document["quicktimeImg"].src="./images/pass.gif";
       }  
   } else {  
       // Check navigator.plugins for "QuickTime Plug-in"  
       if(detectPlugin("QuickTime Plug-in"))
      {
         document["quicktimeImg"].src="./images/pass.gif";
      }
   }  
}

//**************************************************** DONE **************************************************************//

function checkBrowser() {
	if (browserAgent == "Internet Explorer") {
	   if (browserPlatform.toLowerCase().indexOf('windows') >= 0) {
	     if ((parseFloat(browserVersion) >= 6.0) && (parseFloat(browserVersion) <= 8.0))  {
 	       document["browserImg"].src="./images/pass.gif";
		 }
	   } else if (browserPlatform.toLowerCase().indexOf('mac') >= 0) {
	     if (parseFloat(browserVersion) >= 0.0) {
		  	document["browserImg"].src="./images/fail.gif";
	      }
	   }
	} else if (browserAgent == "Netscape") {
	   if (browserPlatform.toLowerCase().indexOf('windows') >= 0) {
	     if (parseFloat(browserVersion) >= 7.1) {
 	       document["browserImg"].src="./images/pass.gif";
		 }
	   } else if (browserPlatform.toLowerCase().indexOf('mac') >= 0) {
	     if (parseFloat(browserVersion) >= 0.0) {
		  	document["browserImg"].src="./images/fail.gif";
	      }
	   }
	} else if (browserAgent == "Safari") {
	   if (browserPlatform.toLowerCase().indexOf('mac') >= 0) {
	     if (parseFloat(browserVersion) >= 1.0) {
		  	document["browserImg"].src="./images/pass.gif";
	      }
	   }
	} else if (browserAgent == "Firefox") {
	   if (browserPlatform.toLowerCase().indexOf('windows') >= 0) {
	     if (parseFloat(browserVersion) >= 2.0) {
 	       document["browserImg"].src="./images/pass.gif";
		 }
	   } else if (browserPlatform.toLowerCase().indexOf('mac') >= 0) {
	     if (parseFloat(browserVersion) >= 2.0) {
		  	document["browserImg"].src="./images/pass.gif";
	      }
	   }
	}
}

function returnBrowserAgent() {
  return browserAgent;
}

function returnBrowserVersion() {
  return browserVersion;
}

function returnBrowserPlatform() {
	if(navigator.userAgent.indexOf("Windows NT 6.0") != -1)	{
 		return("Windows Vista");
	} else if(navigator.userAgent.indexOf("Windows NT 5.2") != -1) {
		return("Windows .NET Server");
	} else if(navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
 		return("Windows XP");
	} else if(navigator.userAgent.indexOf("Windows NT 5.0") != -1) {
 		return("Windows 2000");
	} else if(navigator.userAgent.indexOf("Windows 2000") != -1) {
 		return("Windows 2000");
	} else if(navigator.userAgent.indexOf("Win 9x") != -1) {
 		return("Windows ME");
	} else if(navigator.userAgent.indexOf("Win98") != -1) {
 		return("Windows 98");
	} else if(navigator.userAgent.indexOf("Windows 98") != -1) {
 		return("Windows 98");
	} else if(navigator.userAgent.indexOf("98") != -1) {
 		return("Windows 98");
	} else if(navigator.userAgent.indexOf("95") != -1) {
 		return("Windows 95");
	} else if(navigator.userAgent.indexOf("Win95") != -1) {
 		return("Windows 95");
	} else if(navigator.userAgent.indexOf("Windows 95") != -1) {
 		return("Windows 95");
	} else if(navigator.userAgent.indexOf("NT") != -1) {
 		return("Windows NT");
	} else if(navigator.userAgent.indexOf("WinNT") != -1) {
 		return("Windows NT");
	} else if(navigator.userAgent.indexOf("WinNT4.0") != -1) {
 		return("Windows NT");
	} else if(navigator.userAgent.indexOf("Windows NT 4.0") != -1) {
 		return("Windows NT");
	} else if(navigator.userAgent.indexOf("Windows NT") != -1) {
 		return("Windows NT");
	} else if(navigator.userAgent.indexOf("16") != -1) {
 		return("Win 3.1");
	} else if(navigator.userAgent.indexOf("SunOS") != -1) {
 		return("Sun");
	} else if(navigator.userAgent.indexOf("Linux") != -1) {
 		return("Linux");
	} else if(navigator.userAgent.indexOf("Mac_PowerPC") != -1)	{
 		return("Mac PowerPC");
	} else if(navigator.userAgent.indexOf("PPC Mac OS") != -1)	{
 		return("Mac OSX");
	} else if(navigator.userAgent.indexOf("Macintosh") != -1)	{
 		return("Macintosh");
	} else if(navigator.userAgent.indexOf("Mac") != -1)	{
 		return("Macintosh");
	} else {
 		return("Unkown OS");
	}
}

function checkPopup() {
	window.open("popup.html","popup","toolbar=no, width=250, height=250");
}

function checkCookies() {
	var msg;
	msg = " ";
   navigator.cookiesAreEnabled = checkCookiesAreEnabled();
   if (navigator.cookiesAreEnabled) {
     document["cookiesImg"].src="./images/pass.gif";
	 msg = " ";
   } 
  return msg; 
 }

function checkCookiesAreEnabled() {
  SetCookie( "mo", "mule" );
  if ( GetCookie( "mo" ) ) {
    DeleteCookie( "mule" );
    return true;
  } else {
    return false;
  }
}

function GetCookie( name ) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while ( i < clen ) {
    var j = i + alen;
    if ( document.cookie.substring(i, j) == arg ) return getCookieVal(j);
    i = document.cookie.indexOf( " ", i ) + 1;
    if ( i == 0 ) break;
  }
  return null;
}

function DeleteCookie( name, path, domain ) {
  if ( GetCookie( name ) ) {
    document.cookie = name + "=" +
    ( ( path ) ? "; path=" + path : "" ) +
    ( ( domain ) ? "; domain=" + domain : "" ) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function SetCookie( name, value, expires, path, domain, secure ) {
  document.cookie = name + "=" + escape (value) +
  ( ( expires ) ? "; expires=" + expires.toGMTString() : "" ) +
  ( ( path ) ? "; path=" + path : "" ) +
  ( ( domain ) ? "; domain=" + domain : "" ) +
  ( ( secure ) ? "; secure" : "" );
}

function getCookieVal( offset ) {
  var endstr = document.cookie.indexOf ( ";", offset );
  if ( endstr == -1 ) endstr = document.cookie.length;
  return unescape( document.cookie.substring( offset, endstr ) );
}

function checkPorts() {
  if (document.images) {
    imgPort80URL = "./images/pass.gif";
   	var imgPort80 = new Image();
	imgPort80.src = imgPort80URL;
    if (imgPort80.width = "100") {
       document["port80Img"].src=imgPort80URL;
    }
  }
}

function runChecks() {
  checkBrowser();
  document["javaScriptImg"].src="./images/pass.gif";
  checkCookies();
  checkPopup();
  checkPorts();
  checkFlash();
  checkAdobeReader();
  checkShockwavePlayer();
  checkWindowsMedia();
  checkQuickTime();
  var e = document.getElementById("notice");
  e.style.display = 'none';
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin