﻿function CBannerManipulator()
{
	var me = this;

	// Térképi állapothoz köthető reklámok bejegyzése
	this.SetMapBanner = function(div, pTopoliszMap)
	{
		pTopoliszMap.OnMapStateChanged = function()
		{
			me.ShowMapBanner(div, pTopoliszMap.GetMapData());
		}
	}
	/*
	// A később keletkezendő térképhez tartozó reklámblokkok elkészítése
	this.OnCreateMap = function(pTopoliszMap)
	{
		var divMap = pTopoliszMap.GetMapDiv();
		var div = NewTag("div", divMap.parentNode, divMap.nextSibling);
		me.SetMapBanner(div, pTopoliszMap);
	}
	*/
	//CTopoliszMap.prototype.OnCreate = me.OnCreateMap; // static function

	// A címkereső állapotától függő reklámok
	this.SetAddressBanner = function(div, pRouteSearch)
	{
		var func = function(pDummy, pAddress)
		{
			me.ShowAddressBanner(div, pAddress);
		}
		CUtvonaltervAddressBlock.prototype.OnShow = func;
	}

	// Közlekedési reklámok
	this.SetTrafficBanner = function(div,pRouteResult)
	{
		pRouteResult.OnRouteChanged = function(pRoute)
		{
			me.ShowTrafficBanner(div, pRoute);
		}
	}

	//megjelenítés
	this.ShowMapBanner = function(div, mapdata)
	{
		var strCity = mapdata.strCaption;
		if(strCity != "")
		{
			while(div.firstChild) {
				div.removeChild(div.firstChild);
			}
			var iPos = strCity.indexOf('(');
			if(iPos >= 0)
				strCity = strCity.substr(0, iPos);
			var div = NewTag('div', div);
			div.className = 'banner';
			var iWidth = GetLayerWidth (div);
			var iCount = Math.floor(iWidth / 102);
			iWidth = iCount * 102;
			/*var iframe = NewIframe("http://www.hungaryrooms.com/affiliate/listView.php?braffcode=1043972374374646&limit="+iCount+"&city=" + strCity, iWidth, 137,div); // 5, 510
			iframe.className = "mapbanner";
			AddEvent(iframe,'load', function() {me.CheckIframe(iframe, div)});*/
			//AddTag(iframe, div);
		}
	}

	this.ShowAddressBanner = function(div, address)
	{
		if (address != null)
		{
			var strCity = address.strAddress.split(" ")[0];
			if(strCity.indexOf("megye") >=0)
				strCity = "";
			if(strCity != "")
			{
				while(div.firstChild)
				{
					div.removeChild(div.firstChild);
				}
				if(strCity == "Bp")
					strCity == "Budapest";

				var div = NewTag('div', div);
				div.className = 'banner';

				var iWidth = GetLayerWidth (div);
				var iCount = Math.floor(iWidth / 102);
				iWidth = iCount * 102;
				var iframe = NewIframe("http://www.hungaryrooms.com/affiliate/listView.php?braffcode=1043972374374646&limit="+iCount+"&city=" + strCity, iWidth, 137,div); // 5, 510
				iframe.className = "mapbanner";
				AddEvent(iframe,'load', function() {me.CheckIframe(iframe, div)});
				//AddTag(iframe, div);
			}
		}
	}
	
	this.CheckIframe = function(iframe, divToDelete)
	{
		/*var body = iframe.contentDocument;
		if(body.firstChild == null)
		{
			divToDelete.parentNode.removeChild(divToDelete);
		}*/
	}
	
	this.ShowTrafficBanner = function(divParent, pRoute)
	{
		while(divParent.firstChild)
			divParent.removeChild(divParent.firstChild);
		divParent.style.display = "none";
		if(pRoute != null)
		{
			var div = NewTag('div', divParent);
			div.className = "routeBanner";
			if(g_Babel.GetLang()=="en")
			{
				var xmlIc=document.createElement('object');
				xmlIc.setAttribute('type','application/x-shockwave-flash');
				xmlIc.setAttribute('data', '');
				xmlIc.data="images/topolisz_bch_en.swf";
				xmlIc.setAttribute('width', '');
				xmlIc.width="315";
				xmlIc.setAttribute('height','');
				xmlIc.height="240";
				var paramIc=document.createElement('param');
				paramIc.setAttribute('name','');
				paramIc.name="movie";
				paramIc.setAttribute('value','');
				paramIc.value="images/topolisz_bch_en.swf";
				xmlIc.appendChild(paramIc);
				div.appendChild(xmlIc);
				try
				{
					xmlIc.LoadMovie(0,"images/topolisz_bch_en.swf");
				}
				catch(e)
				{
				}
			}
			else
			{
				var xmlIc=document.createElement('object');
				xmlIc.setAttribute('type','application/x-shockwave-flash');
				xmlIc.setAttribute('data', '');
				xmlIc.data="images/barat_taxi_468_60.swf";
				xmlIc.setAttribute('width', '');
				xmlIc.width="468";
				xmlIc.setAttribute('height','');
				xmlIc.height="60";

				var paramIc=document.createElement('param');
				paramIc.setAttribute('name','');
				paramIc.name="movie";
				paramIc.setAttribute('value','');
				paramIc.value="images/barat_taxi_468_60.swf";
				xmlIc.appendChild(paramIc);
				div.appendChild(xmlIc);
				try
				{
					xmlIc.LoadMovie(0,"images/barat_taxi_468_60.swf");
				}
				catch(e)
				{
				}
			}

			var div = NewTag('div', divParent);
			div.className = "routeBanner";
			if (g_Babel.GetLang() != "" && g_Babel.GetLang() != "hu")
			{
				var xmlIc=document.createElement('object');
				xmlIc.setAttribute('type','application/x-shockwave-flash');
				xmlIc.setAttribute('data', '');
				xmlIc.data="images/topolisz_bch_hu.swf";
				xmlIc.setAttribute('width', '');
				xmlIc.width="315";
				xmlIc.setAttribute('height','');
				xmlIc.height="240";

				var paramIc=document.createElement('param');
				paramIc.setAttribute('name','');
				paramIc.name="movie";
				paramIc.setAttribute('value','');
				paramIc.value="images/topolisz_bch_hu.swf";
				xmlIc.appendChild(paramIc);
				div.appendChild(xmlIc);
				try
				{
					xmlIc.LoadMovie(0,"images/topolisz_bch_hu.swf");
				}
				catch(e)
				{
				}
			}
			else {
				iframe = NewIframe("http://www.logostudio.hu/box.php?partner=utvonalterv&template=1&service=25", 120, 120);
				AddTag(iframe, div);
			}

			var div = NewTag('div', divParent);
			div.className = "routeBanner";

			a = NewTag("a", div);
			a.setAttribute("target", "_blank");
			a.setAttribute("href", "http://www.domainrendeles.hu/");
			img = NewTag("img", a);
			SetImage(img, "http://www.domainrendeles.hu/banner/utvonalterv/domainrendeles.gif", 120, 120, "DomainRendelés");

			var div = NewTag('div', divParent);
			div.className = "routeBanner";
			iframe = NewIframe("http://www.dint.hu/partnerek/boxok/utvonalterv_nyelvipercek.php", 120, 120);
			AddTag(iframe, div);

			var div = NewTag('div', divParent);
			div.className = "routeBanner";
			a = NewTag("a", div);
			a.setAttribute("target", "_blank");
			a.setAttribute("href", "http://www.airporthotel.hu/partner/usr_start.php?nyelv=hu&partner=utvonalterv");
			img = NewTag("img", a);
			SetImage(img, "./images/partners/egyuttmukodo/parkolo_120_240.gif", 120, 240, "Airport Hotel");

			var div = NewTag('div', divParent);
			div.className = "routeBanner";
			var xmlIc=document.createElement('object');
			xmlIc.setAttribute('type','application/x-shockwave-flash');
			xmlIc.setAttribute('data', '');
			xmlIc.data="images/fot_120x240-2.swf";
			xmlIc.setAttribute('width', '');
			xmlIc.width="120";
			xmlIc.setAttribute('height','');
			xmlIc.height="240";
			var paramIc=document.createElement('param');
			paramIc.setAttribute('name','');
			paramIc.name="movie";
			paramIc.setAttribute('value','');
			paramIc.value="images/fot_120x240-2.swf";
			xmlIc.appendChild(paramIc);
			div.appendChild(xmlIc);
			try
			{
				xmlIc.LoadMovie(0,"images/fot_120x240-2.swf");
			}
			catch(e)
			{
			}
			
			divParent.style.display = "";
		}
		
	}

}

