/* Javascript */

// Onload Manager
window.onload = function() {
	preloadHomepageImages();
	prepHomepageSections();
	prepFormTabs();
	// prepLinks();
}
// Homepage Image Preloader
function preloadHomepageImages() {
	// Test to make sure we're on the homepage
	if (!document.getElementById("homeContent")) return false;
	// If so, get to loading the images
	image1 = new Image();
	image1.src = "common/img/home_baseBackground_one.gif";
	image2 = new Image();
	image2.src = "common/img/home_bottomBackground.gif";
	image3 = new Image();
	image3.src = "common/img/home_baseBackground_two.gif";
	image4 = new Image();
	image4.src = "common/img/home_baseBackground_three.gif";
	image5 = new Image();
	image5.src = "common/img/home_baseBackground_four.gif";
	image6 = new Image();
	image6.src = "common/img/home_baseBackground_five.gif";
	image7 = new Image();
	image7.src = "common/img/home_baseBackground_six.gif";
	image8 = new Image();
	image8.src = "common/img/home_baseBackground_eight.gif";

}

function prepHomepageSections() {
	// Make sure these methods are supported and quit if they aren't
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	//Test to make sure we're on the homepage
	if (!document.getElementById("homeContent")) return false;
	
	// Get the sectionsNav list
	var sectionNavigation = document.getElementById("sectionNav");
	var sectionLinks = sectionNavigation.getElementsByTagName("a");
	// And the container that displays the background image
	var sectionsContainer = document.getElementById("sections");
	// And all the divs iin that
	var divsInSections = sectionsContainer.getElementsByTagName("div");
	// Set The first item to be selected
	sectionLinks[0].setAttribute("class","selected");
	
	// Attach the behavior to the mouseover event
	sectionLinks[0].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[0].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_one.gif)';
		document.getElementById("sectionOne").style.display = "block";
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "none";

	}
	
	sectionLinks[1].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[1].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_two.gif)';
		document.getElementById("sectionOne").style.display = "none";
		document.getElementById("sectionTwo").style.display = "block";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "none";

	}

	sectionLinks[2].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[2].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_three.gif)';
		document.getElementById("sectionOne").style.display = "none";
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "block";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "none";
	}
	
	sectionLinks[3].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[3].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'none';
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_four.gif)';
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "block";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "none";
	}

	sectionLinks[4].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[4].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_five.gif)';
		document.getElementById("sectionOne").style.display = "none";
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "block";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "none";
	}
	
	sectionLinks[5].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[5].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_six.gif)';
		document.getElementById("sectionOne").style.display = "none";
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "block";
		document.getElementById("sectionSeven").style.display = "none";
	}
	
	sectionLinks[6].onmouseover = function() {
		for (var i=0; i<sectionLinks.length; i++) {
			sectionLinks[i].setAttribute("class","unselected");
		}
		sectionLinks[6].setAttribute("class","selected");
		sectionsContainer.style.backgroundImage = 'url(common/img/home_baseBackground_seven.gif)';
		document.getElementById("sectionOne").style.display = "none";
		document.getElementById("sectionTwo").style.display = "none";
		document.getElementById("sectionThree").style.display = "none";
		document.getElementById("sectionFour").style.display = "none";
		document.getElementById("sectionFive").style.display = "none";
		document.getElementById("sectionSix").style.display = "none";
		document.getElementById("sectionSeven").style.display = "block";
	}

}


