var arrEveryday = new Array('menstruation','isnormal','aui','menopause','yourhealth','protection','products', 'sleep');
var arrTeens = new Array('pms','flow','guardians','protection','products');
var arrMoms = new Array('bladder_control','aui','spot','protection','products');

function checkCurrentPage( menu ){
	var address = location.href;
	var regMenu = new RegExp( 'nosection','gi' );
	var i;
	var img;
	var div1;
	var base_menu;
	var product_finder;

	if( String( menu ) == 'undefined' || String( menu ) == 'everyday' ){
		regMenu = new RegExp( 'everyday','gi' );
	}

	if( address.match( regMenu ) ){
		//Menu
		div1 = document.getElementById( 'sub_everyday' );
		div1.className = 'showMenu';
		//Img
		img = document.getElementById( 'm_everyday' );
		img.src = 'images/menu/m_everyday_on.jpg';
		
		for( i=0; i < arrEveryday.length; i++ ){
			regMenu = new RegExp( arrEveryday[i] ,'gi' );
			if( address.match( regMenu ) ){
				img = document.getElementById( 'm_ed_' + arrEveryday[i] );
				img.src = 'images/menu/m_ed_' + arrEveryday[i] + '_on.jpg';
				break;
			}
		}
		//Base Menu
		base_menu = document.getElementById('base_menu');
		base_menu.src = 'images/menu/m_base_everyday.jpg';
		//Product Finder
		product_finder = document.getElementById('productfinder');
		product_finder.className = 'productfinder_everyday';
	}else{
		if( String( menu ) == 'undefined' || String( menu ) == 'teens' ){
			regMenu = new RegExp( 'teens','gi' );
		}

		if( address.match( regMenu ) ){
			//Menu
			div1 = document.getElementById( 'sub_teens' );
			div1.className = 'showMenu';
			//Img
			img = document.getElementById( 'm_teens' );
			img.src = 'images/menu/m_teens_on.jpg';
			
			for( i=0; i < arrTeens.length; i++ ){
				regMenu = new RegExp( arrTeens[i] ,'gi' );
				if( address.match( regMenu ) ){
					img = document.getElementById( 'm_teens_' + arrTeens[i] );
					img.src = 'images/menu/m_teens_' + arrTeens[i] + '_on.jpg';
					break;
				}
			}
			//Base Menu
			base_menu = document.getElementById('base_menu');
			base_menu.src = 'images/menu/m_base_teens.jpg';
			//Product Finder
			product_finder = document.getElementById('productfinder');
			product_finder.className = 'productfinder_teens';
		}else{
			if( String( menu ) == 'undefined' || String( menu ) == 'moms' ){
				regMenu = new RegExp( 'moms','gi' );
			}
			
			if( address.match( regMenu ) ){
				//Menu
				div1 = document.getElementById( 'sub_moms' );
				div1.className = 'showMenu';
				//Img
				img = document.getElementById( 'm_moms' );
				img.src = 'images/menu/m_moms_on.jpg';
				
				for( i=0; i < arrMoms.length; i++ ){
					regMenu = new RegExp( arrMoms[i] ,'gi' );
					if( address.match( regMenu ) ){
						img = document.getElementById( 'm_moms_' + arrMoms[i] );
						img.src = 'images/menu/m_moms_' + arrMoms[i] + '_on.jpg';
						break;
					}
				}
				//Base Menu
				base_menu = document.getElementById('base_menu');
				base_menu.src = 'images/menu/m_base_moms.jpg';
				//Product Finder
				product_finder = document.getElementById('productfinder');
				product_finder.className = 'productfinder_moms';
			}else{
				if( String( menu ) == 'undefined' || String( menu ) == 'gidc' ){
					regMenu = new RegExp( 'gidc','gi' );
				}	
				
				if( address.match( regMenu ) ){
					//Img
					var img = document.getElementById( 'm_teens_gidc' );
					img.src = 'images/menu/m_teens_gidc_on.jpg';
				}
			}
		}
	}
}

function redirectTo( links ){
	window.location.href = links;
}

