// Copyright © 2007 Replisoft, LLC

// Options:
//	name			default: auto-incrementing id
//	width,height	default: 100x100
//	x,y				default: 0,0
//	zIndex			default: 1000
//	point			corner to show point in: 0=none(default),1=northwest,2=northeast,3=southwest,4=southeast
//	smallPoint		show a smaller point, default: false
//	parent			parent element to create it in, default: body
//	create			create it in the constructor, default: true
//	display			display when created, default: true
//	imagePath		path and base name for image files, default: images/bal
//	showClose		show the close button, default: true
//	underHTML		content to display under the pane
//	innerHTML		content to display in the pane
//	clearOnHide		clear the content when hiding, default: false
//	destroyOnHide	remove the element and content when hiding, default: false
//	onmouseover		code (string) to call on mouse over events
//	onmouseout		code (string) to call on mouse out events
//	onclick			code (string) to call on mouse click events
//	onpointclick	code (string) to call on point mouse click events
//	onclose			code (string) to call when close button is clicked, default: GlassPaneTable['{NAME}'].hide()
// In event strings and content, {NAME} is replaced by the object name, use GlassPaneTable['{NAME}'] to get the object
function GlassPane(opts,pos)
{
	this.options={};
	if(opts) { for(a in opts) this.options[a]=opts[a]; }
	this.element=null;
	this.created=false;
	if(!this.options.name) this.options.name="GP"+(GlassPaneNextID++);
	GlassPaneTable[this.options.name]=this;
	this.procOptions();
	if(pos) this.position(pos);
	else if(this.options.create) this.create();
}
var GlassPaneNextID=0;
var GlassPaneTable={};
GlassPane.prototype.create=function(opts)
{
	if(opts) { for(a in opts) this.options[a]=opts[a]; this.procOptions(); }
	var o=this.options;
	el=this.element;
	if(!el) {
		var el=document.createElement('div');
		el.style.position="absolute";
		el.style.zIndex=o.zIndex;
		el.style.display="none";
		o.parent.appendChild(el);
		this.element=el;
	}
	else if(!o.display) el.style.display="none";
	el.style.left=o.x; el.style.top=o.y;
	var w=o.width,h=o.height;
	var ex=w-58,mw=w-112,sy=h-12,mh=h-28;
	if(mh<0) mh=1; if(mw<0) mw=1;
	var n=o.name;
	var p=o.imagePath;
	var pt=o.point;
	var pth=o.smallPoint?24:32;
	var ht=
"<img id="+n+"pt src='"+p+"p"+(["nw","nw","ne","sw","se"][pt])+(o.smallPoint?"s":"")+".png' style='position:absolute;left:"+(pt&1?0:ex+4)+";top:"+(pt>2?h:-pth)+(pt?"":";display:none")+"' width="+(pt&1?54:58)+" height="+pth+" border=0"+(o.onpointclick?" onclick=\""+o.onpointclick+"\"":"")+(o.onmouseover?" onmouseover=\""+o.onmouseover+"\"":"")+(o.onmouseout?" onmouseout=\""+o.onmouseout+"\"":"")+">"+
"<div id="+n+"box style='position:absolute;width:"+w+";height:"+h+";top:0;left:0;overflow:hidden'"+(o.onmouseover?" onmouseover=\""+o.onmouseover+"\"":"")+(o.onmouseout?" onmouseout=\""+o.onmouseout+"\"":"")+">"+
" <div id="+n+"under style='position:absolute;top:0;left:0;width:"+w+";height:"+h+"'>"+o.underHTML+"</div>"+
" <div style='position:absolute;top:0;left:0;width:"+w+";height:"+sy+";overflow:hidden' id="+n+"nt>"+
"  <img src='"+p+"nw"+(pt==1?"p"+(o.smallPoint?"s":""):"")+".png' style='position:absolute;top:0;left:0' width=54 height=16 id="+n+"nw>"+
"  <img src='"+p+"n.png' style='position:absolute;top:0;left:54' width="+mw+" height=16 id="+n+"n>"+
"  <img src='"+p+"ne"+(pt==2?"p"+(o.smallPoint?"s":""):"")+".png' style='position:absolute;top:0;left:"+ex+"' width=58 height=16 id="+n+"ne>"+
"  <img src='"+p+"w.png' style='position:absolute;top:16;left:0' width=54 height="+mh+" id="+n+"w>"+
"  <img src='"+p+"m.png' style='position:absolute;top:16;left:54' width="+mw+" height="+mh+" id="+n+"m>"+
"  <img src='"+p+"e.png' style='position:absolute;top:16;left:"+ex+"' width=58 height="+mh+" id="+n+"e>"+
" </div>"+
" <img src='"+p+"sw"+(pt==3?"p"+(o.smallPoint?"s":""):"")+".png' style='position:absolute;top:"+sy+";left:0' width=54 height=12 id="+n+"sw>"+
" <img src='"+p+"s.png' style='position:absolute;top:"+sy+";left:54' width="+mw+" height=12 id="+n+"s>"+
" <img src='"+p+"se"+(pt==4?"p"+(o.smallPoint?"s":""):"")+".png' style='position:absolute;top:"+sy+";left:"+ex+"' width=58 height=12 id="+n+"se>"+
" <div id="+n+"inner style='position:absolute;top:0;left:0;width:"+w+";height:"+h+"'>"+o.innerHTML+"</div>"+
" <img id="+n+"close title='close' style='position:absolute;left:"+(w-26)+";top:9;cursor:pointer"+(o.showClose?"":";display:none")+"' src='"+p+"close.gif' width=12 height=11 border=0 onclick=\""+(o.onclose?o.onclose:"GlassPaneTable['"+n+"'].hide()")+"\">"+
"</div>";
	el.innerHTML=ht;
	this.created=true;
	if(o.display) el.style.display="";
}
GlassPane.prototype.update=function(opts)
{
	if(!this.created && (opts.create || this.options.create)) { this.create(opts); return; }
	if(opts) { for(a in opts) this.options[a]=opts[a]; this.procOptions(); }
	if(!this.created) return;
	var o=this.options;
	var el=this.element;
	if(!o.display) el.style.display="none";
	var n=o.name;
	var pt=o.point;
	var p=o.imagePath;
	if(opts.x||opts.y) {
		el.style.left=o.x; el.style.top=o.y;
	}
	if(opts.width) {
		var w=o.width;
		var ex=w-58,mw=w-112; if(mw<0) mw=1;
		document.getElementById(n+"box").style.width=w;
		document.getElementById(n+"inner").style.width=w;
		document.getElementById(n+"under").style.width=w;
		document.getElementById(n+"n").style.width=mw;
		document.getElementById(n+"m").style.width=mw;
		document.getElementById(n+"s").style.width=mw;
		document.getElementById(n+"ne").style.left=ex;
		document.getElementById(n+"e").style.left=ex;
		document.getElementById(n+"se").style.left=ex;
		document.getElementById(n+"close").style.left=w-26;
		if((pt&1)==0) document.getElementById(n+"pt").style.left=ex;
	}
	if(opts.height) {
		var h=o.height;
		var sy=h-12,mh=h-28; if(mh<0) mh=1;
		document.getElementById(n+"box").style.height=h;
		document.getElementById(n+"inner").style.height=h;
		document.getElementById(n+"under").style.height=h;
		document.getElementById(n+"nt").style.height=sy;
		document.getElementById(n+"w").style.height=mh;
		document.getElementById(n+"m").style.height=mh;
		document.getElementById(n+"e").style.height=mh;
		document.getElementById(n+"sw").style.top=sy;
		document.getElementById(n+"s").style.top=sy;
		document.getElementById(n+"se").style.top=sy;
		if(pt>2) document.getElementById(n+"pt").style.top=h;
	}
	if(opts.zIndex) el.style.zIndex=o.zIndex;
	if(opts.point || opts.point==0) {
		var dirs=["nw","nw","ne","sw","se"];
		var pt=o.point;
		var pth=o.smallPoint?24:32;
		for(var i=1;i<=4;i++) {
			document.getElementById(n+dirs[i]).src=p+dirs[i]+(i==pt?"p"+(o.smallPoint?"s":""):"")+".png";
		}
		var pel=document.getElementById(n+"pt");
		pel.src=p+"p"+dirs[pt]+(o.smallPoint?"s":"")+".png";
		pel.style.left=pt&1?0:o.width-54;
		pel.style.top=pt>2?o.height:-pth;
		pel.style.display=pt>0?"":"none";
		pel.style.width=pt&1?54:58;
		//document.getElementById(n+"close").src=p+"close"+(pt==2?"s":"c")+".png";
	}
	if(opts.showClose || opts.showClose==false) document.getElementById(n+"close").style.display=o.showClose?"":"none";
	if(opts.underHTML || opts.underHTML=="") document.getElementById(n+"under").innerHTML=o.underHTML;
	if(opts.innerHTML || opts.innerHTML=="") document.getElementById(n+"inner").innerHTML=o.innerHTML;
	if(o.display) el.style.display="";
}
GlassPane.prototype.show=function()
{
	this.options.display=true;
	if(!this.created) this.create();
	else this.element.style.display="";
}
GlassPane.prototype.hide=function()
{
	this.options.display=false;
	if(this.element) this.element.style.display="none";
	if(this.options.destroyOnHide) this.destroy();
	else if(this.options.clearOnHide) this.clear();
}
GlassPane.prototype.clear=function()
{
	if(this.element) this.element.innerHTML="";
	this.created=false;
}
GlassPane.prototype.destroy=function()
{
	if(!this.element) return;
	this.options.parent.removeChild(this.element);
	delete this.element;
	this.element=null;
	this.created=false;
}
GlassPane.prototype.procOptions=function()
{
	var o=this.options;
	for(var i=0;i<7;i++) {
		var s=["underHTML","innerHTML","onmouseover","onmouseout","onclick","onpointclick","onclose"][i];
		if(o[s]) o[s]=o[s].split("{NAME}").join(o.name);
	}
	for(i=0;i<3;i++) {	// default to true if not defined
		var s=["create","display","showClose"][i];
		if(typeof o[s]=='undefined') o[s]=true;
	}
	o.parent=o.parent||document.body;
	o.width=o.width||100; o.height=o.height||100;
	o.x=o.x||0; o.y=o.y||0;
	o.zIndex=o.zIndex||1000;
	o.point=o.point||0;  if(o.point<0 || o.point>4) o.point=0;
	o.imagePath=o.imagePath||"images/all/clean/bal";
	o.underHTML=o.underHTML||"";
	o.innerHTML=o.innerHTML||"";
	o.smallPoint=o.smallPoint||false;
}
// Options:
//	byEvent			event to take position from (pass event||window.event)
//	x,y				position within parent
//	dx,dy			position within document
//	offset			pixels to offset from position - positive=out, negative=in, default:0
//	showPoint		default: false
//	preferPoint		1=northwest(default),2=northeast,3=southwest,4=southeast
//	inWindow		try to keep it in the window, default: true, 'force' will slide it and remove pointer if necessary
//	inParent		keep it inside the parent, default: false
//	recreate		create the HTML again instead of updating, default: false
// Optional updated options to apply (see GlassPane options)
GlassPane.prototype.position=function(pos,updt)
{
	var o=this.options;
	if(updt) { for(a in updt) o[a]=updt[a]; }
	var px=0,py=0;	// parent's position
	var el=o.parent;
	while(el && el!=document.body) { px+=el.offsetLeft; py+=el.offsetTop; el=el.offsetParent; }
	var ax=0,ay=0;	// anchor point in document
	if(pos.byEvent) {
		e=pos.byEvent;
		if(e.pageX||e.pageY) { ax=e.pageX; ay=e.pageY; }
		else if(e.clientX||e.clientY||e.clientX==0) {
			var bs=bodyScroll();
			ax=e.clientX+bs.x; ay=e.clientY+bs.y;
		}
	} else {
		if(pos.dx||pos.dx==0) { ax=pos.dx; ay=pos.dy; }
		else if(pos.x||pos.x==0) { ax=pos.x+px; ay=pos.y+py; }
		else if(o.x||o.x==0) { ax=o.x+px; ay=o.y+py; }
	}
	var w=o.width||100,h=o.height||100;
	var xo=0,yo=0;
	if(pos.offset) { xo=pos.showPoint?(pos.offset/2)|0:pos.offset; yo=pos.offset; }
	var dx=0,dy=0;	// pane position in doc
	var sp=pos.showPoint;
	var pth=o.smallPoint?24:32;
	var pt;
	var fit;
	do {
		fit=false;
		pt=pos.preferPoint||1; if(pt<1 || pt>4) pt=1;
		if(sp) {
			dx=ax+(pt&1?xo-11:22-w-xo);
			dy=ay+(pt<3?yo+pth:8-pth-h-yo);
		} else {
			dx=ax+(pt&1?xo:1-w-xo);
			dy=ay+(pt<3?yo:1-h-yo);
		}
		if(pos.inWindow!=false) {
			var wp=bodyScroll();
			var ws=winSize();
			
			if(pt&1) {
				if(dx+w-wp.x>ws.w && ax-w-xo+(sp?12:1)>=0) { pt++; dx=ax+(sp?12:1)-w-xo; }
			} else {
				if(dx<wp.x) { pt--; dx=ax+xo-(sp?21:0); }
			}
			if(pt<3) {
				if(dy+h-wp.y>ws.h && ay-h-yo+(sp?8-pth:1)>=0) { pt+=2; dy=ay-h-yo+(sp?8-pth:1); }
			} else {
				if(dy<wp.y) { pt-=2; dy=ay+yo+(sp?pth:0); }
			}
			if(!sp) {
				if(dx+w-wp.x>ws.w) dx=wp.x+ws.w-w;
				if(dx<wp.x) dx=wp.x;
				if(dy+h-wp.y>ws.h) dy=wp.y+ws.h-h;
				if(dy<wp.y) dy=wp.y;
			} else if(pos.inWindow=='force') {
				if(dx+w-wp.x>ws.w || dx<wp.x || dy+h-wp.y>ws.h || dy<wp.y) { sp=false; fit=true; }
			}
		}
	} while(fit);
	if(pos.inParent) {
		if(sp) {
		
		} else {
			var pw=o.parent.offsetWidth||parseInt(o.parent.style.width);
			var ph=o.parent.offsetHeight||parseInt(o.parent.style.height);
			if(pw) {
				if(dx+w>px+pw) dx=px+pw-w;
				if(dx<px) dx=px;
			}
			if(ph) {
				if(dy+h>py+ph) dy=py+ph-h;
				if(dy<py) dy=py;
			}
		}
	}
	o={}; if(updt) { for(a in updt) o[a]=updt[a]; }
	o.x=dx-px; o.y=dy-py; o.point=sp?pt:0;
	if(pos.recreate) this.create(o);
	else this.update(o);
}


