var maxPanels  = $A($$('#panelContainer > #panelScroll > .panel')).length;
var curPanel   = 1;
var inProgress = 0;

var panelTitles = ['Personal Information','Loan Information','Financial Information','Co-borrower Information','Co-borrower Financial Information','Other Information'];

function nextPanel() {
  if(curPanel + 1 <= maxPanels)
	showPanel(curPanel + 1);
}

function prevPanel() {
  if(curPanel - 1 >= 1)
	showPanel(curPanel - 1);
}

function showPanel(num) {
  if(validatePanel(curPanel)) {
    scrollOffset = ((curPanel-1)*558) - ((num-1)*558);

    if(!inProgress) {
      inProgress = 1;

      new Effect.Move($('panelScroll'), { x: scrollOffset, y: 0, mode: 'relative', duration: 0.3, afterFinish: showPanelDone });

      $('panelButton'+curPanel).removeClassName('tabbtactive');
      $('panelButton'+curPanel).addClassName('tabbt');
      $('panelButton'+num).removeClassName('tabbt');
      $('panelButton'+num).addClassName('tabbtactive');

      $('panelTitle').innerHTML=panelTitles[(num-1)];

      curPanel = num;
    }
  }
}

function showPanelDone() {
  inProgress = 0;
}

function validatePanel(num) {
  if(num == 1) {
    if($('Borrowers_Name').value=='') {
      alert("'Borrowers Name' is a required field.\n\nPlease correct this omition before continuing.");
      $('Borrowers_Name').focus();
      return false;
    }
    else if($('Email_Address').value=='') {
      alert("'Email Address' is a required field.\n\nPlease correct this omition before continuing.");
      $('Email_Address').focus();
      return false;
    }
    else if($('Home_Phone').value=='') {
      alert("'Home Phone' is a required field.\n\nPlease correct this omition before continuing.");
      $('Home_Phone').focus();
      return false;
    }
  }
  return true;
}