function selectSubItem( menu, subitem ){
	var img;

	img = document.getElementById( subitem );
	if( menu == 'everyday' ){		
		switch( subitem ){
			case "m_ed_menstruation":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_isnormal":
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_aui":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_menopause":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_yourhealth":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_protection":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_products' );
				img.src = 'images/menu/m_ed_products_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
			case "m_ed_products":
				img = document.getElementById( 'm_ed_isnormal' );
				img.src = 'images/menu/m_ed_isnormal_off.jpg';
				img = document.getElementById( 'm_ed_aui' );
				img.src = 'images/menu/m_ed_aui_off.jpg';
				img = document.getElementById( 'm_ed_menstruation' );
				img.src = 'images/menu/m_ed_menstruation_off.jpg';
				img = document.getElementById( 'm_ed_menopause' );
				img.src = 'images/menu/m_ed_menopause_off.jpg';
				img = document.getElementById( 'm_ed_yourhealth' );
				img.src = 'images/menu/m_ed_yourhealth_off.jpg';
				img = document.getElementById( 'm_ed_protection' );
				img.src = 'images/menu/m_ed_protection_off.jpg';
				img = document.getElementById( 'm_ed_sleep' );
				img.src = 'images/menu/m_ed_sleep_off.jpg';
				break;
		}
		checkCurrentPage( 'everyday' );
	}else{ 
		if( menu == 'teens' ){
			switch( subitem ){
				case "m_teens_pms":
					img = document.getElementById( 'm_teens_flow' );
					img.src = 'images/menu/m_teens_flow_off.jpg';
					img = document.getElementById( 'm_teens_guardians' );
					img.src = 'images/menu/m_teens_guardians_off.jpg';
					img = document.getElementById( 'm_teens_protection' );
					img.src = 'images/menu/m_teens_protection_off.jpg';
					img = document.getElementById( 'm_teens_products' );
					img.src = 'images/menu/m_teens_products_off.jpg';
					break;
				case "m_teens_flow":
					img = document.getElementById( 'm_teens_pms' );
					img.src = 'images/menu/m_teens_pms_off.jpg';
					img = document.getElementById( 'm_teens_guardians' );
					img.src = 'images/menu/m_teens_guardians_off.jpg';
					img = document.getElementById( 'm_teens_protection' );
					img.src = 'images/menu/m_teens_protection_off.jpg';
					img = document.getElementById( 'm_teens_products' );
					img.src = 'images/menu/m_teens_products_off.jpg';
					break;
				case "m_teens_guardians":
					img = document.getElementById( 'm_teens_pms' );
					img.src = 'images/menu/m_teens_pms_off.jpg';
					img = document.getElementById( 'm_teens_flow' );
					img.src = 'images/menu/m_teens_flow_off.jpg';
					img = document.getElementById( 'm_teens_protection' );
					img.src = 'images/menu/m_teens_protection_off.jpg';
					img = document.getElementById( 'm_teens_products' );
					img.src = 'images/menu/m_teens_products_off.jpg';
					break;
				case "m_teens_protection":
					img = document.getElementById( 'm_teens_pms' );
					img.src = 'images/menu/m_teens_pms_off.jpg';
					img = document.getElementById( 'm_teens_flow' );
					img.src = 'images/menu/m_teens_flow_off.jpg';
					img = document.getElementById( 'm_teens_guardians' );
					img.src = 'images/menu/m_teens_guardians_off.jpg';
					img = document.getElementById( 'm_teens_products' );
					img.src = 'images/menu/m_teens_products_off.jpg';
					break;
				case "m_teens_products":
					img = document.getElementById( 'm_teens_pms' );
					img.src = 'images/menu/m_teens_pms_off.jpg';
					img = document.getElementById( 'm_teens_flow' );
					img.src = 'images/menu/m_teens_flow_off.jpg';
					img = document.getElementById( 'm_teens_guardians' );
					img.src = 'images/menu/m_teens_guardians_off.jpg';
					img = document.getElementById( 'm_teens_protection' );
					img.src = 'images/menu/m_teens_protection_off.jpg';
					break;
			}
			checkCurrentPage( 'teens' );		
		}else{
			if( menu == 'moms' ){
				switch( subitem ){
					case "m_moms_bladder_control":
						img = document.getElementById( 'm_moms_aui' );
						img.src = 'images/menu/m_moms_aui_off.jpg';
						img = document.getElementById( 'm_moms_spot' );
						img.src = 'images/menu/m_moms_spot_off.jpg';
						img = document.getElementById( 'm_moms_protection' );
						img.src = 'images/menu/m_moms_protection_off.jpg';
						img = document.getElementById( 'm_moms_products' );
						img.src = 'images/menu/m_moms_products_off.jpg';
						break;
					case "m_moms_aui":
						img = document.getElementById( 'm_moms_bladder_control' );
						img.src = 'images/menu/m_moms_bladder_control_off.jpg';
						img = document.getElementById( 'm_moms_spot' );
						img.src = 'images/menu/m_moms_spot_off.jpg';
						img = document.getElementById( 'm_moms_protection' );
						img.src = 'images/menu/m_moms_protection_off.jpg';
						img = document.getElementById( 'm_moms_products' );
						img.src = 'images/menu/m_moms_products_off.jpg';
						break;
					case "m_moms_spot":
						img = document.getElementById( 'm_moms_bladder_control' );
						img.src = 'images/menu/m_moms_bladder_control_off.jpg';
						img = document.getElementById( 'm_moms_aui' );
						img.src = 'images/menu/m_moms_aui_off.jpg';
						img = document.getElementById( 'm_moms_protection' );
						img.src = 'images/menu/m_moms_protection_off.jpg';
						img = document.getElementById( 'm_moms_products' );
						img.src = 'images/menu/m_moms_products_off.jpg';
						break;
					case "m_moms_protection":
						img = document.getElementById( 'm_moms_bladder_control' );
						img.src = 'images/menu/m_moms_bladder_control_off.jpg';
						img = document.getElementById( 'm_moms_aui' );
						img.src = 'images/menu/m_moms_aui_off.jpg';
						img = document.getElementById( 'm_moms_spot' );
						img.src = 'images/menu/m_moms_spot_off.jpg';
						img = document.getElementById( 'm_moms_products' );
						img.src = 'images/menu/m_moms_products_off.jpg';
						break;
					case "m_moms_products":
						img = document.getElementById( 'm_moms_bladder_control' );
						img.src = 'images/menu/m_moms_bladder_control_off.jpg';
						img = document.getElementById( 'm_moms_aui' );
						img.src = 'images/menu/m_moms_aui_off.jpg';
						img = document.getElementById( 'm_moms_spot' );
						img.src = 'images/menu/m_moms_spot_off.jpg';
						img = document.getElementById( 'm_moms_protection' );
						img.src = 'images/menu/m_moms_protection_off.jpg';
						break;
				}
				checkCurrentPage( 'moms' );
			}
		}
	}
	
	img = document.getElementById( subitem );
	if( img.src.indexOf('off') > 0 ){
		img.src = 'images/menu/' + subitem + '_over.jpg';
	}
}

