var advert_maxdurations = 4;var advert_spot_type = 2;var advert_spot_id = 129;var advert_spot_name = 'Naimisiin.info';var advert_width = 140;var advert_height = 140;var advert_maxcount = 10;var advert_ad_div = "advert_spot_129";document.write('<div id="advert_container" style="width: 100%; overflow-x: hidden; overflow-y: hidden; overflow: hidden; font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: normal; margin: 0px; padding: 0px;  text-align:left;">');document.write('<div id="advert_spot_129" style="word-wrap: break-word; text-align:left;"> </div> </div>');var advert_data = '25,30,4,2,9261,061http://www.haavalokuvaus.com/ [[=Terhi Ruuskanen Photography 036http://plainplay.com/banner/9261.png,2,9208,045http://www.sinunkuvasi.com [[=Sinunkuvasi.com036http://plainplay.com/banner/9208.png,2,8799,059http://www.jannemiettinen.fi [[=Valokuvaaja Janne Miettinen036http://plainplay.com/banner/8799.png,2,6079,048http://www.akactanya.hu [[=HÄÄT UNKARIN PUSTALLA036http://plainplay.com/banner/6079.png,';var advert_latest = 0;var advert_moderation = 0;var advert_click_for_more = "Klikkaa lisätietoja!";var advert_day = "päivä";var advert_days = "päivää";var advert_week = "viikko";var advert_weeks = "viikkoa";var advert_clicks = "klikkausta";var advert_title = "Jätä kuvailmoitus";var advert_text = "Tähän oma kuvailmoitus minuutissa.";var advert_price_only = "Hinta vain";var advert_currency = "\u20AC";var advert_locale = "&cc=fi&cl=fi";var advert_url = "";var advert_domain = "1";var advert_text_phone = "Puhelin";var advert_text_mail = "Sähköposti";var advert_text_website = "Verkkosivu";var advert_price_model = "1";
function advert_ad_imagetext(container, title, description, src, httplink, linkid, isInfo)
{
	if (!container)
		return;

	var containerDiv = document.createElement('a');

	if (!containerDiv)
		return;

	containerDiv.setAttribute("href", linkid);

	// if ad buying is embedded within site then do not open new page
	if (advert_url == '')
		containerDiv.setAttribute("target", "_blank");

	containerDiv.setAttribute("title", advert_click_for_more);

	containerDiv.style.display = "block";
	containerDiv.style.top = "0";
	containerDiv.style.left = "0";
	containerDiv.style.textDecoration = "none";
	containerDiv.style.width = (advert_width)+"px";
	if (!isInfo)
		containerDiv.style.minHeight = (advert_height)+"px";

	containerDiv.style.backgroundColor = "white";
	containerDiv.style.cursor = "pointer";
	containerDiv.style.position = "relative";
	containerDiv.style.overflowX = "hidden";
	containerDiv.style.overflowY = "hidden";
	containerDiv.style.overflow = "hidden";
	containerDiv.style.textAlign = "left";
	containerDiv.style.marginLeft = "auto";
	containerDiv.style.marginRight = "auto";

	var oDiv = document.createElement('div');
	if (!oDiv)
		return;

	if (container.appendChild(containerDiv) && containerDiv.appendChild(oDiv))
	{
		if (src)
		{
			var pDiv = document.createElement('img');
			if (pDiv)
			{
				{
					pDiv.setAttribute("src", src);
					pDiv.setAttribute("alt", "");
					pDiv.style.display = "block";
					pDiv.style.top = "0";
					pDiv.style.left = "0";
					pDiv.style.textDecoration = "none";
					pDiv.style.border = "none";
					pDiv.style.position = "relative";
					pDiv.style.overflowX = "hidden";
					pDiv.style.overflowY = "hidden";
					pDiv.style.overflow = "hidden";
					pDiv.style.width = "60px";
					pDiv.style.height = "60px";


					oDiv.style.marginRight = "5px";
					oDiv.style.styleFloat = "left";
					oDiv.style.cssFloat = "left";

					oDiv.appendChild(pDiv);
				}
			}
		}

		oDiv = document.createElement('div');

		oDiv.style.width = "235px";
		oDiv.style.styleFloat = "left";
		oDiv.style.cssFloat = "left";

		containerDiv.appendChild(oDiv);

		if (title)
		{
			var titleDiv = document.createElement('div');
			if (titleDiv)
			{
				var newText = document.createTextNode(title);
				if (newText)
				{
					titleDiv.appendChild(newText);

					titleDiv.style.color = "green";
					oDiv.appendChild(titleDiv);
				}

				titleDiv.style.fontSize = "12px";
				titleDiv.style.lineHeight = "15px";
				titleDiv.style.fontWeight = "bolder";
				titleDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
			}
		}

		if (description)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(description);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "14px";
					pDiv.style.color = "black";
					pDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					pDiv.style.fontWeight = 'normal';
					oDiv.appendChild(pDiv);
				}
			}
		}
		if (httplink && !isInfo)
		{
			var showlink = ''; //httplink;

			if (httplink.substr(0,"http://".length) != "http://" && httplink.substr(0,"https://".length) != "https://")
			{
				httplink = "http://" + httplink;
			}

			var link_name_pos = httplink.indexOf(" [[=");
			if (link_name_pos >= 0)
			{
				if (httplink.substr(link_name_pos+4).length > 0)
					showlink = httplink.substr(link_name_pos+4);
				else
					showlink = httplink.substr(0, link_name_pos);
				httplink = httplink.substr(0, link_name_pos);
			} else
			{
				showlink = httplink;
			}
			if (showlink)
			{
				if (showlink.substr(0,"http://".length) == "http://")
				{
					showlink = showlink.substr("http://".length);
				}
				if (showlink.substr(0,"https://".length) == "https://")
				{
					showlink = showlink.substr("https://".length);
				}
				var pos = showlink .indexOf("/");
				if (pos > 0)
				{
					showlink = showlink.substr(0,pos);
				}

				var pos2 = showlink.indexOf("?");
				if (pos2 > 0)
				{
					if (pos2 < pos || pos < 0)
					{
						showlink = showlink.substr(0,pos2);
					}
				}
			}

			var linkDiv = document.createElement('div');
			if (linkDiv)
			{
				var newText = document.createTextNode(showlink);
				if (newText)
				{
					linkDiv.appendChild(newText);
					linkDiv.style.fontSize = "12px";
					linkDiv.style.whiteSpace = "nowrap";
					linkDiv.style.color = "#117799";
					linkDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					linkDiv.style.fontWeight = 'normal';
					linkDiv.style.overflow = "hidden";
					linkDiv.style.lineHeight = "15px";
					linkDiv.style.height = "15px";
					linkDiv.style.paddingLeft = "2px";
					linkDiv.style.paddingRight = "2px";

					oDiv.appendChild(linkDiv);
				}
			}
		}
	}
}

