var rootURL = "/";
var browserName=navigator.appName;
var browserAgent=navigator.userAgent.toLowerCase();
var browserVersion=navigator.appVersion;
var currLocation = document.location.pathname.toLowerCase();
var browserVer = navigator.appVersion
browserVer = browserVer.substring(0,1);
currLocation = currLocation.substr(0,currLocation.lastIndexOf('/')+1)
var parentLocation = currLocation.substr(0,currLocation.lastIndexOf('/'))
parentLocation = parentLocation.substr(0,parentLocation.lastIndexOf('/')+1)

$(document).ready(function(){

	/*RESIZERS FOR DROPDOWN MENU DROPSHADOWS*/
  $("#wrapper_QuickLinks").width($("#nav_Home").width()-20);
  $("#wrapper_Highlights").width($("#nav_Home").width()-20);

  /*CREATES ACCORDIAN LISTS FROM LEFT NAV ITEMS IF THEY EXIST*/
  if ($("ul#wrapper_LeftNav").get()!="") {
  	$("ul#wrapper_LeftNav").Accordion({
			header:".ui-accordion-link",
	  	active: false,
	    animated: false,
	    navigation: true,
	    selectedClass: "on"
	  });
	}

  /*ADD SELECTED CLASS TO SUBMENUS IF THEY ARE THE ACTIVE Link*/
  $("ul.subnav a").each(function() {
  	if($(this).attr("href")==currLocation) {
  		$(this).addClass("on")
  	}
  })

  /*ADD CLICKABLE HEADER FEATURE*/
  $("li a.ui-accordion-link").each(function() {
  	$(this).click(function() {
  		document.location=$(this).attr("href")
  	})
  	if (parentLocation.indexOf($(this).attr("href"))==0) {
  		$(this).addClass("on")
  		jQuery("ul#wrapper_LeftNav").activate($(this))
  		/*RESELECT SUBMENU WHEN ON A THIRD LEVEL OR LOWER PAGE*/
  		$("ul.subnav a").each(function() {
		  	if(currLocation.indexOf($(this).attr("href"))==0) {
		  		$(this).addClass("on")
		  	}
		  })
  	}
  })

  $("#wrapper_ThirdNav table td").attr("width","");

  $("input[type=checkbox]").addClass("nob")
  $("input[type=radio]").addClass("nob")

  $("form[name=testOnlineFormName]").addClass("webinarForm")
});

function resetHeight() {
	$("ul#wrapper_LeftNav").height($("#wrapper_Content").height());
}

function formNotComplete() {
	if ($.query.get('error')=='true') {
		document.write('<span style="color:red;">Please complete all fields below.</span>')
	}
}

function htmlEncode(source, display, tabs)
{
	function special(source)
	{
		var result = '';
		for (var i = 0; i < source.length; i++)
		{
			var c = source.charAt(i);
			if (c < ' ' || c > '~')
			{
				c = '&#' + c.charCodeAt() + ';';
			}
			result += c;
		}
		return result;
	}

	function format(source)
	{
		// Use only integer part of tabs, and default to 4
		tabs = (tabs >= 0) ? Math.floor(tabs) : 4;

		// split along line breaks
		var lines = source.split(/\r\n|\r|\n/);

		// expand tabs
		for (var i = 0; i < lines.length; i++)
		{
			var line = lines[i];
			var newLine = '';
			for (var p = 0; p < line.length; p++)
			{
				var c = line.charAt(p);
				if (c === '\t')
				{
					var spaces = tabs - (newLine.length % tabs);
					for (var s = 0; s < spaces; s++)
					{
						newLine += ' ';
					}
				}
				else
				{
					newLine += c;
				}
			}
			// If a line starts or ends with a space, it evaporates in html
			// unless it's an nbsp.
			newLine = newLine.replace(/(^ )|( $)/g, '&nbsp;');
			lines[i] = newLine;
		}

		// re-join lines
		var result = lines.join('<br />');

		// break up contiguous blocks of spaces with non-breaking spaces
		result = result.replace(/  /g, ' &nbsp;');

		// tada!
		return result;
	}

	var result = source;

	// ampersands (&)
	result = result.replace(/\&/g,'&amp;');

	// less-thans (<)
	result = result.replace(/\</g,'&lt;');

	// greater-thans (>)
	result = result.replace(/\>/g,'&gt;');

	if (display)
	{
		// format for display
		result = format(result);
	}
	else
	{
		// Replace quotes if it isn't for display,
		// since it's probably going in an html attribute.
		result = result.replace(new RegExp('"','g'), '&quot;');
	}

	// special characters
	result = special(result);

	// tada!
	return result;
}
/*LEGACY FUNCTIONS*/
if (browserVer == '.') browserVer = 2;
      else browserVer = browserVer;

if (browserName == "Netscape" && browserVer >= 3 || browserVer > 3) version = "n3";
      else version = "n2";

function openUp(item)
    {
    	$("#expnd_" + item).toggle()
    	$("#link_" + item).toggleClass("open")
    	resetHeight();
    }

function on(imgName) {
      if (version == "n3") {
        imgOn = eval(imgName + "on.src");
        document [imgName].src = imgOn;
      }
    }

    function off(imgName) {
      if (version == "n3") {
        imgOff = eval(imgName + "off.src");
        document [imgName].src = imgOff;
      }
    }

    function flip(imgName) {
      if (version == "n3") {
        imgNameRoot = imgName.substring(0,5)
        imgOn = eval(imgName + "on.src");
        document [imgNameRoot].src = imgOn;
      }
    }

    function relocate(that)
    {
      var url = that.options[that.selectedIndex].value;
      window.location = url;
    };

    function openWindow(url) {
	popupWin = window.open(url, 'remote', 'width=600,height=815');
	}

	function openWindow2(url) {
	popupWin = window.open(url, 'remote', 'width=430,height=600');
	}

	function openWindow3(url) {
	popupWin = window.open(url, 'remote', 'width=630,height=740,scrollbars=yes');
	}

	function openWindow4(url) {
	popupWin = window.open(url, 'remote', 'width=357,height=460');
	}

	function openWindowHomePage(url) {
	popupWin = window.open(url, 'remote', 'width=300,height=250');
	}
	
	function openWindow350x600(url) {
	popupWin = window.open(url, 'remote', 'width=350,height=600');
	}
	function openWindow400x600(url) {
	popupWin = window.open(url, 'remote', 'width=400,height=600');
	}

    var state = 'none';

    function showhide(layer_ref) {
      if (state == 'block') {
        state = 'none';
      }
      else {
        state = 'block';
      }
      if (document.all) { //IS IE 4 or 5 (or 6 beta)
        eval( "document.all." + layer_ref + ".style.display = state");
      }
      if (document.layers) { //IS NETSCAPE 4 or below
        document.layers[layer_ref].display = state;
      }
      if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.display = state;
      }
        //showDiv(layer_ref);
      resetHeight();
    }