
/* 
	 Title: Global Scripts					
	 Version: 1.0													
	 Author: Dan Green, Web Developer		
	 Company: TMP Government, LLC					
*/	 

// *** Files for javascript-enabled browsers only
document.write('<link href="global/_css_source/app_script_enabled.css" rel="stylesheet" type="text/css">');
document.write('<script type="text/javascript" src="global/_js_source/thickbox-compressed.js"></script>');
document.write('<script src="/js/careers_irs_reporting_firstpartycookie.js" type="text/javascript"></script>');

// *** Set Global Variables and Object References
var arrSilo=["default","precollege","student","midcareer","seasonal"];
var boolShowPluginLink = false;
var strThickboxMsg = 'You will be leaving the jobs.irs.gov domain and entering an external link. The link provides additional information that may be useful or interesting and is being provided consistent with the intended purpose of the IRS Careers Web site. However, IRS cannot attest to the accuracy of information provided by this link or any other linked site. Providing links to a non-IRS Web site does not constitute an endorsement by IRS or any of its employees of the sponsors of the site or the information or products presented on the site. Also, be aware that the privacy protection provided on the IRS.gov domain (see <a href="/privacy.html" onclick="tb_remove();return false;">Privacy and Security Notice</a>) may not be available at the external link.';

// *** Initialize Global Page Scripts once DOM is loaded
$(function(){
	if ((!document.getElementById)||(!document.getElementsByTagName)) return false;
	$("#nav-careers-menu").load("/nav/nav-util.html");
	$("#nav-socialt-menu").load("/nav/nav-twitter.html");
	rotateIMGClass(5);
	setBtnEvents();
	writeExternalLinkIcon();
	writeContextNav();	
	//addListClass("nav-utility");
	addListClass("colophon");
	addListClass2("nav-global-container");
	addStickyClass("nav-global");
	if(!document.getElementById("page-home"))createJumpMenu();	
	showActiveNav();
	showActivePlugins();
	createThickBox();
	checkURL();
	hideTopLink();
	setGoogleTranslateLink();
});

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

sfHover = function() {
	var sfEls = document.getElementById("nav-global").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

mcAccessible = function() {
	var mcEls = document.getElementById("nav-global").getElementsByTagName("A");
	for (var i=0; i<mcEls.length; i++) {
		mcEls[i].onfocus=function() {
			this.className+=(this.className.length>0? " ": "") + "sffocus"; //a:focus
			this.parentNode.className+=(this.parentNode.className.length>0? " ": "") + "sfhover"; //li < a:focus
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < a:focus
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=(this.parentNode.parentNode.parentNode.parentNode.parentNode.className.length>0? " ": "") + "sfhover"; //li < ul < li < ul < li < a:focus
				}
			}
		}
		mcEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp("( ?|^)sffocus\\b"), "");
			this.parentNode.className=this.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			if(this.parentNode.parentNode.parentNode.nodeName == "LI") {
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				if(this.parentNode.parentNode.parentNode.parentNode.parentNode.nodeName == "LI") {
					this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
				}
			}
		}
	}
}


if(window.addEventListener) window.addEventListener('load', mcAccessible, false); // gecko, safari, konqueror and standard
else if(document.addEventListener) document.addEventListener('load', mcAccessible, false); // opera 7
else if(window.attachEvent) { // win/ie
	window.attachEvent('onload', sfHover);
	window.attachEvent('onload', mcAccessible);
} else { // mac/ie5
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			sfHover();
			mcAccessible();
		}
	} else {
		window.onload = function() {
			sfHover();
			mcAccessible();
		}
	}
}


function addStickyClass(myElementID){
	if(document.getElementById(myElementID)){
		arrListItems = document.getElementById(myElementID).getElementsByTagName("ul");		
		for (var i=0; i<arrListItems.length; i++) {
			arrListItems[i].onmouseover=function() {
				this.parentNode.getElementsByTagName("a")[0].className+=" sticky";
			}
			arrListItems[i].onmouseout=function() {
				this.parentNode.getElementsByTagName("a")[0].className=this.parentNode.getElementsByTagName("a")[0].className.replace(/sticky/gi, "");
			}
		}
	}
}


