// METRO INQUIRY FORM

var fieldValidation={salutation:['rw','Salutation'],'firstName':['rw','First Name'],'lastName':['rw','Last Name'],'email':['re','Email'],'country':['r','Country'],Inquiry_Arrival_Date:['r','Check In Date'],Inquiry_Departure_Date:['r','Check Out Date'],Inquiry_Num_Bedrooms:['r','Number Of Bedrooms'],Inquiry_Num_Guests:['r','Number Of Guests']}
//var xc=new XHConn();

EventManager.Add(window,'beforeunload',SaveForm)
EventManager.Add(window,'load',LoadForm)
function findMapPopUpTop(e) {
    var t=e.offsetTop
    while (e=e.offsetParent) t+=e.offsetTop
    return t;

}

function findMapPopUpLeft(e) {
    var t=e.offsetLeft
    while (e=e.offsetParent) t+=e.offsetLeft
    return t

}
function SaveForm() {
	var f=$('inquiry')
	if (!f) return;	
	var str=formToString(f)
	createCookie('inquiryForm',str)
}

function LoadForm(){
	var f=$('inquiry')
	if (!f) return;
	var str=readCookie('inquiryForm')
	if (!str) return
	var elems=str.split('&');var kv;var e;
	for (var i=0;i<elems.length;i++) {
		e=elems[i]
		if (!e || e.type=='submit' || e.type=='button') continue
		kv=e.split("=");
		setValue(f[kv[0]],unescape(kv[1]))
	}
	$('adult').innerHTML=((f.Inquiry_Num_Guests.selectedIndex==0)?'adult':'adults')
	$('children').innerHTML=((f.Inquiry_Num_Children.selectedIndex==1)?'child':'children')	
}

function setValue(e,v) { 
	var i;var o;
	if (!e) return;
	if (e.type && e.type.match('select')) {
		for (i=0;o=e.options[i];i++) {
			if (o.value==v) { e.selectedIndex=i}
		}
	}
	else e.value=v;
	}
function submitInquiry(f) {
	if (f.Unit_ID.selectedIndex>0)	location='customerCenter/createInvoiced41d.html?'+formToString(f)
	else showMessage(f.Unit_ID,"You must select an apartment");
}

