var isMSIE = /*@cc_on!@*/false;
if (isMSIE) var classStr = "className";
else var classStr = "class";
var fDiv,fIFrame,fShadow;
var main;

function getScrollPos()
{
	return [(document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop];
}

function getWinSize()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth,myHeight];
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function hideMap(obj)
{
	fDiv.style.display = "none";
	return false;
}

function showMap(arg)
{
	if (!fDiv)
	{
		fDiv = document.createElement("div");
		fDiv.setAttribute("id","gMapsDiv");
		fDiv.style.display = "none";
		fDiv.style.position = "absolute";
		
		fClose = document.createElement("a");
		fClose.setAttribute("id","gMapsDivclose");
		fClose.style.position = "absolute";
		fClose.setAttribute("href","#");
		
		if (isMSIE)
		{
			fClose.onclick = function() { return hideMap(this); }
		} else {
			fClose.setAttribute("onclick","return hideMap(this)");
		}
		fDiv.appendChild(fClose);
		
		fIFrame = document.createElement("iframe");
		fIFrame.setAttribute("id","gMapsDivIframe");
		fIFrame.frameBorder = "0";
		
		main.appendChild(fDiv);
		fDiv.appendChild(fIFrame);
	}
	var coords = findPos(arg);
	
	
	var ws = getWinSize();
	var sp = getScrollPos();
	var dY = (ws[1] + sp[1]) - (coords[1] + 206);
	
	if (dY > 0) dY = 0;
	if (dY < -190) dY = -190;
	
	fDiv.style.top = (coords[1] + dY) + "px";
	if (ws[0] < (coords[0] + arg.offsetWidth + 316))
	{
		fDiv.setAttribute(classStr,"gMapsDivR");
		fDiv.style.left = (coords[0] - 300) + "px";
		fDiv.style.backgroundPosition = "100% " + (-dY) + "px";
	} else { 
		fDiv.setAttribute(classStr,"gMapsDivL");
		fDiv.style.left = (coords[0] + arg.offsetWidth) + "px";
		fDiv.style.backgroundPosition = "0 " + (-dY) + "px";
	}

	fDiv.style.display = "";
	fIFrame.setAttribute("src","./Popups/iframeGMaps.php?adr=" + arg.getAttribute("adr"));
	return false;
}

function initCm()
{
	main = document.getElementById("content");
	var list = main.getElementsByTagName("a");
	var str = "";
	var ok;
	
	for (var i = 0;li = list[i];i++)
	{
		ok = true;
		if (li.getAttribute("href"))
		{
			if (li.getAttribute("href").indexOf(".pdf") != -1)
			{
				li.setAttribute(classStr,"aPdf");
				ok = false;
			}
		}
		if (ok)
		{
			if (li.getAttribute("target") == "_blank")
			{
				li.setAttribute(classStr,"aBlank");
			}
		}
	}
	
	list = main.getElementsByTagName("table");
	var RE = />([^<&]*)[^<]*<[^>]*>[^<]*<[^>]*>[^<]*<[^>]*>[^<]*<[^>]*>[^>]*<td colspan=[^>]*>[^<&]*<p>([0-9][0-9][0-9][0-9][0-9]\ [a-zA-Z0-9_-]+)/gi;
	
	for (var i = 0;li = list[i];i++)
	{
		var res;
		if (li.getElementsByTagName("table").length == 0)
		{
			while (res = RE.exec(li.innerHTML))
			{
				var mapIcon = document.createElement("A");
				mapIcon.setAttribute(classStr,"mapIcon");
				mapIcon.setAttribute("href","#");
				mapIcon.setAttribute("adr",res[1] + " " + res[2]);
				if (isMSIE)
				{
					mapIcon.onclick = function() { return showMap(this); }
				} else {
					mapIcon.setAttribute("onclick","return showMap(this)");
				}
				var li = li.getElementsByTagName("td");
				li = li[0].firstChild;
				while (li.firstChild)
				{
					mapIcon.appendChild(li.firstChild);
				}
				li.appendChild(mapIcon);
			}
		}
	}
}

