﻿// ********************************************
//     All the common functions used by GTG
// ********************************************

var gtgMapID = "m_Map";

function SetupVeil()
{
	try
	{
		var ie=document.all && !window.opera
		var VeilObj = document.getElementById("GTG_LayoutSelector_Blade_Veil");
		
		//Preliminary doc width in non IE browsers
		var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 
		//create reference to common "body" across doctypes
		var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body 
		var scroll_top=(ie)? standardbody.scrollTop : window.pageYOffset
		var scroll_left=(ie)? standardbody.scrollLeft : window.pageXOffset
		var docwidth=(ie)? standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
		var docheight=(ie)? standardbody.clientHeight: window.innerHeight
		var docheightcomplete=(standardbody.offsetHeight>standardbody.scrollHeight)? standardbody.offsetHeight : standardbody.scrollHeight
		
		VeilObj.style.width=docwidth+"px" //set up veil over page
		VeilObj.style.height=docheightcomplete+"px" //set up veil over page
			
		VeilObj.style.left=0 //Position veil over page
		VeilObj.style.top=0 //Position veil over page
		VeilObj.style.visibility="visible" //Show veil over page
		VeilObj.style.display="block" //Show veil over page
		VeilObj.state = "fullview";
		
		var LayoutSel = GetElementByID("GTG_LayoutSelector_Blade_Center");
		LayoutSel.style.display = "block";
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in SetupVeil() { GTG_Common.js }" );
	}
}

String.prototype.trim = function() 
{
	try
	{
		return this.replace(/^\s+|\s+$/g,"");
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in String.prototype.trim { GTG_Common.js }" );
	}
}

// This gets the Element by ID (browser independant)
// Ret: The object or null if no object exists
function GetElementByID( id )
{
	try
	{
		if( document.layers )
		{
			return document.layers[id];
		}
		else if( document.all )
		{
			return document.all[id];
		}
		else if( document.getElementById )
		{
			return document.getElementById(id);
		}
		
		return null;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GetElementByID( id ) { GTG_Common.js }" );
	}
}

