var number = top.number;
var page = top.page;
var maxPageNumber = top.maxYP01;
var section = top.section;
var minPageNumber = 1;
var fsw = 0;
var atVal = top.atkOff;

// - tree.htm functions
function styles() {
var size;
if (top.window.screen.AvailWidth < 900) {
	size = top.links800;
}
else {
	size = top.links;
}
	top.select.sectionList.document.writeln("<STYLE TYPE='text/css'>");
	top.select.sectionList.document.writeln(".link {  font-family: 'Verdana', Arial, Helvetica, sans-serif; font-size: " + size + "pt; font-style: normal; line-height: normal; text-decoration: none;}");
//	top.select.sectionList.document.writeln(".active {  font-family: 'Verdana', Arial, Helvetica, sans-serif; font-size: " + size + "pt; font-style: normal; line-height: normal; color: " + activeColor + "; text-decoration: none;}");
	top.select.sectionList.document.writeln(".title {font-family: 'Arial', Helvetica, sans-serif; font-size: 10pt; font-style: bold; line-height: normal; color: "+ top.guiTextColor +"; text-decoration: none;}");
	top.select.sectionList.document.writeln(".body { overflow-x:hidden; background-color: #" + top.color + " }");
	top.select.sectionList.document.writeln("</STYLE>");
}

var newSection = "cover";
var guides = 1;
var activeSubsection = "";

function moveToTopDelay(number, section) {
	if(navigator.appName!="Netscape") {
		 setTimeout("top.select.sectionList.window.location='#" + section + "Anchor" + number + "'",75);
	}
}

function makeSubsectionActive(subsection) {
	activeSubsection = subsection;
}

function testForColor(subsection) {
	if(subsection == activeSubsection) { return top.activeLinksColor }
	else { return top.linksColor; }
}

var guides = "0"
function setGuides(guideNumber) {
	guides = guideNumber
}
// - end tree.htm functions

function setATVal(num)
{
	atVal = num;
}
function isSinglePageView()
{
	return true;
}

function isDoubleTruck(pageNumber)
{ var pg = pageNumber;
  if (pageNumber%2==1) //is odd
	pg = pg - 1;
	for(i = 0; i < top.doubleTrucks.length; i++)
	{
		if(top.doubleTrucks[i] == pg)
			return true;
	}
 return false;
}


var visitedSpots = new Array();
var numSpots = 0;
var maxNumSpots = 10;
var isNav4, isIE4;
var lastSearchIndex = 0;
var lastSearchValue = escape('null');
var expansionList = new Array();

function trackAdvertiser(advertiser)
{
   if(ActivTrakCheck())
	top.trak.location.href="http://"+top.traip+"?book="+top.trakVal+"&type=advertiser&text="+advertiser;
}

storeSpot('cover', 1, 1, 0, 0);
if (parseInt(navigator.appVersion.charAt(0)) >= 4) { 
	isNav4 = (navigator.appName == "Netscape") ? true : false;  
	isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;}

var loc = "";

function storeSpot(section, page, maxPage, x, y)
{	//alert("store spot: " + section + ",pg. " + page + ",x: " + x + ",y: " + y); 
	deactivateButton("forward");

   if(ActivTrakCheck())
{
 	loc = "http://"+top.traip+"?book="+top.trakVal+"&type=pageview&text="+section+"_"+page;
       setTimeout('setTrakLocation()', 500);
}
  if (numSpots != 0)
	activateButton("back");
   else
	deactivateButton("back");
   var spot = new Array(section, page, maxPage, x, y);
	if (numSpots < maxNumSpots) {
		var howMany = maxNumSpots - numSpots;
		if (visitedSpots.length >= maxNumSpots) 
			visitedSpots = spliceArray(visitedSpots, numSpots, howMany, spot);
		else
			visitedSpots[numSpots] = spot;
		++numSpots;
		}
	else {
		shiftVisitedArray();
		visitedSpots[numSpots-1] = spot; 
		}
	
//displayArray();
}

var backButtonIsActive = false;
var forwardButtonIsActive = false;