function advert_ad_text(container, title, description, httplink, linkid, isInfo)
{
	if (!container)
		return;

	var containerDiv = document.createElement('a');

	if (!containerDiv)
		return;

	containerDiv.setAttribute("href", linkid);

	// if ad buying is embedded within site then do not open new page
	if (advert_url == '')
		containerDiv.setAttribute("target", "_blank");

	containerDiv.setAttribute("title", advert_click_for_more);

	containerDiv.style.display = "block";
	containerDiv.style.top = "0";
	containerDiv.style.left = "0";
	containerDiv.style.textDecoration = "none";
	containerDiv.style.width = (advert_width)+"px";
	if (!isInfo)
		containerDiv.style.minHeight = (advert_height+4)+"px";
	if (advert_spot_id == 43 || advert_spot_id == 50 || advert_spot_id == 0) // within iframe => no room for frame
	{
	} else
	if (!isInfo)
		containerDiv.style.border = "1px solid black";
	else if (advert_spot_type == 3)
	{
		containerDiv.style.marginTop = "5px";
	} 
	else
	{
//		containerDiv.style.border = "1px solid silver";
		containerDiv.style.marginBottom = "5px";
	}
	containerDiv.style.backgroundColor = "#fcfcfc";
	containerDiv.style.cursor = "pointer";
	containerDiv.style.position = "relative";
	containerDiv.style.overflowX = "hidden";
	containerDiv.style.overflowY = "hidden";
	containerDiv.style.overflow = "hidden";
	containerDiv.style.textAlign = "left";
	containerDiv.style.marginLeft = "auto";
	containerDiv.style.marginRight = "auto";
if (advert_spot_id == 0)
{
	containerDiv.style.styleFloat = "left";
	containerDiv.style.cssFloat = "left";
}
	var oDiv = document.createElement('div');

	if (oDiv && container.appendChild(containerDiv) && containerDiv.appendChild(oDiv))
	{
		oDiv.style.width = "100%";
//		oDiv.style.height = "100%";

		if (title)
		{
			var titleDiv = document.createElement('div');
			if (titleDiv)
			{
				var newText = document.createTextNode(title);
				if (newText)
				{
					titleDiv.appendChild(newText);

					if (isInfo)
					{
						titleDiv.style.color = "brown";
					} else
					{
						titleDiv.style.color = "green";
					}
					oDiv.appendChild(titleDiv);
				}

				titleDiv.style.fontSize = "11px";
				titleDiv.style.lineHeight = "16px";
				titleDiv.style.height = "16px";
				titleDiv.style.textTransform = "uppercase";
				titleDiv.style.whiteSpace = "nowrap";
				titleDiv.style.fontWeight = "bolder";
				titleDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
				titleDiv.style.overflow = "hidden";
				titleDiv.style.paddingLeft = "2px";
				titleDiv.style.paddingRight = "2px";
				titleDiv.style.paddingTop = "2px";
			}
		}

		if (description)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(description);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "11px";
					pDiv.style.lineHeight = "14px";
					pDiv.style.color = "black";
					pDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					pDiv.style.fontWeight = 'normal';
					pDiv.style.paddingLeft = "2px";
					pDiv.style.paddingRight = "2px";
					oDiv.appendChild(pDiv);
				}
			}
		}
		if (httplink && !isInfo)
		{
			var showlink = ''; //httplink;

			if (httplink.substr(0,"http://".length) != "http://" && httplink.substr(0,"https://".length) != "https://")
			{
				httplink = "http://" + httplink;
			}

			var link_name_pos = httplink.indexOf(" [[=");
			if (link_name_pos >= 0)
			{
				if (httplink.substr(link_name_pos+4).length > 0)
					showlink = httplink.substr(link_name_pos+4);
				else
					showlink = httplink.substr(0, link_name_pos);
				httplink = httplink.substr(0, link_name_pos);
			} else
			{
				showlink = httplink;
			}
			if (showlink)
			{
				if (showlink.substr(0,"http://".length) == "http://")
				{
					showlink = showlink.substr("http://".length);
				}
				if (showlink.substr(0,"https://".length) == "https://")
				{
					showlink = showlink.substr("https://".length);
				}
				var pos = showlink .indexOf("/");
				if (pos > 0)
				{
					showlink = showlink.substr(0,pos);
				}

				var pos2 = showlink.indexOf("?");
				if (pos2 > 0)
				{
					if (pos2 < pos || pos < 0)
					{
						showlink = showlink.substr(0,pos2);
					}
				}
			}

			var linkDiv = document.createElement('div');
			if (linkDiv)
			{
				var newText = document.createTextNode(showlink);
				if (newText)
				{
					linkDiv.appendChild(newText);
					linkDiv.style.fontSize = "11px";
					linkDiv.style.whiteSpace = "nowrap";
					linkDiv.style.color = "blue";
					linkDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					linkDiv.style.fontWeight = 'normal';
					linkDiv.style.overflow = "hidden";
					linkDiv.style.lineHeight = "16px";
					linkDiv.style.height = "16px";
					linkDiv.style.paddingLeft = "2px";
					linkDiv.style.paddingRight = "2px";

					oDiv.appendChild(linkDiv);
				}
			}
		}
	}

	if (!isInfo)
	{
		var marginDiv = document.createElement('div');
		marginDiv.style.height = "10px";
		marginDiv.style.width = "10px";
		marginDiv.style.overflow = "hidden";
if (advert_spot_id == 0)
{
		marginDiv.style.styleFloat = "left";
		marginDiv.style.cssFloat = "left";
}
		if (marginDiv)
		{
			container.appendChild(marginDiv);
		}
	} else
	{
		var marginDiv = document.createElement('div');
		marginDiv.style.height = "5px";
		marginDiv.style.overflow = "hidden";
		if (marginDiv)
		{
			container.appendChild(marginDiv);
		}
	}
}