// Options:
//	overDelay		default: 10
//	outDelay		default: 10
//	autoHide		default: false
//	parent			"parent" popup to keep open, default: null
//	blockDelay		time to block it from opening if explicitly closed, default: 0
//	showing			function to call when it's about to be shown
//	hiding			function to call when it's just been hidden
//	pointClick		function to call when the point is clicked on
//	compareData		function to compare pending & current data, default: memberwise compare
// All functions except compareData called with this object as a parameter
function GlassPopup(opts,pane,pos)	// popup options, pane or pane options, optional pane position options
{
	this.idx=GlassPopupNextID++;
	GlassPopupList[this.idx]=this;
	if(opts) { for(a in opts) this[a]=opts[a]; }
	this.pane=null;
	var pevents={display:false,onmouseover:("GlassPopupList["+this.idx+"].overSelf()"),onmouseout:("GlassPopupList["+this.idx+"].out()"),onpointclick:("GlassPopupList["+this.idx+"].pclicked()"),onclose:("GlassPopupList["+this.idx+"].hide(true)")};
	if(pane&&pane.update) {
		this.pane=pane;
		this.pane.update(pevents);
	}
	else if(pane) {
		var p={};
		for(a in pane) p[a]=pane[a];
		for(a in pevents) p[a]=pevents[a];
		this.pane=new GlassPane(p);
	}
	this.overDelay=this.overDelay||10;
	this.outDelay=this.outDelay||10;
	this.blockDelay=this.blockDelay||0;
	this.data=this.data||null;
	this.pos=pos||{};
	this.pending=null;
	this.pendingParent=null;
	this.block=false;
	this.overTimer=null;
	this.outTimer=null;
	this.blockTimer=null;
	this.ex=0; this.ey=0;
	this.visible=false;
}
var GlassPopupList=[];
var GlassPopupNextID=0;
// Call this to start the over timer for showing, pass event or set e.pageX and e.pageY, optional data
GlassPopup.prototype.over=function(e,data,p)
{
	if(this.data && data) {
		if(this.compareData) {
			if(this.compareData(this.data,data)) { if(!this.block) this.isOver=true; if(this.outTimer!=null) clearTimeout(this.outTimer); this.outTimer=null; return; }
		} else if(data && this.data) {
			var eq=true;
			for(a in data) { if(data[a]!=this.data[a]) { eq=false; break; } }
			if(eq) { if(!this.block) this.isOver=true; if(this.outTimer!=null) clearTimeout(this.outTimer); this.outTimer=null; return; }
		}
	}
	if(!e) e=window.event;
	if(e.pageX||e.pageY) { this.ex=e.pageX; this.ey=e.pageY; }
	else if(e.clientX||e.clientY||e.clientX==0) {
		var bs=bodyScroll();
		this.ex=e.clientX+bs.x; this.ey=e.clientY+bs.y;
	}
	this.pending=data;
	this.pendingParent=p||null;
	if(this.overTimer!=null) clearTimeout(this.overTimer);
	this.overTimer=setTimeout("GlassPopupList["+this.idx+"].doShow()",this.overDelay);
}
GlassPopup.prototype.overSelf=function()
{
	this.isOver=true;
	if(this.outTimer!=null) { clearTimeout(this.outTimer); this.outTimer=null; }
}
GlassPopup.prototype.newestData=function() { return this.pending?this.pending:this.data; }
GlassPopup.prototype.pclicked=function()
{
	if(this.pointClick) {
		if(!this.pointClick(this.data)) {	// hide if it returns false
			if(this.overTimer!=null) { clearTimeout(this.overTimer); this.overTimer=null; }
			if(this.outTimer!=null) { clearTimeout(this.outTimer); this.outTimer=null; }
			this.pending=null;
			this.pendingParent=null;
			this.hide();
		}
	}
}
GlassPopup.prototype.out=function()
{
	this.isOver=false;
	this.pending=null; this.pendingParent=null;
	if(this.overTimer!=null) { clearTimeout(this.overTimer); this.overTimer=null; return; }
	if(this.outTimer!=null) { clearTimeout(this.outTimer); this.outTimer=null; }
	if(this.autoHide) this.outTimer=setTimeout("GlassPopupList["+this.idx+"].doHide()",this.outDelay);
}
// Call to show immediately without timer, optional data, position, and parent
GlassPopup.prototype.show=function(data,pos,p)
{
	if(this.overTimer!=null) clearTimeout(this.overTimer);
	if(this.blockTimer) { clearTimeout(this.blockTimer); this.blockTimer=null; }
	this.block=null;
	if(data) this.data=data;
	this.parent=p||null;
	if(pos) {
		for(a in pos) this.pos[a]=pos[a];
		if(pos.dx||pos.dx==0) this.ex=pos.dx;
		if(pos.dy||pos.dy==0) this.ey=pos.dy;
	}
	this.pending=null; this.pendingParent=null;
	this.doShow();
}
// Call this to hide without timer
GlassPopup.prototype.hide=function(block)
{
	if(this.outTimer!=null) clearTimeout(this.outTimer);
	this.pending=null; this.pendingParent=null;
	if(block && this.blockDelay) {
		d=this.data;
		this.block=true;
		if(this.blockTimer!=null) clearTimeout(this.blockTimer);
		this.blockTimer=setTimeout("GlassPopupList["+this.idx+"].endBlock()",this.blockDelay);
		this.doHide();
		this.data=d;
		return;
	}
	this.doHide();
}
GlassPopup.prototype.endBlock=function() { this.blockTimer=null; this.block=false; this.data=null; }
GlassPopup.prototype.doShow=function()
{
	this.overTimer=null;
	if(this.blockTimer) { clearTimeout(this.blockTimer); this.blockTimer=null; }
	this.block=null;
	if(this.pending) { this.data=this.pending; this.pending=null; this.parent=this.pendingParent; this.pendingParent=null; }
	var o=null;
	if(this.showing) o=this.showing(this);	// showing can return pane options to use
	if(this.parent) this.parent.autoHide=false;
	o=o||{};
	o.create=true; o.display=true;
	this.pos.dx=this.ex; this.pos.dy=this.ey;
	this.pane.position(this.pos,o);
	this.isOver=true;
	this.visible=true;
}
GlassPopup.prototype.doHide=function()
{
	this.outTimer=null;
	if(!this.visible) return;
	if(this.parent) { this.parent.autoHide=true; if(!this.parent.isOver && this.parent.out) this.parent.out(); }
	this.pane.hide();
	if(this.hiding) this.hiding(this);
	this.data=null;
	this.isOver=false;
	this.visible=false;
}

