var windowHeight = GetWindowHeight();
var windowWidth = GetWindowWidth();

function GetWindowWidth()
{
	var width=0;
	if(typeof(window.innerWidth)=='number')
	{
		width=window.innerWidth;
	}
	else if(document.documentElement&&document.documentElement.clientWidth)
	{
		width=document.documentElement.clientWidth;
	}
	else if(document.body&&document.body.clientWidth)
	{
		width=document.body.clientWidth;
	}
	if(!width||width<100)
	{
		width=100;
	}
	return width;
}
function GetWindowHeight()
{
	var height=0;
	if(typeof(window.innerHeight)=='number')
	{
		height=window.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		height=document.documentElement.clientHeight;
	}
	else if(document.body&&document.body.clientHeight)
	{
		height=document.body.clientHeight;
	}
	if(!height||height<100)
	{
		height=100;
	}
	return height;
}
function VE_Panel_o(id,x,y,width,height,color,zIndex,title,body,footer,mouseovertitle,addclosebutton)
{
	this.index=0;
	this.x=x;
	this.y=y;
	this.width=width;
	this.height=height;
	this.color=color;
	this.toolbarHeight=20;
	this.footerHeight=20;
	this.min=false;
	this.visible=true;
	this.onTitleClick=null;
	this.onCloseClick=null;
	var el=VE_Panel_o._CreateElement("div",id,"VE_Panel_o_el",zIndex);
	this.el=el;
	this.title=VE_Panel_o._CreateElement("a",id+"_title","VE_Panel_o_title VE_Panel_o_title_"+color+(mouseovertitle?" VE_Panel_o_title_mouseover":""),zIndex+1);
	this.title.innerHTML=title;
	this.title.onclick=VE_Panel_o._OnTitleClick;
	this.title.unselectable="on";
	el.appendChild(this.title);
	
	if(typeof addclosebutton == "undefined" || addclosebutton == "true")
	{
		this.cb=VE_Panel_o._CreateElement("a",id+"_cb","VE_Panel_o_cb VE_Panel_o_cb_"+color,zIndex+1);
		this.cb.innerHTML="X";
		this.cb.onclick=VE_Panel_o._OnCloseClick;
		this.cb.unselectable="on";
		el.appendChild(this.cb);

		this.hasclosebutton = true;
	}
	else
		this.hasclosebutton = false;

	
	this.tb=VE_Panel_o._CreateElement("div",id+"_tb","VE_Panel_o_tb VE_Panel_o_tb_"+color,zIndex+1);
	this.tb.unselectable="on";
	el.appendChild(this.tb);
	this.body=VE_Panel_o._CreateElement("div",id+"_body","VE_Panel_o_body",zIndex+1);
	
	if(typeof body == 'string')
		this.body.innerHTML=body;
	else
		this.body.appendChild(body);
		
	el.appendChild(this.body);
	this.foot=VE_Panel_o._CreateElement("div",id+"_foot","VE_Panel_o_foot VE_Panel_o_foot_"+color,zIndex+1);
	this.foot.innerHTML=footer;
	this.foot.unselectable="on";
	el.appendChild(this.foot);
	this.Resize();
	this.SetOpacity(90);
	VE_Panel_o.panels.push(this);
	document.body.appendChild(el);
}
VE_Panel_o.panels=new Array();
VE_Panel_o.shadowThickness=3;
VE_Panel_o._CreateElement=function(type,id,className,zIndex)
{
	var el=document.createElement(type);
	el.id=id;
	el.className=className;
	el.style.position="absolute";
	el.style.zIndex=zIndex;
	return el;
}
VE_Panel_o._PositionElement=function(el,x,y,w,h)
{
	el.style.top=y+"px";
	el.style.left=x+"px";
	el.style.width=w+"px";
	el.style.height=h+"px";
}
VE_Panel_o.prototype.SetPosition=function(x,y,w,h)
{
	this.x=x;
	this.y=y;
	this.w=w;
	this.h=h;
}
VE_Panel_o.prototype.SetToolbarSize=function(toolbarHeight)
{
	this.toolbarHeight=toolbarHeight;
	var d=eval(toolbarHeight)>0?"block":"none";
	this.tb.style.display=d;
	this.Resize();
}
VE_Panel_o.prototype.SetFooterSize=function(footerHeight)
{
	this.footerHeight=footerHeight;
	var d=eval(footerHeight)>0?"block":"none";
	this.foot.style.display=d;
	this.Resize();
}
VE_Panel_o.prototype.Resize=function()
{
	var x=eval(this.x);
	var y=eval(this.y);
	var w=Math.max(eval(this.width),100);
	var h=Math.max(eval(this.height),18);
	var th=eval(this.toolbarHeight);
	var fh=eval(this.footerHeight);
	var st=VE_Panel_o.shadowThickness;
	var by=21+th;
	var bh=h-27-th-fh;
	if(this.min)
	{
		h=21;
	}
	else
	{
		if(th>0)
		{
			VE_Panel_o._PositionElement(this.tb,1,19,w-4,th);
		}
		else
		{
			by-=2;
			bh+=2;
		}
		if(fh>0)
		{
			VE_Panel_o._PositionElement(this.foot,1,h-fh-3,w-4,fh);
		}
		else
		{
			bh+=2;
		}
		if(bh>0)
		{
			VE_Panel_o._PositionElement(this.body,1,by,w-4,bh);
		}
	}
	VE_Panel_o._PositionElement(this.el,x,y,w,h);
	
	if(this.hasclosebutton)
	{
		VE_Panel_o._PositionElement(this.title,1,1,w-19,17);
		VE_Panel_o._PositionElement(this.cb,w-19,1,16,17);
	}
	else
	{
		if(navigator.userAgent.toLowerCase().indexOf('gecko') != -1)
			VE_Panel_o._PositionElement(this.title,1,1,w-9,17);
		else
			VE_Panel_o._PositionElement(this.title,1,1,w-4,17);
	}
}
VE_Panel_o.prototype.SetTitle=function(c)
{
	this.title.innerHTML=IOSec.EncodeHtml(c);
}
VE_Panel_o.prototype.SetToolbar=function(c)
{
	this.tb.innerHTML=c;
}
VE_Panel_o.prototype.SetBody=function(c)
{
	this.body.innerHTML=c;
}
VE_Panel_o.prototype.SetFooter=function(c)
{
	this.foot.innerHTML=c;
}
VE_Panel_o.prototype.SetOpacity=function(o)
{
	if(o>=100)o=99.99;
	with(this.el.style)
	{
		filter="alpha(opacity:"+o+")";
		o*=0.01;
		KHTMLOpacity=o;
		MozOpacity=o;
		opacity=o;
	}
}
VE_Panel_o.prototype.SetColor=function(c)
{
	this.color=c;
	this.title.className="VE_Panel_o_title VE_Panel_o_title_"+c;
	this.foot.className="VE_Panel_o_foot VE_Panel_o_foot_"+c;
	
	if(this.hasclosebutton)
		this.cb.className="VE_Panel_o_cb VE_Panel_o_cb_"+c;
}
VE_Panel_o.prototype.Minimize=function()
{
	this.min=true;
	this.tb.style.display="none";
	this.body.style.display="none";
	this.foot.style.display="none";
	this.Resize();
}
VE_Panel_o.prototype.Maximize=function()
{
	this.min=false;
	if(eval(this.toolbarHeight)>0)
	{
		this.tb.style.display="block";
	}
	if(eval(this.footerHeight)>0)
	{
		this.foot.style.display="block";
	}
	this.body.style.display="block";
	this.Resize();
}
VE_Panel_o.prototype.Show=function()
{
	this.el.style.display="block";
	this.visible=true;
}
VE_Panel_o.prototype.Hide=function()
{
	this.el.style.display="none";
	this.visible=false;
}
VE_Panel_o.prototype.Toggle=function()
{
	if(this.min)
	{
		this.Maximize();
	}
	else
	{
		this.Minimize();
	}
}
VE_Panel_o.prototype.Destroy=function()
{
	document.body.removeChild(this.el);
	var p=VE_Panel_o.panels;
	for(var i=0;i<p.length;i++)
	{
		if(p[i]==this)
		{
			p.splice(i,1);
			return;
		}
	}
}
VE_Panel_o.ResizeAllPanels=function()
{
//	VE_Scratchpad._ResizePanel();
	var p=VE_Panel_o.panels;
	for(var i=0;
	i<p.length;
	i++)
	{
		p[i].Resize();
	}
}
function VE_Panel_oEvent(srcPanel)
{
	this.srcPanel=srcPanel;
}
VE_Panel_o.prototype._CreateEvent=function()
{
	return new VE_Panel_oEvent(this);
}
VE_Panel_o._OnTitleClick=function(e)
{
	if(!e)e=window.event;
	var t=GetTarget(e);
	var p=VE_Panel_o.panels;
	for(var i=0;
	i<p.length;
	i++)
	{
		if(p[i].title==t)
		{
			if(p[i].onTitleClick)
			{
				p[i].onTitleClick(p[i]._CreateEvent());
			}
			return;
		}
	}
}
VE_Panel_o._OnCloseClick=function(e)
{
	if(!e)e=window.event;
	var c=GetTarget(e);
	var p=VE_Panel_o.panels;
	for(var i=0;
	i<p.length;
	i++)
	{
		if(p[i].cb==c)
		{
			if(p[i].onCloseClick)
			{
				p[i].onCloseClick(p[i]._CreateEvent());
			}
			return;
		}
	}
}
function GetTarget(e)
{
	if(!e)var e=window.event;
	var eventTarget;
	if(e.srcElement)eventTarget=e.srcElement;
	else if(e.target)eventTarget=e.target;
	if(eventTarget.nodeType==3)eventTarget=targ.parentNode;
	return eventTarget;
}
function VE_ZoomControl(x,y,zoomLevel,position)
{
	this.x=x;
	this.y=y;
	this.offsetLeft=0;
	this.dragging=false;
	this.zoomLevel=zoomLevel;
	var el=document.createElement("div");
	el.id="VE_ZoomControl";
	el.style.position=position;
	el.style.left=x;
	el.style.top=y;
	this.el=el;
	var minus=document.createElement("a");
	minus.className="VE_ZoomControl_minus";
	minus.style.left="0px";
	minus.href="javascript:void(0)";
	minus.onclick=VE_ZoomControl._Minus;
	minus.unselectable="on";
	this.minus=minus;
	el.appendChild(minus);
	var bar=document.createElement("div");
	bar.className="VE_ZoomControl_bar";
	bar.style.left="26px";
	bar.unselectable="on";
	bar.onclick=VE_ZoomControl._Jump;
	this.bar=bar;
	el.appendChild(bar);
	var slider=document.createElement("a");
	slider.className="VE_ZoomControl_slider";
	slider.style.left="0px";
	slider.style.top="1px";
	slider.href="javascript:void(0)";
	slider.onmousedown=VE_ZoomControl._MouseDown;
//	slider.onmousemove=VE_ZoomControl._MouseMove;
//	slider.onmouseup=VE_ZoomControl._MouseUp;
	slider.unselectable="on";
	this.slider=slider;
	bar.appendChild(slider);
	var plus=document.createElement("a");
	plus.className="VE_ZoomControl_plus";
	plus.style.left="154px";
	plus.href="javascript:void(0)";
	plus.onclick=VE_ZoomControl._Plus;
	plus.unselectable="on";
	this.plus=plus;
	el.appendChild(plus);
	VE_ZoomControl.control=this;
	VE_ZoomControl.SetZoomLevel(zoomLevel);
}
VE_ZoomControl.control=null;
VE_ZoomControl.snaps=[0,9,18,27,36,44,52,60,68,76,84,91,97,102,106,110,114,117,120];
VE_ZoomControl.Create=function(x,y,z,position)
{
	VE_ZoomControl.control=new VE_ZoomControl(x,y,z,position);
	return VE_ZoomControl.control.el;
}
VE_ZoomControl._MouseDown=function(e)
{
	if(!e)e=window.event;
	e.cancelBubble=true;
	var z=VE_ZoomControl.control;
	var s=z.slider;
	if(s.setCapture)s.setCapture();
	
	// changes for firefox
	// avoids 'sticky' zoom slider
//	alert(window.attachEvent);
	window.attachEvent('onmousemove', _WindowMouseMove);
	window.attachEvent('onmouseup', _WindowMouseUp);
	
	z.dragging=true;
	return false;
}