var months={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sept:8,Oct:9,Nov:10,Dec:11}
var daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];
function addInquiry(f) {
	
	var date30daysOut=new Date();
	date30daysOut.setDate(date30daysOut.getDate()+14);
	var ad=f.Inquiry_Arrival_Date.value.split('-');
	var arDate=new Date();	
	arDate.setFullYear(ad[2],(months[ad[1]]),ad[0]);
	var dd=f.Inquiry_Departure_Date.value.split('-');
	var deDate=new Date();	
	deDate.setFullYear(dd[2],(months[dd[1]]),dd[0]);
	
	if (arDate>date30daysOut && !arguments[1] && deDate-arDate>431999999) {
		if (validate(f)) 	toggleInquiryPane(1,f);
		return false;
	}
	if (validate(f)) {	
		if (window.frames['hiddenFrame']){ 
			//xc.connect('/formSubmission/addInquiry.php','POST',formToString(f),displayInquiryMessage);			
			f.target="hiddenFrame";
			f.onsubmit=''
			f.action='formSubmission/addInquiry.html';		
			$('inquirySubmissionButton').style.display='none'
			$('onlineReservationContinueButton').style.display='none'			
			$('submissionWaitTimer').style.display='';
			f.submit();	return false;
	 	}
	return true;
	}
	
return false;
}
var curUnitID;
function checkDateRange(f) {  
	if (!f.Inquiry_Arrival_Date || !f.Inquiry_Departure_Date) return
	var date30daysOut=new Date();
	date30daysOut.setDate(date30daysOut.getDate()+14);	
	var ad=f.Inquiry_Arrival_Date.value.split('-');
	var arDate=new Date();	
	arDate.setFullYear(ad[2],(months[ad[1]]),ad[0]);
	var dd=f.Inquiry_Departure_Date.value.split('-');
	var deDate=new Date();	
	deDate.setFullYear(dd[2],(months[dd[1]]),dd[0]);
	if (arDate<=date30daysOut || deDate-arDate<432000000) {
		$('onlineReservationContinueButton').style.visibility='hidden'
	}
	else {$('onlineReservationContinueButton').style.visibility='visible'
	}
}
function toggleInquiryPane(d) {
	if (d) {
		var types=['Studio','1 Bedroom','2 Bedroom'];
		SaveForm()
		f=arguments[1]
		var personalInfo=f.firstName.value+' '+f.lastName.value+'<BR>'+f.email.value+'<BR>'+f.phone.value+'<BR>'+f.country.value
		var guests=f.Inquiry_Num_Guests.value+" adult"+((f.Inquiry_Num_Guests.value>1)?"s":'');
		if (f.Inquiry_Num_Children.value>0) {
			guests+="<BR>"+(f.Inquiry_Num_Children.value+" child"+((f.Inquiry_Num_Children.value>1)?"ren":''))
		}
		var numBedrooms=f.Inquiry_Num_Bedrooms.value
		var comments=f.Inquiry_Comments.value
		var dd=f.Inquiry_Departure_Date.value
		var ad=f.Inquiry_Arrival_Date.value	
		var partsD=dd.split('-');
		var partsA=ad.split('-')
		/*var date1=new Date();
		var date2=new Date();
		date1.setFullYear(partsA[2],(months[partsA[1]]),partsA[0]);
		date2.setFullYear(partsD[2],(months[partsD[1]]),partsD[0]);
		date2.setDate(date2.getDate()-30);
		if (date2>date1) {
			season='Monthly'
		}*/
		if((partsD[2]>partsA[2] && (months[partsA[1]]-months[partsD[1]]!=11 || (partsD[0]+1)>=partsA[0])) || months[partsD[1]]-months[partsA[1]]>1 || (months[partsD[1]]>months[partsA[1]] &&  (partsD[0]+1)>=partsA[0]) || (partsA[0]==1 && partsD[0]==daysInMonth[months[partsD[1]]])) {
			season='Monthly'
		}
		else {var month=months[partsA[1]];
			var season="Season"+((month<4)?1:((month<9)?2:3))
		}
	
		$('form1').style.display='none';
		$('form2').style.display=''
		$('unitSelectTD').innerHTML="<select name=Unit_ID id=Unit_ID>"+window['unitOptions'+season+"_"+numBedrooms]+"</select>"
		$('guests').innerHTML=guests;
		$('comments').innerHTML=comments
		$('personalInfo').innerHTML=personalInfo
		$('departure_date').innerHTML=dd
		$('arrival_date').innerHTML=ad
		$('apartment_type').innerHTML=types[numBedrooms]
		
	}
	else {
			$('form1').style.display='';
			$('form2').style.display='none'
	}
}
var msgTimer
function displayInquiryMessage(success) {
//	eval(r.responseText);
	if (success) {
		
	var message="<div class=\"res-results\"><h3>Your inquiry has been received.</h3><p>A Metro-Home representative will respond very shortly, but in any case within 24 hours.<BR></p><p>If you are planning a trip within the next 30 days, for the fastest service, we recommend calling now:</p><p><b>phone:</b> 1 646 274 1505<BR><b>toll-free in US:</b> 1 800 987 1235<BR><b>local access:</b><br> Australia 02 8011 4831<BR>Brazil 051 3251 4206<BR>United Kingdom 020 8816 7589</p>";
	$('form').innerHTML=message;
		eraseCookie('inquiryForm')
}
	else {
	var message='<p style=margin:4px;color:red>Sorry, The System Is Experiencing Problems.<BR>Please Call.<BR>1 646 274 1505<BR>toll-free in US: 1 800 987 1235<BR>local access: Australia 02 8011 4831<BR>Brazil 051 3251 4206<BR>United Kingdom 020 8816 7589<BR><BR>'
	$('form').innerHTML=message;
}

//	if (success) msgTimer=setTimeout("eraseMessage()",10000);
	
}

function eraseMessage() { 
	$('inquiry').reset();
	$('message').innerHTML='';
	
}	


// METRO NEIGHBORHOODS


var bannerTimer;var scrollDir;

function setBanner(id){
	var left=$('n'+id).offsetLeft
	left=(left<(bannerWidth-393))?left:bannerWidth-393
	left=(left<1)?0:left-10
	$('banner').style.left=-left+'px';
}
function moveBanner() {
	var left=parseInt(banner.style.left)+scrollDir*4

	if (left<-1 && left>-(bannerWidth+15-407-1)) 	banner.style.left=left+'px'
}