utilHover = function() {
	var sfEls = document.getElementById("nav-utility-careers");

		sfEls.onmouseover=function() {
			this.className+=" utilhover";
			document.getElementById("jumpmenu").className='hide';
		}
		sfEls.onmouseout=function() {
			this.className=this.className.replace(new RegExp(" utilhover\\b"), "");
			document.getElementById("jumpmenu").className='show';
		}

}
if (window.attachEvent) window.attachEvent("onload", utilHover);

socialHover = function() {
	var sfEls = document.getElementById("nav-social-t");

		sfEls.onmouseover=function() {
			this.className+=" socialhover";
			document.getElementById("jumpmenu").className='hide';
		}
		sfEls.onmouseout=function() {
			this.className=this.className.replace(new RegExp(" socialhover\\b"), "");
			document.getElementById("jumpmenu").className='show';
		}

}
if (window.attachEvent) window.attachEvent("onload", socialHover);

function addListClass(myElementID){
	if(document.getElementById(myElementID)){
		arrListItems = document.getElementById(myElementID).getElementsByTagName("ul")[0].getElementsByTagName("li");		
		arrListItems[arrListItems.length-1].className+=' lastItem';
	}
}

function addListClass2(myElementID){
	if(document.getElementById(myElementID)){
		arrListItems = document.getElementById(myElementID).getElementsByTagName("ul")[0].getElementsByTagName("li");		
		arrListItems[0].className+=' firstItem';
	}
}

function writeContextNav(){ 
	if(document.getElementById('nav-primary-container')){
		strContextNav = document.getElementById('nav-global').innerHTML;
		document.getElementById('nav-primary-container').innerHTML = '<div id="nav-primary"><ul id="nav">' + strContextNav.replace(/nav-global/gi, "nav") + '</ul></div>';
	}
}

function createJumpMenu(){
	if(!document.createElement)return false;	
	if(document.getElementById('nav-global-container')){
		var objContainer = document.getElementById("nav-global-container");
		var objDOMElement=document.createElement('div');
		objDOMElement.setAttribute("id","jumpmenu");
		objContainer.appendChild(objDOMElement);
		objContent = '<h4>Who are you?</h4>';
		objContent += '<form>';
		objContent += '<select OnChange="location.href=this.options[selectedIndex].value">';
		objContent += '<option value="/precollege/">Pre-College</option>';
		objContent += '<option value="/student/">Students &amp; Recent Grads</option>';
		objContent += '<option value="/midcareer/">Mid-Career &amp; Experienced</option>';
		objContent += '<option value="/seasonal/">Seasonal &amp; Part Time</option>';
		objContent += '</select>';
		objContent += '</form>';
		document.getElementById("jumpmenu").innerHTML = objContent;
		preSelectJumpMenu();
	}
}

function preSelectJumpMenu(){
	selectmenu = document.getElementById("jumpmenu").getElementsByTagName("select")[0];
	pageClass = document.getElementsByTagName("body")[0].className;
	if (pageClass.indexOf("precollege")!=-1){selectmenu.options[0].selected = true;}
	if (pageClass.indexOf("student")!=-1){selectmenu.options[1].selected = true;}
	if (pageClass.indexOf("midcareer")!=-1){selectmenu.options[2].selected = true;}
	if (pageClass.indexOf("seasonal")!=-1){selectmenu.options[3].selected = true;}
}

function setULIDs(myElementID){	
	if(document.getElementById(myElementID)){
		arrListItems = document.getElementById(myElementID).getElementsByTagName("UL");
		for(var i = 0; i < arrListItems.length; i++){	
			arrListItems[i].id = "ul_" + i;
		}	
	}
}