function switchHeader( menu_name, action ){
	
	var header = document.getElementById( 'm_' + menu_name );
	if( String(header.src).indexOf("on") == -1 ){
		header.src = 'images/menu/m_' + menu_name + '_' + action + '.jpg';
	}
	
}

function openMenu( menu ){

	var sub_menu = document.getElementById('sub_' + String( menu ));
	var img = document.getElementById( 'm_' + String( menu ) );
	var base_menu;
	var bolClose = false;
	var product_finder;
	var specialoffer;
	var main_link = "";

	if( String(sub_menu.className) == 'showMenu' ){
		sub_menu.className = 'hideMenu';
		img.src = 'images/menu/m_' + menu + '_off.jpg';
		bolClose = true;
	}else{
		sub_menu.className = 'showMenu';
		img.src = 'images/menu/m_' + menu + '_on.jpg';
	}
	
	switch( String(menu) ){
		case "everyday":
			//Menu
			sub_menu = document.getElementById('sub_teens');
			sub_menu.className = 'hideMenu';
			sub_menu = document.getElementById('sub_moms');
			sub_menu.className = 'hideMenu';
			//Img
			img = document.getElementById( 'm_teens' );
			img.src = 'images/menu/m_teens_off.jpg';
			img = document.getElementById( 'm_moms' );
			img.src = 'images/menu/m_moms_off.jpg';
			//Base Menu
			base_menu = document.getElementById('base_menu');
			//Product Finder
			product_finder = document.getElementById('productfinder');
			product_finder.className = 'productfinder_everyday';
			//Special Offer
			specialoffer = document.getElementById('specialoffers');
			specialoffer.className = 'specialoffers_everyday';
			//Checks if it is closing the menu
			if( bolClose ){
				base_menu.src = 'images/menu/m_base_closed.jpg';
				product_finder.className = 'productfinder';
				specialoffer.className = 'productfinder';
			}else{
				base_menu.src = 'images/menu/m_base_everyday.jpg';
				//set main link
				main_link = "everydaysf.jsp";
			}
			break;
		case "teens":
			//Menu
			sub_menu = document.getElementById('sub_everyday');
			sub_menu.className = 'hideMenu';
			sub_menu = document.getElementById('sub_moms');
			sub_menu.className = 'hideMenu';				
			//Img
			img = document.getElementById( 'm_everyday' );
			img.src = 'images/menu/m_everyday_off.jpg';
			img = document.getElementById( 'm_moms' );
			img.src = 'images/menu/m_moms_off.jpg';
			//Base Menu
			base_menu = document.getElementById('base_menu');
			//Product Finder
			product_finder = document.getElementById('productfinder');
			product_finder.className = 'productfinder_teens';
			//Special Offer
			specialoffer = document.getElementById('specialoffers');
			specialoffer.className = 'specialoffers_teens';
			//Checks if the menus is closing
			if( bolClose ){
				base_menu.src = 'images/menu/m_base_closed.jpg';
				product_finder.className = 'productfinder';
				specialoffer.className = 'productfinder';
			}else{
				base_menu.src = 'images/menu/m_base_teens.jpg';
				//set main link
				main_link = "teens_forteens.jsp";
			}
			break;
		case "moms":
			//Menu
			sub_menu = document.getElementById('sub_teens');
			sub_menu.className = 'hideMenu';
			sub_menu = document.getElementById('sub_everyday');
			sub_menu.className = 'hideMenu';	
			img = document.getElementById( 'm_moms' );
			img.src = 'images/menu/m_moms_off.jpg';
			//Img
			img = document.getElementById( 'm_teens' );
			img.src = 'images/menu/m_teens_off.jpg';
			img = document.getElementById( 'm_everyday' );
			img.src = 'images/menu/m_everyday_off.jpg';
			//Base Menu
			base_menu = document.getElementById('base_menu');
			//Product Finder
			product_finder = document.getElementById('productfinder');
			product_finder.className = 'productfinder_moms';
			//Special Offer
			specialoffer = document.getElementById('specialoffers');
			specialoffer.className = 'specialoffers_moms';
			//Checks if the menu is closing
			if( bolClose ){
				base_menu.src = 'images/menu/m_base_closed.jpg';
				product_finder.className = 'productfinder';
				specialoffer.className = 'productfinder';
			}else{
				base_menu.src = 'images/menu/m_base_moms.jpg';
				//set main link
				main_link = "moms_formoms.jsp";
			}
			break;
		case "gidc":
			//Menu
			sub_menu = document.getElementById('sub_teens');
			sub_menu.className = 'hideMenu';
			sub_menu = document.getElementById('sub_everyday');
			sub_menu.className = 'hideMenu';	
			//Img
			img = document.getElementById( 'm_teens' );
			img.src = 'images/menu/m_teens_off.jpg';
			img = document.getElementById( 'm_everyday' );
			img.src = 'images/menu/m_everyday_off.jpg';
			//Base Menu
			base_menu = document.getElementById('base_menu');
			//Product Finder
			product_finder = document.getElementById('productfinder');
			product_finder.className = 'productfinder_moms';
			//Special Offer
			specialoffer = document.getElementById('specialoffers');
			specialoffer.className = 'specialoffers_moms';
			//Checks if the menu is closing
			if( bolClose ){
				base_menu.src = 'images/menu/m_base_closed.jpg';
				product_finder.className = 'productfinder';
				specialoffer.className = 'productfinder';
			}else{
				base_menu.src = 'images/menu/m_base_moms.jpg';
				//set main link
				main_link = "moms_formoms.jsp";
			}
			break;
		
	}
	if( main_link != "" ){
		redirectTo( main_link );
	}
	
}