function winSize()
{
	if(self.innerWidth) return {w:self.innerWidth,h:self.innerHeight};
	else if(document.documentElement && document.documentElement.clientWidth) return {w:document.documentElement.clientWidth,h:document.documentElement.clientHeight};
	else if(document.body) return {w:document.body.clientWidth,h:document.body.clientHeight};
	return {w:1000,h:750};
}

function bodyScroll()
{
	return {x:0+(document.body.scrollLeft?document.body.scrollLeft:document.documentElement.scrollLeft),
		y:0+(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop)};
}



// Balloons
var popDelay=500;

// Map balloon
var baseIcon,gmap=null,geocoder=null;
function mapinit()
{
	if(gmap) return;
	gmap = new GMap2(document.getElementById("mapbalmap"),{size:new GSize(300,240)});
	gmap.addControl(new GSmallMapControl());    
	gmap.addControl(new GScaleControl());    
	baseIcon = new GIcon();    
	baseIcon.image = "/sys/images/all/redmarker.png";    
	baseIcon.iconSize = new GSize(20, 20);    
	baseIcon.shadowSize = new GSize(20, 20);    
	baseIcon.iconAnchor = new GPoint(6, 20);    
	baseIcon.infoWindowAnchor = new GPoint(5, 1);    
	gmap.setCenter(new GLatLng(180,0));
	
	var dc=document.cookie;
	var pos=dc.indexOf("addr1=");
	if(pos>=0) {
		var end=dc.indexOf(";",pos);
		if(end<0) end=dc.length;
		document.mapbalform["addr1"].value=unescape(dc.substring(pos+6,end));
	}
}
function mapover(e,name,addr,city,st,zip,geo,p)
{
	if(geo && !p && typeof(geo)!="string") { p=geo; geo=''; }	// for backward compatability
	var str=addr;if(str.length)str+=", ";str+=city;if(st.length)str+=", "+st;if(zip.length)str+=" "+zip;
	mappop.over(e,{n:name,a:addr,c:city,s:st,z:zip,g:str,l:geo},p);
	mapinit();
}
function mapout() {	mappop.out() }
function mapclick()
{
	var d=mappop.newestData();
	if(!d) return;
	mappop.hide();
	map(d.n,d.a,d.c,d.s,d.z,d.l);
}
function mapshow(p)
{
	if(!p.data) return;
	if(wfpop.visible) p.parent=wfpop;
	document.getElementById("mapname").innerHTML=p.data.n;
	document.getElementById("mapaddr").innerHTML=p.data.g;
	document.getElementById("mapbalnotfound").style.top=-90;
	gmap.setCenter(new GLatLng(180,0));
	trynum=0;
	
	setTimeout("mapgeocode()",1);
}
function maphide(p) { p.parent=null; }
function mapdir()
{
	var saddr=escape(document.mapbalform["addr1"].value);
	var daddr=escape(mappop.data.g);
	if(typeof(mappop.data.l)=='string' && mappop.data.l.length) daddr+=escape(" @"+mappop.data.l);
	mappop.hide();
	document.cookie="addr1="+saddr+";expires=Fri, 31-Dec-2023 00:00:00 GMT";
	window.open("http://maps.google.com/?saddr="+saddr+"&daddr="+daddr,"Directions","titlebar=no,status=no,toolbar=no,menubar=no,resizable=yes");
}
function mapgeocode()
{
	if(!mappop.data) return;
	var lat=null;
	var lon=null;
	var lev=15;
	var geo=mappop.data.l;
	if(geo && geo.length) {
		geo=geo.split(",");
		if(geo.length>1) {
			lat=parseFloat(geo[0]);
			lon=parseFloat(geo[1]);
		}
		if(geo.length>2) lev=parseInt(geo[2]);
	}
	if(lat||lon) {
		placeMarker(lev,lat,lon);
	} else {
		if(!geocoder) geocoder=new GClientGeocoder();
		geocoder.getLocations(mappop.data.g,geocodeCallback);
	}
}
function geocodeCallback(g)
{
	if(!mappop.data) return;
	if(!g || g.Status.code!=200) {	// not found
		gmap.setCenter(new GLatLng(37.150677,-97.690431),2);
		document.getElementById("mapbalnotfound").style.top=90;
	} else {
		var b=0,ba=0;
		if(typeof(zipcodes)!="undefined") {
			for(i=0;i<g.Placemark.length;i++) {
				var a=0,zip=null,p=g.Placemark[i];
				if(p.AddressDetails) p=p.AddressDetails;
				if(p.Accuracy) a=p.Accuracy;
				if(p.Country) p=p.Country;
				if(p.AdministrativeArea) p=p.AdministrativeArea;
				if(p.SubAdministrativeArea) p=p.SubAdministrativeArea;
				if(p.Locality) p=p.Locality;
				if(p.LocalityName && p.LocalityName.toLowerCase()==mappop.data.c.toLowerCase()) a++;
				if(p.PostalCode) zip=p.PostalCode.PostalCodeNumber;
				if(!zip) continue;
				if(zipcodes.indexOf(","+zip+",")>=0 && a>ba) { b=i; ba=a; }
			}
		}
		var p=g.Placemark[b];
		var lev=7+p.AddressDetails.Accuracy;
		placeMarker(lev,p.Point.coordinates[1],p.Point.coordinates[0]);
	}
}
function placeMarker(lev,lat,lon)
{
	var pt=new GLatLng(lat,lon);
	gmap.setCenter(pt,lev); 
	var marker=new GMarker(pt,baseIcon);
	var cap="<div style='font-family:arial;font-size:11px;text-align:left'><b>"+mappop.data.n+"</b><br>"+mappop.data.g+"</div>";             
	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(cap);  }); 
	gmap.clearOverlays();
	gmap.addOverlay(marker);
}

