//T.Daniel
//tree menu for google map

var Lat = Array();
var Lon = Array();
var Info = Array();
var Olay = Array();
var firstLat = 44.82482;
var	firstLon = -87.385683;
var	firstInfo;
var	Zoom;
var nrRows;

//cities()
//when you select a city checkbox
function cities(NrListings,City)
{
	//if a city checkbox is checked , then all the properties are checked
	if(document.forms[City].city.checked){
		var form;
		for(form = City+1; form <= City + NrListings; form ++){ 
			document.forms[form].property.checked=true;
			if (!(Olay[form]) || (Olay[form] == 0)){
				PutMark(form);
			}
		}
	}
	//unchecked
	else{
		var form;
		for(form = City+1; form <= City + NrListings; form ++){ 
			document.forms[form].property.checked=false;
		//delete mark
			remove(form);
		}
	}
		
}
//end of cities()


//ptoperties()
//when you select a property checkbox
function properties(Row){

	if (document.forms[Row].property.checked){
		//send coordonates to google functions for ploting mark
		//if overlay does not exists and <> 0
		if (!(Olay[Row]) || (Olay[Row] == 0)){
			PutMark(Row);
		}
	}
	else{
		//delete mark
		remove(Row);
		//return true;
	}
}

			
//citylink()
function citylink(NrListings,Row){

	firstLat = 0;
	firstLon = 0;
	firstInfo = Info[Row];
	Zoom = 8;
	
	//center of city ( medium of coordinates )
if ((NrListings) && (NrListings != 0)){
	for (form = Row + 1; form <= Row + NrListings; form ++){
		
		firstLat += Lat[form];
		firstLon += Lon[form];

		if (!(Olay[form]) || (Olay[form] == 0)){
			PutMark(form);
		}
			
	}
		firstLat = firstLat / NrListings;
		firstLon = firstLon / NrListings;
		
		
		centerOn (firstLat, firstLon, Zoom);
}

}

//propertylink()
function propertylink(Row){
	
	Zoom = 6;
	firstInfo = Info[Row];
	firstLat = 44.82482;
	firstLon = -87.385683;
	

	if (!(Olay[Row]) || (Olay[Row] == 0)){
			PutMark(Row);
	}
	
	centerOn (Lat[Row],Lon[Row], Zoom);
	
}

//on click check property
function checkP(Row){
	document.forms[Row].property.checked=true;
}

//check city
function checkC(City){
	document.forms[City].city.checked=true;
}