// JavaScript Document
var displayDiv;
var connectSpeed;
var conType;
var flshVrsn;
var acroVrsn;
var screenRes;
var referer;
var myBrowser;
var OS,OSver,browser,total,thestring,nextSemi;
var speedType;
var NISEnabled;
var ipAd;
var custnum;
var keepData;
var showSpecs;

function getSpecs(ip,dataKeep,custnumber,myDiv,displaySpecs,myReferer){
	ipAd = ip;
	if(ipAd.indexOf("192.168") == -1){
		keepData = dataKeep;
	}else{
		keepData = 0;	
	}
	custnum = custnumber;
	showSpecs = displaySpecs;
	referer = myReferer;
	flshVrsn = getFlashVersion();
	acroVrsn = getAcrobatVersion();
	NISEnabled = checkNIS();
	//var QTVrsn = isQTInstalled();
	screenRes = screen.width+"x"+screen.height;
	var browserString = navigator.userAgent;
	var userString = "";
	var agt = navigator.userAgent.toLowerCase();
	var vendor = (navigator.vendor) ? navigator.vendor.toLowerCase() : "";
	var version = (navigator.vendorSub) ? navigator.vendorSub : "";
	displayDiv = myDiv;
	if (checkIt('konqueror', agt))	{
		myBrowser = "Konqueror";
		OS = "Linux";
	}
	
	var FirefoxBrowser = browserString.indexOf("Firefox");
	var IEBrowser = browserString.indexOf("MSIE");
	var NSBrowser = browserString.indexOf("Netscape");
	var OperaBrowser = browserString.indexOf("Opera");
	var SafariBrowser = browserString.indexOf("Safari");
	if (FirefoxBrowser!= -1){
		myBrowser = browserString.substring(FirefoxBrowser,FirefoxBrowser+11);
	}else if (IEBrowser!= -1){
		myBrowser = browserString.substring(IEBrowser,IEBrowser+6);
	}else if (NSBrowser!= -1){
		myBrowser = browserString.substring(NSBrowser,NSBrowser+10);
	}else if (SafariBrowser!= -1){
		myBrowser = browserString.substring(SafariBrowser,SafariBrowser+10);
	}
	if (!OS){
		if (checkIt('linux', agt)) OS = "Linux";
		else if (checkIt('x11', agt)) OS = "Unix";
		else if (checkIt('mac', agt)) OS = "Mac"
		else if (checkIt('win', agt)) OS = "Windows"
		else OS = "an unknown operating system";
	}

	// *** PLATFORM ***
	var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
	// NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
	//        Win32, so you can't distinguish between Win95 and WinNT.
	var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

	// is this a 16 bit compiled version?
	var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
	var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

	// NOTE: Reliable detection of Win98 may not be possible. It appears that:
	//       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
	//       - On Mercury client, the 32-bit version will return "Win98", but
	//         the 16-bit version running on Win98 will still return "Win95".
	var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
	var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
	var is_winxp = ((is_winnt) && (checkIt("nt 5.1",agt)!=-1));
	var is_win32 = (is_win95 || is_winnt || is_win98 || 
					(navigator.platform == "Win32") ||
					(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

	var is_os2   = ((agt.indexOf("os/2")!=-1) || 
					(navigator.appVersion.indexOf("OS/2")!=-1) ||   
					(agt.indexOf("ibm-webexplorer")!=-1));

	var is_mac    = (agt.indexOf("mac")!=-1);
	// hack ie5 js version for mac
	//if (is_mac && is_ie5up) is_js = 1.4;
	var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) || 
							   (agt.indexOf("68000")!=-1)));
	var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) || 
								(agt.indexOf("powerpc")!=-1)));
	var is_macintel = (is_mac && ((agt.indexOf("intel")!=-1) || 
								(agt.indexOf("intel")!=-1)));
	var is_macppcx = (is_mac && (((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1)) && (agt.indexOf("OS X")!=-1)));
	if (is_win95) OS = "Windows 95"
	else if (is_winme) OS = "Windows ME"
	else if (is_win2k) OS = "Windows 2000"
	else if (is_win98) OS = "Windows 98"
	else if (is_winxp) OS = "Windows XP"
	else if (is_winnt) OS = "Windows NT"
	else if (is_os2) OS = "OS/2"
	else if (is_mac68k) OS = "Mac 68k"
	else if (is_macppc) OS = "Mac PPC"		
	else if (is_macppcx) OS = "Mac PPC OS X"	
	else if (is_macintel) OS = "Mac Intel OS X"	
	else if (is_mac) OS = "Mac"
	else OS = "unknown"
	
	/*if(myBrowser.indexOf("MSIE") > -1){
		var pluginArray = document.plugins;
	}else{
		var pluginArray = navigator.plugins;
		for (x in pluginArray){
			document.getElementById("info").innerHTML = document.getElementById("info").innerHTML+"<p>"+pluginArray[x].name+"</p>";
		}
	}*/
}

