var neigh;
var neighborhood_flag=0;
function find_neighborhood(requested){
	
	
	if (requested=='contact'){
		window.location = "index.aspx?neighborhood=true";
		return
	}
	document.getElementById('column2_neighborhood_hidden').style.display='none';
	document.getElementById('column1_hidden').style.display='none';
	document.getElementById('column2_hidden').style.display='none';
	document.getElementById('favoritestitle').style.display="none";
	document.getElementById('fav_button').style.display="none";
	document.getElementById('columnscontrols').style.display="block";
	if (requested=='1'){
		
		//CHECKBOXES REMOVED IN JAN 09
		//un-check everything in the query options
		/*
		var homecharacteristics_checked=new Array();
		var x=0;
		var full_list='';
		for (i=0; i<homecharacteristics.length; i++){
			var theitem = 'check_'+i;
			if (document.getElementById(theitem).checked==true){
				document.getElementById(theitem).checked=false;
			
			}
		}
		*/
		
		//now show query option menu
		//hide_show('neighborhoodDiv');
	}else{
		document.getElementById('neighborhoodDiv').style.display='none';
		document.getElementById('MLSListings').style.overflow = 'auto';
		document.getElementById("neighborhoodDetailColumn").style.overflow = "auto"
	}
}
function find_your_neighborhood(){
	
	document.getElementById('column2_neighborhood_hidden').style.display='none';
	document.getElementById('column2_neighborhood').style.display='none';
	document.getElementById('column1_hidden').style.display='none';
	document.getElementById('column2_hidden').style.display='none';
	
	map.clearOverlays(); //clear map
	document.getElementById('column1').style.display="block"; //ensure that the results form is  shown
	document.getElementById('column2').style.display="none"; //ensure that the login form is NOT displayed
	
	document.getElementById('next_paging_button').innerHTML="<a href=\"\"></a></div>"; //not needed
	document.getElementById('viewing').innerHTML=""; //not needed
	document.getElementById('map_paging').innerHTML=""; //not needed
	
	//CHECKBOXES and DROP LIST REMOVED IN JAN 09
	/*
	var homecharacteristics_checked=new Array();
	var x=0;
	var full_list='';
	for (i=0; i<homecharacteristics.length; i++){
		var theitem = 'check_'+i;
		if (document.getElementById(theitem).checked==true){
			homecharacteristics_checked[x] = homecharacteristics[i]; //homecharacteristics_checked array now has all checked items.
			x++;
		}
	}
	//find items in array
	for (i=0; i<homecharacteristics_checked.length; i++){
		
		//alert(homecharacteristics_checked[i]);
		if (full_list==''){
			full_list=homecharacteristics_checked[i]
		}else{
			full_list+='|'+homecharacteristics_checked[i]
		}
	}
	
	//check neighborhood
	neigh = document.getElementById('select_neighborhood').value;
	
	if (neigh!='' && neigh!=undefined && document.getElementById('select_neighborhood').selectedIndex!=0){
		document.getElementById('selectNeighborhoodPark').selectedIndex = document.getElementById('select_neighborhood').selectedIndex; //set list on the main query form to the neighborhood selected
		document.getElementById('HomeType').selectedIndex = 2; //set list on the main query form so user has to select type of home (currently single family will be shown)
	
		//alert("hit");
		var url = "../../find_your_neighborhood_interface.aspx?neigh=true&items="+neigh
		make_query(url);
		
		load_neighborhood_preview(neigh);
		
		
	}else{
		var url = "../../find_your_neighborhood_interface.aspx?neigh=false&items="+full_list
		make_query(url);
	}
	document.getElementById('select_neighborhood').selectedIndex=0;
	*/
	
	var url = "../../find_your_neighborhood_interface.aspx?neigh=false&items=ALL" //added functionality to accept ALL as parameter JAN 09
	make_query(url);
}

var xml;
var data;

function make_query(url){
	//alert(url);
	document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	query_and_parse_neighborhood();

	//close the dom REMOVED JAN 09
	//document.getElementById('neighborhoodDiv').style.display="none";
}

