function DrivingDirections(){var g=[];var q=this;function j(u,s){var r=false;for(var t=u.length-1;t>=0;t--){if(u.options[t].value==s){r=true;break}}if(r){alert("Location already in the Selected Location list.")}return r}function h(){var v=document.getElementById("mapsearch-directions-locations-list");if(v.length==-1){alert("There are no locations which can be moved!")}else{if(v.length>0){var r=v.selectedIndex;if(r==-1){alert("You must select a location to be moved!")}else{if(r>0){var u=v[r-1].text;var t=v[r].text;var w=v[r-1].value;var s=v[r].value;v[r].text=u;v[r].value=w;v[r-1].text=t;v[r-1].value=s;v.selectedIndex=r-1;e(v)}}}}}function m(){var v=document.getElementById("mapsearch-directions-locations-list");if(v.length==-1){alert("There are no locations which can be moved!")}else{if(v.length>0){var r=v.selectedIndex;if(r==-1){alert("You must select a location to be moved!")}else{if(r!=v.length-1){var u=v[r+1].text;var t=v[r].text;var w=v[r+1].value;var s=v[r].value;v[r].text=u;v[r].value=w;v[r+1].text=t;v[r+1].value=s;v.selectedIndex=r+1;e(v)}}}}}function e(r){var s;for(i=r.length-1;i>=0;i--){s=r.options[i].text;r.options[i].text=s.replace(s.substring(0,s.indexOf(": ")),String.fromCharCode(i+65))}}function c(){var r=document.getElementById("mapsearch-directions-locations-list");for(i=r.length-1;i>=0;i--){if(r.options[i].selected){r.options[i]=null}}e(r)}function b(r){$("#"+r).val("").blur()}function d(s){var r="mapsearch-directions-"+s+"-";b(r+"street");b(r+"city");b(r+"state");b(r+"zip")}function p(t){var s=false;var r=$("#"+t);if(r.length>0){var u=r.val();s=(u!=""&&u!=r.attr("title"))}return s}function o(t){var r="mapsearch-directions-"+t+"-";var s=((p(r+"city")&&p(r+"state"))||(p(r+"zip")));if(!s){alert("City and State or Zip is required for "+t+" location")}return s}function n(r){if(p(r)){return $("#"+r).val()+" "}else{return""}}function a(t){var s="";var r="mapsearch-directions-"+t+"-";s+=n(r+"street");s+=n(r+"city");s+=n(r+"state");s+=n(r+"zip");if(s!=""){if(!o(t)){return"INVALID"}}return s}function k(){d("start");document.getElementById("mapsearch-directions-locations-list").options.length=0}function f(){var v=document.getElementById("mapsearch-directions-locations-list");if(v){g=[];var r=0;var t=a("start");if(t!="INVALID"){if(t!=""){g[0]=t;r=1}for(var u=0,s=v.length;u<s;u++){g[r]=v.options[u].value.replace("#","").replace("&","");r++}if(g.length>1){OpenDrivingDirections()}else{alert("Enter more than one location to get directions")}}}}function l(){var r=a("add");if(r!="INVALID"){if(r==""){alert("Please Enter Location to Add")}else{q.AddLocationToList(r);d("Add")}}}this.load=function(){$("#mapsearch-directions-button-moveup").click(h);$("#mapsearch-directions-button-movedown").click(m);$("#mapsearch-directions-button-remove").click(c);$("#mapsearch-directions-button-clear").click(k);$("#mapsearch-directions-button-get").click(f);$("#mapsearch-directions-button-add").click(l)};this.printDirections=function(r){OpenDrivingDirections(r)};this.AddLocationToList=function(t){$("#mapsearch-left-accordion").accordion("activate",1);var s=document.getElementById("mapsearch-directions-locations-list");if(s){var r=s.length;if(r>=20){alert("We only support Driving Directions for 20 locations")}t=t.replace("  ","");if(!j(s,t)){var u=new Option(String.fromCharCode(r+65)+": "+t,t);s.options[r]=u}}};this.getLocations=function(){return g}};