var APPLICATIONPATH = '/';
var SUBNAVTIMEOUT = 999999999999;

var reverts = new Array();
var mouseInSubNav = false;

function openAcrobat() {
	var acro = window.open('http://www.adobe.com/products/acrobat/readstep2.html', 'acrobat', 'width=750,height=500,scrollbars=yes,toolbar=yes,status=yes,resizable=yes');
	acro.focus();
}

function hideHelp() {
	hideDescription();
}

function helpText(name) {
	var container = document.createElement('span');
	
	var icon = document.createElement('img');
	icon.setAttribute('src', APPLICATIONPATH + 'media/images/icon/info.gif');
	icon.setAttribute('align', 'absmiddle');
	icon.setAttribute('hspace', '3');
	
	var text = null;
	
	switch(name) {
		case 'acrobat':
			text = document.createTextNode('This form is provided in PDF format. To read a PDF file, you will need Adobe Acrobat Reader which can be downloaded free of charge from the Adobe website.');
			break;
	}
	
	container.appendChild(icon);
	container.appendChild(text);
	
	showDescription(container);
}

if(!document.all) { document.captureEvents(Event.MOUSEMOVE); }
document.onmousemove = getMouseXY;

var tempX = 0
var tempY = 0
var id_intern = 'fastalt_container';
var show_element = null;
var lastTimeoutID = null;

function getMouseXY(e) {
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}  

	if(tempX < 0) { tempX = 0; }
	if(tempY < 0) { tempY = 0; }
	
	if(show_element != null) {
		show_element.style.top = tempY + 2;
		show_element.style.left = tempX + 10;
	}
	
	return true;
}

function Point(x, y) {
	this.x = x;
	this.y = y;
}

function changeText(obj, text) {
	if(obj) {
		if(obj.innerHTML) {
			obj.innerHTML = text;
		} else if(obj.childNodes) {
			var newText = document.createTextNode(text);
			for(var i = 0; i < obj.childNodes.length; i++) {
				if(obj.childNodes[i].nodeType == Node.TEXT) {
					obj.replaceChild(newText, obj.childNodes[i]);
					return;
				}
			}
			obj.appendChild(newText);
		}
	}
}

function showDescription(el) {
	show_element = getObj(id_intern);
	
	while(show_element.hasChildNodes()) {
		show_element.removeChild(show_element.childNodes[0]);
	}
	
	show_element.style.display = 'block';
	show_element.appendChild(el);
	if(lastTimeoutID != null) {
		window.clearTimeout(lastTimeoutID);
	}
}

function hideDescription() {
	if(show_element != null) {
		lastTimeoutID = window.setTimeout('if(show_element != null) { show_element.style.display = "none"; show_element = null; }', 350);
	}
}

function inSubNav() {
	mouseInSubNav = true;
}

function outSubNav() {
	mouseInSubNav = false;
}

function revertSubNav(name) {
	if(mouseInSubNav) {
		return;
	}
	resetSubNavTimeout();
	clearSubNav(name);
	
	if(window.defaultSubNav) {
		var subnav = findSubNav(defaultSubNav);
		
		if(subnav != null) {
			writeSubNav(subnav, name);
		}
	}
}

function resetSubNavTimeout() {
	var next = reverts.pop();
	while(next) {
		window.clearTimeout(next);
		next = reverts.pop();
	}
}

function clearSubNav(name) {
	var container = getObj(name + 'drop');

	while(container.hasChildNodes()) {
		container.removeChild(container.childNodes[0]);
	}
}

function findSubNav(name) {
	if(!window.subnavs) {
		return null;
	}
	
	for(var i = 0; i < subnavs.length; i++) {
		if(name.toLowerCase() == subnavs[i].name.toLowerCase()) {
			return subnavs[i];
		}
	}
}

