var tablename;
var interestType;
var neighborhood;
var hometype;
var bed;
var bath;
var priceMin;
var priceMax;
var footageMin;
var footageMax;
var featuredcheck;
var checked_items;
var musthaves;
var garages;
var paged_by_map=0;
var initial_state=0;
var tmp_polylineflg=0;
function set_initial_state(){
	initial_state=0;
	neighborhood_flag=0;
	document.getElementById('HomeType').selectedIndex = 2;
	var initial = initial_state;
	initiate_form_query(initial);
}
function check_garage(){
	if (document.getElementById('musthave5').checked==true){
		document.getElementById('garages').disabled=false;
		document.getElementById('garages').style.display="block";
	}else{
		document.getElementById('garages').disabled=true;
		document.getElementById('garages').style.display="none";
	}
}
var loadonlybaldwin;
function initiate_form_query(initial){
	
	
	
	neighborhood_flag=0;
	
	//hide neighborhood column if it is out
	document.getElementById('column2_neighborhood').style.display="none";
	document.getElementById("column2_neighborhood_hidden").style.display="none";
		
	document.getElementById('favoritestitle').style.display="none";
	document.getElementById('fav_button').style.display="none";
	document.getElementById('columnscontrols').style.display="block";
		
	if (initial==undefined || initial==0){
		initial_state=0;
		loadonlybaldwin=1;
	}else{
		loadonlybaldwin=0;
	}
	
	document.getElementById('column1_hidden').style.display="none";
	document.getElementById('column2_neighborhood_hidden').style.display="none";
	document.getElementById('column2_hidden').style.display="none";
	document.getElementById("column2_neighborhood").style.display="none";
	
	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
		
	interestType = getCheckedValue(document.forms['thesearchform'].elements['searchmls']);
	if (interestType=='buy'){
		tablename='listings';
		hometype = obtainHomeTypes();
		if (hometype==''){
			alert('Please select a type of home')
			return;
		}
	}else if (interestType=='rent'){
		tablename='rentals';
	}else{
		//FEATURED PROPERTIES
	}
	neighborhood = document.getElementById('selectNeighborhoodPark').value;
	
	bed = document.getElementById('BedNumber').value;
	bath = document.getElementById('BathNumber').value;
	priceMin = document.getElementById('minprice').value;
	priceMax = document.getElementById('maxprice').value;
	footageMin = document.getElementById('minft').value;
	footageMax = document.getElementById('maxft').value;
	garages = document.getElementById('garages').value;
	//var musthaves=new Array("Fireplace","Pool","Balcony","Waterfront","Garage","Central Air");
	
	//NOTE: DUE TO A CHANGE ORDER AIR CONDITIONING HAS BEEN REMOVED
	
	//musthaves=new Array("FPL_Y_2801","PoolY_2352","Balcony","Water_2628","GAR_C_2805","AirCN_1732");
	musthaves=new Array("FPL_Y_2801","PoolY_2352","Balcony","Water_3067","GAR_C_2805");
	musthaves_checked=new Array();
	var x=0;
	for (i=0; i<document.getElementById('mustcount').value; i++){
		var theitem = document.getElementById('musthave'+(i+1));
		
		//var field = document.thesearchform.musthave;
		//alert(field[i]);
		if (theitem.checked==true){
		
			//check the interestType becasue if it is Rent, the fields are different
			if (interestType=='rent'){
				switch(musthaves[i]){
					case "FPL_Y_2801": 
						musthaves_checked[x] = "FPL_Y_2893"; 
						x++;
						break;
					case "GAR_C_2805": 
						break; //nothing because we dont have garage listings in rental MLS. Dont increment x.
					/*case "AirCN_1732": 
						musthaves_checked[x] = "AirCN_1317"; 
						x++;
						break;
					*/
					default: 
						musthaves_checked[x] = musthaves[i];
						x++;
						break
				}
			}else{
				musthaves_checked[x] = musthaves[i]; //musthaves_checked array now has all checked items.
				x++;
			}
			
		}
		
	}
	//Alert all items in array
	checked_items='';
	for (i=0; i<musthaves_checked.length; i++){
		//alert(musthaves_checked[i]);
		if (checked_items==''){
			checked_items = musthaves_checked[i];
		}else{
			checked_items += ','+musthaves_checked[i];
		}
	}

	//clear the current box of data
	document.getElementById('MLSListings').innerHTML="<div class=\"mlsitem\"><h4>Please Wait...</h4></div>";
	
	//setTimeout("obtain_find_your_home_info(\'"+interestType,neighborhood,hometype,bed,bath,priceMin,priceMax,footageMin,footageMax,checked_items+"\')",1000);
	//alert(document.forms['thesearchform'].featuredlistings.checked)
	featuredcheck = document.forms['thesearchform'].featuredlistings.checked;
	obtain_find_your_home_info(interestType,neighborhood,hometype,bed,bath,priceMin,priceMax,footageMin,footageMax,checked_items,document.getElementById('garages').value,document.forms['thesearchform'].featuredlistings.checked)
	//alert(interestType+'||'+neighborhood+'||'+hometype+'||'+bed+'||'+bath+'||'+priceMin+'||'+priceMax+'||'+footageMin+'||'+footageMax+'||'+checked_items)
	
	
}
function obtainHomeTypes(){
	
	//The db values are placed in the alt tags
	var x=0;
	var home_checked=new Array();
	var hometypeStr='';
	for (i=0; i<=9; i++){
		var theitem = document.getElementById('hometype'+(i+1));
		if (theitem.checked==true){
			home_checked[x] = theitem.alt;
			if(hometypeStr!=''){
				hometypeStr += ','+theitem.alt;
			}else{
				hometypeStr += theitem.alt;
			}		
		}
	}
	return hometypeStr
}
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/* +-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 +------      The following will create the proper queries
 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/

var pagesAvailable=0;
var current_page=1;
var xml;
var data;
var listingCount=0;
var start=0;
var end=20;
var sortcriteria='';
var loaded_favorite_items=0;
var loaded_search_items=0;
var text_searchmls='';
var favURL='';
var featuredURL='';
var lastQuery=''; //this will store the last used query if we need to use a paging button.
function load_favorite_listings(){
	
	
	var sel = document.thesort.sort.selectedIndex=0;
	
	//before i was trying to incorporate all search criteria included with the favorites... but that doesnt really make sense
	favURL = "../../find_a_home_interface.aspx?favorite="+logged_in_id //+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	lastQuery = favURL;
	document.getElementById("testbox").value=favURL;
    xml = new JKL.ParseXML(favURL);
    data = xml.parse();
	current_page=1;
	neighborhood_flag=0;
	loaded_favorite_items=1;
	loaded_search_items=0;
	initial_state=0;
	//need to alter column1 for the favorites
	document.getElementById('favoritestitle').style.display="block";
	document.getElementById('fav_button').style.display="block";
	document.getElementById('columnscontrols').style.display="none";
	document.getElementById('column2_neighborhood').style.display="none";
	query_and_parse();
	

}
function search_btn(theval){
	
	if (theval=='' || theval==undefined){
		text_searchmls = document.getElementById('text_searchmls').value;
	}else{
		text_searchmls = theval;
	}
	
	//alert('theval: '+theval+' SEARCH'+text_searchmls);
	
	var sel = document.thesort.sort.selectedIndex=0;
	
	//search currently only works with buy properties
	tablename='listings';
	var url = "../../find_a_home_interface.aspx?favorite="+logged_in_id+"&table="+tablename+"&search="+text_searchmls+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	lastQuery=url;
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page=1;
	loaded_favorite_items=0;
	loaded_search_items=1;
	initial_state=0;
	query_and_parse();
	
	
	
	
}
function obtain_find_your_home_info(){

	//this is the start of a standard query
	//set the sort list to the first item (best match)
	var sel = document.thesort.sort.selectedIndex=0;
	var url='';
	if (initial_state==1){
		//alert('initial')
		url = "../../find_a_featured_home_interface.aspx?table=listings&initial_state=1&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages;
		featuredURL = url;
	}else{
		if (featuredcheck==true){
			//alert('featuredcheck')
			url = "../../find_a_featured_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages;
		}else{
			//alert('else')
			if (loadonlybaldwin==1){ //added as a temp solution?
				url = "../../find_a_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+'Baldwin Park'+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages;
			}else{
				
				url = "../../find_a_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages;
			}
			
		}
	}	
	lastQuery=url;
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page=1;
	loaded_favorite_items=0;
	loaded_search_items=0;
	query_and_parse();
	
} 
function load_next_page(){

	var newEnd = (end+20);
	var url;
	/*
	if (interestType=="featured" && loaded_favorite_items!=1 && loaded_search_items!=1){
		url = "../../find_a_featured_home_interface.aspx?table=listings&start="+end+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else if (loaded_favorite_items==1){
		url = "../../find_a_home_interface.aspx?favorite="+logged_in_id+"&search="+text_searchmls+"&table="+tablename+"&start="+end+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else if (loaded_search_items==1){
		url = "../../find_a_home_interface.aspx?search="+text_searchmls+"&table="+tablename+"&start="+end+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else{
		var url = "../../find_a_home_interface.aspx?table="+tablename+"&start="+end+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}
	*/
	url = lastQuery+"&start="+end+"&end="+newEnd //just add new starting and ending to the lastquery (base query)
	
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page+=1;
	query_and_parse();
	
}
function load_previous_page(){
	
	var newEnd;
	var newStart;
	
	var tmpend=end;
	//alert('tmpend'+tmpend);
	if (tmpend>40){
		end = (tmpend-40);
	}else{
		end =tmpend
	}
	newEnd = end;
	
	if (newEnd>60){
		start = (tmpend-60);
	}else{
		start = 0;
	}
	//alert(start);
	newStart = start;
	
	
	
	
	//alert('start '+start+' '+newStart)
	/*
	if (interestType=="featured" && loaded_favorite_items!=1 && loaded_search_items!=1){
		url = "../../find_a_featured_home_interface.aspx?table=listings&start="+newStart+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else if (loaded_favorite_items==1){
		url = "../../find_a_home_interface.aspx?favorite="+logged_in_id+"&table="+tablename+"&start="+newStart+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else if (loaded_search_items==1){
		url = "../../find_a_home_interface.aspx?&search="+text_searchmls+"&table="+tablename+"&start="+newStart+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
	}else{
		url = "../../find_a_home_interface.aspx?table="+tablename+"&start="+newStart+"&end="+newEnd+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
		
	}
	*/
	url = lastQuery+"&start="+newStart+"&end="+newEnd //just add new starting and ending to the lastquery (base query)
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page-=1;
	
	query_and_parse();
}
function mainsort(){
		//if you do a sort one would assume it would put you back on the first page of data. the following does this. 
		start=0;
		end=20;
	
		//proceed with query
		sortcriteria = document.getElementById('sort').value;
		var url='';
		/*
		if (loaded_favorite_items==1){
			url = "../../find_a_home_interface.aspx?s="+sortcriteria+"&favorite="+logged_in_id+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
		}else if (loaded_search_items==1){
			var url = "../../find_a_home_interface.aspx?table="+tablename+"&s="+sortcriteria+"&search="+text_searchmls+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
		}else{
			url = "../../find_a_home_interface.aspx?table="+tablename+"&s="+sortcriteria+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items
		}
		*/
		
		url = lastQuery+"&s="+sortcriteria;
		document.getElementById("testbox").value=url;
	    xml = new JKL.ParseXML(url);
	    data = xml.parse();
		current_page=1;
		query_and_parse();
		
}