function checkIt(term, string){
	place = string.indexOf(term.toLowerCase()) + 1;
	thestring = term;
	return place;
}

function getFlashVersion() {
	var flashversion;
/*	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
		for(var i = 15; i >= 1 && result != true; i--){
			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
			flashversion = i;
		}
	}
	return flashversion;*/
	 // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    flashversion = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        flashversion = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
return flashversion.split(',').shift();
}

function getAcrobatVersion() {
	var displayString;
	var acrobat=new Object();
	acrobat.installed=false;
	acrobat.version='0.0';
	if (navigator.plugins && navigator.plugins.length) {
		var mars = navigator.mimeTypes["application/vnd.adobe.x-mars"];
		var pdf = navigator.mimeTypes["application/pdf"];
		if(mars){
			if(mars.enabledPlugin){
				acrobat.version = 8;
			}
		}else if(pdf){
			if(pdf.enabledPlugin){
				acrobat.version = 1;	
			}
		}else{
			acrobat.version = 0;	
		}
	}else if (window.ActiveXObject){
		for (x=2; x<10; x++){
			try{
				oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
				if (oAcro){
					acrobat.installed=true;
					acrobat.version=x+'.0';
					displayString = 'Acrobat Version: '+acrobat.version;
				}
			}
			catch(e) {}
		}
		try{
			oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
			if (oAcro4){
				acrobat.installed=true;
				acrobat.version='4.0';
				displayString = 'Acrobat Version: '+acrobat.version;
			}
		}
		catch(e) {}
		try	{
			oAcro7=new ActiveXObject('AcroPDF.PDF.1');
			if (oAcro7)	{
				acrobat.installed=true;
				acrobat.version='7.0';
				displayString = 'Acrobat Version: '+acrobat.version;
			}
		}
		catch(e) {}
	} 
	return acrobat.version;
}

function checkNIS(){
	//window.open();
	if(window.SymOnLoad){
		var NIS = true;
	}else{
		var NIS = false;	
	}
	return NIS;
}

var connectionSpeed = 0; // The variable where connection speed information will be stored when it is available.

function drawCSImageTag( fileLocation, fileSize, imgTagProperties ) {
	// This function draws the image tag required to run this process.
	// It needs to be passed:
	//     1.  (String)   The location of the file to be loaded
	//     2.  (Integer)  The size of the image file in bytes
	//     3.  (String)   The tag properties to be included in the <img> tag
	// Place a call to this function inside the <body> of your file
	// in place of a static <img> tag.
	
	start = (new Date()).getTime();
		// Record Start time of <img> load.
		
	loc = fileLocation + '?t=' + escape(start);
		// Append the Start time to the image url
		// to ensure the image is not in disk cache.
		
	document.write('<img src="' + loc + '" ' + imgTagProperties + ' onload="computeConnectionSpeed(' + start + ',' + fileSize + ');" class="noPrint">');
		// Write out the <img> tag.
	
	return;
}