var mappop=new GlassPopup(
	{autoHide:true,overDelay:popDelay,outDelay:popDelay,showing:mapshow,hiding:maphide,pointClick:mapclick},
	{create:false,x:-500,y:-500,width:335,height:330,innerHTML:"<span id=mapname style='position:absolute;top:10;left:5;width:310;font-family:arial;font-size:12px;font-weight:bold;text-align:center;overflow:hidden'></span><span id=mapaddr style='position:absolute;top:27;left:5;width:310;font-family:arial;font-size:12px;text-align:center;overflow:hidden'></span><div style='width:302px;height:242px;background-color:#666;position:absolute;top:45px;left:14px;overflow:hidden'><div id='mapbalmap' style='width:300px;height:240px;position:absolute;top:1px;left:1px;z-index:1;overflow:hidden'></div><div id='mapbalnotfound' style='width:200px;height:50px;position:absolute;top:-90px;left:51px;z-index:2;font-family:arial;font-size:14px;font-weight:bold;text-align:center;border-width:1px;border-style:solid;border-color:#f22;background-color:#ddd;padding-top:6px' onclick='this.style.top=-90'>Sorry, this address could<br>not be found on the map.</div><div style='width:66px;height:13px;position:absolute;top:0px;left:118px;z-index:2;font-family:arial;font-size:11px;line-height:12px;text-align:center;border-width:1px;border-style:solid;border-color:#008;background-color:#fff;color:#00c;cursor:pointer;-moz-opacity:.75;opacity:.75;filter:alpha(opacity=75);' onclick='mapclick()'>Large Map</div></div><span style='position:absolute;top:295;left:15;font-family:arial;font-size:12px'>Directions&nbsp;from:</span><form name=mapbalform onsubmit='mapdir();return false'><input name=addr1 type=text style='position:absolute;top:292;left:105;font-family:arial;font-size:12px;width:172;height:21'><img src='images/all/go.png' title='get directions' onclick='mapdir()' style='position:absolute;top:292;left:281' width=35 height=22 border=0></form>"},
	{showPoint:true,inWindow:"force"});