function scrollBanner(n) {
	if(bannerTimer) releaseBanner()
	scrollDir=n;
	bannerTimer=setInterval('moveBanner()',5)
}
function releaseBanner(){

	clearInterval(bannerTimer);bannerTimer=null;
}
function showNeighborhood(id) { 
	if ($('n'+id)) { $('n'+currentNeighborhood).className='';$('n'+id).className='bold';currentNeighborhood=id}
	var q=DB.query("SELECT * from buildingHoods where buildingHood_ID='"+id+"'");
	$('neighborhood_title').innerHTML=q[0]['buildingHood_Text']	
	var q=DB.query("Select * from hood_Photos where Hood_ID="+id);
	stopSlideShow();
	if (q.length) 	{showNeighborhoodSlides(id);startSlideShow();}
	else showNeighborhoodText(id)
	}			
function showNeighborhoodText(id) {
	
	$('photo_navigation').style.display='none'
	q=DB.query("SELECT * from buildingHoods where buildingHood_ID='"+id+"'");
	$('neighborhood_desc').innerHTML="<p>"+q[0]['buildingHood_Description'].replace(/[\r\n]+/g,'</p><p>')+"</p>"
	var q=DB.query("Select * from hood_Photos where Hood_ID="+id);
	$('neighborhood_link').innerHTML=(q[0])?'<a onclick=showNeighborhoodSlides('+id+')>See Neighborhood Photos</a>':'';

	
}

function showNeighborhoodSlides(id) { 
		var leadPainting=1;

	slides=new Array();
	curSlide=0; 
	preSlide=0;
	initSlide=0;
	t='';t2='';var k;
	slidesHTML='';
	
	var q=DB.query("Select * from hood_Photos where Hood_ID='"+id+"'");
	
	for (var i=0;q[i];i++) {
		k=slides.length
		slides[k]=new Slide(k,'',q[i]['Hood_Caption'],q[i]['Hood_File']);
		slidesHTML+="<table id=slide"+k+" style=visibility:hidden;position:absolute;top:0;left:0; cellspacing='0' cellpadding='0' width=447 height=300><tr><td width=447 height=300 valign=center  align=center ><img src='/photos/neighborhoods/"+q[i]['Hood_File']+"'></td></tr></table>"
				}	
	numSlides=slides.length
	$('neighborhood_desc').innerHTML=slidesHTML
	$('neighborhood_link').innerHTML='<a onclick=showNeighborhoodText('+id+')>See Neighborhood Description</a>'
	if (q.length>1)$('photo_navigation').style.display=''
	showSlide();
	
	}
	
//METRO HOME
var curMHPane=1;
function showMH(n) {
	if (n==curMHPane) return
	document.getElementById('mh_bar'+curMHPane).className=''	
	document.getElementById('mh_bar'+n).className='active'
	document.getElementById('MHpane'+curMHPane).style.display='none'	
	document.getElementById('MHpane'+n).style.display=''	
	curMHPane=n
}
	
var DB=new dbFunctions(this);
isIE6 = /msie|MSIE 6/.test(navigator.userAgent); 
isIE= /msie|MSIE/.test(navigator.userAgent);

//MAP
      var buildingmap = null; 
      var layerid=1; 
      var layer=null;
      var pinid = 0;
      var icon = "<div  class=icondiv>"+((isIE)?"<img src=/images/m-h-icon.gif class=icon>":"<img src=/images/m-h-icon.png class=icon>")+"</div>";
      var attraction_icon = "<div class=icondiv><img src=/images/icon.gif class=icon></div>";      
 
var attraction_infobox="<div id='header_popup'>	<h1>%1</h1><h2>%2</h2></div><div id='content_left_right_popup' style=text-align:center;><table align=center height=100% cellspacing=0 cellpadding=0><tr><td><img src='/photos/attractions/%3'  border='0' /></td></tr></table></div><div id='footer_popup'>  <p style=margin-top:10px>%4</p></div>";

var infobox="<div id='header_popup'>	<h1>%9</h1><h2>%1</h2><h3><a onclick=loadNeighborhoodFromMap(%3)>%2</a></h3></div><div id='content_left_right_popup'><div id='right_popup'><img src='/photos/buildings/%7' width='196' height='271' border='0' /></div><div id='left_popup'>    	<h1>Amenities</h1>        <ul>        	 %6         </ul>        %8 </div></div><div id='footer_popup'>  <p style=margin-top:10px>%5</p></div>";

