/* d3mls.js */
var d3mls_main={setupJQueryUI:function()
{$("head").append('<script type="text/javascript" src="/js/jquery/extensions/ui/ui.core.js"></script>').append('<script type="text/javascript" src="/js/jquery/extensions/ui/ui.draggable.js"></script>').append('<script type="text/javascript" src="/js/jquery/extensions/ui/ui.dialog.js"></script>').append('<script type="text/javascript" src="/js/jquery/extensions/ui/ui.tabs.js"></script>').append('<script type="text/javascript" src="/js/jquery/extensions/ui/ui.resizable.js"></script>').append('<link href="/js/jquery/extensions/ui/themes/base/ui.all.css" rel="stylesheet" type="text/css" />');}};

/* d3mls_search.js */
var d3mls_search={buttonClass:"button",divId:"d3mls_search",init:function(divId,buttonClass)
{if(divId!='')
this.divId=divId;if(buttonClass!='')
this.buttonClass=buttonClass;this.setupSearchForm();},setupSearchForm:function()
{$("#"+this.divId+" a."+this.buttonClass).bind("click",function(e){e.preventDefault();$("#"+d3mls_search.divId+" input[type=text]").each(function(){if($(this).val()==$(this).attr("default"))
$(this).val("");});$("form[name=search_form]").append("<input type='text' class='hidden' name='scrolltops' value='"+d3mls_search.selectScrollTops.join(",")+"' />");$("form[name=search_form]").submit();});this.setupLoadingIcon();this.setupButtonsToActivateLoadingIcon();this.setupLocationsSelectInputs();},setupSearchTabs:function()
{$("#"+this.divId).tabs();},getSuggest:function(input)
{$input=$(input);if(($input.val().length>2&&parseInt($input.val()))||$input.val().length>5){$.post('/app/modules/d3mls/ninja_code/search_simple.php',{'loc':$input.val()},function(data){if(data.length>1)
$input.next().html(data).show();else
$input.next().hide();});}},locationSuggestFill:function(value,suggestResult)
{$(suggestResult).parent().prev().val(value);$("#suggestBox").hide();},$loadingBlanket:null,$loadingIcon:null,activateLoadingIcon:function()
{this.$blanket.show();this.$loadingIcon.show();},setupLoadingIcon:function()
{this.$blanket=$("<div class='loadingBlanket'></div>").css({height:$(document).height()}).appendTo(document.body);this.$loadingIcon=$("<img class='loadingIcon' src='/images/ajax-loader.gif' />").css({"top":($(window).height()/2)-(300/2),"left":($(window).width()/2)-(400/2)}).appendTo(document.body);},setupButtonsToActivateLoadingIcon:function()
{$("#"+this.divId+" ."+this.buttonClass).each(function(){$(this).bind("click",function(){d3mls_search.activateLoadingIcon();});});},selectedLocations:[[],[],[],[],[]],selectScrollTops:[0,0,0,0,0],setupLocationsSelectInputs:function()
{$("#"+this.divId+" > #generalSearchDiv >#locationsSection > #locationsSelectsContainer div.locations input[type=checkbox]").each(function()
{$(this).bind("click",function(event){d3mls_search.selectInputs($(this),parseInt($(this).attr("index")),event);});});},selectInputs:function($input,index,$event)
{this._dim($(".locationsSelects:eq("+(index)+")"),true);this.selectScrollTops[index]=$input.parents(".locationsSelects").scrollTop();var locations=$input.val().split("|");if($input.is(":checked")&&$.inArray(locations[index],this.selectedLocations[index])<0)
this.selectedLocations[index].push(locations[index]);else
this.selectedLocations[index]=this._removeElements([locations[index]],this.selectedLocations[index]);if(index<4)
{$.post("/app/modules/d3mls/xml/getLocations.php",{'locations':this.selectedLocations,'index':index},function(data,status)
{$("#locationsSelectsContainer").replaceWith(data);$(".locationsSelects").each(function(i){var scrollTopValue=d3mls_search.selectScrollTops[i+1];$(this).scrollTop(scrollTopValue);});});}},updateScrolltops:function(scrolltopsAr)
{this.selectScrollTops=scrolltopsAr;$(".locationsSelects").each(function(i){var scrollTopValue=d3mls_search.selectScrollTops[i+1];$(this).scrollTop(scrollTopValue);});},_dim:function($div,dim)
{$div.css({"color":"black","-ms-filter":"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)","filter":"alpha(opacity="+((dim)?40:100)+")","-moz-opacity":((dim)?.40:1),"opacity":((dim)?.40:1)});},_removeElements:function(theseElements,fromThisArray)
{$.unique(theseElements);$.unique(fromThisArray);for(var i=0;i<theseElements.length;i++)
fromThisArray=$.grep(fromThisArray,function(value){return value!=theseElements[i];});return fromThisArray;},locationsAccordion:function(divId,openFirst)
{$('#'+divId+' .locationsSelectSection .locationsHeader').click(function(){var $locationsHeaderIcon=$(this).find("div.locationsHeaderIcon");if($locationsHeaderIcon.hasClass('locationsHeaderIconClicked'))
$locationsHeaderIcon.removeClass("locationsHeaderIconClicked");else
$locationsHeaderIcon.addClass("locationsHeaderIconClicked");$(this).next().toggle('slow');}).next().hide();if($('#'+divId+' > .locationsSelectSection').children().size()<4||openFirst)
{$('#'+divId).find(">:first-child .locationsHeader .locationsHeaderIcon").addClass("locationsHeaderIconClicked:eq(0)").end().find(".locationsContent:eq(0)").show();}
else
{$('#'+divId+' .locationsSelectSection .locationsContent input:checked').each(function(){$(this).parent().parent().parent().prev().find(".locationsHeaderIcon").addClass("locationsHeaderIconClicked").end().next().show();});}},accordion:function(divId)
{$('#'+divId+' .accordionPanel').click(function(){$(this).next().toggle('slow');}).next().hide();}};

