/* ------------------------------------------------------------------------------------------------
*  This is the Bike Function Javascript.
*  The Bike Function is to set up the initial page which lists the counties and the pages for download.
*  The variables {a b c d & j} {1 and 2} are simply for string variable simplicity.
*  The 2 arrays are the most important part of this function as they hold the name and page number indentifiers
*  The BPMs array is for names
*  The twoBack array is to designate when either 1 or 2 files have been used to display the back.
*  The split back is a result of, when the map was scanned unfolded half the image was upside down.
*  I cut the image in half manually using CorelPaint, though almost any graphics package would do.
*  This Javascript is called by the GISBikeMaps.html file.
   ------------------------------------------------------------------------------------------------ */ 

	// * Function used to open up page 
	// * Called before makeTitle()
	function beginFrame()
	{
		document.writeln('');
		document.writeln('<TABLE border="0" cellSpacing="0" cellPadding="3" width="745" bgColor="#ffffff" border="0">');
			document.writeln('<TR>');
		document.writeln('<!-- Header Text -->');
				document.writeln('<TD colspan="3" align="center" vAlign="center" height="50" width="740">');
	}

	// * Non-GIS Frame Title
	// * THe GIS Frame is the Frame work provided by the IT dept. (look and feel)
	// * This is simply a String for which we want to express the first letter.
	// * Since it is called after beginFrame() it must be followed by a simple document.writeln('</td></tr>') statement.
	function makeTitle(gTitle)
	{
		firstLetter = gTitle.substr(0,1);
		remainder = gTitle.substr(1);

		document.write('<span class=Title1>',firstLetter,'</span><span class=Title1>',remainder,'</span>');
	}

	// * Non-GIS Frame Title
	// * THe GIS Frame is the Frame work provided by the IT dept. (look and feel)
	// * This is simply a String for which we want to express the first letter.
	// * Since it is called after beginFrame() it must be followed by a simple document.writeln('</td></tr>') statement.
	function makeTitleThumb(gTitle)
	{
		arrNum = -1;
		for(i=0;i<BPMs.length;i++) { if(gTitle==BPMs[i][2]) { arrNum=i; } } // * Gets the appropriate record

		if(arrNum==-1) gTitle = 'No Such Map';

		firstLetter = gTitle.substr(0,1);
		remainder = gTitle.substr(1);

		document.write('<span class=Title1>',firstLetter,'</span><span class=Title1>',remainder,'</span>');

	}

	// * Grabs any variables from the URL
	// * THis function currently does not support more than 1 variable.
	function checkURL()
	{
		strURL = new String(window.location);
		startOfVars = strURL.indexOf('?');
		strVars = strURL.substr(startOfVars+1);

		varSep = strVars.indexOf('=');
		tVar = strVars.substr(0,varSep);
		tValue = strVars.substr(varSep+1);
		tValue = tValue.replace(/%20/g, ' '); // * Replace %20 with a space.  happened in URL conversion.

		
		listType = new Array();
		listType[0] = [tVar, tValue];

		return listType;
	}

	// * Paragraph group writing function
	function paraWrite(pArray)
	{
		for(i=0;i<pArray.length;i++)
		{
			document.writeln('<span class="',pArray[i][0],'">',pArray[i][1],'</span><br><br>');
		}
	}

	// * A small functions to quickly link a single file to its appropriate place on the download server.
	// * Specific to Bikemaps.
	function dlLink(filename)
	{
		var FTPPath = "http://dotw-xfer01.dot.state.nc.us/gisdot/";
		DataPath= FTPPath + "DOTBikeMaps/";

		link_start = '<a href="' + DataPath;
		link_start += '/';
		link_start += filename + '">' + filename + '</a>';

		document.writeln(link_start);
	}

	// * Links to associated Pages
	function jumpLinks(lArray)
	{
		document.writeln('<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="4" WIDTH="720">');
		for(i=0;i<lArray.length;i++)
		{
			document.writeln('<TR class="text2b"><td style="padding-left:35px;">',lArray[i][1].link(lArray[i][0]),'</td></tr>');
			if(lArray[i][2] != '')
				document.writeln('<TR class="text2"><td style="padding-left:55px;">',lArray[i][2],'</td></tr>');
		}
		document.writeln('</table>');
	}

	// * function to create the Bike Map List.from GISBikeMaps.html
	function Bike() {
		var FTPPath = "http://dotw-xfer01.dot.state.nc.us/gisdot/"
		DataPath= FTPPath+"DOTBikeMaps/"; //  BikeMaps/";
		var DataType=".jpg"; var DataType2=".pdf";
		var nameMap; var j; var lr = 1; var a1, a2;
	
		//First Part for top line of entry (Name, Year, Year)
		for(i=0;i<BPMs.length;i++){
	//------------------------------------------------
			link_start = 'href="'+DataPath;
			if(BPMs[i][0]=='City') link_start += '_';
	
			link_start += BPMs[i][2].replace(/ /g, '');
			link_start += '/';
			if(BPMs[i][2]=='Lake Norman Maps')
				link_start += 'Lake Norman Rds6'.replace(/ /g, '');
			else
				link_start += BPMs[i][2].toLowerCase().replace(/ /g, '');
	
				Dtype = DataType+'"';
				Dtype2 = DataType2+'"';
			JPGfront = link_start+'-front-sm'+Dtype; 
			JPGback_x = link_start+'-back-sm'+Dtype; 
			JPGback_1 = link_start+'-back-sm1'+Dtype; 
			JPGback_2 = link_start+'-back-sm2'+Dtype;
	
			PDFfront = link_start+'-front'+Dtype2;
			PDFback = link_start+'-back'+Dtype2;
			PDFfull = link_start+Dtype2;
	
	//------------------------------------------------
			document.writeln('<tr align="left"');
			if(i%2==1) // Even
				document.writeln(' bgcolor="#BFD9ED"');
			document.writeln('>');
				document.writeln('<td width=50>&nbsp;</td>'); 
				if(BPMs[i][9]==1)
					document.writeln('<td align="left" width=100> <a class="tableText" href="Thumbs.html?thumb=',BPMs[i][2],'">',BPMs[i][1],'</a></td>');
				else
					document.writeln('<td align="left" width=100> <span class="tableText">',BPMs[i][1],'</span></td>');
				document.writeln('<td width=50>&nbsp;</td>'); 
			if(BPMs[i][0]=='Other' && BPMs[i][2]=='Lake Norman Maps')
			{
				var Title="Bicycle and Pedestrian Maps";
				var FullName = ["Lake Norman Bike Route Proposed"];
				var DirPath = ["LakeNormanMaps"];
				var FileName = ["LakeNormanRds6"];
				var FileSizePDF = ["2.2 MB"];
				var FileSizeJPG = ["4.6 MB"];
	
				//document.writeln('<th colspan=10 align="left"><a href="javascript:OtherThumb(\'',FullName[0],'\')">',FullName[0],'</a></th>');
				if(FileSizeJPG[0]!="0") 
					document.writeln('<td align="left" colspan="3"> <a class="tableText" href="',DataPath,DirPath[0],'/',FileName[0].toLowerCase(),DataType,'">.jpg (',FileSizeJPG[0],')</a></td>');			//OtherMaps();
				document.writeln('<td bgcolor="#7CACD0" width="15">&nbsp;</td>');  // * Spacer
				document.writeln('<td align="left" colspan="3"> <a class="tableText" href="',DataPath,DirPath[0],'/',FileName[0].toLowerCase(),DataType2,'">.pdf (',FileSizePDF[0],')</a></td>');
			}
			else if(BPMs[i][0]=='Other' && BPMs[i][2]=='Dare')
			{
				var Title="Bicycle and Pedestrian Maps";
				var FullName = ["Dare County Maps"];
				var DirPath = ["Dare"];
				var FileName = ["Dare"];
				var FileSizePDF = ["3.5 MB", "3.8 MB", "4.0 MB"];
				var FileSizeJPG = ["2.0 MB", "2.6 MB", "1.9 MB"];
				var FileNameD = ["Welcome_Locator_Map","Maps_1-5_Corolla-Nags_Head","Maps_6_7_Hatteras_Manteo"];
	
				//document.writeln('<th colspan=10 align="left"><a href="javascript:OtherThumb(\'',FullName[0],'\')">',FullName[0],'</a></th>');
				//if(FileSizeJPG[0]!="0") 
				document.writeln('<td align="left" colspan="3">');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[0],DataType,'">Welcome and Locator .jpg (',FileSizeJPG[0],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[1],DataType,'">Maps 1-5 Corolla to Nags Head .jpg (',FileSizeJPG[1],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[2],DataType,'">Maps 6&amp;7 Hatteras &amp; Manteo .jpg (',FileSizeJPG[2],')</a>');
					document.writeln('</td>');
				document.writeln('<td bgcolor="#7CACD0" width="15">&nbsp;</td>');  // * Spacer
				document.writeln('<td align="left" colspan="3">');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[0],DataType2,'">Welcome and Locator .pdf (',FileSizePDF[0],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[1],DataType2,'">Maps 1-5 Corolla to Nags Head .pdf (',FileSizePDF[1],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[2],DataType2,'">Maps 6&amp;7 Hatteras &amp; Manteo .pdf (',FileSizePDF[2],')</a>');
					document.writeln('</td>');
			}
			else if(BPMs[i][0]=='Other' && BPMs[i][2]=='Greensboro')
			{
				var Title="Bicycle and Pedestrian Maps";
				var FullName = ["Greensboro Rural Maps"];
				var DirPath = ["Greensboro"];
				var FileName = ["Greensboro"];
				var FileSizePDF = ["16.8 MB", "1.6 MB"];
				var FileSizeJPG = ["6.0 MB", "6.1 MB"];
				var FileNameD = ["GreensboroRural","GreensboroInset"];
	
				//document.writeln('<th colspan=10 align="left"><a href="javascript:OtherThumb(\'',FullName[0],'\')">',FullName[0],'</a></th>');
				//if(FileSizeJPG[0]!="0") 
				document.writeln('<td align="left" colspan="3">');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[0],DataType,'">Rural Greensboro .jpg (',FileSizeJPG[0],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[1],DataType,'">Inset .jpg (',FileSizeJPG[1],')</a>');
					document.writeln('</td>');
				document.writeln('<td bgcolor="#7CACD0" width="15">&nbsp;</td>');  // * Spacer
				document.writeln('<td align="left" colspan="3">');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[0],DataType2,'">Rural Greensboro .pdf (',FileSizePDF[0],')</a>');
					document.writeln('<hr>');
					document.writeln('<a class="tableText" href="',DataPath,DirPath[0],'/',FileNameD[1],DataType2,'">Inset .pdf (',FileSizePDF[1],')</a>');
					document.writeln('</td>');
			}
			else
			{
				// ** JPGs
				if(BPMs[i][3]==1)
					document.writeln('<td align="left"> <a class="tableText" ',JPGfront,'>Front</a></td>');
				else 
					document.writeln('<td width=50>&nbsp;</td>'); 
				if(BPMs[i][4]==1 && BPMs[i][5]==0)
					document.writeln('<td align="left"> <a class="tableText" ',JPGback_x,'>Back</a></td>');
				else if(BPMs[i][4]==1 && BPMs[i][5]==1)
					document.writeln('<td align="left"> <a class="tableText" ',JPGback_1,'>Back 1</a></td>');
				else
					document.writeln('<td width=0>&nbsp;</td>'); 
				if(BPMs[i][5]==1)
					document.writeln('<td align="left"> <a class="tableText" ',JPGback_2,'>Back 2</a></td>');
				else 
					document.writeln('<td width=50>&nbsp;</td>'); 
				document.writeln('<td bgcolor="#7CACD0" width="15">&nbsp;</td>');  // * Spacer
	
				// ** PDFs
				if(BPMs[i][6]==1)
					document.writeln('<td align="left"> <a class="tableText" ',PDFfront,'>Front</a></td>');
				else 
					document.writeln('<td width=50>&nbsp;</td>'); 
				if(BPMs[i][7]==1)
					document.writeln('<td align="left"> <a class="tableText" ',PDFback,'>Back</a></td>');
				else
					document.writeln('<td width=50>&nbsp;</td>'); 
				if(BPMs[i][8]==1)
					document.writeln('<td align="left"> <a class="tableText" ',PDFfull,'>Full</a></td>');
				else 
					document.writeln('<td width=50>&nbsp;</td>'); 
			}
			document.writeln('<tr>');
	
		}
	}

	/* displayThumbs uses a string value of the map name given to it.
	 * displayThumbs is for viewing either the City or County bike maps.  
	 * If the map falls under another category a separate function will need to be called,
	 * This function outputs a thumbnail image with a link for the JPGs of a City or COunty bike map.
	 */
	function displayThumbs(map) 
	{
		arrNum = -1;
		for(i=0;i<BPMs.length;i++) { if(map==BPMs[i][2]) { arrNum=i; } } // * Gets the appropriate record

		if(map=='Lake Norman Maps' || map=='Dare' || map=='Greensboro')
			{ displayOtherThumbs(map); return; }

		if(arrNum!=-1)
		{
			var dataset2, DivPath, nameMap, j, text1, pfb, pNum, tb, DataPath, pdfYes; 
	
			var FTPPath = "http://dotw-xfer01.dot.state.nc.us/gisdot/"
			DataPath= FTPPath+"DOTBikeMaps/"; 
			var DataType=".jpg"; var DataType2=".pdf";
	
			var nameMap; var j; var lr = 1; var a1, a2; var arrNum;
	
			for(i=0;i<BPMs.length;i++) { if(map==BPMs[i][2]) { arrNum=i; } } // * Gets the appropriate record
		
			document.writeln('<table>');
				pfb="front"; pNum='';
				imgName = BPMs[arrNum][2].replace(/ /,'');
				document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',imgName.toLowerCase(),'-',pfb,'-T',pNum,'.jpg"></td>');
				document.write('<td align="center" valign="center"><a href="',DataPath);
				if(BPMs[arrNum][0]=='City') document.write('_');
				document.writeln(imgName,'/',imgName.toLowerCase(),'-',pfb,'-sm',DataType,'">Download ',pfb,'</a></td></tr>');
		
				pfb="back"; if(BPMs[arrNum][5]==1) {pNum="1";} else {pNum='';}
				document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',imgName.toLowerCase(),'-',pfb,'-T',pNum,'.jpg"></td>');
				document.write('<td align="center" valign="center"><a href="',DataPath);
				if(BPMs[arrNum][0]=='City') document.write('_');
				document.writeln(imgName,'/',imgName.toLowerCase(),'-',pfb,'-sm',pNum,DataType,'">Download ',pfb,pNum,'</a></td></tr>');
		
				if(BPMs[arrNum][5]==1) 
				{
					pfb="back"; pNum="2";
					document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',imgName.toLowerCase(),'-',pfb,'-T',pNum,'.jpg"></td>');
					document.write('<td align="center" valign="center"><a href="',DataPath);
					if(BPMs[arrNum][0]=='City') document.write('_');
					document.writeln(imgName,'/',imgName.toLowerCase(),'-',pfb,'-sm',pNum,DataType,'">Download ',pfb,pNum,'</a><br></td></tr>'); 
				}
			document.writeln('</td></tr></table>');
		}
		else
		{
			document.writeln('<table width="500"><tr><td class="text3b">An Incorrect thumb name is called in the URL.  Please return to the Bike Maps page and choose an available map.</td></tr></table>');
		}
	}

	/* displayOtherThumbs is the sister fuciton to displayThumbs.
	 * This function is specifically for special Bike Maps.
	 * As of 2/15/4. there is only 1 other map so it is handled below as a special specific case.
	 * Also in the Bike function above.
	 * If more get added, then a method to keep track of that data in a more efficient way should be devised.
	 */
	function displayOtherThumbs(map) {
		var dataset2, DivPath, nameMap, j, text1, pfb, pNum, tb, DataPath; 
		var FTPPath = "http://dotw-xfer01.dot.state.nc.us/gisdot/";
			DataPath= FTPPath+"DOTBikeMaps/"; //  BikeMaps/";
		var DataType1=".pdf"; 	var DataType2=".jpg";
		if(map=='Lake Norman Maps')
		{
			var Title="Bicycle and Pedestrian Maps";
			var FullName = ["Lake Norman Bike Route Proposed"];
			var DirPath = ["LakeNormanMaps"];
			var FileName = ["LakeNormanRds6"];
			var FileSizePDF = ["2.2 MB"];
			var FileSizeJPG = ["4.6 MB"];
			var LNText = 'NCDOT Board of Transportation member Frank L. Johnson is promoting a plan to develop an on and off-road bicycle route around Lake Norman.  The idea is to utilize existing low-volume roads, make improvements to busier roads and develop off-road connectors between residential areas to provide a 150-mile bicycle route around the lake.  Mr. Johnson is quoted as saying, " I know this will take many years to complete, but it\'s a great opportunity to provide for bicycle transportation and recreation in this fast-growing area."';
		
			    document.writeln('<table width=99% cellpadding=2>');
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[0].toLowerCase(),'.gif"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileName[0].toLowerCase(),DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileName[0].toLowerCase(),DataType2,'">Download ',DataType2,'</a></td></tr>');
		}
		else if (map=='Dare')
		{
			var Title="Bicycle and Pedestrian Maps";
			var FullName = ["Dare County Maps"];
			var DirPath = ["Dare"];
			var FileName = ["dare1-T", "dare2-T", "dare3-T"];
			var FileSizePDF = ["3.5 MB", "3.8 MB", "4.0 MB"];
			var FileSizeJPG = ["2.0 MB", "2.6 MB", "1.9 MB"];
			var FileNameD = ["Welcome_Locator_Map","Maps_1-5_Corolla-Nags_Head","Maps_6_7_Hatteras_Manteo"];
			var LNText = ['Welcome and Locator','Maps 1-5 Corolla to Nags Head','Maps 6&7 Hatteras & Manteo'];
		
			    document.writeln('<table width=99% cellpadding=2>');
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[0],'.gif"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText[0]);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileNameD[0],DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileNameD[0],DataType2,'">Download ',DataType2,'</a></td></tr>');
			    document.writeln('<tr><td colspan="2"><hr></td></tr>');
			    
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[1],'.gif"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText[1]);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileNameD[1],DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileNameD[1],DataType2,'">Download ',DataType2,'</a></td></tr>');
				document.writeln('<tr><td colspan="2"><hr></td></tr>');
			    
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[2],'.gif"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText[2]);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileNameD[2],DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileNameD[2],DataType2,'">Download ',DataType2,'</a></td></tr>');
		}
		else if (map=='Greensboro')
		{
			var Title="Bicycle and Pedestrian Maps";
			var FullName = ["Greensboro Rural Maps"];
			var DirPath = ["Greensboro"];
			var FileName = ["GreensboroRural-T", "GreensboroInset-T"];
			var FileSizePDF = ["16.8 MB", "1.6 MB"];
			var FileSizeJPG = ["6.0 MB", "6.1 MB"];
			var FileNameD = ["GreensboroRural","GreensboroInset"];
			var LNText = ['Rural Greensboro','Greensboro Inset'];
		
			    document.writeln('<table width=99% cellpadding=2>');
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[0],'.jpg"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText[0]);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileNameD[0],DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileNameD[0],DataType2,'">Download ',DataType2,'</a></td></tr>');
			    document.writeln('<tr><td colspan="2"><hr></td></tr>');
			    
			    document.writeln('<tr><td align=left><img border=0 src="/it/gis/graphics/bike/',FileName[1],'.jpg"></td>');
			    document.writeln('<td align="left" valign="top">');
			    document.writeln(LNText[1]);
			    document.writeln('<br><br><a href="',DataPath,DirPath[0],'/',FileNameD[1],DataType1,'">Download ',DataType1,'</a><br>');
			    document.writeln('<a href="',DataPath,DirPath[0],'/',FileNameD[1],DataType2,'">Download ',DataType2,'</a></td></tr>');
				document.writeln('<tr><td colspan="2"><hr></td></tr>');
		}
		
		document.writeln('</td></tr></table>');
	}