
function load_wheel_section(section){

  Element.show('certcontrol_tab_blocker');
  Element.show('home_tab_menu_blocker');

  // Set up a section hash
  var sections = new Array('software',
                           'costs',
                           'compliance',
                           'process',
                           'time',
                           'audits');

  switch(section){

    case 'hide':

      // Do hides
      for (i=0; i< sections.length; i++){
        new Effect.Fade(sections[i]+'_content',{duration: 0.5});
        new Effect.Fade(sections[i]+'_picture',{duration: 0.5});
      }
      new Effect.Fade('woman_picture',{duration: 0.5});
      new Effect.Fade('wheel_instructions',{duration: 0.5});
      new Effect.Fade('wheel_certcontrol',{duration: 0.5});
      new Effect.Fade('wheel_put_you',{duration: 0.5});
      new Effect.Fade('wheel_section_nav',{duration: 0.5});
      new Effect.Fade('certcontrol_wheel',{duration: 0.4, queue: 'end'});
      break;

    case 'show':
    case 'main':

      if (section == 'main'){
        // Do fades
        new Effect.Fade('wheel_section_nav',{duration: 0, queue: 'end'});

        // Find visible section and hide
        for (i=0; i< sections.length; i++){
          if (Element.visible($(sections[i]+'_content'))){
            new Effect.Fade(sections[i]+'_content',{duration: 0.5, queue: 'end'});
            break;
          }
	    }
      }

      // Iteratively show all the links
      for (i=0; i < sections.length; i++){
        new Effect.Appear(sections[i]+'_picture',{duration: 0.20, queue: 'end'});
      }

      new Effect.Appear('woman_picture',{duration: 0.20, queue: 'end'});
      new Effect.Appear('wheel_certcontrol',{duration: 0.20, queue: 'end'});
      new Effect.Appear('wheel_instructions',{duration: 0.20, queue: 'end'});
      new Effect.Appear('wheel_put_you',{duration: 0.20, queue: 'end'});

      if (section == 'main'){
        new Effect.Fade('home_tab_menu_blocker',{duration: 0, queue: 'end'});
	  }
	  break;

    case 'software':
    case 'costs':
    case 'compliance':
    case 'process':
    case 'time':
    case 'audits':

      // Fade the wheel
      for (i=0; i< sections.length; i++){
        new Effect.Fade(sections[i]+'_picture',{duration: 0.5});
      }

      new Effect.Fade('woman_picture',{duration: 0.5});
      new Effect.Fade('wheel_instructions',{duration: 0.5});
      new Effect.Fade('wheel_certcontrol',{duration: 0.5});
      new Effect.Fade('wheel_put_you',{duration: 0.5});
      new Effect.Appear(section+'_content',{duration: 0.5, queue: 'end'});
      new Effect.Appear('wheel_section_nav',{duration: 0, queue: 'end'});
      new Effect.Fade('home_tab_menu_blocker',{duration: 0, queue: 'end'});
      break;

    case 'next':
    case 'prev':

      var selected;

      new Effect.Fade('wheel_section_nav',{duration: 0});

      // Find visible section, mark and hide
      for (i=0; i< sections.length; i++){
        if (Element.visible($(sections[i]+'_content'))){
          selected = i;
          new Effect.Fade(sections[i]+'_content',{duration: 0.5, queue: 'end'});
          break;
        }
      }

      var index = 0;
      if (section == 'prev'){
	    // Show previous section
        index = (selected == 0) ? sections.length - 1 : selected - 1;
	  }
	  else {
        // Show next section
        index = (selected == (sections.length - 1)) ? 0 : selected + 1;
	  }
      new Effect.Appear(sections[index]+'_content',{duration: 0.5, queue: 'end'});
      new Effect.Appear('wheel_section_nav',{duration: 0, queue: 'end'});
      new Effect.Fade('home_tab_menu_blocker',{duration: 0, queue: 'end'});
      break;

  }
  new Effect.Fade('certcontrol_tab_blocker',{duration: 0, queue: 'end'});

}


function load_tab_section(section){

  if (Element.visible($('certcontrol_'+section))){
    return;
  }

  Element.show('home_tab_menu_blocker');

  // Set up a section hash
  var sections = new Array('wheel',
                           'sales_tax',
                           'use_tax',
                           'retail');


  
  if (Element.visible($('certcontrol_wheel'))){
    load_wheel_section('hide');
    $('wheel_anchor').className = 'home_tab_menu_link_off';
  }

  // Find visible section and hide
  for (i=1; i< sections.length; i++){
    if (Element.visible($('certcontrol_'+sections[i]))){
      new Effect.Fade('certcontrol_'+sections[i],{duration: 0.5, queue: 'end'});
      $(sections[i]+'_anchor').className = 'home_tab_menu_link_off';
      break;
    }
  }

  $(section+'_anchor').className = 'home_tab_menu_link_on';

  switch(section){

    case 'wheel':
      new Effect.Appear('certcontrol_'+section,{duration: 0, queue: 'end'});
      load_wheel_section('show');
      break;

    default:
      new Effect.Appear('certcontrol_'+section,{duration: .75, queue: 'end'});
      break;
  }
  new Effect.Fade('home_tab_menu_blocker',{duration: 0, queue: 'end'});
}

function wait_cursor(){
  document.body.style.cursor = 'progress';
}

function clear_cursor(){
  document.body.style.cursor = 'default';
}

// This is used because IE can't fade a TR element, only TD elements
function fade_row(id_stub, start_column, end_column) {
  for (i=start_column; i <= end_column; i++){
    var item = $(id_stub+'_td_'+i);
    if (item){
      new Effect.Fade(item,{duration: 1.5});
    }
  }

  // Fade the TR Element - Needed for alternating row comparisons to be correct
  new Effect.Fade(id_stub+'_tr',{duration: 1.5});

}

// This is used because IE can't pulsate a TR element, only TD elements
function pulsate_row(id_stub, start_column, end_column) {
  for (i=start_column; i <= end_column; i++){
    var item = $(id_stub+'_td_'+i);
    if (item){
      new Effect.Pulsate(item,{pulses: 3, duration: 1.5});
    }
  }
}

function validateDate(field) {
  var regEx = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
  if ((field.value.match(regEx)) && (field.value!='')) {
    return true;
  }
  else {
    alert('Please enter a valid date in month, day, year format using slashes, hyphens or\nperiods to separate the values.\n\nEx: mm/dd/yyyy, mm-dd-yyyy, mm.dd.yyyy');
    field.focus();
    return false;
  }
}

function selectAll() {
    var checkBoxes = document.getElementsByTagName('input');
    for (i = 0; i < checkBoxes.length; i++) {
            checkBoxes[i].checked = true; // this checks all the boxes
    }
}

function unselectAll() {
    var checkBoxes = document.getElementsByTagName('input');
    for (i = 0; i < checkBoxes.length; i++) {
            checkBoxes[i].checked = false; // this checks all the boxes
    }
}
