// ALL FUNCTIONS COPYRIGHT IME (UK) LTD 2004
// ALL RIGHTS RESERVED
// 06/09/04
function cmdPreviewMap()
{
	var mapObj = parent.iFrmMap.formMap;
	// verify data
	var szDataType = document.frmMapURL.selDataType.options[document.frmMapURL.selDataType.selectedIndex].value;
	var txtDataValue = document.frmMapURL.txtDataValue.value;
	var szSelDept = document.frmMapURL.selDept.options[document.frmMapURL.selDept.selectedIndex].value;
	//var BgC = document.frmMapURL.selBGcolour.value;
	var BgC = document.frmMapURL.szBGcolour[0].checked;
	var szWidth = document.frmMapURL.selZoomWidth.options[document.frmMapURL.selZoomWidth.selectedIndex].value;
	var Width = document.frmMapURL.selMapWidth.options[document.frmMapURL.selMapWidth.selectedIndex].value;
	var Height = document.frmMapURL.selMapWidth.options[document.frmMapURL.selMapWidth.selectedIndex].value;
	var szBgMapping = document.frmMapURL.selBgMapping.checked;
	var szZoomIn = document.frmMapURL.selZoomIn.checked;
	var szZoomOut = document.frmMapURL.selZoomOut.checked;
	var szPan = document.frmMapURL.selPan.checked;
	//var szUnZoom = document.frmMapURL.selUnZoom.checked;
	var szSearch = document.frmMapURL.selSearch.checked;
	var szPlanning = document.frmMapURL.selPlanning.checked;	
	var szRoads = document.frmMapURL.selRoads.checked;
	var szSelect = document.frmMapURL.selSelect.checked;
	//Gets the value from the department select list and appends the layers selected 			
	szSelLayer = "";
	
	if (true == BgC)
	{
		BgC = "cacaff";
	}
	else
	{
		BgC = "e8e8ff";
	} 
	
	// DEFAULT LAYERS		
	if (true == szBgMapping)
	{
		szMapname = "BACKGROUND.MWF";
		
		for (i = 0; i < document.frmMapURL.selLayer.options.length; i++) 
	    {
			
			szSelLayer = document.frmMapURL.selLayer.options[i].value;
			szMapname =   szMapname + ",DEPARTMENTS.MWF\\" + szSelLayer;	
		}		
	}
	else
	{
		szMapname = "";
		
		for (i = 0; i < document.frmMapURL.selLayer.options.length; i++) 
	    {
			szSelLayer =   document.frmMapURL.selLayer.options[i].value;
			szMapname =  szMapname + "DEPARTMENTS.MWF\\" + szSelLayer;
		}
	}
	//OPTIONAL LAYERS
	if (document.frmMapURL.selLayer_Other.options.length > 0)
	{
	
	var szOptionalLayers = "";
		for (i = 0; i < document.frmMapURL.selLayer_Other.options.length; i++) 
	    {
			szSelLayer_Other = document.frmMapURL.selLayer_Other.options[i].value;
			szOptionalLayers =  szOptionalLayers + ",DEPARTMENTS.MWF\\" + szSelLayer_Other;		
		}
	}

	//Error trapping to ensure a datavalue and layer group are selected
	if ("" == szDataType)
	{
		alert('Please select a data value to centre the map');
		frmMapURL.txtDataValue.focus();
		return false;
	}
	
	if ("" == txtDataValue )
	{
		alert('Please enter a data value to centre the map');
		frmMapURL.txtDataValue.focus();
		return false;
	}
			
	if (false == szBgMapping & "" == szSelDept)
	{
		alert('You must select either background mapping or an individual layer from the list of layer groups.');
		return false;
	}

	//Create pgGenericMap URL
	szURL = '../publicfiles/site/pgGenericMap.cfm?szMapname=' + szMapname + '&szOptionalLayers=' + szOptionalLayers + '&szSearch=' + szSearch + '&szZoomIn=' + szZoomIn + '&szZoomOut=' + szZoomOut + '&szPan=' + szPan + '&szSelect=' + szSelect + '&szWidth=' + szWidth + '&BgC=' + BgC + '&txtDataValue=' + txtDataValue + '&szDataType=' + szDataType + '&szRoads=' + szRoads + '&szPlanning=' + szPlanning + '&Width=' + Width + '&Height=' + Height;
	parent.iFrmMap.location = szURL;
	
	// code snippet url
	szURL = '../publicfiles/site/pgCodeSnippet.cfm?szURL=gis.east-ayrshire.gov.uk/UniversalMapping/publicfiles/site/pgGenericMap.cfm!szMapname=' + szMapname + ':szOptionalLayers=' + szOptionalLayers + ':szSearch=' + szSearch + ':szZoomIn=' + szZoomIn + ':szZoomOut=' + szZoomOut + ':szPan=' + szPan + ':szSelect=' + szSelect + ':szWidth=' + szWidth + ':BgC=' + BgC + ':txtDataValue=' + txtDataValue + ':szDataType=' + szDataType + ':szRoads=' + szRoads + ':szPlanning=' + szPlanning + ':Width=' + Width + ':Height=' + Height;
	parent.iFrmEAC.location = szURL;

	showIF('Map', 'Options');
}
//Function to show/hide Map and Options IFrames.
function showIF(what, whatNot)
{
	var Height = document.frmMapURL.selMapWidth.options[document.frmMapURL.selMapWidth.selectedIndex].value;
	
	showiFrameID = "iFrm" + what;
	hideiFrameID = "iFrm" + whatNot;
	var oShowiFrame = parent.document.getElementById(showiFrameID);
	var oHideiFrame = parent.document.getElementById(hideiFrameID); 
	oHideiFrame.height = 0;
	oHideiFrame.width = 0;
	//oShowiFrame.height = 600;
	
	if ("iFrmMap" == showiFrameID & "200" == Height)
	{
		oShowiFrame.height = 285;
		oShowiFrame.width = 235;
	}
	else if ("iFrmMap" == showiFrameID & "300" == Height)
	{
		oShowiFrame.height = 420;
		oShowiFrame.width = 360;
	}
	else if ("iFrmMap" == showiFrameID & "400" == Height)
	{
		oShowiFrame.height = 600;
		oShowiFrame.width = 455;
	}	
	else if ("iFrmMap" == showiFrameID & "500" == Height)
	{
		oShowiFrame.height = 650;
		oShowiFrame.width = 570;
	}	
	
	else if ("iFrmMap" == showiFrameID & "600" == Height)
	{
		oShowiFrame.height = 750;
		oShowiFrame.width = 655;
	}	
	else
	{
		oShowiFrame.height = 1000;
		oShowiFrame.width = 800;
	}
}
//Function to move selected items between select boxes
function moveOption(from,index,to) 
 {
   var origOpt = from.options[index];
   var newOpt = new Option(origOpt.text,origOpt.value);
   from.options[index]=null;
   to.options[to.options.length] = newOpt;
 }

