var State;
   
  	var IE4 = (document.all) ? true : false;
  	var NS4 = (document.layers) ? true : false;
	var ViewState = "";
	var ViewCount = 4;
	var View0DisplayCount = 8;
	var View1DisplayCount = 8;
	var View2DisplayCount = 8;
	var View3DisplayCount = 8;
	//var ScriptPath= "http://192.168.3.2/scripts/map.dll/";
	//var ScriptPath= "http://www.globalimage.co.za/scripts/map.dll/"; 
	var ScriptPath= "/scripts/map.dll/";
  var MapPath= "maps/MapMeGI/MapMeGI.map";	//edit this
	var Path = ScriptPath+MapPath;
	var MapWidth = 394;
  	var MapHeight = 267;
	var MapBorder = 0;			  	  
	var ZoomLevel = "0";
	var MapClickState ="ZoomInX3";
	var Action ="";
	var Hint ="";
	var SetupMap ="No";

function SetQuickFind(SavedLocationSelect)
	{
	AA = SavedLocationSelect.options[SavedLocationSelect.selectedIndex].value;
    d=new Date();
    SetSrc("Map", Path+"?action=SavedLocation&SavedLocationID="+AA+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	document.all.QuickFind.selectedIndex = 0;
	}	
	
function ResetMapHeader()	
		 {
		 //alert("reset");
		 document.all.MapHeader.innerText="Welcome to South Africa's most advanced interactive map.";
		 }
	

function SetHint(Text, Permanent)
	{
  	//if (timeId>0)
		//clearTimeout(timeId);
  	//timeId=0;
  	if (NS4)
  		{
    		with (document.map.document.hint.document)
			{
      			write('<FONT Size=1 Face="Arial">'+Text+'</FONT>');
      			close();
    		}
  		}
  	else
		document.all.hint.innerHTML=Text;
  	if (Permanent)
 	 	{
    		Hint=Text;
    		//SetAlt("MapArea", Text);
  		}
  	//window.MapArea=Text;
	}
	
function RestoreHint()
	{
	//SetHint(Hint, false)
  	//if (timeId==0)
		//timeId=setTimeout("SetHint('"+Hint+"')", 50);
	}

	
function CreateHint(ID, X, Y, Width, Height, Text)
	{
	//alert(Text);
  	Hint=Text;
  	z = '<STYLE TYPE="text/css">'+
    	'#'+ID+' {'+
      	'position: absolute;'+
      	'left: '+X+';'+
      	'top: '+Y+';'+
      	'width: '+Width+';'+
      	'height: '+Height+';'+
      	'z-index: 1;'+
      	'font: 7pt Arial;'+
		'border: 1;'+
		'color: white;'+
    	'}'+
    	'</STYLE>'+
    	'<DIV ID="'+ID+'">'+
   	 Text+
   	'</DIV>';
	document.write(z)
	}
	
function SetMapClickState(S)
	{
	//alert(S);
  	MapClickState=S;
	SetSrc("Query", (MapClickState=="Query")?"MapNavNewImages/infoOn.gif":"MapNavNewImages/infoOff.gif");
  	SetSrc("ZoomInX5", (MapClickState=="ZoomInX2")?"MapNavNewImages/zoomInOn.gif":"MapNavNewImages/zoomInOff.gif");
  	SetSrc("ZoomOutX5", (MapClickState=="ZoomOutX2")?"MapNavNewImages/zoomOutOn.gif":"MapNavNewImages/zoomOutOff.gif");
  	SetSrc("Pan", (MapClickState=="Pan")?"MapNavNewImages/centerOn.gif":"MapNavNewImages/centerOff.gif");
	
	if (MapClickState=="Query")
		SetHint('You are in Query clickmode - Click an an entity on the map to display its tag', true)
  	else
		if ((MapClickState=="ZoomInX2") || (MapClickState=="ZoomInX5"))
			SetHint('You are in ZoomIn clickmode - Click on the map to zoom in', true)
  		else
			if ((MapClickState=="ZoomOutX2") || (MapClickState=="ZoomOutX5"))
				SetHint('You are in ZoomOut clickmode - Click on the map to zoom out', true)
  			else
				if (MapClickState=="Pan")
					SetHint('You are in Pan clickmode - Click on the map to center that position', true);
	
	}	
	
function SetMapClickStateOnly(S)
	{
	//alert(S);
  	MapClickState=S;
	SetSrc("Query", (MapClickState=="Query")?"MapNavNewImages/infoOn.gif":"MapNavNewImages/infoOff.gif");
  	SetSrc("ZoomInX5", (MapClickState=="ZoomInX2")?"MapNavNewImages/zoomInOn.gif":"MapNavNewImages/zoomInOff.gif");
  	SetSrc("ZoomOutX5", (MapClickState=="ZoomOutX2")?"MapNavNewImages/zoomOutOn.gif":"MapNavNewImages/zoomOutOff.gif");
  	SetSrc("Pan", (MapClickState=="Pan")?"MapNavNewImages/centerOn.gif":"MapNavNewImages/centerOff.gif");
	}	
	
	
function CreateMapImage(MapMeVars) 
		 {
	//alert(Path);
		 d=new Date();
		 //alert("buildingmap");
		 document.write(
		 '<STYLE TYPE="text/css">#MAPimg{position:absolute; left:0; top:0;width:'+MapWidth+'; height:'+MapHeight+'; cursor:hand; z-index:1}</STYLE>'+
    	 '<DIV ID="MAPimg">');
		 //alert("building");
		 document.write(
    	 '<IMG NAME="Mapimg" ID="Mapimg" SRC="'+ Path +'?'+MapMeVars+'&HEIGHT='+MapHeight+'&WIDTH='+MapWidth+'&time='+d.getTime()+'"'
		 );
		 //alert("building2");
		 document.write(
    	 '" BORDER="'+MapBorder+'" onLoad="MapLoaded()"  onMouseover="" HEIGHT="'+MapHeight+'" WIDTH="'+MapWidth+'" STYLE="{cursor:hand;}">'+
    	 '</DIV>'			 
		 );
		 //alert("building3");		 		 
		 }	
	
 
function getCookie(Name){	
   		 var search = Name + "="	
		 if (document.cookie.length != 0)
			{
   			if (document.cookie.length > 0)
		 		{
      			offset = document.cookie.indexOf(search) 
      			if (offset != -1)
				   {
					   offset += search.length 
					   end = document.cookie.indexOf(";", offset) 
					   if (end == -1) end = document.cookie.length;
						return unescape(document.cookie.substring(offset, end))
      			} 
   			}
	      }
	 }	
 
function MapLoaded()
		 {
  		 if (NS4)
		 	{
		 	//document.map.document.PleaseWait.visibility="hidden"
		 	}
  		 else
		 	 {
			 //alert("PleaseWait now hidden");
		 	 document.all.PleaseWaitimg.style.visibility="hidden";
			 //alert("PleaseWait now hidden");
			 if(MapClickState=="RegisterTemp"){
							MapClickState = "Register";
							document.RegStepMapForm.DisplayKeyC.value = getCookie("CLIENT_DisplayKeyC");
							document.RegStepMapForm.XCoord.value = getCookie("CLIENT_XCoord");
							document.RegStepMapForm.YCoord.value = getCookie("CLIENT_YCoord");
							document.all.ACCEPT.style.display = "";
							};
		 	 }
		 }

function CreateMapInterface(){
		//alert("buildingmap");
		 document.write(
		 '<STYLE TYPE="text/css">#MapInterfaceimg{position:absolute; left:0; top:0; width:394; height:267; cursor:hand; z-index:1}</STYLE>'+
    	 '<DIV ID="MapInterface">');
		 document.write(
    	 '<IMG NAME="MapInterfaceimg" ID="MapInterfaceimg" SRC="MapNavNewImages/Viewer.gif"'
		 );
		 //alert("building2");
		 document.write(
    	 '" BORDER="0" onLoad=""  onMouseover="" HEIGHT="280" WIDTH="413" >'+
    	 '</DIV>'			 
		 );
		 //alert("building3");	
		}			 
		 
function CreateImage(name, X_pos, Y_pos, URL, X_size, Y_size)
	{
	document.write( '<STYLE TYPE="text/css">'+
     	'#HintArea'+' {'+
        'position:relative;'+
        'left:'+X_pos+';'+
        'top:'+Y_pos+';'+
      	'width:'+X_size+';'+
      	'height:'+Y_size+';'+
		'z-index:1'+
    	'}'+
   	'</STYLE>'+
    	'<DIV ID="'+name+'">'+
    	'<IMG NAME='+name+'img SRC="'+(URL)+'" width="'+X_size+'" height="'+Y_size+'">'+
    	'</DIV>');
	}


function CreatePleaseWait(ID, NormalURL, HighlightURL, ClickedURL, Width, Height, Alt, X, Y, onClick)
	{
  	document.write( 
		//'<STYLE TYPE="text/css">#map {position:relative;width:410;height:274;}</STYLE><DIV ID="map">'+
		'<STYLE TYPE="text/css">'+
    	'#'+ID+' {'+
      	'position:absolute;'+
      	'left:'+X+';'+
      	'top:'+Y+';'+
      	'width:'+Width+';'+
      	'height:'+Height+';'+
      	'z-index:1'+
    	'}'+
    	'</STYLE>'+
    	'<DIV ID="'+ID+'">'+
    	'<IMG NAME="'+ID+'img" ID="'+ID+'img" SRC="'+NormalURL+'" ALT="'+Alt+
    	'" BORDER="0" HEIGHT="'+Height+'" WIDTH="'+Width+'">'+
    	'</DIV>');
	}	
	
	
function CreateButton(ID, NormalURL, HighlightURL, ClickedURL, Width, Height, Alt, X, Y, onClick)
{
  //alert("dfsf");
  document.write( '<STYLE TYPE="text/css">'+
    '#'+ID+' {'+
      'position:absolute;'+
      'left:'+X+';'+
      'top:'+Y+';'+
      'width:'+Width+';'+
      'height:'+Height+';'+
	  'cursor:hand;'+
      'z-index:1'+
    '}'+
    '</STYLE>'+
    '<DIV ID="'+ID+'">'+
    '<A HREF="javascript:'+
    ((ClickedURL)?"SetSrc('"+ID+"','"+ClickedURL+"');":"")+
    onClick+'"'+
    ((HighlightURL)?
      ' onMouseOver="'+'if (State!='+"'"+ID+"') "+"SetSrc('"+ID+"','"+HighlightURL+"')"+'"'+
      ' onMouseOut=" if (State!='+"'"+ID+"') "+"SetSrc('"+ID+"','"+NormalURL+"')"+'"':'')+
    '>'+
    '<IMG NAME="'+ID+'img" ID="'+ID+'img" SRC="'+((State==ID)?ClickedURL:NormalURL)+'" ALT="'+Alt+
    '" BORDER="0" HEIGHT="'+Height+'" WIDTH="'+Width+'">'+
    '</A></DIV>');
}
	
function CreateMapDummy() 
		 {
		 //alert("buildingmap");
		 document.write(
		 '<STYLE TYPE="text/css">#MAPDummyimg{position:absolute; left:0; top:0;width:'+MapWidth+'; height:'+MapHeight+'; cursor:hand; z-index:1}</STYLE>'+
    	 '<DIV ID="MAPimg">');
		 //alert("building");
		 document.write(
    	 '<IMG NAME="MapDummyimg" ID="MapDummyimg" SRC="MapNavNewImages/TransParentPixel.gif"'
		 );
		 //alert("building2");
		 document.write(
    	 '" BORDER="'+MapBorder+'" onLoad=""  onMouseover="SetupMapNow();" HEIGHT="'+MapHeight+'" WIDTH="'+MapWidth+'" STYLE="{cursor:hand;}">'+
    	 '</DIV>'			 
		 );
		 //alert("building3");		 		 
		 }		
	
function SetSrc(id, url)
			 {
  			 if (NS4)
  			 	{
    		 	if (id=="Map")
			 	   {
			 	   //alert("set visible");
      			   //document.map.document.PleaseWait.visibility="visible"
			 	   };
    		 	eval("document.map.document." + id + ".document." + id ).src = url;
  			 	}
  			 else
  			 	 {
    			 if (id=="Map")
				 	{					
      				//alert(url);
					document.all.PleaseWaitimg.style.visibility="visible";					
					};				 
				 eval("document.all." + id  + "img").src = url;
				 };
	         }	

function DoAction(v)
	{
	d=new Date();
	Action=v;
	//alert("Action="+Action);
	//alert(Path + "?Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	SetSrc("Map", Path + "?Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	}	
	
function DoActionx(v)
	{
	d=new Date();
	Action=v;
	//alert("Action="+Action);
	alert(Path + "?Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	//SetSrc("Mapx", Path + "?Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	document.all.Mapximg.src = Path + "?interface=off&Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime();
	//document.all.Mapximg.src = "MapNavNewImages/s13.gif";
	//alert(document.location);
	//window.location="http://www.mapme.co.za";
	//document.location=Path + "?Action="+Action+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime();
	}		
	
function SetMapClickStateOldmminterface(S)
	{
  	MapClickState=S;    
	}		
	
	
function MapClick(e)
	{
  	if (NS4)
  		{
    		x=e.layerX;
    		y=e.layerY;
  		}
  	else
  		{
    		x=window.event.offsetX;
    		y=window.event.offsetY;
  		}
		
	switch (MapClickState){ 
   	   case "Info" : 
           DoInfo(x, y); 
       	   break; 
   	   case "Register" : 
		   MapClickState = "RegisterTemp";
		   d=new Date();
		   SetSrc("Map", ScriptPath+MapPath+"?clickX="+x+"&clickY="+y+"&Action=getcoords&Display=Towns&TagText=Are you HERE? Click the ACCEPT button below to continue, or click the map again to reselect."+
		   	      "&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
       	   break;
	   default : 
           d=new Date();
    	   SetSrc("Map", ScriptPath+MapPath+"?clickX="+x+"&clickY="+y+"&Action="+MapClickState+"&width="+MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	   } 
	}	
	
function Pan(X,Y)
	{
  	d=new Date();
  	SetSrc("Map", ScriptPath+MapPath+"?Action=Pan&X="+X+"&Y="+Y+"&width="+
	MapWidth+"&height="+MapHeight+"&time="+d.getTime());
	}		
	
	
function SetupMapNow()
	{
	if (SetupMap == "No")
	   {
	   SetupMap = "Yes";
	   onLoadMapMe();	   
	   };
	}	
	
function onLoadMapMe()
	{
  	IE4 = (document.all) ? true : false;
  	NS4 = (document.layers) ? true : false;
  	if (NS4)
  		{
    		if (document.map)
    			{
      			document.map.document.MapDummyimg.document.captureEvents(Event.MOUSEUP);
      			document.map.document.MapDummyimg.document.onmouseup=MapClick;
    			}
    	origWidth=innerWidth;
    	origHeight=innerHeight;
    	onresize=function(){if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload()}
  		}
  	else
  		{
		//alert("1");
    		if (document.all.Mapimg)
			document.all.MapDummyimg.onclick=MapClick;
  		}
	}

	
	