
function locOpenWindow(url,targetname,x,y,w,h,is_resize)
{
	var s='';
	if(y!='')s=s+'top='+y+',';
	if(x!='')s=s+'left='+x+',';
	if(w!='')s=s+'width='+w+',';
	if(h!='')s=s+'height='+h+',';
	s=s+'status=no,location=no,scrollbars=yes,resize=';
	if(is_resize=1) s=s+'yes';
	else s=s+'no';
	s=s+',directories=no,toolbar=no,menubar=no,copyhistory=no';
	window.open(url,targetname,s);
}

function MyOpenWindow(url)
{
	locOpenWindow(url,'_blank',(screen.width-450-30)/2,40,450,500,0);
}


function changeOpac(opacity, elem)
{
	elem.style.opacity = (opacity / 100);
	elem.style.MozOpacity = (opacity / 100);
	elem.style.KhtmlOpacity = (opacity / 100);
	elem.style.filter = "alpha(opacity=" + opacity + ")";
}

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function myGetWindowSize(id)
{
	var myWidth = 0, myHeight = 0;

	if (typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	if (id == 'width') return (myWidth);

	return (myHeight);
}

function getScrollXY(id)
{
	var scrOfX = 0, scrOfY = 0;

	if (typeof (window.pageYOffset) == 'number')
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}

	if (id == 'width') return (scrOfX);

	return (scrOfY);
}

function showPhoto(rAct)
{
	if (typeof rAct == "undefined")
	{
		getInfos("/?action=display_photo&id="+g_SelectedPhoto+"&mls="+g_SelectedMLS, null, showPhoto);
	}
	else if (rAct.readyState == 4 && rAct.status == 200)
	{
		var html = rAct.responseText;

		showOverViewer(html, 668, 538);
	}
}

function showMap(rAct)
{
	if (typeof rAct == "undefined")
	{
		getInfos("/?action=display_map&big=1&mls="+g_SelectedMLS, null, showMap);
	}
	else if (rAct.readyState == 4 && rAct.status == 200)
	{
		var html = rAct.responseText;

		//var vWidth  = myGetWindowSize('width') - 100;
		//var vHeight = myGetWindowSize('height') - 100;

		//showOverViewer(html, vWidth, vHeight);

		showOverViewer(html, 668, 538);


		var curPt = map.getCenter();
		var curZm = map.getZoom();
		var fctToExec;

		fctToExec = function()
		{			
			markerMan.addMarkers(markers, 7, 17);
			markerMan.refresh();

			map.addOverlay(selMarker);
			map.setCenter(curPt, curZm);

			map.enableScrollWheelZoom();
		}

		loadGMap(fctToExec, "map2");
	}
}

function OWNavig(navTo)
{
	txtOW = document.getElementById('OWtxt');

	getInfos(navTo, null, 
		function(rAct)
		{
			if (rAct.readyState == 4 && rAct.status == 200)
			{
				var html = rAct.responseText;

				txtOW.innerHTML = html;
			}
		});
}

function showOverViewer(html, width, height)
{
	var vWidth  = myGetWindowSize('width');
	var vHeight = myGetWindowSize('height');

	var sHeight = getScrollXY('height');

	var leftCoord = ((vWidth - width) / 2);
	var topCoord  = 10;

	if (vHeight > height) topCoord = sHeight + ((vHeight - height) / 2)


	onTopViewer = document.createElement("DIV");
	onTopViewer.id = "onTopViewer";
	document.body.appendChild(onTopViewer);

	filler = document.createElement("DIV");
	filler.style.backgroundColor = "black";
	filler.style.position = "absolute";
	filler.style.top    = "0px";
	filler.style.left   = "0px";
	filler.style.width  = "100%";
	filler.style.height = document.body.scrollHeight;
	filler.style.zIndex  = "999996";
	changeOpac(60, filler);
	onTopViewer.appendChild(filler);
	
	container = document.createElement("DIV");
	container.style.backgroundColor = "white";
	container.style.border = "black 4px solid";
	container.id = "OWtxt";
	container.style.position = "absolute";
	container.style.top    = topCoord+"px";;
	container.style.left   = leftCoord+"px";
	container.style.zIndex  = "999998";
	container.style.color = "white";

	container.innerHTML = html;

	onTopViewer.appendChild(container);
						
	frame = document.createElement("iframe");
	frame.style.position = "absolute";
	frame.style.top    = container.style.top;
	frame.style.left   = container.style.left;
	frame.style.width  = parseInt(width);
	frame.style.height = parseInt(height);
	frame.style.zIndex  = "999997"
	onTopViewer.appendChild(frame);

	//document.body.scrollTop  = 0;
	//document.body.scrollLeft = 0;
	document.body.style.overflow = "hidden";
}

function hideOverViewer(callback)
{
	//if("undefined" != typeof callback){callback();}

	var onTopViewer = document.getElementById("onTopViewer");

	if (onTopViewer != null)
	{
		while(onTopViewer.childNodes.length >= 1)
		{
			onTopViewer.removeChild(onTopViewer.firstChild);
		}

		document.body.removeChild(onTopViewer);
		document.body.style.overflow = "";
	}
}

function hideMap()
{
	var curPt = map.getCenter();
	var curZm = map.getZoom();

	mId = mId - 1;
	activateMap(mId);
	map.setCenter(curPt, curZm);
	map.addOverlay(selMarker);

	var onTopViewer = document.getElementById("onTopViewer");

	if (onTopViewer != null)
	{
		document.body.removeChild(onTopViewer);
		document.body.style.overflow = "";
	}
}
