function startUp(){
	setNavigation();
	setLowerNavigation();	
	formFunctions();
	goToPrint();
	if($("#countries").length>0){
		setupCountries();
	}
	if($('.bottom_bucket.expand').length>0){
		BUHideLinks();	
	}
	if($("#contact").length > 0) {
		showContact();
	}
	if($('.subnavmenu').length>0){
		setBottomNav();
	}
	if($('#findform').length>0){
		document.forms.findform.reset();
	}
}
//set up header mouseovers on every page
function setNavigation(){	
	//world mpa hover state on/off
	$('.nav_worldwide>a').mouseover(function(){
		$('#gmap').attr({
			src: "images/nav_map_on.gif"
		});
	$('.nav_worldwide>a').mouseout(function(){
		if($('.nav_worldwide.on>a').length==0){		
			$('#gmap').attr({
				src: "images/nav_map_off.gif"
			});
		}
		});
	});	
	if($('.nav_worldwide.on>a').length>0){
		$('#gmap').attr({
			src: "images/nav_map_on.gif"
		});
	}
	//set up global navigation rollovers
    var navRoot;
	var node='';
	var tempClassName='';
	var leftPosition=0;
	var topPosition=0;
    navRoot=$('#global_menu');
	$(navRoot).children('li').mouseover(function(){
		tempClassName=this.className;
		if(tempClassName.indexOf('over')==-1){
			$(this).addClass('over');	
			if($(this).children('ul:first').length>0){
				node=$(this).children('ul:first')[0];
				//if its IE > 7 hide select boxes on mouseovers
				 if (navigator.appName == "Microsoft Internet Explorer" && (!window.XMLHttpRequest)){
					leftPosition = 0;
					topPosition = 0;
					hideShowSelectBox(findGlobalPosX(node),findGlobalPosY(node),node.offsetWidth,node.offsetHeight); 
				 }
			}
		}
	}).mouseout(function(){
		$(this).removeClass('over');	
		showAllSelectBoxes();
	});;
	//call function to fire Choose Language mouseover
	showLanguage();
	//set up all button elements to do form submits
	$("button").click(function(){$(this).parent().submit()});
}
//called in setNavigation() to find position of menues and select boxes for IE < 7 show/hide
function findGlobalPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}
//called in setNavigation() to find position of menues and select boxes for IE < 7 show/hide
function findGlobalPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
        curtop += 1;
    } else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}