function advert_ad_image(container, src, httplink, linkid, isInfo)
{
	if (!container)
	{
		return;
	}

	var oDiv;
	oDiv = document.createElement('a');

	if (!oDiv)
	{
		return;
	}

	if (container.appendChild(oDiv))
	{
		if (src)
		{
			var pDiv = document.createElement('img');
			if (pDiv)
			{
				{
					pDiv.setAttribute("src", src);
					pDiv.setAttribute("alt", "");
					pDiv.setAttribute("style", "display: block; top: 0; left: 0; text-decoration: none; border: none; cursor: pointer; position: relative; overflow-x: hidden; overflow-y: hidden; overflow: hidden; margin-bottom: 6px;");
					pDiv.style.display = "block";
					pDiv.style.top = "0";
					pDiv.style.left = "0";
					pDiv.style.textDecoration = "none";
					pDiv.style.border = "none";
					pDiv.style.cursor = "pointer";
					pDiv.style.position = "relative";
					pDiv.style.overflowX = "hidden";
					pDiv.style.overflowY = "hidden";
					pDiv.style.overflow = "hidden";
					pDiv.style.marginBottom = "6px";

					pDiv.style.marginLeft = "auto";
					pDiv.style.marginRight = "auto";

					oDiv.appendChild(pDiv);
				}
			}
		}
		if (httplink)
		{
			var showlink = advert_click_for_more;

			if (httplink.substr(0,"http://".length) != "http://" && httplink.substr(0,"https://".length) != "https://")
			{
				httplink = "http://" + httplink;
			}

			var link_name_pos = httplink.indexOf(" [[=");
			if (link_name_pos >= 0)
			{
				if (httplink.substr(link_name_pos+4).length > 0)
					showlink = httplink.substr(link_name_pos+4);
				else
					showlink = httplink.substr(0, link_name_pos);
				httplink = httplink.substr(0, link_name_pos);
			} else
			{
				showlink = httplink;
				if (showlink.substr(0,"http://".length) == "http://")
				{
					showlink = showlink.substr("http://".length);
				}
				if (showlink.substr(0,"https://".length) == "https://")
				{
					showlink = showlink.substr("https://".length);
				}
				var pos = showlink .indexOf("/");
				if (pos > 0)
				{
					showlink = showlink.substr(0,pos);
				}

				var pos2 = showlink.indexOf("?");
				if (pos2 > 0)
				{
					if (pos2 < pos || pos < 0)
					{
						showlink = showlink.substr(0,pos2);
					}
				}
			}

			oDiv.setAttribute("href", linkid);
			if (advert_url == '')
				oDiv.setAttribute("target", "_blank");
			oDiv.setAttribute("title", showlink );
			oDiv.style.textDecoration = "none";
		}
	}

	return;
}