/* d3mls_user.js */
var d3mls_user={changeSubmitState:function(state,checkbox,submit)
{if(typeof checkbox=="undefined"||checkbox==null){var $d3mls_userSubmitButton=$('#d3mls_userSubmitButton');if(state=='register')
{if($('#nameRow').hasClass('hidden'))
{$d3mls_userSubmitButton.attr("name","register").val("Register");$('#d3mls_userSubmitLink span').html('Register');$('#nameRow').removeClass('hidden');}
else
{$d3mls_userSubmitButton.attr("name","login").val("Login");$('#nameRow').addClass('hidden');}}
else if(state=='forgot')
{$d3mls_userSubmitButton.attr("name","forgot").val("Get Password");$('#popupSubmitButton').attr("name","forgot").val("Get Password");$('#d3mls_userSubmitLink span').html('Get Password');}
else if(state=='update')
$d3mls_userSubmitButton.attr("name","update").val("Update");else if(state=='logout')
$d3mls_userSubmitButton.attr("name","logout").val("Logout");}
else if(typeof checkbox!="undefined"||checkbox!=null)
{if($(checkbox).is(":checked"))
{$(checkbox.form).find("a.button > span").html("Get password").end().find("#d3mls_userSubmitButton").attr("name","forgot").end().find('#popupSubmitButton').attr("name","forgot").val("Get Password").end();}
else
$(checkbox.form).find("a.button > span").html("Login").end().find("#d3mls_userSubmitButton").attr("name","login");}
if(submit===true)
{document.forms.d3mls_usersForm.submit();return false;}},changePasswordFieldType:function(link){$(link).html(($(link).html()=='hide')?"show":"hide");$passwordField=$('#d3mls_user form input[name=password]').clone();$('#d3mls_user form input[name=password]').replaceWith("<input type='"+(($passwordField.attr("type")=="password")?"text":"password")+"' value='"+$passwordField.attr("value")+"' name='password' autocomplete='off' class='frm-text'>");},removeWishlist:function(system_id,link,addText,removeText)
{if(typeof system_id!='undefined'&&system_id!=null){$.post("/app/modules/d3mls/ninja_code/wishlists.php",{'system_id':system_id},function(data){if(typeof link!="undefined"&&link!=null)
$(link).find('span').html(($(link).find('span').html()==addText)?removeText:addText);else if(data==system_id)
$(".wishlist_"+system_id).remove();});}
return false;}}

