//GEOMAP Engine v 3.0
//Copyright  Cyber PLANET Ltd. 2001
// www.geomap.ru info@geomap.ru

//Initializing  variables
var MapName = "";
var Location_x=new Array();
var Location_y=new Array();
var Location_title=new Array();
var Location_url=new Array();
var Location_picurl=new Array();
var Pointer=new Array();
var TotalGroups = 0;
var LocationsInGroup=new Array();
var GroupsDuplicated = new Array();
var GroupNames = new Array();
var LocationBuffer_G=new Array();
var LocationBuffer_L=new Array();
var LBSize = 0;
var GroupBuffer=new Array();
var GBSize = 0;
var MMSize = 0;
var MoveBuffer_x = new Array();
var MoveBuffer_y = new Array();

function addLocation(group_nr, location_nr, x, y, title, picurl, url)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

Location_x[group_nr][location_nr] = x;
Location_y[group_nr][location_nr] = y;
Location_title[group_nr][location_nr] = title;
Location_url[group_nr][location_nr] = url;
Location_picurl[group_nr][location_nr] = picurl;

if (LocationsInGroup[group_nr] == null){LocationsInGroup[group_nr] = 1;}
else {LocationsInGroup[group_nr]++;}
}


function addLocationsGroup(group_nr, group_name, pointer, pointer_size)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

Location_x[group_nr] = new Array();
Location_y[group_nr] = new Array();
Location_title[group_nr] = new Array();
Location_url[group_nr] = new Array();
Location_picurl[group_nr] = new Array();
TotalGroups++;
Pointer[group_nr] = pointer;
GroupNames[group_nr] = group_name;
movie.SetVariable("/:GroupsNumber",TotalGroups); 
movie.SetVariable("/:CurrentPointer", pointer); 
movie.SetVariable("/:CPSize", pointer_size); 
// running script
movie.TCallLabel("/ScriptObject2", "GC");

var pointerName= "/MapObject/Pointer_" + TotalGroups;
movie.TSetProperty(pointerName, 7, 0);
movie.SetVariable("/:GroupsNumber",TotalGroups); 
}

//Показать
function showLocation(group_nr, location_nr)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

var MapLoaded = movie.GetVariable("/:MapLoaded");
if (MapLoaded != 1)
	{
	LBSize++;
	LocationBuffer_G[LBSize] = group_nr;
	LocationBuffer_L[LBSize] = location_nr;
	//movie.TSetProperty("/Warning", 7, 1);//get rid of not loaded warning
	}
else
	{

	showObject(group_nr, Location_x[group_nr][location_nr], Location_y[group_nr][location_nr], Location_title[group_nr][location_nr], Location_url[group_nr][location_nr], Location_picurl[group_nr][location_nr]);
	scrollTo(0,0);
	}
}

//Show object group
function showLocationsGroup(group_nr)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

//Hide NotMapped warning if displayed
movie.TSetProperty("/NotMapped", 7, 0);

var MapLoaded = movie.GetVariable("/:MapLoaded");
if (MapLoaded != 1)
	{
	GBSize++;
	GroupBuffer[GBSize] = group_nr;
	}
else
	{
	
	if (GroupsDuplicated[group_nr] != 1)
     		{
     		GroupsDuplicated[group_nr] = 1;
     		for (i=1;i<LocationsInGroup[group_nr] + 1;i++)
     			{
     			movie.SetVariable("/:CGroup", group_nr); 
     			movie.SetVariable("/:CLocation", i);
// inserting code			
				if  (Location_picurl[group_nr][i]==""||Location_picurl[group_nr][i]==null || Location_picurl[group_nr][i]==0) {

     			movie.SetVariable("/:CPointer", Pointer[group_nr]);
				} else {
				movie.SetVariable("/:CPointer", Location_picurl[group_nr][i]);
				}
//---------------------------------------
     			movie.TCallLabel("/ScriptObject2", "OC");
				
     			//initially hide the pointers
     			var LocationName = "/MapObject/Pointer_" + group_nr + "_" + i;
				
     			movie.TSetProperty(LocationName, 7, 0);

     			//setup myurl, mypicurl and mytitle vars in the new pointer

   			var PNameVar = LocationName + ":myname";
			movie.SetVariable(PNameVar, Location_title[group_nr][i]);
			var PUrlVar = LocationName + ":myurl";
			movie.SetVariable(PUrlVar, Location_url[group_nr][i]);
			
			var PPicUrlVar = LocationName + ":mypicurl";
			movie.SetVariable(PPicUrlVar, Location_picurl[group_nr][i]);			
     			}   		
		}

	//Now make all group visible
	if (MapName == ""){MapName = movie.GetVariable("/:OriginalMapName");}
	if (GroupNames[group_nr] != ""){NewMapName = MapName + " - " + GroupNames[group_nr];}
	movie.SetVariable("/:mapname", NewMapName);

	for (i=1;i<LocationsInGroup[group_nr] + 1;i++)
		{
		if (Location_x[group_nr][i] == 0 && Location_y[group_nr][i] == 0)
			{
			}
		else
			{
			var LocationName = "/MapObject/Pointer_" + group_nr + "_" + i;
			
			movie.TSetProperty(LocationName, 0, Location_x[group_nr][i]);
			movie.TSetProperty(LocationName, 1, Location_y[group_nr][i]);
			movie.TSetProperty(LocationName, 7, 1);
			}
		}
	}
}
// load map
function LoadMapObject(MyMapUrl,MyMapName)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];