function advert_get_location(location)
{
	var locationText = null;
	if (location == "00060100")
		locationText = "Android";
	else if (location == "00060200")
		locationText = "BlackBerry";
	else if (location == "00060300")
		locationText = "J2ME";
	else if (location == "00060400")
		locationText = "Palm";
	else if (location == "00060500")
		locationText = "Symbian";
	else if (location == "00060600")
		locationText = "Windows Mobile";
	else if (location == "00060700")
		locationText = "Web browser";
	return locationText;
}

var advert_items = [];
var advert_areas = [];
function advert_ad_service(container, title, description, mail, phone, src, location, link, street, post, linkid, isInfo)
{
	if (!container)
		return;

	var containerDiv = document.createElement('div');

	if (!containerDiv)
		return;

	containerDiv.style.display = "block";
	containerDiv.style.top = "0";
	containerDiv.style.left = "0";

	containerDiv.className = "advert_area_"+location;

	var select = document.getElementById('advert_service_area_select');
	if (select)
	{
		select.style.display = "block";
		for (i=0; i < select.options.length; i++)
		{
			if (select.options[i].value == location)
				select.options[i].style.display = "block";
		}
	}

	//containerDiv.style.minHeight = (advert_height+10)+"px";

	if (!isInfo)
	{
		containerDiv.style.borderBottom = "1px solid silver";
		containerDiv.style.paddingBottom = "5px";
		containerDiv.style.paddingTop = "5px";
	}
	else
	{
//		containerDiv.style.border = "1px solid silver";
//		containerDiv.style.marginBottom = "5px";
	}

	containerDiv.style.backgroundColor = "#ffffff";
//	containerDiv.style.cursor = "pointer";
	containerDiv.style.position = "relative";
	containerDiv.style.overflowX = "hidden";
	containerDiv.style.overflowY = "hidden";
	containerDiv.style.overflow = "hidden";
	containerDiv.style.textAlign = "left";

		containerDiv.style.width = (advert_width+10)+"px";
		containerDiv.style.marginLeft = "auto";
		containerDiv.style.marginRight = "auto";

//		oDiv.style.margin = "5px";

	var oDiv = document.createElement('div');

	if (oDiv && container.appendChild(containerDiv) && containerDiv.appendChild(oDiv))
	{
		oDiv.style.width = (advert_width)+"px";
		oDiv.style.minHeight = (advert_height)+"px"
		oDiv.style.backgroundColor = "#f4f4f4";
		oDiv.style.padding = "5px";
//		oDiv.style.marginLeft = "auto";
//		oDiv.style.marginRight = "auto";

		var imgDiv = document.createElement('div');
		if (imgDiv && oDiv.appendChild(imgDiv))
		{
			imgDiv.style.styleFloat = "left";
			imgDiv.style.cssFloat = "left";
			imgDiv.style.width = "180px";
			imgDiv.style.height = "180px";
			var pDiv = document.createElement('img');
			if (pDiv && src)
			{
				{
					pDiv.setAttribute("src", src);
					pDiv.setAttribute("alt", "");
					pDiv.style.display = "block";
					pDiv.style.top = "0";
					pDiv.style.left = "0";
					pDiv.style.textDecoration = "none";
					pDiv.style.border = "none";
					pDiv.style.cursor = "pointer";
					pDiv.style.position = "relative";
					pDiv.style.overflowX = "hidden";
					pDiv.style.overflowY = "hidden";
					pDiv.style.overflow = "hidden";

					imgDiv.appendChild(pDiv);
				}
			}
		}

		var contentDiv = document.createElement('div');
		contentDiv.style.styleFloat = "left";
		contentDiv.style.cssFloat = "left";
		contentDiv.style.paddingLeft = "10px";
		contentDiv.style.width = "290px";

		oDiv.appendChild(contentDiv)

		if (title)
		{
			var titleDiv = document.createElement('a');
			if (titleDiv)
			{
				var newText = document.createTextNode(title);
				if (newText)
				{
					titleDiv.appendChild(newText);

					if (isInfo)
					{
						titleDiv.style.color = "brown";
					} else
					{
						titleDiv.style.color = "green";
					}
					contentDiv.appendChild(titleDiv);
				}

				titleDiv.setAttribute("href", linkid);
				titleDiv.setAttribute("title", link);
				titleDiv.setAttribute("target", "_blank");

				titleDiv.style.fontSize = "18px";
				titleDiv.style.lineHeight = "22px";
				titleDiv.style.height = "22px";
				titleDiv.style.whiteSpace = "nowrap";
				titleDiv.style.color= "#117799";
				//titleDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
				titleDiv.style.overflow = "hidden";
/*				titleDiv.style.paddingLeft = "2px";
				titleDiv.style.paddingRight = "2px";
				titleDiv.style.paddingTop = "2px";
*/
				titleDiv.style.textDecoration = "none";
				titleDiv.onmouseover = function() {
					this.style.textDecoration = "underline";
				}			
				titleDiv.onmouseout = function() {
					this.style.textDecoration = "none";
				}			
			}
		}

		if (street)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(street);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "110%";
					pDiv.style.color = "black";
					pDiv.style.marginTop = "2px";
					contentDiv.appendChild(pDiv);
				}
			}
		}

		if (post)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(post);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "110%";
					pDiv.style.color = "black";
					contentDiv.appendChild(pDiv);
				}
			}
		}

		if (phone)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(advert_text_phone + " " + phone);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "18px";
					pDiv.style.color = "black";
					pDiv.style.marginTop = "2px";
					contentDiv.appendChild(pDiv);
				}
			}
		}

		if (mail)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createElement('a');
				if (newText)
				{
					newText.innerHTML = advert_text_mail;
					pDiv.appendChild(newText);

					newText.setAttribute("href", "mailto:"+mail+"?subject="+advert_spot_name);
					newText.setAttribute("title", mail);

					newText.style.textDecoration = "none";
					newText.onmouseover = function() {
						this.style.textDecoration = "underline";
					}			
					newText.onmouseout = function() {
						this.style.textDecoration = "none";
					}	

					newText.style.fontSize = "12px";
					newText.style.lineHeight = "18px";
					newText.style.color = "#117799";
					contentDiv.appendChild(pDiv);
				}
			}
		}

		if (link)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createElement('a');
				if (newText)
				{
					newText.innerHTML = advert_text_website;
					pDiv.appendChild(newText);

					newText.setAttribute("href", linkid);
					newText.setAttribute("title", link);
					newText.setAttribute("target", "_blank");

					newText.style.textDecoration = "none";
					newText.onmouseover = function() {
						this.style.textDecoration = "underline";
					}			
					newText.onmouseout = function() {
						this.style.textDecoration = "none";
					}	

					newText.style.fontSize = "12px";
					newText.style.lineHeight = "18px";
					newText.style.color = "#117799";
					contentDiv.appendChild(pDiv);
				}
			}
		}


		if (description)
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(description);
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "15px";
					pDiv.style.color = "black";
					//pDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					//pDiv.style.fontWeight = 'normal';
					pDiv.style.marginTop = "2px";
					contentDiv.appendChild(pDiv);
				}
			}
		}
		if (advert_text_phone == "Tel.")
		{
			var pDiv = document.createElement('div');
			if (pDiv)
			{
				var newText = document.createTextNode(advert_get_location(location));
				if (newText)
				{
					pDiv.appendChild(newText);

					pDiv.style.fontSize = "12px";
					pDiv.style.lineHeight = "15px";
					pDiv.style.color = "green";
					//pDiv.style.fontFamily = 'Verdana,Arial,Helvetica,sans-serif';
					//pDiv.style.fontWeight = 'normal';
					pDiv.style.marginTop = "2px";
					contentDiv.appendChild(pDiv);
				}
			}
		}

	}
	advert_items.push(containerDiv);

    for (l in advert_areas)
        if (advert_areas[l] === location) return;

	advert_areas.push(location);
}