function writeSubNav(subnav, name) {

	
	if(name == null || name == '')
	{
		name = defaultSubNav;
	}
	
	var container = getObj(name + 'drop');
	var UList = document.createElement('div');
	UList.setAttribute('class', 'drop');
	for(var s = 0; s < subnav.items.length; s++) {
		
		//var List = document.createElement('li')
		//List.setAttribute('id', name);
		//List.setAttribute('class', 'dropli');
		var newSub = document.createElement('a');
		newSub.setAttribute('href', subnav.items[s].template + '?item=' + subnav.items[s].path);
 		
		newSub.appendChild(document.createTextNode(subnav.items[s].title));
		
		///var sep = document.createElement('img');
		//sep.setAttribute('src', APPLICATIONPATH + 'media/images/subnav-spacer.gif');
		//sep.setAttribute('align', 'absmiddle');
		//sep.setAttribute('hspace', '6');
		var br = document.createElement('br');
		UList.appendChild(newSub);
		UList.appendChild(br);
	//	container.appendChild(newSub);
		
		//if(s < (subnav.items.length - 1)) {
		//	List.appendChild(sep);
		//}
		//UList.appendChild(List);
	}
	container.appendChild(UList);
}
function Rollover(offFilename) {
	var dashIndex = offFilename.lastIndexOf('-');
	
	if(dashIndex < 0) {
		alert('Javascript application error: ' + filename + ' is not a valid nav filename. Please use the pattern \'filename-off.gif\'');
		return;
	}
	
	var onFilename = offFilename.substring(0, dashIndex) + '-on.gif';
	var overFilename = offFilename.substring(0, dashIndex) + '-over.gif';
	
	var on = new Image();
	on.src = APPLICATIONPATH + 'media/images/' + onFilename;
	
	var off = new Image();
	off.src = APPLICATIONPATH + 'media/images/' + offFilename;
	
	var over = new Image();
	over.src = APPLICATIONPATH + 'media/images/' + overFilename;
	
	this.mover = function(obj, name) {
		obj.src = over.src;
		if(name === undefined || !window.subnavs) {
			return;
		}
		
		var subnav = findSubNav(name);
		
		if(subnav != null && subnav.items.length > 0) {
			clearSubNav(name);
			resetSubNavTimeout();
			writeSubNav(subnav, name);
		}
	}
	
	this.mout = function(obj, name) {
		obj.src = off.src;
		var revertText = 'revertSubNav(' + name + ')'
		reverts.push(window.setInterval(revertText, SUBNAVTIMEOUT));
	}
}

function SubNavGroup(name) {
	this.name = name;
}

function SubNavItem(template, path, title) {
	this.template = template;
	this.path = path;
	
	this.title = title;
}

function getObj(id) {
	if(document.all) {
		return document.all[id];
	} else if(document.getElementById) {
		return document.getElementById(id);
	} else if(document.layers) {
		return document.layers[id];
	} else {
		alert('This browser doesn\'t support "document.all", "document.layers", or "document.getElementById".');
		return null;
	}
}

function getPosition(el) {
	if(document.all) {
		return getPositionIE(el);
	} else if(document.getElementById) {
		return getPositionNS(el);
	}
}

function getPositionNS(el) {
	return new Point(el.x, el.y);
}

function getPositionIE(el) {
	var r = new Point(el.offsetLeft, el.offsetTop);
	
	if(el.offsetParent) {
		var tmp = getPositionIE(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}

	return r;
}




//jQuery(document).ready(function($) {

//	$('.navli').hover(function() {
//			var id = $(this).attr('id') + 'drop';
//			$('#'+ id).css('display', 'block');
//	},
//		function() 
//	{
//			var id = $(this).attr('id') + 'drop';
//			$('#' + id).css('display', 'none');
//	});
//});

//function clearSubNav() {

	
	///var container = getObj(name + 'drop');

	//while(container.hasChildNodes()) {
	//	container.removeChild(container.childNodes[0]);
	//}
//}

//function findSubNav(name) {
	//if(!window.subnavs) {
	//	return null;
	//}
	
	///for(var i = 0; i < subnavs.length; i++) {
		///if(name.toLowerCase() == subnavs[i].name.toLowerCase()) {
		//	return subnavs[i];
		///}
	//}
//}


