//var mf = false;

//WBt.fs.push('var fr = dcg("WBmapFrame"+shw);if(fr){mf=fr.contentWindow}else{mf=false;}');



var wbMaps = new Object();

	wbMaps.GC = false; //geocoder;

	

	wbMaps.init=function(fr){

		try{

			if( WB.status < 2 ){

				setTimeout(function(){wbMaps.init(fr)},500);

				return;

			}

			if( !WB.f || !wbMaps.CO(WB.f,fr.frameElement) ){

				setTimeout(function(){wbMaps.init(fr)},2000);

				return;

			}

			fm = WB.f;

			

			if( !fr.GBrowserIsCompatible() ){

				//setTimeout(function(){wbMaps.init(fr)},200);

				//wbMaps.mess('1');

				//alert('Your browser seems to be incompatible with google maps.');

				return;

			}

			

			

			fr.mapDiv = fr.dcg('mapDiv');

			if( !fr.mapDiv || !wbMaps ){

				WB.TO(function(){wbMaps.init(fr)},200);

				return;

			}

			fr.mapDiv.style.height = '250px';

			fr.mapDiv.style.width = '350px';

			

			fr.myGmap = new fr.GMap2(fr.mapDiv);

			fr.myGmap.addControl(new fr.GSmallMapControl());

			fr.myGmap.addControl(new fr.GMapTypeControl() );

			

			

			

			var lat = parseFloat(fm.center_lat.value);

			var lng = parseFloat(fm.center_lng.value);

			var c = new fr.GLatLng(lat,lng);

			if( (lat == 0) && (lng == 0) ){

				fr.myGmap.setCenter(c,0);

			}else{

				wbMaps.setCenter(c,fr);

			}

			

			if( (typeof(fm.cmd) != 'undefined') && (fm.cmd.value == 'savelocation') ){

				wbMaps.getLocation(fr,fm);

			}

		}

		catch(m){

			err(m,'wbMaps.init');

		}		

	}

	

	wbMaps.CO=function(a,b){

		if( !a || !b)return false;

		

		//firefox doesn't support the contains method

		if( typeof(a.contains) != 'undefined' ){

			return a.contains(b);

		}

		do{

			if(b == a){

				return true;

			}

			b = b.parentNode;

		}while(b);

		

		return false;

	}	

	

	wbMaps.setCenter=function(pt,fr){

		try{

			fr.myGmap.setCenter(pt, 15);

			fr.myGmap.clearOverlays();

			var m = new fr.GMarker(pt);

			fr.myGmap.addOverlay(m);

		}

		catch(m){

			err(m,'wbMaps.setCenter');

		}

	}

	

	wbMaps.getLocation=function(fr,fm){

		try{

			if( !wbMaps.GC ){

				wbMaps.GC = new fr.GClientGeocoder();

			}

			wbMaps.GC.getLatLng(fm.search.value,function(pt){wbMaps.saveLocation(pt,fr,fm);});

		}

		catch(m){

			err(m,'wbMaps.getLocation');

		}

	}

	

	wbMaps.saveLocation=function(pt,fr,fm){

		try{

			var arg;

			if( pt ){

				wbMaps.setCenter(pt,fr);

				arg = 'cmd=savelocation&location='+pt.toUrlValue();

			}else{

				alert(fm.search.value+' was not found');

				arg = 'cmd=savelocation&location=false';

			}

			WBx.goTo(fm.action,arg);

		}

		catch(m){

			err(m,'wbMaps.saveLocation');

		}		

	}