function hasClass(e,name) {
	return e.className.match(new RegExp('(\\s|^)'+name+'(\\s|$)'));
}

function advert_area_select(e)
{
	var selectedIndex = e.selectedIndex;
	var option = e.options[selectedIndex];
	var name = "advert_area_"+option.value;
    for (l in advert_items)
	{
		var item = advert_items[l];
		var display = "none";
		if (e.value == 0)
			display = "block";
		else if (hasClass(item,name))
			display = "block";
		item.style.display = display;
	}
}

function advert_add_area_select(container)
{
	if (advert_areas.length > 1)
	{
		var main = document.createElement('div');
		if (main)
		{
			main.style.width = "490px";
			main.style.textAlign = "center";
			main.style.marginTop = "10px";
			main.style.marginBottom = "10px";
			main.style.marginLeft = "auto";
			main.style.marginRight = "auto";
			container.parentNode.insertBefore(main, container);
		}

		var div = document.createElement('div');
		if (div)
		{
			div.style.width = "200px";
			div.style.marginLeft = "auto";
			div.style.marginRight = "auto";
			main.appendChild(div);
		}

		var select = document.createElement('select');
		if (select)
		{
			select.style.width = "200px";
			select.setAttribute("id", "advert_service_area_select");
			select.setAttribute("name", "advert_service_area_select");
			select.onchange = function() {
				advert_area_select(this);
			}			
			main.appendChild(select);
		}

		advert_areas.sort();

		var option = document.createElement('option');

		if (advert_text_phone != "Tel.")
   	    	select.options[select.options.length] = new Option("Valitse alue", "0", false, true);
		else
   	    	select.options[select.options.length] = new Option("Select platform", "0", false, true);

	    for (l in advert_areas)
		{
			var location = advert_areas[l];
			var option = document.createElement('option');
			if (option)
			{
				var locationText = null;
				if (advert_text_phone != "Tel.")
				{
					if (location == "4d01")
						locationText = "Ahvenanmaa";
					if (location == "4d02")
						locationText = "Etel&auml;-Karjala";
					if (location == "4d03")
						locationText = "Etel&auml;-Pohjanmaa";
					if (location == "4d04")
						locationText = "Etel&auml;-Savo";
					if (location == "4d05")
						locationText = "It&auml;-Uusimaa";
					if (location == "4d06")
						locationText = "Kainuu";
					if (location == "4d07")
						locationText = "Kanta-H&auml;me";
					if (location == "4d08")
						locationText = "Keski-Pohjanmaa";
					if (location == "4d09")
						locationText = "Keski-Suomi";
					if (location == "4d0a")
						locationText = "Kymenlaakso";
					if (location == "4d0b")
						locationText = "Lappi";
					if (location == "4d0c")
						locationText = "Pirkanmaa";
					if (location == "4d0d")
						locationText = "Pohjanmaa";
					if (location == "4d0e")
						locationText = "Pohjois-Karjala";
					if (location == "4d0f")
						locationText = "Pohjois-Pohjanmaa";
					if (location == "4d10")
						locationText = "Pohjois-Savo";
					if (location == "4d11")
						locationText = "P&auml;ij&auml;t-H&auml;me";
					if (location == "4d12")
						locationText = "Satakunta";
					if (location == "4d13")
						locationText = "Uusimaa";
					if (location == "4d14")
						locationText = "Varsinais-Suomi";
					if (location == "4d15")
						locationText = "Verkkokauppa";
				} else
				{
					locationText = advert_get_location(location);
				}

				if (locationText)
				{
			        select.options[select.options.length] = 
		            new Option(locationText, location, false, false);
				}
			}
		} // for
	}
}