setTimeout("mappop.pane.show()",100);


// Web balloon
function webover(e,iid,url,name,p)
{
	webpop.over(e,{i:iid,u:url,n:name},p);
	if(!webpop.pane.created) webpop.pane.create();
}
function webout() {	webpop.out() }
function webclick()
{
	var d=webpop.newestData();
	if(!d) return;
	webpop.hide();
	ll(16,d.i,d.u);
}
function webshow(p)
{
	if(!p.data) return;
	if(wfpop.visible) p.parent=wfpop;
	document.getElementById("webname").innerHTML=p.data.n;
	document.getElementById("webaddr").innerHTML="<a href='javascript:void webclick()'>"+p.data.u+"</a>";
	document.getElementById("webimg").innerHTML="<img src='images/web/"+encodeURIComponent(encodeURIComponent(p.data.u))+".gif' border=0 onclick='webclick()' style='cursor:pointer'>";
}
function webhide(p) { p.parent=null; }
var webpop=new GlassPopup(
	{autoHide:true,overDelay:popDelay,outDelay:popDelay,showing:webshow,hiding:webhide,pointClick:webclick},
	{width:335,height:290,create:false,innerHTML:"<span id=webname style='position:absolute;top:10;left:5;width:310;font-family:arial;font-size:12px;font-weight:bold;text-align:center;overflow:hidden'></span><span id=webaddr style='position:absolute;top:27;left:5;width:310;font-family:arial;font-size:12px;font-weight:bold;text-align:center;overflow:hidden'></span><table cellspacing=0 cellpadding=0 border=0 style='position:absolute;top:47px;left:15px;width:300px;height:225px'><tr><td id='webimg' align=center valign=middle></td></tr></table>"},
	{showPoint:true,inWindow:"force"});