movie.SetVariable("/:Mapurl", MyMapUrl);
movie.SetVariable("/:OriginalMapName", MyMapName);
movie.TCallLabel("/ScriptObject2","LM");
}
//Set scale map
function SetMapScale(ScaleFactor)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];

	movie.TSetProperty("/MapObject",3,ScaleFactor);
	movie.TSetProperty("/MapObject",2,ScaleFactor);
	gocenter();
}

//Go center  map
function GoCenter()
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];

movie.TCallLabel("/ScriptObject2","Gcent");
}

//Set cursor for edit
function GoEditCenter()
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];

var pointerName = "/MapObject/Pointer_1" ;
	

	
	var Mzoom = movie.TGetProperty("/MapObject", 2);
	var x=movie.TGetProperty("/MapObject", 0);
	var y=movie.TGetProperty("/MapObject", 1);
	
	movie.TSetProperty(pointerName, 0, Math.round(375-x*(Mzoom/100)));
	movie.TSetProperty(pointerName, 1, Math.round(220-y*(Mzoom/100)));


}

// Print map
function PrintMapObject()
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];

//movie.SetVariable("/:Mapurl", MyMapUrl);
movie.TCallLabel("/ScriptObject2","PM");
}
//Initialize GEOMAP engine...
function iniMap(mode,formname,xname,yname,offsetname,recx,recy,recscale)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var movie = InternetExplorer ? window.movie : document.embeds[0];
if (mode == "Editor")
	{
		movie.SetVariable("/:EditorMode", 1);
	}
if (mode == "EditorNormal")
	{
	var epx = xname;
	var epy = yname;
	movie.TSetProperty("/EditorClip", 7, 1);
	movie.TSetProperty("/MapObject/EditorPointer", 0, epx);
	movie.TSetProperty("/MapObject/EditorPointer", 1, epy);
	movie.TSetProperty("/MapObject/EditorPointer", 7, 1);
	movie.SetVariable("/:EditorMode", 1);
	}
if (mode == "EditorAuto")
	{
	var epx = offsetname;
	var epy = recx;
	movie.TSetProperty("/EditorAutoClip", 7, 1);
	movie.TSetProperty("/MapObject/EditorPointer", 0, epx);
	movie.TSetProperty("/MapObject/EditorPointer", 1, epy);
	movie.TSetProperty("/MapObject/EditorPointer", 7, 1);
	movie.SetVariable("/:EditorAutoMode", 1);
	movie.SetVariable("/MapObject/EditorPointer:FormName", formname);
	movie.SetVariable("/MapObject/EditorPointer:XFieldName", xname);
	movie.SetVariable("/MapObject/EditorPointer:YFieldName", yname);
	}
if (mode == "Search")
	{
	var RName = "/MapObject/MapRect";
	movie.TSetProperty(RName, 0, recx);
	movie.TSetProperty(RName, 1, recy);
	movie.TSetProperty(RName, 2, recscale);
	movie.TSetProperty(RName, 3, recscale);
	movie.TSetProperty(RName, 7, 1);
	movie.SetVariable("/:SearchMode", 1);
	movie.SetVariable("/MapObject/MapRect:FormName", formname);
	movie.SetVariable("/MapObject/MapRect:XFieldName", xname);
	movie.SetVariable("/MapObject/MapRect:YFieldName", yname);
	movie.SetVariable("/MapObject/MapRect:OffsetFieldName", offsetname);
	movie.TCallFrame("/ScriptObject2", 10);
	}
}

//Show object function
function showObject(group_nr, x, y, title, url,picurl)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

var MapLoaded = movie.GetVariable("/:MapLoaded");

if (MapLoaded != 1)
	{

	movie.TSetProperty("/Warning", 7, 1);
	}