// Browser independant way of getting the window height
// Ret: the window height in pixels
function GetWindowHeight() 
{
	try
	{
		var myHeight = 0;
		
		if( typeof( window.innerWidth ) == 'number' ) 
		{
			//Non-IE
			myHeight = window.innerHeight;
		}
		else if( document.documentElement && 
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
			//IE 6+ in 'standards compliant mode'
			myHeight = document.documentElement.clientHeight;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{
			//IE 4 compatible
			myHeight = document.body.clientHeight;
		}

		return myHeight;	
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GetWindowHeight() { GTG_Common.js }" );
	}
}

// Browser independant way of getting the window height
// Ret: the window width in pixels
function GetWindowWidth() 
{
	try
	{
		var myWidth = 0;
		
		if( typeof( window.innerWidth ) == 'number' ) 
		{
			//Non-IE
			myWidth = window.innerWidth;
		}
		else if( document.documentElement && 
			( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
			//IE 6+ in 'standards compliant mode
			myWidth = document.documentElement.clientWidth;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
		}
		
		return myWidth;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GetWindowWidth() { GTG_Common.js }" );
	}
}

// This sets the image of a <img> html element.
// Arg1: The string ID of the <img> html element to change
// Arg2: The image url to change the src attribute to.
function SetImage( id, img )
{
	try
	{
		var oImg = GetElementByID(id);
		oImg.src = img;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in SetImage( id, img ) { GTG_Common.js }" );
	}
}

// This sets the image of a <img> html element.
// Arg1: The string ID of the <img> html element to change
// Arg2: The ID to check if Hidden.
// Arg3: The image url to change the src attribute to if its hidden.
// Arg4: the image url to change the src attribute to if its visible.
function SetImage( id, idHide, imgHidden, imgVis )
{
    try
	{
		// The image object
		var oImg = GetElementByID(id);
		
		// The ID of the obj that might be visible
		var oObjVisible = GetElementByID( idHide );
		
		if( oImg == null || oObjVisible == null )
		{
			return;
		}
		
		if( oObjVisible.style.visibility == "collapse" )
		{
			oImg.src = imgHidden;
		}
		else
		{
			oImg.src = imgVis;
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in SetImage( id, idHide, imgHidden, imgVis ) { GTG_Common.js }" );
	}
}

// This collapses and expands an element that collapses
// Arg1: The string ID of the <img> html element to change
function ToggleHorizontalHidden( idBody, idImg, TableID, ImgHide, ImgVis )
{
	try
	{
		var oObj = GetElementByID(idBody);
		var oObj2 = GetElementByID(TableID);
		var oImgObj = GetElementByID(idImg);
		
		if( oObj.style.visibility == "collapse" )
		{
			oObj.style.visibility = "visible";
			oObj2.style.height = "100%";
			oImgObj.src = ImgHide;
		}
		else
		{
			oObj.style.visibility = "collapse";
			oObj2.style.height = "";
			oImgObj.src = ImgVis;
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ToggleHorizontalHidden( idBody, idImg, TableID, ImgHide, ImgVis ) { GTG_Common.js }" );
	}
}

function ToggleVerticleHidden( idFullObj, idHiddenObj, idImgID, InitImage )
{
    try
	{
		var oFullObj = GetElementByID( idFullObj );
		var oHideObj = GetElementByID( idHiddenObj );
		var oImg = GetElementByID( idImgID );
	    
		if( oFullObj == null || oHideObj == null || oImg == null )
		{
			return; 
		}
	    
		if( oFullObj.style.visibility == "collapse" )
		{
			oFullObj.style.visibility = "visible";
			oHideObj.style.visibility = "hidden";
		}
		else
		{
			oFullObj.style.visibility = "collapse";
			oHideObj.style.visibility = "visible";
		}
	    
		oImg.src = InitImage
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ToggleVerticleHidden( idFullObj, idHiddenObj, idImgID, InitImage ) { GTG_Common.js }" );
	}
}

// ********************************************
//     All the dragging/moving functions/variables
// ********************************************

//The X position of the object that is being moved
var m_oMoveableObj_PosX;
// The Y position of the object that is being moved
var m_oMoveableObj_PosY;
// The Z position Max
var m_oMoveableObj_ZMax = 0;
// An instance of the Moveable Object
var m_oMoveableObj;
// This is whether the object is stored as percent or pixel value
//var m_ObjectPlacement;

// This should be fired from the "onmousedown" event and will set up the dragging for this object.
function Drag_Start( itemToMove, e )
{
    try
	{
		itemToMove.style.zIndex = ++window.m_oMoveableObj_ZMax;
	    
		// Attempt to make this browser independant
		if( !e ) 
		{
			e = window.event;
		}
		
		m_oMoveableObj = itemToMove;
	    
		// This is the test variable. I store off the style.left/top to it so that 
		// I can do string manipulation with it
		var test = m_oMoveableObj.style.left;
	    
		// This is the initial X position
		var InitialX = parseInt(m_oMoveableObj.style.left);
	    
		// Test if it is in percentatges
		if( test.charAt( test.length-1) == '%' )
		{
			// Try to get the percent
			InitialX = parseFloat(m_oMoveableObj.style.left);
			
			// If we got something back...convert to screen coords
			if( InitialX != 0 )
			{
				InitialX = parseInt( InitialX * GetWindowWidth() / 100 );
			}
		}
	    
		// Now do the same for the Y
		var InitialY = parseInt(m_oMoveableObj.style.top);
	    
		// Store off the top
		test = m_oMoveableObj.style.top;
	    
		// Its possible this is a percent.
		if( test.charAt( test.length-1) == '%' )
		{
			// Try to get the percent
			InitialY = parseFloat(m_oMoveableObj.style.top);
			
			// If we got something back...convert to screen coords
			if( InitialY != 0 )
			{
				InitialY = parseInt( InitialY * GetWindowHeight()  / 100 );
			}
		}
	    
		// Calculate the offset of the cursor
		m_oMoveableObj_PosX = e.clientX - InitialX;
		m_oMoveableObj_PosY = e.clientY - InitialY;
		itemToMove.style.cursor = "move";
	    
		if( e.preventDefault )
		{
			e.preventDefault();
		}
		else
		{
			e.returnValue = false;
		}
	    
		// This sets up some events for mouse move and mouse down.
		document.onmousemove = drag;
		document.onmouseup = drag_stop;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in Drag_Start( itemToMove, e ) { GTG_Common.js }" );
	}
}

// This is called when the mouse key is up.
function drag_stop( e )
{
	try
	{
		// Check if we have an object first
		if( m_oMoveableObj ) 
		{
			m_oMoveableObj.style.cursor = "pointer";            
			m_oMoveableObj = null;
	        
			// Release these events
			document.onmousemove = null;
			document.onmouseup = null;
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in drag_stop( e ) { GTG_Common.js }" );
	}
}

// When the mouse is moving, this event is called.
function drag(e)
{
    try
	{
		if( !m_oMoveableObj )
		{
			return;
		}

		if( !e )
		{
			e = window.event;
		}

		var height, width;
	    
		// Attempt to be browser independant
		if( document.all )
		{
			height = document.body.offsetHeight;
			width = document.body.offsetWidth;
		}
		else if( document.layers )
		{
			height = window.innerHeight;
			width = window.innerWidth;
		}
	    
		var newX = e.clientX - m_oMoveableObj_PosX;
		var newY = e.clientY - m_oMoveableObj_PosY;
	    
		if( newX < -m_oMoveableObj.clientWidth / 2 )
		{
			newX = -m_oMoveableObj.clientWidth / 2;
			m_oMoveableObj_PosX = e.clientX - parseInt(m_oMoveableObj.style.left);
		}
	    
		if( newY < -m_oMoveableObj.clientHeight / 2 )
		{
			newY = -m_oMoveableObj.clientHeight / 2;
			m_oMoveableObj_PosY = e.clientY - parseInt(m_oMoveableObj.style.top);
		}

		m_oMoveableObj.style.left = newX + "px";
		m_oMoveableObj.style.top = newY + "px";

		if( e.preventDefault )
		{
			e.preventDefault();
		}
		else 
		{
			e.returnValue = false;
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in drag(e) { GTG_Common.js }" );
	}
}

//document.ondragstart = function()
//{
//    return false;
//}
//document.onselectstart = function()
//{
//    return false;
//}


// ********************************************
//  End of all the dragging/moving functions/variables
// ********************************************



function UpdateGTG_WebPanel( ReturnValue )
{
	try
	{
		// This is the beginning up to ":::" of the Return value
		// 0 - will tell us what object to update
		// 1 - will replace the html currently in the object
		var data = ReturnValue.split( ":::" );
		
		// Get the Object
		var TheObject = GetElementByID( data[0] );
	    
		TheObject.style.left = data[1];
		TheObject.style.top = data[2];
		TheObject.style.width = data[3];
		TheObject.style.height = data[4];
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in UpdateGTG_WebPanel( ReturnValue ) { GTG_Common.js }" );
	}
}



//New Apple functions
//function SetChildrenToInherit(id)
//{
//    if ( !document.getElementById
//        || !document.getElementsByTagName) 
//	{
//        return;
//    }

//    var nodesToDisable = {div :'', table :''};

//    var node, nodes;
//    var div = document.getElementById(id);
//    if (!div) return;

//    nodes = div.getElementsByTagName('*');
//    if (!nodes) return;

//    var i = nodes.length;
//    while (i--)
//    {
//		node = nodes[i];
//        
//		if( (node.nodeName != null ) && ( node.nodeName.toLowerCase() in nodesToDisable ) )
//		{
//			node.style.visibility = "inherit";
//		}
//    }
//}

function ToggleObjectVisibility( ObjID, Postback )
{
	try
	{
		var Obj = GetElementByID( ObjID );
		
		if( Obj.style.display == "none" )
		{
			Obj.style.display = "";
		}
		else
		{
			Obj.style.display = "none";
		}
		
		// Make sure any Nav tools are hidden
		if( GTGToolbarOpenedItem != null )
		{
			GetElementByID(GTGToolbarOpenedItem).style.visibility = "hidden";
		}
		
		if( Postback == true )
		{
			GTG_Resize();
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ToggleObjectVisibility( ObjID, Postback ) { GTG_Common.js }" );
	}
}

// This makes one of the major button item's appear on screen while making all the other objects disapear.
function MakeObjectVisible( ObjID, ObjThis )
{
	try
	{
		// Make sure any Nav tools are hidden
		if( GTGToolbarOpenedItem != null )
		{
			GetElementByID(GTGToolbarOpenedItem).style.visibility = "hidden";
		}
		
		// If the object that we are showing is alraedy visible, lets hide it.
		var ShowObject = true;
		
		// This is the array of all objects the need to be turned off when the menu changes.
		var arrAllObjects = new Array("m_ToolbarBubble_table", "m_SearchBubble_table", "m_FindSelectorBubble_table", "m_FindAddressBubble_table", "m_FindIntersectionBubble_table");

		for( i = 0; i<arrAllObjects.length; i++ )
		{
			var obj = GetElementByID( arrAllObjects[i] );
			
			if( ObjID == arrAllObjects[i] && !( obj.style.display == "none" || obj.style.visibility == "hidden" ) )
			{
				ShowObject = false;
			}
			
			if( obj != null )
			{
				obj.style.display = "none";
			}
		}
		
		// Turn off the Find Intersection/Find Address
	//	GetElementByID("m_FindAddressBubble_table").style.display = "none";
	//	GetElementByID("m_FindIntersectionBubble_table").style.display = "none";
		
		var objReal = GetElementByID( ObjID );
		
		if( objReal != null && ShowObject )
		{
			var pos = findPos(ObjThis);
			
			if( ToolbarDockPos == "Left" )
			{
				objReal.style.left = pos[0] + 100 + "px";
				objReal.style.top = pos[1] + "px";
			}
			else if( ToolbarDockPos == "Top" )
			{
				objReal.style.left = pos[0] + "px";
				objReal.style.top = pos[1] + 85 + "px";
			}
			else if( ToolbarDockPos == "Right" )
			{
				objReal.style.display = "";
				objReal.style.left = pos[0] - objReal.clientWidth - 25 + "px";
				objReal.style.top = pos[1] + "px";;
			}

			// make sure to set the display after we move it.		
			objReal.style.display = "";
			objReal.style.visibility = "visible";
		}
		
		if( ObjID == "m_SearchBubble_table" )
		{
			var Children = GetElementByID("Search_Submit").getElementsByTagName("input");
			
			Children[0].focus();
			Children[0].select();
		}
		else if( ObjID == "m_FindAddressBubble_table" )
		{
			var addy = GetElementByID("FindAddress_AddyField");
			
			if( addy.style.visibility == "visible" && addy.style.display == "" )
			{
				addy.focus();
				addy.select();
			}
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in MakeObjectVisible( ObjID, ObjThis ) { GTG_Common.js }" );
	}
}

// This will find the X, Y position of any window in pixels
function findPos(obj) 
{
	try
	{
		var curleft = curtop = 0;
		if( obj.offsetParent )
		{
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while( obj = obj.offsetParent )
			{
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in findPos(obj) { GTG_Common.js }" );
	}
}


function UpdateGTG_URL( ReturnValue ) 
{
	try
	{
		var urlLink = GetElementByID( "m_GenerateLink_m_txtbxGenerateURL" );
		urlLink.value = ReturnValue;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in UpdateGTG_URL( ReturnValue ) { GTG_Common.js }" );
	}
}

function ShowSearchItem( ItemIdx ) 
{
	try
	{
		for( x in GlobalSearch_IDs ) 
		{ 
			GetElementByID( GlobalSearch_IDs[x] ).style.display = "none"; 
		}

		var item = GetElementByID( GlobalSearch_IDs[ItemIdx] );
		
		if( item != null ) 
		{ 
			item.style.display = "";
			
			var Children = item.getElementsByTagName("input");
			
			Children[0].focus();
			Children[0].select(); 
		}
		
		var SearchBtn = GetElementByID( "Searches_SearchBtn" );
		if( SearchBtn.style.display == "none" ) 
		{ 
			SearchBtn.style.display = "";	
		} 
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ShowSearchItem( ItemIdx ) { GTG_Common.js }" );
	}
}

function PerformSearch( evt, btnID )
{
	try
	{
		if(  evt.keyCode == 13 )
		{
			var btn = GetElementByID(btnID);
			
			if( btn != null )
			{
				btn.click();
			}
		
			return true;
		}
		
		return false;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in PerformSearch( evt, btnID ) { GTG_Common.js }" );
	}
}

// This will make the print box appear on screen in the middle of the window
function ShowPrintBox()
{
	try
	{
		GTGToolbarOpenedItem = "PrintPopUp";
		
		var Width = GetWindowWidth();
		var Height = GetWindowHeight();
		
		var obj = GetElementByID("PrintPopUp");
		
		if( obj == null )
		{
			return;
		}
		
		obj.style.display = "";
		obj.style.visibility = "visible";
		GetElementByID("Printing_Step1").style.display = "";
		GetElementByID("Printing_Step2").style.display = "none";
		
		obj.style.left = Width / 2 - obj.clientWidth / 2 + "px";
		obj.style.top = Height / 2 - obj.clientHeight / 2 + "px";
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ShowPrintBox() { GTG_Common.js }" );
	}
}

// Event handler for Generating the Print
function GeneratePrintCallback() 
{
	try
	{
		var radRes;
		
		for( var i=0; i < document.form1.LayoutType.length; i++ )
		{
			if( document.form1.LayoutType[i].checked )
			{
				radRes = document.form1.LayoutType[i].value;
				break;
			}
		}

		var map = Maps["m_Map"];

		var message = "ControlID=Map1&ControlType=Print&EventArg=" + 
			document.form1.Page_Size[document.form1.Page_Size.selectedIndex].value + ":::" + 
			GetElementByID("PrintTitle").value + ":::" + radRes;
		var context = map.controlName;
		eval( printCallbackFunctionString );
		
		GetElementByID("Printing_Step1").style.display = "none";
		GetElementByID("Printing_Step2").style.display = "";
		
		return false;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GeneratePrintCallback() { GTG_Common.js }" );
	}
}

// This parses the print callback from the server.
function processPrintCallback(callback)
{
	try
	{
		var Rets = callback.split(":::");

		GetElementByID("PrintPopUp").style.display = "none";
		window.open( Rets[1],"Print","width=" + GetWindowWidth() + ",height=" + GetWindowHeight() + "menubar=1,resizable=1,toolbar=1")
		
		GetElementByID("gtgPopupDownload").href = Rets[1];
			
		var objFTP = GetElementByID("FileTransfer_PopUp");
		
		objFTP.style.visibility = "visible";
		objFTP.style.display = "";
		
		var vClientWidth = GetWindowWidth();
		var vClientHeight = GetWindowHeight();
		
		objFTP.style.top = ((vClientHeight / 2) - ( objFTP.clientHeight / 2)) + "px";
		objFTP.style.left = ((vClientWidth / 2) - ( objFTP.clientWidth / 2)) + "px";
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processPrintCallback(callback) { GTG_Common.js }" );
	}
}

// This will parse the result that we got from the resize event from the server.
function processResizeCallback(callback)
{
	try
	{
		var ovm = $find("m_OVPanel_m_OverviewMap"); 
	
		var arrVars = callback.split(";;;");
		
		for( var i=0; i < arrVars.length-2; i++ )
		{
			if( arrVars[i] == "javascript" )
			{
				eval( arrVars[i+1] );
				i += 1;
				continue;
			}
			else
			{
				// Get the object
				var obj = GetElementByID( arrVars[i] );
				
				if( obj == null )
				{
					i += 5;
					continue;
				}
				
				// Set visibility
				if( arrVars[i+1] == "True" )
				{
					obj.style.display = "";
				}
				// Make sure its not empty
				else if( arrVars[i+1] != "" )
				{
					obj.style.display = "none";
				}
				
				// Set X
				if( arrVars[i+2] >= 0 )
				{
					obj.style.left = arrVars[i+2] + "px";
				}
				
				// Set Y
				if( arrVars[i+3] >= 0 )
				{
					obj.style.top = arrVars[i+3] + "px";
				}
				
				// Set Width
				if( arrVars[i+3] >= 0 )
				{
					obj.style.width = arrVars[i+4] + "px";
				}
				
				// Set Height
				if( arrVars[i+5] >= 0 )
				{
					obj.style.height = arrVars[i+5] + "px";
				}

				// Increment so that the next iteration will be on the next obj name	
				i += 5;
			}
		}
		
		// Resize the table within the Result panel
		var ResultTable = GetElementByID("m_ResultsPanel_div");
		var InnerTable = ResultTable.getElementsByTagName("table");
		
		InnerTable[0].style.width = ResultTable.style.width;
		InnerTable[0].style.height = ResultTable.style.height;
		
		var ResultRows = ResultTable.getElementsByTagName("tr");
		
		var ResTableContent = GetElementByID("ResultsPanel_Content");
		if( ResultTable.clientWidth >= 0 )
		{
			ResTableContent.style.width = ResultTable.clientWidth  + "px";
		}
		
		if( (ResultTable.clientHeight - 15 - ResultRows[0].clientHeight) >= 0 )
		{
			ResTableContent.style.height = ResultTable.clientHeight - 15 - ResultRows[0].clientHeight + "px";
		}
		
		if( (ResultTable.clientHeight - 15 - parseInt(ResultRows[0].style.Height)) >= 0 )
		{
			ResTableContent.style.height = ResultTable.clientHeight - 15 - ResultRows[0].clientHeight + "px";
		}
		
		if( arrVars[arrVars.length-1] != "" )
		{
			var sizes = arrVars[arrVars.length-1].split(":::");
			ModifyToolbarImageSizes( parseInt( sizes[0] ), parseInt( sizes[1] ) );
		}
		
		var ResultPanelObjs = GetElementByID("gtgResultButtons");
		var tds = ResultPanelObjs.getElementsByTagName("td");
		var WidthCount = 0;
		
		for( var a=0; a<tds.length-1; a++ )
		{
			WidthCount += parseInt( tds[a].style.width, 10 );
		}
		
		if( ResultTable.clientWidth > 0 )
		{		
			tds[4].style.width = (ResultTable.clientWidth - WidthCount) + "px";
		}
		
		var OVPanel = GetElementByID("m_OVPanel_div");
		var OVMap = GetElementByID("m_OVPanel_m_OverviewMap");
		OVMap.style.width = OVPanel.clientWidth + "px";
		OVMap.style.height = OVPanel.clientHeight + "px";
		
		// Resize the Legend if Standard Layout
		var objInnerLegend;
		if( (objInnerLegend = GetElementByID("m_LegendPanel_m_Legend")) != null )
		{
			var objOutterLegend = GetElementByID("m_LegendPanel_div");
			
			objInnerLegend.style.width = objOutterLegend.style.width;
			objInnerLegend.style.height = objOutterLegend.style.height;
		}
		
		// This will reload the map properly
		window.clearTimeout( reloadTimer );
		reloadTimer = window.setTimeout("AdjustMapSize();", 500);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processResizeCallback(callback) { GTG_Common.js }" );
	}
}

// This is used for when a button on the Result Panel is pressed.
// buttonID = The ID of the button that was pressed
// extraArgs = Any extra arguments that must be passed back to the server. This must start with an "&"
function ResultTableButtonPressed(buttonID, extraArgs)
{
	try
	{
		if( buttonID == "ResultTable_Reports" && extraArgs == "" )
		{
			var Width = GetWindowWidth();
			var Height = GetWindowHeight();
			
			var obj = GetElementByID("ReportsPopup");
			
			if( obj == null )
			{
				return;
			}
			
			obj.style.left = Width / 2 - obj.clientWidth / 2 + "px";
			obj.style.top = Height / 2 - obj.clientHeight / 2 + "px";
		
			// Check to see if we have any reports firt.
			var listElements = GetElementByID("Reporting_Step1").getElementsByTagName("li");
			
			if( listElements.length == 0 )
			{
				GetElementByID("Reporting_Step1").style.display = "none";
				GetElementByID("Reporting_Step2").style.display = "none";
				GetElementByID("Reporting_NoReports").style.display = "";
			
				GetElementByID("ReportsPopup").style.display = "";
			}
			else if( listElements.length == 1 )
			{
				var message = "ControlType=ResultTable&BtnPressed=" + buttonID + "&ServiceReportIdx=0,0";
				var context = "m_ResultPanel";
				
				GetElementByID("Reporting_Step1").style.display = "none";
				GetElementByID("Reporting_Step2").style.display = "";
				GetElementByID("Reporting_NoReports").style.display = "none";
				GetElementByID("ReportsPopup").style.display = "";
				
				eval( ResultPanelButtonCallbackFunction );
			}
			else
			{	
				GetElementByID("Reporting_Step1").style.display = "";
				GetElementByID("Reporting_Step2").style.display = "none";
				GetElementByID("Reporting_NoReports").style.display = "none";
				
				GetElementByID("ReportsPopup").style.display = "";
			}
		}
		else
		{
			var message = "ControlType=ResultTable&BtnPressed=" + buttonID + extraArgs;
			var context = "m_ResultPanel";
			
			GetElementByID("Reporting_Step1").style.display = "none";
			GetElementByID("Reporting_Step2").style.display = "";
			
			eval( ResultPanelButtonCallbackFunction );
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ResultTableButtonPressed(buttonID, extraArgs) { GTG_Common.js }" );
	}
}

function processResultCallback( callback )
{
	try
	{
		var indexOfClearData = callback.indexOf( "&***&" );
		var Rets = callback.split(";;;")

		if( Rets[0] == "Report" )
		{
			GetElementByID("ReportsPopup").style.display = "none";

			window.open( Rets[1],"Report","width=" + GetWindowWidth() + ",height=" + GetWindowHeight() + "menubar=1,resizable=1,toolbar=1")
			
			
			GetElementByID("gtgPopupDownload").href = Rets[1];
			
			var objFTP = GetElementByID("FileTransfer_PopUp");
			
			objFTP.style.visibility = "visible";
			objFTP.style.display = "";
			
			var vClientWidth = GetWindowWidth();
			var vClientHeight = GetWindowHeight();
			
			objFTP.style.top = ((vClientHeight / 2) - ( objFTP.clientHeight / 2)) + "px";
			objFTP.style.left = ((vClientWidth / 2) - ( objFTP.clientWidth / 2)) + "px";
						
			return;
		}
		else if( indexOfClearData >= 0 )
		{
			var Split = callback.split( "&***&" );
			
			processResultTableCallback( Split[1] );
			
			if( Split[2] != null && Split[2] != "" )
			{
				processResizeCallback( Split[2] );
			}
		}
		else
		{
			processCallbackResult( callback );
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processResultCallback( callback ) { GTG_Common.js }" );
	}
}

//var gtgGlobalProcessCallBackArgs = "";

function processResultTableCallback(callback)
{
	try
	{
		if( callback == "" )
		{
			return false;
		}

		var ResultPanelTitle = GetElementByID( "ResultsTitle" );
		var ResultPanel = GetElementByID( "ResultsPanel_Content" );
		var Rets = callback.split(";;;")
		
			
		ResultPanelTitle.innerHTML = Rets[0];
		
		if( Rets[1] == null )
		{
			ResultPanel.innerHTML = Rets[0];
			
			var ResultButtonTableColumn = GetElementByID( "gtgResultButtons" );
			var Buttons = ResultButtonTableColumn.getElementsByTagName("img");
			
			var btnList = new Array( "Images/zoom in_disabled.gif", "Images/Purchase Order_Disabled.gif" );
			
			if( btnList.length == Buttons.length )
			{
				for( var i=0; i<btnList.length; i++ )
				{
					Buttons[i].src = btnList[i];
				}
			}	
			
			map.redraw();
		}
		else
		{
			ResultPanel.innerHTML = Rets[1];
			
	//		map.redraw();
		}
		
		if( Rets[2] != null && Rets[2] != "" )
		{
			// Change the button to the appropriate icon.
			var ResultButtonTableColumn = GetElementByID( "gtgResultButtons" );
			var Buttons = ResultButtonTableColumn.getElementsByTagName("img");
			
			var btnList = Rets[2].split(":::");
			
			if( btnList.length == Buttons.length )
			{
				for( var i=0; i<btnList.length; i++ )
				{
					Buttons[i].src = btnList[i];
				}
			}
		}
		
		if( Rets[4] != null )
		{
			GetElementByID("ReportsPopup_ReportData").innerHTML = Rets[4];
		}
			
		if( Rets[3] != null && Rets[3] != "" )
		{
			processCallbackResult( Rets[3] );
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processResultTableCallback(callback) { GTG_Common.js }" );
	}
}

function ResultRowClicked( obj, color1, color2 )
{
	try
	{
		var table = GetElementByID( "ResultTableOutput" );  
		var rows = table.getElementsByTagName("tr");
		
		for(i = 0; i < rows.length; i++)
		{
			if(i % 2 == 0)
			{
				obj.style.backgroundColor  = "";
			}
			else
			{
				obj.style.backgroundColor  = "";
			}
		}

	//	obj.style.backgroundColor  = "rgb(145, 176, 251)";
		obj.style.backgroundColor  = "rgb(167, 216, 252)";
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ResultRowClicked( obj, color1, color2 ) { GTG_Common.js }" );
	}
}

function FindAddyGenerateCallback()
{
	try
	{
		if( GetElementByID('m_ResultsPanel_div').style.display == 'none' )
		{
			GetElementByID('m_ResultsPanel_div').style.display = '';
			GTG_Resize();
		}

		// Hide the Find Selector
		GetElementByID("m_FindSelectorBubble_table").style.display = "none";
		
		// Make the Find addy popup disappear.
		GetElementByID("m_FindAddressBubble_table").style.display = "none";
		
		// Set some text at the bottom so that the user knows the search is being performed.
		var fpBody = document.getElementById( 'ResultsPanel_Content' );
		fpBody.innerHTML = "<div><img src='images/callbackActivityIndicator.gif' align='middle'/> Getting Information. . .</div>";

		var Zone = "";
		var ZoneObj = GetElementByID("FindAddress_Zone");
		
		if( ZoneObj != null )
		{
			Zone = ZoneObj.value;
		}

		var message = "ControlType=FindAddress&Addy=" + GetElementByID("FindAddress_AddyField").value + "&Zone=" + Zone;
		var context = "me";
		
		eval( GeoCodeFindAddressCallbackFcnStr );
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in FindAddyGenerateCallback() { GTG_Common.js }" );
	}
}

function GenerateIntersectionList()
{
	try
	{
		var message = "ControlType=FindIntersection&EventArg=GetIntersectingStreets&Street1=" + document.form1.FindStreet_Street1[document.form1.FindStreet_Street1.selectedIndex].value;
		var context = "me";
		
		eval( FindIntersectionCallbackFunction );
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GenerateIntersectionList() { GTG_Common.js }" );
	}
}

function FindIntersectionCallback()
{
	try
	{
		// Hide the Find Selector
		GetElementByID("m_FindSelectorBubble_table").style.display = "none";

		// Hide the Find Intersection popup
		GetElementByID("m_FindIntersectionBubble_table").style.display = "none";

		var StreetSearch;
		var message = "";
		
		for( var i=0; i<document.form1.IntersectionOrStreet.length; i++ )
		{
			if( document.form1.IntersectionOrStreet[i].checked )
			{
				StreetSearch = i;
			}
		}
		
		if( StreetSearch == 0 )
		{
				message = "ControlType=FindIntersection&EventArg=FindStreet&Street1=" + 
					document.form1.FindStreet_Street1.selectedIndex;
		}
		else
		{
			message = "ControlType=FindIntersection&EventArg=GetIntersection&Street1=" + document.form1.FindStreet_Street1[document.form1.FindStreet_Street1.selectedIndex].value
				+ "&Street2=" + document.form1.FindStreet_Street2[document.form1.FindStreet_Street2.selectedIndex].value;
		}
		
		var context = "me";
		
		eval( FindIntersectionCallbackFunction );
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in FindIntersectionCallback() { GTG_Common.js }" );
	}
}

function processFindIntersection( callback )
{
	try
	{
		var splitVals = callback.split(";;;");
		
		if( splitVals[0] == "IntersectionList" )
		{
			// Make sure to clear it first
			var selectList = document.getElementById("FindStreet_Street2");
			
			while(selectList.lastChild)
			{
				selectList.removeChild(selectList.lastChild);
			}


			var Obj = document.form1.FindStreet_Street2;
			var values = splitVals[1].split(":::");
			
			var selObj = document.forms["form1"].elements["FindStreet_Street2"];
			var option = document.createElement("option");

			for(var count = 0; count < values.length-1; ++count)
			{
				var myOption = option.cloneNode(false);
				myOption.value = values[count];
				myOption.appendChild(document.createTextNode(values[count]));
				selObj.appendChild(myOption);
			}
		}
		else if( splitVals[0] == "IntersectionFound" )
		{
			processCallbackResult( splitVals[2] );
		}
		else if( splitVals[0] == "StreetFound" )
		{
			processCallbackResult( splitVals[2] );
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processFindIntersection( callback ) { GTG_Common.js }" );
	}
}

function ShowFindItem( item )
{
	try
	{
		var ToolTable = GetElementByID("m_FindSelectorBubble_table");
		var pos = findPos(ToolTable);
		var FindObjects = new Array( "m_FindAddressBubble_table", "m_FindIntersectionBubble_table" );
	  
		GTGToolbarOpenedItem = FindObjects[item];
	  
		// Make all the items invisible
		for( var i=0; i<FindObjects.length; i++ )
		{
			GetElementByID( FindObjects[i] ).style.display = "none";
		}
		
		// Set the item visible
		GetElementByID( FindObjects[item] ).style.display = "";
		GetElementByID( FindObjects[item] ).style.visibility = "visible";
	    
		var IDToolbar = GetElementByID( FindObjects[item] );
		IDToolbar.style.left = pos[0] + "px";
		IDToolbar.style.top = pos[1] + ToolTable.clientHeight + "px";
	    
		if( FindObjects[item] == "m_FindAddressBubble_table" )
		{
			var addy = GetElementByID("FindAddress_AddyField");
			
			addy.focus();
			addy.select();
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ShowFindItem( item ) { GTG_Common.js }" );
	}
}

function VerifyNumbers(evt, bDecPoint)
{
	try
	{
		if( evt.keyCode >= 48 && evt.keyCode <= 57 || evt.keyCode == 8 || evt.keyCode == 46 || 
			evt.charCode >= 48 && evt.charCode <= 57 || evt.charCode == 8 || evt.charCode == 46 ||
			evt.keyCode >=37 && evt.keyCode <= 40 || evt.keyCode >= 96 && evt.keyCode <= 105  )
		{
			return true;
		}
		else if( bDecPoint )
		{
			if( evt.keyCode == 46 )
				return true;
			else if( evt.charCode == 99 )
				return true;
		}
		
		return false;
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in VerifyNumbers(evt, bDecPoint) { GTG_Common.js }" );
	}
}

var GTGToolbarOpenedItem = null;

function GTGToolbar_OnClick(evt, table, popup)
{
	try
	{
		// Try to close the opened window
		if( GTGToolbarOpenedItem )
			GetElementByID( GTGToolbarOpenedItem ).style.visibility = "hidden";
			
		if( popup )
		{
			var popupObj = GetElementByID( popup );
			
			if( popupObj == GTGToolbarOpenedItem )
			{
				GTGToolbarOpenedItem = null;
			}
			else
			{
				GTGToolbarOpenedItem = popupObj;
				
				GTGToolbarOpenedItem.style.visibility = "visible";
			}
		}
		
		var cells = GetElementByID(table).getElementsByTagName("td");
		
		for( var i=0; i<cells.length; i++ )
		{
			cells[i].style.border = "1px none black";
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in GTGToolbar_OnClick(evt, table, popup) { GTG_Common.js }" );
	}
}

// This is called whenever the lat/long button is pressed.
function OpenLatLont()
{
	try
	{
//		GTGToolbarOpenedItem = "LatLongToolbar";

		var map = Maps["m_Map"];
		//MapPoint(map.controlName, "LatLong", false);
		//map.divObject.onmousedown = LatLongCallback;
		
		if (map!=null) {
			map.getGeometry(ESRI.ADF.Graphics.ShapeType.Point,LatLongCallback,null,'black',null,'pointer', true);        
		}     
	
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in OpenLatLont() { GTG_Common.js }" );
	}
}

function LatLongCallback(e)
{
	try
	{
		// Clear the errors
		GetElementByID("LatLongErrors").innerHTML = "";
		
		var inputs = GetElementByID("LatLongToolbar").getElementsByTagName("input");
		
		for( var i=0; i<inputs.length; i++ )
		{
			inputs[i].style.backgroundColor = "";
		}
		
		var map = Maps["m_Map"];
		map.cursor = map.divObject.style.cursor;

		//getXY(e);
		//var box = calcElementPosition(map.containerDivId);
		//zleft = mouseX - box.left;
		//ztop = mouseY - box.top;

		geomString = e.toString(':');
		var split = geomString.split(':');
		
		var message = "ControlID=Map1&ControlType=Map&minx=" + split[0] + "&miny=" + split[1] + "&Func=GetLatLong";
		var context = map.controlName;
		
		eval(LatLongCallbackFunction);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in LatLongCallback(e) { GTG_Common.js }" );
	}
}

function processLatLongCallback( callback )
{
	try
	{
		var split = callback.split( ";;;" );
		
		
		// Option 1: Lat/Long coords returned
		if( split[0] == "GetLatLong" )
		{
			// Anything else is incorrect
			if( split.length == 9 )
			{
				document.form1.DMS_Lat_Degree.value = split[1];
				document.form1.DMS_Lat_Minutes.value = split[2];
				document.form1.DMS_Lat_Seconds.value = split[3];
				
				document.form1.DMS_Lon_Degree.value = split[4];
				document.form1.DMS_Lon_Minutes.value = split[5];
				document.form1.DMS_Lon_Seconds.value = split[6];
				
				document.form1.LLDec_Longitude.value = split[7];
				document.form1.LLDec_Latitude.value = split[8];
			}
		}
		else
		{
			if( split.length == 2 )
			{
				processCallbackResult(split[1]);
			}
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in processLatLongCallback( callback ) { GTG_Common.js }" );
	}
}

function EnableLatLong( option )
{
	try
	{
		if( option == 0 )
		{
			
			GetElementByID("LLDec_Longitude").disabled = "disabled";
			GetElementByID("LLDec_Latitude").disabled = "disabled";
			
			GetElementByID("DMS_Lat_Degree").disabled = "";
			GetElementByID("DMS_Lat_Minutes").disabled = "";
			GetElementByID("DMS_Lat_Seconds").disabled = "";
			
			GetElementByID("DMS_Lon_Degree").disabled = "";
			GetElementByID("DMS_Lon_Minutes").disabled = "";
			GetElementByID("DMS_Lon_Seconds").disabled = "";
		}
		else
		{
			GetElementByID("LLDec_Longitude").disabled = "";
			GetElementByID("LLDec_Latitude").disabled = "";
			
			GetElementByID("DMS_Lat_Degree").disabled = "disabled";
			GetElementByID("DMS_Lat_Minutes").disabled = "disabled";
			GetElementByID("DMS_Lat_Seconds").disabled = "disabled";
			
			GetElementByID("DMS_Lon_Degree").disabled = "disabled";
			GetElementByID("DMS_Lon_Minutes").disabled = "disabled";
			GetElementByID("DMS_Lon_Seconds").disabled = "disabled";
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in EnableLatLong( option ) { GTG_Common.js }" );
	}
}

function FindLatLongCallback()
{
	try
	{
		// Clear the errors
		GetElementByID("LatLongErrors").innerHTML = "";
		
		var inputs = GetElementByID("LatLongToolbar").getElementsByTagName("input");
		
		for( var i=0; i<inputs.length; i++ )
		{
			inputs[i].style.backgroundColor = "";
		}
		

		var message = "ControlID=Map1&ControlType=Map&Func=FindLatLong&Lat=";
		var FindLatLong = 0;
		
		for( var i=0; i<document.form1.LatLongType.length; i++ )
		{
			if( document.form1.LatLongType[i].checked )
			{
				FindLatLong = i;
				break;
			}
		}
		
		var Lat;
		var Long;
		
		// Based on what is checked, postback those results
		if( FindLatLong == 0 )
		{
			var bError = false;
			var LatDegree = parseInt(document.form1.DMS_Lat_Degree.value);
			
			if( isNaN( LatDegree ) )
			{
				LatDegree = 0;
			}
			
			if( LatDegree < 0 || LatDegree > 180 )
			{
				AddError( "LatLongErrors", "Latitude Degrees must be between 0 and 180", "DMS_Lat_Degree" );
				bError = true;
			}
			
			var LatMinutes = parseInt(document.form1.DMS_Lat_Minutes.value) / 60;
			
			if( isNaN( LatMinutes ) )
			{
				LatDegree = 0;
			}
			
			if( LatMinutes < 0 || LatMinutes >= 1 )
			{
				AddError( "LatLongErrors", "Latitude Minutes must be between 0 and 59", "DMS_Lat_Minutes" );
				bError = true;
			}
			
			var LatSeconds = parseFloat(document.form1.DMS_Lat_Seconds.value) / 3600;
			
			if( isNaN( LatSeconds ) )
			{
				LatDegree = 0;
			}
			
			if( LatSeconds < 0 || LatSeconds >= (60/3600) )
			{
				AddError( "LatLongErrors", "Latitude Seconds must be between 0 and 59", "DMS_Lat_Seconds" );
				bError = true;
			}
			
			Lat = LatDegree + LatMinutes + LatSeconds;
			
			var LongDegree = parseInt(document.form1.DMS_Lon_Degree.value);
			
			if( isNaN( LongDegree ) )
			{
				LongDegree = 0;
			}
			
			if( LongDegree < 0 || LongDegree > 180 )
			{
				AddError( "LatLongErrors", "Longitude Degrees must be between 0 and 180", "DMS_Lon_Degree" );
				bError = true;
			}
			
			var LongMinutes = parseInt(document.form1.DMS_Lon_Minutes.value) / 60;
			
			if( isNaN( LongMinutes ) )
			{
				LongMinutes = 0;
			}
			
			if( LongMinutes < 0 || LongMinutes >= 1 )
			{
				AddError( "LatLongErrors", "Longitude Minutes must be between 0 and 59", "DMS_Lon_Minutes" );
				bError = true;
			}
			
			var LongSeconds = parseFloat(document.form1.DMS_Lon_Seconds.value) / 3600;
			
			if( isNaN( LongSeconds ) )
			{
				LongSeconds = 0;
			}
			
			if( LongSeconds < 0 || LongSeconds >= (60/3600) )
			{
				AddError( "LatLongErrors", "Longitude Seconds must be between 0 and 59", "DMS_Lon_Seconds" );
				bError = true;
			}
			
			if( bError )
				return false;
					
			Long = LongDegree + LongMinutes + LongSeconds;
			
			
			if( Lat < GTGLatitudeMin || Lat > GTGLatitudeMax || isNaN( Lat ) )
			{
				var LatMin = ConvertLatToDegreesMinsSecs(GTGLatitudeMin);
				var LatMax = ConvertLatToDegreesMinsSecs(GTGLatitudeMax);

				AddError( "LatLongErrors", "Acceptable Latitude is " +
					LatMin[0] + " ° " + LatMin[1] + " \' " + truncate(LatMin[2], 2) + " \" and " + 
					LatMax[0] + " ° " + LatMax[1] + " \' " + truncate(LatMax[2], 2) + " \" ", "DMS_Lat_Degree" );
					
				GetElementByID("DMS_Lat_Minutes").style.backgroundColor = "red";
				GetElementByID("DMS_Lat_Seconds").style.backgroundColor = "red";
					
				bError = true;
			}
			
			if( Long < GTGLongitudeMin || Long > GTGLongitudeMax || isNaN( Long ))
			{
				var LatMin = ConvertLatToDegreesMinsSecs(GTGLongitudeMin);
				var LatMax = ConvertLatToDegreesMinsSecs(GTGLongitudeMax);

				AddError( "LatLongErrors", "Acceptable Longitude is " +
					LatMin[0] + " ° " + LatMin[1] + " \' " + truncate(LatMin[2], 2) + " \" and " + 
					LatMax[0] + " ° " + LatMax[1] + " \' " + truncate(LatMax[2], 2) + " \"", "DMS_Lon_Degree" );
				
				GetElementByID("DMS_Lon_Minutes").style.backgroundColor = "red";
				GetElementByID("DMS_Lon_Seconds").style.backgroundColor = "red";
				
				bError = true;
			}
			
			if( bError )
				return false;
		}
		else
		{
			var bError = false;
			Lat = parseFloat( document.form1.LLDec_Latitude.value );
			Long = parseFloat( document.form1.LLDec_Longitude.value );
			
			if( Lat < GTGLatitudeMin || Lat > GTGLatitudeMax || isNaN( Lat ) )
			{
				AddError( "LatLongErrors", "Acceptable Latitude is " +
					truncate(GTGLatitudeMin, 5) + " and " + truncate(GTGLatitudeMax, 5), "LLDec_Latitude" );
				bError = true;
			}
			
			if( Long < GTGLongitudeMin || Long > GTGLongitudeMax || isNaN( Long ))
			{
				AddError( "LatLongErrors", "Acceptable Longitude is " +
					truncate(GTGLongitudeMin, 5) + " and " + truncate(GTGLongitudeMax, 5), "LLDec_Longitude" );
				bError = true;
			}
			
			if( bError )
				return false;
		}
		
		message += Lat;
		message += "&Long=" + Long;
		
		var map = Maps["m_Map"];
		var context = map.controlName;
		eval(LatLongCallbackFunction);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in FindLatLongCallback() { GTG_Common.js }" );
	}
}

function truncate ($num, $digits ) 
{
	try
	{
		$shift = Math.pow(10, $digits);
		return ((Math.floor($num * $shift)) / $shift);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in truncate ($num, $digits )  { GTG_Common.js }" );
	}
}

function AddError(ObjID, Error, ErrorInputID)
{
	try
	{
		var obj = GetElementByID(ObjID);
		obj.innerHTML += " - " + Error + "<br/>";
		
		GetElementByID(ErrorInputID).style.backgroundColor = "red";
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in AddError(ObjID, Error, ErrorInputID) { GTG_Common.js }" );
	}
}

function ConvertLatToDegreesMinsSecs( Lat )
{
	try
	{
		var iLatDegrees = Math.floor(Lat)

		// Save us some time, save this
		var fLatMinutes = (Lat - iLatDegrees) * 60

		var iLatMins = Math.floor(fLatMinutes)
		var fLatSecs = (fLatMinutes - Math.floor(fLatMinutes)) * 60

		return new Array(iLatDegrees, iLatMins, fLatSecs);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ConvertLatToDegreesMinsSecs( Lat ) { GTG_Common.js }" );
	}
}

function ConvertLongToDegreesMinsSecs( Long )
{
	try
	{
		var iLongDegrees = Math.floor(Long)

		// Save us some time, save this
		var fLongMinutes  = (Long - iLongDegrees) * 60

		var iLongMins = Math.floor(fLongMinutes)
		var fLongSecs = (fLongMinutes - Math.floor(fLongMinutes)) * 60
		
		return new Array(iLongDegrees, iLongMins, fLongSecs);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ConvertLongToDegreesMinsSecs( Long ) { GTG_Common.js }" );
	}
}

function ModifyToolbarImageSizes( iSize, clientHeight )
{
	try
	{
		var Images = GetElementByID("m_NavToolbarPanel_m_GTGToolbar").getElementsByTagName("img");
		GetElementByID("m_NavToolbarPanel_m_GTGToolbar").style.height = clientHeight + "px";
		
		for( var i=0; i<Images.length; i++ )
		{
			if( iSize > 0 )
			{
				Images[i].style.width = iSize + "px";
				Images[i].style.height = iSize + "px";
			}
			else
			{
				Images[i].style.width = "";
				Images[i].style.height = "";
			}
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in ModifyToolbarImageSizes( iSize, clientHeight ) { GTG_Common.js }" );
	}
}

function gtgClearData()
{
	try
	{
		removeSpatialSearchGraphic();
	
		var message = "ControlType=ClearData";
		var context = "me";
		
		eval(identifyCallbackFunctionString);
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in gtgClearData() { GTG_Common.js }" );
	}
}

function ShowResultsPanel()
{
	try
	{
		if( GetElementByID('m_ResultsPanel_div').style.display == 'none' )
		{
			GetElementByID('m_ResultsPanel_div').style.display = '';
			GTG_Resize();
		}
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in AdjustMapSize() { GTG_Common.js }" );
	}
}

function Sleep( iMilliseconds )
{
	try
	{
		var sleeping = true;
		var now = new Date();
		var alarm;
		var startingMSeconds = now.getTime();

		while(sleeping)
		{
			alarm = new Date();
			alarmMSeconds = alarm.getTime();
			if( alarmMSeconds - startingMSeconds > iMilliseconds )
			{
				sleeping = false; 
			}
		}      
	}
	catch( ex )
	{
		SendErrorToServer( ex.message + " in Sleep( iMilliseconds ) { GTG_Common.js }" );
	}
}

// All javascript exceptions should be sent here
function SendErrorToServer( ErrorMsg )
{
	var map = Maps["m_Map"];
	var message = "ControlType=ClientException&Error=" + ErrorMsg;
	var context = map.controlName;
	
	eval(map.identifyCallbackFunctionString);
}

function ClosePopupWindow( id )
{
	var obj = GetElementByID(id);
	obj.style.visibility = "hidden";
}

var iZidx = 310;

function gtgUpdateZ( name ) 
{
    var obj = GetElementByID( name );
    iZidx += 1;
    obj.style.zIndex = iZidx;
} 