// Web feature balloon
function wfover(e,i)
{
	if(!document.getElementById("ad"+i)) return true;
	if(!e) e=window.event;
	wfpop.over(e,{el:"ad"+i});
}
function wfout(i)
{
	wfpop.out();
	return true;
}
function wfshow(p)
{
	if(!p.data) return;
	p.pane.hide();
	p.autoHide=true;
	var el=document.getElementById(p.data.el);
	var w=parseInt(el.firstChild.style.width),h=parseInt(el.firstChild.style.height);
	w+=35; h+=26; if(h<55) h=55;
	var ht=el.innerHTML;
	if(ht.indexOf('")"')!=-1) ht=ht.split('"webover').join("'webover").split('")"').join("\")'");
	
	ht="<div style='position:absolute;left:12;top:9;width:"+w+";height:"+h+";z-index:0'>"+ht+"</div>";
	document.getElementById(p.data.el).firstChild.style.display='none';
	document.getElementById(p.data.el).style.display='';
	el=document.getElementById(p.data.el).offsetParent.offsetParent;
	document.getElementById(p.data.el).style.display='none';
	document.getElementById(p.data.el).firstChild.style.display='';
	return {width:w,height:h,parent:el,innerHTML:ht};
}
var wfpop=new GlassPopup(
	{autoHide:true,overDelay:100,outDelay:100,blockDelay:5000,showing:wfshow},
	{create:false,destroyOnHide:true,zIndex:900},
	{showPoint:false,inParent:true});


