﻿// iT, iL: a felulbiralando koordinatak
	// iWT, iWL, iWW, iWH: befoglalo window adatai
	// iRX, iRY: ref point vektor (annak eldontesere, hogy a modositott vagy az eredeti koordinatat adjuk vissza)
	// az (iT,iL)hez kepest
	// iBW, iBH: kirajzolando window (B-ox)

function GetCoords  (iT, iL, iRX, iRY, iWT, iWL, iWW, iWH, iBW, iBH)
{
	var mvt = iWT;
	var mvl = iWL;		
	var mvb = iWT + iWH;
	var mvr = iWL + iWW;
	var mdw = iBW;
	var mdh = iBH;	

	// egyik utkozik

	var oL;
	if (iL + mdw < mvr)
		oL = iL;
	else
		oL = mvr - mdw;

	// masik utkozik

	var oT;
	if (iT + mdh < mvb)
		oT = iT;
	else
		oT = mvb - mdh;

	// mindketto utkozik

	if ((iL + mdw >= mvr) && (iT + mdh >= mvb))
	{
		oL = iL - mdw;
		oT = iT - mdh;
	}

	if (((mvt <= iT + iRY) && ( iT + iRY <= mvb )) && ((mvl  + iRX <= iL ) && ( iL + iRX <= mvr )))
		return [oT, oL];
	else if ((mvt <= iT + iRY) && ( iT + iRY <= mvb ))
		return [oT, iL];
	else
		return [iT, iL];
}

function GetPxlX (label)
{
	return label.pMarker.iPixX - label.pMap.pGridMain.GetMapViewVectorX();
}

function GetPxlY (label)
{
	return label.pMarker.iPixY - label.pMap.pGridMain.GetMapViewVectorY();
}

function SetSignParamsG (label , strClass, strImgUrl, iImgWidth, iImgHeight, iImgRefX, iImgRefY)
{
	label.strCssClass = strClass;
	label.strImgUrl = strImgUrl;
	label.iImgWidth = iImgWidth;
	label.iImgHeight = iImgHeight;
	label.iImgRefX = iImgRefX;
	label.iImgRefY = iImgRefY;
}

function FormatCoordG (dX, dY)
{
	var str = "";
	if (isFinite(dX) && isFinite(dY) && (dX != 0 || dY != 0))
	{
		str  = (dY < 0) ? "S" : "N";
				str += (Math.round(dY * 100000) / 100000);
				str += "°; ";
				str += (dX < 0) ? "W" : "E";
				str += (Math.round(dX * 100000) / 100000);
				str += "°";
	}
	return str;
}

function GetLabelCaptionClassG()
{
	if(typeof(g_TopoliszControls) != 'undefined' && g_TopoliszControls != null)
	{
		if(g_TopoliszControls.pLogin && g_TopoliszControls.pLogin && g_TopoliszControls.pLogin.name)
			return "labelcaptionlogged";
	}
	return "labelcaption";
}

function PreLabelCreateG(pLabel)
{
	if(pLabel && pLabel.pMap)
	{
		if(pLabel.pMap.PreLabelCreate)
		{
			try
			{
				pLabel.pMap.PreLabelCreate(pLabel);
			}
			catch(e)
			{
			}
		}
	}
}

function OnLabelCreateG(pLabel)
{
	if(pLabel && pLabel.pMap)
	{
		if(pLabel.pMap.OnLabelCreate)
		{
			try
			{
				pLabel.pMap.OnLabelCreate(pLabel);
			}
			catch(e)
			{
			}
		}
	}
}