function _WindowMouseMove()
{
	var e=window.event;
	e.cancelBubble=true;
	var c=VE_ZoomControl.control;

	if(c.dragging)
	{
		var s=c.slider;
		s.style.left=AdjustMouseXbyOffsets(GetMousePosX(e))+"px";
	}
}

function _WindowMouseUp()
{
	var e=window.event;
	e.cancelBubble=true;
	var c=VE_ZoomControl.control;
	var s=c.slider;
	if(s.releaseCapture)s.releaseCapture();

	window.detachEvent('onmousemove', _WindowMouseMove);
	window.detachEvent('onmouseup', _WindowMouseUp);
	
	c.dragging=false;
	VE_ZoomControl._SetPosition(AdjustMouseXbyOffsets(GetMousePosX(e)));
	return false;
}


/*
VE_ZoomControl._MouseMove=function(e)
{
	if(!e)e=window.event;
	e.cancelBubble=true;
	var c=VE_ZoomControl.control;

	if(c.dragging)
	{
		var s=c.slider;
		s.style.left=AdjustMouseXbyOffsets(GetMousePosX(e))+"px";
	}
	return false;
}

VE_ZoomControl._MouseUp=function(e)
{
	if(!e)e=window.event;
	e.cancelBubble=true;
	var c=VE_ZoomControl.control;
	var s=c.slider;
	if(s.releaseCapture)s.releaseCapture();
	if(window.releaseCapture)window.releaseCapture();
	c.dragging=false;
	VE_ZoomControl._SetPosition(AdjustMouseXbyOffsets(GetMousePosX(e)));
	return false;
}
*/

