// Trigger DropDown Nav in IE6
startList = function(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					subUL = this.getElementsByTagName("ul");
					if(subUL.length>0) subUL[0].style.display = 'block';
					//this.className+=" over";
				}
				node.onmouseout=function() {
					subUL = this.getElementsByTagName("ul");
					if(subUL.length>0) subUL[0].style.display = 'none';
					//this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
addLoadEvent(startList)


// Set Active State & Expand LeftNav Subs
function leftnav(){
	if(!document.getElementById) return;
	var lnav = document.getElementById('leftnav');
	if(!lnav) return;
	// Get page name
	var url = window.location.pathname;
	var page = url.substring(url.lastIndexOf('/') + 1/*,url.lastIndexOf('.')*/);
	
	// If subpage...
	if(page.indexOf('_')!=-1){
		// If it's an upperlevel subpage...
		if(page.indexOf('_') == page.lastIndexOf('_')){
			var parent = "";
		} else { // If it's a sub-sub page...
			var parent = page.substring(0,page.lastIndexOf('_'))+".html";
			
		}
	} else { // Not a subpage...
		return;
	}
	
	lnavList = lnav.getElementsByTagName('li');
	for(x=0;x<lnavList.length;x++){
		var e = lnavList[x].firstChild.toString();
		// If it's a main sub page
		if(!parent){
			if(page == e.substring(e.lastIndexOf('/') + 1)){
				addClass(lnavList[x],'active');
				if(lnavList[x].getElementsByTagName('ul').length>0){
					lnavList[x].getElementsByTagName('ul')[0].style.display = 'block';
				}
			}
		}
		// If it's a sub sub page
		else {
			// Expand the Subs
			if(parent == e.substring(e.lastIndexOf('/') + 1)){
				if(lnavList[x].getElementsByTagName('ul').length>0){
					lnavList[x].getElementsByTagName('ul')[0].style.display = 'block';
				}
			}
			// Set sub nav active
			if(page == e.substring(e.lastIndexOf('/') + 1)){
				addClass(lnavList[x],'active');
			}
		}
	}
	// *** If it's an article for News Room...
	if(page.indexOf('_') != page.lastIndexOf('_') && page.indexOf('newsRoom')!=-1){
		for(i=0;i<lnavList.length;i++){
			var e = lnavList[i].firstChild.toString();
			if(parent == e.substring(e.lastIndexOf('/') + 1)){
				addClass(lnavList[i],'active');
			}
		}
	}
}
addLoadEvent(leftnav);



// Random Fact on Refresh
function randomFact(){
	if(!document.getElementById) return;
	if(!document.getElementById('randomFact')) return;
	p = document.getElementById('randomFact');
	var rand = Math.floor(Math.random()*facts.length);
	p.innerHTML = facts[rand];
	// On homepage there are two Random Facts...
	if(document.getElementById('randomFact2')) {
		p2 = document.getElementById('randomFact2');
		var rand2 = Math.floor(Math.random()*facts.length);
		// Don't show the same fact...
		if(rand == rand2){
			if(rand==(facts.length-1)){rand2-=1;}
			else {rand2+=1;}
		}
		p2.innerHTML = facts[rand2];
	}
}
addLoadEvent(randomFact);
	// Facts
	var facts = new Array(
		"The average rail employee's compensation puts them in the top nine percent of all wage earners in United States.",
	
		"With freight demand expected to jump 67% in the next 20 years, freight railroads are expected to hire more than 80,000 new workers over the next six years.",
	
		"North American railroads operate more than 173,000 miles of track.<br><br><span class='factSource'>Source: RR Industry info</span>",
	
		"North American railroads earn $42 billion in annual revenues.<br><br><span class='factSource'>Source: RR Industry info</span>",
		
		"In the U.S., railroads account for more than 40 percent of all freight transportation -that's more than trucks, boats, barges or planes.<br><br><span class='factSource'>Source: RR Industry info</span>",
		
		"U.S. freight railroads are the world's busiest, moving more freight than any rail system in any other country. In fact, U.S. railroads move more than four times as much freight as do all of Western Europe's freight railroads combined.<br><br><span class='factSource'>Source: RR Industry info</span>",
		
		"The more than 600 freight railroads operating today in Canada, Mexico, and the United States are vital to North America's economic health.",
		
		"Seventy percent of all automobiles produced in the U.S. move by train. So does 30 percent of the nation's grain harvest and 65 percent of the coal which, in turn, provides more than half of the nation's electricity.<br><br><span class='factSource'>Source: RR Industry info</span>",
		
		"Every ton of freight that moves one mile by rail instead of by truck reduces greenhouse gas emissions by two-thirds or more.<br><br><span class='factSource'>Source: BNSF</span>",
		
		"On average, railroads are three times more fuel efficient than trucks and railroad fuel efficiency is improving all the time.<br><br><span class='factSource'>Source: RR Industry info</span>",
		
		"According to the EPA, railroads account for just nine percent of total transportation-related NOx emissions and four percent of transportation-related particulate emissions, even though they account for 42 percent of the nation's intercity freight ton-miles.",
		
		"U.S. freight railroads-a $55 billion industry-are a vital link in the national economy, connecting producers with manufacturers and distributors at home and abroad, via a network of more than 140,000 route-miles that serve every major U.S. port and metropolitan area.<br><br><span class='factSource'>Source: raillaborfacts.org</span>",
		
		"From 1980 to 2006, freight railroads spent more than $375 billion to maintain and improve infrastructure and equipment.",
		
		"According to the American Association of State Highway and Transportation Officials, if all the freight that moves by rail today were switched to truck, shippers would pay an extra $69 billion annually in transportation costs."

		
		
		
		
		
		
		
	);




// Validate Careers Request Info form...
function validateCareersRequestInfo(){
	if(!document.getElementById) return;
	if(!document.getElementById('careersRequestInfo')) return;
	document.getElementById('careersRequestInfo').onsubmit = function(){
		var e = 0;
		if(!validateElem('fname','txt','You must enter your First Name.')){e = ++e;}
		if(!validateElem('lname','txt','You must enter your Last Name.')) {e = ++e;}
		if(!validateElem('email','email','You must enter a valid Email address.')){e = ++e;}
		
		if(e == 0) return true;
		else {
			alert(msg);
			msg = "";
			return false;
		}
	}
}
addLoadEvent(validateCareersRequestInfo);

// Validate Employee Request Info form...
function validateEmployeeRequestInfo(){
	if(!document.getElementById) return;
	if(!document.getElementById('employeeRequestInfo')) return;
	document.getElementById('employeeRequestInfo').onsubmit = function(){
		var e = 0;
		if(!validateElem('fname','txt','You must enter your First Name.')){e = ++e;}
		if(!validateElem('lname','txt','You must enter your Last Name.')){e = ++e;}
		if(!validateElem('company','txt','You must enter your Company Name.')){e = ++e;}
		if(!validateElem('email','email','You must enter a valid Email address.')){e = ++e;}
			
		if(e == 0) return true;
		else{
			alert(msg);
			msg = "";
			return false;
		}
	}
}
addLoadEvent(validateEmployeeRequestInfo);

// Validate form elements....
var msg = "";
function validateElem(id,type,error){
	if(type == 'txt'){
		if(!document.getElementById(id) || trim(document.getElementById(id).value) == ""){
			msg += error + "\n";
			return false;
		}
	} else if(type == 'email'){
		if(!document.getElementById(id) || trim(document.getElementById(id).value) == ""){
			msg += error + "\n";
			return false;
		} else if(!checkRegex(document.getElementById(id).value, /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/)){
			msg += error + "\n";
			return false;
		}
	}
	return true;
}
function checkRegex(object_value, regex) {return regex.test(object_value);}
function trim(value) {var temp = value;	var obj = /^(\s*)([\W\w]*)(\b\s*$)/; if (obj.test(temp)) { temp = temp.replace(obj, '$2'); } var obj = / +/g; temp = temp.replace(obj, " "); if (temp == " ") { temp = ""; } return temp;}



	
	
	
	
	
	
	
	
	
// Adds functions to onload event
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){window.onload = func;}
	else{window.onload = function(){oldonload(); func();}}
}

// Add ClassName to Element
function addClass(element,value){
	if (!element.className){element.className = value;}
	else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}