/*
 *	Functions listed in this page have been written to meet 
 *  the specific needs of this project and does not constitute 
 *  the standard set of ArcIMS HV functions
 * 
 *
 *	Written By T M Govindarajan, 
 *  Tata Consultancy Services
 *
 *  Dec,2002
 *  Copyrights TCS
 *
 */


//Convert Degree decimals to DMS
function DD_To_DMS(aValue)
{
	try
	{
		//
		var Deg=parseInt(aValue);
		var dec = aValue-Deg;

		//
		var tmp = dec*60;
		var Mins = parseInt(tmp);

		var Sec = parseInt((dec-Mins/60.0)*3600.0+0.5);
		return Deg + "d " + Mins + "' " + Sec + "\"";
	}
	catch(e)
	{
		return "-999.0";
	}
}

//Array holds the planned deployment locations
var arrPvX=new Array();
var arrPvY=new Array();


//Preview Points
function DisplayPoints()
{	
		//alert(" arrPvX.length " + arrPvX.length);

		//Check for X coordinates
		if(arrPvX.length==0 || arrPvX==null)
		{
			return '';
		}

		//Check for Y coordinates
		if(arrPvX.length==0 || arrPvY==null)
		{
			return '';
		}

		var thePPString="";
		for(i=0;i<arrPvY.length;i++)
		{
			// draw the User supplied Preview Points on Map
			thePPString += '<LAYER type="acetate"  name="lyrPP'+ (i+1) +'" id="pt'+(i+1)+'">\n';
			thePPString += '<OBJECT units="database">\n';
			thePPString += '	<POINT coords="'+arrPvX[i] +' '+ arrPvY[i] +'">\n';
			thePPString += '		<SIMPLEMARKERSYMBOL color="255,255,0" type="Star" outline= "0,0,0" width="13"/>';
			thePPString += '	</POINT>';
			thePPString += '\n</OBJECT>';
			thePPString += '\n</LAYER>';
			thePPString +='\n';
		}

		//alert(thePPString);
		return thePPString;

}




//Show Preview Points
function ShowPreviewPoints(arrLng,arrLat)
{		
	
	arrPvX = new Array();
	arrPvY = new Array();

	blnShowPreviewPoints=true;


	//Check for Values
	for(i=0;i<arrLng.length;i++)
	{
		if(parseFloat(arrLng[i])==-99.0 || parseFloat(arrLat[i])==-99.0)
		{
			alert("Unable to display Points. Check the lat/long values for the points");	
			return; 
		}

		if(parseFloat(arrLng[i])<30.0 || parseFloat(arrLng[i])> 120.0 )
		{
			alert("Unable to display Points. Check the long values for the points");	
			return; 
		}

		if(parseFloat(arrLat[i])>30.0  || parseFloat(arrLat[i])< -50.0)
		{
			alert("Unable to display Points. Check the lat values for the points");	
			return; 
		}

	}


	//
	if(arrLng.length!=0 && arrLat.length !=null)
	{
		for(i=0;i<arrLng.length;i++)
		{
			arrPvX[i]=parseFloat(arrLng[i]);
			arrPvY[i]=parseFloat(arrLat[i]);
		}
		
	}

	//Zoom To Layer -eLeft,eBot,eRight,eTop
	zoomToEnvelope(eLeft,eBottom,eRight,eTop);

	blnShowPreviewPoints=false;
	
}


function setFullMapExtents()
{
	
	//Zoom To Layer -eLeft,eBot,eRight,eTop
	zoomToEnvelope(20,-53,150,20);
}


function getMapExtents()
{
	alert(" eLeft " + eLeft + " eBottom " + eBottom + " eRight " + eRight + " eTop " + eTop);
}

function ListAllFutLayers()
	{
		for(i=0;i<LayerName.length;i++)
		{
			alert("i " + i + " " + LayerName[i]);
		}
	}


//Display Tips
    function DisplayTips()
	{
		switch(parent.MapFrame.toolMode)
		{
			case 1: strDisplay = " Current Tool is ZOOM IN";
					break;
			
			case 2: strDisplay = " Current Tool is ZOOM OUT";
					break;
					
			case 5: strDisplay = " Current Tool is Float Info";
					break;

			case 9: strDisplay = " No Current Tool";
					break;
					
			case 20:strDisplay = " Current Tool is MEASURE";
					break;
		}

		parent.SouthDownFrame.document.location="futDisplay.htm";
					
	}

	function toggleLayerVisibility(aImg,aLyrID)
	{	
		var aValue = aImg.src.toLowerCase();
		//alert(LayerName[aLyrID] + " " + LayerVisible[aLyrID]);

		if (aValue.indexOf("eye_open.jpg")!=-1) 
		{
			aImg.src="images/webdesign/eye_closed.jpg";
			LayerVisible[aLyrID]=0;
		}
		else 
		{
			LayerVisible[aLyrID]=1;
			aImg.src="images/webdesign/eye_open.jpg";
		}
		
		sendMapXML();
	}

	function ChangeImage(aImg)
		{	
			//
			if (aImg.src.indexOf("eye_open.jpg")!=-1) 
			{
				aImg.src="images/webdesign/eye_closed.jpg";
			}
			else 
			{
				aImg.src="images/webdesign/eye_open.jpg";
			}

		}

		
	//Update Layers
	function UpdateLayers()
	{		
		//alert(LayerName[intLCenterIndex] + " " + LayerVisible[intLCenterIndex] );
		//LCenter
		parent.MapFrame.document.futureTools.FDP.src=((LayerVisible[intFDPIndex]==1)?"images/webdesign/eye_open.jpg":"images/webdesign/eye_closed.jpg");
		parent.MapFrame.document.futureTools.FDF.src=((LayerVisible[intFDFIndex]==1)?"images/webdesign/eye_open.jpg":"images/webdesign/eye_closed.jpg");
		parent.MapFrame.document.futureTools.FDB.src=((LayerVisible[intFDBIndex]==1)?"images/webdesign/eye_open.jpg":"images/webdesign/eye_closed.jpg");
	}

	function ShowPresent()
	{
		LayerVisible[intFDPIndex] = 1 //Visible
		LayerVisible[intFDFIndex] = 0 //Invisible
		LayerVisible[intFDBIndex] = 0 //Invisible

	//refresh map see the click event of the other layers lile
	  sendMapXML();
	}

	function ShowFuture()
	{
	    LayerVisible[intFDPIndex] = 0 //Invisible
		LayerVisible[intFDFIndex] = 1 //Visible
		LayerVisible[intFDBIndex] = 0 //Invisible

	//refresh map see the click event of the other layers lile
	  sendMapXML();
	}

	function ShowBoth()
	{
	    LayerVisible[intFDPIndex] = 0 //Invisible
		LayerVisible[intFDFIndex] = 0 //Invisible
		LayerVisible[intFDBIndex] = 1 //Visible

	//refresh map see the click event of the other layers lile
	  sendMapXML();
	}

   function ShowNothing()
	{
	    LayerVisible[intFDPIndex] = 0 //Invisible
		LayerVisible[intFDFIndex] = 0 //Invisible
		LayerVisible[intFDBIndex] = 0 //Invisible 

	//refresh map see the click event of the other layers lile
	 sendMapXML();
	}