var address_information;
var lat_array;
var lng_array;
var info_array;
var featured_array;

function view_next_map(current_end){
	//hide the show hide buttons
	document.getElementById('column2_neighborhood_hidden').style.display='none';
	document.getElementById('column1_hidden').style.display='none';
	document.getElementById('column2_hidden').style.display='none';
	
	
	var sel = document.thesort.sort.selectedIndex=0;
	//proceed with query
	sortcriteria = document.getElementById('sort').value;
	
	var tmpend = current_end;
	var tmpstart = parseInt(current_end)+20;
	//alert(tmpstart)
	paged_by_map=1;
	
	var url = "../../find_a_home_interface.aspx?&search="+text_searchmls+"&table="+tablename+"&start="+tmpend+"&end="+tmpstart+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages
	//alert(url);
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page=current_end/20; //20 get page number that would be the current page;
	query_and_parse();
}
function view_prev_map(current_start){
	//hide the show hide buttons
	document.getElementById('column2_neighborhood_hidden').style.display='none';
	document.getElementById('column1_hidden').style.display='none';
	document.getElementById('column2_hidden').style.display='none';
	
	
	var sel = document.thesort.sort.selectedIndex=0;
	//proceed with query
	sortcriteria = document.getElementById('sort').value;
	//alert(current_start);
	var tmpend = (current_start);
	var tmpstart = parseInt(current_start-100);
	//alert(tmpstart)
	paged_by_map=1;
	
	var url = "../../find_a_home_interface.aspx?&search="+text_searchmls+"&table="+tablename+"&start="+tmpstart+"&end="+tmpend+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages
	//alert(url);
	document.getElementById("testbox").value=url;
    xml = new JKL.ParseXML(url);
    data = xml.parse();
	current_page=(tmpstart)/20; //20 get page number that would be the current page;
	query_and_parse();
}
function query_and_parse(){
	//alert('query_and_parse')
	//if (isnew=='NEW_QUERY'){
	//	current_page=0;
	//}
	
	document.getElementById('thesort').style.display="block";
		document.getElementById('neighborhoodtitles').style.display="none";
	listingCount = data["interfacedata"]["FullCount"];
	
	
	pagesAvailable=listingCount/20;
	
	var tmppagesAvailable = pagesAvailable+''; //convert to string
	if (tmppagesAvailable.indexOf(".")>-1){
		pagesAvailable=pagesAvailable+1;
	}else{
		pagesAvailable=Math.round(pagesAvailable);
	}
	pagesAvailable = parseInt(pagesAvailable);
	
	if (pagesAvailable==0){
		pagesAvailable=1; //just because of low rounding like .03 would still be first page but it would round down
	}
	
	if (data["interfacedata"]["result_start_returnedInXML"]==20){
		start=20;  //calculate start number based on page number
		end=40; //calculate end number based on page number
	}else{
		start=(current_page*20);  //calculate start number based on page number
		end=start+20; //calculate end number based on page number
	}
	
	
	
	
	if (end>listingCount){ //if our calculated end number is greater than the listingCount set end to listing count.
		end = listingCount;
	}
	if (current_page==1 || current_page==0){
		start=0;
		if (listingCount<20){
			end=listingCount;
		}else{
			end=20;
		}
	}
	
	
	//prepare the address information array
	address_information = data["interfacedata"]["listing"];

	//clear out the please wait message
	document.getElementById('MLSListings').innerHTML="";
	if (listingCount==0 || listingCount==-1){
		document.getElementById('MLSListings').innerHTML="<div class=\"mlsitem\"><h4>No results matched search criteria.</h4></div>";
		
		document.getElementById('viewing').innerHTML="Viewing 0 of 0";
		document.getElementById('next_paging_button').innerHTML="";
		query_noresults();
			
		return //exit function with current points on the map
		
	//	map.setCenter(new GLatLng(28.55377,-81.36578), 14); 
	}else{
		//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
	var thestopnumber=0;
	if (data["interfacedata"]["result_end_returnedInXML"]<=20){
		thestopnumber=data["interfacedata"]["result_end_returnedInXML"];
	}else if (data["interfacedata"]["results_returnedInXML"]<=20){
		thestopnumber=data["interfacedata"]["results_returnedInXML"]; //zero based
	
	}else{
	
		thestopnumber=20;
	}
	
	lat_array=new Array();
	lng_array=new Array();
	featured_array=new Array();
	
	info_array=new Array();
	GoogleID=new Array();
	
	geo_location_count=0;
	
	//alert(thestopnumber);
	var favoriteID_list=''; //this will store all items for favorites catalog
	//---------------------------------------------------START PARSING DATA TO HTML
	//---------------2 THINGS CAN HAPPEN HERE
	//------1. CAN HAVE 1 LISTING IN XML. IF THIS IS THE CASE REMOVE ARRAYS (FIRST PART OF IF STATEMENT)
	//------2. CAN HAVE MULTIPLE LISTINGS. USE ARRAY METHOD(SECOND PART OF IF STATEMENT)
	if (data["interfacedata"]["FullCount"]==1){
		thestopnumber=0
	}
	//alert('thestopnumber '+thestopnumber)
	if (thestopnumber==0){ //only 1 listing. Zero based. So, take all array information out
		fulldata ='';
		if (address_information["AddressInfo"]["propertytype"]=="neighborhood"){
			fulldata += "<div class=\"mlsitem\"><h4>"+address_information["neighborhood"]["fulldata"]["name"]+"</h4>"
			fulldata += "<p><a href=\"javascript:load_neighborhood_preview('"+address_information["neighborhood"]["fulldata"]["name"]+"');\">"+get_property_image(address_information["neighborhood"]["fulldata"]["thumb_image"])+"</a>"+address_information["neighborhood"]["fulldata"]["short_description"]+"</p><ul><li><a href=\"javascript:load_neighborhood_preview('"+address_information["neighborhood"]["fulldata"]["name"]+"');\">Preview</a><li><a href=\"javascript:pull_neighborhood_point('"+address_information["neighborhood"]["fulldata"]["id"]+"');\">Map it</a></li>"
			
			if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
				fulldata += "<li>- <a href=\"javascript:remove_neighborhood_favorite('"+address_information["neighborhood"]["fulldata"]["name"]+"','"+address_information["neighborhood"]["fulldata"]["id"]+"');\">Remove Favorite</a></li></ul><div style=\"clear:both;\"></div></div>";
			}else{
				fulldata += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+address_information["neighborhood"]["fulldata"]["name"]+"','"+address_information["neighborhood"]["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
			}
			
		}else{
			var address=address_information["AddressInfo"]["Address"]+",&nbsp;"+address_information["AddressInfo"]["City"]+"&nbsp;"+address_information["AddressInfo"]["State"]+"&nbsp;"+address_information["AddressInfo"]["Zip"];
			if (address_information["listingDetail"]["featured"]=="true"){
				fulldata += "<div class=\"featureditem\">"
			}else{
				fulldata += "<div class=\"mlsitem\">"
			}
			fulldata += "<h4>"+address+"</h4>"
				if (touchapplication=="true"){
					
					if (address_information["listingDetail"]["featured"]=="true"){
						fulldata += "<p><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information["listingDetail"]["thumbnail"],address)+"</a><strong>$"+address_information["listingDetail"]["Price"]+"</strong><br />"+address_information["listingDetail"]["Beds"]+"&nbsp;br "+address_information["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information["listingDetail"]["PropertyType"]+"</p>"
					}else{
						fulldata += "<p><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information["AddressInfo"]["GoogleID"],address)+"</a><strong>$"+address_information["listingDetail"]["Price"]+"</strong><br />"+address_information["listingDetail"]["Beds"]+"&nbsp;br "+address_information["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information["listingDetail"]["PropertyType"]+"</p>"
					}
				}else{
					
					if (address_information["listingDetail"]["featured"]=="true"){
						fulldata += "<p><a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information["listingDetail"]["thumbnail"],address)+"</a><strong>$"+address_information["listingDetail"]["Price"]+"</strong><br />"+address_information["listingDetail"]["Beds"]+"&nbsp;br "+address_information["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information["listingDetail"]["PropertyType"]+"</p>"
					}else{
						fulldata += "<p><a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information["AddressInfo"]["GoogleID"],address)+"</a><strong>$"+address_information["listingDetail"]["Price"]+"</strong><br />"+address_information["listingDetail"]["Beds"]+"&nbsp;br "+address_information["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information["listingDetail"]["PropertyType"]+"</p>"
					}
					
				}
				
				
				//add control buttons (detail map, and add/remove favorite
				fulldata += "<ul>";
				
					if (touchapplication=="true"){
							fulldata += "<li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
						}else{
							fulldata += "<li><a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
						}
						
						
					
						//get the geolocation and add the location to the plot link
						if (address_information["listingDetail"]["lng"]=='' || address_information["listingDetail"]["lng"]==undefined){
							var address_withoutspaces=address_information["AddressInfo"]["Address"]+" "+address_information["AddressInfo"]["City"]+", "+address_information["AddressInfo"]["State"]+" "+address_information["AddressInfo"]["Zip"];
							var ret = obtain_geolocation(address_withoutspaces,address_information["AddressInfo"]["GoogleID"],tablename,address_information["AddressInfo"]["propertytype"]);
							var geoitems = ret.split(",")
						}else{
							fulldata += "<li><a href=\"javascript:pullpoint('"+address_information["AddressInfo"]["GoogleID"]+"');\">Map it</a></li>";
						}
					
					
					if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
						
						fulldata += "<li>- <a href=\"javascript:remove_favorite('"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"','"+address+"','"+address_information["listingDetail"]["Price"]+"','"+address_information["listingDetail"]["Beds"]+"','"+address_information["listingDetail"]["Baths"]+"','"+interestType+"');\">Remove Favorite</a></li>";
						
						if (address_information[i]==undefined){
							//favoriteID_list += address_information["AddressInfo"]["GoogleID"] + '_' + address_information["listingDetail"]["featured"] +','
						}else{
							favoriteID_list += address_information[i]["AddressInfo"]["GoogleID"] + '_' + address_information["listingDetail"]["featured"] +','
						}
					}else{ //property not neighborhood
						if (touchapplication=="true" && keyboard=="false"){
							//dont add link
						}else{ //normal website
							fulldata += "<li>+ <a href=\"javascript:save_favorite('"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"','"+address+"','"+address_information["listingDetail"]["Price"]+"','"+address_information["listingDetail"]["Beds"]+"','"+address_information["listingDetail"]["Baths"]+"','"+interestType+"');\">Save To Favorites</a></li>";
						
						}
						
					}
					
					
				fulldata += "</ul>";
				fulldata += "<div style=\"clear:both;\"></div>";
			fulldata += "</div>";
		}
		//document.getElementById('MLSListings').innerHTML=document.getElementById('MLSListings').innerHTML + fulldata;
		//alert(fulldata)
		document.getElementById('MLSListings').innerHTML=fulldata;
	}else{ //-----------------------------SECOND PART OF IF STATEMENT. USING ARRAY METHOD
		//alert(thestopnumber)
		if (loaded_favorite_items==1){ //for some reason the index is one higher than it should be
			thestopnumber-=1
		}
		for (var i = 0; i <= thestopnumber; i++) { //20 at a time per page AND in XML
			fulldata ='';
			if (address_information[i]["AddressInfo"]["propertytype"]=="neighborhood"){
				//alert("hit " + address_information[i]["neighborhood"]["fulldata"]["name"])
				fulldata += "<div class=\"mlsitem\"><h4>"+address_information[i]["neighborhood"]["fulldata"]["name"]+"</h4>"
				fulldata += "<p><a href=\"javascript:load_neighborhood_preview('"+address_information[i]["neighborhood"]["fulldata"]["name"]+"');\">"+get_property_image(address_information[i]["neighborhood"]["fulldata"]["thumb_image"])+"</a>"+address_information[i]["neighborhood"]["fulldata"]["short_description"]+"</p><ul><li><a href=\"javascript:load_neighborhood_preview('"+address_information[i]["neighborhood"]["fulldata"]["name"]+"');\">Preview</a><li><a href=\"javascript:pull_neighborhood_point('"+address_information[i]["neighborhood"]["fulldata"]["id"]+"');\">Map it</a></li>"
				
				
				
				
				if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
					fulldata += "<li>- <a href=\"javascript:remove_neighborhood_favorite('"+address_information[i]["neighborhood"]["fulldata"]["name"]+"','"+address_information[i]["neighborhood"]["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
					
				}else{
					fulldata += "<li>+ <a href=\"javascript:save_neighborhood_favorite('"+address_information[i]["neighborhood"]["fulldata"]["name"]+"','"+address_information[i]["neighborhood"]["fulldata"]["id"]+"');\">Save To Favorites</a></li></ul><div style=\"clear:both;\"></div></div>";
				}
					
					
					
			}else{
				var address=address_information[i]["AddressInfo"]["Address"]+",&nbsp;"+address_information[i]["AddressInfo"]["City"]+"&nbsp;"+address_information[i]["AddressInfo"]["State"]+"&nbsp;"+address_information[i]["AddressInfo"]["Zip"];
				if (address_information[i]["listingDetail"]["featured"]=="true"){
					fulldata += "<div class=\"featureditem\">"
				}else{
					fulldata += "<div class=\"mlsitem\">"
				}
				fulldata += "<h4>"+address+"</h4>"
					if (touchapplication=="true"){
						if (address_information[i]["listingDetail"]["featured"]=="true"){
							
							fulldata += "<p><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information[i]["listingDetail"]["thumbnail"],address)+"</a><strong>$"+address_information[i]["listingDetail"]["Price"]+"</strong><br />"+address_information[i]["listingDetail"]["Beds"]+"&nbsp;br "+address_information[i]["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information[i]["listingDetail"]["PropertyType"]+"</p>"
						}else{
							fulldata += "<p><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information[i]["AddressInfo"]["GoogleID"],address)+"</a><strong>$"+address_information[i]["listingDetail"]["Price"]+"</strong><br />"+address_information[i]["listingDetail"]["Beds"]+"&nbsp;br "+address_information[i]["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information[i]["listingDetail"]["PropertyType"]+"</p>"
						}
						
					}else{
						if (address_information[i]["listingDetail"]["featured"]=="true"){
							//alert("featured 641" +address_information[i]["listingDetail"]["thumbnail"] + ' ' +address)
							fulldata += "<p><a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information[i]["listingDetail"]["thumbnail"],address)+"</a><strong>$"+address_information[i]["listingDetail"]["Price"]+"</strong><br />"+address_information[i]["listingDetail"]["Beds"]+"&nbsp;br "+address_information[i]["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information[i]["listingDetail"]["PropertyType"]+"</p>"
						}else{
							fulldata += "<p><a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information[i]["AddressInfo"]["GoogleID"],address)+"</a><strong>$"+address_information[i]["listingDetail"]["Price"]+"</strong><br />"+address_information[i]["listingDetail"]["Beds"]+"&nbsp;br "+address_information[i]["listingDetail"]["Baths"]+"&nbsp;ba<br />"+address_information[i]["listingDetail"]["PropertyType"]+"</p>"
						}
						
					}					
					
					fulldata += "<ul>";
					
						if (touchapplication=="true"){
							fulldata += "<li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
						}else{
							fulldata += "<li><a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
						}
						
							//get the geolocation and add the location to the plot link
							if (address_information[i]["listingDetail"]["lng"]=='' || address_information[i]["listingDetail"]["lng"]==undefined){
								var address_withoutspaces=address_information[i]["AddressInfo"]["Address"]+" "+address_information[i]["AddressInfo"]["City"]+", "+address_information[i]["AddressInfo"]["State"]+" "+address_information[i]["AddressInfo"]["Zip"];
								var ret = obtain_geolocation(address_withoutspaces,address_information[i]["AddressInfo"]["GoogleID"],tablename,address_information[i]["AddressInfo"]["propertytype"]);
								var geoitems = ret.split(",")
								//u+=1; //increment this number because this is used in combination with the paging system to associate a link with a map bubble point
							}else{	
								fulldata += "<li><a href=\"javascript:pullpoint('"+address_information[i]["AddressInfo"]["GoogleID"]+"');\">Map it</a></li>";
							}
						
						
						if (logged_in_id!='' && loaded_favorite_items==1){//loading favorites 
							fulldata += "<li>+ <a href=\"javascript:remove_favorite('"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"','"+address+"','"+address_information[i]["listingDetail"]["Price"]+"','"+address_information[i]["listingDetail"]["Beds"]+"','"+address_information[i]["listingDetail"]["Baths"]+"','"+interestType+"');\">Remove Favorite</a></li>";
							favoriteID_list += address_information[i]["AddressInfo"]["GoogleID"] + '_' + address_information[i]["listingDetail"]["featured"] +','
						}else{ //normal listing
							
							if (touchapplication=="true" && keyboard=="false"){
								//dont add link
							}else{ //normal website
								fulldata += "<li>+ <a href=\"javascript:save_favorite('"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"','"+address+"','"+address_information[i]["listingDetail"]["Price"]+"','"+address_information[i]["listingDetail"]["Beds"]+"','"+address_information[i]["listingDetail"]["Baths"]+"','"+interestType+"');\">Save To Favorites</a></li>";
							}
							
						}
					
					
					fulldata += "</ul>";
					fulldata += "<div style=\"clear:both;\"></div>";
				fulldata += "</div>";
			}
			document.getElementById('MLSListings').innerHTML=document.getElementById('MLSListings').innerHTML + fulldata;
		}
	}
	
	if (favoriteID_list!=''){
		if (touchapplication=="true" && keyboard=="true"){
			
			document.getElementById('fav_button').innerHTML='<a href=\'javascript:load_touchlink_other("createcatalog.aspx?properties='+favoriteID_list+'\");\'><img src=\'data/images/btn_CreateFavs.gif\' /></a>'
		}else{
			document.getElementById('fav_button').innerHTML='<a href=\'createcatalog.aspx?properties='+favoriteID_list+'\' target=\'_blank\'><img src=\'data/images/btn_CreateFavs.gif\' /></a>'
		}
		
	}
	//display viewing results
	var tmpstart;
	if (start=='0'){
		tmpstart=1;
	}else{
		tmpstart=start;
	}
	
	
	//var viewingstr = "Viewing "+tmpstart+"-"+data["interfacedata"]["result_end_returnedInXML"]+" of "+tmpfullcount
	//listingCount = parseInt(listingCount)-1
	var viewingstr = "Viewing "+tmpstart+"-"+end+" of "+listingCount
	document.getElementById('viewing').innerHTML=viewingstr;
	
	//clear buttons
	document.getElementById('next_paging_button').innerHTML="";
	//previous button
	if (current_page!=1 && current_page!=0){
		document.getElementById('next_paging_button').innerHTML="<a href=\"javascript:load_previous_page();\"><img src=\"data/htmlimages/prev_butn.gif\" /></a></div>";
	}
	//next button
//	alert(pagesAvailable+' '+current_page);
	if (pagesAvailable>current_page){
		document.getElementById('next_paging_button').innerHTML+="&nbsp;<a href=\"javascript:load_next_page();\"><img src=\"data/htmlimages/btn_Next.gif\" /></a></div>";
	}


	
	
	//always ensure that the results form is displayed
	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
		
		
	//since the map has 100 results on it we only want to reload the map when the results scroller starting number is a multiple of 100.
	
	//alert('current_page: '+current_page);
	
	var tmpnum = current_page/5;
	
	//alert('tmpnum: '+tmpnum+' current_page : '+current_page);
	//alert(parseInt(tmpnum*100) + ' end: '+end)
	
	//alert(tmpnum+' '+current_page)
	var tmpcomp_num = (end/100)
	var tmpcomp_num2 = (end-20)
	
//	alert(tmpcomp_num+' '+parseInt(tmpcomp_num))
	//alert(tmpcomp_num2+' '+tmpstart)
	//alert(loaded_favorite_items)
	if (tmpnum == parseInt(tmpnum) || current_page==1 || loaded_favorite_items==1){
		//alert('whole_number OR just load map: '+tmpnum);
		Load_map()
	}else if((tmpcomp_num == parseInt(tmpcomp_num)) && (tmpcomp_num2 == tmpstart)){
		// the idea here is 
		//alert("loaded map on crazy conditions")
		Load_map()
	}else{
		//dont reload the map. this is because the information on the map is still within the specified column data.
	}
	
}
var tt=0;
function get_image(id,address){

	var theimage = "<img id=\"tt_"+tt+"\" name=\"tt_"+tt+"\" src=\"data/rets_results/media2-"+id+"-1.jpeg\" onError=\"javascript:document.getElementById('tt_"+tt+"').src='data/htmlimages/noimageavailable.jpg';\">";
	
	tt++;
	//alert(theimage);
	return theimage;
}
function get_featured_image(id,address){

	var theimage = "<img id=\"tt_"+tt+"\" name=\"tt_"+tt+"\" src=\"http://newbroadstreetrealty.com/data/uploads/"+id+"\" onError=\"javascript:document.getElementById('tt_"+tt+"').src='data/htmlimages/noimageavailable.jpg';\">";
	tt++;
	//alert("ID: "+id +" address: "+address+"  ||  "+theimage);
	return theimage;
}
function Load_map(){
	var tmpnum;
	//alert('current_page: '+current_page)
	if (current_page==1){
		tmpnum = 0;
	}else{
		tmpnum = current_page/5;
	}
	
	
	//currentpage =20
	//alert('current_page '+current_page)
	if (paged_by_map==1){
		var tmpstart = parseInt(current_page*20);
		var tmpend = parseInt(tmpstart+100);
		
	}else{ //paged by paging system not map paging
		//alert('tmpnum'+tmpnum)
		if (tmpnum>=1 || tmpnum==0){ //greater than or equal to 100%
			var tmpend = parseInt(tmpnum*100)+100;
			var tmpstart = parseInt(tmpnum*100);
			
		}else{ //this part would be in use if a person was paging back into the previous set of 100 from the single previous page back button.
			//.8
			//alert("hit")
			var tmpend = 100;
			var tmpstart = 0;
		//	alert("tmpend: "+tmpend)
		//	var tmpstart = parseInt(tmpnum*100);
		}
	}
	
	
	//alert(tmpstart  + '||' + tmpend + '||' + tmpnum)
	//alert(loaded_search_items+'|'+neighborhood_flag+'|'+loaded_favorite_items+'|'+loaded_search_items+'|'+initial_state)
	if (loaded_search_items==1){
		//alert("HIT1")
		var url = "../../find_a_home_interface.aspx?table="+tablename+"&s="+sortcriteria+"&start="+tmpstart+"&end="+tmpend+"&search="+text_searchmls+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
	    xml = new JKL.ParseXML(url);
	    data = xml.parse();
	}else if (loadonlybaldwin==1){ //added as a temp solution?
		url = "../../find_a_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+'Baldwin Park'+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages+"&start="+tmpstart+"&end="+tmpend;
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
		xml = new JKL.ParseXML(url);
		data = xml.parse();
		loadonlybaldwin=0;
	}else if (featuredcheck==true){
		//alert('include featured');
		url = "../../find_a_featured_home_interface.aspx?table="+tablename+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages+"&start="+tmpstart+"&end="+tmpend;
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
		xml = new JKL.ParseXML(url);
		data = xml.parse();
	}else if (neighborhood_flag==1){
		//alert("HIT4")
		var url = "../../find_a_home_interface.aspx?table=listings&q=|"+neigh+"|Single Family Home|any|any|0|3000000|0|15000|&start="+tmpstart+"&end="+tmpend
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
	    xml = new JKL.ParseXML(url);
	    data = xml.parse();
	}else if (loaded_favorite_items==1){
		//alert("HIT3")
		favURL+="&start="+tmpstart+"&end="+tmpend
		var url = favURL
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+favURL;
	    xml = new JKL.ParseXML(favURL);
	    data = xml.parse();
	}else if ((featuredURL!=""  && loaded_favorite_items!=1 && loaded_search_items!=1) && (initial_state==1)){
		//alert("HIT2")
		featuredURL+="&start="+tmpstart+"&end="+tmpend
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+featuredURL;
	    xml = new JKL.ParseXML(featuredURL);
	    data = xml.parse();
	}else{ //nothing special in query
		//alert("HIT5")
		var url = "../../find_a_home_interface.aspx?s="+sortcriteria+"&table="+tablename+"&start="+tmpstart+"&end="+tmpend+"&q="+interestType+'|'+neighborhood+'|'+hometype+'|'+bed+'|'+bath+'|'+priceMin+'|'+priceMax+'|'+footageMin+'|'+footageMax+'|'+checked_items+'|'+garages
		document.getElementById("testbox").value=document.getElementById("testbox").value+'-----'+url;
	    xml = new JKL.ParseXML(url);
	    data = xml.parse();
	}
	
	
	
	//+-----------------------------------------------------------+-----------------------------------------------------------
	//NOW LOAD GOOGLE MAP WITH ALL RESULTS IN THE XML +---------------------------------------------------
	//+-----------------------------------------------------------+-----------------------------------------------------------
	//+-----------------------------------------------------------+-----------------------------------------------------------
	var y=0;
	
	//prepare the address information array
	address_information = data["interfacedata"]["listing"];
	var results_returnedInXML = data["interfacedata"]["results_returnedInXML"];
	
	//---------------------------------------------------START PARSING DATA TO map points
	//---------------2 THINGS CAN HAPPEN HERE
	//------1. CAN HAVE 1 LISTING IN XML. IF THIS IS THE CASE REMOVE ARRAYS (FIRST PART OF IF STATEMENT)
	//------2. CAN HAVE MULTIPLE LISTINGS. USE ARRAY METHOD(SECOND PART OF IF STATEMENT)

	
	
	if (data["interfacedata"]["FullCount"]==1 && results_returnedInXML==1){
		results_returnedInXML=0
	}
	
	
	if (results_returnedInXML==0){//only 1 listing. Zero based. So, take all array information out
		if (address_information["AddressInfo"]["propertytype"]=="neighborhood"){
					//neighborhood_information = data["interfacedata"]["neighborhood"];
					//var id_list = neighborhood_information["fulldata"]["id"];
					//load_single_polygrid(id_list);
		}else{
					//get the geolocation
					if (address_information["listingDetail"]["lng"]=='' || address_information["listingDetail"]["lng"]==undefined){
					
						var address_withoutspaces=address_information["AddressInfo"]["Address"]+" "+address_information["AddressInfo"]["City"]+", "+address_information["AddressInfo"]["State"]+" "+address_information["AddressInfo"]["Zip"];
						var ret = obtain_geolocation(address_withoutspaces,address_information["AddressInfo"]["GoogleID"],tablename,address_information["AddressInfo"]["propertytype"]);
						var geoitems = ret.split(",")
					}else{
						
						var singlat_array=parseFloat(address_information["listingDetail"]["lat"]);
						var singlng_array=parseFloat(address_information["listingDetail"]["lng"]);
						var singfeatured_array=address_information["listingDetail"]["featured"];
						
						
						//load information for bubble
						var address=" <div id=\"mapDom\" style=\"height:300px;\"><h4>"+address_information["AddressInfo"]["Address"]+",&nbsp;"+address_information["AddressInfo"]["City"]+"&nbsp;"+address_information["AddressInfo"]["State"]+"&nbsp;"+address_information["AddressInfo"]["Zip"]+"</h4>";
						var additional_info = "<p><strong>$"+address_information["listingDetail"]["Price"]+"</strong> "+address_information["listingDetail"]["Beds"]+"&nbsp;beds "+address_information["listingDetail"]["Baths"]+"&nbsp;baths</p>"
						
						
						
						if (touchapplication=="true"){
							
							if (address_information["listingDetail"]["featured"]=="true"){
								additional_info += "<a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information["listingDetail"]["thumbnail"],address)+"</a><ul><li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
							}else{
								additional_info += "<a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information["AddressInfo"]["GoogleID"],address)+"</a><ul><li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
							}
							
						}else{
							
							
							if (address_information["listingDetail"]["featured"]=="true"){
								additional_info += "<a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information["listingDetail"]["thumbnail"],address)+"</a><ul><li><a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
							}else{
								additional_info += "<a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information["AddressInfo"]["GoogleID"],address)+"</a><ul><li><a href=\"javascript:load_preview('"+interestType+"','"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"');\">Detail</a></li>";
							}
						}
						
						if (touchapplication=="true" && keyboard=="false"){
								//dont add link
						}else{ //normal website
							additional_info += "<li>+ <a href=\"javascript:save_favorite('"+address_information["AddressInfo"]["GoogleID"]+"','"+address_information["AddressInfo"]["propertytype"]+"','"+address_information["AddressInfo"]["Address"]+"','"+address_information["listingDetail"]["Price"]+"','"+address_information["listingDetail"]["Beds"]+"','"+address_information["listingDetail"]["Baths"]+"','"+interestType+"','"+address_information["AddressInfo"]["Zip"]+"');\">Save To Favorites</a></li></ul></div>";
						}
						
						
						var singinfo_array = address+additional_info
						
						var singGoogleID = address_information["AddressInfo"]["GoogleID"];
						
						
						//------CENTER MAP ON POINT
						recenter(singlat_array,singlng_array,singlat_array,singlat_array,singlng_array,singlng_array);
						
						
						//------PLOT POINT
						if (singfeatured_array=="true"){ //gold point
							plot_item_immediately_featured(singlat_array,singlng_array,singinfo_array,singGoogleID);//add to map
						}else{ //normal point
							plot_item_immediately(singlat_array,singlng_array,singinfo_array,singGoogleID);//add to map
							//alert(singlat_array+' '+singlng_array);
						}
						
					}
		}
	}else{
			for (var i = 0; i < data["interfacedata"]["results_returnedInXML"]; i++) {
				//alert(i+' '+address_information[i]["AddressInfo"]["GoogleID"]);
				
				if (address_information[i]["AddressInfo"]["propertytype"]=="neighborhood"){
					//neighborhood_information = data["interfacedata"]["neighborhood"];
					//var id_list = neighborhood_information["fulldata"][i]["id"];
					//load_single_polygrid(id_list);
				}else{
					//get the geolocation
					if (address_information[i]["listingDetail"]["lng"]=='' || address_information[i]["listingDetail"]["lng"]==undefined){
					
						var address_withoutspaces=address_information[i]["AddressInfo"]["Address"]+" "+address_information[i]["AddressInfo"]["City"]+", "+address_information[i]["AddressInfo"]["State"]+" "+address_information[i]["AddressInfo"]["Zip"];
						var ret = obtain_geolocation(address_withoutspaces,address_information[i]["AddressInfo"]["GoogleID"],tablename,address_information[i]["AddressInfo"]["propertytype"]);
						var geoitems = ret.split(",")
					}else{
						
						lat_array[y]=parseFloat(address_information[i]["listingDetail"]["lat"]);
						lng_array[y]=parseFloat(address_information[i]["listingDetail"]["lng"]);
						featured_array[y]=address_information[i]["listingDetail"]["featured"];
						
						
						//load information for bubble
						var address=" <div id=\"mapDom\" style=\"height:300px;\"><h4>"+address_information[i]["AddressInfo"]["Address"]+",&nbsp;"+address_information[i]["AddressInfo"]["City"]+"&nbsp;"+address_information[i]["AddressInfo"]["State"]+"&nbsp;"+address_information[i]["AddressInfo"]["Zip"]+"</h4>";
						
						
						var additional_info = "<p><strong>$"+address_information[i]["listingDetail"]["Price"]+"</strong> "+address_information[i]["listingDetail"]["Beds"]+"&nbsp;beds "+address_information[i]["listingDetail"]["Baths"]+"&nbsp;baths</p>"
						
						
						if (touchapplication=="true"){
							if (address_information[i]["listingDetail"]["featured"]=="true"){
								additional_info += "<a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information[i]["listingDetail"]["thumbnail"],address)+"</a><ul><li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a>";
							}else{
								additional_info += "<a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information[i]["AddressInfo"]["GoogleID"],address)+"</a><ul><li><a href=\"javascript:touchapp_detail_link('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a>";
							}
						}else{
							if (address_information[i]["listingDetail"]["featured"]=="true"){
								additional_info += "<a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_featured_image(address_information[i]["listingDetail"]["thumbnail"],address)+"</a><ul><li><a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a>";
							}else{
								additional_info += "<a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">"+get_image(address_information[i]["AddressInfo"]["GoogleID"],address)+"</a><ul><li><a href=\"javascript:load_preview('"+interestType+"','"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"');\">Detail</a>";
							}
						}
						
						
						
						
						if (touchapplication=="true" && keyboard=="false"){
								//dont add link
						}else{ //normal website
							additional_info += "</li><li>+ <a href=\"javascript:save_favorite('"+address_information[i]["AddressInfo"]["GoogleID"]+"','"+address_information[i]["AddressInfo"]["propertytype"]+"','"+address_information[i]["AddressInfo"]["Address"]+"','"+address_information[i]["listingDetail"]["Price"]+"','"+address_information[i]["listingDetail"]["Beds"]+"','"+address_information[i]["listingDetail"]["Baths"]+"','"+interestType+"','"+address_information[i]["AddressInfo"]["Zip"]+"');\">Save To Favorites</a></li></ul></div>";
						}
						
						
						info_array[y] = address+additional_info
						
						GoogleID[y] = address_information[i]["AddressInfo"]["GoogleID"];
						y+=1;
						
					}
				}
			}
			
			
			//find the middle point in the positions
			var running_Lat_tot=0;
			var running_Lng_tot=0;
			//
			//find the min and max,
			var minLat=-100;
			var minLong=-100;
			var maxLat=100;
			var maxLong=100;
			var information='';
			
			//
			//alert(lat_array.length + "{"+lat_array[0]+"}");
			for (var i = 0; i <= lat_array.length; i++) {
				//alert(lat_array[i])
				
				var lat;
				var lng;
				if (lat_array[i]==undefined || lng_array[i]==undefined || isNaN(lng_array[i]) == true || isNaN(lat_array[i])==true){
					//some values that the map can plot get caught in this array
					
					//but we need at least one of the good values to compensate for addition
					
					lat = parseFloat(lat_array[0]);
					var lat2 = parseFloat(running_Lat_tot);
					running_Lat_tot = lat + lat2;
					lng = parseFloat(lng_array[0]);
					var lng2 = parseFloat(running_Lng_tot);
					running_Lng_tot = lng + lng2;
					
					
				}else{
					lat = parseFloat(lat_array[i]);
					var lat2 = parseFloat(running_Lat_tot);
					running_Lat_tot = lat + lat2;
					lng = parseFloat(lng_array[i]);
					var lng2 = parseFloat(running_Lng_tot);
					running_Lng_tot = lng + lng2;
					
					//running_Lat_tot = lat_array[i]+running_Lat_tot;
					//running_Lng_tot = lng_array[i]+running_Lng_tot;
				}
				
				
				//determine min and maxes
				if (minLat>lat){
				}else{
					minLat=lat
				}
				if (maxLat<lat){
				}else{
					maxLat=lat
				}
				if (minLong>lng){
				}else{
					minLong=lng
				}
				if (maxLong<lng){
				}else{
					maxLong=lng
				}
				
				
				
			}
			var final_lat = (running_Lat_tot/lat_array.length);
			var final_lng = (running_Lng_tot/lat_array.length);
			
			var centerpoint = "("+running_Lat_tot+','+running_Lng_tot+')'
			//alert('LAT: '+running_Lat_tot+'   LNG: '+running_Lng_tot);
			//alert('FINAL INFORMATION FOR CENTER POINT LAT: '+final_lat+'   LNG: '+final_lng);
			//center map
			
			
				if (neighborhood_flag!=1){ //we have the neighborhood already centered with polylines
					recenter(final_lat,final_lng,minLat,maxLat,minLong,maxLong);
				}
			
	
	
	
	
	
			//plot all the points in array
			
			t = parseInt(data["interfacedata"]["result_start_returnedInXML"]); //first set the eindex number used to call a point
			
			
			//alert('t:'+t);
			for (var i = 0; i < lat_array.length; i++) {
				//get information
				var theGoogleID = GoogleID[i];
				//alert(featured_array[i]);
				if (featured_array[i]=="true"){ //gold point
					plot_item_immediately_featured(lat_array[i],lng_array[i],info_array[i],theGoogleID);//add to map
				}else{ //normal point
					plot_item_immediately(lat_array[i],lng_array[i],info_array[i],theGoogleID);//add to map
				}
				
			}
			
				//map paging
			
			
			var thefullcount = parseInt(data["interfacedata"]["FullCount"])
			var returnedInXML = parseInt(data["interfacedata"]["result_start_returnedInXML"])
			var returnedEndXML = parseInt(data["interfacedata"]["result_end_returnedInXML"])
			
			
			
			var comparenum = (thefullcount-100)
			//ensure the count doesnt start at 0 on viewing copy. this is a rig to the zero based array of results.
			var startat=0;
			if (returnedInXML==0){
					startat=1;
			}else{
					startat=returnedInXML;
			}
			//end ensure	
			//alert(thefullcount+'\\'+returnedEndXML+'\\'+comparenum) //3255|100|3155
			if (thefullcount>(returnedEndXML+1)){ //page up or page down.
				//alert("passed")
				document.getElementById('map_paging').innerHTML="";
				//alert(returnedInXML+'\\'+returnedEndXML);
				if (returnedInXML>=100){ //means a previous page is available
					document.getElementById('map_paging').innerHTML="<a href=\"javascript:view_prev_map('"+returnedInXML+"');\"><- Prev 100</a>&nbsp;&nbsp;";
				
				}
				
				document.getElementById('map_paging').innerHTML+="Viewing "+startat+"-"+returnedEndXML+" of "+thefullcount+" &nbsp;&nbsp;<a href=\"javascript:view_next_map('"+returnedEndXML+"');\">next 100 -></a><br />";
				
				
			}else if(comparenum<100){ //limit hit
				//alert("limit hit")
				document.getElementById('map_paging').innerHTML="";
				
				if (returnedInXML!=0){
					document.getElementById('map_paging').innerHTML="Viewing "+startat+"-"+(returnedEndXML+1)+" of "+thefullcount+" <a href=\"javascript:view_prev_map('"+returnedInXML+"');\">view previous 100 results</a><br />";
				}
			}else{ //no pages available... only 1
				//alert("not passed")
				document.getElementById('map_paging').innerHTML="";
			}
			
			//if there was a neighborhood selected we want to display the polyline associated with the neighborhood
			
			//CHANGE ORDER APRIL 2009 THIS HAS BEEN REMOVED!!
			/*
			if (neighborhood!="" && document.getElementById('selectNeighborhoodPark').selectedIndex!=0){
				var url = "../../find_your_neighborhood_interface.aspx?neigh=true&items="+document.getElementById('selectNeighborhoodPark').value
				document.getElementById("testbox").value=url;
			    xmlneigh = new JKL.ParseXML(url);
			    var neighdata = xmlneigh.parse();
				load_single_polygrid(neighdata["interfacedata"]["neighborhood"]["fulldata"]["id"],neighdata["interfacedata"]["neighborhood"]["fulldata"]["zoom"]);
				load_neighborhood_preview(neighdata["interfacedata"]["neighborhood"]["fulldata"]["id"]);
			}
			*/
			paged_by_map=0;
	} //END HUGE LOAD MAP ELSE STATEMENT
}