/* Cascaded Dropdown Population with jQuery written in 2010 by Martin T. Zeitler http://www.codeFX.biz/contact */ function bindAjax(){ /* start event: country change */ $('select#country').change(function() { /* fade out notice text & suggestions */ $('div#dropdowns div#notice').fadeOut(300); resetSuggestions(); /* displaying a mode indicator */ if($('input#mode').val() == 0){ $.mode = 'A'; $('input#mode').val("A"); $('div#direction').removeClass('modeA modeB'); $('div#direction').addClass('modeA'); $('div#direction').fadeIn(200); } switch($.mode){ case 'A': /* update state by country */ $.iso = $(this).val(); if($.iso!=0) { /* update the breadcrumb trail */ $('div#dropdowns div#breadcrumb').remove(); $('').prependTo('div#dropdowns'); $('div#dropdowns div#breadcrumb').fadeIn(200); $('select#state').fadeIn(200); $('select#cat').fadeOut(300); /* remove child-nodes from cats & subcats */ $('select#cat').children('option').remove(); $('select#subcat').children('option').remove(); var option = { target: "select#state", url: $.hostname+"ajax.php?mode=state_by_iso&iso="+$.iso, type: "get", success: function() { /* if there's only one result */ if($('select#state').val()!=0){ $('select#state').trigger('change'); } } } $(this).ajaxSubmit(option); } else { resetDropdowns(); } break; case 'B': /* update state by country & category */ $.iso = $(this).val(); $.cat = $('select#cat').val(); $.subcat = $('select#subcat').val(); if($.iso!=0) { /* update the breadcrumb trail */ $('div#dropdowns div#breadcrumb').remove(); $('').prependTo('div#dropdowns'); $('div#dropdowns div#breadcrumb').fadeIn(200); var option = { target: "select#state", url: $.hostname+"ajax.php?mode=state_by_iso_cat&iso="+$.iso+"&cat="+$.cat, type: "get", success: function() { $('select#state').fadeIn(200); /* if there's only one result */ if($('select#state').val()!=0){ $('select#state').trigger('change'); } } } $(this).ajaxSubmit(option); } else { resetDropdowns(); } break; default: GLog.write('select#country - unknown mode'); } bindSearch(); }); /* end event: country change */ /* start event: category change */ $('select#cat').change(function(){ $.state = $('select#state').val(); $.cat = $(this).val(); /* fade out notice text */ $('div#dropdowns div#notice').fadeOut(300); resetSuggestions(); /* displaying a mode indicator */ if($('input#mode').val() == 0){ $.mode = 'B'; $('input#mode').val("B"); $('div#direction').removeClass('modeA modeB'); $('div#direction').addClass('modeB'); $('div#direction').fadeIn(200); } if($.cat != 0){ switch($.mode){ case 'A': /* update subcat by category & state */ /* update the breadcrumb trail */ $('div#breadcrumb').html($('select#country option:selected').text()+' » '+$('select#state option:selected').text()+' » '+$('select#cat option:selected').text()); var option = { target: "select#subcat", url: $.hostname+"ajax.php?mode=subcat_by_state_cat&state="+$.state+"&cat="+$.cat, type: "get", success: function() { $('select#subcat').fadeIn(200); if($('select#subcat').val() != 0 ){ $('div#btnSearch').trigger('click'); } } } $(this).ajaxSubmit(option); break; case 'B': /* update country by cat & subcat */ if($('select#cat').val() != 0 && $('select#subcat').val() != 0){ var option = { /* update subcat by category */ target: "select#country", url: $.hostname+"ajax.php?mode=iso_by_cat&cat="+$.cat, type: "get", success: function() { $('select#country').fadeIn(200); } } $(this).ajaxSubmit(option); } break; default: // GLog.write('select#state - unknown mode'); } } else { /* if $.cat == 0 */ resetDropdowns(); } bindSearch(); }); /* end event: category change */ /* start event: state change */ $('select#state').change(function(){ switch($.mode){ case 'A': /* update category by state */ /* update the breadcrumb trail */ $('div#breadcrumb').html($('select#country option:selected').text()+' » '+$('select#state option:selected').text()); /* fade out subcategory */ $('select#subcat').fadeOut(300); var option = { /* update cat by state */ target: "select#cat", url: $.hostname+"ajax.php?mode=cat_by_state&state="+$(this).val(), type: "get", success: function() { $('select#cat').fadeIn(200); if($('select#cat').val()!=0 && $('select#cat').val()!=null){ $('select#cat').trigger('change'); } } } $(this).ajaxSubmit(option); break; case 'B': /* perform a search, if there's only one result */ if($('select#state').val()!=0){ $('div#btnSearch').trigger('click'); } break; default: // GLog.write('select#state - unknown mode'); } }); /* end event: state change */ /* start event: subcat change */ $('select#subcat').change(function(){ $('div#breadcrumb').html($('select#country option:selected').text()+' » '+$('select#state option:selected').text()+' » '+$('select#cat option:selected').text()+' » '+$('select#subcat option:selected').text()); $('div#btnSearch').trigger('click'); }); /* end event: subcat change */ /* start event: keywords enter pressed */ $('input#keywords').keypress(function(e) { if (e.which == 13){ $('div#btnSearch').trigger('click'); e.preventDefault(); } }); /* end event: keywords enter pressed */ } /* end: bindAjax(); */ function resetDropdowns() { /* fade out state & subcat dropdowns */ $('select#state').fadeOut(200); $('select#subcat').fadeOut(200); /* remove all child nodes and the breadcrumb trail*/ $('select#state').children('option').remove(); $('select#subcat').children('option').remove(); $('div#breadcrumb').remove(); $('div#direction').removeClass('modeA modeB'); /* reset the search mode */ $('input#mode').val("0"); $.mode = 0; var optA = { target: "select#country", url: $.hostname+"ajax.php?mode=iso", type: "get", success: function() { var optB = { target: "select#cat", url: $.hostname+"ajax.php?mode=cat", type: "get" } $(this).ajaxSubmit(optB); } } $(this).ajaxSubmit(optA); }/* end: resetDropdowns(); */ function resetSuggestions(){ $('ul#as-selections-keywords').children('li.as-selection-item').each( function() { $(this).remove(); }); $("input#keywords").val('Search Here'); } /* regular parsing mode */ function parseXML(xml){ places = [];clearList();$.c=0; var bounds = new GLatLngBounds(); $(xml).find("x").each(function(){ $.pid = $(this).attr("id");$.lng = $(this).attr("lg");$.lat = $(this).attr("lt");$.mtl = $(this).attr("t");$.stl = $(this).attr("s");$.ima = $(this).attr("i");$.adr = $(this).attr("a");$.cat = $(this).attr("c");$.view = $(this).attr("v"); /* reverting htmlenties */ $.adr= $.adr.replace( /</g, '<' ); $.adr= $.adr.replace( />/g, '>' ); $.html = '
'+$.mtl+'
'+$.stl+'
'+$.adr+'
';; $('ul#places').append('
  • '+$.mtl+'
  • ');var point = new GLatLng(parseFloat($.lat), parseFloat($.lng));bounds.extend(point); if(point!='(NaN, NaN)'){$.c++; var marker = createMarker(point, $.html, $.cat); places.push(marker); } }); if($.c > 0){ cl.removeMarkers();cl.addMarkers(places); map.setCenter(bounds.getCenter()); if($.iid!=0){map.setMapType(G_HYBRID_MAP);} map.setZoom(map.getBoundsZoomLevel(bounds)-2); map.savePosition(); } else { $('div#map').fadeOut(0); $('div#leftcol').fadeOut(0); $('div#dropdowns').append('

    ... no placemarks have been created yet.

    '); $('div#contentHolder').css({'height':'80px'}); } } /* cummulative parsing mode */ function extendArray(xml){ $.c= places.length; $(xml).find("x").each(function(){ $.pid = $(this).attr("id");$.lng = $(this).attr("lg");$.lat = $(this).attr("lt");$.mtl = $(this).attr("t");$.stl = $(this).attr("s");$.ima = $(this).attr("i");$.adr = $(this).attr("a");$.cat = $(this).attr("c");$.view = $(this).attr("v"); /* reverting htmlenties */ $.adr= $.adr.replace( /</g, '<' ); $.adr= $.adr.replace( />/g, '>' ); $.html = '
    '+$.mtl+''+$.stl+'
    '+$.adr+'
    ';; $('ul#places').append('
  • '+$.mtl+'
  • ');var point = new GLatLng(parseFloat($.lat), parseFloat($.lng));var marker = createMarker(point, $.html, $.cat);places.push(marker);$.c++; }); cl.removeMarkers(); cl.addMarkers(places); cl.fitMapToMarkers(); } function bindSearch() { $('div#btnSearch').unbind('click').bind('click', function(){ if( $('select#country').val()==0 && $('select#cat').val()==0 && $('input#keywords').val()=='' && $('ul#as-selections-keywords').children('li.as-selection-item').text()==''){ $('div#dropdowns div#notice').remove(); $('div#dropdowns').append('
    Please choose or enter keywords
    '); $('div#dropdowns div#notice').fadeIn(200); } else { $.ds = "places.xml?mode=search"; $('div#dropdowns div#notice').fadeOut(300); if($('select#country').val()!=0 && $('select#country option:selected').val()!=null){$.ds+="&iso="+$('select#country').val();} if($('select#state').val()!=0 && $('select#state option:selected').val() != null){$.ds += "&state="+$('select#state').val();} if($('select#cat').val()!=0 && $('select#cat option:selected').val()!=null){$.ds += "&cat="+$('select#cat').val();} if($('select#subcat').val()!=0 && $('select#subcat option:selected').val()!=null){$.ds += "&subcat="+$('select#subcat').val();} $.keyword = $('ul#as-selections-keywords').children('li.as-selection-item').text(); if($.keyword!='Search Here' && $.keyword!=''){ /* reset */ places = []; resetDropdowns(); clearList(); /* adding each keyword to the map */ $('ul#as-selections-keywords').children('li.as-selection-item').each( function() { $.ajax({type: "GET", url: $.hostname+"places.xml?mode=search&keyword="+$(this).html().substring(25, 128), dataType: "xml", success: extendArray }); }); } else { if($('input#keywords').val()!='Search Here' && $('input#keywords').val()!=''){$.ds += "&keyword="+$('input#keywords').val();} $.ajax({type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML}); } } }); /* button most viewed */ $('div#btnMostViewed').unbind('click').bind('click', function(){ $.ds = "places.xml?mode=most_viewed&id=25"; $.ajax({type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML}); }); /* button latest additions */ $('div#btnLatestAdditions').unbind('click').bind('click', function(){ $.ds = "places.xml?mode=latest_additions&id=25"; $.ajax({type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML}); }); }/* end: bindSearch(); */ /* default viewport */ function loadViewport() { var d = map.getBounds(); $.minY = d.getNorthEast().lng(); $.maxY = d.getSouthWest().lng(); $.minX = d.getSouthWest().lat(); $.maxX = d.getNorthEast().lat(); $.ds = "places.xml?mode=viewport&minX="+$.minX+"&maxX="+$.maxX+"&minY="+$.minY+"&maxY="+$.maxY; $.ajax({type:"GET",url:$.hostname+$.ds,dataType:"xml",success: parseXML}); } /* single placemark view */ function getSingle(id) { lowPage(); $('div#leftcol').remove(); $('div#map').css({width:'990px'}); /* switch page header */ $('div#dropdowns').css({'display':'none'}); $('div#details').css({'display':'block'}); $.ajax({ type: "GET", url: $.hostname+"places.xml?mode=single&id="+id, dataType: "xml", success: parseXML }); } /* business profile view */ function getPage(id) { lowPage(); $('div#dropdowns').html('

    '+id+'\'s page

    '); $.ds = "places.xml?mode=member&id="+id; $.ajax({ type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML }); } /* single cat view */ function getCat(id) { lowPage(); $.ds = "places.xml?mode=getCat&id="+id; $.ajax({ type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML }); } /* single subcat view */ function getSubCat(id) { lowPage(); $.ds = "places.xml?mode=getSubCat&id="+id; $.ajax({ type: "GET", url: $.hostname+$.ds, dataType: "xml", success: parseXML }); } /* newsticker functions */ function pauseTicker(){clearInterval(interval);} function restartTicker(){$("div#news").unbind().vTicker();} /* page layout manipulation */ function clearList(){$('ul#places li').remove();} function lowPage(){ $('div#gad').css({'marginTop':'34px'}); $('div#shortcuts').fadeOut(120); $("a.purple").attr("href", $.hostname); $('div#dropdowns').empty(); } function bindModal(){ /* privacy policy */ $('li#pp').click(function (e) { $.ajax({ url:'tabs.php?id=6', success:function(r){ $('div#simplemodal-container').children('.simplemodal-wrap').html(r); } }); $('#basic-modal-content').modal(); return false; }); /* terms and conditions */ $('li#tc').click(function (e) { $.ajax({ url:'tabs.php?id=7', success:function(r){ $('div#simplemodal-container').children('.simplemodal-wrap').html(r); } }); $('#basic-modal-content').modal(); return false; }); /* contact */ $('li#ct').click(function (e) { $.ajax({ url:'tabs.php?id=8', success:function(r){ $('div#simplemodal-container').children('.simplemodal-wrap').html(r); } }); $('#basic-modal-content').modal(); return false; }); } /* displaying an indicator for AJAX activity */ $(document).ajaxSend(function(){$('div#btnSearch').removeClass('activity');$('div#btnSearch').addClass('activity');}); $(document).ajaxStop(function() {$('div#btnSearch').removeClass('activity');}); /* document ready */ $(function(){ /* newsticker */ $("div#news").fadeIn(320).unbind().vTicker({height:632}); $("div#column_right").mouseover(function(){pauseTicker();}).mouseout(function(){restartTicker();}); /* loginpanel */ $("#open").click(function(){$("div#panel").slideDown("slow");}); $("#close").click(function(){$("div#panel").slideUp("slow");}); $("#toggle a").click(function(){$("#toggle a").toggle();}); });