
// Fix for dropdown effects in IE6
//NOTE: THESE NEED TO BE RE-DONE FOR ALL NAVS (INC "BROWSE OUR OFFERINGS") - USE JQUERY
/*
sfHover = function() {
	var sfEls = document.getElementById("mainlevelmainnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" li-hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" li-hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
*/


window.addEvent('domready', function() { // Wait until page loads
	
	//Hide the A R T I O stuff for now
	$$('span.article_separator').setStyle('display','none');
	$$('a[title^=Web]').setStyle('display','none');
	$$('a[title^=Web]').getParent('div').setStyle('display','none');
});

jQuery(document).ready(function() {	
								
	////////// Main nav stuff //////////
	
	// Hack to get the dropdown nav to work in IE6
	// Loop through all <li> elements in the dropdown nav and attach hover events to them 
	jQuery('ul#mainlevelmainnav li, ul#browseOfferings li').each(function(i) {
		jQuery(this).hover(
			function(){
				jQuery(this).addClass('li-hover');
			},
			function(){
				jQuery(this).removeClass('li-hover');
			}
		);
	});
								
	// Add classes to various elements for styling
	jQuery('ul#mainlevelmainnav li:first').addClass('firstItem');
	jQuery('ul#mainlevelmainnav ul, ul#mainlevelsubnav1 ul').parent().addClass('menuParent');
	jQuery('ul#mainlevelmainnav > li:eq(4)').addClass('homeLink');
	
								
	////////// Homepage billboard tabs //////////
	
	// Fire the tabs UI
	if (jQuery('#homeContentUpper').length > 0) {
		jQuery('#homeContentUpper').tabs({
			event: 'mouseover', 
			fx: {opacity: 'toggle', duration: 'fast'}
			})
		.tabs('rotate', 11000);
			
		// Remove the class hiding the list and 2nd and 3rd homepage tabs (IE hack)
		jQuery('.homeHiddenTab').removeClass('homeHiddenTab');
		
		// Clickable billboards
		jQuery('#homeTabIT .moduletable, .ui-tabs-nav li:eq(0) a').click(function() {
		  window.location = "it-management/";
		});
		jQuery('#homeTabSynch .moduletable, .ui-tabs-nav li:eq(1) a').click(function() {
		  window.location = "synchronization/";
		});
		jQuery('#homeTabTest .moduletable, .ui-tabs-nav li:eq(2) a').click(function() {
		  window.location = "testing/";
		});
	}
						
	////////// Partner carousels //////////
	
	if (jQuery('#logoSlide').length > 0) {
		
		jQuery('#logoSlide').cycle({ 
			fx:      'fade', 
			//speed:    300, 
			timeout:  7500 
		});

	}
									
	////////// "What's Hot" stuff (section heading pages) //////////
	
	// Wrap the "What's Hot" news items in divs and add styles
	if (jQuery('div.moduletablewhatshot').length > 0) {
		jQuery('div.moduletablewhatshot table').each(function(i) {	
			jQuery(this).addClass('whatsHotTable'+(i+1)+'');
			
			switch(i) {
				case 0 :
					jQuery(this).addClass('whatsHot1');
					break;
				case 1 :
					jQuery(this).addClass('whatsHot1');
					break;
				case 2 :
					jQuery(this).addClass('whatsHot2');
					break;
				case 3 :
					jQuery(this).addClass('whatsHot2');
					break;
				case 4 :
					jQuery(this).addClass('whatsHot3');
					break;
				case 5 :
					jQuery(this).addClass('whatsHot3');
					break;			
				default :
					break;
			}
			
		});
		jQuery('.whatsHot1').wrapAll('<div class="whatsHotItem1" />');
		jQuery('.whatsHot2').wrapAll('<div class="whatsHotItem2" />');
		jQuery('.whatsHot3').wrapAll('<div class="whatsHotItem3" />');
	}
						
	////////// Twitter feed links //////////
	
	if (jQuery('#sectionLowerC2').length > 0) {
		jQuery('#sectionLowerC2 a').live("mouseover", function(){ // Need to use .live because the feed links are not loaded when the page is
		    jQuery('#sectionLowerC2 a').attr('target', '_blank');
		});
	}
						
	////////// Sidebar stuff //////////
	
	if (jQuery('.sidebar').length > 0) {
		
		// Hide the left navs in inappropriate pages
		jQuery('.sectionSubmenu').hide();
		jQuery('body.it-management .corpSubmenu, body.synchronization .corpSubmenu, body.testing .corpSubmenu').hide();
		jQuery('body.blogs .corpSubmenu').show();
		jQuery('body.it-management .sectionSubmenu, body.synchronization .sectionSubmenu, body.testing .sectionSubmenu').show();
		
		// Get rid of the top border in the first list items of sidebar lists
		jQuery('.sidebar .moduletable, .sidebar .moduletablesubnav1').each(function(i) {	
			jQuery('li:first', this).css({'background-image':'none', 'padding-top':'3px'});
		});
		jQuery('body.blogs ul.xoxo ul').each(function(i) {	
			jQuery('li:first', this).css({'background-image':'none', 'padding-top':'3px'});
		});
		
		// Sidebar nav 
		jQuery('#mainlevelsubnav1 a#active_menusubnav1').parents('ul').show();
		jQuery('#mainlevelsubnav1 a#active_menusubnav1').parent().addClass('activeItem');
		
		// Add appropriate subject to mail links
		
		if (jQuery('#corpSalesMail').length > 0) { // Corporate & Sales link
			var origLink = jQuery('#corpSalesMail').attr('href');
			var mailSubject = '?subject=Empowered Networks - I have a question';
			
			if (jQuery('body.it-management').length > 0) {
				mailSubject = '?subject=IT Management - I have a question';
			}
			if (jQuery('body.synchronization').length > 0) {
				mailSubject = '?subject=Synchronization Solutions - I have a question';
			}
			if (jQuery('body.testing').length > 0) {
				mailSubject = '?subject=Testing - I have a question';
			}
			
			var newLink = origLink+mailSubject;
			jQuery('#corpSalesMail').attr('href', newLink);
		} 
		if (jQuery('#techAssistMail').length > 0) { // Technical Assistance link
			var origLink2 = jQuery('#techAssistMail').attr('href');
			var mailSubject2 = '?subject=Empowered Networks - I have a question';
			
			if (jQuery('body.it-management').length > 0) {
				mailSubject2 = '?subject=IT Management - I have a question';
			}
			if (jQuery('body.synchronization').length > 0) {
				mailSubject2 = '?subject=Synchronization Solutions - I have a question';
			}
			if (jQuery('body.testing').length > 0) {
				mailSubject2 = '?subject=Testing - I have a question';
			}
			
			var newLink2 = origLink2+mailSubject2;
			jQuery('#techAssistMail').attr('href', newLink2);
		} 		
		if (jQuery('#corpSalesMail2').length > 0) { // Content footer link
			var origLink3 = jQuery('#corpSalesMail2').attr('href');
			var mailSubject3 = '?subject=Empowered Networks - I have a question';
			
			if (jQuery('body.it-management').length > 0) {
				mailSubject3 = '?subject=IT Management - I have a question';
			}
			if (jQuery('body.synchronization').length > 0) {
				mailSubject3 = '?subject=Synchronization Solutions - I have a question';
			}
			if (jQuery('body.testing').length > 0) {
				mailSubject3 = '?subject=Testing - I have a question';
			}
			
			var newLink3 = origLink3+mailSubject3;
			jQuery('#corpSalesMail2').attr('href', newLink3);
		} 
		
	}
						
	////////// Content page title //////////
	
	jQuery('.contentcolumn td.contentheading').parent().addClass('contentHeadingRow');
						
	////////// DT Register page title //////////
	
	if (jQuery('body.component-com_dtregister').length > 0) {
		
		var content = '<div class="componentHeadingWrapper"><div class="componentHeadingInnerWrapper">Empowered Networks<h2 class="contentheading">Events</h2></div><div style="clear: both;"></div></div>';
		
		jQuery('body.component-com_dtregister #component').prepend(content);
		jQuery('body.component-com_dtregister .componentHeadingWrapper').css({'margin-bottom':'47px'});
		jQuery('body.component-com_dtregister #component  form').css({'top':'0'});
		
		jQuery('body.component-com_dtregister tr.categoryRow td:contains("IT Management")').css({'background-color':'#006A72'});
		jQuery('body.component-com_dtregister tr.categoryRow td:contains("Synchronization")').css({'background-color':'#0082C8'});
		jQuery('body.component-com_dtregister tr.categoryRow td:contains("Testing")').css({'background-color':'#556293'});
		
		jQuery('body.component-com_dtregister select[name="country"] option:contains("United States")').attr('selected', '');
		jQuery('body.component-com_dtregister select[name="country"] option:contains("Canada")').attr('selected', 'selected');
		
		var html1 = jQuery('body.component-com_dtregister form[name="frmcart"] td:contains("State:")').html();
		html1 = html1.replace(/State:/, 'Province/State:');
		jQuery('body.component-com_dtregister form[name="frmcart"] td:contains("State:")').html(html1);
		
		var html2 = jQuery('body.component-com_dtregister form[name="frmcart"] td:contains("Zip Code:")').html();
		html2 = html2.replace(/Zip Code:/, 'Postal/Zip Code:');
		jQuery('body.component-com_dtregister form[name="frmcart"] td:contains("Zip Code:")').html(html2);
		
	}
						
	////////// BreezingForms //////////
	
	if (jQuery('.bfQuickMode').length > 0) {
		
		// Focus on the first form input
		jQuery('.bfQuickMode input:visible:enabled:first').focus();
		
		// Hide empty page intros
		var pageIntroText = jQuery('.bfPageIntro').text();
		if (pageIntroText < 2){
			jQuery('.bfPageIntro').hide();
		}
		
		// Captcha
		jQuery('.bfCaptcha').parent().addClass('captchaParent');

	}			
								
	////////// Career Application Form //////////
	
	if (jQuery('form#adminForm').length > 0) {
		// Replace the default text in the captcha input
		if (jQuery('input#captcha_entered').attr ('value') == 'Enter Security Code Here') {
			jQuery('input#captcha_entered').attr ('value', 'Please enter all visible characters');
			jQuery('input#captcha_entered').click(function() {
				if (this.value=='Please enter all visible characters') this.value='';
			});
		}
	}				
								
	////////// Xirrus custom landing page //////////
	
	if (jQuery('#contentWrapperXirrus').length > 0) {
	
		if (jQuery('.bfQuickMode').length > 0) {
			jQuery('.bfQuickMode p').each(function(i) {
				jQuery('.bfRequired', this).appendTo(jQuery('label', this));
			});
			jQuery('input#ff_elem1121').css({'float':'left', 'margin-right':'5px'}).prependTo(jQuery('#bfElemWrap1121'));
		}
		
		jQuery('#topNavContainer a, #footerContent a').attr('target', '_blank');
		
	}	
	
});


// Job application form validation
function validateJobAppForm () {
	
	if (jQuery('input#first_name').val() == '') {
		alert ('Please enter a first name.');
		return false;
	}
	else if (jQuery('input#last_name').val() == '') {
		alert ('Please enter a last name.');
		return false;
	}
	else if (jQuery('input#home_phone').val() == '') {
		alert ('Please enter a home phone number.');
		return false;
	}
	else if (jQuery('input#email_address').val() == '') {
		alert ('Please enter an email address.');
		return false;
	}
	else if (jQuery('input#captcha_entered').val() == '' || jQuery('input#captcha_entered').val() == 'Please enter all visible characters') {
		alert ('Please enter the security code.');
		return false;
	}
	else {
		document.adminForm.submit();
	}

}