var slideShowHTML="<div id='header_popup'><!--header--><div id=content_popup2BackLink><span style=text-decoration:underline;cursor:hand;cursor:pointer onclick=backToPopUp1() style=cursor:pointer;cursor:hand><< back</span>  </div></div><div id='content_popup2'><!--slides--></div><div id='footer_popup2'><table align=center valign=middle height=100% width=50%><tr>         <td align=center><img onclick=changeSlide(-1) src='../WEB2/js/img/images/previous.gif' alt=''   border='0'  style=cursor:pointer;cursor:hand /></td>            <td align=center><img onclick=stopSlideShow() src='../WEB2/js/img/images/pause.gif' alt=''   border='0' id=pause  style=cursor:pointer;cursor:hand;display:none><img onclick=startSlideShow() src='../WEB2/js/img/images/play.gif' alt=''  border='0' id=play style=display:;cursor:pointer;cursor:hand /></td>      <td align=center><img onclick=changeSlide(1) src='../WEB2/js/img/images/next.gif' alt=''   border='0'  style=cursor:pointer;cursor:hand /></td>             </tr></table></div>";


var slides; var slidesHTML;
var curSlide,preSlide,initSlide;
var infoboxCache=''

function backToPopUp1() {
	stopSlideShow();
	e=getElementsByClassName(document, 'div','VE_Pushpin_Popup_Body');
	e[0].innerHTML=infoboxCache	
	
}
var slidesHTMLArray=[];
var slidesArray=[];
function showSlideShow(id) {	 
		slidesHTML=slidesHTMLArray[id];
		slides=slidesArray[id];
		curSlide=0; 
		preSlide=0;
		initSlide=0;
		leadPainting=1;
		numSlides=slides.length;
		var header=$('header_popup').innerHTML;
		e=getElementsByClassName(document, 'div','VE_Pushpin_Popup_Body');
		infoboxCache=e[0].innerHTML		
		var ssHTML=slideShowHTML.replace('<!--slides-->',slidesHTML)
		var ssHTML=ssHTML.replace('<!--header-->',header)
		e[0].innerHTML=ssHTML	
		stopSlideShow();showSlide();
		startSlideShow()
		}
function makeSlideShow(id) {	
	slidesArray[id]=new Array();slidesHTMLArray[id]='';
	t='';t2='';var k;	
	var q=DB.query("Select Unit_ID from units where Building_ID="+id);
	for (i=0;q[i];i++) {
		var q2=DB.query("SELECT * from unit_Photos where Unit_ID="+q[i].Unit_ID+" order by unit_Photo_DisplayOrder");
		for (j=0;q2[j];j++) {
			k=slidesArray[id].length
			slidesArray[id][k]=new Slide(k,'',q2[j]['unit_Photo_Title'],q2[j]['unit_Photo_File']);
			slidesHTMLArray[id]+="<table id=slide"+k+" style=visibility:hidden;position:absolute;top:0;left:0; cellspacing='0' cellpadding='0' width=490 height=350><tr><td width=490 height=350 valign=center  align=center ><img src='/photos/apartments/"+q2[j]['unit_Photo_File']+"'></td></tr></table>"
		}
	}
	return (slidesArray[id].length);

	}
	
	function showHTML() {
	var e=getElementsByClassName(document, 'div','customInfoBox-previewArea')
	
}

      function GetMap()

      {
        buildingmap = new VEMap('map');
	//	buildingmap.SetDashboardSize(VEDashboardSize.Tiny);
		buildingmap.HideDashboard();
        buildingmap.LoadMap(new VELatLong(40.777140,-73.935683),10);
		buildingmap.ClearInfoBoxStyles();
		var zoom= document.createElement("div"); 
		zoom.id='zoom';
		zoom.style.top = '10px'
        zoom.style.left = '10px'
		zoom.innerHTML="<img src=/images/zoom.gif width=19 height=74 USEMAP=#zoomMap border=0>"
		buildingmap.AddControl(zoom);
		//$('zoom').onclick=function() {buildingmap.ZoomIn();}
		/*
		var zoomIn= document.createElement("div"); 
		zoomIn.id='zoom';
		zoomIn.style.top = '10px'
        zoomIn.style.left = '10px'
		zoomIn.innerHTML="<img src=../WEB2/js/images/zoom.gif width=30>"
		buildingmap.AddControl(zoomIn);
		var zoomOut= document.createElement("div"); 
		zoomOut.id='zoomOut';
		zoomOut.style.top = '44px'
        zoomOut.style.left = '10px'
		zoomOut.innerHTML="<img src=../WEB2/js/images/zoomOut.gif width=30>";		
		buildingmap.AddControl(zoomOut);
		$('zoomOut').onclick=function() {buildingmap.ZoomOut();	}	
		$('zoomIn').onclick=function() {buildingmap.ZoomIn();}
		
	*/
		buildingmap.AttachEvent("onendzoom",setIconHeight);
	//	buildingmap.AttachEvent("onstartzoom",checkZoom)
		buildingmap.AttachEvent("onmouseover", mouseOverHandler);
		
      } 