function PinLabel (tmTopoliszMap, pMarker)
{
	this.pMap = tmTopoliszMap;
	this.divParent = tmTopoliszMap.divPoiParent;
	this.divLabelSign = null;
	this.pMarker = pMarker;
	this.divLabelBox = null;
	this.divLabelBoxHeader = null;
	this.divLabelBoxContent = null;
	this.aDetails = null;
	this.divDetails = null;
	
	this.iImgRefX = 2;
	this.iImgRefY = 14;
	this.iImgWidth = 16;
	this.iImgHeight = 16;	
	this.iPxlX = pMarker.iPixX - tmTopoliszMap.pGridMain.GetMapViewVectorX();// view koord
	this.iPxlY = pMarker.iPixY - tmTopoliszMap.pGridMain.GetMapViewVectorY();
	this.iLabDX = pMarker.GetProperty("label_dx");
	this.iLabDY = pMarker.GetProperty("label_dy");
	this.iLabW = 0;
	this.iLabH = 0;	
	this.iLabLegD = 0;
	this.iLabLegY = 0;
	if (this.iLabDX == "???") this.iLabDX = 0;
	if (this.iLabDY == "???") this.iLabDY = 0;
	
	this.registeredButtons = null;
	this.divAddMapIcon = null;
	this.strCssClass = pMarker.GetProperty("div_label_sign_class");
	this.strImgUrl = GetAbsUrl("images/mapctrl/marker.gif");
	this.bDeleteMarkerOnLabelClose = false;	
	this.strID = pMarker.sID;
	this.m_bSignless = true;
	this.m_bPositionCorrection = true;
	this.divLabelLeg = null;
	this.divLabelBox2 = null;
	
	
	if (this.pMap.iLabelDesignVersion == 1)
		this.m_Position = "undersign";
	else
		this.m_Position = "abovesign";
		
	this.bHandleDetails = pMarker.bHandleDetails;

	var me = this;
	

	this.GetDesignVersion = function ()
	{
		if ((me.pMap.iLabelDesignVersion != null) && (me.pMap.iLabelDesignVersion != undefined))
		{
			return me.pMap.iLabelDesignVersion;
		}
		return 1;
	}


	// a felhasznalo ki akarja torolni a labelt es esetleg a 
	// mogotte allo markert is.

	this.OnDelete = function (pEvent)
	{				
		if(me.bDeleteMarkerOnLabelClose)
		{
			me.RemoveBox();
			me.pMap.pMarkers.Delete (me.strID);
		}
		else
		{
			me.RemoveBox();
		}
	}

	this.OnAddRoute = function (pEvent)
	{
		var addressList = me.pMap.pRouteSearch.GetAddressList();
		addressList[GetArrayLength(addressList)] = me.pMarker.ToAddress();
		me.pMap.pRouteSearch.SetAddressList(addressList);

		me.pMap.pRouteSearch.FindRoute(false);

		if (me.divAddMapIcon != null)
			me.divAddMapIcon.style.display = "none";
	}
	
	
	this.WGSDataArrived = function (result, func)
	{
		me.pMarker.dX = result.arrRecords[0].dX;
		me.pMarker.dY = result.arrRecords[0].dY;
		if (me.pMarker.HasWGSCoords())
			func();
	}	
	
	this.OnAddStartAddress = function(pEvent)
	{	
	    if (me.pMap.OnAddStartAddress != null)
	    {
	        me.pMap.OnAddStartAddress(me.pMarker);
	    }
	    else
	    {
			var ServerID = me.pMarker.GetProperty ("get_wgs_from_server");
			if (me.pMarker.HasWGSCoords())
			{
				g_TopoliszControls.ShowRouteSearch();
				me.pMap.pRouteSearch.SetStartAddress(me.pMarker.ToAddress());
			}
			else if (ServerID != "???")
			{
				me.pMap.NoSessionServer.CallFunction ("SearchPoi", "iID=" + ServerID, 0, me.WGSDataArrived, me.OnAddStartAddress); 
			}
		}
	}

	this.OnAddStopAddress = function(pEvent)
	{		
	    if (me.pMap.OnAddStopAddress != null)
	    {
	        me.pMap.OnAddStopAddress(me.pMarker);
	    }
	    else
	    {
			var ServerID = me.pMarker.GetProperty ("get_wgs_from_server");
			if (me.pMarker.HasWGSCoords())
			{
				g_TopoliszControls.ShowRouteSearch();	       	        	         			
				me.pMap.pRouteSearch.SetStopAddress(me.pMarker.ToAddress());
			}
			else if (ServerID != "???")
			{
				me.pMap.NoSessionServer.CallFunction ("SearchPoi", "iID=" + ServerID, 0, me.WGSDataArrived, me.OnAddStopAddress); 
			}
		}		
	}
	
	this.OnAddThroughAddress = function(pEvent)
	{
			var ServerID = me.pMarker.GetProperty ("get_wgs_from_server");
			if (me.pMarker.HasWGSCoords())
			{
				g_TopoliszControls.ShowRouteSearch();	       	        	         			
				me.pMap.pRouteSearch.AddThroughAddress(me.pMarker.ToAddress());
			}
			else if (ServerID != "???")
			{
				me.pMap.NoSessionServer.CallFunction ("SearchPoi", "iID=" + ServerID, 0, me.WGSDataArrived, me.OnAddThroughAddress); 
			}
	}


	this.DrawSign = function () // can be overridden in Marker: DrawSign_Custom
	{
		if (me.pMarker.DrawSign_Custom != null)
			me.pMarker.DrawSign_Custom ();
		else
			me.DrawSign_Default ();
	}

	this.DrawBox = function () // can be overridden in Marker: DrawBox_Custom(Marker)
	{
		if (me.pMarker.DrawBox_Custom != null)
			me.pMarker.DrawBox_Custom (me);
		else
			me.DrawBox_Default ();
	}

	this.DrawBoxHeader = function () // can be overridden in Marker: DrawBoxHeader_Custom (divLabelBox)
	{
		if (me.pMarker.DrawBoxHeader_Custom != null)
			me.pMarker.DrawBoxHeader_Custom (me.divLabelBox);
		else
			me.DrawBoxHeader_Default ();
	}

	this.DrawBoxContent = function () // can be overridden in Marker: DrawBoxContent_Custom (divLabelBox)
	{
		if (me.pMarker.DrawBoxContent_Custom != null)
			me.pMarker.DrawBoxContent_Custom (me.divLabelBox);
		else
			me.DrawBoxContent_Default ();
	}
		
	this.DrawBoxContent_Default = function ()
	{
		if (me.GetDesignVersion() == 1)
			return me.DrawBoxContent_Default_v1();
		else
			return me.DrawBoxContent_Default_v2();
	}		

	this.DrawBoxHeader_Default = function ()
	{
		if (me.divLabelBoxHeader == null)
			return;
				
		if (me.GetDesignVersion() == 1)
			return me.DrawBoxHeader_Default_v1();
		else
			return me.DrawBoxHeader_Default_v2();
	}		
		
	/// private
	/// must not override	
	this.DrawBoxContent_Default_v2 = function ()
	{			
		return me.DrawBoxContent_Default_v1(); // same as v1
	}		
	
	this.DrawBoxContent_Default_v1 = function ()
	{	
		// label box / coordinates

		if (me.pMarker.GetProperty("show_coordinates")) 
		{
			var divCoord = NewTag('div', me.divLabelBoxContent);
			NewTextTag(FormatCoordG(me.pMarker.dX, me.pMarker.dY), divCoord);
			divCoord.ondragstart = function() { return false; }; 
			divCoord.onselectstart = function() { return false; }; 
		}
		
		if (me.pMarker.DrawBoxContentData != null)
			me.pMarker.DrawBoxContentData (me.divLabelBoxContent);

			
		// label box / details link
			
		if (me.pMarker.GetProperty("handle_details")) 
		{
			var oDetails = me.pMarker.GetProperty("details_to_show");
			var bShowLink = false;
			if (oDetails != "???")
			{
				// the details
				
				var containerdiv = NewTag("div", me.divLabelBoxContent);
				me.divDetails = NewTag("div", containerdiv);
				me.divDetails.style.display = (me.pMarker.bDetailsMustBeVisible ? "" : "none");
				AddTag(oDetails, me.divDetails);
				bShowLink = true;
			}
			
			var actGetDetails = me.pMarker.GetProperty("get_details_from_server");
			bShowLink = bShowLink || (actGetDetails != "???");
			
			if (bShowLink)
			{
				// the "details" link
				var detailslinkdiv = NewTag("div", containerdiv);
				var detailslinkdiv = NewTag("div", me.divLabelBoxContent);
				detailslinkdiv.style.textAlign = "right";
				me.aDetails = NewTag("a", detailslinkdiv);
				me.aDetails.onclick = me.ShowHideDetails;
				me.aDetails.onmousedown = function (e) {StopEventPropagation(e); return false;};
				me.aDetails.setAttribute("href", "javascript:void(0)");
				NewTextTag(g_Babel.GetWord('AddressLabelDetails'), me.aDetails);
			}
		}
	}
	
	/// private
	/// must not override
	this.DrawBoxHeader_Default_v2_callBack = function (hasNorc)
	{
		var tab2 = NewTag ("table", me.divLabelBoxHeader);
		tab2.cellSpacing = "0";
		tab2.cellPadding = "0";
		tab2.style.border = "0px";		
		var tb2 = NewTag ("tbody", tab2);		
		var tr2 = NewTag ("tr", tb2);				
		var td3 = NewTag ("td", tr2);		
		td3.className = "label_caption";
		AddEvent (td3, "click", me.pMarker.OnLabelSignClick);
		NewTextTag (me.pMarker.GetLabelCaption(), td3);		
		var td4 = NewTag ("td", tr2);		
		td4.className = "label_buttons";
		
		if (me.pMarker.DrawCustomButtons) {
			me.pMarker.DrawCustomButtons(td4/*linkdiv*/, me);
		}
				
		// label box / panomara button
		if (me.pMarker.GetProperty("panorama_button") && hasNorc && g_strAppID.toLowerCase() != "trafficnav") {
				var a = NewTag ("a", td4);
				a.setAttribute("href", "javascript:void(0)");
				NewTextTag(g_Babel.GetWord('capLabHeaderBtnNorc'), a);	
				
				var NorcLoader = function(serverParams) {
					serverParams=eval(serverParams);
					me.m_bPositionCorrection = true;
					me.m_Position = "abovesign";
					if (serverParams != null) {
						me.divLabelBoxContent.innerHTML = "<iframe src='http://www.norc.ro/embed.aspx?id=" + serverParams.m_id + "&ppa=" + serverParams.m_angle + "&r=0&vla=5&lz=70&acc=f005f0ae-728b-4d6a-9e91-ae03fb095bcd&hrg=0&hrg=0' frameborder='0' scrolling='no' width='360' height='298' top='0' left = '0'></iframe>";
					}
					else {
						me.divLabelBoxContent.innerHTML = "<div style='line-height: 50px; vertical-align: middle; text-align: center'>" + g_Babel.GetWord("noPanorama") + "</div>";
					}
					a.style.display = "none";
					me.ReArrange();
				}
				
				// server or userparam depending on type of call, param should have dX and dY
				var NorcQuery = function(param) {
					if (param != null) {
						me.divLabelBoxContent.innerHTML = "<div style='line-height: 50px; vertical-align: middle; text-align: center'><img src='/design/globe32.gif' alt='" + g_Babel.GetWord("loadingPanorama") + "'></img></div>";
						var strParams = "lat=" + param.arrRecords[0].dY + "&lon=" + param.arrRecords[0].dX;
						var ajax = new Ajax();
						ajax.doPost("/norc/norc.ashx", strParams, NorcLoader, "text");
					}
					else {
						NorcLoader(null);
					}
				}
				
				a.onclick = function (e) {
					var ServerID = me.pMarker.GetProperty ("get_wgs_from_server");
					if (me.pMarker.HasWGSCoords())
					{
						var temp = new Object();
						temp.arrRecords = new Array();
						temp.arrRecords[0] = me.pMarker;
						NorcQuery(temp);
					}
					else if (ServerID != "???")
					{
						me.pMap.NoSessionServer.CallFunction ("SearchPoi", "iID=" + ServerID, 0, NorcQuery); 
					}
					else {
						NorcQuery(null);
					}
					return false;
				};
				
				a.onmousedown = function (e) {StopEventPropagation(e); return false;};
				a.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('NorcHint'))};
				a.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
				a.ondragstart = function() { return false; };
				a.onselectstart = function() { return false; };
		}
		
		// label box / start button
		if (me.pMarker.GetProperty("start_button")) {		
			var a1 = NewTag ("a", td4);
			NewTextTag(g_Babel.GetWord('capLabHeaderBtnStart'), a1);
			a1.href = "javascript:void(0)";
			a1.onclick = function (e)
			{				
				me.OnAddStartAddress(); 
				StopEventPropagation(e);				
				return false;
			};
			a1.onmousedown = function (e) {StopEventPropagation(e); return false;};		
			a1.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('TrafficFromHere'))};
			a1.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			a1.ondragstart = function() { return false; }; 
			a1.onselectstart = function() { return false; }; 							
		}
		
		// label box / through button
		
		if (me.pMarker.GetProperty("through_button") && g_strAppID.toLowerCase() != "trafficnav") 
		{			    
			var a2 = NewTag ("a", td4);
			a2.href = "javascript:void(0)";
			NewTextTag(g_Babel.GetWord('capLabHeaderBtnThrough'), a2);		
		    a2.onclick = function ()
		    {			
			    me.OnAddThroughAddress();
		    };
		    a2.onmousedown = function (e) {StopEventPropagation(e); return false;};			
		    a2.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('Through'))};
		    a2.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
		    a2.ondragstart = function() { return false; }; 
			a2.onselectstart = function() { return false; }; 						
		}						
		
		// label box / stop button
		
		if (me.pMarker.GetProperty("stop_button")) {

			var a3 = NewTag ("a", td4);
			a3.href = "javascript:void(0)";
			NewTextTag(g_Babel.GetWord('capLabHeaderBtnStop'), a3);
						
			a3.onclick = function ()
			{			
				me.OnAddStopAddress();
			};
			a3.onmousedown = function (e) {StopEventPropagation(e); return false;};
			a3.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('TrafficToHere'))};
			a3.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			a3.ondragstart = function() { return false; };
			a3.onselectstart = function() { return false; };
			
		}	
			
		/*var a4 = NewTag ("a", td4);
		a4.href = "javascript:void(0)";
		NewTextTag("kedvenc", a4);	*/
				
		// label box / span for additional buttons
			
		me.registeredButtons = NewTag("span", td4);
		
		// label box / close button
		
		if (me.pMarker.GetProperty("close_button")) 
		{
			var a5 = NewTag ("a", td4);
			NewTextTag("X", a5);
			a5.onclick = me.OnDelete;
			a5.onmousedown = function (e) {StopEventPropagation(e); return false;};
			a5.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  "Bezár")};
			a5.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			a5.ondragstart = function() { return false; };
			a5.onselectstart = function() { return false; };			
		}						
	}
	
	/// private
	/// must not override	
	this.DrawBoxHeader_Default_v2 = function ()
	{
		//g_TopoliszMap.NoSessionServer.CallFunction("HasNorc", "x=" + me.pMarker.dX + "&y=" + me.pMarker.dY, 0, me.DrawBoxHeader_Default_v2_callBack);
		me.DrawBoxHeader_Default_v2_callBack(true);
	}

	this.DrawBoxHeader_Default_v1 = function ()
	{
		// label box / caption 
		
		var caption = NewTag('div', me.divLabelBoxHeader);
		caption.className = GetLabelCaptionClassG();
		caption.ondragstart = function() { return false; }; 
		caption.onselectstart = function() { return false; }; 
		NewTextTag(me.pMarker.GetLabelCaption(), caption);
	
		// label box / buttons parent
		var linkdiv = NewTag("div", me.divLabelBoxHeader);		
		linkdiv.className = "labelclose";
		linkdiv.ondragstart = function() { return false; }; 
		linkdiv.onselectstart = function() { return false; };

		if (me.pMarker.DrawCustomButtons) {
			me.pMarker.DrawCustomButtons(linkdiv, me);
		}

		// label box / start button
		if (me.pMarker.GetProperty("start_button")) {
			a = NewTag("a", linkdiv);
			a.setAttribute("href", "javascript:void(0)");
			a.onclick = function (e)
			{				
				me.OnAddStartAddress(); 
				StopEventPropagation(e);				
				return false;
			};
			a.onmousedown = function (e) {StopEventPropagation(e); return false;};
			img = NewTag("img", a);
			img.paddingRight = "2px";
			SetImage(img, GetAbsUrl("images/trafficctrl/traffic_from_small.gif"), 12, 12, "");	 
			img.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('TrafficFromHere'))};
			img.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			img.ondragstart = function() { return false; }; 
			img.onselectstart = function() { return false; }; 			
		}
			
		// label box / through button
			
		if (me.pMarker.GetProperty("through_button")) 
		{			    
		    a = NewTag("a", linkdiv);
		    a.setAttribute("href", "javascript:void(0)");
		    a.onclick = function ()
		    {			
			    me.OnAddThroughAddress();
		    };
		    a.onmousedown = function (e) {StopEventPropagation(e); return false;};			
		    img = NewTag("img", a);
		    img.paddingRight = "2px";
		    SetImage(img, GetAbsUrl("images/trafficctrl/traffic_through_small.gif"), 12, 12, "");
		    img.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('Through'))};
		    img.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
		    img.ondragstart = function() { return false; }; 
		    img.onselectstart = function() { return false; }; 			
        }			

		// label box / stop button
			
        if (me.pMarker.GetProperty("stop_button")) {
			a = NewTag("a", linkdiv);
			a.setAttribute("href", "javascript:void(0)");
			a.onclick = function ()
			{			
				me.OnAddStopAddress();
			};
			a.onmousedown = function (e) {StopEventPropagation(e); return false;};
			img = NewTag("img", a);
			img.paddingRight = "2px";
			SetImage(img, GetAbsUrl("images/trafficctrl/traffic_to_small.gif"), 12, 12, "");	 
			img.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  g_Babel.GetWord('TrafficToHere'))};
			img.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			img.ondragstart = function() { return false; }; 
			img.onselectstart = function() { return false; }; 
		}

		// label box / span for additional buttons
			
		me.registeredButtons = NewTag("span", linkdiv);
		
		// label box / close button
			
		if (me.pMarker.GetProperty("close_button")) 
		{
			a = NewTag("a", linkdiv);
			a.setAttribute("href", "javascript:void(0)");
			a.onclick = me.OnDelete;
			a.onmousedown = function (e) {StopEventPropagation(e); return false;};
			var img = NewTag("img", a);
			img.paddingRight = "2px";
			SetImage(img, GetAbsUrl("images/mapctrl/close.gif"), 12, 12, "");
			img.onmouseover = function (pEvent) {g_TopoliszMap.ShowToolTip (pEvent,  "Bezár")};
			img.onmouseout = function () {g_TopoliszMap.HideToolTip ()};
			img.ondragstart = function() { return false; };
			img.onselectstart = function() { return false; };			
		}			
	}	

	/// private
	/// must not override
	this.DrawSign_Default = function ()
	{
		me.m_bSignless = (me.pMarker.GetProperty("pin_img_url") == "???");
		var bNumberedSign = ((me.pMarker.GetProperty("pinnumber") != 0) && (me.pMarker.GetProperty("pinnumber") != "???"));
		if (!me.m_bSignless || bNumberedSign)
		{
			//var bNumberedSign = ((me.pMarker.GetProperty("pinnumber") != 0) && (me.pMarker.GetProperty("pinnumber") != "???"));
			if (bNumberedSign)
			{
				return me.DrawSign_Numbered();
			}				
		
			var newImg = new Image();
			newImg.src = me.pMarker.GetProperty("pin_img_url");
		
			var iSignImgW = me.pMarker.GetProperty("pin_img_width");
			if (iSignImgW == "???") iSignImgW = newImg.width;
			var iSignImgH = me.pMarker.GetProperty("pin_img_height");
			if (iSignImgH == "???") iSignImgH = newImg.height;
		
		
			SetSignParamsG(me,	me.pMarker.GetProperty("pin_css_class"), 
								me.pMarker.GetProperty("pin_img_url"), 
								iSignImgW, 
								iSignImgH, 
								me.pMarker.GetProperty("pin_img_refx"), 
								me.pMarker.GetProperty("pin_img_refy"));
										
			me.bDeleteMarkerOnLabelClose = me.pMarker.GetProperty("delete_marker_on_label_close");
			me.divLabelSign					= NewTag("div",me.divParent);
			me.divLabelSign.className		= me.strCssClass;
			me.divLabelSign.style.position	= "absolute";		
			me.divLabelSign.style.width		= me.iImgWidth + "px";
			me.divLabelSign.style.height	= me.iImgHeight + "px";		
			me.divLabelSign.onselectstart	= function () { return false; }; 
			me.divLabelSign.ondragstart		= function () { return false; }; 			
			
			AddEvent (me.divLabelSign, "mouseover", me.pMarker.OnLabelSignMouseOver);
			AddEvent (me.divLabelSign, "click", me.pMarker.OnLabelSignClick);
			AddEvent (me.divLabelSign, "click", me.pMarker.GetProperty ("func_label_sign_on_click"));

			me.divLabelSign.ondblclick		= function (pEvent)	{	StopEventPropagation (pEvent); return false;	}
			
			// label sign / image
			
			if ((me.pMarker.GetProperty("pinnumber") != 0) && (me.pMarker.GetProperty("pinnumber") != "???"))
			{
				var imgMarker = NewTag("span",me.divLabelSign);
				imgMarker.className = "findpoinumber";
				NewTextTag (me.pMarker.GetProperty("pinnumber"),imgMarker);		
			}
			else
			{			
				var imgMarker = NewTag("img", me.divLabelSign);
				imgMarker.style.paddingTop = "0px";
				imgMarker.style.top = "0px";
				imgMarker.style.left = "0px";
				
				SetImage(imgMarker, me.strImgUrl, me.iImgWidth, me.iImgHeight, "");
				imgMarker.ondragstart			= function () { return false; }; 
				imgMarker.onselectstart			= function () { return false; }; 	
			}
			
			OnLabelCreateG(me);
			me.ReArrange ();
		}	
		else
		{
			me.pMarker.m_bSignlessActive = true;
		}	
	}
	
	this.DrawSign_Numbered = function ()
	{
		me.bDeleteMarkerOnLabelClose = me.pMarker.GetProperty("delete_marker_on_label_close");
		me.divLabelSign					= NewTag("div",me.divParent);
		me.divLabelSign.style.position	= "absolute";	
		
		me.iImgRefX = me.pMarker.GetProperty("pin_img_refx");
		me.iImgRefY = me.pMarker.GetProperty("pin_img_refy");
	
		
		/*me.divLabelSign.style.width = "20px";
		me.divLabelSign.style.height = "20px";
		me.divLabelSign.style.backgroundColor = "Red";*/

		var strNumber = me.pMarker.GetProperty("pinnumber");		
		var arrDivs = me.DrawStructureNr_1 (me.divLabelSign);
		var divLL	= arrDivs[0];
		var divLBC	= arrDivs[1];
		var divLBH	= arrDivs[2];		
		var propColor = me.pMarker.GetProperty("pinnumbercolor");
		if (propColor == "???")
			me.DrawStructureNr_2 (divLBH, strNumber);
		else
			me.DrawStructureNr_2 (divLBH, strNumber, propColor);
		me.divLabelSign.style.zIndex = 7;	
		divLBH.style.fontSize = "20px";	
		
		me.divLabelSign.onselectstart	= function () { return false; }; 
		me.divLabelSign.ondragstart		= function () { return false; }; 			
		AddEvent (me.divLabelSign, "mouseover", me.pMarker.OnLabelSignMouseOver);
		AddEvent (me.divLabelSign, "click", me.pMarker.OnLabelSignClick);
		AddEvent (me.divLabelSign, "click", me.pMarker.GetProperty ("func_label_sign_on_click"));
		me.divLabelSign.ondblclick = function (pEvent)	{	StopEventPropagation (pEvent); return false;	}
		OnLabelCreateG(me);
		me.ReArrange ();	
	}
	
	/// private
	/// must not override	
	this.DrawBox_Default = function ()
	{
		if (me.divLabelBox != null)
			return null;
					
		me.divLabelBox = NewTag ('div', me.divParent);						
		me.divLabelBox.style.visibility = "hidden";
		me.divLabelBox.style.display	= "none";		
		me.divLabelBox.ondblclick		= function (pEvent) {StopEventPropagation (pEvent); return false;}		
		me.divLabelBox.onclick			= function (pEvent) {StopEventPropagation (pEvent); return false;}
		me.divLabelBox.onmousewheel		= function (pEvent) {StopEventPropagation (pEvent); return false;}
		me.divLabelBox.onselectstart	= function () { return false; }; 
		me.divLabelBox.ondragstart		= function () { return false; }; 				
		me.divLabelBox.style.left		= "0px"; // set by ReArrange()
		me.divLabelBox.style.top		= "0px"; // set by ReArrange()
								
		me.DrawBoxSkeleton ();
		me.DrawBoxHeader();	
		me.DrawBoxContent ();				
					
		me.divLabelBox.style.visibility = "visible";
		me.divLabelBox.style.display	= "";
		me.pMarker.bLabelBoxMustBeVisible = true;
		me.ReArrange ();				
		
		me.pMap.OnPinLabelBoxCreated (me.pMarker);		
		return me.divLabelBox;
	}		
	
	this.DrawBoxSkeleton = function ()
	{
		if (me.divLabelBox == null)
			return;
	
		if (me.GetDesignVersion() == 1)
			me.DrawBoxSkeleton_v1();
		else
			me.DrawBoxSkeleton_v2();		
	}
	
	this.DrawBoxSkeleton_v1 = function ()
	{
		me.divLabelBox.className		= me.pMarker.GetProperty("labelbox_css_classname");		
		me.divLabelBoxHeader = NewTag ("div", me.divLabelBox);
		me.divLabelBoxContent = NewTag ("div", me.divLabelBox);
	}

	this.DrawBoxSkeleton_v2 = function ()
	{
		me.divLabelBox.className = me.pMarker.GetProperty("label_css_classname");//"label_v2";		
		AddEvent (me.divLabelBox, "click", me.pMarker.OnLabelSignClick);
		me.divLabelLeg = NewTag("div", me.divLabelBox);		
		me.divLabelLeg.className = "label_leg";
		AddEvent (me.divLabelLeg, "click", me.pMarker.OnLabelSignClick);
		me.divLabelLeg.style.paddingLeft = "0px";	
		if (me.pMarker.GetProperty("LeglessLabel") == "true")
			me.divLabelLeg.style.display = "none";
		me.divLabelBox2 = NewTag("div", me.divLabelBox);
		me.divLabelBox2.className = me.pMarker.GetProperty("labelbox_css_classname");//"label_box";
		var tab1 = NewTag ("table", me.divLabelBox2);		
		tab1.cellSpacing = "0";
		tab1.cellPadding = "0";
		tab1.style.border = "0px";	
		var tb1 = NewTag ("tbody", tab1);
		var tr1 = NewTag ("tr", tb1);		
		tr1.className = "lbl_top";
		var td1 = NewTag ("td", tr1);		
		td1.className = "lbl_left";
		var td2 = NewTag ("td", tr1);		
		td2.className = "lbl_center";
		me.divLabelBoxHeader = NewTag ("div", td2);
		var td5 = NewTag ("td", tr1);		
		td5.className = "lbl_right";				
		var tr3 = NewTag ("tr", tb1);				
		tr3.className = "lbl_mid";
		var td6 = NewTag ("td", tr3);		
		td6.className = "lbl_left";
		var td7 = NewTag ("td", tr3);		
		td7.className = "lbl_center";	
		me.divLabelBoxContent = NewTag ("div", td7);
		me.divLabelBoxContent.className = "label_content";
		var td8 = NewTag ("td", tr3);		
		td8.className = "lbl_right";
		var tr4 = NewTag ("tr", tb1);		
		tr4.className = "lbl_bottom";
		var td9 = NewTag ("td", tr4);		
		td9.className = "lbl_left";
		var td10 = NewTag ("td", tr4);		
		td10.className = "lbl_center";		
		var td11 = NewTag ("td", tr4);		
		td11.className = "lbl_right";	
	}
		
	this.DrawStructureNr_1 = function (divLB)
	{		
		var divLL;
		var divLBC;
		var divLBH;
		divLB.className = me.pMarker.GetProperty("label_css_classname");//"label_v2";		
		AddEvent (divLB, "click", me.pMarker.OnLabelSignClick);
		divLL = NewTag("div", divLB);		
		divLL.className = "label_leg";
		AddEvent (divLL, "click", me.pMarker.OnLabelSignClick);
		divLL.style.paddingLeft = "0px";	
		if (me.pMarker.GetProperty("LeglessLabel") == "true")
			divLL.style.display = "none";
		var divLabelContentBox = NewTag("div", divLB);
		divLabelContentBox.className = "label_box";						
		var tab1 = NewTag ("table", divLabelContentBox);		
		tab1.cellSpacing = "0";
		tab1.cellPadding = "0";
		tab1.style.border = "0px";	
		var tb1 = NewTag ("tbody", tab1);
		var tr1 = NewTag ("tr", tb1);		
		tr1.className = "lbl_top";
		var td1 = NewTag ("td", tr1);		
		td1.className = "lbl_left";
		var td2 = NewTag ("td", tr1);		
		td2.className = "lbl_center";
		divLBH = NewTag ("div", td2);
		var td5 = NewTag ("td", tr1);		
		td5.className = "lbl_right";				
		var tr3 = NewTag ("tr", tb1);				
		tr3.className = "lbl_mid";
		var td6 = NewTag ("td", tr3);		
		td6.className = "lbl_left";
		var td7 = NewTag ("td", tr3);		
		td7.className = "lbl_center";	
		divLBC = NewTag ("div", td7);
		divLBC.className = "label_content";
		var td8 = NewTag ("td", tr3);		
		td8.className = "lbl_right";
		var tr4 = NewTag ("tr", tb1);		
		tr4.className = "lbl_bottom";
		var td9 = NewTag ("td", tr4);		
		td9.className = "lbl_left";
		var td10 = NewTag ("td", tr4);		
		td10.className = "lbl_center";		
		var td11 = NewTag ("td", tr4);		
		td11.className = "lbl_right";	
		
		var divLL;
		var divLBC;
		var divLBH;
		return [divLL, divLBC, divLBH];
	}
	
	this.DrawStructureNr_2 = function (divLBH, captionText, color)
	{
		var tab2 = NewTag ("table", divLBH);
		tab2.cellSpacing = "0";
		tab2.cellPadding = "0";
		tab2.style.border = "0px";		
		var tb2 = NewTag ("tbody", tab2);		
		var tr2 = NewTag ("tr", tb2);				
		var td3 = NewTag ("td", tr2);				
		td3.className = "label_caption";
		if (color != undefined)
			td3.style.color = color;
		td3.style.textAlign = "center";
		td3.style.minWidth = "18px";
		AddEvent (td3, "click", me.pMarker.OnLabelSignClick);
		NewTextTag (captionText, td3);
		var strSignUrl = me.pMarker.GetProperty("pin_img_url");
		if(strSignUrl != "???")
		{
			var td4 = NewTag("td", tr2);
			var img = NewTag("img", td4);
			img.src = strSignUrl;
			img.alt = "";
		}
		
	}
	
	this.IsLabelBoxVisible = function ()
	{
		if (me.divLabelBox == null)
			return false;
		else
		{
			if ((me.divLabelBox.style.visibility == "visible") && (me.divLabelBox.style.display == ""))
				return true;
			else
				return false;
		}
	}
	
	this.DestroyDivLabelBox = function ()
	{
		if (me.divLabelBox)
		{
			if (me.divLabelBox.parentNode)
			{
				me.divLabelBox.parentNode.removeChild (me.divLabelBox);
				me.divLabelBox = null;
				return true;
			}
		}		
		return false;
	}
		
	this.RemoveBox = function () 
	{
		var bExisted = me.DestroyDivLabelBox ();
		if (bExisted)
		{
			//me.pMap.bFixedLabel = false;								
			me.pMarker.bLabelBoxMustBeVisible = false;		
			me.pMarker.bDetailsMustBeVisible = false;
			me.pMap.OnPinLabelBoxDestroyed (me.pMarker);					
		}
	}	
	
	this.RemoveSign = function () 
	{
		if (!me.m_bSignless)
		{
			if (me.divLabelSign)
			{
				if(me.divLabelSign.parentNode)
					me.divLabelSign.parentNode.removeChild (me.divLabelSign);
				me.divLabelSign = null;
			}
		}	
		else
		{
			me.pMarker.m_bSignlessActive = false;
		}
	}	
	
	
	this.DetailsDataArrived = function (result)
	{		
		me.divDetails = NewTag("div", me.divLabelBoxContent);	
		NewTextTag(g_Babel.GetWord("PoiType") + ": " + g_Babel.GetWord("poi"+result.arrRecords[0].nTypeID), me.divDetails);
		NewTag ("br",me.divDetails); 					
		
		var j;
		for (j = 1; j < result.arrRecords[0].arrValues.length; j++)
		{
			if (me.pMap.GetLang() == "hu")
				NewTextTag(result.arrRecords[0].arrNames[j] + ": " + result.arrRecords[0].arrValues[j], me.divDetails);
			else
				NewTextTag(result.arrRecords[0].arrValues[j], me.divDetails);
				
			NewTag ("br",me.divDetails); 					
		};			
		
		me.divDetails.style.display = "none";
		me.ShowHideDetails();			
	}
	
	this.ShowHideDetails = function () 
	{
		
		if (me.divDetails == null) 
		{
			var iServerID = me.pMarker.GetProperty("get_details_from_server");		
			if (iServerID != "???")
			{
				me.pMap.NoSessionServer.CallFunction("SearchPoi", "iID=" + iServerID, 0, me.DetailsDataArrived); 
			}
			return;
		}		
		
		if (me.aDetails != null && me.divDetails != null)
		{
			me.divDetails.onselectstart = function () { return false; }; 
			me.divDetails.ondragstart = function() { return false; }; 		
			me.aDetails.onselectstart = function () { return false; }; 
			me.aDetails.ondragstart = function() { return false; }; 		
		
			if (me.divDetails.style.display == "none")
			{
				me.aDetails.style.display = "none";
				me.divDetails.style.display = "";
				me.pMarker.bDetailsMustBeVisible = true;
				me.divLabelBox.style.width = "250px";
				//me.pMap.bFixedLabel = true;									
			}
			else
			{
				me.aDetails.style.display = "";
				me.divDetails.style.display = "none";
				me.pMarker.bDetailsMustBeVisible = false;			
				//me.pMap.bFixedLabel = false;				
			}
			me.ReArrange ();
		}
	};
	
