var ie4 = false, ie = false, ie5_mac = false, ie55 = false;
var nn4 = false, dom = false;
//dynamic content 
var iens6= document.all || document.getElementById;
var agent = navigator.userAgent.toLowerCase();
var loaded = 0;
var doc = '';
var scrollY = 0;

if (document.all)
{
	var version = parseFloat(agent.substr(agent.indexOf("msie")+5, 3));
	if (agent.indexOf("mac") != -1 && version >= 5)
		ie5_mac = true;
	else
	{
		if (version >= 5.5)
			ie55 = true;
	}
	if (ie55 || ie5_mac) ie = true;
} else if (document.getElementById) {
	dom = true;
}

function init() {
	if (dom) {
		var flyOut = document.getElementById('leftNavContainer');
		if (flyOut) flyOut.addEventListener("mouseover",setEvent,true);
		
		var files = document.getElementById('relatedFiles');
		if (files) files.addEventListener("mouseover",setEvent,true);
	}
}

var current = "";
var globalHide = '';
var globalHideDoc = '';
var clientY = '';
var leftNavFlyOut = new Array();

function show(name,nohide)
{
	clearTimeout(globalHide);

	if (current && current != name) {
		hide(current);
	}
	
	if (current && current == name && nohide) return;

	current = name;
	var tip = document.getElementById(name + 'Flydown');
	var caller = document.getElementById(name);

	if (tip) {
		if (tip.style.visibility == "visible") {
			hide(current)
		} else {
			tip.style.visibility = 'visible';
			if (caller) caller.style.color = '#FA9A00';
			if (doc) doc.className = 'Headline';
		}
	}
}

function showDocInfo(name,nohide)
{
	clearTimeout(globalHideDoc);

	if (current && current != name) {
		hideDocInfo(current);
	}
	
	if (current && current == name && nohide) return;

	current = name;
	var tip = document.getElementById(name + 'Flydown');
	var caller = document.getElementById(name + 'Link');

	if (tip) {
		if (tip.style.visibility == "visible") {
			hideDocInfo(current)
		} else {
			tip.style.visibility = 'visible';
			if (caller) caller.style.color = '#FA9A00';
		}
	}
}

function hide(name)
{
if (!name) name = current;

var tip = document.getElementById(name + 'Flydown');
var caller = document.getElementById(current);
if (tip)
{
	tip.style.visibility = "hidden";
	if (caller) caller.style.color = '#00349C';
	current="";
} 
}

function hideDocInfo(name)
{
if (!name) name = current;

var tip = document.getElementById(name + 'Flydown');
var caller = document.getElementById(current + 'Link');
if (tip)
{
	tip.style.visibility = "hidden";
	if (caller) caller.style.color = '';
	current="";
} 
}

/* Function highlights left nav section when subnavs are chosen */
function highlight(id){

var x = document.getElementById(id);

if (x)
{
x.style.color = "#FA9A00";
x.onmouseout = "";
x.onmouseover = "";

}
}


/* Highlight function invoked and defined on a per-page basis */
highlight('nav1')

function showLeftNav(num)
{
	for(i=1;i<7;i++)
	{
		//a = eval("document.all.LN" + i)
		a = document.getElementById("LN" + i);
		//alert("i="+i)
		
		if(i==num)
		{
			a.style.display='block';
		}else{
			a.style.display='none';
		}
	}
	
	
}

/* create the language option on the first run */ 
function buildLangs (name) {
	var langSelect = document.getElementById('jumpLangSelect');
	if (langSelect.length == 0) {
		for (i in language) {
			var n = new Option ( language[i][0],language[i][1] );
			langSelect[langSelect.length] = n;
			if (language[i][2]) langSelect.selectedIndex = langSelect.length -1;
		}
	} 
	show(name);
}

/* create the country option on the first run */ 
function buildCountries (name) {
	var countrySelect = document.getElementById('jumpCountrySelect');
	if (countrySelect.length == 0) {
		for (i in countryOptions) { 
			var n = new Option ( countryOptions[i][1],countryOptions[i][0] );
			countrySelect[countrySelect.length] = n;
		}
	} 
	show(name);
}

/* jump to the selected langauge if possible in the same location relative to the lang */
function jumpMenu (select) {
	var s = document.getElementById(select);
	location = s[s.selectedIndex].value;
}

function submitSearch () {

	f.submit();

}

function submitContact()
{
	var f = document.forms['contactUs'];
	if (f.elements[0].value == '')  // check for contact name
	{
		alert('Please enter a contact name.');
	}
	else if (f.elements[1].value == '')  // check for e-Mail address
	{
		alert('Please enter an e-Mail address.');
	}
	else if (f.elements[1].value != '' &&
    (f.elements[1].value.indexOf('@') == -1 ||
	 f.elements[1].value.indexOf('.') == -1))  // check for valid e-Mail address
	{
		alert('Please enter a valid e-Mail address.');		
  	}
	else if (f.elements[3] && f.elements[3].value == '-1')  // check for submission regarding
	{
		alert('Please select what your submission is regarding.');
	}
	else if (f.elements[3].value == '')  // check for comment
	{
		alert('Please enter a question or comment.');
	}
	else
	{
		f.submit();
	}
}