function activateButton(typeOfButton) {
// alert("trying to activate the " + typeOfButton);
	if (typeOfButton == "back") {
		if (!backButtonIsActive) 
		   top.logo.activateBack();
		   backButtonIsActive = true;
	   }
	else {
		if (!forwardButtonIsActive)
		   top.logo.activateForward();
		   forwardButtonIsActive = true;
	   }
}

function deactivateButton(typeOfButton) {
//alert("trying to deactivate the " + typeOfButton);
	if (typeOfButton == "back") {
		if (backButtonIsActive) 
		   top.logo.deactivateBack();
		   backButtonIsActive = false;
	   }
	else {
		if (forwardButtonIsActive)
		   top.logo.deactivateForward();
		   forwardButtonIsActive = false;
	   }

}

function setTrakLocation()
{
	top.trak2.location.href=loc;
}

function shiftVisitedArray()
{ 
 for (i = 0; i < numSpots -1; i++) {
	visitedSpots[i] = visitedSpots[i+1];
	}

}

function spliceArray(arrayObject, start, count, element)
{
var tempArray = new Array();
for (var i = 0; i < start; i++)
   tempArray[i] = arrayObject[i];
var n = start;
for (var i = start + count; i < arrayObject.length; i++) {
   tempArray[n] = arrayObject[i]; 
   n++;
   }
tempArray[n] = element;
return tempArray;
} 

function recallSpot()
{  	if (numSpots == 2) {
	   deactivateButton("back");
	   } 
	if (numSpots > 0) {
	   --numSpots;
	   return visitedSpots[numSpots-1];
	   }
}

function recallForwardSpot()
{ //	alert("numSpots: " + numSpots + ", array length: " + visitedSpots.length);
	if (numSpots >= (visitedSpots.length -1))
	   deactivateButton("forward");
      ++numSpots;
	return visitedSpots[numSpots-1];  
}

function displayArray()
{ var theString = "Length of Array: " + visitedSpots.length + ", numSpots = " + numSpots + "\n";
for(i = 0; i < visitedSpots.length; i++) {
	var tmp = visitedSpots[i]; 
	 theString = theString + "index: " + i + " pg. no. " + tmp[1] + " x: " + tmp[3] + ", y: " + tmp[4] + "\n";
	}
alert(theString);  
}

function goBack() 
{ //  alert("NumSpots at start of 'goBack': " + numSpots);
//displayArray();
	activateButton("forward");
	var theSpot = recallSpot();
	var min = minPageFor(theSpot[0]);
	//alert("The spots: " + theSpot[0] + ", " + theSpot[1] + ", " + theSpot[2] + ", " + theSpot[3] + ", " + theSpot[4]);
	openNewPage(theSpot[0],theSpot[1],theSpot[2],min,theSpot[3],theSpot[4],false);
}

function goForward() 
{ //displayArray();
	activateButton("back");
	var theSpot = recallForwardSpot();
	var min = minPageFor(theSpot[0]);	
	openNewPage(theSpot[0],theSpot[1],theSpot[2],min,theSpot[3],theSpot[4],false);
}

function recordSpot() {
	number = getPage();
	section = getSection();
	maxpage = getMaxPageNumber();
//alert("record spot, x: " + cachedX + ", y: " + cachedY);
	storeSpot(section, number, maxpage, cachedX, cachedY);
	setWindowTitle(section, number)
	}

function shouldShowNoTab(aSection) {
	var notab = false;
	for(i = 0; i < top.noTabSections.length; i++)
	{
		if(top.noTabSections[i] == aSection)
			notab = true;
	}
 return notab;
}

function shouldNotShowNavPageNo(aSection) {
	var should;

	switch (aSection) {
		case 'coupon':
		case 'couponindex':
			should = true;
			break;
		default:
			should = false;
			break;
	}
   return should;
}

function shouldShowPageNo(aSection) {
	var should;

	switch (aSection) {
		case 'cover':
		case 'extras':
			should = false;
			break;
		default:
			should = true;
			break;
	}
   return should;
}