// -------------- design version 2
	this.SetLabelBoxSizeFields = function ()
	{			
		if (me.divLabelBox2 != null)
		{	
			me.iLabW = GetLayerWidth(me.divLabelBox2);
			me.iLabH = GetLayerHeight(me.divLabelBox2);			
		}
	}
	
	// label above sign case
	this.GetCoords2 = function ()
	{
		// default ret values:
		var newPxlY = me.iPxlY + me.iLabDY;
		var newPxlX = me.iPxlX + me.iLabDX;
	
		// input data
		var iViewW = me.pMap.GetMapViewWidth ();
		var iViewH = me.pMap.GetMapViewHeight ();	
		me.iLabLegD = 25;
		me.iLabLegY = 10;
		var iLabLegX2 = 15;
		var iLabLegY2 = 3;
		
		var bCollision = false;
		// calculation
		
		// right
		if ( iViewW < me.iPxlX - me.iLabLegD + me.iLabW )
		{
			newPxlX = iViewW + me.iLabLegD - me.iLabW  + me.iLabDX;	
			bCollision = true;		
		}
		
		// bottom
		if ( iViewH < me.iPxlY - me.iLabLegY)
		{
			newPxlY = iViewH + me.iLabLegY + me.iLabDY;			
			bCollision = true;		
		}
		
		// left
		if ( 0 > me.iPxlX - me.iLabDX - iLabLegX2)
		{
			newPxlX = me.iLabDX + iLabLegX2;			
			bCollision = true;		
		}
		
		// top
		var topMargin = me.pMap.GetMapPinLabelTopMargin(); 
		if ( topMargin > me.iPxlY - me.iLabDY - iLabLegY2 - me.iLabH)
		{
			newPxlY = me.iLabDY + iLabLegY2 + me.iLabH + topMargin;			
			bCollision = true;		
		}
		
		var bPinInView = true;		
		if ((me.iPxlY < 0) || (me.iPxlX < 0) || (me.iPxlX > iViewW) || (me.iPxlY > iViewH))
			bPinInView = false;
										
		return [newPxlY , newPxlX, bCollision, bPinInView];
	}