function advert_handle(str,msgs_container)
{
	var price = 0;
	var ad_life_time = 0;
	var i=0;
	var ad_count = 0;
	var count = 0; // ad count on cache

	if (str && msgs_container)
	{
		var pos = str.indexOf(",");
		if (pos > 0 && pos < 10)
		{
			price = str.substr(0,pos);
		} else
		{
			pos = str.length;
		}
		i = pos+1;
		pos = str.indexOf(",",i);
		if (pos <= i)
			return;
		ad_life_time = parseInt(str.substr(i,pos-i));
//		if (ad_life_time < 0 || ad_life_time > 365)
//			return;

		//alert("str: "+str.substr(i));
		// get count
		i = pos+1;
		pos = str.indexOf(",",i);
		if (pos <= i)
			return;
		count = Number(str.substr(i,pos-i));
		//alert("count: "+str.substr(i,pos-i));
		if (count < 0 || count > 100)
			return;
		i = pos+1;

		for (i=pos+1; i<str.length && pos>0 && count>0; count--)
		{
			var adtitle = '';
			var adcontent = '';
			var adlink = '';
			var msgtext = '';
			var src = '';
			var srclen = 0;
			var linkid = '';
			var contentlen = 0;
			var msglen = 0;
			var content_type = 0;
			var contenttext = '';
			var httplen = 0;
			var httplink = '';
			var linkidlen = 0;
			var httplinkid = '';
			var msgid = 0;

			var mail = '';
			var maillen = 0;
			var phone = '';
			var phonelen = 0;
			var location = '';
			var locationlen = 0;
			var street = '';
			var streetlen = 0;
			var post = '';
			var postlen = 0;



			adtitle = '';
			adcontent = '';
			adlink = '';
			msgtext = '';
			src = '';
			srclen = 0;
			linkid = '';
			contentlen = 0;
			msglen = 0;
			content_type = 0;
			contenttext = '';
			httplen = 0;
			httplink = '';
			linkidlen = 0;
			httplinkid = '';
			msgid = 0;

			mail = '';
			maillen = 0;
			phone = '';
			phonelen = 0;
			location = '';
			locationlen = 0;
			street = '';
			streetlen = 0;
			post = '';
			postlen = 0;


			var eof = str.indexOf(",",i);

					if (eof > 0)
					{
						// get content type
						pos = str.indexOf(",",i);
						if (pos <= i)
							return;
						content_type = Number(str.substr(i,pos-i));
						//alert("content_type: "+str.substr(i,pos-i));
//						if (content_type <= 0 || content_type > 3)
//							return;

						i = pos+1;
						// get message id
						pos = str.indexOf(",",i);
						if (pos <= i)
							return;
						msgid = Number(str.substr(i,pos-i));
						//alert("msgid: "+str.substr(i,pos-i));
						if (msgid  < 0)
							return;

						i = pos+1;

						if (content_type == 1 || content_type == 5) // text
						{
							// get msgtext
							pos = i+3;
							msglen = Number(str.substr(i,pos-i));
							if (msglen < 0 || msglen > 255)
								return;

							i = pos;
							msgtext = str.substr(i,msglen);
							//alert("msgtext: "+msglen+", "+msgtext);

							i += msglen;

							// get ad content
							pos = i+3;
							contentlen = Number(str.substr(i,pos-i));
							if (contentlen < 0 || contentlen > 255)
								return;

							i = pos;
							contenttext = str.substr(i,contentlen);

							//alert("contenttext : "+contenttext +", "+contentlen);

							i += contentlen;

							// get link
							pos = i+3;
							httplen = Number(str.substr(i,pos-i));

							if (httplen < 0 || httplen > 255)
								return;

							i = pos;
							httplink = str.substr(i,httplen);
							if (httplink && httplink != '0')
								linkid = 'http://plainplay.com/?i=' + msgid;

							if (content_type == 1)
							{
								i += httplen+1;

								advert_ad_text(msgs_container, msgtext, contenttext, httplink, linkid, false);
								ad_count++;
							} else
							{
								i += httplen;

								// get src
								pos = i+3;
								srclen = Number(str.substr(i,pos-i));

								if (srclen < 0 || srclen > 255)
									return;

								i = pos;
								src = str.substr(i,srclen);

								i += srclen+1;

								advert_ad_imagetext(msgs_container, msgtext, contenttext, src, httplink, linkid, false);
							}
						} else if (content_type == 2)
						{
							// get link
							pos = i+3;
							httplen = Number(str.substr(i,pos-i));

							if (httplen < 0 || httplen > 255)
								return;

							i = pos;
							httplink = str.substr(i,httplen);
							if (httplink && httplink != '0')
								linkid = 'http://plainplay.com/?i=' + msgid;

							i += httplen;


							// get src
							pos = i+3;
							srclen = Number(str.substr(i,pos-i));

							if (srclen < 0 || srclen > 255)
								return;

							i = pos;
							src = str.substr(i,srclen);

							i += srclen+1;

							advert_ad_image(msgs_container, src, httplink, linkid, false);
							ad_count++;
						} else if (content_type == 3)
						{
							// get msgtext
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							msgtext = str.substr(i,len);
							//alert("msgtext: "+len+", "+msgtext);
							i += len;

							// get ad content
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							contenttext = str.substr(i,len);
							//alert("contenttext : "+contenttext +", "+len);
							i += len;

							// get mail
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							mail = str.substr(i,len);
							//alert("mail: "+len+", "+mail);
							i += len;

							// get phone
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							phone = str.substr(i,len);
							//alert("phone: "+len+", "+phone);
							i += len;

							// get src
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							src = str.substr(i,len);
							//alert("src: "+len+", "+src);
							i += len;

							// get location
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							location = str.substr(i,len);
							//alert("location: "+len+", "+location);
							i += len;

							// get httplink 
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							httplink = str.substr(i,len);
							//alert("link: "+len+", "+httplink);
							i += len;

							// get street
							pos = i+3;

							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							street = str.substr(i,len);
							//alert("street: "+len+", "+street);
							i += len;

							// get post
							pos = i+3;
							len = Number(str.substr(i,pos-i));
							if (len < 0 || len > 255)
								return;
							i = pos;
							post = str.substr(i,len);
							//alert("post: "+len+", "+post);
							i += len;

							i++;
							ad_count++;

							if (httplink && httplink != '0')
								linkid = 'http://plainplay.com/?i=' + msgid;
							else
								linkid = '';

							advert_ad_service(msgs_container, msgtext, contenttext, mail, phone, src, location, httplink, street, post, linkid, false);
						}
				}
			}
	}

	if ( msgs_container && advert_price_model != 2 )
	{
		if (advert_spot_type == 3)
		{
			advert_add_area_select(msgs_container);
		}
		var domain_str = '';
		if (advert_domain >= 4)
			domain_str = '&domain='+advert_domain;
		var link = 'https://plainplay.com/?spot='+advert_spot_id+advert_locale+domain_str;
		if (advert_url != '')
		{
			link = advert_url;
		}

		var timestring = '';
		if (ad_life_time < 0)
			timestring = (-ad_life_time) + ' ' + advert_clicks;
		else if (ad_life_time == 1)
			timestring = advert_day;
		else if (ad_life_time == 7)
			timestring = advert_week;
		else if (ad_life_time % 7 == 0)
			timestring = ad_life_time/7 + ' ' + advert_weeks;
		else
			timestring = ad_life_time + ' ' + advert_days;

		var tt = '';
		var advert_adtime = '';
		if (ad_life_time < 0)
		{
			tt = advert_clicks;
			ad_life_time = -ad_life_time;
			advert_adtime = advert_maxdurations * ad_life_time;
		} else
		if (ad_life_time % 7 == 0)
		{
			tt = advert_weeks;
			advert_adtime = advert_maxdurations;
		} else
		{
			tt = advert_days;
			advert_adtime = (advert_maxdurations*ad_life_time);
		}

		if (price > 0)
			advert_text += ' ' + advert_price_only + ' ' + price + advert_currency + ' / ' + timestring+'!';
		else
			advert_text += ' ' + ' ' + price + advert_currency + '!';

		if (advert_maxdurations > 1)
			advert_text += ' Max. '+advert_adtime+' ' +tt+'.';

		if (/*price > 0 &&*/ ad_count < advert_maxcount)
		{
			advert_ad_text(msgs_container, advert_title, advert_text, link, link, true);
		}
	}
}

var advert_div = document.getElementById(advert_ad_div);
if (advert_div)
{
	advert_handle(advert_data,advert_div);
}