function GUInameFor(aSection) {
   var name;
	switch (aSection) {
		case 'yp01': 
			name = top.ypSection[0][0];
			break;
		case 'yp02': 
			name = top.ypSection[1][0];
			break;
		case 'yp03': 
			name = top.ypSection[2][0];
			break;
		case 'yp04': 
			name = top.ypSection[3][0];
			break;

		case 'b01':
			name = top.whiteSection[0][0];
			break;
		case 'w01': 
			name = 'White Pages';
			break;
		case 'w02': 
			name = top.whiteSection[2][0];
			break;
		case 'w03': 
			name = top.whiteSection[3][0];
			break;
		case 'w04': 
			name = top.whiteSection[4][0];
			break;
		case 'w05': 
			name = top.whiteSection[5][0];
			break;
		case 'w06': 
			name = top.whiteSection[6][0];
			break;
		case 'w07': 
			name = top.whiteSection[7][0];
			break;
		case 'w08': 
			name = top.whiteSection[8][0];
			break;
		case 'w09': 
			name = top.whiteSection[9][0];
			break;
		case 'w10': 
			name = top.whiteSection[10][0];
			break;
		case 'w11': 
			name = top.whiteSection[11][0];
			break;
		case 'w12': 
			name = top.whiteSection[12][0];
			break;
		case 'w13': 
			name = top.whiteSection[13][0];
			break;
		case 'w14': 
			name = top.whiteSection[14][0];
			break;
		case 'w15': 
			name = top.whiteSection[15][0];
			break;
		case 'w16': 
			name = top.whiteSection[16][0];
			break;
		case 'w17': 
			name = top.whiteSection[17][0];
			break;
		case 'w18': 
			name = top.whiteSection[18][0];
			break;
		case 'w19': 
			name = top.whiteSection[19][0];
			break;
		case 'w20': 
			name = top.whiteSection[20][0];
			break;

		case 'index':
			name = top.indexSection[0][0];
			break;
		case 'index01':
			name = top.indexSection[1][0];
			break;
		case 'index02':
			name = top.indexSection[2][0];
			break;
		case 'index03':
			name = top.indexSection[3][0];
			break;

		case 'tourism':
			name = top.tourismSection[0][0];
			break;
		case 'comm':
			name = top.commSection[0][0];
			break;
		case 'brand':
			name = top.brandSection[0][0];
			break;
		case 'bylaws':
			name = top.bylawsSection[0][0];
			break;
		case 'coupon':
			name = top.couponSection[0][0];
			break;
		case 'cust':
			name = top.custSection[0][0];
			break;
		case 'gov':
			name = top.govSection[0][0];
			break;
		case 'tdd':
			name = top.tddSection[0][0];
			break;
		case 'emerg':
			name = "Emergency Numbers";
			break;
		case 'featured':
			name = 'Featured Advertisers';
			break;
		case 'cover':
			name = 'Front Cover';
			break;
		case 'extras':
			name = 'Find A Heading';
			break;
		default:
			name = '';
		break;
	}
   return name;
}

function maxPageFor(aSection) {//alert("inside maxPageFor, section is: " = aSection);
   var maxPage;
	switch (aSection) {
		case 'yp01': 
			maxPage = top.maxYP01;
			break;
		case 'yp02': 
			maxPage = top.maxYp02;
			break;
		case 'yp03': 
			maxPage = top.maxYp03;
			break;
		case 'yp04': 
			maxPage = top.maxYp04;
			break;

		case 'tourism':
			maxPage = top.maxTourism;
			break;
		case 'comm':
			maxPage = top.maxComm;
			break;
		case 'brand': 
			maxPage = top.maxBrand;
			break;
		case 'bylaws': 
			maxPage = top.maxBylaws;
			break;					
		case 'index':
			maxPage = top.maxIndex;
			break;
		case 'coupon':
			maxPage = top.maxCoupon;
			break;
		case 'cust':
			maxPage = top.maxCust;
			break;
		case 'emerg':
			maxPage = top.maxEmerg;
			break;
		case 'gov':
			maxPage = top.maxGov;
			break;
		case 'tdd': 
			maxPage = top.maxTdd;
			break;
		case 'featured':
			maxPage = top.maxFeatured;
			break;

		case 'b01':
			maxPage = top.maxB01;
			break;
		case 'w01':
			maxPage = top.maxW01;
			break;
		case 'w02':
			maxPage = top.maxW02;
			break;
		case 'w03':
			maxPage = top.maxW03;
			break;
		case 'w04':
			maxPage = top.maxW04;
			break;
		case 'w05':
			maxPage = top.maxW05;
			break;
		case 'w06':
			maxPage = top.maxW06;
			break;
		case 'w07':
			maxPage = top.maxW07;
			break;
		case 'w08':
			maxPage = top.maxW08;
			break;
		case 'w09':
			maxPage = top.maxW09;
			break;
		case 'w10':
			maxPage = top.maxW10;
			break;
		case 'w11':
			maxPage = top.maxW11;
			break;
		case 'w12':
			maxPage = top.maxW12;
			break;
		case 'w13':
			maxPage = top.maxW13;
			break;
		case 'w14':
			maxPage = top.maxW14;
			break;
		case 'w15':
			maxPage = top.maxW15;
			break;
		case 'w16':
			maxPage = top.maxW16;
			break;
		case 'w17':
			maxPage = top.maxW17;
			break;
		case 'w18':
			maxPage = top.maxW18;
			break;
		case 'w19':
			maxPage = top.maxW19;
			break;
		case 'w20':
			maxPage = top.maxW20;
			break;

		case 'cover':
			maxPage = 1;
			break;
		case 'extras':
			maxPage = 1;
			break;
		default:
			maxPage = top.maxYP01;
		break;
	}
   return maxPage;
}

