$(document).ready(function () {
  
// This is the JS for Show Hide Form  
var prevOpened1 = null;
var prevOpened2 = null;

$('.NextBtn, .backBtn').click(function () {
      $(this).closest('.FormContent').slideToggle("fast");
      $('.' + $(this).attr('rel')).slideToggle("slow"); 

      prevOpened1 = $(this).closest('.FormContent');
      prevOpened2 = $('.' + $(this).attr('rel')); 
});
$('.Tab').click(function () {
      if (prevOpened1 != null) {
           prevOpened1.slideUp("fast");
           prevOpened2.slideUp("slow"); 
      }
      $(this).closest('.FormContent').slideToggle("fast");
      $('.' + $(this).attr('rel')).slideToggle("slow"); 

      prevOpened1 = $(this).closest('.FormContent');
      prevOpened2 = $('.' + $(this).attr('rel')); 
});
// This is the JS for the multi submit    
    $('#Submit-Level-1').click(function () {
      var btn = $(this);         
      submitForm($("#Form-Level-1, #Form-Submit").serialize(), btn); 
       return false;
    });
    
     $('#Submit-Level-2').click(function () {
      var btn = $(this); 
      submitForm($("#Form-Level-1, #Form-Level-2, #Form-Submit").serialize(), btn); 
       return false;
    });
    
     $('#Submit-Level-3').click(function () {
      var btn = $(this);
      submitForm($("#Form-Level-1, #Form-Level-2, #Form-Level-3, #Form-Submit").serialize(), btn); 
       return false;
    });

function submitForm(data, btn) {
if (         $('#Form-Level-1').find("input[name='Name1']").val() == '' || 
             $('#Form-Level-1').find("input[name='Phone1']").val() == '' || 
             $('#Form-Level-1').find("input[name='Email1']").val() == '') {
                  alert('Please fill in your name, phone, and email address.');
                  return false;
                }
      $.ajax({
         type: "POST",
         url: "/sendmail.aspx",
         data:  data,
         success: function(msg){
           window.location = "/web/page/thank_you"
         }
       });     
    } 
  // End Multi Submit
});
//This is the JS for the fade in/out of banner    
   var prevItem = null;
 function bannerSwitch() {
   var $active = $('#Banner DIV.active');
      if ( $active.length == 0 ) $active = $('#Banner DIV:last');
      var $next =  $active.next().length ? $active.next()
          : $('#Banner DIV:first');
      $active.addClass('last-active');
      $next.css({opacity: 0.0})
          .addClass('active')
          .animate({opacity: 1.0}, 1000, function() {
              $active.removeClass('active last-active');
          });
      $('.' + $next.attr('rel')).addClass('genericHover');  
      if (prevItem != null) {
          prevItem.removeClass('genericHover');
      }
      prevItem =  $('.' + $next.attr('rel'));
}

$(function() {
   setInterval("bannerSwitch()", 7000 );
}); 

