var MappingURLStart = '/intierra/indexResize.php';
var MappingURL = '/intierra/index.phtml';
var MappingURLSize = '?map_width=' + (screen.width - 390) + '&map_height=' + ((screen.width - 390) / 2);
var MappingPoppedOut = false;
var MappingMinimized = false;
var MapWindow;
var Refreshing = false;
var MappingLeft = 0;
var MappingTop = 0;
var PopOutParams = '';
function ShowMap(Parameters)
{
	if (Refreshing == false)
	{
		Refreshing = true;
		var MappingComponent;
		if (MappingPoppedOut)
		{
			MappingComponent = MapWindow.frames[0];
			MapWindow.focus();
		}
		else
		{
			//Show mapping within Ozmine window 
			MappingComponent = window.frames['MappingFrame']
			if (MappingMinimized)
			{
				Max();
			}
		}
		//if MappingComponent was found
		if (MappingComponent)
		{
		
			if (MappingComponent.location.href.indexOf(MappingURL) > 0)
			{
			
				if (Parameters != '' && Parameters != null)
				{
					var x = Parameters.split(',');
					var y = Parameters.split('|');
					if ((x.length - y.length) == 6)
					{
						eval('MappingComponent.changeLayersAndZoomHighlight(' + Parameters + ')');
					}
					else
					{
						eval('MappingComponent.changeLayersAndZoom(' + Parameters + ')');
					}
				}
			}
			else
			{
				StartTime = new Date();
				ShowProgress('Establishing Server Connection...', 0);
				MappingComponent.location.href = MappingURLStart + MappingURLSize + '&params=' + Parameters;
			}
			var Timeout = window.setTimeout(ClearRefresh, 1000);
		}
		else
		{
			alert('Mapping system not found. Please contact Intierra');
		}
	}
	Refreshing = false;
	return false; //always return false, to cancel any default hyperlink actions
}
function ClearRefresh()
{
	Refreshing = false;
}
function Min()
{
//	document.getElementById('OzMine').style.height = '100%';
//	document.getElementById('OzMine').style.width = '100%';
document.getElementById('OzMine').style.display = 'block';
document.getElementById('OzMineMenu').style.display = 'none';
	Mapping.style.display = 'none';
	MappingMinimized = true;
	return false;
}

function Max()
{
	if (!MappingPoppedOut)
	{
//alert(document.getElementById('OzMine').frame);
//	window.frames[0].size.height = '10px';
		//alert(window.frames[0].id + ' - ' + );
//		document.getElementById('OzMine').style.height = '10px';
//		document.getElementById('OzMine').style.width = '110%';
document.getElementById('OzMine').style.display = 'none';
document.getElementById('OzMineMenu').style.display = 'block';
		Mapping.style.display = 'block';
		MappingMinimized = false;
	}
	return ShowMap('');
}
function PopOut(Parameters)
{
	Min();
	var TempString = '';
	if (MapWindow == null)
	{
		if (MappingLeft >= 0) TempString += 'left=' + MappingLeft;
		if (MappingTop >= 0) TempString += ',top=' + MappingTop;
		MapWindow = window.open('../MappingPopup.htm', 'MapWindow', TempString + ',resizable=yes,width=1375,height=711,status=no', 'true');
	}
	MappingPoppedOut = true;
}
function PopIn()
{
	MappingPoppedOut = false;
	MapWindow = null;
}
function KillWindows()
{
	if (MappingPoppedOut)
	{
		MapWindow.close();
	}
}

function ShowProperty(PropID)
{
	document.getElementById('OzMine').src = 'ShowProp.asp?ID=' + PropID;
	if (!MappingPoppedOut && !MappingMinimized)
	{
		Min();
	}
	window.focus();
}

function GOTOCAPS(DocumentName)
{
 	window.document.frames[0].location = DocumentName;
	if (!MappingPoppedOut && !MappingMinimized)
	{
		Min();
	}
	window.focus();
}

function ShowCompany(CompanyID)
{
	document.getElementById('OzMine').src = 'ShowCoy.asp?ID=' + CompanyID;
	if (!MappingPoppedOut && !MappingMinimized)
	{
		Min();
	}
	window.focus();
}
function ShowNews(NewsID)
{
	document.getElementById('OzMine').src = 'ShowNewswire.asp?ID=' + NewsID;
	if (!MappingPoppedOut && !MappingMinimized)
	{
		Min();
	}
	window.focus();
}
function PageResize()
{
	if (document.implementation && document.implementation.createDocument)
	{
		if (document.body.offsetHeight > 45)
		{
			Mapping.style.height = (document.body.offsetHeight - 45) + 'px';
		}
	}
	else
	{
		if (document.body.offsetHeight > 72)
		{
			Mapping.style.height = (document.body.offsetHeight - 72) + 'px';
		}
	}
}

function MapWindowLoaded(Window)
{
	var TheForm = window.frames['MappingFrame'].document.forms[0];
	var ParamString = '';
	
	for (Counter=0;Counter<TheForm.elements.length;Counter++)
	{
		if (TheForm.elements[Counter].type == 'checkbox')
		{
			if (TheForm.elements[Counter].checked && (TheForm.elements[Counter].id != 'Labelling' && TheForm.elements[Counter].id != 'autolegend'))
			{
				ParamString += TheForm.elements[Counter].id + '|1,';
			}
		}
	}
	ParamString += window.frames['MappingFrame'].goCWCJSAPI.oMap.minx + ',';
	ParamString += window.frames['MappingFrame'].goCWCJSAPI.oMap.miny + ',';
	ParamString += window.frames['MappingFrame'].goCWCJSAPI.oMap.maxx + ',';
	ParamString += window.frames['MappingFrame'].goCWCJSAPI.oMap.maxy;

	MappingPoppedOut = true;
	MapWindow = Window;
	ShowMap(ParamString);
	//Nick removed next line to avoid JS error in IE.
	//event.cancelBubble = true;
	if (event != null) event.cancelBubble = true;
}