// -------------- design version 2 --- end
	
	this.ReArrange = function () 
	{				
		if (me.divLabelSign != null)
		{
			if(me.iImgRefX == "???")
				me.iImgRefX = Math.round(me.iImgWidth / 2);
			if(me.iImgRefY == "???")
				me.iImgRefY = Math.round(me.iImgHeight / 2);

			// in grid coordsys:
			me.divLabelSign.style.left = (me.pMarker.iPixX - me.iImgRefX) + "px";
			me.divLabelSign.style.top  = (me.pMarker.iPixY - me.iImgRefY) + "px";		
		}

		if (me.divLabelBox != null)
		{
			me.iPxlX = GetPxlX (me);
			me.iPxlY = GetPxlY (me);
			me.SetLabelBoxSizeFields();										
			var iPxlLabY = me.iPxlY + (me.iImgHeight - me.iImgRefY + 1 + me.iLabDY);
			var iPxlLabX = me.iPxlX + (-me.iImgRefX + me.iLabDX);
			var dX = 0;
			var bCollision = false;	
			var bPinInView = true;	
		
			if (me.m_bPositionCorrection == true)
			{
				var c = null;
				if (me.m_Position == "undersign")
				{
					c = GetCoords ( me.iPxlY + (me.iImgHeight-me.iImgRefY + 1 + me.iLabDY), me.iPxlX + (-me.iImgRefX + me.iLabDX), -(-me.iImgRefX + me.iLabDX), -(me.iImgHeight-me.iImgRefY + 1 + me.iLabDY),
								0,0,
								me.pMap.GetMapViewWidth (), me.pMap.GetMapViewHeight (),
								boxwidth,boxheight);
				}
				else
				{
				/*
					c = GetCoords ( me.iPxlY + (me.iImgHeight-me.iImgRefY + 1 + me.iLabDY), me.iPxlX + (-me.iImgRefX + me.iLabDX), -(-me.iImgRefX + me.iLabDX), -(me.iImgHeight-me.iImgRefY + 1 + me.iLabDY),
								0,0,
								me.pMap.GetMapViewWidth (), -me.pMap.GetMapViewHeight (),
								boxwidth,boxheight);				
								*/
								
					c = me.GetCoords2 ();
				}
											
				iPxlLabY = c[0];
				iPxlLabX = c[1];
				bCollision = c[2];
				bPinInView = c[3];
				
				if (me.divLabelLeg != null)
				{
					me.divLabelLeg.style.visibility = (bCollision) ? "hidden" : "visible";					
				}				
			}			
		
			me.divLabelBox.style.left = (iPxlLabX + me.pMap.pGridMain.GetMapViewVectorX()) + "px";
			me.divLabelBox.style.top  = (iPxlLabY + me.pMap.pGridMain.GetMapViewVectorY()) + "px";
			if (bPinInView)
				me.Show();
			else
				me.Hide();
		}	
	}
	
	this.Delete = function () 
	{
		me.RemoveSign ();
		me.RemoveBox ();			
	};
	
	
	this.Show = function () 
	{
		if (me.divLabelSign)	me.divLabelSign.style.visibility = "visible";
		if (me.divLabelBox)		me.divLabelBox.style.visibility = "visible";

		if (me.OnShow) {
			try {
				me.OnShow(me);
			}
			catch (exp) {
				if(me.pMap.OnError)
					me.pMap.OnError(exp,'Show.OnShow');
			}
		}			
	}
	
	
	this.Hide = function () 	
	{
		if (me.divLabelSign)	me.divLabelSign.style.visibility = "hidden";
		if (me.divLabelBox)		me.divLabelBox.style.visibility = "hidden";	
	}	
		
	PreLabelCreateG(me);	
}