function minPageFor(aSection) {//alert("inside minPageFor, section is: " = aSection);
   var minPage;
	switch (aSection) {
		case 'yp01': 
			minPage = top.minYP01;
			break;
		case 'yp02': 
			minPage = top.minYp02;
			break;
		case 'yp03': 
			minPage = top.minYp03;
			break;
		case 'yp04': 
			minPage = top.minYp04;
			break;

		case 'tourism':
			minPage = top.minTourism;
			break;
		case 'comm':
			minPage = top.minComm;
			break;
		case 'brand': 
			minPage = top.minBrand;
			break;
		case 'bylaws': 
			minPage = top.minBylaws;
			break;				
		case 'index':
			minPage = top.minIndex;
			break;
		case 'coupon':
			minPage = top.minCoupon;
			break;
		case 'cust':
			minPage = top.minCust;
			break;
		case 'emerg':
			minPage = top.minEmerg;
			break;
		case 'gov':
			minPage = top.minGov;
			break;
		case 'tdd': 
			minPage = top.minTdd;
			break;
		case 'featured':
			minPage = top.minFeatured;
			break;

		case 'b01':
			minPage = top.minB01;
			break;
		case 'w01':
			minPage = top.minW01;
			break;
		case 'w02':
			minPage = top.minW02;
			break;
		case 'w03':
			minPage = top.minW03;
			break;
		case 'w04':
			minPage = top.minW04;
			break;
		case 'w05':
			minPage = top.minW05;
			break;
		case 'w06':
			minPage = top.minW06;
			break;
		case 'w07':
			minPage = top.minW07;
			break;
		case 'w08':
			minPage = top.minW08;
			break;
		case 'w09':
			minPage = top.minW09;
			break;
		case 'w10':
			minPage = top.minW10;
			break;
		case 'w11':
			minPage = top.minW11;
			break;
		case 'w12':
			minPage = top.minW12;
			break;
		case 'w13':
			minPage = top.minW13;
			break;
		case 'w14':
			minPage = top.minW14;
			break;
		case 'w15':
			minPage = top.minW15;
			break;
		case 'w16':
			minPage = top.minW16;
			break;
		case 'w17':
			minPage = top.minW17;
			break;
		case 'w18':
			minPage = top.minW18;
			break;
		case 'w19':
			minPage = top.minW19;
			break;
		case 'w20':
			minPage = top.minW20;
			break;

		case 'cover':
			minPage = 1;
			break;
		case 'extras':
			minPage = 1;
			break;
		default:
			minPage = top.minYP01;
		break;
	}
   return minPage;
}