VE_ZoomControl._Plus=function(e)
{
	map.ZoomIn();
}
VE_ZoomControl._Minus=function(e)
{
	map.ZoomOut();
}
VE_ZoomControl._Jump=function(e)
{
	if(!e)e=window.event;
	e.cancelBubble=true;
	VE_ZoomControl._SetPosition(AdjustMouseXbyOffsets(GetMousePosX(e)));

	VE_ZoomControl.control.slider.style.left = AdjustMouseXbyOffsets(GetMousePosX(e))+"px";
}
function AdjustMouseXbyOffsets(x)
{
	var c=VE_ZoomControl.control;
	x=x-c.x-c.offsetLeft-(c.minus.offsetWidth+c.slider.offsetWidth/2);
	var m=c.bar.offsetWidth-c.slider.offsetWidth;
	if(x<0)x=0;
	if(x>m)x=m;
	return x;
}
VE_ZoomControl._SetPosition=function(x)
{
	var sn=VE_ZoomControl.snaps;
	var bd=VE_ZoomControl.control.bar.offsetWidth;
	var bi=0;
	for(var i=sn.length-1;i>=0;i--)
	{
		var d=Math.abs(x-sn[i]);
		if(d<bd)
		{
			bd=d;
			bi=i;
		}
		else
		{
			break;
		}
	}
	map.SetZoom(bi+1);
}
VE_ZoomControl.SetZoomLevel=function(zoomLevel)
{
	var c=VE_ZoomControl.control;
	var s=c.slider;
	var sn=VE_ZoomControl.snaps;
	c.zoomLevel=zoomLevel;
	s.style.left=sn[zoomLevel-1]+"px";
}
function CreateZoomWidget(zoom)
{
	var el=VE_ZoomControl.Create(5,75,zoom,"absolute",0);
	document.body.appendChild(el);
}
function ChangeMapStyle(mapStyle)
{
	map.SetMapStyle(mapStyle);
	UpdateMapStyleWidget();
}
function UpdateMapStyleWidget()
{
	var m=map.GetMapStyle();
	
	var labels=document.getElementById("labels");
	var nolabels=document.getElementById("nolabels");
	var road=document.getElementById("mapStyle_r");
	var hybrid=document.getElementById("mapStyle_h");
	road.className="mapLink";
	hybrid.className="mapLink";
	switch(m)
	{
		case"a":hybrid.className="mapLinkSel";
		hybrid.style.cursor="default";
		hybrid.href="javascript:ChangeMapStyle('a')";
		road.className="mapLink";
		road.style.cursor="hand";
		nolabels.style.fontWeight="bold";
		labels.style.fontWeight="normal";
		break;
		
		case"h":hybrid.className="mapLinkSel";
		hybrid.style.cursor="default";
		hybrid.href="javascript:ChangeMapStyle('h')";
		road.className="mapLink";
		road.style.cursor="hand";
		labels.style.fontWeight="bold";
		nolabels.style.fontWeight="normal";
		break;
		
		case"r":road.className="mapLinkSel";
		road.style.cursor="default";
		hybrid.style.cursor="hand";
		break;
		
		default:road.className="mapLinkSel";
	}
}