var mapleft
function moveInfoBox(){ 
	mapleft=findMapPopUpLeft($('map'))

		var infobox=getElementsByClassName(document, 'div','customInfoBox-with-rightBeak');
		if (infobox[0]) {
			var s=(window.pageYOffset)?window.pageYOffset:((document.documentElement.scrollTop)?document.documentElement.scrollTop:((document.body.scrollTop)?document.body.scrollTop:0));
			infobox[0].style.left=mapleft+'px';
			infobox[0].style.top=s+'px';
			}

		var dots=getElementsByClassName(document, 'div','customInfoBox-progressAnimation')
		dots[0].style.visibility='hidden'

}  
function mouseOverHandler(e){

	setTimeout("moveInfoBox()",10)
return false;
	
}
var locs=[]
function makePoint(lat,lng) {

	var latlng=new VELatLong(lat,lng)
	locs[locs.length]=latlng
	return latlng;
	}
 function AddAttractionPushPin(e,layer) {
		var point=makePoint(e['Attraction_Lat'],e['Attraction_Lng']);

         var shape = new VEShape(VEShapeType.Pushpin,point );

         //Set the icon
        //shape.SetCustomIcon(attraction_icon);
         
         //Set the info box
       
		var img=(e['Attraction_Image'])?e['Attraction_Image']:'popup_attraction.jpg';
		var bd=e['Attraction_Description'].replace(/http:\/\/([a-z0-9\-\._\/\?=]+)/gi,"<a href='http://$1' target=_builtLink>$1</a>");
		bd=bd.replace(/\r\n/g,'<BR>');	
		shape.SetDescription(format(attraction_infobox,e['Attraction_Title'],e['Attraction_Address'],img,bd))
		layer.AddShape(shape);
        pinid++;
}
	
 function AddPushpin(e,layer)
      {
		var point=makePoint(e['Building_Lat'],e['Building_Lng']);

         var shape = new VEShape(VEShapeType.Pushpin,point );

         //Set the icon
        shape.SetCustomIcon(icon);
         
         //Set the info box
      
var img=(e['Building_Exterior_Image'])?e['Building_Exterior_Image']:'popup_building.jpg';
	var bd=e['Building_Description'].replace(/http:\/\/([a-z0-9\-\._\/\?=]+)/gi,"<a href='http://$1' target=_builtLink>$1</a>");
	var title=(e['Building_Title'])?e['Building_Title']+"<BR>":'';
	var amenities=e['Building_Amenities'].replace(/^\s+|\s+$/g,'').split(/[\r\n]+/);
	if (amenities.length>8)  amenities.length=8;
	var amenities='<li>'+amenities.join('</li><li>')+'</li>'; 
	var slideLink=(makeSlideShow(e['Building_ID']))?"<p class='popup_right'><span style=text-decoration:underline;cursor:hand;cursor:pointer onclick=showSlideShow("+e['Building_ID']+")>interior photos >></span>  </p><br /><br />":''; 
 shape.SetDescription(format(infobox,e['Building_Display_Address'],e['buildingHood_Text'],e['Building_Neighborhood'],e['Building_Title'],bd,amenities,img,slideLink,title));
         
         //Add the shape the the map
         layer.AddShape(shape);
         pinid++;
      }
 function showBuildings(bn)  {
	
			if (!window.buildingmap) { return}
		  	buildingmap.ClearInfoBoxStyles();
		//	$('map').style.display=''
			locs=[]
			var e,i;
			var where="where Building_ID>0";
			where+=(bn)?' and Building_Neighborhood=\''+bn+"'":'';

			var q=DB.query("SELECT buildings.*,buildingHoods.buildingHood_Text from buildings join buildingHoods on buildingHoods.buildingHood_ID=buildings.Building_Neighborhood "+where);
			
	         if(layer != null)
			         {
			            buildingmap.DeleteShapeLayer(layer);
			            layer = null;
			         }
	        layer = new VEShapeLayer();
			buildingmap.AddShapeLayer(layer);
			for (i=0;e=q[i];i++) {
				AddPushpin(e,layer);
			}
			/// ATTRACTIONS REMOVED FOR NOW
		/*	var q=DB.query("SELECT * from attractions");
			for (j=0;e=q[j];j++) {
				AddAttractionPushPin(e,layer)
			}*/
			 if (i || j){
				buildingmap.SetMapView(locs)
		
	         	}
	
			}
	function onFeedLoad(feed) { }
	
	var iconHeights=[0,0,0,0,1,2,3,4,5,6,16,20,28,36,44,48,60,64,68,80,84,90,100,110,120]
	
	function setIconHeight(){
		var z=buildingmap.GetZoomLevel();
		if (z>16) {buildingmap.SetZoomLevel(16);return} 	
		theRules[0].style.height=iconHeights[z]+'px';
		theRules[1].style.top=-parseInt(iconHeights[z]*3/4)+'px'
	
	}
	function checkZoom() {
	
	
	}


