jQuery.lmbNavBar = function(id){
	$(id + ' ul li').hover(function(){
		$(this).find('ul:first').show();
		$(this).find('a:first').addClass('menuActive');
	},function(){
		$(this).find('ul:first').hide();
		$(this).find('a:first').removeClass('menuActive');
	});
}

var isValidZipCode=function(ob){
	var re = /^\d{5}?$/;
	return (re.test(ob));
}
$(function(){
	$.lmbNavBar("#menu");
	$("#capsuleMenu").find('li').click(function(){
		$("#capsuleMenu").find('li').removeClass('tabSelected');
		$(this).addClass('tabSelected');
		$('.tabContent').hide();
		$('#'+$(this).attr('id')+'Content').fadeIn('fast');
	});
	$("#capsuleMenu").find('li:first').click();
	
	// add iframes to hover menus (IE6 only)
	$('.navMenu').bgiframe();
	
	var kount=0;
	var bannerTotal=$('.homeBanner').length;
	var setBanner=function(){
		kount++;
		if(kount>(bannerTotal-1)){kount=0};
		$('.homeBanner').hide();
		$('.homeBanner').eq(kount).show();
	};
	var rotateBanners=function(){
		$('#bannerCont').animate({opacity:'hide'},200,function(){
			setBanner();
			$('#bannerCont').animate({opacity:'show'},400);
		});
		timer=setTimeout(rotateBanners,5000);
	};
	$('.homeBanner').eq(kount).show();
	if(bannerTotal > 1){
		timer=setTimeout(rotateBanners,5000);
	}
	
	// Debt dropdown
	$('#creditCardDebt').change(function(){
		if($(this).val()!='' && $(this).val() < 8){
			$('#unsecuredDebtRow').slideDown('fast');
			$('#unsecuredDebt').val('0');
		}
	});
	
	//footer links to pop
	$('#footerLogoTrueSecure').click(function(){
		window.open($(this).attr('href'), "TS", "width=350,height=440,scrollbars=no,alwaysRaised=no,resizable=yes,dependent");
		return false;
	});
	$('#footerUnsuscribe').click(function(){
		window.open("http://LMB.lmbusc.com/addfbedbadd07da5f781ed23f22b3158", "silverPop", "width=640,height=500,scrollbars=no,alwaysRaised,resizable=yes,dependent");
		return false;
	});
	$('#footerLogoTruste').click(function(){
		window.open($(this).attr('href'), "client3", "width=700,height=450,scrollbars=yes,alwaysRaised,resizable=yes,toolbar,dependent");
		return false;
	});
	
	/* FORM SUBMISSIONS */
	$('#lendingForm').submit(function(){
		if($(this).find("select[name='typeOfLoan']").val()!=''){
			try {
		        popupsEnabled = false;
		    } catch(ex) {}
			return true;
		}
		alert('Please select the Type of Loan.');
		return false;
	});
	$('#debtForm').submit(function(){
		if($(this).find("select[name='creditCardDebt']").val()!=''){
			if($('#unsecuredDebt').val()==''){
				$('#unsecuredDebt').val('0');
			}
			return true;
		}
		alert('Please select your Credit Card Debt amount.');
		return false;
	});
	$('#insForm').submit(function(){
		if(isValidZipCode($(this).find('#zipcode').val())){
			switch($(this).find('#insuranceType').val()){
				case '0' : 
					$(this).submit();
					break;
				case '1' : 
					document.location='/fh/homeownersInsurance/ApplicationPageOne_0.jsp?TAG_ID=A037F003F157BC87734AA3C4855237281251998283413';
					break;
				case '2' : 
					document.location='/ire/ire_main_0.jsp?TAG_ID=A037F003F157BC87734AA3C4855237281251998283413';
					break;
				case '3' : 
					document.location='http://www.efinancial.com/smartquoteef.aspx?source=516-123457&zip='+$(this).find('#zipcode').val();
					break;
				case '4' : 
					document.location='https://www.ehealthinsurance.com/ehi/Alliance?allid=Low17350&type=IFP&sid=883636634&zip='+$(this).find('#zipcode').val();
					break;
				default: /* DO NOTHING */;
			}
			return false;
		}
		alert('Please enter a valid U.S. ZIP code.');
		$(this).find('#zipcode').focus();
		return false;
	});
	$('#cusaForm').submit(function(){
		if($(this).find('#programCategoryGroups').val()!=''){
			return true;
		}
		alert('Please select a degree category to get information about.');
		return false;
	});
	
	/* PAGE ONE FORM PREPOPULATION */
	if($('#lendingForm').find("select[name='typeOfLoan']").val()==''){
		$('#lendingForm').find("select[name='typeOfLoan']").val('LRE');
	}
});	

