
lastCat=$.getValueFromCookie('prefs','cat');category=lastCat!==null?lastCat:'cpg';$(document).ready(function(){changeCategory(category);$("#dateRange").datepick({rangeSelect:true,minDate:-30,maxDate:0,dateFormat:'yymmdd'});});feedNo=0;percentIncriment=100/cities.length;widthIncriment=380/cities.length;percent=0;statusWidth=0;function toggle(link,id){if(link.innerHTML=='[+]'){document.getElementById('d'+id).style.display='';link.innerHTML='[-]';}else{document.getElementById('d'+id).style.display='none';link.innerHTML='[+]';}}
function showWait(){$("#content").attr('innerHTML','<div align="center"><img src="wait.gif" alt="Please Wait..." title="Please Wait..." /><br />Fetching Cached Listings...</div>');}
function changeCategory(cat){showWait();$.writeValueToCookie('prefs','cat',cat);category=cat;$("#catLinks").val(cat);$("#titleCat").attr('innerHTML',categories[cat]);$('#content').load('ajax.php?action=show_listings&date='+defaultDateRange+'&category='+cat,function(){if($("#content").attr('innerHTML')==''){$("#content").attr('innerHTML','<p>There are no listings to display.</p><p>Click <b>Fetch Current Listings From Craigslist</b> on the toolbar above to make sure the listings are current, or modify your search using the <b>Advanced Search</b> tool.</p>');}});}
function filter(){if($(".cities input:checked").length<1){alert('Please select at least one city.');return;}
var city=new Array();$(".cities input:checked").each(function(){city.push($(this).val());});city=city.join(",");keywords=$("[name='keywords']").val();var dateRange=$("#dateRange").val().replace(" - ","-");showWait();$("#filters").slideUp("slow");$('#content').load('ajax.php?action=show_listings&category='+category+'&city='+city+'&date='+dateRange+'&keywords='+escape(keywords).replace("+","%2B"),function(){if($("#content").attr('innerHTML')==''){$("#content").attr('innerHTML','<p>There are no listings to display.</p><p>Click <b>Fetch Current Listings From Craigslist</b> on the toolbar above to make sure the listings are current, or modify your search using the <b>Advanced Search</b> tool.</p>');}});}
function getFeeds(){feedNo=0;percent=0;statusWidth=0;$("#status").css({"width":"0px"});$("#percent").attr('innerHTML','0%');$("#content").fadeOut("slow",function(){$(this).attr('innerHTML','');});$("#statusBoxContainer").fadeIn("slow");$.get('ajax.php?action=delete_feed&category='+category,function(){getSingleFeed();});}
function getSingleFeed(){if(feedNo>0){percent=Math.round(feedNo*percentIncriment);statusWidth=feedNo*widthIncriment;$("#status").css({"width":statusWidth+"px"});$("#percent").attr('innerHTML',percent+'%');}
$.get('ajax.php?action=fetch&city='+cities[feedNo]+'&category='+category,function(){feedNo++;if(feedNo+1<=cities.length){getSingleFeed();}else{$("#status").css({"width":"100%"});$("#percent").attr('innerHTML','100%');$("#statusBoxContainer").fadeOut("slow",function(){$("#content").fadeIn("slow");});changeCategory(category);}});}
function selectAllCities(){$(".cities input").attr("checked",true);$("#cityToggle").attr('innerHTML','Select None').attr('href','javascript:selectNoCities();');}
function selectNoCities(){$(".cities input").attr("checked",false);$("#cityToggle").attr('innerHTML','Select All').attr('href','javascript:selectAllCities();');}