function prepFormTabs() {
	// Make sure these methods are supported and quit if they aren't
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	//Test to make sure we're on a formTabs page
	if (!document.getElementById("formTabs")) return false;
	if (!document.getElementById("formOne")) return false;
	
	// Get the tabNavigation list
	var tabNavigation = document.getElementById("formTabs");
	var tabLinks = tabNavigation.getElementsByTagName("a");
	
	// And all the formModules we need
	var formModuleOne = document.getElementById("formOne");
	var formModuleTwo = document.getElementById("formTwo");
	var formModuleThree = document.getElementById("formThree");
	
	// Get all  the inputs in each formModule
	var formModuleOneInputs = formModuleOne.getElementsByTagName("input");
	var formModuleTwoInputs = formModuleTwo.getElementsByTagName("input");
	if (formModuleThree != null) {
			var formModuleThreeInputs = formModuleThree.getElementsByTagName("input");
		}
	
	
	// Set The first item to be selected
	tabLinks[0].style.borderLeftColor = "#CCCCCC";
	tabLinks[0].style.borderRightColor = "#CCCCCC";
	tabLinks[0].style.borderTopColor = "#CCCCCC";
	tabLinks[0].style.borderBottomColor = "#FFFFFF";
	tabLinks[0].style.fontWeight = "bold";
	tabLinks[0].style.textDecoration = "none";
	tabLinks[0].style.color = "#000000";
	formModuleOneInputs[0].focus();
	
	// Attach the behavior to the mouseover event
	tabLinks[0].onclick = function() {
		for (var i=0; i<tabLinks.length; i++) {
			tabLinks[i].style.borderLeftColor = "#FFFFFF";
			tabLinks[i].style.borderRightColor = "#FFFFFF";
			tabLinks[i].style.borderTopColor = "#FFFFFF";
			tabLinks[i].style.borderBottomColor = "#CCCCCC";
			tabLinks[i].style.fontWeight = "normal";
			tabLinks[i].style.textDecoration = "underline";
			tabLinks[i].style.color = "#999999";
		}
		tabLinks[0].style.borderLeftColor = "#CCCCCC";
		tabLinks[0].style.borderRightColor = "#CCCCCC";
		tabLinks[0].style.borderTopColor = "#CCCCCC";
		tabLinks[0].style.borderBottomColor = "#FFFFFF";
		tabLinks[0].style.fontWeight = "bold";
		tabLinks[0].style.textDecoration = "none";
		tabLinks[0].style.color = "#000000";
		formModuleOne.style.display = "block";
		formModuleTwo.style.display = "none";
		if (formModuleThree != null) {
			formModuleThree.style.display = "none";
		}
		formModuleOneInputs[0].focus();
		return false;
	}
	
	tabLinks[1].onclick = function() {
		for (var i=0; i<tabLinks.length; i++) {
			tabLinks[i].style.borderLeftColor = "#FFFFFF";
			tabLinks[i].style.borderRightColor = "#FFFFFF";
			tabLinks[i].style.borderTopColor = "#FFFFFF";
			tabLinks[i].style.borderBottomColor = "#CCCCCC";
			tabLinks[i].style.fontWeight = "normal";
			tabLinks[i].style.textDecoration = "underline";
			tabLinks[i].style.color = "#999999";
		}
		tabLinks[1].style.borderLeftColor = "#CCCCCC";
		tabLinks[1].style.borderRightColor = "#CCCCCC";
		tabLinks[1].style.borderTopColor = "#CCCCCC";
		tabLinks[1].style.borderBottomColor = "#FFFFFF";
		tabLinks[1].style.fontWeight = "bold";
		tabLinks[1].style.textDecoration = "none";
		tabLinks[1].style.color = "#000000";
		formModuleOne.style.display = "none";
		formModuleTwo.style.display = "block";
		if (formModuleThree != null) {
			formModuleThree.style.display = "none";
		}
		formModuleTwoInputs[0].focus();
		return false;
	}

	if (formModuleThree != null) {
		tabLinks[2].onclick = function() {
			for (var i=0; i<tabLinks.length; i++) {
				tabLinks[i].style.borderLeftColor = "#FFFFFF";
				tabLinks[i].style.borderRightColor = "#FFFFFF";
				tabLinks[i].style.borderTopColor = "#FFFFFF";
				tabLinks[i].style.borderBottomColor = "#CCCCCC";
				tabLinks[i].style.fontWeight = "normal";
				tabLinks[i].style.textDecoration = "underline";
				tabLinks[i].style.color = "#999999";
			}
			tabLinks[2].style.borderLeftColor = "#CCCCCC";
			tabLinks[2].style.borderRightColor = "#CCCCCC";
			tabLinks[2].style.borderTopColor = "#CCCCCC";
			tabLinks[2].style.borderBottomColor = "#FFFFFF";
			tabLinks[2].style.fontWeight = "bold";
			tabLinks[2].style.textDecoration = "none";
			tabLinks[2].style.color = "#000000";
			formModuleOne.style.display = "none";
			formModuleTwo.style.display = "none";
			formModuleThree.style.display = "block";
			formModuleThreeInputs[0].focus();
			return false;
		}
	}
}