function submitEmail()
{
	var f = document.forms['emailThis'];
	if (f.elements[0].value == '')  // check for to address
	{
		alert('Please enter a to: address.');
	}
	else if (f.elements[1].value == '')  // check for e-Mail address
	{
		alert('Please enter your e-Mail address.');
	}
	else if (f.elements[0].value != '' &&
    (f.elements[0].value.indexOf('@') == -1 ||
	 f.elements[0].value.indexOf('.') == -1))  // check for valid e-Mail address
	{
		alert('Please enter a valid e-Mail address in the to: address.');		
  	} else if (f.elements[1].value != '' &&
    (f.elements[1].value.indexOf('@') == -1 ||
	 f.elements[1].value.indexOf('.') == -1))  // check for valid e-Mail address
	{
		alert('Please enter a valid e-Mail address for your address.');		
  	}
  	else if (f.elements[2].value == '')  // check for comment
	{
		alert('Please enter a message.');
	}
	else
	{
		;
	}
}

var CurrentSwapColor = '';

function SwapColor (me,inout,color) {
	var link = document.getElementById(me.id + 'Link');
	var doc = document.getElementById(me.id + 'Doc');
	if (inout == 'in') {
		link.style.color = color;
		if (doc) doc.className = 'relatedFilesActive';
	} else if (inout == 'out') {
		link.style.color = color;
		if (doc) doc.className = 'relatedFiles';
	}
}

function flyOut (me, inout) {
	var baseId = me.id;
	var bodyElement = document.body;
	if (leftNavFlyOut[baseId] == null) return;
	var toFly = document.getElementById(baseId + 'Flydown');
	if (toFly) {
		if (inout == 'show') {
			show(baseId,1);
		} else if (inout == 'hide') {
			globalHide = setTimeout("hide()",500);
		}
	} else {
		var ID = baseId + 'Flydown';
		var flyContainer = document.createElement('div');
		flyContainer.setAttribute('id', ID);
		flyContainer.onmouseover =  flyOutMouseOver;
		flyContainer.onmouseout =  flyOutMouseOut;
		flyContainer.style.position = 'absolute';
		flyContainer.style.top = (clientY -11) + 'px';
		flyContainer.style.left = '153px';
		flyContainer.style.backgroundColor = '#FFF';
		flyContainer.style.paddingTop = '6px';
		flyContainer.style.paddingLeft = '6px';
		flyContainer.style.border = '1px';
		flyContainer.style.borderColor = '#B2B2B2';
		flyContainer.style.borderStyle = 'solid';
		flyContainer.style.width = '153px';
		flyContainer.style.zIndex = 100;
		flyContainer.style.visibility = 'hidden';

		
		for (i in leftNavFlyOut[baseId]) {
			par = document.createElement('p');
			par.className = 'LeftNavFlyout';
			anchor = document.createElement('a');
			anchor.setAttribute('href',leftNavFlyOut[baseId][i][1]);
			anchor.appendChild(document.createTextNode(leftNavFlyOut[baseId][i][0]));
			par.appendChild(anchor);
			flyContainer.appendChild(par);
		}
		bodyElement.appendChild(flyContainer);
		show(baseId);
	}
}

function dropOut (me, inout) {
	var baseId = me.id;
	var files = document.getElementById('relatedFiles');
	if (files == null) return;
	var toDrop = document.getElementById(baseId + 'Flydown');
	if (toDrop) {
		toDrop.style.top = (11 + clientY + scrollY) + 'px';
		toDrop.onmouseover = flyOutMouseOverDoc;
		toDrop.onmouseout = flyOutMouseOutDoc;
		if (inout == 'show') {
			showDocInfo(baseId,1);
		} else if (inout == 'hide') {
			globalHideDoc = setTimeout("hideDocInfo()",500);
		}
	}
	return true;
}

function flyOutMouseOver (e) {
	show(current,1);
}

function flyOutMouseOut (e) {
	globalHide = setTimeout("hide()",250);
}

function flyOutMouseOverDoc (e) {
	showDocInfo(current,1);
}

function flyOutMouseOutDoc (e) {
	globalHide = setTimeout("hideDocInfo()",250);
}

function setEvent (e) {
	if (!e && !dom) {
		e = window.event;
		e.cancelBubble = false;
		if (document.documentElement && document.documentElement.scrollTop)
			scrollY = document.documentElement.scrollTop;
		else if (document.body)
			scrollY = document.body.scrollTop
	} else if (dom && e) {
		scrollY = window.pageYOffset;
	}
	if (!e) return;
	clientY = e.clientY;
}
