function jsonThreads(){
this.threads=new Object();
}
jsonThreads.prototype.newThread=function(_1,_2,_3,_4,_5){
var _6=new jsonThread(_1,_2,_3,_4,_5);
this.threads[_6.id]=_6;
return _6;
};
jsonThreads.prototype.killAll=function(){
for(var i in this.threads){
var _8=this.threads[i];
_8.kill();
}
};
jsonThreads.prototype.killThread=function(_9){
var _a=this.getThread(_9);
if(_a==null){
return;
}
_a.kill();
};
jsonThreads.prototype.getThread=function(_b){
if(_b==null){
return null;
}
var _c=json_threads.threads[_b];
return _c;
};
jsonThreads.callback=function(_d,_e,_f){
var _10=_d.getThread(_e);
if(_10==null){
return;
}
_10.json.removeScriptTag();
if(_10.first_run){
_10.init_callback(_e,_f);
_10.first_run=0;
}
var _11;
if(_10.kill_request){
_11=true;
}else{
_11=_10.callback(_e,_f);
}
if(_11){
_10.running=false;
delete _d.threads[_e];
}else{
_10.launch(null,_f.count.last);
_10.accounting_callback(_e,_f);
}
return _10.running;
};
function jsonThread(_12,_13,_14,_15,_16){
this.id=Math.round(Math.random()*10000000);
this.running=false;
this.kill_request=false;
this.callback=_12;
this.init_callback=_13;
this.accounting_callback=_14;
this.abort_callback=_15;
this.update_parameter=_16;
this.update_parameter_count=0;
this.first_run=1;
}
jsonThread.prototype.launch=function(url,_18){
if(url==null&&this.url==null){
return;
}
if(url!=null){
this.url=url;
this.url+="&callback=jsonThreads.callback&callback_params=json_threads,"+this.id;
}
var _19=this.url+"&"+this.update_parameter+"="+_18;
this.json=new JSONscriptRequest(_19);
this.json.buildScriptTag();
this.running=true;
this.json.addScriptTag();
};
jsonThread.prototype.updateParameterCount=function(_1a){
this.update_parameter_count=_1a;
};
jsonThread.prototype.kill=function(){
this.kill_request=true;
this.abort_callback(this.id);
};
function JSONscriptRequest(_1b){
this.fullUrl=_1b;
this.noCacheIE="&noCacheIE="+(new Date()).getTime();
this.headLoc=document.getElementsByTagName("head").item(0);
this.scriptId="JscriptId"+JSONscriptRequest.scriptCounter++;
}
JSONscriptRequest.scriptCounter=1;
JSONscriptRequest.prototype.buildScriptTag=function(){
this.scriptObj=document.createElement("scr"+"i"+"pt");
this.scriptObj.setAttribute("type","text/javascript");
this.scriptObj.setAttribute("charset","utf-8");
this.scriptObj.setAttribute("src",this.fullUrl+this.noCacheIE);
this.scriptObj.setAttribute("id",this.scriptId);
};
JSONscriptRequest.prototype.removeScriptTag=function(){
this.headLoc.removeChild(this.scriptObj);
};
JSONscriptRequest.prototype.addScriptTag=function(){
this.headLoc.appendChild(this.scriptObj);
};
function showAds(){
}
showAds.getAds=function(_1c,_1d,_1e,_1f,_20,_21,_22,_23){
json_threads.killAll();
var _24=new Object();
_24.meter=_1c;
if(_1f==null){
_1f="today";
}
_24.ad_template=_21;
_24.ad_template_logo=_22;
_24.ad_template_images=_23;
_24.meter.reset();
_24.meter.setVisible(true);
_24.meter.updateProgress(0,"CONTACTING SERVER");
_24.processed_ads=0;
var _25=json_threads.newThread(showAds.loadAdsCallback,showAds.loadAdsInitCallback,showAds.loadAdsAccountingCallback,showAds.loadAdsAbortCallback,"start");
_25.updateParameterCount(Number(_24.processed_ads+0));
_24.classifieds_class_id=_1d;
_24.category_id=_1e;
_24.target_day=_1f;
_24.search_term=_20;
var _26="";
if(_24.target_day=="sunday"){
var _26="1";
}
var _27="http://bendbulletinclassifieds.appspot.com/get_ads/";
if(_24.search_term==null||!_24.search_term.length){
_27+="?";
}else{
_27+="?q="+_24.search_term+"&";
}
_27+="class_id="+_24.classifieds_class_id+"&category_id="+_24.category_id+"&sunday="+_26+"&count="+20;
_25.data_object=_24;
_25.launch(_27,"");
return _24;
};
showAds.loadAdsInitCallback=function(_28,ads){
var _2a=json_threads.getThread(_28);
if(_2a==null){
return;
}
var _2b=_2a.data_object;
_2b.ad_count_total=ads.count.total;
};
showAds.loadAdsAbortCallback=function(_2c){
var _2d=json_threads.getThread(_2c);
if(_2d==null){
return;
}
var _2e=_2d.data_object;
_2e.meter.setVisible(false);
};
showAds.loadAdsAccountingCallback=function(_2f,ads){
return;
};
showAds.loadAdsCallback=function(_31,ads){
var _33=json_threads.getThread(_31);
if(_33==null){
return;
}
var _34=_33.data_object;
for(var i=0;i<ads.ads.length;i++){
var ad=ads.ads[i];
if(ad!=null){
var _37="";
var _38="";
if(ad.type=="D"){
_37="classified_ad c900A D";
_38="ads_type_d";
}else{
if(ad.type=="PTA"){
_37="classified_ad c900A A";
_38="ads_type_pta";
}else{
if(ad.type=="PT"){
}else{
_37="classified_ad c900A A";
_38="ads_type_a";
}
}
}
var _39=showAds.prepText(_34,ad.text);
var _3a="";
var _3b="";
if(ad.type!="PT"){
_3a=showAds.addLogo(ad,_34.ad_template_logo);
_3b=showAds.addImages(ad,_34.ad_template_images);
}
if(ad.type=="PT"){
}
_34.ad_template.append(_38,{logo:_3a,images:_3b,content:_39,classes:_37});
_34.processed_ads++;
_34.meter.updateProgress(_34.processed_ads/_34.ad_count_total,"LOADED "+_34.processed_ads+" OF "+_34.ad_count_total+" ADS");
_33.updateParameterCount(Number(_34.processed_ads+0));
}
}
if(_34.processed_ads<_34.ad_count_total){
return false;
}else{
if(_34.processed_ads<1){
_34.meter.updateProgress(0,"NO ADS FOUND");
}
}
return true;
};
showAds.hyphenateLinks=function(_3c,_3d){
_3d=Math.round(_3d/2);
var _3e=_3c.getElementsByTagName("a");
for(var i=0;i<_3e.length;i++){
var a=_3e[i];
var _41=a.firstChild.data;
if(_41.length>_3d){
var _42=_41.substring(0,_3d)+" "+_41.substring(_3d);
a.firstChild.data=_42;
}
}
};
showAds.prepText=function(_43,_44){
var _45=unescape(_44);
return _45;
};
showAds.addLogo=function(ad,_47){
var _48="";
if(ad.images.logos.length>0){
var _49="http://bendbulletinclassifieds.appspot.com/get_image.jpg?w=200&h=50&image_id="+ad.images.logos[0];
var _4a="<img src=\""+_49+"\"/>";
_48+=_47.apply({image:_4a});
}
if(ad.images.logos.length<1&&ad.images.ags.length>0){
var _49="http://bendbulletinclassifieds.appspot.com/get_image.jpg?w=200&h=50&image_id="+ad.images.ags[0];
var _4a="<img src=\""+_49+"\"/>";
_48+=_47.apply({image:_4a});
}
return _48;
};
showAds.addImages=function(ad,_4c){
var _4d="";
var _4e;
var _4f;
for(var i=0;i<ad.images.photos.length;i++){
_4e="http://bendbulletinclassifieds.appspot.com/get_image.jpg?image_id="+ad.images.photos[i];
if(i==0){
_4f="<a onclick=\"tb_show(this.title,this.href,this.rel); this.blur(); return false;\" href=\""+_4e+"&w=600&h=450\" title=\"\" class=\"thickbox\" rel=\"gallery-classifieds-"+String(ad.ad_id)+"\"><img src=\""+_4e+"&w=200&h=50\" alt=\"\" /></a>";
_4d+=_4c.apply({image:_4f});
}else{
_4f="<a style=\"display:none;\" href=\""+_4e+"&w=600&h=450\" title=\"\" class=\"thickbox\" rel=\"gallery-classifieds-"+String(ad.ad_id)+"\"></a>";
_4d+=_4c.apply({image:_4f});
}
}
return _4d;
};
var BrowserDetect={init:function(){
this.browser=this.searchString(this.dataBrowser)||"An unknown browser";
this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";
this.OS=this.searchString(this.dataOS)||"an unknown OS";
},searchString:function(_51){
for(var i=0;i<_51.length;i++){
var _53=_51[i].string;
var _54=_51[i].prop;
this.versionSearchString=_51[i].versionSearch||_51[i].identity;
if(_53){
if(_53.indexOf(_51[i].subString)!=-1){
return _51[i].identity;
}
}else{
if(_54){
return _51[i].identity;
}
}
}
},searchVersion:function(_55){
var _56=_55.indexOf(this.versionSearchString);
if(_56==-1){
return;
}
return parseFloat(_55.substring(_56+this.versionSearchString.length+1));
},dataBrowser:[{string:navigator.vendor,subString:"Apple",identity:"Safari"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};
BrowserDetect.init();
function ajaxHistory(){
this.last_processed_click_href=0;
this.history=new Array();
this.click_count=0;
this.ie_first_click=0;
}
ajaxHistory.prototype.initTimer=function(_57){
this.friends=_57.friends;
this.timer=window.setInterval(followUrl,200);
};
ajaxHistory.prototype.firstLoad=function(_58){
this.default_hash=_58;
if(window.location.hash==null||window.location.hash.length<2){
this.insertClick(_58);
}else{
if(BrowserDetect.browser=="Explorer"){
var _59=window.location.hash.split(":");
var _58=_59[0];
if(_58!=null){
if(_58.length){
this.insertClick(_58);
}
}
}
}
};
ajaxHistory.prototype.newHistoryObject=function(_5a){
var _5b=new Object();
_5b.click=this.click_count;
_5b.hash=_5a;
_5b.click_id=Math.round(Math.random()*10000000);
this.history.unshift(_5b);
return _5b;
};
ajaxHistory.prototype.registerClick=function(_5c){
this.insertClick(_5c.hash);
};
ajaxHistory.prototype.insertClick=function(_5d){
_5d=_5d.replace(/^#/,"");
this.click_count++;
var _5e=this.newHistoryObject(_5d);
this.current_history_obj=_5e;
if(BrowserDetect.browser=="Explorer"){
var _5f=$("#browserHistoryFrame");
var url="/inc/statics/classifieds-ajax/_blank.html?session="+_5e.click_id+"#"+_5d+":"+_5e.click_id;
_5f.attr("src",url);
this.ie_first_click=1;
}else{
window.location.hash=_5d+":"+_5e.click_id;
}
};
ajaxHistory.prototype.browserHistoryFrameLoad=function(_61){
if(this.ie_first_click){
window.location.hash=_61;
}
};
ajaxHistory.prototype.followUrl=function(){
if(window.location.hash==undefined||this.last_processed_click_href==window.location.href){
return;
}
this.last_processed_click_href=window.location.href;
var _62=window.location.hash.replace(/%23/g,"");
_62=_62.replace(/^#/,"");
_62=_62.replace(/;/g,",'");
var _63=_62.split(":");
var _64=_63[0];
var _65=_63[1];
_63=_64.split(",");
_64=_63.shift();
if(_64==null||!_64.length){
return;
}
var _66=_64+"(";
for(var i=0;i<_63.length;i++){
if(i>0){
_66+=", ";
}
var _68=_63[i];
if(_68.search(/^'/)>-1){
_68+="'";
}
_66+=_68;
}
_66+=");";
eval(_66);
};
function followUrl(){
ajax_history.followUrl();
}
var json_threads;
var ajax_history;
Ext.BLANK_IMAGE_URL="/inc/statics/extjs/resources/images/default/s.gif";
Ext.namespace("bendbulletinClassifieds");
bendbulletinClassifieds.setCategoriesJson=function(_69){
bendbulletinClassifieds._categories_json=_69;
};
bendbulletinClassifieds.app=function(){
return {init:function(){
function bendbulletinClassifiedsCategories(_6a){
this._data=_6a;
var _6b=new Object();
var _6c=new Array();
for(var i=0;i<this._data.length;i++){
var _6e=this._data[i];
for(var y=0;y<_6e.categories.length;y++){
var _70=_6e.categories[y];
var _71=_70.id;
_6c.push([_71,_70.name]);
_6b[_71]=i+","+y;
}
}
this.json=function(){
return this._data;
};
this.categories=function(){
return _6c;
};
this.classifications=function(_72){
var _73=_6b[_72];
if(_73!=null){
var _74=_73.split(/,/);
var _75=this._data[_74[0]].categories[_74[1]];
if(_75!=null){
var _76=new Array();
for(var i=0;i<_75.classes.length;i++){
var _78=_75.classes[i];
_76.push([_78.id,_78.name]);
}
return _76;
}else{
return null;
}
}else{
return null;
}
};
}
function bendbulletinClassifiedsSearch(_79,_7a){
var _7b=false;
var _7c;
var _7d;
var _7e;
var _7f;
var _80;
var _81;
this.getCategoryName=function(){
return _7e.getRawValue();
};
this.submit=function(){
var _82=_7c.getValue();
var _83=_7d.getValue();
var _84=_7e.getValue();
var _85=_7f.getValue();
_7b=true;
_7a.signalSearchResults(_80,_83,_84,_85,_82);
};
var _86=new Ext.FormPanel({labelAlign:"top",title:"Search",frame:true,collapsible:true,buttonAlign:"right",onSubmit:Ext.emptyFn,submit:this.submit});
_7c=new Ext.form.TextField({xtype:"textfield",fieldLabel:"<b>3</b> Search by word (optional)",name:"first"});
var _87=new Ext.data.SimpleStore({fields:["id","name"]});
_7d=new Ext.form.ComboBox({disabled:true,editable:false,fieldLabel:"<b>2</b> Choose a classification",store:_87,hiddenName:"name",displayField:"name",valueField:"id",selectOnFocus:true,mode:"local",triggerAction:"all"});
category_store=new Ext.data.SimpleStore({fields:["id","name"],data:_79.categories()});
_7e=new Ext.form.ComboBox({editable:false,fieldLabel:"<b>1</b> Choose a category",store:category_store,hiddenName:"name",displayField:"name",valueField:"id",selectOnFocus:true,mode:"local",triggerAction:"all"});
this.category_combo_select_handler=function(_88,_89){
var _8a=Ext.data.Record.create([{name:"id"},{name:"name"}]);
var _8b=new Ext.data.ArrayReader({},_8a);
var _8c=_79.classifications(_89.data.id);
if(_8c.length){
_8c.unshift(["any","All"]);
}
var o=_8b.readRecords(_8c);
_7d.store.removeAll();
_7d.store.add(o.records);
_7d.setDisabled(false);
_7d.setValue(o.records[0].data.id);
_81.setDisabled(false);
};
_7e.on({"select":{fn:this.category_combo_select_handler}});
_7f=new Ext.form.ComboBox({editable:false,fieldLabel:"<b>4</b> Choose a date",store:[["today","Today"],["sunday","Last Sunday"]],selectOnFocus:true,triggerAction:"all"});
_7f.setValue("today");
_81=new Ext.Button({disabled:true,text:"Submit",handler:function(){
_86.getForm().submit({});
}});
_86.add({layout:"column",items:[{columnWidth:0.5,layout:"form",items:[_7e,_7d]},{columnWidth:0.5,layout:"form",items:[_7c,{layout:"column",items:[{columnWidth:0.7,layout:"form",items:[_7f]},{columnWidth:0.3,layout:"form",items:[_81]}]}]}]});
_80=new Ext.ProgressBar({});
this.progress=_80;
_86.add({layout:"fit",items:[this.progress]});
_86.render("main_search_box");
var w=_86.getInnerWidth();
_7e.setWidth(Math.round((w/2)*0.9));
_7d.setWidth(Math.round((w/2)*0.9));
_7c.setWidth(Math.round((w/2)*0.9));
_7f.setWidth(Math.round((w/2)*0.5));
_81.addClass("form_submit_button");
this.progress.getEl().setX(_7e.getEl().getX());
_80.setVisible(false);
this.setDefaults=function(_8f,_90,_91,_92){
if(_7b){
_7b=false;
return;
}
_7e.setValue(_90);
var _93=new Object();
_93.data={id:_90,name:_7e.getRawValue()};
_7e.fireEvent("select",_7e,_93);
_7d.setValue(_8f);
_7c.setValue(_92);
_7f.setValue(_91);
};
}
function bendbulletinClassifiedsResults(_94){
var _95=new Ext.TabPanel({defaults:{autoHeight:true},frame:true,renderTo:"results_tabs",activeTab:2,items:[{id:"browse",contentEl:"results_browse",title:"Browse"},{id:"browse_all",contentEl:"results_browse_all",title:"Browse all"},{id:"search_results",contentEl:"results_search",title:"Search results"}]});
var _96=Ext.Template.from("browse_buttons_template");
_96.compile();
var _97=Ext.Template.from("browse_buttons_template_all");
_97.compile();
var _98=Ext.Template.from("browse_buttons_category_template");
_98.compile();
var _99=Ext.Template.from("browse_buttons_category_url_template");
_99.compile();
var _9a=_94.json();
var _9b=Math.ceil(_9a.length/3);
for(var i=0;i<_9a.length;i++){
var _9d=Math.floor(i/_9b);
var _9e=_9a[i];
var _9f="";
for(var y=0;y<_9e.categories.length;y++){
var _a1=_9e.categories[y];
var _a2="";
for(var x=0;x<_a1.classes.length;x++){
var _a4=_a1.classes[x];
var _a5=_a1.id;
_a2+=_99.apply({url:"<a onclick =\"ajax_history.registerClick(this); return false;\" href=\"#search_ads;"+_a5+";"+_a4.id+";,0\">"+_a4.name+"</a>"});
}
_9f+=_98.apply({urls:_a2,title:_a1.name});
}
_96.append("results_browse_col"+_9d,{id:i,button_class:_9e.button_class,categories:_9f,label:_9e.title});
_97.append("results_browse_all_col"+_9d,{button_class:_9e.button_class,categories:_9f,label:_9e.title});
}
var _a6=Ext.Template.from("ad_template");
_a6.compile();
var _a7=Ext.Template.from("ad_template_logo");
_a7.compile();
var _a8=Ext.Template.from("ad_template_images");
_a8.compile();
this.signalSearchResults=function(_a9,_aa,_ab,_ac,_ad){
var _ae=1;
if(_ac!="sunday"){
_ae=0;
}
var _af="#search_ads;"+_ab+";"+_aa+";"+_ad+","+_ae;
ajax_history.insertClick(_af);
};
this.handleSearchResults=function(_b0,_b1,_b2,_b3,_b4){
$("#ads_type_pta").empty();
$("#ads_type_d").empty();
$("#ads_type_a").empty();
var tab=_95.getItem("search_results");
_95.setActiveTab(tab);
var _b6=new showAds();
var _b7=_b2.split(/_/);
_b2=_b7[0];
showAds.getAds(_b0,_b1,_b2,_b3,_b4,_a6,_a7,_a8);
};
this.activateBrowse=function(){
_95.activate("browse");
};
this.setTabTitle=function(_b8,_b9){
$("#results_search_title").empty();
$("#results_search_term").empty();
var t=_95.getItem("search_results");
var _bb="Search results for "+_b8;
if(_b9!=null&&_b9.length>0){
_bb+=", \""+_b9+"\"";
$("#results_search_term").append("\""+_b9+"\"");
}
t.setTitle(_bb);
$("#results_search_title").append(_b8);
};
}
$("#preloader").hide();
json_threads=new jsonThreads();
ajax_history=new ajaxHistory();
var _bc=new bendbulletinClassifiedsCategories(bendbulletinClassifieds._categories_json);
var _bd=new bendbulletinClassifiedsResults(_bc);
var _be=new bendbulletinClassifiedsSearch(_bc,_bd);
ajax_history.initTimer({friends:{search_results:_bd,classifieds_search:_be}});
ajax_history.firstLoad("link");
_bd.activateBrowse();
}};
}();
function browserHistoryFrameOnload(_bf){
if(ajax_history!=null){
ajax_history.browserHistoryFrameLoad(_bf.contentWindow.location.hash);
}
}
function search_ads(_c0,_c1,_c2,_c3){
if(_c2==null){
_c2="";
}
if(_c0!=null&&_c0!="any"){
_c0=_c0.replace(/[^0-9]/g,"");
if(_c0.length<3){
_c0=_c0+"0";
}
}
if(_c1!=null&&_c1!="any"){
_c1=_c1.replace(/[^0-9]/g,"");
_c1=_c1.replace(/^0/,"");
}
var _c4="today";
if(_c3){
_c4="sunday";
}
var _c5=$("#classifiedsHeaderTop").get(0);
if(_c5!=null&&_c5.scrollIntoView!=null){
_c5.scrollIntoView();
}
ajax_history.friends.classifieds_search.setDefaults(_c1,_c0,_c4,_c2);
ajax_history.friends.search_results.setTabTitle(ajax_history.friends.classifieds_search.getCategoryName(),_c2);
ajax_history.friends.search_results.handleSearchResults(ajax_history.friends.classifieds_search.progress,_c1,_c0,_c4,_c2);
var _c6="";
var _c7=_c0;
if(_c7!=null){
_c6="&class_category="+_c7;
}
var _c8=$("#right_ad_rail").get()[0];
if(_c8!=null){
if(_c8.contentWindow!=null){
_c8.contentWindow.location.replace("/apps/pbcs.dll/section?Category=CLASSIFIEDSAJAXADS&template=classifiedsajaxrightadrail"+_c6);
}
}
var _c9=$("#top_banner_ad").get()[0];
if(_c9!=null){
if(_c9.contentWindow!=null){
_c9.contentWindow.location.replace("/apps/pbcs.dll/section?Category=CLASSIFIEDSAJAXVIEWS&template=classifiedsajaxbannerad&"+_c6);
}
}
}
function link(_ca){
if(_ca!=null){
browse_button_show_hide(_ca);
}
ajax_history.friends.search_results.activateBrowse();
}


