﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min-vsdoc.js" />

var fieldsets;
var currentIndex;
var formPager;
var numberOfPages;
var previousSection;
var nextSection;
var formPageInfo;

$(function() {
    fieldsets = $("#mainContent fieldset");
    formPager = $(".formPager");
    previousSection = $("li.previousSection", formPager).hide();
    nextSection = $("li.nextSection", formPager);
    formPageInfo = $("#formPageInfo");
    numberOfPages = fieldsets.length;
    formPageInfo.text("1 of " + numberOfPages);
    currentIndex = 0;

    fieldsets.filter(":gt(0)").hide();

    $("li.nextSection", formPager).click(function() {
        ChangeListingPage(currentIndex + 1);
    });
});

function ChangeListingPage(pageIndex) {
    currentIndex = pageIndex;
    formPageInfo.text((currentIndex + 1) + " of " + numberOfPages);

    fieldsets.hide().filter(":eq(" + currentIndex + ")").show();

    if (currentIndex > 0) {
        previousSection.unbind("click").click(function() {
            ChangeListingPage(currentIndex - 1);
        }).show();
        nextSection.css("border-left", "solid 1px #D9D7D0");
    }
    else {
        previousSection.unbind("click").hide();
        nextSection.css("border-left", "none");
    }

    if (currentIndex < numberOfPages - 1) {
        nextSection.unbind("click").click(function() {
            ChangeListingPage(currentIndex + 1);
        }).show();
    }
    else {
        nextSection.unbind("click").hide();
    }
}
