// Application page navigation
//
//
// See: "CHANGE HERE" below
//

var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
     var currentLength = this.length;
     for (var i = 0; i < arguments.length; i++) {
        this[currentLength + i] = arguments[i];
     }
     return this.length;
  };
}

// Setup list of pageID values.
var pagesArray = new Array();

// CHANGE HERE:
// CHANGE THIS LIST IF NEEDED
pagesArray.push('92001');
pagesArray.push('92002');
pagesArray.push('92003');
pagesArray.push('92004');
pagesArray.push('92005');
pagesArray.push('11655');
pagesArray.push('12731');
pagesArray.push('92008');
pagesArray.push('12075');
pagesArray.push('12689');
pagesArray.push('9292');
pagesArray.push('11443');
pagesArray.push('11579');
pagesArray.push('11807');
pagesArray.push('11867');
pagesArray.push('11884');
pagesArray.push('13618');
pagesArray.push('14152');
pagesArray.push('14155');
pagesArray.push('14397');
pagesArray.push('100069');
pagesArray.push('100100');
pagesArray.push('14631');
pagesArray.push('14872');
pagesArray.push('14718');
// 
// END 

// Function to search pagesArray for current page ID's index.
// Returns -1 if not found.
//
function  findPageIndex(pageId)
{
	var i;
	for (i =0; i <= pagesArray.length - 1; i++) 
	{
		if (pagesArray[i] == pageId)
		{
			// Found a match, so
			// Return the current index
			return i; 
		}
	}
	
	// If we got here, there is no match, so
	// return failure code
	return -1; 
}

// Function to generate URL for a page based on the page index
// 
function generateUrlFromId(pageIndex)
{
	return "applications_" + pagesArray[pageIndex] + ".html";
	//return "apptest.html?application_" + pagesArray[pageIndex] + ".html";
}

// Setup Regexp to search URL for current page name.
//
var re = /applications_(.+)\.html/;
var m = re.exec(window.location.href);

// If there is a match, generate the nav menu.
//
if ( (m != null) && (findPageIndex(m[1]) != -1) )
{
	var currentPageIndex = findPageIndex(m[1]);
	var nextPageIndex = (pagesArray[currentPageIndex + 1] != null) ? currentPageIndex + 1 : -1;
	var prevPageIndex = (pagesArray[currentPageIndex - 1] != null) ? currentPageIndex - 1 : -1;
	
	var nextPageButtonHtml = '';
	var prevPageButtonHtml = '';
	
	// Generate HTML for the "next page button"
	//
	if ( nextPageIndex != -1)
	{
		nextPageButtonHtml = '<a href="' + generateUrlFromId(nextPageIndex) +'">';
		nextPageButtonHtml += '<img src="images/applications-nav-next-on.gif" border="0">';
		nextPageButtonHtml += '</a>';
	} else
	{
		nextPageButtonHtml = '<img src="images/applications-nav-next-off.gif" border="0">';
	}
	
	// Generate HTML for the "prev page button"
	//
	if ( prevPageIndex != -1)
	{
		prevPageButtonHtml = '<a href="' + generateUrlFromId(prevPageIndex) +'">';
		prevPageButtonHtml += '<img src="images/applications-nav-prev-on.gif" border="0">';
		prevPageButtonHtml += '</a>';
	} else
	{
		prevPageButtonHtml = '<img src="images/applications-nav-prev-off.gif" border="0">';
	}
	
	document.write('<table width="100%">');
	document.write('<tr><td align="left" width="50%">');
	document.write(prevPageButtonHtml);
	document.write('</td><td align="right">');
	document.write(nextPageButtonHtml);
	document.write('</td></tr></table>');;
}
	