$(function(){
	var $sho = null;
	$('external').attr({ target: "_blank", title: "Opens in a new window"});
	
	$('#service-image').cycle({
		fx: 'fade',
		delay: 2000,
		speed: 600,
		cleartype: !$.support.opacity,
		cleartypeNoBg: true
		});
	
	$('#legal p').html('All Content &copy;2012 Independent Benefit Services');
		
		$('a.external').attr('target','_blank');
		
	    $('#enewslettersignup').click(function() {
				  var v = true;
				  var error = '#E5B1B0';
				  var valid = '#FFF';
				  var name =  $('#your_name').val();
				  var company = $('#user_company').val();
				  var email = $('#email').val();
				  var title = $('#user_title').val();
				  var street = $('#user_street').val();
				  var city = $('#city').val();
				  var state = $('#mailing_state').val();
				  var zip = $('#zip').val();
				  var choiceone = null;
				  var choicetwo	= null;
				  var choicethree = null;
						if ($('#want_one').is(':checked')){ choiceone = $('#want_one').val(); }
						if ($('#want_two').is(':checked')){ choicetwo = $('#want_two').val(); }
						if ($('#want_three').is(':checked')){ choicethree = $('#want_three').val(); }
						if ($('#want_four').is(':checked')){ choicefour = $('#want_four').val(); }
						if(name == 0){
							$('#your_name').css({'background-color': error});
							$('#your_name').focus();
							return false;
						}else{
							$('#your_name').css({'background-color': valid});
						}
						
						if(company == 0){
							$('#user_company').css({'background-color': error});
							$('#user_company').focus();
							return false;
						}else{
							$('#user_company').css({'background-color': valid});
						}

						if(title == 0){
							$('#user_title').css({'background-color': error});
							$('#user_title').focus();
							return false;
						}else{
							$('#user_title').css({'background-color': valid});
						}

						if(street == 0){
							$('#user_street').css({'background-color': error});
							$('#user_street').focus();
							return false;
						}else{
							$('#user_street').css({'background-color': valid});
						}

						if(city == 0){
							$('#city').css({'background-color': error});
							$('#city').focus();
							return false;
						}else{
							$('#city').css({'background-color': valid});
						}

						if(!isValidZip(zip)){
							$('#zip').css({'background-color': error});
							$('#zip').focus();
							return false;
						}else{
							$('#zip').css({'background-color': valid});
						}
						
						if(!isValidEmailAddress(email)){
							$('#email').css({'background-color': error});
							$('#email').focus();
							return false;
						}else{
							$('#email').css({'background-color': valid});
						}
						
						if(choiceone == null && choicetwo == null && choicethree == null && choicefour == null){
							$('div.wants').css({'background-color': error});
							return false;
						}else{
							$('div.wants').css({'background-color': valid});
						}
							
						$('#register_form').submit();
		    	});

				$('#showyears li a:eq(0), #showbyears li a:eq(0), #reportsbyyears li a:eq(0)').addClass('current');
				$('.year:gt(0), .byear:gt(0), .cyear:gt(0)').hide();
				$('#showyears li a').click(function(){
					$('#showyears li a').removeClass('current');
					$(this).addClass('current');
					var sho = $(this).attr('rel');
					$('.year').hide();
					$(sho).show();
					return false;
				})
				$('#showbyears li a').click(function(){
					$('#showbyears li a').removeClass('current');
					$(this).addClass('current');
					var sho = $(this).attr('rel');
					$('.byear').hide();
					$(sho).show();
					return false;
				})
				$('#reportsbyyears li a').click(function(){
					$('#reportsbyyears li a').removeClass('current');
					$(this).addClass('current');
					var sho = $(this).attr('rel');
					$('.cyear').hide();
					$(sho).show();
					return false;
				})

		    		
		  });
		
		function isValidZip(zip)
		{
		reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (!reZip.test(zip)) {
			return false;
			}
		return true;
		}
		
		function isValidEmailAddress(emailAddress)
		{
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
		}