//METRO HOME
var curMHPane=1;
function showMH(n) {
	if (n==curMHPane) return
	document.getElementById('mh_bar'+curMHPane).className=''	
	document.getElementById('mh_bar'+n).className='active'
	document.getElementById('MHpane'+curMHPane).style.display='none'	
	document.getElementById('MHpane'+n).style.display=''	
	curMHPane=n
}
	
//RESOURCES

var resources=['','',{menu:'Dining',link:'http://feeds.nytimes.com/nyt/rss/DiningandWine',header:'<h1>New York Times Dining</h1>'},{menu:'Theater',link:'http://feeds.nytimes.com/nyt/rss/Theater',header:'<h1 >New York Times Theater</h1>'},{menu:'Music',link:'http://feeds.nytimes.com/nyt/rss/Music',header:'<h1>New York Times Music</h1>'}]

var xcs=[]


function addResource(r,args) { 
	var i=args[0]
	$('pane'+i).innerHTML=resources[i].header+r.responseText
	// resources[i].array=xml2array(r.responseText)
}

var curPane=1;
function show(n) {
	if (n==curPane) return
	document.getElementById('event_'+curPane).className=''	
	document.getElementById('event_'+n).className='active'
	document.getElementById('pane'+curPane).style.display='none'	
	document.getElementById('pane'+n).style.display=''	
	curPane=n
}	
function showHome(n) {
	if (n==curPane) return
	document.getElementById('event_'+curPane).className=''	
	document.getElementById('event_'+n).className='active'
	document.getElementById('pane'+curPane).style.display='none'	
	document.getElementById('pane'+n).style.display=''	
	$('zoom').style.display=(n==1)?'':'none';
	curPane=n
}	
//PAGE LOADS	
function closePopUp() {
	// need to hide the popup
	var e=getElementsByClassName(document,'div','undefined customInfoBox-with-leftBeak')
	if (!e.length) e=getElementsByClassName(document,'div','undefined customInfoBox-with-rightBeak')
	e[0].style.visibility='hidden'
}
function loadNeighborhoodFromMap(id) { 
/*	closePopUp()	
	currentNeighborhood=id
	if (loadPage(1,'neighborhoods.html',setUpNeighborhoods)) 
		{
	showNeighborhood(id);
	setBanner(id);
	}
	*/
	location='neighborhoods09f2.html?nId='+id
}

	function setUpMap(r) {
		GetMap()
		showBuildings()
	
	
	}
	