/* d3mls_maps.js */
d3mls_main.setupJQueryUI();var d3mls_maps={googleMaps:{map:null,mapNode:null,mapNodeId:"gMap",dialogMap:{map:null,gMarker:null,domNode:null,domNodeId:"gMapDialog"},clickedMarker:{gMarker:null,gOverlay:null,icon:null,balloonHtml:null},gDirectionsObj:null,gDirectionsNodeId:"gDirectionsNodeId",gDirectionsInputAddressId:"gDirectionsInputAddress",gStreetviewClientObj:null,gStreetviewPanoramaObj:null,gStreetviewPanoramaNodeId:"gStreetviewPanoramaNodeId",gLatLngArray:[],gMarkerTemplate:"<div class='d3mls_maps_balloon'><div class='d3mls_maps_balloon_image'><img src='{$image}' width='120px' height='100px' alt='Image' /></div><div class='d3mls_maps_balloon_content'><div class='d3mls_maps_balloon_title'>{$address}</strong><br /> {$city}, {$state}</div><p><strong>Price:</strong> {$price}<br /><strong>Beds:</strong> {$bedrooms} <strong>Baths:</strong> {$bathrooms_full}</p><p>{$description}</p></div><div class='d3mls_maps_balloon_links'><a href='{$system_id}' class='button'><span>More Details</span></a></div><div class='clearfix'></div></div>"},d3mlsMaps:{width:null,height:null,map_type:null,zoom:null,lat:null,lon:null,directions:null,street_view:null,markers:null,detailsPage:null,markerClickAction:null,dialogNodeId:null,tabsNodeId:null,dialogObj:null,tabsObj:null,balloonImgResizer:"/app/modules/d3mls/ninja_code/ninja_resize.php?h=100&w=120",dialogTemplate:"<div class='d3mls_maps_dialog_details'><div class='d3mls_maps_dialog_details_image'><img src='{$image}' width='200px' height='150px' alt='Image' /></div><div class='d3mls_maps_dialog_details_content'><div class='d3mls_maps_dialog_details_title'>{$address}<br /> {$city}, {$state}</div><p><strong>Price:</strong> {$price}<br /><strong>Beds:</strong> {$bedrooms} <strong>Baths:</strong> {$bathrooms_full}</p></div><div class='d3mls_maps_dialog_details_description'>  {$description}</div><div class='d3mls_maps_dialog_details_links'><a href='{$system_id}' class='button'><span>More Details</span></a></div></div>"},init:function(mapData)
{for(var propKey in mapData)
eval("("+"this.d3mlsMaps."+propKey+" = '"+mapData[propKey]+"'"+")");this.d3mlsMaps.markers=eval("("+this.d3mlsMaps.markers+")");this._initjQueryUI();this._initGoogle();this._setUpMap();},_initjQueryUI:function()
{jQuery("#"+d3mls_maps.d3mlsMaps.dialogNodeId).dialog({autoOpen:false,width:parseInt(jQuery("#"+d3mls_maps.d3mlsMaps.dialogNodeId).width()),height:parseInt(jQuery("#"+d3mls_maps.d3mlsMaps.dialogNodeId).height()),open:function()
{jQuery(this).dialog('option','title',jQuery(this).attr("title"));d3mls_maps.googleMaps.dialogMap.map.checkResize();d3mls_maps.googleMaps.gStreetviewPanoramaObj.checkResize();},close:function(){d3mls_maps.googleMaps.dialogMap.map.clearOverlays();jQuery(d3mls_maps.d3mlsMaps.tabsObj).tabs('select',0);},resize:function()
{var dialogWidth=jQuery(".d3mls_maps_dialog").width();var dialogHeight=jQuery(".d3mls_maps_dialog").height();var tabsWidth=dialogWidth-20;var tabsHeight=dialogHeight-40;var tabPanelWidth=tabsWidth-20;var tabPanelHeight=tabsHeight-40;var tabPanelItemWidth=tabPanelWidth-20;var tabPanelItemHeight=tabPanelHeight-40;jQuery(".d3mls_maps_dialog_tabs").css({'width':tabsWidth,'height':tabsHeight});jQuery(".d3mls_maps_dialog_tabpanel").css({'width':tabPanelWidth,'height':tabPanelHeight});jQuery(".d3mls_maps_dialog_tabpanel_item").css({'width':tabPanelItemWidth,'height':tabPanelItemHeight});d3mls_maps.googleMaps.dialogMap.map.checkResize();d3mls_maps.googleMaps.gStreetviewPanoramaObj.checkResize();}});this.d3mlsMaps.tabsObj=jQuery("#"+d3mls_maps.d3mlsMaps.tabsNodeId).tabs();$('#'+d3mls_maps.d3mlsMaps.tabsNodeId).bind('tabsshow',function(event,ui){if(ui.panel.id=="mapTab"){d3mls_maps.googleMaps.dialogMap.map.closeInfoWindow();d3mls_maps.googleMaps.dialogMap.map.checkResize();var point=d3mls_maps.googleMaps.clickedMarker.gMarker.getLatLng();d3mls_maps.googleMaps.dialogMap.map.setCenter(point,15);}});},_initGoogle:function()
{this.googleMaps.mapNode=document.getElementById(this.googleMaps.mapNodeId);this.googleMaps.map=new google.maps.Map2(this.googleMaps.mapNode);this.googleMaps.map.setUIToDefault();this.googleMaps.map.setMapType(eval(this.d3mlsMaps.map_type));this.googleMaps.dialogMap.domNode=document.getElementById(this.googleMaps.dialogMap.domNodeId);this.googleMaps.dialogMap.map=new google.maps.Map2(this.googleMaps.dialogMap.domNode);this.googleMaps.dialogMap.map.setUIToDefault();this.googleMaps.dialogMap.map.setMapType(eval(this.d3mlsMaps.map_type));this.googleMaps.gDirectionsObj=new GDirections(((this.d3mlsMaps.markerClickAction=="infowindow")?this.googleMaps.map:this.googleMaps.dialogMap.map),document.getElementById(this.googleMaps.gDirectionsNodeId));this.googleMaps.gStreetviewClientObj=new GStreetviewClient();this.googleMaps.gStreetviewPanoramaObj=new GStreetviewPanorama(document.getElementById(this.googleMaps.gStreetviewPanoramaNodeId));},_setUpMap:function()
{if(this.d3mlsMaps.markers.length=="undefined"||this.d3mlsMaps.markers.length==0)
this.googleMaps.map.setCenter(new GLatLng(this.d3mlsMaps.lat,this.d3mlsMaps.lon),this.d3mlsMaps.zoom);else
{this._setMarkers();this._setBounds();}},_setMarkers:function()
{for(var i=0;i<this.d3mlsMaps.markers.length;i++)
{var point=new GLatLng(this.d3mlsMaps.markers[i].lat,this.d3mlsMaps.markers[i].lon);this.googleMaps.gLatLngArray.push(point);var markerIcon=this._createMarkerIcon({width:24,height:24,primaryColor:this.d3mlsMaps.markers[i].color});var eventProperties={gMarker:new GMarker(point,{icon:markerIcon}),icon:markerIcon,dialogTitle:this.d3mlsMaps.markers[i].address+", "+this.d3mlsMaps.markers[i].city+", "+this.d3mlsMaps.markers[i].state,balloonHtml:this.googleMaps.gMarkerTemplate,dialogHtml:this.d3mlsMaps.dialogTemplate};for(var markerProp in this.d3mlsMaps.markers[i])
{if(markerProp=="image"&&this.d3mlsMaps.markers[i]["system"]!=null)
{if(this.d3mlsMaps.balloonImgResizer=='null')
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$image}",this.d3mlsMaps.markers[i].image);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$image}",this.d3mlsMaps.markers[i].image);}
else
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$image}",this.d3mlsMaps.balloonImgResizer+"&s="+this.d3mlsMaps.markers[i].system+"&img="+this.d3mlsMaps.markers[i].image);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$image}",this.d3mlsMaps.balloonImgResizer+"&s="+this.d3mlsMaps.markers[i].system+"&img="+this.d3mlsMaps.markers[i].image);}}
else if(markerProp=="image")
{if(this.d3mlsMaps.balloonImgResizer=='null')
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$image}",this.d3mlsMaps.markers[i].image);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$image}",this.d3mlsMaps.markers[i].image);}
else
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$image}",this.d3mlsMaps.balloonImgResizer+"&img="+this.d3mlsMaps.markers[i].image);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$image}",this.d3mlsMaps.balloonImgResizer+"&img="+this.d3mlsMaps.markers[i].image);}}
else if(markerProp=="system_id")
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$"+markerProp+"}",this.d3mlsMaps.detailsPage+this.d3mlsMaps.markers[i][markerProp]);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$"+markerProp+"}",this.d3mlsMaps.detailsPage+this.d3mlsMaps.markers[i][markerProp]);}
else
{eventProperties.balloonHtml=eventProperties.balloonHtml.replace("{$"+markerProp+"}",this.d3mlsMaps.markers[i][markerProp]);eventProperties.dialogHtml=eventProperties.dialogHtml.replace("{$"+markerProp+"}",this.d3mlsMaps.markers[i][markerProp]);}}
function addEvent(eventProperties)
{GEvent.addListener(eventProperties.gMarker,"click",function(overlay)
{d3mls_maps.googleMaps.clickedMarker.gOverlay=overlay;d3mls_maps.googleMaps.clickedMarker.gMarker=this;d3mls_maps.googleMaps.clickedMarker.icon=eventProperties.icon;d3mls_maps.googleMaps.clickedMarker.balloonHtml=eventProperties.balloonHtml;jQuery("#"+d3mls_maps.d3mlsMaps.dialogNodeId).attr("title",eventProperties.dialogTitle);jQuery("#detailsDialogNodeId").html(eventProperties.dialogHtml);if(d3mls_maps.d3mlsMaps.markerClickAction=="infowindow")
this.openInfoWindowHtml(eventProperties.balloonHtml);else if(d3mls_maps.d3mlsMaps.markerClickAction=="dialog")
d3mls_maps._setDialogMap();d3mls_maps.googleMaps.gStreetviewClientObj.getNearestPanorama(overlay,d3mls_maps._showStreetviewData);});}
addEvent(eventProperties);this.googleMaps.map.addOverlay(eventProperties.gMarker);}},_createMarkerIcon:function(opts)
{var width=opts.width||32;var height=opts.height||32;var primaryColor=opts.primaryColor||"#ff0000";var strokeColor=opts.strokeColor||"#000000";var cornerColor=opts.cornerColor||"#ffffff";var baseUrl="http://chart.apis.google.com/chart?cht=mm";var iconUrl=baseUrl+"&chs="+width+"x"+height+"&chco="+cornerColor.replace("#","")+","+primaryColor.replace("#","")+","+strokeColor.replace("#","")+"&ext=.png";var icon=new GIcon(G_DEFAULT_ICON);icon.image=iconUrl;icon.iconSize=new GSize(width,height);icon.shadowSize=new GSize(Math.floor(width*1.6),height);icon.iconAnchor=new GPoint(width/2,height);icon.infoWindowAnchor=new GPoint(width/2,Math.floor(height/12));icon.printImage=iconUrl+"&chof=gif";icon.mozPrintImage=iconUrl+"&chf=bg,s,ECECD8"+"&chof=gif";var iconUrl=baseUrl+"&chs="+width+"x"+height+"&chco="+cornerColor.replace("#","")+","+primaryColor.replace("#","")+","+strokeColor.replace("#","");icon.transparent=iconUrl+"&chf=a,s,ffffff11&ext=.png";icon.imageMap=[width/2,height,(7/16)*width,(5/8)*height,(5/16)*width,(7/16)*height,(7/32)*width,(5/16)*height,(5/16)*width,(1/8)*height,(1/2)*width,0,(11/16)*width,(1/8)*height,(25/32)*width,(5/16)*height,(11/16)*width,(7/16)*height,(9/16)*width,(5/8)*height];for(var i=0;i<icon.imageMap.length;i++)
icon.imageMap[i]=parseInt(icon.imageMap[i]);return icon;},_setBounds:function()
{var latlngbounds=new GLatLngBounds();for(var i=0;i<this.googleMaps.gLatLngArray.length;i++)
latlngbounds.extend(this.googleMaps.gLatLngArray[i]);this.googleMaps.map.setCenter(latlngbounds.getCenter(),parseInt(this.d3mlsMaps.zoom));if(d3mls_maps.d3mlsMaps.markerClickAction=="dialog")
this.googleMaps.dialogMap.map.setCenter(latlngbounds.getCenter(),this.googleMaps.map.getBoundsZoomLevel(latlngbounds));else
this.googleMaps.dialogMap.map.setCenter(new GLatLng(this.d3mlsMaps.lat,this.d3mlsMaps.lon),this.d3mlsMaps.zoom);},_showStreetviewData:function(streetviewData)
{if(streetviewData.code!=200)
document.getElementById(d3mls_maps.googleMaps.gStreetviewPanoramaNodeId).innerHTML="There is no street view available.";else
{document.getElementById(d3mls_maps.googleMaps.gStreetviewPanoramaNodeId).innerHTML="";d3mls_maps.googleMaps.gStreetviewPanoramaObj.setLocationAndPOV(d3mls_maps.googleMaps.clickedMarker.gOverlay);}},_setDialogMap:function()
{this.googleMaps.dialogMap.map.clearOverlays();this.showDialog(false);var point=this.googleMaps.clickedMarker.gMarker.getLatLng();var markerIcon=this.googleMaps.clickedMarker.icon;var balloonHtml=this.googleMaps.clickedMarker.balloonHtml.replace(/<span id='showDialogLink'>(.*?)<\/span>/,'');var marker=new GMarker(point,{icon:markerIcon});GEvent.addListener(marker,"click",function()
{this.openInfoWindowHtml(balloonHtml);});this.googleMaps.dialogMap.map.setCenter(point,15);this.googleMaps.dialogMap.gMarker=marker;this.googleMaps.dialogMap.map.addOverlay(marker);this.googleMaps.dialogMap.map.checkResize();},showDialog:function(setMap)
{if(setMap)
this._setDialogMap();else
jQuery("#"+d3mls_maps.d3mlsMaps.dialogNodeId).dialog('open');},getDirections:function()
{var inputAddress=jQuery("#"+this.googleMaps.gDirectionsInputAddressId).val();this.googleMaps.gDirectionsObj.load("from: "+inputAddress+" to: "+this.googleMaps.dialogMap.gMarker.getLatLng(),{"locale":"en_US"});}}