// Ad balloon
function adover(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if(targ.nodeType==3) targ = targ.parentNode; // defeat Safari bug
	else if(!targ.href || targ.tagName.toLowerCase()=="img") targ = targ.parentNode;
	if(!targ.href) return;
	var hsp=targ.href.split(",");
	var a1=hsp[0].split("(")[1];
	adpop.over(e,{s:(hsp.length==4?a1:sec),i:(hsp.length==4?hsp[1]:a1),w:parseInt(hsp[hsp.length-2]),h:parseInt(hsp[hsp.length-1].split(")")[0])});
}
function adout() { adpop.out() }
function adclick()
{
	var d=adpop.newestData();
	if(!d) return;
	adpop.hide();
	if(typeof spopad!='undefined') spopad(d.s,d.i,d.w,d.h); else popad(d.i,d.w,d.h);
}
function adshow(p)
{
	var a=p.data;
	if(!a) return;
	var wf=300/a.w,hf=300/a.h;
	var sc=((wf<hf?wf:hf)*1000)|0;
	if(sc>500) sc=500;
	var w=(sc*a.w/1000)|0,h=(sc*a.h/1000)|0;
	var bw=w+30,bh=h+50;
	if(bw<150) bw=150; if(bh<100) bh=100;
	return {width:bw+5,height:bh,innerHTML:("<span style='position:absolute;top:10;left:5;width:"+(bw-12)+";font-family:arial;font-size:12px;text-align:center'><a href='javascript:void adclick()'>Click to enlarge</a></span><table cellspacing=0 cellpadding=0 border=0 style='position:absolute;top:30px;left:15px;width:"+(bw-30)+"px;height:"+(bh-50)+"px'><tr><td align=center valign=middle><iframe width="+w+" height="+h+" border=0 frameborder=no marginwidth=0 marginheight=0 scrolling=no src='pageserver.dll?b="+a.s+"&f=pw"+a.i+"&z="+sc+"'></iframe></td></tr></table><img src=clr.gif width="+(bw-30)+" height="+(bh-50)+" style='position:absolute;top:30px;left:15px;cursor:pointer' border=0 onclick='adclick()'>")};
}
var adpop=new GlassPopup(
	{autoHide:true,overDelay:popDelay,outDelay:popDelay,showing:adshow,pointClick:adclick},
	{create:false,clearOnHide:true},
	{showPoint:true});


