// JavaScript Document
// toc.js
/*  it's order to show toc information
*  JavaScript template file for ArcIMS HTML Viewer
*		dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*		aimsLayers.js, aimsDHTML.js
*		aimsNavigation.js
*/
	
		
		
		function setActiveLayer(i) {
			var t=document.frames["mapframe"].MapFrame;
			var  theForm = document.forms[0];
			t.ActiveLayer=t.LayerID[i];
			t.ActiveLayerType=t.LayerType[i];
			t.ActiveLayerIndex=i;
			t.setActiveLayer(i);
			var isOk = t.checkHyperLinkLayer(i);
			if (t.toolMode==15) {
				
				if (!isOk) {
					t.currentHyperLinkLayer="";
					t.currentHyperLinkField="";
					t.currentHyperLinkPrefix="";
					t.currentHyperLinkSuffix="";
					alert(t.msgList[47]);
			
				}
			}
			//alert(t.ActiveLayerIndex + "." + t.ActiveLayer);
	
		}
		
		function showLayerInfo(i) {
			var t=document.frames["mapframe"].MapFrame;
			t.showLayerInfo(i);
		}
		
		// refresh map display with checked layers visible	
		function updateLayers() {
			var t=document.frames["mapframe"].MapFrame;
			//alert(layerCount);
			//alert(parent.TOCFrame.document.forms[0].LayerVisible.length);
			var theForm = document.forms[0];
			var j = 0;
			if (theForm.LayerVisible.length>1) {
				for (var i=0;i<theForm.LayerVisible.length;i++) {
					j = theForm.LayerVisible[i].value;
					if (theForm.LayerVisible[i].checked) {
						t.LayerVisible[j] = 1;
					}
					else {
						t.LayerVisible[j] = 0;
					}
				}
				/*
			} else {
					if (theForm.LayerVisible.checked) {
						j = theForm.LayerVisible.value;
						t.LayerVisible[j] = 1;
					}
					else {
						t.LayerVisible[j] = 0;
					}
			}
			*/
			} else {
				j = theForm.LayerVisible.value;
				if (theForm.LayerVisible.checked) {
					t.LayerVisible[j] = 1;
				} else {
					t.LayerVisible[j] = 0;
				}
			}

			t.sendMapXML();
		
		}
		// stop displaying the Layerlist
		// 	only works in  separate window
		function closeIt() {
			var t=document.frames["mapframe"].MapFrame;
			t.LayerListOpen=false;
			window.close();
		}
		// startup function for separate window
		function startUp() {
			var t=document.frames["mapframe"].MapFrame;
			if (opener) {
				t.LayerListOpen=true;
				window.focus();
			}
		}
		function filltoc()
		{
			var t=document.frames["mapframe"].MapFrame;
			
			var winstr='<FORM>';
				
				winstr+='<div id="seealsohead">Geographics</div><br />';
				winstr+='<TABLE CELLSPACING="0" CELLPADDING="1">';
				winstr+='<TR>';
				winstr+='<TD><div id="toctext">Visible</div></TD>';
				winstr+='<TD style="position:relative; left=20px"><div id="toctext">Active</TD>';
				winstr+='<TD style="position:relative; left=55px"><div id="toctext">Name</TD>';				
				//winstr+='<TD><FONT FACE="Arial Narrow" SIZE="-3">Name</FONT></TD>';
						
				winstr+='</TR>';
				winstr+='<tr><table>';
					var theCount = t.layerCount;
					//alert(theCount);
					for (var i=0;i<theCount;i++) 
					{
						if ((!t.hideLayersFromList) || ((t.hideLayersFromList) && (!t.noListLayer[i]))) 
						{
							if ((t.listAllLayers) || ((t.mapScaleFactor>=t.LayerMinScale[i]) && (t.mapScaleFactor<=t.LayerMaxScale[i]))) 
							{
								winstr+='<tr ><td width="38%">';
								winstr+='<input type="Checkbox" name="LayerVisible" value="' + i + '"';
								if (t.LayerVisible[i] == 1) winstr+='checked';
								winstr+='></td>';
								winstr+='<td width="38%">';

								if (t.LayerIsFeature[i])
								{
									winstr+='<input type="Radio" onclick="setActiveLayer(' + i + ')" name="Active"';
									if (t.ActiveLayerIndex==i) winstr+=' checked';
									winstr+='>';
								} 
								else 
								{
									winstr+='&nbsp;';
								}
								winstr+='</td>';
								if(i==2)
								{
									winstr+='<td width="24%" style="font-size: 16px;"><FONT FACE="Arial Narrow" color="#3C9344">District</font></td>';
								
								}
								else															winstr+='<td width="24%" style="font-size: 16px;"><FONT FACE="Arial Narrow" color="#3C9344">' + t.LayerName[i] + '</font></td>';
								//if (t.displayLayerInfoButton)
								//{
									//winstr+='<td><INPUT TYPE="Button" NAME="InfoButton" VALUE="' + t.buttonList[43] + '" onclick="showLayerInfo(' + i + ')"></td>';
								//}
								winstr+='</tr>';
							}
						}
					}
				
				winstr+='</table></tr>';
				//winstr+='</tr>';
					winstr+='<TR width="60%" align=center>';
					winstr+='<TD style="position:relative; top=10px" ALIGN="center" COLSPAN="3">';
					//winstr+='<INPUT TYPE="button" width="60%" NAME="refreshButton" VALUE="' + t.buttonList[44] + '" onClick="updateLayers()">';
					//winstr+='<input type="submit" name="submit" value="Refesh"> ';
					//winstr+='<input type="image" border="0" name="refreshButton1" value="Refesh" src="pic/btn.jpg" onClick="updateLayers()">';
					winstr+='<img src="pic/btn.jpg" NAME="refreshButton1" VALUE="' + t.buttonList[44] + '" style="cursor:hand" onClick="updateLayers()">';
					
					winstr+='</TD>';
					winstr+='</TR>';
				
				
				
			winstr+='</TABLE>';
	
			

	winstr+='</FORM>';

	//document.write(winstr);
	//alert(document.getElementById("tochtm"));
	//document.write(winstr);
		top.tocstr=winstr;
		//switchbutton(1);
		document.getElementById("tochtm").innerHTML = winstr;
			//alert("fillOK");
		}
		