function connectionType() {
	// This function returns a string describing the connection type
	// being used by the user-agent hitting the page.
	var dialUP = 57;
	var medBroad = 800;
	var highBroad = 2000;
	var blazeBroad = 6000;
	// These are constants which define the base speeds for a number of different connections.  They are measured in units of kbps.
	if (connectSpeed < dialUP) {
		return "Dial Up";
	} else if (connectSpeed < medBroad) {
		return "Medium Broadband(DSL, Satelite)";
	} else if (connectSpeed < highBroad) {
		return "High Broadband(DSL, Cable, Wireless, T1)";
	} else if (connectSpeed < blazeBroad) {
		return "Blazing Fast Broadband(DSL, Cable, Wireless, Fiber Optic, T3)";
	} else {
		return "Whoa! We are not sure which internet service you have, but it is FAST!";
	}
}

function computeConnectionSpeed( start, fileSize ) {
	// This function returns the speed in kbps of the user's connection,
	// based upon the loading of a single image.  It is called via onload 
	// by the image drawn by drawCSImageTag() and is not meant to be called
	// in any other way.  You shouldn't ever need to call it explicitly.
	end = (new Date()).getTime();
	connectSpeed = (Math.floor((((fileSize * 8) / ((end - start) / 1000)) / 1024) * 10) / 10);
	conType = connectionType();
	if(connectSpeed>1024){
		connectSpeed = Math.round(connectSpeed/1024);
		speedType="mbps";
	}else{
		speedType="kbps";
	}
	var mySpeed = connectSpeed+speedType;
	if(document.getElementById("conType")){
		document.getElementById("conType").innerHTML = 	"<strong>"+mySpeed+" - "+conType+"</strong>";
	}
	if(showSpecs == "showSpecs"){
		document.getElementById(displayDiv).innerHTML = document.getElementById(displayDiv).innerHTML+"<p><strong>OS</strong>: "+OS+"<p><strong>Screen Resolution</strong>: "+screenRes+"</p></p><p><strong>Browser</strong>: "+myBrowser+"</p><p><strong>Flash Version</strong>: "+flshVrsn+"</p><p><strong>Windows Media Player Version</strong>: "+v_mediaplayer+"</p><p><strong>Connection Speed</strong>: aprox. "+ connectSpeed +" "+speedType+"</p>";//<p><strong>Quicktime</strong>: QTVrsn; <p><strong>screenRes</strong>: "+screenRes+"</p> <p><strong>ipAddress</strong>: "+ipAd+"</p>
	}	
	
	if(keepData == "record"){
		keepData=1;
	}else{
		keepData=0;
	}
	
	var helpFullValue = "N/A";
	
	var specsArray = new Array();
	var windowsMediaPlayer = v_mediaplayer.slice(0,4);//cut of the trailing decimals to keep the data
	specsArray = [ipAd,OS,myBrowser,flshVrsn,windowsMediaPlayer,acroVrsn,screenRes,mySpeed,NISEnabled,custnum,window.location,referer,helpFullValue,keepData];
	var sysForm = document.getElementById("sysSpecs").getElementsByTagName("input");
	for(var spec=0;spec<sysForm.length;spec++){
		sysForm[spec].value = specsArray[spec];
	}
	
	if(document.getElementById("ipAddress") && document.getElementById("ipAddress").value!=""){
		ajaxFormSubmit("sysSpecs", "POST", "/jsLib/systemChecker/saveSpecs.cfm", true, "");
	}
	
	return mySpeed;
}

/*function isQTInstalled() {
	var qtInstalled = false;
	qtObj = false;
	if (navigator.plugins && navigator.plugins.length) {
		for (var i=0; i < navigator.plugins.length; i++ ) {
         var plugin = navigator.plugins[i];
         if (plugin.name.indexOf("QuickTime Plug-in") > -1) {
			var y = plugin.name;
			qtInstalled = y.charAt(y.indexOf('.')-1);
         }
      }
	} else {
		for(var qt = 15; qt >= 1 && result != true; qt--){
			execScript('on error resume next: result = IsObject(CreateObject("QuickTime.QuickTime.'+qt+'"))','VBScript');
			qtInstalled = qt;
			alert(qtInstalled);
		}
	}
	return qtInstalled;
}*/