function colorFor(section) 
{ var color = top.headingcolor;
switch (section) {
	case 'gov': 
		color = top.secColor1;
		break;
	case 'b01': 
		color = top.secColor2;
		break;
	case 'w01': 
		color = top.secColor3;
		break;
	case 'w02': 
		color = top.secColor4;
		break;
	case 'w03': 
		color = top.secColor5;
		break;
	case 'w04': 
		color = top.secColor6;
		break;
	case 'w05': 
		color = top.secColor7;
		break;
	case 'w06': 
		color = top.secColor8;
		break;
	case 'w07': 
		color = top.secColor9;
		break;
	case 'w08': 
		color = top.secColor10;
		break;
	case 'w09': 
		color = top.secColor11;
		break;
	case 'w10': 
		color = top.secColor12;
		break;
	case 'w11': 
		color = top.secColor13;
		break;
	case 'w12': 
		color = top.secColor14;
		break;
	case 'w13': 
		color = top.secColor15;
		break;
	case 'w14': 
		color = top.secColor16;
		break;
	case 'yp02': 
		color = top.secColor10;
		break;
	case 'yp03': 
		color = top.secColor11;
		break;
	case 'yp04': 
		color = top.secColor12;
		break;

		default:		
		color = top.headingColor;
	}
return color;

}

function oP() {
		return iP( "A");
}	
function setCouponPageNo(pageNo) {

	if (pageNo < (top.numCouponIndex + top.minCoupon)) {
		if (pageNo <=3) {
			pg = "";
			for (i = 0; i < pageNo; i++)
			pg = pg + "I";
		}
		if (pageNo == 4) {
			pg = "";
			pg = "IV";
		}
		if (pageNo == 5) {
			pg = "";
			pg = "V";
		}
		if (pageNo > 5 && pageNo <= 8) {
			pg = "V";
			for (i = 0; i < (pageNo - 5); i++)
			pg = pg + "I";
		}
		if (pageNo == 9) {
			pg = "IX"
		}
		if (pageNo == 10) {
			pg = "X"
		}
	}
	else { 
		if (top.doubleCoupon) {
			pg = (pageNo - top.numCouponIndex - top.minCoupon +2)/2;
			if (pageNo%2 != 1)
				pg = parseInt(pg+"") + "B";
			}
		else 
			pg = pageNo - top.numCouponIndex - top.minCoupon +1;
	}
return pg;
}

function setWindowTitle(section, number) 
{ // alert("setWindowTitle");
  var theTitle = top.title;
	if (number != 0) {
   		theTitle = theTitle + " - " + GUInameFor(section);
  		if (shouldShowPageNo(section)) {
		var pgNo = parseInt(number);
		if (section == "coupon")
			pgNo = setCouponPageNo(pgNo);
		if (section == "dining")
			theTitle = theTitle + ", p.D" + pgNo;
		else
			theTitle = theTitle + ", p." + pgNo;
		}
	}
   top.document.title = theTitle;
}

function openSection(theSection,Mypage)
{
cachedX = 0;
cachedY = 0;
currentPage = Mypage;
currentSection = theSection;
var maxPg = maxPageFor(theSection);
setFrames(maxPg);
}

function openPage(section, number, maxPage, minPage)
{

openNewPage(section, number, maxPage, minPage, 0, 0, true);
}

function openNewPage(section, number, maxPage, minPage, x, y, shouldStoreSpot)
{ 
	if (number == 0 && section != "extras") {
		section = 'featured';
	}
 	cachedX = x;
	cachedY = y;
//	if (shouldStoreSpot)
//	   n = 1;
//	else
	  var n = 0;
	setSection(section);
	setPage(number);
	setMaxPage(maxPage);
	setMinPage(minPage);

	var rootPath = top.pages.location.href.substring(0,top.pages.location.href.lastIndexOf("data")+5);

//alert("PATH in openNewPage: " + rootPath+"svg/"+section+"/page.htm?page="+number+"%26x="+x+"%26y="+y+"%26s="+section+"%26n="+n);
		top.pages.location.href=(rootPath+"svg/"+section+"/page.htm?page="+number+"%26x="+x+"%26y="+y+"%26s="+section+"%26n="+n);
  		top.tabs.location.href=(rootPath+"tab.htm");
		setWindowTitle(section, number);
	if (shouldStoreSpot)
		storeSpot(section, number, maxPage, cachedX, cachedY);

}

function openPageFromSVG(section, number, maxPage) 
{
openNewPageFromSVG(section, number, maxPage, 0, 0, true);
}

