// Travel Map variables and functions var txtFrom; var txtTo; var TMvendorsFound = new Object; var TMvendorsFilter = new Object; var TMvendorDetails; var TMcoords; var TM_MAP_WIDTH = 500; var TM_MAP_HEIGHT = 611; var TMaddressesValidated = false; var TMaddressesFound; var TMaddressFrom = ''; var TMaddressTo = ''; var TMmarkers = [{'length': 0}]; var TMselectedCategories = new Object; var TMlockMainCount = false; var map2; var map_canvas2; var loadedonmap = "no"; var geocoder; var addrPoints = new Object; var gdir; var frm_distanceUnit; var frm_distance; var polyline; var bounds; var infoWindows; function recargame() { reloadMe('travel_map'); // <- no remover reloadMe('notebook'); } // Legacy section, compatibility with previous variables and functions // Notebook function nbkLogin(){ var $trigger = function() { if(nbkAction == 'savevendor') { nbkSaveVendor(nbkVendor); } else if(nbkAction == 'saveselected') { nbkSaveSelected(); closeLogin(); fireLogin(); } }; Login($trigger); } // Printable Guide function pgLogin(){ $trigger = function(){ closeLogin(); fireLogin(); pgLogged = 1; pgTrigger = function(){ TMpopupMapa(); } TMpopupMapa(); }; Login($trigger); } function fireLogin() { jQuery('#btnSaveSelected').get(0).onclick = function(){ TMnbkSaveSelected(); }; jQuery('#btnPopupMapa').get(0).onclick = function(){ TMpopupMapa(); }; showVendorListings(TMvendorsFilter); changeText(); } var LNbaseURI = 'http://'+window.location.toString().split('/')[2]; var LNvendorsFound; function loadingLN() { } function mapNbkError(action,vendor){ nbkAction = action; nbkVendor = vendor; popupNbk(document.getElementById('mapMsgNoLogin').innerHTML); } function mapLogin(){ document.forms['login'].elements[2].disabled=false; pressed = false; document.forms['login'].submit = function(){ mapAjaxLogin(); return false; }; Login(function(){}); } // Loging through out the whole site function mapLogin2(){ document.forms['login'].elements[2].disabled=false; pressed = false; document.forms['login'].submit = function(){ mapAjaxLogin2(); return false; }; Login2(function(){}); } function Login2($trigger){ Trigger = $trigger; try{closeNbk()}catch(e1){}; try{closePG()}catch(e2){}; popupLogin2(); } function popupLogin2(){ document.getElementById('divLoginMessage').innerHTML = ''; displayPopup2('divLogin'); document.forms['login'].reset(); document.forms['login']['data[Login][email]'].focus(); } function displayPopup2(objID){ var target = document.getElementById(objID); $_top = document.body.scrollTop + (document.body.clientHeight - target.offsetHeight)/2; if($_top < 0) $_top = 0; target.style.top = $_top; target.style.left = (document.body.clientWidth - target.offsetWidth)/2; target.style.visibility = 'visible'; } function mapAjaxLogin2(){ var $_pars = new Array(); var $_form = document.forms['login']; $_pars['data[Login][email]'] = ''; $_pars['data[Login][password]'] = ''; for(v=0;v<$_form.elements.length;v++){ try{ $_pars[$_form.elements[v].name] = $_form.elements[v].value; }catch(err){}; } var myAjax = new Ajax.Request( LNbaseURI+'/notebook/ajaxlogin', {method:'post',parameters: $_pars, onLoading: loadingLN, onComplete: _mapLogin2} ); } function _mapLogin2($rs){ if($rs.responseText==1){ closeLogin(); changeText(); var txtFrom1 = trim(jQuery(txtFrom).val()+''); var txtTo1 = trim(jQuery(txtTo).val()+''); if(txtFrom1){SetCookie('txtFrom1', '' + txtFrom1 + '','');} if(txtTo1){SetCookie('txtTo1', '' + txtTo1 + '','');} window.location.reload(); } else{ loginError();} } var today = new Date(); var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) { endstr = document.cookie.length; } return unescape(document.cookie.substring(offset, endstr)); } function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { return getCookieVal (j); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function DeleteCookie (name,path,domain) { if (GetCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } function SetCookie (name,value,expires,path,domain,secure) { document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } function Get_Cookie( check_name ) { // first we'll split this cookie up into name/value pairs // note: document.cookie only returns name=value, not the other components var a_all_cookies = document.cookie.split( ';' ); var a_temp_cookie = ''; var cookie_name = ''; var cookie_value = ''; var b_cookie_found = false; // set boolean t/f default f for ( i = 0; i < a_all_cookies.length; i++ ) { // now we'll split apart each name=value pair a_temp_cookie = a_all_cookies[i].split( '=' ); // and trim left/right whitespace while we're at it cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, ''); // if the extracted name matches passed check_name if ( cookie_name == check_name ) { b_cookie_found = true; // we need to handle case where cookie has no value but exists (no = sign, that is): if ( a_temp_cookie.length > 1 ) { cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') ); } // note that in cases where cookie is initialized but no value, null is returned return cookie_value; break; } a_temp_cookie = null; cookie_name = ''; } if ( !b_cookie_found ) { return null; } } function Get_Cookie( name ) { var start = document.cookie.indexOf( name + "=" ); var len = start + name.length + 1; if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return null; } if ( start == -1 ) return null; var end = document.cookie.indexOf( ";", len ); if ( end == -1 ) end = document.cookie.length; return unescape( document.cookie.substring( len, end ) ); } function Delete_Cookie( name, path, domain ) { if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } function mapAjaxLogin(){ var $_pars = new Array(); var $_form = document.forms['login']; $_pars['data[Login][email]'] = ''; $_pars['data[Login][password]'] = ''; for(v=0;v<$_form.elements.length;v++){ try{ $_pars[$_form.elements[v].name] = $_form.elements[v].value; }catch(err){}; } var myAjax = new Ajax.Request( LNbaseURI+'/notebook/ajaxlogin', {method:'post',parameters: $_pars, onLoading: loadingLN, onComplete: _mapLogin} ); } function _mapLogin($rs){ if($rs.responseText==1){ nbkSaveLNvendor(nbkVendor); closeLogin(); }else loginError(); } function displayLNvendorListings($vendorsFound, $action){ showVendorListings(TMvendorsFilter); } function print_r(theObj){ var out = ''; if(theObj.constructor == Array || theObj.constructor == Object){ out+=""; } return out; }//end function print_r function TMpopupMapa(origin) { document.getElementById('travelguide')['data[Results][vendedores]'].value = jQuery('#TMvendorsID').val(); $_vendors = pgGetSelected(pgParent); document.getElementById('frmPf')['data[Print][vendors]'].value = $_vendors; popupPG(document.getElementById('pgMsgChoice').innerHTML.replace('[count]', pgCount)); changeText(); // pgPopupMapa(); } function changeText(){ document.getElementById('loginpannel').innerHTML = "Welcome "; } function TMpgSelected(origin){ if(!pgCount) return pgMsgError('no_selected_guide'); if(pgCount>1000) return pgMsgError('selected_max_2'); document.getElementById('frmPf')['data[Print][type]'].value = 'selected'; $_vendors = pgGetSelected(pgParent); //el valor de pgParent: NotebookListings--> Notebook/Listings document.getElementById('data[Result][vendedores]').value = $_vendors; popupPG(document.getElementById('pgMsgChoice').innerHTML.replace('[count]', pgCount)); if(pgCount > 0){ document.getElementById('data[direcciones]').value = document.getElementById('direcciones').value; document.getElementById('travelguide').action = '/travel_map/travelguidei'; document.getElementById('travelguide').submit(); setTimeout("closePG()", 1000); } else{ alert("You must select at least one item."); closePG(); } } function TMpgSaveSelected(){ document.getElementById('frmPf')['data[Print][type]'].value = 'save'; document.getElementById('frmPf').target = ''; TMpgSubmit('pg'); } function TMpgAlll(){ document.getElementById('travelguide')['data[Results][vendedores]'].value = jQuery('#TMvendorsID').val(); pgPopupMapa(); setTimeout("closePG()", 3000); } function TMpgSubmit(origin){ //submiteamos a listing/actions es en donde se imprime el pdf document.getElementById('frmPf').action = '/travel_map/action'; document.getElementById('frmPf')['data[Print][origin]'].value = origin; // que vale : nbk document.getElementById('frmPf')['data[Print][action]'].value = 'pg'; document.getElementById('frmPf').submit(); } function TMpgClear(){ document.getElementById('frmPf')['data[Print][type]'].value = 'clear'; document.getElementById('frmPf').target = ''; TMpgSubmit('pg'); } function TMpfPrintSelected() { pfPrintSelected('SearchListings','pf'); } function TMnbkSaveSelected(){ var $_vendors = ''; var $_titles = ''; var $_collection = document.getElementById('SearchListings').getElementsByTagName('input'); for($_i = 0; $_i < $_collection.length; $_i++){ if( $_collection[$_i].name == 'data[Results][vendor_id][]' && $_collection[$_i].checked ){ $_vendors+=$_collection[$_i].value+'|'; $_titles+=vendorTitles[$_collection[$_i].value]+'|'; } } jQuery.post("/notebook/action", { 'data[Notebook][action]': 'save', 'data[Notebook][vendors]': $_vendors, 'data[Notebook][titles]': $_titles, 'data[Notebook][text]': '', 'data[Notebook][referer]': '', 'data[Notebook][type]': 'listings', 'data[Notebook][id]': '' }, function (data, textStatus) { if (textStatus == 'success') { showVendorListings(TMvendorsFilter); } } ); jQuery('#btnPopupMapa').get(0).onclick = function(){ TMpopupMapa(); }; showVendorListings(TMvendorsFilter); if($_vendors){alert("Thank you! Your selected listings have been saved to your notebook.");} } function TMnbkSaveLNvendor(vendor){ jQuery.post("/notebook/action", { 'data[Notebook][action]': 'save', 'data[Notebook][vendors]': vendor, 'data[Notebook][titles]': vendorTitles[vendor], 'data[Notebook][text]': '', 'data[Notebook][referer]': '', 'data[Notebook][type]': 'listings', 'data[Notebook][id]': '', 'data[Notebook][answer]': 'json' }, function (data, textStatus) { if (textStatus == 'success') { if(data == 1 || data == 2 || data == '') { showVendorListings(TMvendorsFilter); alert("Thank you! Your selected listings have been saved to your notebook."); } else if(data != 2) alert('Error saving... Please try again later.'); } } ); } function clearForm() { jQuery('#txtFrom').val(''); jQuery('#txtTo').val(''); jQuery('#cmbDistance').val(5); jQuery('#cmbDistanceUnit_km').get(0).checked = false; jQuery('#cmbDistanceUnit_mi').get(0).checked = true; uncheckCategories(); } function uncheckCategories() { jQuery('#TMcategories :checkbox').each(function() { this.checked=false; jQuery(this).parent().css({'background-color': 'transparent', 'border-style': 'none'}); jQuery('img', jQuery(this).parent().get(0)).show(); }); } function initialize() { // Internal Popup jQuery('#iPopup').css({'z-index': 20, 'opacity': 0.9}); jQuery('#iPopup_close').click(function() { iPopup_close(); jQuery("#iPopup_title").html("Notification"); return false; }); // Fix nbkHiddenForm target jQuery('#frmNbk').attr({'target': 'iPublic'}); // Fashion rules for categories uncheckCategories(); jQuery('#TMcategories :checkbox').click(function() { TMlockMainCount = true; if(jQuery(this).attr('checked')) { jQuery(this).parent().css({'background-color': '#F0F0F0', 'border': '1px solid #D0D0D0'}); // Switch On category globe jQuery('img', jQuery(this).parent().get(0)).show(); } else { jQuery(this).parent().css({'background-color': 'transparent', 'border-style': 'none'}); jQuery('img', jQuery(this).parent().get(0)).show(); } filterByCategories(); }); // Prepare GMap if (window.GBrowserIsCompatible()) { // Configure GMap map2 = new window.google.maps.Map2(document.getElementById("map_canvas2"), {'GSize': {'width': 500, 'height': 410}}); geocoder = new window.GClientGeocoder(); gdir = new window.GDirections(map2, window.document.getElementById("map_directions")); txtFrom = parent.document.getElementById('txtFrom'); txtTo = parent.document.getElementById('txtTo'); // Event listeners window.GEvent.addListener(gdir, "load", onGDirectionsLoad); window.GEvent.addListener(gdir, "error", handleErrors); window.GEvent.addListener(map2, 'load', function(){ jQuery('#btnSubmit').attr('value','submit'); jQuery('#btnSubmit').removeAttr('disabled'); iPopup_close(); }); // Controls map2.addControl(new window.GLargeMapControl()); map2.addControl(new window.GMapTypeControl()); map2.addControl(new window.GScaleControl()); // Initial position map2.setCenter(new window.GLatLng(50, -110), 3); } return map2; } // Push selected categories into TMcoords for further dinamical filter function filterByCategories() { var counter = 0; var eraser = 0; jQuery('#TMcategories :checkbox').each(function(c) { delete TMcoords['data[Filter][vendor_category]['+ eraser +']']; if (jQuery(this).attr('checked')) { TMcoords['data[Filter][vendor_category]['+ counter +']'] = jQuery(this).val(); ++counter; } ++eraser; }); lookNearBy(TMcoords); } function fireMap() { jQuery('#btnSubmit').attr('disabled','disabled'); //jQuery('#txtFrom').val() = "10016"; switchMapHeader(); TMaddressesValidated = false; TMaddressFrom = ''; TMaddressTo = ''; TMlockMainCount = false; uncheckCategories(); fireMapEvents(); // Display Map Results jQuery('#TMwrapper').css({'position':'absolute', 'visibility':'hidden'}); } function switchMapHeader() { jQuery('#map_initial_header').hide(); jQuery('#map_header').show(); jQuery('#map_totalCount').hide(); } function fireMapEvents() { // Address Validation if (!TMaddressesValidated) { validateAddresses(); return false; } // Clean Directions Tab jQuery("#map_directions").html(''); // Retrieve parameters frm_distanceUnit = getDistanceUnit().value; frm_distance = getDistance(jQuery('#cmbDistance').val()); // Fire search iPopup_show('', 'Loading directions...'); setDirections(TMaddressFrom, TMaddressTo); } function getDistance(distance) { return distance * 1000 * frm_distanceUnit; } function getFilterDistance(distance) { var d; if (frm_distanceUnit == 1) d = Math.round((distance / 1.6093439)*10000)/10000; else d = distance; return d; } function getReverseDistance(meters) { return Math.round((meters / 10) / frm_distanceUnit)/100; } // Guess addresses function validateAddresses() { var fromAddress = trim(jQuery(txtFrom).val()+''); var toAddress = trim(jQuery(txtTo).val()+''); if(fromAddress =="brooklyn,ny" || fromAddress =="Brooklyn, ny" || fromAddress =="Brooklyn, Ny" || fromAddress =="Brooklyn, NY" || fromAddress =="Brooklyn" || fromAddress =="Brooklyn,ny" || fromAddress =="Brooklyn,ny" || fromAddress =="Brooklyn,Ny" || fromAddress =="Brooklyn,NY" || fromAddress =="brooklyn"){jQuery('#txtFrom').val("Brooklyn, ny 11226");} if(toAddress =="brooklyn,ny" || toAddress =="Brooklyn, ny" || toAddress =="Brooklyn, Ny" || toAddress =="Brooklyn, NY" || toAddress =="Brooklyn" || toAddress =="Brooklyn,ny" || toAddress =="Brooklyn,ny" || toAddress =="Brooklyn,Ny" || toAddress =="Brooklyn,NY" || toAddress =="brooklyn"){jQuery('#txtTo').val("Brooklyn, ny 11226");} var fromAddress = trim(jQuery(txtFrom).val()+''); var toAddress = trim(jQuery(txtTo).val()+''); if(toAddress == ""){ jQuery('#txtTo').val(fromAddress);} if (fromAddress != '') geocoder.getLocations(fromAddress, handleFromLocation); else iPopup_show('Please provide at least a valid START address.', 'Error!'); } function handleFromLocation(data) { pm = handleLocations(data); if (pm.Status == 100) { TMaddressFrom = pm.address; if (trim(jQuery(txtFrom).val()) != '') { geocoder.getLocations(trim(jQuery(txtTo).val()), handleToLocation); } else { TMaddressesValidated = true; fireMapEvents(); } } else if (pm.Status == 200) { pickAddress(pm.Placemark, '#txtFrom'); } } function handleToLocation(data) { pm = handleLocations(data); if (pm.Status == 100) { TMaddressTo = pm.address; TMaddressesValidated = true; fireMapEvents(); } else if (pm.Status == 200) { pickAddress(pm.Placemark, '#txtTo'); } } function handleLocations(data) { for(i in data.Placemark) { var p = data.Placemark[i]; } i = (i*1+1); if (i == 0) { parent.iPopup_show(errorString(404) + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); p['Status'] = 0; return p; } else if (i == 1) { p['Status'] = 100; return p; } else if (i > 1) { data['Status'] = 200; return data; } } function pickAddress(Placemark, selector) { var out = ''; TMaddressesFound = Placemark; var count = 0; for (i in Placemark) { out = 'Your address returned more than one match, please pick one of the alternatives below and try again:
'; out+= ''+ Placemark[i].address +'
'; ++count; } // Prevents submit button to stay disabled if (count < 1) { jQuery('#btnSubmit').removeAttr('disabled'); iPopup_show('Can\'t guess an address. Please verify your input is accurate and try again. ' , IPOPUP_DEFAULT_TITLE); } else iPopup_show(out,'Pick an Address'); } function setAddress(selector, addressID) { jQuery(selector).val(TMaddressesFound[addressID].address); } // Switch between Directions and Listings tabs. function switchTo(target) { if (target == 'Directions') { jQuery('#map_listings').hide(); jQuery('#map_listings_buttons').hide(); jQuery('#map_directions').show(); jQuery('#map_directions_buttons').show(); } else if(target == 'Listings') { jQuery('#map_directions').hide(); jQuery('#map_directions_buttons').hide(); jQuery('#map_listings').show(); jQuery('#map_listings_buttons').show(); } } function switchAddresses() { buffer = jQuery('#txtFrom').val(); jQuery('#txtFrom').val(jQuery('#txtTo').val()); jQuery('#txtTo').val(buffer); } function setDirections(fromAddress, toAddress, locale) { map2.clearOverlays(); //LUISA if(toAddress == '') toAddress = fromAddress; gdir.load("from: " + fromAddress + " to: " + toAddress, 'en_US'); } function getDistanceUnit() { if (jQuery('#cmbDistanceUnit_mi').is(':checked')) { return {'name': 'mi','value': 1.6093439}; } else if(jQuery('#cmbDistanceUnit_km').is(':checked')) { return {'name': 'km','value': 1}; } else { parent.window.iPopup_show('Please select a Distance Unit: Mi or Km', IPOPUP_DEFAULT_TITLE); return false; } } function coordsAdd(latlng) { TMcoords['data[Points]['+ (TMcoords.length - 1) +']'] = latlng.lat() +','+ latlng.lng(); ++TMcoords.length; } // Once START and END addresses are found, this function handle answer from // GMaps API, then extracts coords for later search of vendors. function onGDirectionsLoad() { // If got right directions if (gdir.getStatus().code == window.G_GEO_SUCCESS) { // Display wrapper // Validate direction polyline, it analizes segment(vertex) by segment var vertex, vStart, vPrev, vEnd, radio=0, max=0, errShort, coords, start=0, prev=0, segment=0; polyline = gdir.getPolyline(); // Get distance radious TMcoords = { 'data[Filter][range]': getFilterDistance(jQuery('#cmbDistance').val()), //~ 'data[Filter][vendor_category][0]': 'stores|', 'length': 1 }; // Get initial coords vStart = polyline.getVertex(start); vPrev = vStart; coordsAdd(vStart); // Get Middle coords for (var end=1; end < polyline.getVertexCount(); ++end) { vEnd = polyline.getVertex(end); radio = vEnd.distanceFrom(polyline.getVertex(prev)); segment+= radio; if (radio > frm_distance*2) { errShort = true; } // fix segment to farest vertex if (segment > frm_distance) { coordsAdd(vPrev); // Reset counter segment = radio; // Move initial pointer start = prev; } // Update pointer of previous position to latest position prev = end; vPrev = vEnd; } // Get final coords if (end > 1) coordsAdd(vEnd); if (errShort) iPopup_show('Warning! current route have segments exceeding given distance radius, some vendors will not be shown. Please increase distance radius and try again.', IPOPUP_DEFAULT_TITLE); // Fix IE Directions not displayed setTimeout("jQuery('#map_directions').html(jQuery('#map_directions', window.document).html())", 250); // Procceed to request vendors near route lookNearBy(TMcoords); } else { iPopup_show('Unfortunatelly there has been and unexpected error. Please reload the page and try again later, or contact us.', IPOPUP_DEFAULT_TITLE); } } // Interface to database, looks for vendors in given coords(from route) and criterias function lookNearBy(conditions) { jQuery.post("/travel_map/bridge/", conditions, function (data, textStatus) { if (textStatus == 'success') { // Format data var rs = tmEval(data); // Validate amount of Results if (!(rs.Vendors.length > 0)) { iPopup_show('Your search returned 0 results.', IPOPUP_DEFAULT_TITLE); return false; } // Proceed to show listings LNvendorsFound = rs.Vendors; filter = { 'data[Map][lpp][0]': 0, 'data[Map][lpp][1]': 10, 'data[Map][order][criteria]': 'category', 'data[Map][order][direction]': 'ASC', 'data[Map][order_backup][criteria]': 'category', 'data[Map][order_backup][direction]': 'ASC' }; TMvendorsFound = new Object; TMvendorsFilter = new Object; for (d=0; d < rs.Vendors.length; ++d) { vendor = rs.Vendors.distances[d]; filter['data[Distances]['+ d +']'] = vendor[0] +','+ vendor[1]; TMvendorsFound['data[Index]['+ d +']'] = vendor[0]; filter['data[Index]['+ d +']'] = vendor[0]; } displayTotalCount(rs.Vendors.length); // Send data showVendorMarkers(TMvendorsFound); showVendorListings(filter); TMvendorsFilter = filter; } } ); } // Listings Tab function sortTMlistings(criteria) { TMvendorsFilter['data[Map][order][criteria]'] = criteria; TMvendorsFilter['data[Map][order_backup][criteria]'] = criteria; showVendorListings(TMvendorsFilter); } function displayTMPage(page) { TMvendorsFilter['data[Map][lpp][0]'] = page; showVendorListings(TMvendorsFilter); } // <-- end of Listings Tab function displayTotalCount(count) { if (!TMlockMainCount) { jQuery('#map_totalCount').html("Your search returned "+ count +" result(s) in all categories. To filter your results, check below."); jQuery('#map_totalCount').show(); } } function tmEval(source) { try { return eval("a="+source); } catch(e) { //~ iPopup_show(source); } } function showVendorMarkers(index) { iPopup_show('', 'Loading listings...'); jQuery.post("/travel_map/bridge/vendorDetails/", index, function (data, textStatus) { if (textStatus == 'success') { // Clean Up markers if (TMmarkers.length > 0) { for (vendor in TMmarkers) { try { TMmarkers[vendor].remove(); } catch(e) {} } } // Display vendors in map var rs = tmEval(data); bounds = new window.GLatLngBounds(); var index = rs.Details.index; TMvendorDetails = index; TMmarkers = [{'length': 0}]; var i = 0; var vendorsID = ''; // Base icon var baseIcon = new window.GIcon(); baseIcon.shadow = null; baseIcon.transparent = null; baseIcon.iconSize = new window.GSize(9, 9); baseIcon.shadowSize = new window.GSize(9, 9); baseIcon.iconAnchor = new window.GPoint(3, 9); baseIcon.infoWindowAnchor = new window.GPoint(9, 1); baseIcon.infoShadowAnchor = null; for (vendor in index) { vendorsID+= vendor +'|'; var latlng = new window.GLatLng(index[vendor].latitude, index[vendor].longitude); bounds.extend(latlng); // Create icon for marker var icon = new window.GIcon(baseIcon, '/images/'+ LNvendorsFound.colors[vendor] +'.png'); // Create marker TMmarkers[vendor] = new window.GMarker(latlng, icon); ++TMmarkers.length; // Add marker to map map2.addOverlay(TMmarkers[vendor]); //LUISA TMmarkers[vendor].bindInfoWindowHtml(index[vendor].description); ++i; if (i > 100) iPopup_show('', 'Still working...'); } // For later use on Travel Guide // Pre-format directions var route = gdir.getRoute(0); preformatDirections(route); jQuery('#TMvendorsID').val(vendorsID); // Add route start and end points bounds.extend(route.getStep(0).getLatLng()); bounds.extend(route.getEndLatLng()); // adapted from http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/gmap/gmap2.module?view=markup var center_lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2.0; var center_lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2.0; var center = new window.GLatLng(center_lat, center_lng); var zoom = map2.getBoundsZoomLevel(bounds); //LUISA map2.setCenter(center,zoom); //LUISA // Re-enable btnSubmit jQuery('#btnSubmit').removeAttr('disabled'); //~ centerToBound(); iPopup_close(); } } ); } function preformatDirections(route) { var output = ''; var j = 0; for (i=0; i < route.getNumSteps(); ++i) { j = i + 1; var step = route.getStep(i); output+= i +" . "+ step.getDescriptionHtml() +" - "+ getReverseDistance(step.getDistance().meters) +" "+ getDistanceUnit().name +"|"; } output = replaceSubstring(output, "", ""); output = replaceSubstring(output, "", ""); output = replaceSubstring(output, '
', ""); output = replaceSubstring(output, "
", ""); output = replaceSubstring(output, "/", "
"); output = replaceSubstring(output, '
', ""); jQuery('#direcciones').val(output); } function replaceSubstring(inputString, fromString, toString) { // Goes through the inputString and replaces every occurrence of fromString with toString var temp = inputString; if (fromString == "") { return inputString; } if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation) while (temp.indexOf(fromString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(fromString)); var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length); temp = toTheLeft + toString + toTheRight; } } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop var midStrings = new Array("~", "`", "_", "^", "#"); var midStringLen = 1; var midString = ""; // Find a string that doesn't exist in the inputString to be used // as an "inbetween" string while (midString == "") { for (var i=0; i < midStrings.length; i++) { var tempMidString = ""; for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; } if (fromString.indexOf(tempMidString) == -1) { midString = tempMidString; i = midStrings.length + 1; } } } // Keep on going until we build an "inbetween" string that doesn't exist // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string while (temp.indexOf(fromString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(fromString)); var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length); temp = toTheLeft + midString + toTheRight; } // Next, replace the "inbetween" string with the "toString" while (temp.indexOf(midString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(midString)); var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length); temp = toTheLeft + toString + toTheRight; } } // Ends the check to see if the string being replaced is part of the replacement string or not return temp; // Send the updated string back to the user } // Ends the "replaceSubstring" function String.prototype.replaceAll2=function(s1, s2) { return this.replace(new RegExp(s1,"g"), s2); } function popupMarker(vendor) { TMmarkers[vendor].openInfoWindow(TMvendorDetails[vendor].description, {'maxWidth': 357}); } function showVendorListings(conditions) { jQuery.post("/travel_map/bridge/vendorListings/", conditions, function (data, textStatus) { if (textStatus == 'success') { jQuery('#map_listings').html(data); switchTo('Listings'); // Display Map Results jQuery('#TMwrapper').css({'position':'relative', 'visibility':'visible'}); jQuery('#TMwrapper2').css({'position':'relative', 'visibility':'hidden'}); jQuery('#TMcategories').show(); } } ); } // Displays a sort of custom messages when some error occurs, // used by events called AFTER addresses validation. function handleErrors() { // Look for alternative locations if (gdir.getStatus().code == window.G_GEO_UNKNOWN_ADDRESS) iPopup_show(errorString(404) + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); else if (gdir.getStatus().code == window.G_GEO_SERVER_ERROR) iPopup_show("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); else if (gdir.getStatus().code == window.G_GEO_MISSING_QUERY) iPopup_show("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); // else if (gdir.getStatus().code == window.G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong // iPopup_show("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code); else if (gdir.getStatus().code == window.G_GEO_BAD_KEY) iPopup_show("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); else if (gdir.getStatus().code == window.G_GEO_BAD_REQUEST) iPopup_show("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code, IPOPUP_DEFAULT_TITLE); else iPopup_show("An unknown error occurred.", 'Error!'); } // For custom messages called by other functions than handleErrors() function errorString(code){ if (code == 404) return "No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: "; } // Print Directions function TMprintDirections() { var directions = window.document.getElementById("map_directions"); directions = jQuery(directions).html(); var frm = document.getElementById('frmDirections'); frm['data[directions]'].value = directions; frm.submit(); } // Debug Functions function reloadMe(file) { var script = document.createElement('script'); script.src = '/js/getjs.php?f='+ file; script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); }