function GetMousePosX(e)
{
	var posX=0;
	if(e.pageX)
	{
		posX=e.pageX;
	}
	else if(e.clientX)
	{
		posX=e.clientX+document.body.scrollLeft;
	}
	return posX;
}
function GetMousePosY(e)
{
	var posY=0;
	if(e.pageY)
	{
		posY=e.pageY;
	}
	else if(e.clientY)
	{
		posY=e.clientY+document.body.scrollTop;
	}
	return posY;
}
function DisplayMapList()
{
	var m=document.getElementById("mapstylelist");
	m.style.left=GetElementLeftPosition('mapStyle_h');
	if(m.style.visibility=="visible")
	{
		m.style.visibility="hidden";
		if(m.releaseCapture)
		{
			m.releaseCapture();

		}
	}
	else
	{
		window.attachEvent("onclick",HideMapStyleList);
		m.style.visibility="visible";
		m.setCapture(false);
		m.focus();
		document.getElementById("toolslist").style.visibility="hidden";
	}
}
function item_MouseOver()
{
	var el=GetTarget();
	var d=document.getElementById(el.parentNode.id);
	d.style.visibility="visible";
	var options=d.childNodes;
	newOption=-1;
	for(i=0;i<options.length;i++)
	{
		options.item(i).className='item';
	}
	el.className="item_on";
	if(d.id=='whereambiglist')
		document.f.where.value=el.innerText;
	
}

function item_MouseOut()
{
	var el=GetTarget();
	el.className="item";
}

function GetElementLeftPosition(elemID)
{
	var offsetTrail=document.getElementById(elemID);
	var offsetLeft=0;
	while(offsetTrail)
	{
		offsetLeft+=offsetTrail.offsetLeft;
		offsetTrail=offsetTrail.offsetParent;
	}
	if(navigator.userAgent.indexOf("Mac")!=-1&&typeof(document.body.leftMargin)!="undefined")
	{
		offsetLeft+=document.body.leftMargin;
	}
	return offsetLeft;
}
function HideMapStyleList()
{
	var m=document.getElementById("mapstylelist");
	m.style.visibility="hidden";
	if(m.releaseCapture)
	{
		m.releaseCapture();
	}
}