function showActiveNav(){	
	var objPrimaryNav = document.getElementById("nav-primary");
	var strCurrentElementID = document.getElementsByTagName("body")[0].id.replace(/page/i, "nav")
	var arrActiveElementIDs = new Array();
	var count=0;
	var strTopLevelID = "nav";
	setULIDs(strTopLevelID);
	if(document.getElementById(strCurrentElementID)!=null){
		while (strCurrentElementID != strTopLevelID)
		{
			if (document.getElementById(strCurrentElementID).nodeName == "LI") {
				arrActiveElementIDs[count] = strCurrentElementID;
				document.getElementById(strCurrentElementID).className+=' activeListItem';
				count++;
			}
			strCurrentElementID = document.getElementById(strCurrentElementID).parentNode.id;
		}
		document.getElementById(arrActiveElementIDs[0]).getElementsByTagName("a")[0].className+=' activeLink';
		document.getElementById(arrActiveElementIDs[arrActiveElementIDs.length-1]).getElementsByTagName("a")[0].className+=' headLink';
		globalnavid = arrActiveElementIDs[arrActiveElementIDs.length-1].replace(/nav/i, "nav-global");
		document.getElementById(globalnavid).getElementsByTagName("a")[0].className+=' stuck';
	} else {
		if(objPrimaryNav)objPrimaryNav.className+=' hide'; //hide container if no matching nav item	
	}

	if(document.getElementById("nav-breadcrumb"))appendBreadcrumb(arrActiveElementIDs.reverse());
	
	//Adjustments for nav
	if(objPrimaryNav)objPrimaryNav.getElementsByTagName("li")[0].className='hide';
	
}


function showActiveNavGlobal(arrActiveElementIDs){	
	var strGlobalPageId = arrActiveElementIDs[arrActiveElementIDs.length-1].replace(/nav/i, "page");
	objBody.className+=" "+ strGlobalPageId;
}

function showActiveNavGlobal2(arrActiveElementIDs){	
	var strGlobalPageId = arrActiveElementIDs[arrActiveElementIDs.length-1].replace(/nav/i, "page");
	objBody.className+=" "+ strGlobalPageId;
}


var arrParentNodeIDs = new Array();

function addSubLevelClass(myElementID){	
	if(document.getElementById){
		if(document.getElementById(myElementID)){
			arrListItems = document.getElementById(myElementID).getElementsByTagName("UL");
			for(var i = 0; i < arrListItems.length; i++){				
				if (arrListItems[i].parentNode.className != 'activeListItem')arrListItems[i].parentNode.className = 'hasSubNav';
			}	
		}
	}
}

function appendBreadcrumb(arrCrumbIDs) {
	var objContainer=document.getElementById("nav-breadcrumb").getElementsByTagName("ul")[0];
	addPrimaryCrumb(objContainer);
	for(var i = 0; i < arrCrumbIDs.length; i++){	
		objDOMElement=document.createElement('li');
		currCrumbID = "crumb" + i;
		objDOMElement.setAttribute("id",currCrumbID);
		objContainer.appendChild(objDOMElement);
		firstAnchor = document.getElementById(arrCrumbIDs[i]).getElementsByTagName("a")[0];
		document.getElementById(currCrumbID).innerHTML = ' &raquo; <a href="' + firstAnchor.href + '">' + firstAnchor.innerHTML + '</a>';
	}
	if(arrCrumbIDs.length==0)addUtilityCrumb(objContainer);
	var arrCrumbs=document.getElementById("nav-breadcrumb").getElementsByTagName("li");
	arrCrumbs[arrCrumbs.length-1].className = "lastCrumb";
}

