function initialize() {
	markNavigationLink(); 
}

function displayComingSoon() {
	alert("The ACO web portal is currently undergoing system-wide upgrade. Please check back later. Thank you!");
}

function refresh() {
	var regex = ".*(iphone|ipod|series60|symbian|android|windows ce|blackberry|palm).*";
	var agent = navigator.userAgent.toLowerCase();

	if (!agent.match(regex))
		document.location = document.location;
}

function loadPage(url, newWindow) {
	if (newWindow != undefined && newWindow == true)
		window.open(url);
	else
		document.location.href = url;
}

function roundedCorners(file, width, radius, applyTo, name) {
	var output = '';
	var basicStyle = 'position: absolute; background-image: url(\'' + file + '\'); height: ' + radius + 'px; width: ' + radius + 'px;';
	var topLeft = true;
	var topRight = true;
	var bottomLeft = true;
	var bottomRight = true;

	if (applyTo != undefined) {
		corners = applyTo.split(' ');

		if (corners[0] == undefined || ((corners[0] != true) && (corners[0] != 'true')))
			topLeft = false;

		if (corners[1] == undefined || ((corners[1] != true) && (corners[1] != 'true')))
			topRight = false;

		if (corners[2] == undefined || ((corners[2] != true) && (corners[2] != 'true')))
			bottomLeft = false;

		if (corners[3] == undefined || ((corners[3] != true) && (corners[3] != 'true')))
			bottomRight = false;
	}

	var basicTag = '<div ';

	if (name != undefined)
		basicTag += 'class="' + name + '" ';
		
	basicTag += 'style="';
	
	if (topLeft)
		output += basicTag + basicStyle + 'left: -' + width + 'px; top: -' + width + 'px;"></div>';

	if (topRight)
		output += basicTag + basicStyle + 'right: -' + width + 'px; top: -' + width + 'px; background-position: -' + radius + 'px 0px;"></div>';

	if (bottomLeft)
		output += basicTag + basicStyle + 'left: -' + width + 'px; bottom: -' + width + 'px; background-position: 0px -' + radius + 'px;"></div>';

	if (bottomRight)
		output += basicTag + basicStyle + 'right: -' + width + 'px; bottom: -' + width + 'px; background-position: -' + radius + 'px -' + radius + 'px;"></div>';

	document.write(output);
}

function fadeElements(classname, id, direction, speed)
{
	var elements;
	var jclass = "";
	var jid = "";
	
	if (classname != undefined)
		jclass = "." + classname;
	
	if (id != undefined)
		jid = "#" + id;

	elements = $(jid + jclass);

	if (direction == "in")
		$(elements).fadeIn(speed);
	else
		$(elements).fadeOut(speed);
}

function extractHtmlFilename(link) {
	if (link.length == 0)
		return link;
		
	var index = link.lastIndexOf("/");
    var name = link.substring(index + 1, link.length);

	index = name.lastIndexOf("\\");
    name = name.substring(index + 1, name.length);

	index = name.lastIndexOf("#");
	
	if (index >= 0)
    	name = name.substring(0, index);

	if (name.length <= 0)
		name = "index.html";
	
	return name;
}

function markCurrentLink() {
    var name = extractHtmlFilename(document.URL);

	for (i = 0; i < document.links.length; i++) {
		if (document.links[i].href.match(name))
			document.links[i].style.color = "#ffe2c0";
	}    
}

function markNavigationLink(link) {
	if (link == undefined)
		link = document.URL;
		
    var name = extractHtmlFilename(link);
	var links = $(".header_tab a");

	for (i = 0; i < links.length; i++) {
		if (links[i].href.match(name))
			links[i].style.color = "#ffe2c0";
	}    
}

function tracer(clearance, lineHeight, tracePoints, debug) {
	var output = '';
	var frame = '';
	
	if (debug)
		frame = 'border: 1px red solid; ';
	
	points = tracePoints.split(';');
	
	if (clearance > 0)
		output = '<div style="float: left; clear: left; height: ' + clearance + 'px; width: 0px;"></div>';
		
	for(i = 0; i < points.length; i++) {
		parts = points[i].split(',');
		
		if (parts.length < 3)
			continue;
			
		height = Math.round(lineHeight * parts[2]);
		
		if (parts[0].indexOf('%') >= 0)
			ending = ';';
		else
			ending = 'px;';
		
		output += '<div style="' + frame + 'float: left; clear: left; height: ' + height + 'px; width: ' + parts[0] + ending + '"></div>';

		if (parts[1].indexOf('%') >= 0)
			ending = ';';
		else
			ending = 'px;';
		
		output += '<div style="' + frame + 'float: right; clear: right; height: ' + height + 'px; width: ' + parts[1] + ending + '"></div>';
	}
	
	document.write(output);
}

function getLoadedSectionID(containerID) {
	var column = document.getElementById(containerID);
	
	if (column == undefined)
		return null;
		
    var loadedSectionID;
    
	for (i = 0; i < column.childNodes.length; i++) {
		if (column.childNodes[i].nodeName == "DIV") {
			if (column.childNodes[i].style.display != "none")
			    loadedSectionID = column.childNodes[i].id;
		}
	}
	
	return loadedSectionID;
}

function loadSection(sectionID, containerID) {
	var column = document.getElementById(containerID);
    var loadedSectionID = getLoadedSectionID(containerID);

    if (column == undefined || loadedSectionID == undefined)
    	return;
    	
	for (i = 0; i < column.childNodes.length; i++) {
		if (column.childNodes[i].nodeName == "DIV") {
			column.childNodes[i].style.display = "none";
		}
	}
	
	document.getElementById(sectionID).style.display = "block"; 
}

