// Tools for ted website


// check whether the navigator supports java
// taken from http://www.faqts.com/knowledge_base/view.phtml/aid/9521
function checkJavaSupport () 
{
  var result = 
  { 
    javaEnabled: false,
    version: ''
  };
  if (typeof navigator != 'undefined' && typeof navigator.javaEnabled != 'undefined') 
  {
    result.javaEnabled = navigator.javaEnabled();
  }
  else
  {
    result.javaEnabled = 'unknown';
  }
  if (navigator.javaEnabled() && typeof java != 'undefined')
  {
    result.version = java.lang.System.getProperty("java.version");
  }
  return result;
}

// checks operating system of user
// inspired by http://members.ozemail.com.au/~enigman/javascript/js_binfo6.html
function checkOS()
{
	var version = 0.9715;
	var dotLessVersion = "09715";
	var result =
	{
		text: version,
		url: 'http://prdownloads.sourceforge.net/ted/tedv'+dotLessVersion+'.zip?download',
		analytics: "/downloads/tedv"+dotLessVersion+".zip"
	};
	if(navigator.userAgent.indexOf('Win') != -1) 
	{
		result.text = version + " for windows";
		result.url	= "http://prdownloads.sourceforge.net/ted/tedv"+dotLessVersion+".exe?download";
		result.analytics = "/downloads/tedv"+dotLessVersion+".exe";
	}
	else if (navigator.appVersion.indexOf("Linux") !=-1)
  	{ 
		result.text = version + " for linux"; 
	}

  	else if(navigator.userAgent.indexOf('Mac') != -1)
	{
		result.text = version + " for mac";
		result.url = "http://prdownloads.sourceforge.net/ted/tedv"+dotLessVersion+".dmg?download";
		result.analytics = "/downloads/tedv"+dotLessVersion+".dmg";
	}

  	else 
	{
		
	}
	return result;
}

// show a div
function displayDiv(whichDiv)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichDiv );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichDiv];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichDiv];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
    vis.display = 'block';
}

// hide a div
function hideDiv(whichDiv)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichDiv );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichDiv];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichDiv];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
    vis.display = 'none';
}

// show screenshots corresponding with user OS
function showScreenshotsOS()
{
	
	/*if (navigator.appVersion.indexOf("Linux") !=-1)
  	{ 
		hideDiv('screensmac');
		hideDiv('screenswin');
		displayDiv('screenslinux');
	}

  	else */if(navigator.userAgent.indexOf('Mac') != -1)
	{
		hideDiv('screenswin');
		//hideDiv('screenslinux');
		displayDiv('screensmac');
	}
	else
	{
		hideDiv('screensmac');
		//hideDiv('screenslinux');
		displayDiv('screenswin');
	}
}

// clear searchform on focus
// taken from: http://javascript.programmershelp.co.uk/cleartextjs.php
function clearText(theText) 
{
	if (theText.value == theText.defaultValue)
	 {
         theText.value = ""
     }
}