else
{

if (MapName == ""){MapName = movie.GetVariable("/:OriginalMapName");}
var pointerName = "/MapObject/Pointer_" + group_nr;
var NewMapName = MapName;

if (title != ""){NewMapName = MapName + " - " + title;}
movie.SetVariable("/:hint", NewMapName); 
if((y==0 || y=="" || y==null) && (x==0 || x=="" || x==null))
	{
	movie.TSetProperty("/NotMapped", 7, 1);
	}
else
	{
	movie.TSetProperty("/NotMapped", 7, 0);
	
	movie.TSetProperty(pointerName, 7, 1);
	movie.TSetProperty(pointerName, 0, x);
	movie.TSetProperty(pointerName, 1, y);
if (picurl != "") {
	movie.SetVariable("/:picurl_tmp", picurl); 
	movie.SetVariable("/:gr_tmp", group_nr); 	
	movie.TCallLabel("/ScriptObject2", "LIP");
}
	var PNameVar = pointerName + ":myname";
	movie.SetVariable(PNameVar, title);
	var PUrlVar = pointerName + ":myurl";
	movie.SetVariable(PUrlVar, url);

				
	var Mzoom = movie.TGetProperty("/MapObject", 2);
	movie.TSetProperty("/MapObject", 0, Math.round(375-x*(Mzoom/100)));
	movie.TSetProperty("/MapObject", 1, Math.round(220-y*(Mzoom/100)));
	
//Указатель	
	movie.TSetProperty("/flash", 0, 375+10);
	movie.TSetProperty("/flash", 1, 220+10);
	movie.TPlay("/flash"); 
//***	
	}
}
}
// Move map X,Y coords
function MoveMapXY (x,y) {
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape
var MapLoaded = movie.GetVariable("/:MapLoaded");

if (MapLoaded != 1)
	{
	MoveBuffer_x[MMSize]=x;
	MoveBuffer_y[MMSize]=y;	
	MMSize++;
	}
else
	{
	var Mzoom = movie.TGetProperty("/MapObject", 2);
	movie.TSetProperty("/MapObject", 0, Math.round(375-x*(Mzoom/100)));
	movie.TSetProperty("/MapObject", 1, Math.round(220-y*(Mzoom/100)));
	}
}

//Hide group
function hideGroup(group_nr)
{
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;//Added for Netscape
var movie = InternetExplorer ? window.movie : document.embeds[0];//Added for Netscape

movie.TSetProperty("/NotMapped", 7, 0);
if (GroupsDuplicated[group_nr] == 1)
{
if (MapName == ""){MapName = movie.GetVariable("/:OriginalMapName");}
NewMapName = MapName;
movie.SetVariable("/:mapname", NewMapName); 



for (i=1;i<LocationsInGroup[group_nr] + 1;i++)
	{
	if (Location_x[group_nr][i] == 0 && Location_y[group_nr][i] == 0)
		{
		}
	else
		{
		var LocationName = "/MapObject/Pointer_" + group_nr + "_" + i;
		movie.TSetProperty(LocationName, 7, 0);
		}	
	}
}
//hide the root object too
var RootLocationName = "/MapObject/Pointer_" + group_nr;
movie.TSetProperty(RootLocationName, 7, 0);
}
//for edit mode
function setAutoXY(formname, xname, xvalue, yname, yvalue)
{
if (xvalue == 0 && yvalue == 0)
	{
	xvalue = 1;
	yvalue = 1;
	}
var execute = "document."+formname+"."+xname+".value="+xvalue+"; document."+formname+"."+yname+".value="+yvalue; 

eval(execute);
//document.write('<? require("adm.php"); ?>');
}


function setAutoXYO(formname, xname, xvalue, yname, yvalue, oname, ovalue)
{
var execute = "document."+formname+"."+xname+".value="+xvalue+"; document."+formname+"."+yname+".value="+yvalue+"; document."+formname+"."+oname+".value="+ovalue; 
eval(execute);
}


function onMapLoaded()
{
//Display all in Locations buffer
if(LBSize > 0)
	{
	for (var i=1;i<=LBSize;i++)
		{
		showLocation(LocationBuffer_G[i], LocationBuffer_L[i]);
		}
	}
if(GBSize > 0)
	{
	for (var i=1;i<GBSize+1;i++)
		{
		showLocationsGroup(GroupBuffer[i]);
		}
	}
if (MMSize > 0)
	{
	for (var i=0;i < MMSize;i++)
		{

			MoveMapXY(MoveBuffer_x[i],MoveBuffer_y[i]);
		}
	}
}

function eIn(o) {
if (document.all && document.all[o]!=null)  document.all[o].style.display = "block" ;

}
function eOut(o) {
if (document.all && document.all[o]!=null) document.all[o].style.display='none';
}
