//window.onload = function()
//{
//	Nifty("div.innerboxSameHeight", "bottom same-height");
//	Nifty("div.boxheader", "top");
//	Nifty("div.innerbox", "bottom");
//}

function sameHeight (id1, id2) {
	var leftBoxHeight = xHeight(id1);
	var rightBoxHeight = xHeight(id2);
  
	var maxHeight = Math.max(leftBoxHeight, rightBoxHeight);
	xHeight(id1, maxHeight);
	xHeight(id2, maxHeight);
}

//Event.observe(window, 'load', loadAccordions, false);
//
//	Set up all accordions
//
function loadAccordions() {
	bottomAccordion = new accordion('accordionMenu', {
	  classNames : {
			toggle : 'accordion_toggle',
			toggleActive : 'accordion_toggle_active',
			content : 'accordion_content'
		}
	});
	// Open first one
	// bottomAccordion.activate($$('#accordionMenu .accordion_toggle')[0]);
}

function openActiveMenu () {
	var verticalAccordions = $$('.accordion_toggle');
	var found = false;
	verticalAccordions.each(function(accordion) {
		if (accordion.id == 'activeAccordion') {
			bottomAccordion.activate($(accordion));
			found = true;
		}
		else {
			$(accordion.next(0)).setStyle({
			  height: '0px'
			});
		}
	});
	
	if (!found) {
		verticalAccordions.each(function(accordion) {
			bottomAccordion.activate($(accordion));
			return;
		});
	}
}

function toggleSearchBox () {
	var visible = toggle("searchBox");
	if (visible) {
		document.getElementById("searchBoxText").focus();
	}
}

function toggle (elementId) {
	var el = document.getElementById(elementId);
	var visible = el.style.display != 'none';
	el.style.display = (visible ? 'none' : 'block' );
	return !visible;
}

function toggleDiv (elementId) {
	var el = document.getElementById(elementId);
	var visible = el.style.display != 'none';
	el.style.display = (visible ? 'none' : 'block' );
	return !visible;
}

function setDownloadLink (linkId) {
	var loc = document.location.toString();
	if (loc && loc.indexOf('url=') > 0) {
		var url = loc.substring(loc.indexOf('url=') + 4);
		if (url.indexOf('&') > 0) {
			url = url.substring(0, url.indexOf('&'));
		}
		document.getElementById(linkId).href = url;
	}
}

/*
Alternating row color script by Joost de Valk ( http://www.joostdevalk.nl/ ) to add alternating row classes to a table.
Copyright (c) 2006 Joost de Valk.
*/

/* Don't change anything below this unless you know what you're doing */
addEvent(window, "load", alternate_init);

function alternate_init() {
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("alternate_rows") != -1) /*&& (thisTbl.id)*/) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,	NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("Handler could not be removed");
	}
} 

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}

function hasJavaInstalled () {
	return getJavaVersion != null;
}

function getJavaVersion () {
	var javaVersion = null;
	try {
		var appletVar = document.getElementById('JavaVersionApplet');
		if (appletVar) {
			javaVersion = appletVar.getJavaVersion();
		}
	}
	catch (e) {
		// try fallback implementation:
		javaVersion = getJavaVersionFallback();
	}
	return javaVersion;
}

function getJavaVersionFallback () {
	var javaVersion = null;
	try {
		var tmp = window.java.lang.System.getProperty('java.version').split("\\.");
		if (tmp) {
			if (tmp.length > 0) {
				javaVersion = tmp[0];
				if (tmp.length > 1) {
					javaVersion += "." + tmp[1];
				}
				else {
					javaVersion += ".0";
				}
			}
		}
	}
	catch (e) {
		javaVersion = null;
	}
	
	return javaVersion;
}

function checkPlugInVersion() {
	// Check for Java Plugin Version
	var requiredJavaVersion = "1.5";
	var javaVersion = getJavaVersion();
	
	if(javaVersion == null) {
		return false;
	}
	
	if ( javaVersion >= requiredJavaVersion ) {
		return true;
	}

	return false;
}

function delayedCreateEmpytApplet () {
	setTimeout('createEmptyApplet()', 4000);
}

function createEmptyApplet() {
  var emptyAppletDiv = document.getElementById('emptyAppletDiv');
  removeChildNodes(emptyAppletDiv);
  if(BrowserDetect.browser == 'Opera' || BrowserDetect.browser == 'Firefox'){
    emptyAppletDiv.innerHTML='<applet code="JavaVersionApplet.class" codebase="/JavaVersionApplet" width="0" height="0"></applet>';
  }else{
  	emptyAppletDiv.style.display = "none";
    var applet = document.createElement('applet');
    applet.setAttribute("code", "JavaVersionApplet.class");
    applet.setAttribute("codebase", "/JavaVersionApplet");
    applet.setAttribute("width", "0");
    applet.setAttribute("height", "0");
    emptyAppletDiv.appendChild(applet);
  }
}

function removeChildNodes(ctrl)
{
  while (ctrl.childNodes[0])
  {
    ctrl.removeChild(ctrl.childNodes[0]);
  }
}

function toggleSteps(stepDiv, text) {
	document.getElementById(stepDiv).innerHTML = text;
}

function clearSteps(stepDiv) {
	document.getElementById(stepDiv).innerHTML = "";
}
