/* 
Title: Deloitte - Global JavaScript Functions
Author: Michael "Spell" Spellacy, Senior UI Developer
Email: michael.spellacy@tmp.com
Company: TMP Worldwide Advertising and Communications, LLC
*/

// Supress BOM Script Errors

function errorsuppressor(){
	return true;
}

function fnClearStatus(val){
    document.getElementById(val).innerHTML = "";
}

if(location.href.indexOf("localhost") == -1){

	window.onerror = errorsuppressor;

}

// Multiple Onload Utility

function addLoadEvent(func) {

	var oldonload = window.onload;

	if (typeof window.onload != 'function') {

		window.onload = func;

	} else {

		window.onload = function() {
		oldonload();
		func();

		}

	}

}

// Insert-after Function

function insertAfter(newElement, targetElement) {

var parent = targetElement.parentNode;

if (parent.lastChild == targetElement) {

	parent.appendChild(newElement);

} else {

	parent.insertBefore(newElement, targetElement.nextSibling);

	}

}

// Toggle, Show/Hide Element(s)

function toggleElement(val, obj){

	if(document.getElementById(val).style.display == "none") { 

		obj.className = "expandon";
		document.getElementById(val).style.display = "block";

	} else {

		obj.className = "expand";
		document.getElementById(val).style.display = "none";

	}

}

// Primary Nav (IE 6 only)

primarynavhover = function() {

	if (!document.getElementById) return false;
	if (!document.getElementById("nav-i")) return false;

	var listElements = document.getElementById("nav-i").getElementsByTagName("li");

	for (var i=0; i < listElements.length; i++) {

		listElements[i].onmouseover = function() {

			this.className+=" iehover";

		}

		listElements[i].onmouseout = function() {

			this.className-= this.className.replace(new RegExp(" iehover\\b"));

		}

	}

}

if (window.attachEvent) window.attachEvent("onload", primarynavhover);

breadcrumbnavhover = function() {

	if (!document.getElementById) return false;
	if (!document.getElementById("breadcrumb")) return false;

	var listElements = document.getElementById("breadcrumb").getElementsByTagName("li");

	for (var i=0; i < listElements.length; i++) {

		listElements[i].onmouseover = function() {

			this.className+=" iehover";

		}

		listElements[i].onmouseout = function() {

			this.className-= this.className.replace(new RegExp(" iehover\\b"));

		}

	}

}

if (window.attachEvent) window.attachEvent("onload", breadcrumbnavhover);

// Global Pop-up (parse through DOM, if particular class exists, append event)

function newWinLinks() {

	for (var i=0; i < document.links.length; i++) {

		if (document.links[i].className == "newwindow") {
		
			document.links[i].setAttribute("target", "_blank");
		
		}
		
		if (document.links[i].className == "viewlocation") {

			document.links[i].onclick = openLocationDetails;

		}
						
	}
	
}

addLoadEvent(newWinLinks);

// Add title attribute to all select boxes for usability (global)

function addOptionTitle() { 

	if (!document.getElementsByTagName("select")) return false;

	var list = document.getElementsByTagName("select");

	for(var i = 0; i < list.length; i++) {

		var option = list[i].getElementsByTagName("option")

		for(var j = 0; j < option.length; j++) {

			option[j].setAttribute("title", option[j].text);

		}
		
	}
	
}

addLoadEvent(addOptionTitle);

/* Add common jQuery functions here */

// Handling Career Area Dropdown Click (career-area.aspx)

$(".gobtn").click(function() {   

	var CareerAreaID = $("#ddlCareerAreas").val();

	if(CareerAreaID.length == 0)

		alert("Please select a Career Area");

	else

		location.href="/career-area/"+CareerAreaID;

	return false;

});
