// JavaScript Document
// Contains a series of scripts to build elements of 
// of the sites pages
// Copyright Leonard Horthy 2003 - All rights reserved

// Requires page struct to be declared (see site_struct.js)


var pos;
var sectionId;
var subSectionId = '';

// Parse out sectionId and subSectionId from path
var docHREF = document.location.href; // get path
// get file name
var fileName = docHREF.substring(docHREF.lastIndexOf('/') + 1, docHREF.length);

pos = fileName.indexOf('_');// find position of first underscore

if (pos > 0){ // if there is an underscore then get section and subsection
	sectionId = fileName.substring(0, pos);
	subSectionId = fileName.substring(pos + 1, fileName.indexOf('.'));
} else { // no underscore
	sectionId = fileName.substring(0, fileName.indexOf('.'));
}

// Clear any third level description off the end of subSectionId
pos = subSectionId.indexOf('_');
if (pos > 0) subSectionId = subSectionId.substring(0, pos);

//alert(sectionId);
//alert('Sub Section: ' + subSectionId);

// find out which section we are in
var curSection = siteSections[0]; //default to home page
for(var i = 0; i < siteSections.length; i++) {
		//alert('i=' + i + ' sec=' + siteSections[i].id);
	if (siteSections[i].id == sectionId) {
		curSection = siteSections[i];
		break;
	}
}

//alert('done ' + curSection.id);

function buildBanner() 
{
	//alert('function buildBanner()');

	var htmlCode = '';
	htmlCode += '<table border="0" cellpadding="0" cellspacing="0">\n';
	htmlCode += '<tr>\n';
	htmlCode += '<td width="640"><img src="';
	htmlCode += curSection.banner;
	htmlCode += '" width="640" height="95"></td>\n';
	htmlCode += '<td width="3" bgcolor="#000000">';
	htmlCode += '<img src="images/spacer.gif" width="3" height="1"></td>\n';
 	htmlCode += '</tr>\n';
	htmlCode += '</table>';
    
    //alert(htmlCode);
    
    document.write(htmlCode);
}

function buildNavBar() 
{
	//alert('function buildNavBar()');

	var htmlCode = '';
	htmlCode += '<tr>\n';
	htmlCode += '<td height="35" bgcolor="' + curSection.color + '">\n';
	htmlCode += '<table width="100%" border="0" cellpadding="2" cellspacing="3">\n';
	htmlCode += '<tr><td>';
	
	// build a link to each section
	for(var i = 0; i < siteSections.length; i++) {
	
		if (siteSections[i].id == sectionId) {
			// special color for news link
			if (sectionId == 'news') htmlCode += '<a class="highlight1a" href="';
			else htmlCode += '<a class="highlight1" href="';
		} else {
			htmlCode += '<a class="link1" href="';
		}
		
		htmlCode += siteSections[i].fileName + '">' + siteSections[i].navLabel + '</a>';
		
		if (i < (siteSections.length - 1))
			htmlCode += ' <span class="divider1"> :: </span> \n'; // :: etc.
	}
	
	htmlCode += '</td>\n';
	htmlCode += '<td align="right" class="pageTitle">';
	htmlCode += curSection.label1;
	htmlCode += '<span class="pageTitleBold">';
	htmlCode += curSection.label2;
	htmlCode += '</span></td>\n';
	htmlCode += '</tr></table></td>\n';
    htmlCode += '</tr>';
    
    //alert(htmlCode);
    
    document.write(htmlCode);
}

function buildSubNavBar() 
{
	var htmlCode = '';
	var curSubSectionId = '';
	var pos;
	
	// build a link to each section
	for(var i = 0; i < curSection.subLinks.length; i++) {
		
		// parse the subsection id out of the file name
		pos = curSection.subLinks[i].indexOf('_')
		if (pos > 0) curSubSectionId = curSection.subLinks[i].substring(pos + 1, 
			curSection.subLinks[i].indexOf('.'));
		//alert ('cur: '+ curSubSectionId + '\nsub: ' + subSectionId);
		
		if (curSubSectionId == subSectionId) htmlCode += '<a class="highlight2" href="';
		else htmlCode += '<a class="link2" href="';
		
		htmlCode += curSection.subLinks[i] + '">' + curSection.subLabels[i] + '</a>';
		
		if (i < (curSection.subLinks.length - 1))
			htmlCode += ' <span class="divider2"> :: </span> \n'; // :: etc.
	}
	
    
    //alert(htmlCode);
    
    document.write(htmlCode);
}







function buildCopyright() 
{
	var htmlCode = '';
	htmlCode += '<tr>\n';
	htmlCode += '<td height="19" align="center" valign="middle" bgcolor="';
	htmlCode +=  curSection.color;
	htmlCode += '" class="copyrightText">Copyright\n';
	htmlCode += '&copy; 2010 All rights reserved.</td>\n';
	htmlCode += '</tr>\n';
   
    //alert(htmlCode);
    
    document.write(htmlCode);
}

