var required = { 'kmForm':[
  { 'defecttype':'Type of defect','problemdate':'Date that problem occurred','dealerrepairs':'Dealer repair attempts','dealerdays':'Days at dealership','warrantynow':'Currently under warranty','warrantythen':'Under warranty when problem occurred','mileagenow':'Mileage now','mileagethen':'Mileage when problem occurred' },
  { 'year':'Vehicle year','make':'Vehicle make','model':'Vehicle model','boughtas':'Bought as','purchasedate':'Date purchased','fullname':'Your name','email':'Email address','phone':'Phone number','state':'State of residence','description':'Description of issue' }
]};

$(function() {
  $('#kamLink,#kaaLink').click(function() {
    $.scrollTo($(''+this.href.match(/\#.+/)),{speed:800});
    return(false);
  });

  $('#kmForm a.next').bind('click',function() { nexthandler(this); });
  $('#kmForm a.prev').bind('click',function() { prevhandler(this); });
  $('#kmForm').bind('submit',function() { return(lemonlead(this)); });
  $('#kmForm fieldset:eq(0)').show();

  $('#problemdate input,#purchasedate input').datepicker({ showOn:'both',buttonImage:'/images/icon-calendar.gif',buttonImageOnly:true,dateFormat:'mm/dd/y',maxDate:new Date(),clearText:'Date Problem Occurred',closeText:'X',prevText:'&laquo;',nextText:'&raquo;',dayNames:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],changeFirstDay:false });
});

function nexthandler(aRef) {
  var fRef = $('#kmForm')[0];
  if (validate(fRef,aRef)) {
    var fIndex = getfIndex(fRef,aRef);
    if ((fIndex+1) < $('fieldset',fRef).length) {
      switchfieldset(fRef,aRef,1);
    }
    else {
      setTimeout("$('#kmForm').slideUp(1000);",5000);
      tb_show('','about:blank?TB_iframe=true&width=450&height=150');
      fRef.target = $('#TB_iframeContent').attr('name');
      fRef.submit();
    }
  }
}

function prevhandler(aRef) {
  var kmFref = $('#kmForm')[0];
  switchfieldset(kmFref,aRef,-1);
}