function addPrimaryCrumb(objContainer){
	pageClass = document.getElementsByTagName("body")[0].className;
	if (pageClass.indexOf("precollege")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="index.html">Pre-College Home</a>';}
	if (pageClass.indexOf("student")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="index.html">Students &amp; Recent Grads Home</a>';}
	if (pageClass.indexOf("midcareer")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="index.html">Mid-Career &amp; Experienced Home</a>';}
	if (pageClass.indexOf("seasonal")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="index.html">Seasonal &amp; Part-Time Home</a>';}
}

function addUtilityCrumb(objContainer){
	if (window.location.href.indexOf("sitemap")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="sitemap.html">Sitemap</a>';}
	if (window.location.href.indexOf("careers")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="/careers.html">Our Careers</a>';}
	if (window.location.href.indexOf("faqs")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="faqs.html">FAQs</a>';}
	if (window.location.href.indexOf("matchup")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="/matchup.html">Benefits Matchup</a>';}
	if (window.location.href.indexOf("privacy")!=-1){objContainer.innerHTML += '<li> &raquo; <a href="/privacy.html">Privacy</a>';}
}

function showActivePlugins(){
	var intCount = 0;
	var arrPlugins = document.getElementById("plugins").getElementsByTagName("li");
	var arrLinks = document.links;
	var arrActivePlugins = new Array();
	var boolIsActiveExt;
	
	for(i=0;i<arrPlugins.length;i++){
		arrPlugins[i].style.display = "none";
		currentFileExt = arrPlugins[i].id.replace(/pluginLink-/i,".");
		boolIsActiveExt = false;
		
		for(j=0;j<arrLinks.length;j++){
			currentArrLink = arrLinks[j].href.toLowerCase();
			if(currentArrLink.indexOf(currentFileExt)!=-1)boolIsActiveExt = true;
		}
		
		if(currentFileExt == ".swf" && boolShowPluginLink)boolIsActiveExt = true;
		
		if(boolIsActiveExt){
			arrActivePlugins[intCount] = arrPlugins[i];
			intCount++;
		}
		
	}
	
	for(i=0;i<arrActivePlugins.length;i++){
		arrActivePlugins[i].style.display = "inline";
		if (i == 0) arrActivePlugins[i].innerHTML = "[ " + arrActivePlugins[i].innerHTML;
		if (i < (arrActivePlugins.length-1)) arrActivePlugins[i].innerHTML += ", ";
		if (i == arrActivePlugins.length-1) arrActivePlugins[i].innerHTML += " ]";
	}
	
	if(arrActivePlugins.length == 0)document.getElementById("plugins").style.display = "none";	
		
}

function writeExternalLinkIcon(){
	var arrElementIDs = new Array('nav-global-history', 'nav-global-organization', 'nav-global-mission');
	strIMG = ' <img src="/global/_images/main/icon-extwindow.gif" align="absmiddle" />';
	for (i in arrElementIDs) {
		if(document.getElementById(arrElementIDs[i]))document.getElementById(arrElementIDs[i]).getElementsByTagName("a")[0].innerHTML += strIMG;
	}
	writeExternalLinkIconFooter(strIMG);
}

function writeExternalLinkIconFooter(strIMG){
	/*strNew = strIMG + "<span>";
	for (var i = 0; i < 2; i++){
		currObj = document.getElementById("footer-portlet-4").getElementsByTagName("a")[i];
		strElementInnerHTML = currObj.innerHTML;
		currObj.innerHTML = strElementInnerHTML.replace(/<span>/gi, strNew);
	}*/
}
				
function checkURL(){
	var mainHost = location.hostname.toLowerCase();
	for (var i = 0; i < document.links.length; i++) {
		currentLink = document.links[i].href.toLowerCase();
		if(isExternalLink(currentLink,mainHost)&&(document.links[i].id!="logo")){
			var origLink = document.links[i].href;
			/*document.links[i].title += " (external link)";
			document.links[i].className += " b-external";
			document.links[i].onclick = function(){setLink(this.href);return false};*/
		}
	}
}

function isExternalLink(currLink,mainHost){
	//  USE following line if making IRS.gov links internal instead of external
	//  if(((currLink.indexOf("javascript")==-1)&&(currLink.indexOf("mailto")==-1)&&(currLink.indexOf(mainHost)==-1)&&(currLink.indexOf("irs.gov")==-1))||(currLink.indexOf("usajobs")!=-1)){return true;}else{return false;}
	
	if(
	   ((currLink.indexOf("javascript")==-1)&&(currLink.indexOf("mailto")==-1)&&(currLink.indexOf(mainHost)==-1))||(currLink.indexOf("usajobs")!=-1)||(currLink.indexOf("jobs.irs.gov")>=1)){return true;}else{return false;}}
 
function setLink(url) {
	var exitAnchor = document.getElementById("exit_anchor");
	exitAnchor.href=url;
	if ( exitAnchor.innerText == null ) {
		exitAnchor.textContent = url;
	} else {
		exitAnchor.innerText = url;
	}
	tb_show("External Link", "#TB_inline?height=225&width=300&inlineId=exit_div", null);
}



function createThickBox(){
	if(!document.createElement)return false;	
	var objContainer = document.getElementsByTagName("body")[0];
	var objDOMElement=document.createElement('div');
	objDOMElement.setAttribute("id","exit_div");
	objContainer.appendChild(objDOMElement);
	objContent = '<a name="leaving"></a><div id="thicktop"><h2>You are leaving jobs.irs.gov</h2>';
	objContent = objContent + '<p>';
	objContent = objContent + 'Click the following link to continue:';
	objContent = objContent + '<br /><a id="exit_anchor">exit</a>';
	objContent = objContent + '</p>';
	objContent = objContent + '<p id="btnCancel">[<a href="#" onclick="tb_remove();return false;">cancel and close this window</a>]</p></div>';
	objContent = objContent + '<h3>Privacy Information</h3>';
	objContent = objContent + '<p>' + strThickboxMsg + '</p>';
	objContent = objContent + '<p><a href="#leaving">top of page</a> | <a href="#" onclick="tb_remove();return false;">cancel and close this window</a></p><br />';
	document.getElementById("exit_div").innerHTML = objContent;
	document.getElementById("exit_div").className = 'hide';
}

function getX(obj){
  return(obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent));
}

function getY(obj) {
	return(obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent));
}

function hideTopLink(){
	if(document.all) {
		if(document.all.contentBot){
		    if ((getY(document.all.contentBot)) < 610) document.all.contentBot.style.display = 'none';
		}	
	} else if(document.getElementById) {
		    if (document.getElementById("contentBot")){
		        if ((getY(document.getElementById("contentBot"))) < 610) document.getElementById("contentBot").style.display = 'none';
		    }
	}
}



function rotateIMGClass(total){
	if(!document.getElementById("content-secondary"))return false;	
	var rand_no = Math.ceil(total*Math.random())
	targetElement = document.getElementById("content-secondary").getElementsByTagName("h4")[0];
	//if (targetElement)targetElement.className = "random" + rand_no;
	
	var objContainer = document.getElementsByTagName("body")[0];
	if(targetElement){
		if(objContainer.id=="page-disabilities" || objContainer.id=="page-disabilities-commitment" || objContainer.id=="page-reasonable-accommodation" || objContainer.id=="page-disabilities-affinity-groups" || objContainer.id=="page-lions-world" || objContainer.id=="page-sources-interest"){
			targetElement.className = "disrandom" + rand_no;
		} else {
			targetElement.className = "random" + rand_no;
		}
	}	
	
}


function setBtnEvents(){
	if(!document.getElementById("page-home"))return false;	
	
	/*
	for (var i = 1; i < 5; i++) {
		document.getElementById("portlet" + i).onclick = function(){window.location = document.getElementById("portlet" + i).getElementsByTagName("a")[0].href};
	}
	
	arrBtns = document.getElementById("portlets").getElementsByTagName("a")[0];
	for (var i = 0; i < arrBtns.length; i++) {
	document.getElementById(arrBtns[i].parentNode.id).onclick = function(){window.location = arrBtns[i].href};
	}
	*/
	
	/*document.getElementById("portlet1").onclick = function(){window.location = "/precollege/"};
	document.getElementById("portlet2").onclick = function(){window.location = "/student/"};
	document.getElementById("portlet3").onclick = function(){window.location = "/midcareer/"};
	document.getElementById("portlet4").onclick = function(){window.location = "/seasonal/"};*/
}


function setGoogleTranslateLink(){
	var gttLink = document.getElementById("gttLink");
	if(gttLink)gttLink.href = gttLink.href.replace(/http:\/\/jobs.irs.gov/gi, window.location.href);
	gttLink.onclick = function(){
		try {
			pageTracker._trackPageview("/outbound/google-translate-link"); // Google Analytics tracks outbound link tagged as "google-translate-link"
		}catch(err){}
	};
}


//////////////////////  Google Analytics Tracking Code ///////////////////////////////

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8851023-3']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

//////////////////////  Google Analytics Tracking Code ///////////////////////////////