function openNewPageFromSVG(section, number, maxPage, x, y, shouldStoreSpot)
{
	cachedX = x;
	cachedY = y;
	setSection(section);
	setPage(number);
	setMaxPage(maxPage);
	setMinPage(minPage);
	top.pages.location.href=(top.pages.location.href+"/../../"+section+"/page.htm?page="+number+"%26x="+x+"%26y="+y+"%26s="+section+"%26n=0");
	setWindowTitle(section, number);
	if (shouldStoreSpot)
		storeSpot(section, number, maxPage, cachedX, cachedY);
}

var cachedX =0;
var cachedY =0;

function setAndGoToPage(page)
{ 
	var newNumber = page;
	var newPage = newNumber;
	var x = 0;
	var y = 0;
	if(newPage.length > 4)
	{ 
		newPage = newPage.substring(0, 4);
		while(newPage.charAt(0) == '0') 
			newPage= newPage.substring(1, newPage.length);
		var xString = newNumber.substring(5, 8); 
		while(xString.charAt(0) == '0' && xString.length > 1) 
			xString = xString.substring(1, xString.length); 
		var yString = newNumber.substring(9);
		while(yString.charAt(0) == '0' && yString.length > 1) 
			yString = yString.substring(1, yString.length); 
		x = parseInt(xString);
		y = parseInt(yString); 
		if(newNumber.substring(4, 5) == 'n')	
			x  = 0-x; 
		if(newNumber.substring(8, 9) == 'n')	
			y = 0-y;
	}
	
	openNewPage("yp01", newPage, top.maxYP01, top.minYP01, x, y, true);
}

function setAndGoToPageFromSVG(page)
{ 
	var newNumber = page;
	var newPage = newNumber;
	var x = 0;
	var y = 0;
	if(newPage.length > 4)
	{
		newPage = newPage.substring(0, 4);
		while(newPage.charAt(0) == '0') 
			newPage= newPage.substring(1, newPage.length);
		var xString = newNumber.substring(5, 8); 
		while(xString.charAt(0) == '0' && xString.length > 1) 
			xString = xString.substring(1, xString.length); 
		var yString = newNumber.substring(9);
		while(yString.charAt(0) == '0' && yString.length > 1) 
			yString = yString.substring(1, yString.length); 
		x = parseInt(xString);
		y = parseInt(yString); 
		if(newNumber.substring(4, 5) == 'n')	
			x  = 0-x; 
		if(newNumber.substring(8, 9) == 'n')	
			y = 0-y;
	}
	
	openNewPageFromSVG("yp01", newPage, maxYP01, minYP01, x, y, true);
}


function setFrames(maxPage)
{
	setSection(currentSection);
	setPage(currentPage);
	setMaxPage(maxPage);

	top.pages.location.href=(top.pages.location.href.substring(0,top.pages.location.href.indexOf("/data/")+6)+"svg/"+currentSection +"/page.htm?page="+currentPage+"%26x="+cachedX+"%26y="+cachedY+"%26s="+currentSection+"%26n=0");
	top.tabs.location.href=(top.pages.location.href.substring(0,top.pages.location.href.indexOf("/data/")+6)+"tab.htm");

	setWindowTitle(currentSection, currentPage);
	storeSpot(currentSection, currentPage, maxPage, 0, 0);

}

function openTabHeading(letter)
{
	var theSection = getSection();
	

}

function ActivTrakCheck() {
	var value = false;
	
	if(top.trak != null && navigator.appVersion.indexOf("Mac") == -1 && navigator.appName != "Netscape" && atVal == 0)
		value = true;
		
	return value;
}

function setPage(newPage)       {  page = newPage; }
function setSection(newSection) { section = newSection; }
function setMaxPage(maxPage)    { maxPageNumber = maxPage; }
function setMinPage(minPage)    { minPageNumber = minPage; }
function setFsw(fswValue)	  { fsw = fswValue; }

function getPage()		  { return page; }
function getSection()		  { return section; }
function getMaxPageNumber()	  { return maxPageNumber; }
function getMinPageNumber()	  { return minPageNumber; }
function getFsw()			  { return fsw; }