//function called in setNavigation() to hide/show select boxes
function hideShowSelectBox(menuLeftPos,menuTopPos,menuWidth,menuHeight){	
    for(slectLoop2=0;slectLoop2<document.getElementsByTagName("select").length;slectLoop2++){		
        var tempSelectY = findGlobalPosY(document.getElementsByTagName("select")[slectLoop2]);
        var tempSelectX = findGlobalPosX(document.getElementsByTagName("select")[slectLoop2]);
        var tempSelectWidth = document.getElementsByTagName("select")[slectLoop2].offsetWidth;
        var tempSelectHeight = document.getElementsByTagName("select")[slectLoop2].offsetHeight;
        if((tempSelectY <= menuTopPos + menuHeight && tempSelectY + tempSelectHeight >= menuTopPos ) && ((tempSelectX <= menuLeftPos && menuLeftPos <= (tempSelectWidth + tempSelectX)) || ((menuLeftPos <= tempSelectX) && (menuLeftPos + menuWidth > tempSelectX)))){
            document.getElementsByTagName("select")[slectLoop2].style.visibility = 'hidden';
        }else{
            document.getElementsByTagName("select")[slectLoop2].style.visibility = 'visible';
        }
    }
}
//function called in setNavigation() to show all select boxes when global nav is moused off of
function showAllSelectBoxes(){
	if (navigator.appName == "Microsoft Internet Explorer" && (!window.XMLHttpRequest)){
		for(j=0;j<document.getElementsByTagName("select").length;j++){				
			document.getElementsByTagName("select")[j].style.visibility = 'visible';
		}
	}
}
//function to set up the three-tiered Products and Services menu
function setLowerNavigation(){
	var lowerRoot='';
	var lnode='';
	var targetUL=$('#link_series');
	var ulToLoad;
	var ulNew;
	if($('#link_category>ul>li.selected')){
		ulToLoad=$('#link_category>ul>li.selected').children('ul');
		$(targetUL).empty();
		$(ulToLoad).clone().appendTo($(targetUL));
	}
	lowerRoot = $('#link_category>ul:first');
	for(j=0;j<lowerRoot.children('li').length;j++){
		lnode=lowerRoot.children('li')[j];
		lnode.onmouseover=function(){
			removeStyle();
			$(this).addClass('selected');
			ulNew=$(this).children('ul');
			$(targetUL).empty();
			$(ulNew).clone().appendTo($(targetUL));
		}
	}
}
//this function shows the Languages div in the footer on rollover
function showLanguage(){
	if($("#lang_main").length>0){
		$("#lang_main").mouseover(function(){
			$("#lang_holder").css("display","inline");										   
		}).mouseout(function(){
			$("#lang_holder").css("display","none");	
		});
	}	
}
//function called in setLowerNavigation() to remove all .selected styles from links on new mouseover
function removeStyle(){
	var lowerRoot;
	var lnode;
	if($('#prod_list')){
		lowerRoot = $('#link_category>ul:first');
		for(var j=0;j<lowerRoot.children('li').length;j++){
			lnode=lowerRoot.children('li')[j];
			$(lnode).removeClass('selected');
		}
	}
}
//function used only when there is a #countries table to setup mouseover events on the table rows
function setupCountries(){
	var theRow;
	var firstCell;
	var secondCell;
	theRow=$("#countries");
	$("#countries tr").mouseover(function(){
		$(this).addClass("rowOver1");
		firstCell=$(this).children('td')[0];
		secondCell=$(this).children('td')[1];
		$(firstCell).addClass("rowOver1");
		$(secondCell).addClass("rowOver2");
	}).mouseout(function(){
		$(firstCell).removeClass("rowOver1");
		$(secondCell).removeClass("rowOver2");
	});
}
//function to show/hide links in business unit page if more/less than 3 available
function BUHideLinks(){
	var numLIs=0;
	var linkText;
	var thisLI;
	var appendLink;
	linkSpan=$('.bottom_bucket.expand>.view_link:first');
	linkText=$('.bottom_bucket.expand>.view_link:first>a');
	if($('.bottom_bucket.expand').length>0){
		numLIs=$('.bottom_bucket.expand>ul:first').children('li').length;
		if(numLIs>3){
			//first, loop through all items > 3 and hide them
			for(var l=3;l<numLIs;l++){
				thisLI = $('.bottom_bucket.expand>ul:first').children('li')[l];
				$(thisLI).hide();
			}
			//add hidden links for other states
			appendLink="<span class='view_link' id='hideLink'><img src='images/lg_arrow.gif' width='5' height='9' alt='' /><a href='#'>"+hideText+"</a></span><span class='view_link' id='allLink'><img src='images/lg_arrow.gif' width='5' height='9' alt='' /><a href='"+allLink+"'>"+allText+"</a></span>"
			$(appendLink).appendTo(".bottom_bucket.expand");
			$("#hideLink").hide();
			$("#allLink").hide();
			//change text to 'view more'
			linkText.html(moreText);
			linkSpan.attr("id","moreLink");
		} else {
			linkText.html(allText);	
		}
	}
	$("#hideLink").click(function(){					 
		for(var l=3;l<numLIs;l++){
		thisLI = $('.bottom_bucket.expand>ul:first').children('li')[l];
			$(thisLI).hide();
		}
		$("#hideLink").hide();
		$("#allLink").hide();
		$("#moreLink").show();
	});
	$("#moreLink").click(function(){
		for(var l=3;l<10;l++){
			thisLI=$('.bottom_bucket.expand>ul:first').children('li')[l];
			$(thisLI).show();
		}
		$("#moreLink").hide();
		$("#hideLink").show();
		if(numLIs>10){
			$("#allLink").show();
		}						 
	});
}
//function is called inline when a select box is supposed to enable/disable related select boxes
function dropSense(sel) { 
	var selected = $(sel).val(); 
	if (selected != "") { 
		$(sel).next('select').removeAttr('disabled'); 
	} else { 
		$(sel).next('select').val("").attr("disabled", true);
	} 
}
//function hides/shows the Request More Info form
function showContact(){
	//contact display none unless RMI1 (confirmation)
	if(location.href.indexOf("status=RMI1")==-1){
		$("#contact").css("display","none");
	}
	$("#closeform").show();
	$("#submit").hide();
	//set up expand click to open form, show buttons
	$("#expand").click(function(){
		$("#contact").animate({height: "show"});
		$("#expand").hide();
		$("#submit").show();
	});
	//set up close click to close form, hide buttons
	$("#closeform").click(function(){
		$("#contact").animate({height: "hide"});	
		$("#submit").hide();
		$("#expand").show();
	});
	//set pageTitle and Address appropriately and attach them to for hidden fields
	var pageTitle = document.title;
	var pageAddr = location.href + "?status=RMI1";
	document.cform.rpagetitle.value = pageTitle;
	document.cform.rpageaddress.value = pageAddr;	
}
//validation called for Request More Info form
function validateForm() {
	document.getElementById("emailerr").style.display="none";		
	var willReturn = 1;
	//required fields
	var reqAry=new Array(7)
	for (i=0; i <7; i++)
	reqAry[i]=new Array(2)
	reqAry[0][0] = document.cform.C_FirstName.value;
	reqAry[0][1] = document.getElementById("fnamelabel");
	reqAry[1][0] = document.cform.C_LastName.value;
	reqAry[1][1] = document.getElementById("lnamelabel");
	reqAry[2][0] = document.cform.C_Title.value;
	reqAry[2][1] = document.getElementById("titlelabel");
	reqAry[3][0] = document.cform.C_EmailAddress.value;
	reqAry[3][1] = document.getElementById("emaillabel");
	reqAry[4][0] = document.cform.C_Company.value;
	reqAry[4][1] = document.getElementById("companylabel");
	reqAry[5][0] = document.cform.C_BusPhone.value;
	reqAry[5][1] = document.getElementById("phonelabel");
	reqAry[6][0] = document.cform.C_Country.value;
	reqAry[6][1] = document.getElementById("countrylabel");
	for(i=0; i<reqAry.length; i++){
		if(reqAry[i][0]==null||reqAry[i][0]==""){
			reqAry[i][1].className="error";
			willReturn = 0;
		} else {
			reqAry[i][1].className="";	
		}
	}
	if(willReturn==0){
		return false;
	} else {
		if(validate_email(reqAry[3][0])==true){
			return true;
		} else {
			document.getElementById("emailerr").style.display="inline";	
			return false;
		}
	}
}
//function called to validate Email to a Friend form
function validateEmailForm() {
	document.getElementById("emailtoerr").style.display="none";
	document.getElementById("emailfromerr").style.display="none";
	var willReturn = 1;
	//required fields
	var reqAry=new Array(4)
	for (i=0; i <4; i++)
	reqAry[i]=new Array(2)
	reqAry[0][0] = document.eform.C_To_Email_Address1.value;
	reqAry[0][1] = document.getElementById("emailtolabel");
	reqAry[1][0] = document.eform.C_From_Email_Address1.value;
	reqAry[1][1] = document.getElementById("emailfromlabel");
	reqAry[2][0] = document.eform.C_Subject1.value;
	reqAry[2][1] = document.getElementById("emailsubjlabel");
	reqAry[3][0] = document.eform.recaptcha_response_field.value;
	reqAry[3][1] = document.getElementById("recaptcha_label");
	for(i=0; i<reqAry.length; i++){
		if(reqAry[i][0]==null||reqAry[i][0]==""){
			reqAry[i][1].className="error";
			willReturn = 0;
		} else {
			reqAry[i][1].className="";	
		}
	}
	if(willReturn==0){
		return false;
	} else {
		if(validate_email(reqAry[0][0])==false){
			document.getElementById("emailtoerr").style.display="inline";	
			return false;
		} else if(validate_email(reqAry[1][0])==false) {
			document.getElementById("emailfromerr").style.display="inline";	
			return false;
		} else {
			return true;	
		}
	}
}
//called in validateForm() and validateEmailForm()
function validate_email(value) {
	with (value) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {
		  	return false;
		} else {
			return true;
		}
	}
}
//this is called when opening the email form via AJAX, to load the reCAPTCHA javascript
//in IE this is necessary to avoid JS errors when the script has not already loaded
function addScript(){
	var script_ID='captcha_script';
	var head=document.getElementsByTagName('head').item(0);
	var scriptTag=document.getElementById(script_ID);
	if(!scriptTag){
		script=document.createElement('script');
		script.src="http://api.recaptcha.net/js/recaptcha_ajax.js";
		script.type='text/javascript';
		script.id=script_ID;
		head.appendChild(script);
	}
}	
//this function calls the goToEmail() function with the appropriate parameter after calling loadScript()
function showEmail(form){
	addScript();
	if(form=='conf') {
		goToEmail('conf');
	} else {
		setTimeout("goToEmail('mail')",500);
	}
}
//function called in showEmail to AJAX lod the email form or email confirmation onto the page
function goToEmail(theForm){
	if($("#email_holder").length>0){
		$("#email_holder").show();	 
	} else {
		$("body").append("<div id='email_holder'></div>");
		if(theForm=="conf"){
			$("#email_holder").load("email_conf.html");
		} else {
			$("#email_holder").load("email_form.html", pageInfo);
		}
	}
	$("#emaillink").click(function(){return false;});	
}
//removes email popup page from the page
function hideEmail(){
	if(document.getElementById("shim")){
		var shimmer = document.getElementById("shim");
		shimmer.style.visibility='hidden';
	}
	$("#email_holder").remove();
	$("#emaillink").click(showEmail);
}
//function called in goToEmail to set up hidden fields, and add iframe shim technique if > IE7
function pageInfo(){
	var pageTitle = document.title;
	var pageAddr = location.href + "?status=STF1";
	document.eform.PageTitle.value = pageTitle;
	document.eform.C_Page_URL1.value = pageAddr;
	if (navigator.appName == "Microsoft Internet Explorer" && (!window.XMLHttpRequest)){	
		if($("#shim").length==0){
			shimmer=document.createElement('iframe');
			shimmer.id="shim";
			shimmer.style.height=$("#emailform").height();
			shimmer.setAttribute('frameborder','0');
			shimmer.src="#";
			$("body").append(shimmer);
		}
		$("#shim").css("visibility","visible");
	}
}
//this function is called on page load to check the state of the forms on the page
function formFunctions(){
	//you can change this variable's text to display any "Thank you" text in any language
	var email_Conf="Thank you. Your message has been sent.";
	if($('#emaillink').length>0){
		$('#emaillink').attr("href","javascript:showEmail('mail');");	
	}
	var fullURL = location.href;
	//show Send to Friend confirmation if STF1
	if(fullURL.indexOf("status=STF1")!=-1 && $("#emaillink").length>0){
		showEmail('conf');
	}
	//show Request More Info confirmation if RMI1
	if($("#contact").length>0){
		if(fullURL.indexOf("status=RMI1")!=-1){
			if(!window.request_Conf){
				request_Conf="Thank you. Your information has been received.";
			}
			$("#expand").css("display","none");
			$(".required").hide();
			$(".contactform").remove();
			$("#submit").remove();
			$("#contact").prepend("<div class='contactform'><p>"+request_Conf+"</p></div>");
		}
	}
	//handle return from reCAPTCHA server-side validation error. Repopulate form fields
	//with their values other than the recaptcha response
	if(fullURL.indexOf("captchaerror=1")!=-1){
		if($("#emaillink").length>0){
			$("#emaillink").click(function(){return false;});
			addScript();
			$("body").append("<div id='email_holder'></div>");
			$("#email_holder").load("email_form.html", function(){
				pageInfo();
				var formAry=new Array('ToEmailAddress','FromEmailAddress','Subject','Message');
				var fieldAry=new Array(document.eform.emailto, document.eform.emailfrom, document.eform.subject, document.eform.emailmsg);
				for(q=0;q<formAry.length;q++){
					if(getQueryVariables(formAry[q])){
						fieldAry[q].value=getQueryVariables(formAry[q]);
					}
				}								
				$("#recaptcha_label").addClass("error");
			});
		}
	}
}
//see if variable is defined
function isDefined(object,variable){
	return(typeof(eval(object)[variable])!='undefined');	
}
//called in formFunctions to parse/de-encode the querystring paramaters on a reCAPTCHA error response
function getQueryVariables(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	var theAnswer;
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			theAnswer=decodeURIComponent(pair[1]);
			return theAnswer.replace(/\+/g," ");
		}
	}
}
//About Aon subnav menu rollovers, show/hide states, etc
function setBottomNav() {
	$(".subnavmenu").children('li').children('ul').hide();
	//this part adds/removes the blue arrow class on hovers
	$(".subnavmenu").children('li').hover(function(){
		if ($(this).hasClass("opened")) {
			return true;
		} else {
			if($(this).children('ul').length>0){
				$(this).addClass("open");		  
			} else {
				$(this).addClass("over");	
			}
		}
	},function(){
		if ($(this).hasClass("opened")) {
			return true; 			  
		} else {			  
			$(this).removeClass("open");
			$(this).removeClass("over");
		}
	});
	//this part handles the click actions only if the LI/A being clicked ha a child UL of hidden elements
	//otherwise, the link clicked will just take you to the href specified
	$(".subnavmenu").children('li').children('a').click(function(){
		if($(this).parent('li').children('ul').length>0){																	 
			if ($(this).parent('li').hasClass("opened")) {
				$(this).parent('li').children('ul').slideUp("slow");
				$(this).parent('li').removeClass("open").removeClass("opened");			  
			} else {
				$(this).parent('li').children('ul').slideDown("slow");
				$(this).parent('li').addClass("open").addClass("opened");
			}
		}
	});
}
//this function is called in the Request More Info form to show/hide the city and state selects if a user chooses United States
function hideState(sel) {
	$("#C_State").hide(); 
	$("#C_City").hide(); 	
	var selected = $(sel).val(); 
	if (selected == "us") { 
		$("#C_State").show(); 
		$("#C_City").show(); 		 
	} else { 
		$("#C_State").val("").hide();
		$("#C_City").val("").hide();		
	}  
}
//function caleld to open popup window to print the page
function printPage(loc) { 
	printPages = window.open(loc,"babywindow","width=880,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizeable=0");
	printPages.focus();
}
//show the print page if this is the print popup window
//add URL to the bottom of the page
function goToPrint() {
	if (window.name == 'babywindow'){
		if (navigator.appName != "Netscape"){
			$('link:last').attr('media','')			
		} else {
			$('link:last').append("<link href='css/print.css' rel='stylesheet' type='text/css'/>");
		}
		$("#container").append("<strong>Find this content at: </strong>" + location.href);
	}
}
