var subnavlis;	
var ffpage;
var x=true;




   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", loadpage, false);
   }
   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
       document.write('<script defer src="http://www.cfo.com/js/ie_onload.js"><'+'/script>');
   /*@end @*/
	window.onload=loadpage;



function loadpage(){
	if(x){
		x=false;
	//remove right image-made table padding;
	document.getElementById("wideWrap").getElementsByTagName("table")[0].getElementsByTagName("td")[2].getElementsByTagName("img")[0].width="0";
	if(getElementsByClassName("ffH1")[0].parentNode) {getElementsByClassName("ffH1")[0].parentNode.width="990"; getElementsByClassName("ffH1")[0].className+=" firstffH1";}
	
	if (isSection("Employer") && !isSection("Client")) emp();
	if (isSection("JobSeeker") && !isSection("Client")) seeker();
	
	fixButtons();
	}
}

function emp(){
	empNav();
	empReplaceHome();
}

function seeker(){
	jsNav();
	
}



//isSection(section name) returns true or false for a section name in the URL. Typically this would be used to find "Employer", "JobSeeker", or "Client"
function isSection(secname){
	var pathname=window.location.pathname.toLowerCase();
	secname=secname.toLowerCase();
	if(pathname.indexOf(secname)!= "-1"){ return true; }
	else return false;
}

//makeCrumbs: returns the page name for the bottom breadcrumb. Searches the text of the ffH1 of the page.
function makeCrumbs(){	
		// This is an array for overrides. Put the filename before ".aspx" as the key for corresponding trailing crumb
		var pagecrumbs = { "EmpHome": "Employer Home", "JobSeekerAccount": "My Job Seeker Account"};
		
		if(pagecrumbs[ffpage]) return("&nbsp;:&nbsp;" + pagecrumbs[ffpage]);
		else if(getElementsByClassName("ffH1")[0]) return "&nbsp;:&nbsp;" + getElementsByClassName("ffH1")[0].innerHTML;
		else return "";
}
	
// any necessary button changes. 
function fixButtons(){
	if(document.getElementById("btnHidden_PageSizeChange")){
		document.getElementById("btnHidden_PageSizeChange").setAttribute("value", "go");
	}

}


// unlike getElementsByTagName, this does not have a calling object; it searches the whole dom. this can be changed later but references to it will need to be prepended with a parent node.	
function getElementsByClassName(findclass){
	var j=0;
	var thisset = new Array();
	var allPageTags=document.getElementsByTagName("*");
	for(var i=0; i<allPageTags.length; i++){
		if(allPageTags[i].className.indexOf(findclass)!=-1){
			thisset[j]=allPageTags[i];
			j++;
		}
	}
	return thisset;
}


//element builder/destroyer. makeElement with no innertext should be included in inline html so it can be called to make nav placeholder.
function makeTextElement(tagname, innertext, id){
	var thisnode=document.createElement(tagname);
	thisnode.appendChild(document.createTextNode(innertext));
	thisnode.setAttribute("id", id);
	return thisnode;
}




function empNav(){
	var jsnav=makeElement("div", "jsnav");
	jsnav.innerHTML='<div class="ffCrumbs"><div class="ffCrumbsTop clear"><h1>Post and Manage Jobs<\/h1><ul class="ffCrumbsNav"><li><a href="\/Employer\/EmpHome.aspx?abbr=CFOCOM">Employer home</a> | <\/li><li><a href="\/Employer\/EmpJobs.aspx?abbr=CFOCOM">Post\/view jobs<\/a> | <\/li><li><a href="\/Employer\/ApplicationList.aspx?abbr=CFOCOM">Manage applications</a> | <\/li><li><a href="\/Employer\/ResumeMenu.aspx?abbr=CFOCOM">Search resumes</a> | <\/li><li><a href="\/Employer\/emphelp.aspx?abbr=CFOCOM" onclick="showHelp()\; return false\;">Help</a> | <\/li><li>' + emploginlink() +'<\/li><\/ul><\/div><p class="clear"><span class="ffCrumbBottom">You are here: <a href="http:\/\/www.cfo.com\/?f=bc">Home</a>&nbsp\;:&nbsp\;<a href="http:\/\/www.cfo.com\/careers\/?f=bc">Careers</a>&nbsp\;:&nbsp\;<a href="\/Employer\/EmpHome.aspx?abbr=CFOCOM">Post and Manage Jobs<\/a>' + makeCrumbs() + '<\/span><span class="ffCrumbUname">' + empUname() +'<\/span><\/p><\/div>';
	getElementsByClassName("firstffH1")[0].parentNode.insertBefore(jsnav, getElementsByClassName("firstffH1")[0]);

}

//constructs the Employer login link; we want to clear the old navigational element in the body, so we set a loggedin variable before doing so
function emploginlink(){
	if(loggedin) return '<a href="http://jobs.cfo.com/Employer/Logout.aspx?abbr=CFOCOM">Log Out</a>';
	else {return '<a href="http://jobs.cfo.com/Employer/Login.aspx?abbr=CFOCOM">Log In</a>';}
}


//return employer's username, if found.
function empUname(){
	var empu="";
	if(document.getElementById("lblEmpAndUser")){
		var empstring=document.getElementById("lblEmpAndUser").innerHTML;
		empu=empstring.substring(empstring.toLowerCase().indexOf("<br>")+4, empstring.toLowerCase().indexOf("</b>"));
		var empcont=document.getElementById("lblEmpAndUser").parentNode;
		empcont.parentNode.removeChild(empcont);
	}
	if(isSection("EmpHome") && loggedin){
		var empstring=document.getElementById("rowWelcome").getElementsByTagName("td")[0].innerHTML;
		empu=empstring.substring(empstring.toLowerCase().indexOf("<i>")+3, empstring.toLowerCase().indexOf("</i>"));
		removeElement(document.getElementById("rowWelcome").getElementsByTagName("td")[0]);
	}
	return empu;
}

// Change the "Home Page" button to a link to Employer Home
function empReplaceHome(){
	if(document.getElementById("btnHomePage")){
		var homebutton=document.getElementById("btnHomePage");
		var homelink=makeTextElement("a", "Home Page", "ffLinkHomePage");
		homelink.setAttribute("href", "/Employer/EmpHome.aspx?abbr=CFOCOM");
		homebutton.parentNode.replaceChild(homelink, homebutton);
	}
}



function jsNav(){
	var jsnav=makeElement("div", "jsnav");
	
	jsnav.innerHTML='<div class="ffCrumbs"><div class="ffCrumbsTop clear"><h1>Find a Job<\/h1><\/div><p class="clear"><span class="ffCrumbBottom">You are here: <a href="http:\/\/www.cfo.com\/?f=bc">Home</a>&nbsp\;:&nbsp\;<a href="http:\/\/www.cfo.com\/careers\/?f=bc">Careers</a>&nbsp\;:&nbsp\;<a href="http://www.cfo.com/careers/jobsearch.cfm">Find a Job<\/a>' + makeCrumbs() + '<\/span><\/p><\/div>';
	if(getElementsByClassName("ffH1")){	
		getElementsByClassName("ffH1")[0].parentNode.insertBefore(jsnav, getElementsByClassName("ffH1")[0]);
		getElementsByClassName("ffH1")[0].parentNode.setAttribute("width", "990");
		if(document.getElementById("pnlConfirm")){ document.getElementById("pnlConfirm").getElementsByTagName("table")[0].setAttribute("width", 990);}
	}
	if(document.getElementById("lblEmpName")){document.getElementById("lblEmpName").innerHTML="";}

}