function moveSelectedOptions(from,to) 
 {
   var i=0;
   while (i<from.options.length) 
   {
      if (from.options[i].selected) 
	  {
         from.options[i].selected=false;
         moveOption(from,i,to);
      } 
	  else 
	  {
         i++;
      }
   }     
 }

function cmdSetZoommode(cmdmode)
{
	var mapObj = parent.iFrmMap.formMap;
//Swith function for navigation buttons, setting the mode, target and action
	switch (cmdmode)
	{
		case "Pan":
			mapObj.action = "pgGenericMap.cfm";
			mapObj.target = "iFrmMap";
			mapObj.mode.value = "Pan";
			
		break	
		case "ZoomIn":
			mapObj.action = "pgGenericMap.cfm";
			mapObj.target = "iFrmMap";
			mapObj.mode.value = "ZoomIn";
		break	
		case "ZoomOut":
			
			mapObj.action = "pgGenericMap.cfm";
			mapObj.target = "iFrmMap";
			mapObj.mode.value = "ZoomOut";
		break	
		case "Selected":
			mapObj.action = "rpFeatureInfo.cfm";
			mapObj.target = "iFrmResults";
			mapObj.mode.value = "Selected";
		break
	}
	
	//mapObj.txtDataValue.value = "";
}
//UnZoom Map function to recenter map
function cmdRecenter()
{
	var mapObj = parent.iFrmMap.formMap;

	mapObj.xBL.value = "210000";
	mapObj.yBL.value = "580000";
	mapObj.xTR.value = "290000";
	mapObj.yTR.value = "660000";
	
	//mapObj.xBL.value = "183000";
	//mapObj.yBL.value = "565000";
	//mapObj.xTR.value = "293000";
	//mapObj.yTR.value = "675000";
	
	mapObj.action = "pgGenericMap.cfm";
	mapObj.target = "iFrmMap";
	mapObj.mode.value = "ready";
	mapObj.txtDataValue.value = "";
	mapObj.submit();	
}
	// TOOLTIP FUNCTIONS
	var ie = document.all ? 1 : 0
	var ns = document.layers ? 1 : 0
	
	if(ns){doc = "document."; sty = ""}
	if(ie){doc = "document.all."; sty = ".style"}
	
	var initialize = 0
	var Ex, Ey, topColor, subColor, ContentInfo
	
	if(ie){
		Ex = "event.x - 155"
		Ey = "event.y + 10"
		
		topColor = "#ffff99"
		subColor = "#fdf9e9"
	}
	
	if(ns){
		Ex = "e.pageX"
		Ey = "e.pageY"
		window.captureEvents(Event.MOUSEMOVE)
		window.onmousemove=overhere
		
		topColor = "#fdf9e9"
		subColor = "#ffff99"
	}

	function MoveToolTip(layerName, FromTop, FromLeft, e)
	{
		if(ie){eval(doc + layerName + sty + ".top = "  + (eval(FromTop) + document.body.scrollTop))}
		if(ns){eval(doc + layerName + sty + ".top = "  +  eval(FromTop))}
		eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))
	}
	
	function ReplaceContent(layerName)
	{
		if(ie){document.all[layerName].innerHTML = ContentInfo}
		if(ns){
				with(document.layers[layerName].document) 
				{ 
	   				open(); 
	   				write(ContentInfo); 
	   				close(); 
				}
			}
	}

	function Activate(){initialize=1}
	function deActivate(){initialize=0}
	
	function overhere(e)
	{
		if(initialize)
		{
			MoveToolTip("ToolTip", Ey, Ex, e)
			eval(doc + "ToolTip" + sty + ".visibility = 'visible'")
		}
		else
		{
			MoveToolTip("ToolTip", 0, 0)
			eval(doc + "ToolTip" + sty + ".visibility = 'hidden'")
		}
	}
	
	
	function EnterContent(layerName, TTitle, TContent)
	{
		ContentInfo = '<table style="1px solid black" width="190" cellspacing="0" cellpadding="0">'+
		'<tr><td width="100%" bgcolor="#000000">'+
		
		'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
		'<tr><td width="100%" bgcolor='+topColor+'>'+
		
		'<table border="0" width="90%" cellspacing="0" cellpadding="0" align="center">'+
		'<tr><td width="100%">'+
		
		'<font class="tooltiptitle">'+TTitle+'</font>'+
		
		'</td></tr>'+
		'</table>'+
		
		'</td></tr>'+
		
		'<tr><td width="100%" bgcolor='+subColor+'>'+
		
		'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+
		
		'<tr><td width="100%">'+
		
		'<font class="tooltipcontent"><BR>'+TContent+'<BR><BR></font>'+
		
		'</td></tr>'+
		'</table>'+
		
		'</td></tr>'+
		'</table>'+
		
		'</td></tr>'+
		'</table>';
		
		ReplaceContent(layerName)
	}
	// END TOOLTIP FUNCTIONS
	