var bannerWidth;var banner;var currentNeighborhood=0;	
function setUpNeighborhoods() { 
//	pageLoaded[1]=1;
//	$('page1').innerHTML=r.responseText
	 DB=new dbFunctions(this);
	var e;var content='';
	q=DB.query("SELECT * from buildingHoods order by buildingHood_Text");
	for (var i=0;e=q[i];i++) {
		if (!currentNeighborhood) {
			var q2=DB.query("Select * from hood_Photos where Hood_ID="+q[i].buildingHood_ID);
			if (q2.length) 	currentNeighborhood=e['buildingHood_ID'];
		}
		content+="<div id=n"+e['buildingHood_ID']+" onclick=\"showNeighborhood("+e['buildingHood_ID']+");\">"+e['buildingHood_Text']+"</div>"
	}
	if (initNeighborhood) currentNeighborhood=initNeighborhood;
	banner=$('banner')
	banner.innerHTML=content;
	bannerWidth=banner.offsetWidth
	$('n'+currentNeighborhood).className='bold';
	showNeighborhood(currentNeighborhood);
	setBanner(currentNeighborhood);	
	
}
	function setUpMetro(r){
		pageLoaded[2]=1
		$('page2').innerHTML=r.responseText	
	}
	
	function setUpResources(r){
		pageLoaded[3]=1
		$('page3').innerHTML=r.responseText	
		for (var i=2;resources[i];i++) {
		if (resources[i]){
			var len=xcs.length
			if (!xcs[len-1].bComplete) { xcs[len]=new XHConn();}
		}	xcs[len].connect('xmlProxy.html','GET','link='+resources[i].link, addResource,[i])
	}
	}
	

    var currentPage=-1;var pageLoaded=[];
	function loadPage(index,page,func) { 
	/*	if (index==currentPage) return;
		$('menuLink'+(index+1)).className='li'+(index+1)+'_active';
		if (index && $('zoom')) { $('zoom').style.visibility='hidden';}
		else if ($('zoom')){$('zoom').style.visibility='visible';}
		if (currentPage>-1 ) {
			$('menuLink'+(currentPage+1)).className='li'+(currentPage+1);
			$('page'+currentPage).style.display='none'
		}
		$('page'+index).style.display='';
		*/
		currentPage=index
		if (!pageLoaded[index])	{
			var len=xcs.length;		
			if (!len || !xcs[len-1].bComplete) { xcs[len]=new XHConn();}
			xcs[len].connect('/htmlPages/'+page+"?unique="+curTime,'GET','',func)
			return 0;
			}
			else return 1;
	}

	function setUp(){
		setTimeout("checkDateRange($('inquiry'))",100);
		var currentDate = new Date()
		curTime=currentDate.getTime()
		var pages={'map':[0,'map.html',setUpMap],'neighborhoods':[1,'neighborhoods.html',setUpNeighborhoods],'whymetro':[2,'why_metro.html',setUpMetro],'localnews':[3,'events.html',setUpResources]}
		if (!window.initPage || !pages[initPage]) return
		page=pages[initPage];
		var currentDate = new Date()
		curTime=currentDate.getTime()
		if (document.styleSheets[0].cssRules)		theRules = document.styleSheets[0].cssRules
		else if (document.styleSheets[0].rules) theRules = document.styleSheets[0].rules
		loadPage(page[0],page[1],page[2])
		loadImages();
	}
	
	
function loadImages() {
	var imageArray=[];var i;var j=0;var k;var img;
	if (initPage=='map') {
	var q=DB.query("SELECT * from buildings");
	for (i=0;q[i];i++) { 
		if(q[i].Building_Exterior_Image) {
			imageArray[j]=new Image();
			imageArray[j].src='/photos/buildings/'+q[i].Building_Exterior_Image;
			j+=1;
		}
	}
	q=DB.query("SELECT * from attractions");
	for (i=0;q[i];i++) {
		if (q[i].Attraction_Image) {
			imageArray[j]=new Image();
			imageArray[j].src='/photos/attractions/'+q[i].Attraction_Image;
			j+=1;
		}
	}
	q=DB.query("SELECT * from units");
	for (i=0;q[i];i++) {
		for (k=1;k<7;k++) {
			if (img=q[i]['Unit_Int_Image'+k]) { 
				imageArray[j]=new Image();
				imageArray[j].src='/photos/apartments/'+img;
				j+=1;
				}
			}
		}
	}
	if (initPage='neighborhoods') {
		q=DB.query("SELECT * from hood_Photos");
		for (i=0;q[i];i++) {
			if (q[i].Hood_File) {
				imageArray[j]=new Image();
				imageArray[j].src='/photos/neighborhoods/'+q[i].Hood_File;
				j+=1;
				}
			}	
		}
	}	
function freeMemory() {
		
	//delete window['xc'];
xc=''
}	

function number_format( number, decimals, dec_point, thousands_sep ) {
    // Formats a number with grouped thousands 
    //
    // version: 902.1517
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // %        note 1: For 1000.55 result with precision 1 in FF/Opera is 1,000.5, but in IE is 1,000.6
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
 
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    return s;
}
EventManager.Add(window,'load',setUp)
EventManager.Add(window,'beforeunload',freeMemory)		