// Text balloon
function textover(e,iid)
{
	if(!e) e=window.event;
	textpop.over(e,iid);
	if(!textpop.pane.created) textpop.pane.create();
}
function texthide() { textpop.hide() }
function textout() { textpop.out() }
function textshow(p)
{
	if(!p.data) return;
	textImp=p.data;
	document.getElementById('tsent').style.display='none';
	setTimeout("setsend();document.getElementById('tnum').focus()",200);
}
var textpop=new GlassPopup(
	{autoHide:false,overDelay:popDelay,outDelay:popDelay,showing:textshow},
	{width:260,height:140,zIndex:10000,create:false,innerHTML:"<form name=textform style='margin:0px'><div style='margin:20px 20px 10px 10px;position:relative'><img style='position:relative;top:3px' src=images/31/cell16.png width=16 height=16>Text to number <input type=text id=tnum name=tnum value='' style='width:100px;padding-left:1px;border:1px solid #888'><br><br><select name=tserv id=tserv style='border:1px solid #888'><option value='0' selected>Select a provider</option><option value='1'>-----------------</option><option value='txt.att.net'>AT&T</option><option value='mobile.celloneusa.com'>CellularOne</option><option value='cingularme.com'>Cingular</option><option value='messaging.nextel.com'>Nextel</option><option value='qwestmp.com'>Qwest</option><option value='messaging.sprintpcs.com'>Sprint PCS</option><option value='tmomail.net'>T-Mobile USA</option><option value='email.uscc.net'>US Cellular</option><option value='vtext.com'>Verizon Wireless</option></select><br><br><input type=button name=tbtn value='Send' onclick='textit()' class=btn><span id='tsent' style='display:none;position:absolute;top:0;left:0;width:230;height:100;background-color:#fff;font-size:20px;font-weight:bold'><br>Message Sent</span></div></form>"},
	{showPoint:false});
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                