var neighborhood_information;
var thestopnumber;
var neighborhood_tmpLAT_array = [];
var neighborhood_tmpLNG_array = [];
var neighborhood_tmpNFO_array = [];
var neighborhood_tmpID_array = [];
function query_and_parse_neighborhood(){

	//let them know to wait
	document.getElementById('MLSListings').innerHTML="<div class=\"mlsitem\"><h4>Please Wait...</h4></div>";
	//clear again and load data
	document.getElementById('MLSListings').innerHTML="";
	
	//load new data
	
	thestopnumber=data["interfacedata"]["results_returnedInXML"];
	//alert(thestopnumber)
	neighborhood_information = data["interfacedata"]["neighborhood"];

	var fulldata;
	var id_list='';
	
	neighborhood_tmpLAT_array=new Array();
	neighborhood_tmpLNG_array=new Array();
	if (data["interfacedata"]["FullCount"]==1){
		thestopnumber=0
	}
	
	if (thestopnumber!=1){
		map.clearOverlays() //clear existing points
		
		if (thestopnumber==0){
			fulldata ='';
			if (id_list==''){
				id_list = id_list + neighborhood_information["fulldata"]["id"];
			}else{
				id_list = id_list + '|' + neighborhood_information["fulldata"]["id"];
			}
			fulldata += "<div class=\"mlsitem\"><h4>"+neighborhood_information["fulldata"]["name"]+"</h4>"
			
			
			fulldata += "<p><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["id"]+"','1');\">"+get_property_image(neighborhood_information["fulldata"]["thumb_image"])+"</a>"+neighborhood_information["fulldata"]["short_description"]+"</p><ul><li><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["id"]+"','1');\">Detail</a><li><a href=\"javascript:pull_neighborhood_point('"+neighborhood_information["fulldata"]["id"]+"');\">Map it</a></li>"
			
			
			
			if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save
				fulldata += "</ul><div style=\"clear:both;\"></div></div>";
			}else{ //normal website or touch app that can save
				fulldata += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information["fulldata"]["ID"]+"','"+neighborhood_information["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
			}
			
				
			document.getElementById('MLSListings').innerHTML=document.getElementById('MLSListings').innerHTML + fulldata;
			
			var address=" ";
			var additional_info="";
			
			additional_info = "<div id=\"mapDom\" style=\"height:300px;\"><h4>"+neighborhood_information["fulldata"]["name"]+"</h4><p><strong></strong></p><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/uploads/"+neighborhood_information["fulldata"]["thumb_image"]+"\" /></a><ul><li><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["id"]+"');\">Detail</a></li><li><a href=\"javascript:pull_neighborhood_point('"+neighborhood_information["fulldata"]["id"]+"');\">Map it</a></li>" 
			
			
			if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
				if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save/remove
					fulldata += "</ul></div>";
				}else{ //normal website or touch app that can save/remove
					additional_info += "<li>- <a href=\"javascript:remove_neighborhood_favorite('"+neighborhood_information["fulldata"]["ID"]+"','"+neighborhood_information["fulldata"]["id"]+"');\">Remove Favorite</a></li></ul></div>";
				}
			}else{
				if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save
					fulldata += "</ul></div>";
				}else{ //normal website or touch app that can save
				additional_info += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information["fulldata"]["ID"]+"','"+neighborhood_information["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul></div>";
				}
			}
		
			//alert("hit")
			
			plot_item_immediately_featured(neighborhood_information["fulldata"]["lat"],neighborhood_information["fulldata"]["lng"],additional_info,neighborhood_information["fulldata"]["id"])
			neighborhood_tmpLAT_array[i] = neighborhood_information["fulldata"]["lat"].toString();
			neighborhood_tmpLNG_array[i] = neighborhood_information["fulldata"]["lng"].toString();
			neighborhood_tmpNFO_array[i] = additional_info.toString();
			neighborhood_tmpID_array = neighborhood_information["fulldata"]["id"];
			map.setCenter(new GLatLng(neighborhood_information["fulldata"]["lat"],neighborhood_information["fulldata"]["lng"]), 13);
		}else{
			for (var i = 0; i < thestopnumber; i++) {
				
				fulldata ='';
				if (id_list==''){
					id_list = id_list + neighborhood_information[i]["fulldata"]["id"];
				}else{
					id_list = id_list + '|' + neighborhood_information[i]["fulldata"]["id"];
				}
				fulldata += "<div class=\"mlsitem\"><h4>"+neighborhood_information[i]["fulldata"]["name"]+"</h4>"
				
				fulldata += "<p><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information[i]["fulldata"]["id"]+"','1');\">"+get_property_image(neighborhood_information[i]["fulldata"]["thumb_image"])+"</a>"+neighborhood_information[i]["fulldata"]["short_description"]+"</p><ul><li><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information[i]["fulldata"]["id"]+"','1');\">Detail</a><li><a href=\"javascript:pull_neighborhood_point('"+neighborhood_information[i]["fulldata"]["id"]+"');\">Map it</a></li>"
				
				if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save
					fulldata += "</ul><div style=\"clear:both;\"></div></div>";
				}else{ //normal website or touch app that can save
					fulldata += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information[i]["fulldata"]["ID"]+"','"+neighborhood_information[i]["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
				}	
				
				document.getElementById('MLSListings').innerHTML=document.getElementById('MLSListings').innerHTML + fulldata;
				
				var address=" ";
				
				
				var additional_info = ""; 
				
				
				additional_info = ""; "<div id=\"mapDom\" style=\"height:300px;\"><h4>"+neighborhood_information[i]["fulldata"]["name"]+"</h4><p><strong></strong></p><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information[i]["fulldata"]["id"]+"','1');\"><img src=\"data/uploads/"+neighborhood_information[i]["fulldata"]["thumb_image"]+"\" /></a><ul><li><a href=\"javascript:javascript:load_neighborhood_preview('"+neighborhood_information[i]["fulldata"]["id"]+"','1');\">Detail</a></li><li><a href=\"javascript:pull_neighborhood_point('"+neighborhood_information[i]["fulldata"]["id"]+"');\">Map it</a></li>" 
				
				if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
					
					
					if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save
						fulldata += "</ul></div>";
					}else{ //normal website or touch app that can save
						additional_info += "<li>- <a href=\"javascript:remove_neighborhood_favorite('"+neighborhood_information[i]["fulldata"]["ID"]+"','"+neighborhood_information[i]["fulldata"]["id"]+"');\">Remove Favorite</a></li></ul></div>";
					}
					
				}else{
					
					
					if (touchapplication=="true" && keyboard=="false"){ //nothing cannot save
						fulldata += "</ul></div>";
					}else{ //normal website or touch app that can save
						additional_info += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information[i]["fulldata"]["ID"]+"','"+neighborhood_information[i]["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul></div>";
					}	
				}
			
				
				
				plot_item_immediately_featured(neighborhood_information[i]["fulldata"]["lat"],neighborhood_information[i]["fulldata"]["lng"],additional_info,neighborhood_information[i]["fulldata"]["id"])
				neighborhood_tmpLAT_array[i] = neighborhood_information[i]["fulldata"]["lat"].toString();
				neighborhood_tmpLNG_array[i] = neighborhood_information[i]["fulldata"]["lng"].toString();
				neighborhood_tmpNFO_array[i] = additional_info.toString();
				neighborhood_tmpID_array = neighborhood_information[i]["fulldata"]["id"];
			}
			
			map.setCenter(new GLatLng(neighborhood_information[0]["fulldata"]["lat"],neighborhood_information[0]["fulldata"]["lng"]), 13);
			
		
		}
		
		
		document.getElementById('thesort').style.display="none";
		document.getElementById('neighborhoodtitles').style.display="block";
		
	}else{
	
	
		//IT WAS DECIDED NOT TO SHOW SINGLE NEIGHBORHOOD IN COLUMN--------------------------------------------------------------------------------------------------------------------------------
		//fulldata ='';
		//fulldata += "<div class=\"mlsitem\"><h4>"+neighborhood_information["fulldata"]["name"]+"</h4>"
		//fulldata += "<p><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["name"]+"');\">"+get_property_image(neighborhood_information["fulldata"]["thumb_image"])+"</a>"+neighborhood_information["fulldata"]["short_description"]+"</p><ul><li><a href=\"javascript:load_neighborhood_preview('"+neighborhood_information["fulldata"]["name"]+"');\">Preview</a><li><a href=\"javascript:pull_neighborhood_point('"+neighborhood_information["fulldata"]["id"]+"');\">Map it</a></li><li>+ <a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information["fulldata"]["name"]+"','"+neighborhood_information["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
		//document.getElementById('MLSListings').innerHTML=document.getElementById('MLSListings').innerHTML + fulldata;
		id_list = neighborhood_information["fulldata"]["id"];
		load_single_polygrid(id_list,neighborhood_information["fulldata"]["zoom"]);
		
		//query and load points
		var url='';
		var sel = document.thesort.sort.selectedIndex=0;
		if (hoodname!='' && hoodname!=undefined){
			url = "../../find_a_home_interface.aspx?table=listings&q=|"+hoodname+"|Single Family Home|any|any|0|3000000|0|15000|"
		}else{
			url = "../../find_a_home_interface.aspx?table=listings&q=|"+neigh+"|Single Family Home|any|any|0|3000000|0|15000|"
		}
		//alert(url)
		lastQuery = url;
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
	    xml = new JKL.ParseXML(url);
	    data = xml.parse();
		current_page=1;
		loaded_favorite_items=0;
		loaded_search_items=0;
		neighborhood_flag=1;
		hoodname='';
		query_and_parse();
	}
	
	
	
	
	
	
	
	
}
var hoodname='';
function map_neighborhood_items(name,id){	
	//THE COMMENTED OUT INFOTMATION SEEMED TO BE WORKING BEFORE WE MADE ONLY 1 NEIGHBORHOOD AVAILABLE
	//var url = "../../find_your_neighborhood_interface.aspx?neigh=true&items="+name;
	var url = "../../find_a_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+name+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages;
	xml = new JKL.ParseXML(url);
	data = xml.parse();
	hoodname = name;
	//make_query(url);
	document.getElementById('selectNeighborhoodPark').selectedIndex = id; //set list on the main query form to the neighborhood selected
	document.getElementById('HomeType').selectedIndex = 2; //set list on the main query form so user has to select type of home (currently single family will be shown)
	query_and_parse();
	
	
	
	//BELOW WAS A FIX TO THE ISSUE OF ONLY 1 NEIGHBORHOOD AVAILABLE. mAYBE THIS IS JUST HOW IT NEEDS TO STAY THOUGH JULY 09 08
	//var url = "../../find_a_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+name+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items;
	//xml = new JKL.ParseXML(url);
    //data = xml.parse();
	//hoodname = name;
	//query_and_parse();
	
	//check neighborhood
	
	
	
}
function get_property_image(thumb){

	var theimage = "<img id=\"tt_"+tt+"\" name=\"tt_"+tt+"\" src=\"data/uploads/"+thumb+"\" onError=\"javascript:document.getElementById('tt_"+tt+"').src='data/htmlimages/noimageavailable.jpg';\">";
	tt++;
	//alert(theimage);
	return theimage;

}
function backtoneighborhood(){
	document.getElementById('column2_neighborhood').style.display="none";
	document.getElementById('column1').style.display="block";
}
function load_neighborhood_preview(id,showBackButton){
	
	var buttondata='';
	
	if (showBackButton=='1'){ //if there are multiple listings then show a back button and hide multiple listings when the detail form is open.
		buttondata = "<a href=\"javascript:backtoneighborhood();\" style=\"color:#E8941A\">back to neighborhoods</a>"
		document.getElementById('column1').style.display="none";
	}
	
	document.getElementById('column2_neighborhood').style.display="block"; //show the neighborhood detail
	
	var url = "../../find_your_neighborhood_interface.aspx?neigh=true&items="+id
	xml = new JKL.ParseXML(url);
    data = xml.parse();
	neighborhood_information = data["interfacedata"]["neighborhood"];
	
	var thedata;
	
	if (neighborhood_information["fulldata"]["overview_video"]!=undefined && neighborhood_information["fulldata"]["overview_video"]!=null && neighborhood_information["fulldata"]["overview_video"]!=""){
		thedata = "<div class=\"columnscontrols\"><h1>"+neighborhood_information["fulldata"]["name"]+"</h1><h2>"+buttondata+"</h2><div class=\"hidecolumn\"><a href=\"javascript:hide_show('column2_neighborhood');\"><img src=\"data/htmlimages/btn_hide.gif\" alt=\"Hide This Column\" title=\"Hide This Column\" /></a></div></div><div class=\"columncontentwrapper\"><div id=\"videoembed\" style=\"width:245;height:148;\">"+neighborhood_information["fulldata"]["overview_video"]+"</div><p>"+neighborhood_information["fulldata"]["overview_copy"].split('[lbr]').join('<br />') +"</p></div><ul id=\"columnsfootercontrols\"><li><a href=\"javascript:map_neighborhood_items('"+neighborhood_information["fulldata"]["name"]+"','"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/htmlimages/btn_MAPNeighborhood.gif\" alt=\"Map neighborhood properties\" /></a></li>"
	}else{ //show no video player
		thedata = "<div class=\"columnscontrols\"><h1>"+neighborhood_information["fulldata"]["name"]+"</h1><h2>"+buttondata+"</h2><div class=\"hidecolumn\"><a href=\"javascript:hide_show('column2_neighborhood');\"><img src=\"data/htmlimages/btn_hide.gif\" alt=\"Hide This Column\" title=\"Hide This Column\" /></a></div></div><div class=\"columncontentwrapper\"><p>"+neighborhood_information["fulldata"]["overview_copy"].split('[lbr]').join('<br />') +"</p></div><ul id=\"columnsfootercontrols\"><li><a href=\"javascript:map_neighborhood_items('"+neighborhood_information["fulldata"]["name"]+"','"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/htmlimages/btn_MAPNeighborhood.gif\" alt=\"Map neighborhood properties\" /></a></li>"
	}
	
	
	if (touchapplication=="true" && keyboard=="false"){ //DONT allow save favorite
	}else{ //allow save favorite
		thedata += "<li><a href=\"javascript:save_neighborhood_favorite('"+neighborhood_information["fulldata"]["name"]+"','"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/htmlimages/btn_SaveNeighborhood.gif\" alt=\"Save This Neighborhood to My Favorites\" /></a></li>"
	}
	
	if (touchapplication=="true"){
		thedata += "<li><a href=\"javascript:touchapp_load_neighborhood_detail('"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/htmlimages/btn_LaunchPhotoGallery.gif\" alt=\"Lunch Photo Gallery\" /></a></li></ul>"
	}else{
		thedata += "<li><a href=\"javascript:load_neighborhood_detail('"+neighborhood_information["fulldata"]["id"]+"');\"><img src=\"data/htmlimages/btn_LaunchPhotoGallery.gif\" alt=\"Lunch Photo Gallery\" /></a></li></ul>"
	}
	
		document.getElementById('column2_neighborhood').innerHTML=thedata;
	if (neighborhood_information["fulldata"]["overview_video"]!=undefined && neighborhood_information["fulldata"]["overview_video"]!=null && neighborhood_information["fulldata"]["overview_video"]!=""){
		initneighborhoodvideo(neighborhood_information["fulldata"]["overview_video"]);
	}
}
function load_neighborhood_detail(id){
	window.open("neighborhood.aspx?id="+id+"&c="+logged_in_id)
}

function errorHandler2(err,erros){
	var wrapper = document.getElementById("flv_wrapper")
	var _html=""
	switch (err){
		case "invalidFlash":
			_html += '<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW" target="_blank"><img src="data/htmlimages/NoFlash.gif" alt="" /></a>'
			wrapper.innerHTML = _html
		break;
	}
}
function initneighborhoodvideo(flvpath){
	//if(previewmode == "flash"){		
		
		//alert(unescape(flvpath))
		FlashControl.createSWFObject(
			"videoPlayer.swf" + "?flv=data/uploads/" + unescape(flvpath),
			{
				width:"245",
				height:"148",
				wmode:"transparent",
				bgcolor:"#000000",
				quality:"high",
				align:"middle",
				salign:"tl",
				allowScriptAccess:"sameDomain",
				id:"theswf"				
			},
			"videoembed",
			{
			
				detectFlash:true,
				flashVersion:8, 
				detectResolution:false,
				onError:errorHandler2
			}
		)
		
	//}else{
		//window.close
	//}
	
}
