
JMCLite=function(){this.isLiveSearching=false
this.includeSocialBookmarking=false;this.SearchResults=null;this.Container=null;this.SERVER_SCRIPT='mclite.dll';this.SearchContainer=null;this.ListingContainer=null;this.ClassContainer=null;this.PaginateContainer=null;this.AdvertContainer=null;this.ButtonFlags=0;this.AjaxContainer=null;this.BookName=null;this.MAX_LISTINGS=15;this.MAX_RANDOM_ADVERTS=3;this.MAP_BUTTON_ENABLED=(1<<0);this.GRAPHIC_BUTTON_ENABLED=(1<<1);this.AD_BUTTON_ENABLED=(1<<2);this.COMPARE_BUTTON_ENABLED=(1<<3);this.SHOW_ADVERT_CONTAINER=(1<<4);this.PAID_ADS_ONLY=false;this.socialNetworks=[{'image':'img/digg_32.png','url':'http://digg.com/submit?phase=2&url=URL&title=TITLE'},{'image':'img/delicious_32.png','url':'http://del.icio.us/post?url=URL&title=TITLE'},{'image':'img/facebook_32.png','url':'http://www.facebook.com/share.php?u=URL&t=TITLE'},{'image':'img/myspace_32.png','url':'http://www.myspace.com/Modules/PostTo/Pages/?l=3&u=URL&t=TITLE'},{'image':'img/reddit_32.png','url':'http://reddit.com/submit?url=URL&title=TITLE'},{'image':'img/google_32.png','url':'http://www.google.com/bookmarks/mark?op=edit&bkmk=URL&title=TITLE'}];this.languageInfo=[{'language':'English','id':'clang1','listLabelText':'Classification List','searchLabelText':'Search','searchOptionAll':'Any','searchOptionClass':'Classification','searchOptionName':'Name','searchOptionAddress':'Address','searchOptionPhone':'Phone','compareText':'Compare','compareAlert':'Please select one or more listings to compare.','pageselectText':'Select Page: ','pageNext':'Next>>','pagePrevious':'<<Previous'},{'language':'Español','id':'clang2','listLabelText':'Lista de Clasificación','searchLabelText':'Buscar en','searchOptionAll':'Todo','searchOptionClass':'Clasificación','searchOptionName':'Nombre','searchOptionAddress':'Dirección','searchOptionPhone':'Teléfono','compareText':'Comparar','compareAlert':'Por favor, seleccione una o más listas para comparar.','pageselectText':'Seleccione la página: ','pageNext':'Siguiente >>','pagePrevious':'<< Anterior'}];this.languageIndex=0;this.classlistLabel=null;this.searchLabel=null;this.searchOptionAll=null;this.searchOptionClass=null;this.searchOptionName=null;this.searchOptionAddress=null;this.searchOptionPhone=null;}
JMCLite.prototype.AjaxCallback=function(svar){var This=this;if(svar){$(This.AjaxContainer).text(svar).show();}else{$(This.AjaxContainer).text('').hide();}}
JMCLite.prototype.Init=function(book,flags){var This=this;This.ButtonFlags=flags;if(!This.Container){This.ErrorHandler('MagicCarpet Lite must be provided with a container element in which to place listing and classification information.<br />Use JMCLite.Container object property to assign the container element');return false;}
This.BookName=book;This.AjaxContainer=document.createElement('div');This.ListingContainer=document.createElement('div');This.ClassContainer=document.createElement('div');This.PaginateContainer=document.createElement('div');$(This.AjaxContainer).attr('id','mclite-ajax-status');$(This.AjaxContainer).hide();$(This.AjaxContainer).appendTo($('body'));var languageIndex=This.languageIndex+1;if(languageIndex>=This.languageInfo.length)languageIndex=0;This.createSearchContainer();This.classlistLabel=$(document.createElement('label'));$(This.classlistLabel).attr('for','mclite-class-container').text(This.languageInfo[0].listLabelText).css({'position':'absolute','top':'40px','left':'0px','font-weight':'bold'}).appendTo('#'+This.Container);var languageSelect=$(document.createElement('a'));$(languageSelect).attr('href','#')
$(languageSelect).text(This.languageInfo[languageIndex].language)
$(languageSelect).css({'position':'absolute','top':'40px','left':'240px','text-decoration':'none','font-size':'90%'});$(languageSelect).click(function(){This.languageIndex=This.languageIndex+1;if(This.languageIndex>=This.languageInfo.length)This.languageIndex=0;$(This.classlistLabel).text(This.languageInfo[This.languageIndex].listLabelText);$(This.searchLabel).text(This.languageInfo[This.languageIndex].searchLabelText);$(This.searchOptionAll).text(This.languageInfo[This.languageIndex].searchOptionAll);$(This.searchOptionClass).text(This.languageInfo[This.languageIndex].searchOptionClass);$(This.searchOptionName).text(This.languageInfo[This.languageIndex].searchOptionName);$(This.searchOptionAddress).text(This.languageInfo[This.languageIndex].searchOptionAddress);$(This.searchOptionPhone).text(This.languageInfo[This.languageIndex].searchOptionPhone);$('.compare-link').text(This.languageInfo[This.languageIndex].compareText);var otherLanguage=This.languageIndex+1;if(otherLanguage>=This.languageInfo.length)otherLanguage=0;$(this).text(This.languageInfo[otherLanguage].language);This.getClassifications(This.BookName);return false;});$(languageSelect).appendTo('#'+This.Container);$(This.ClassContainer).attr('id','mclite-class-container').appendTo('#'+This.Container);$(This.ListingContainer).attr('id','mclite-listing-container').appendTo('#'+This.Container);$(This.PaginateContainer).attr('id','mclite-paginate-container');if((This.ButtonFlags&This.SHOW_ADVERT_CONTAINER)==This.SHOW_ADVERT_CONTAINER){This.AdvertContainer=document.createElement('div');$(This.AdvertContainer).attr('id','mclite-advert-container').appendTo('#'+This.Container);if(!This.PAID_ADS_ONLY){This.AjaxCallback("Loading...");$.ajax({type:"GET",url:This.SERVER_SCRIPT+"/randomadvert",data:{book:This.BookName,count:This.MAX_RANDOM_ADVERTS},success:function(res){This.AjaxCallback(null);$(This.AdvertContainer).html(res);$('.mclite-advert').click(function(){var l={anchlink:$(this).attr('rel')}
This.ShowDisplayAd(This.BookName,l);}).css('cursor','pointer');}});}}
return true;}
JMCLite.prototype.liveSearch=function(query){var self=this;if(!self.isLiveSearching){var csr=$('#csr');var osr=$('#osr');if(query&&query.length>=4){self.isLiveSearching=true;$(osr).html($(csr).html());$(csr).css('display','none');$(osr).css('display','block');$(csr).html("");$.getJSON(self.SERVER_SCRIPT+'/livesearch',{'book':self.BookName,'q':query},function(data,textStatus){if(!data||data.errors||!data.length){$(csr).css('display','none');$(csr).html("");$(osr).css('display','none');$(osr).html("");}else{$(data).each(function(){var obj=this;if(obj.id&&obj.clang1){var a=document.createElement('a');$(a).attr('href','#');$(a).addClass('mclite-class-item')
$(a).click(function(){$(csr).css('display','none').html("");$(osr).css('display','none').html("");self.getYellowClassListings(self.BookName,obj.id,0,self.MAX_LISTINGS);return false;});$(a).text(obj.clang1);var d=document.createElement('div');$(a).appendTo(d);$(d).appendTo(csr);}});$(osr).css('display','none');$(csr).css('display','block');}
self.isLiveSearching=false;});}else{$(csr).css('display','none').html("");$(osr).css('display','none').html("");}}}
JMCLite.prototype.createSearchContainer=function(){var This=this;var FieldSet;var SearchForm;This.SearchContainer=document.createElement('div');$(This.SearchContainer).attr('id','mclite-search-container');$(This.SearchContainer).css('z-index','1');SearchForm=document.createElement('form');$(SearchForm).attr('autocomplete','off');$(SearchForm).submit(function(){This.searchListings($('#mclite-search-input').val(),$('#mclite-search-field').val());return false;});FieldSet=document.createElement('fieldset');$(FieldSet).attr('id','mclite-search-fieldset');This.searchLabel=$(document.createElement('legend'));$(This.searchLabel).text(This.languageInfo[0].searchLabelText).appendTo($(FieldSet));$(document.createElement('input')).attr('id','mclite-search-input').attr('type','text').css('width','191px').appendTo($(FieldSet));$(document.createElement('span')).text(' in ').appendTo($(FieldSet));This.searchOptionAll=document.createElement('option');$(This.searchOptionAll).attr('value','all').text(This.languageInfo[This.languageIndex].searchOptionAll);This.searchOptionClass=document.createElement('option');$(This.searchOptionClass).attr('value','klass').text(This.languageInfo[This.languageIndex].searchOptionClass)
This.searchOptionName=document.createElement('option');$(This.searchOptionName).attr('value','all').text(This.languageInfo[This.languageIndex].searchOptionName);This.searchOptionAddress=document.createElement('option');$(This.searchOptionAddress).attr('value','address').text(This.languageInfo[This.languageIndex].searchOptionAddress);This.searchOptionPhone=document.createElement('option');$(This.searchOptionPhone).attr('value','phone').text(This.languageInfo[This.languageIndex].searchOptionPhone);$(document.createElement('select')).attr('id','mclite-search-field').append($(This.searchOptionAll),$(This.searchOptionClass),$(This.searchOptionName),$(This.searchOptionAddress),$(This.searchOptionPhone)).appendTo($(FieldSet));$(document.createElement('input')).attr('type','submit').attr('value','Search Book').css('margin-left','10px').appendTo($(FieldSet));$(FieldSet).appendTo($(SearchForm));$(SearchForm).appendTo($(This.SearchContainer));var lSC=document.createElement('div');var lSCo=document.createElement('div');var lSCc=document.createElement('div');$(lSC).attr('id','lsr').css({'text-align':'left','background-color':'#F7F7FF','font-size':'90%'});$(lSCc).attr('id','csr').css({'display':'none','width':'420px'}).appendTo(lSC);$(lSCo).attr('id','osr').css({'display':'none','width':'420px'}).appendTo(lSC);$(lSC).appendTo(This.SearchContainer);$(This.SearchContainer).appendTo('#'+This.Container);$('#mclite-search-input').keyup(function(){This.liveSearch($(this).val());return false;});}
JMCLite.prototype.showYellow=function(){var This=this;This.getClassifications(This.BookName)}
JMCLite.prototype.getClassifications=function(Book){var This=this;This.AjaxCallback("Loading...");$.getJSON(This.SERVER_SCRIPT+'/classcontent',{'book':Book,'lang':This.languageInfo[This.languageIndex].id},function(data,textStatus){if(data.errors){This.ErrorHandler(data.errors);}else{This.TypesetClassifications(Book,data);}
This.AjaxCallback(null);});}
JMCLite.prototype.getYellowClassListings=function(Book,Klass,Start,Count){var This=this;var klassArray=new Array();klassArray.push({id:Klass,clang1:null});This.AjaxCallback("Loading...");$.getJSON(This.SERVER_SCRIPT+'/classlistings',{'book':Book,'class':Klass,'start':Start,'count':Count},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{$(This.ListingContainer).empty();This.PaginateYellow(Book,Klass,Start,data);This.TypesetYellow(Book,Klass,Start,data);This.UpdateAdvertizements(klassArray);}});}
JMCLite.prototype.showSingleListing=function(bookName,listingId){var This=this;This.AjaxCallback("Loading...");$.getJSON(This.SERVER_SCRIPT+'/listingById',{'book':bookName,'id':listingId},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{if(data&&data.length>1&&data[0].total>0){var klassId=data[1][0].klassid
$(This.ListingContainer).empty();This.PaginateYellow(bookName,klassId,0,data);This.TypesetYellow(bookName,null,0,data);}}});}
JMCLite.prototype.getWhiteListings=function(Book,Section,Alpha,Start,Count){var This=this;This.AjaxCallback("Loading...");$.getJSON(This.SERVER_SCRIPT+'/alphalistings',{'book':Book,'alpha':Alpha,'offset':Start,'count':Count,'section':Section},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{This.TypesetWhite(data);}});}
JMCLite.prototype.TypesetClassifications=function(Book,data){var This=this;if(!This.ListingContainer||!This.ClassContainer){This.ErrorHandler('Listing/Class Container element not specified.<br />MagicCarpet Lite must be provided with a container element in which to place listing and classification information.<br />Use JMCLite.ListingContainer/ClassContainer object to assign the container element');return;}
$(This.ClassContainer).empty();$(data).each(function(){var klass=this;$(document.createElement('a')).attr('href','#').addClass('mclite-class-item').click(function(){This.getYellowClassListings(Book,klass.id,0,This.MAX_LISTINGS);return false;}).text(klass.clang1).appendTo($(This.ClassContainer));});}
JMCLite.prototype.TypesetYellow=function(Book,Klass,Start,data){var This=this;var nTotal=data[0].total;$(data[1]).each(function(){This.TypesetYellowListing(this,Book,Klass);});}
JMCLite.prototype.TypesetYellowListing=function(Listing,Book,Class){var This=this;var div0=document.createElement('div');var div1=null;var div2=null;var lref=null;$(div0).addClass('yellow-listing-container');if(!Class&&Listing.klass){var d=document.createElement('div');var a=document.createElement('a');var b=document.createElement('b');$(d).addClass('yellow-listing-klass');$(a).attr('href','#').click(function(){This.getYellowClassListings(This.BookName,Listing.klassid,0,This.MAX_LISTINGS);return false;}).text(Listing.klass);$(b).text('See: ');$(b).appendTo($(d));$(a).appendTo($(d));$(d).appendTo($(div0));}
if(Listing.links){for(var i=0;i<Listing.links.length;i++){if(Listing.links[i].match(/http/i)){lref=Listing.links[i];break;}}}
if(lref){var d=document.createElement('div');var a=document.createElement('a');$(d).addClass('yellow-listing-finding');$(a).attr('href',lref);$(a).text(Listing.lfinding);$(a).appendTo($(d));$(d).appendTo($(div0));}else{$(document.createElement('div')).addClass('yellow-listing-finding').text(Listing.lfinding).appendTo($(div0));}
$(document.createElement('div')).addClass('yellow-listing-address').text(Listing.laddress||'-').appendTo($(div0));$(document.createElement('div')).addClass('yellow-listing-phone').text(Listing.lphone||'-').appendTo($(div0));if(Listing.secondary&&Listing.secondary.length){div1=document.createElement('div');$(div1).addClass('yellow-secondary-container');$(Listing.secondary).each(function(){This.TypesetYellowSecondary(this,div1);});$(document.createElement('a')).attr('href','#').attr('style','text-decoration:none;font-size:75%').text('More').click(function(){$(div1).toggle();if($(this).text()=='More')$(this).text('Less');else $(this).text('More');return false;}).appendTo($(div0));$(div1).appendTo($(div0));}
var extraConDiv=document.createElement('div');$(extraConDiv).addClass('extra-info-div');if(Listing.lgraphic||Listing.map||Listing.anchlink||Listing.coupon||Listing.url||Listing.email||Listing.save||Listing.video||Listing.audio){div2=document.createElement('div');$(div2).addClass('yellow-listing-buttons');This.TypesetYellowButtons(Listing,div2,Book);$(div2).appendTo(extraConDiv);}
var compareDiv=document.createElement('div');$(compareDiv).addClass('yellow-compare-div');var compareCheck=$(document.createElement('input'));$(compareCheck).attr('type','checkbox');$(compareCheck).attr('class','mclite-compare-checkbox');$(compareCheck).attr('value',Listing.id);$(compareCheck).click(function(){if($('.mclite-compare-checkbox:checked').size()==0){$('.yellow-listing-container').css('background-color','#FFFF99');}else{$('.yellow-listing-container').each(function(){if($('.mclite-compare-checkbox',this).is(':checked')){$(this).css('background-color','#FFFF99');}else{$(this).css('background-color','#C3C3C3');}});}});$(document.createElement('a')).addClass('compare-link').attr('href','#').text(This.languageInfo[This.languageIndex].compareText).css('float','none').click(function(){This.CompareYellow(Book);return false;}).appendTo($(compareDiv));$(compareCheck).appendTo($(compareDiv));$(compareDiv).appendTo(extraConDiv);$(extraConDiv).appendTo(div0);$(div0).appendTo($(this.ListingContainer));}
JMCLite.prototype.TypesetYellowButtons=function(Listing,Parent,Book){var This=this;if(Listing.lgraphic){var graphicDiv=document.createElement('div');var graphicLink=document.createElement('a');$(graphicDiv).addClass('yellow-button-div');$(graphicLink).attr('href','#');$(graphicLink).click(function(){This.ShowListingGraphic(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/NotextInfo.png').attr('alt','info').attr('border','0').appendTo(graphicLink);$(graphicLink).appendTo(graphicDiv);$(graphicDiv).appendTo(Parent);}
if(Listing.map){var mapDiv=document.createElement('div');var mapLink=document.createElement('a');$(mapDiv).addClass('yellow-button-div');$(mapLink).attr('href','#');$(mapLink).click(function(){This.ShowListingMap(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/RedTextEarth.png').attr('alt','map').attr('border','0').appendTo(mapLink);$(mapLink).appendTo(mapDiv);$(mapDiv).appendTo(Parent);}
if(Listing.anchlink){var adDiv=document.createElement('div');var adLink=document.createElement('a');$(adDiv).addClass('yellow-button-div');$(adLink).attr('href','#');$(adLink).click(function(){This.ShowDisplayAd(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/ad.png').attr('alt','See Advertisement').attr('border','0').appendTo(adLink);$(adLink).appendTo(adDiv);$(adDiv).appendTo(Parent);}
if(Listing.coupon){var couponDiv=document.createElement('div');var couponLink=document.createElement('a');$(couponDiv).addClass('yellow-button-div');$(couponLink).attr('href','#');$(couponLink).click(function(){This.ShowCoupon(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/coupon.gif').attr('alt','coupon').attr('border','0').appendTo(couponLink);$(couponLink).appendTo(couponDiv);$(couponDiv).appendTo(Parent);}
if(Listing.url){var urlDiv=document.createElement('div');var urlLink=document.createElement('a');$(urlDiv).addClass('yellow-button-div');$(urlLink).attr('href',Listing.url);$(urlLink).attr('target','_blank');$(document.createElement('img')).attr('src','img/WWW.gif').attr('alt','url').attr('border','0').appendTo(urlLink);$(urlLink).appendTo(urlDiv);$(urlDiv).appendTo(Parent);}
if(Listing.email){var emailDiv=document.createElement('div');var emailLink=document.createElement('a');$(emailDiv).addClass('yellow-button-div');$(emailLink).attr('href',Listing.email);$(document.createElement('img')).attr('src','img/Email.gif').attr('alt','email').attr('border','0').appendTo(emailLink);$(emailLink).appendTo(emailDiv);$(emailDiv).appendTo(Parent);}
if(Listing.save){var saveDiv=document.createElement('div');var saveLink=document.createElement('a');$(saveDiv).addClass('yellow-button-div');$(saveLink).attr('href','#');$(saveLink).click(function(){This.BookmarkListing(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/Save.gif').attr('alt','save').attr('border','0').appendTo(saveLink);$(saveLink).appendTo(saveDiv);$(saveDiv).appendTo(Parent);}
if(Listing.video){var videoDiv=document.createElement('div');var videoLink=document.createElement('a');$(videoDiv).addClass('yellow-button-div');$(videoLink).attr('href','#');$(videoLink).click(function(){This.ShowVideo(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/TV.gif').attr('alt','video').attr('border','0').appendTo(videoLink);$(videoLink).appendTo(videoDiv);$(videoDiv).appendTo(Parent);}
if(Listing.audio){var audioDiv=document.createElement('div');var audioLink=document.createElement('a');$(audioDiv).addClass('yellow-button-div');$(audioLink).attr('href','#');$(audioLink).click(function(){This.ShowAudio(Book,Listing);return false;});$(document.createElement('img')).attr('src','img/Audio%20Player.gif').attr('alt','audio').attr('border','0').appendTo(audioLink);$(audioLink).appendTo(audioDiv);$(audioDiv).appendTo(Parent);}}
JMCLite.prototype.TypesetYellowSecondary=function(Secondary,Parent){if(Secondary.saddress)
$(document.createElement('div')).addClass('yellow-secondary-address').text(Secondary.saddress).appendTo($(Parent));if(Secondary.sphone)
$(document.createElement('div')).addClass('yellow-secondary-phone').text(Secondary.sphone).appendTo($(Parent));}
JMCLite.prototype.TypesetWhite=function(data){var This=this;if(!This.ListingContainer){This.ErrorHandler('Container element not specified.<br />MagicCarpet Lite must be provided with a container element in which to place listing information.<br />Use JMCLite.Container object to assign the container element');return;}}
JMCLite.prototype.ErrorHandler=function(errors){var msg=errors+'<br />Click to close.';$('body').prepend($(document.createElement('div')).attr('class','mclite-error').html(msg).click(function(){$(this).remove();return false;}));}
JMCLite.prototype.ShowCoupon=function(Book,Listing){alert('The ShowCoupon method is not yet implemented');}
JMCLite.prototype.BookmarkListing=function(Book,Listing){var listingUrl=window.location.protocol+"//"+window.location.host+window.location.pathname+'?book='+this.BookName+'&id='+Listing.id;var listingTitle=Listing.lfinding;if(window.sidebar){window.sidebar.addPanel(listingTitle,listingUrl,"");}else if(window.external){window.external.AddFavorite(listingUrl,listingTitle);}else if(window.operal&&window.print){var elem=document.createElement('a');elem.setAttribute('href',listingUrl);elem.setAttribute('title',listingTitle);elem.setAttribute('rel','sidebar');elem.click();}else{alert('Cannot add bookmark, your browser is not yet supported.');}}
JMCLite.prototype.ShowVideo=function(Book,Listing){alert('The ShowVideo method is not yet implemented');}
JMCLite.prototype.ShowAudio=function(Book,Listing){alert('The ShowAudio method is not yet implemented');}
JMCLite.prototype.ShareListing=function(Book,Listing,Url){var listingUrl=window.location.protocol+"//"+window.location.host+window.location.pathname+'?book='+this.BookName+'%26id='+Listing.id;var listingTitle=Listing.lfinding;Url=Url.replace(/URL/,listingUrl);Url=Url.replace(/TITLE/,listingTitle);window.open(Url);return false;}
JMCLite.prototype.ShowDisplayAd=function(Book,Listing){var This=this;This.AjaxCallback('Loading...');$.getJSON(This.SERVER_SCRIPT+'/displayad',{'book':Book,'anchid':Listing.anchlink},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{var dw=parseFloat(data.width);var dh=parseFloat(data.height);var borderSize=75;var div0=document.createElement('div');var div1=document.createElement('div');$(div0).attr('id','addialog').attr('title',Listing.lfinding);$(div1).css({'text-align':'center','position':'absolute','left':'10px'});if(dw>=document.body.clientWidth){var r=document.body.clientWidth/dw;data.width=parseInt(String((dw*r)),10)-borderSize;data.height=parseInt(String((dh*r)),10)-borderSize;}
$(document.createElement('img')).attr('src',data.image).attr('alt','Display Advertisement').attr('width',data.width).attr('height',data.height).attr('border','0').appendTo(div1);if(data.links){$(data.links).each(function(){var Link=this;var div2=document.createElement('div');var a=document.createElement('a');$(a).attr('href',Link.uri);$(div2).css('left',parseInt(Link.x,10));$(div2).css('top',parseInt(Link.y,10));$(div2).css('position','absolute');$(document.createElement('img')).attr('src','img/blank.gif').attr('width',Link.width).attr('height',Link.height).attr('border',0).appendTo(a);$(a).appendTo($(div2));$(div2).appendTo($(div1));});}
$(div1).appendTo($(div0));$(div0).dialog({width:data.width,height:data.height+borderSize,close:function(event,ui){$('#addialog').dialog('destroy');}});}});}
JMCLite.prototype.ShowListingGraphic=function(Book,Listing){var This=this;This.AjaxCallback('Loading...');$.getJSON(This.SERVER_SCRIPT+'/listingdetail',{'book':Book,'id':Listing.id},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{var div0=document.createElement('div');var div1=document.createElement('div');$(div0).attr('id','listingdialog').attr('title',Listing.lfinding);$(div1).css({'text-align':'center','position':'absolute','left':'10px'});$(document.createElement('img')).attr('src',data.image).attr('alt','Display Advertisement').attr('width',data.width).attr('height',data.height).attr('border','0').appendTo(div1);if(data.links){$(data.links).each(function(){var Link=this;var div2=document.createElement('div');var a=document.createElement('a');$(a).attr('href',Link.uri);$(div2).css('left',parseInt(Link.x,10));$(div2).css('top',parseInt(Link.y,10));$(div2).css('position','absolute');$(document.createElement('img')).attr('src','img/blank.gif').attr('width',Link.width).attr('height',Link.height).attr('border',0).appendTo(a);$(a).appendTo($(div2));$(div2).appendTo($(div1));});}
$(div1).appendTo($(div0));$(div0).dialog({width:data.width+25,height:data.height+55,close:function(event,ui){$('#listingdialog').dialog('destroy');}});}});}
JMCLite.prototype.ShowListingMap=function(Book,Listing){var This=this;This.AjaxCallback('Loading...');$.getJSON(This.SERVER_SCRIPT+'/geocode',{'book':Book,'id':Listing.id},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{var map;var point;var mdialog=document.createElement('div');var ydialog=document.createElement('div');$(ydialog).attr('id','ymap');$(mdialog).attr('id','mapdialog').attr('title',Listing.lfinding);point=new YGeoPoint(data.latitude,data.longitude);map=new YMap(ydialog);map.addPanControl();map.addZoomLong();map.drawZoomAndCenter(point,3);map.addOverlay(new YMarker(point));$(ydialog).appendTo($(mdialog));$(mdialog).dialog({width:450,height:450,close:function(event,ui){$('#mapdialog').dialog('destroy');}});}});}
JMCLite.prototype.CompareYellow=function(Book){var This=this;var Listings=new Array();var Points=new Array();if($('.mclite-compare-checkbox:checked').size()==0){alert(This.languageInfo[This.languageIndex].compareAlert);return;}
$('.mclite-compare-checkbox:checked').each(function(){Listings.push($(this).attr('value'));});This.AjaxCallback("Loading...");$.getJSON(This.SERVER_SCRIPT+'/compare',{'book':Book,'id':Listings},function(data,textStatus){This.AjaxCallback(null);if(data.errors){This.ErrorHandler(data.errors);}else{var ddiv=document.createElement('div');var mdiv=document.createElement('div');var ldiv=document.createElement('div');var map=null;var pts=null;var haspts=false;$(data).each(function(){if(this.latitude&&this.longitude)haspts=true;});$(ddiv).attr('id','compare-dialog-container');$(ddiv).attr('title','Comparing Selection');$(ldiv).attr('id','compare-listing-container');if(haspts){$(mdiv).attr('id','compare-map-container');map=new YMap(mdiv,YAHOO_MAP_REG,new YSize(530,350));map.addTypeControl();map.addZoomLong();map.addPanControl();map.setMapType(YAHOO_MAP_REG);}
$(data).each(function(){var Marker=null;var idiv=document.createElement('div');$(idiv).addClass('yellow-listing-compare-container');if(haspts&&this.latitude&&this.longitude){var Point=new YGeoPoint(this.latitude,this.longitude);Marker=new YMarker(Point);if(this.lfinding)Marker.addAutoExpand(this.lfinding)
YEvent.Capture(Marker,EventsList.MouseOver,function(){$('.yellow-listing-compare-container').each(function(){if(this==idiv)
$(this).css('background-color','#FFFF99');else
$(this).css('background-color','#C3C3C3');});});map.addOverlay(Marker);Points.push(Point);}
$(idiv).hover(function(){var self=this;$('.yellow-listing-compare-container').each(function(){if(self==this)
$(this).css('background-color','#FFFF99');else
$(this).css('background-color','#C3C3C3');if(Marker)Marker.openAutoExpand();});},function(){$('.yellow-listing-compare-container').each(function(){$(this).css('background-color','#FFFF99');});if(Marker)Marker.closeAutoExpand();});if(this.klass&&this.klassid){var d=$(document.createElement('div'));var b=$(document.createElement('b'));$(d).addClass('yellow-listing-klass-compare');$(b).text(this.klass);$(b).appendTo($(d));$(d).appendTo($(idiv));}
$(document.createElement('div')).addClass('yellow-listing-finding').text(this.lfinding).appendTo($(idiv));$(document.createElement('div')).addClass('yellow-listing-address').text(this.laddress||'-').appendTo($(idiv));$(document.createElement('div')).addClass('yellow-listing-phone').text(this.lphone||'-').appendTo($(idiv));if(this.secondary&&this.secondary.length){div1=document.createElement('div');$(div1).addClass('yellow-secondary-container');$(this.secondary).each(function(){This.TypesetYellowSecondary(this,div1);});$(document.createElement('a')).attr('href','#').attr('style','text-decoration:none;font-size:75%').text('More').click(function(){$(div1).toggle();if($(this).text()=='More')$(this).text('Less');else $(this).text('More');return false;}).appendTo($(div1));$(div1).appendTo($(ldiv));}
$(idiv).appendTo($(ldiv));});if(haspts){var bz=map.getBestZoomAndCenter(Points);map.drawZoomAndCenter(bz.YGeoPoint,bz.zoomLevel);$(mdiv).appendTo(ddiv);}
$(ldiv).appendTo(ddiv);$(ddiv).dialog({width:600,height:600,close:function(event,ui){$('#compare-dialog-container').dialog('destroy');}});}});}
JMCLite.prototype.IsValidAddress=function(address){var expr="[0-9]+\\s*[a-zA-Z]+";var matched=false;if(!address)return false;matched=address.match(expr);if(matched){return true;}
return false;}
JMCLite.prototype.maybePhone=function(str){if(!str||str.match(/[a-zA-Z]/))return false;return true;}
JMCLite.prototype.PaginateYellow=function(Book,Klass,Start,data){var This=this;var sel;if(This.PaginateContainer==null){This.ErrorHandler('Paginate Container element not specified.<br />MagicCarpet Lite must be provided with a container element in which to place pagination information.<br />Use JMCLite.PaginateContainer object to assign the container element');return;}
$(This.PaginateContainer).empty();if(data[0].total<=This.MAX_LISTINGS)return;if(Start>0){$(document.createElement('a')).attr('href','#').text(This.languageInfo[This.languageIndex].pagePrevious).css('margin-right','5px').click(function(){This.getYellowClassListings(Book,Klass,Start-This.MAX_LISTINGS,This.MAX_LISTINGS);return false;}).appendTo($(This.PaginateContainer));}
if((Start+This.MAX_LISTINGS)<data[0].total){$(document.createElement('a')).attr('href','#').text(This.languageInfo[This.languageIndex].pageNext).css('margin-right','5px').click(function(){This.getYellowClassListings(Book,Klass,Start+This.MAX_LISTINGS,This.MAX_LISTINGS);return false;}).appendTo($(This.PaginateContainer));}
$(document.createElement('label')).text(This.languageInfo[This.languageIndex].pageselectText).appendTo($(This.PaginateContainer));sel=document.createElement('select');$(sel).change(function(){var n=parseInt($('option:selected',this).text());n=(n-1)*This.MAX_LISTINGS;This.getYellowClassListings(Book,Klass,n,This.MAX_LISTINGS);});for(var i=0;i<data[0].total;i+=This.MAX_LISTINGS){if(i!=Start){$(document.createElement('option')).text(((i/This.MAX_LISTINGS)+1).toString(10)).appendTo($(sel));}else{$(document.createElement('option')).attr('selected',true).text(((i/This.MAX_LISTINGS)+1).toString(10)).appendTo($(sel));}}
$(sel).appendTo($(This.PaginateContainer));$(This.PaginateContainer).appendTo($(This.ListingContainer));}
JMCLite.prototype.searchListings=function(svalue,sfield){var This=this;var quote=false;var query='';This.SearchResults=null;if(sfield.match(/address/i)||sfield.match(/phone/i)||This.maybePhone(svalue)){quote=true;}
if(quote){query='"'+svalue+'"';}else{var words=svalue.split(' ');for(word in words){var term=words[word].singularize();query=query+'+'+term;if(term.length>1)query=query+'*';}}
if(sfield=="address"||sfield=="phone")sfield="all";This.AjaxCallback("Searching...");$.getJSON(This.SERVER_SCRIPT+'/search',{book:This.BookName,q:query,field:sfield},function(data,textStatus){var klassArray=null;This.AjaxCallback(null);$(This.PaginateContainer).empty();$(This.ListingContainer).empty();if(data==null||data.length==1){$(document.createElement('b')).text('0 results found for '+svalue).appendTo($(This.ListingContainer));return;}else{This.SearchResults=data;if(This.SearchResults.length<2){$(document.createElement('b')).text('0 results found for '+svalue).appendTo($(This.ListingContainer));return;}
if(This.SearchResults[0].total!=This.SearchResults[1].length)This.SearchResults[0].total=This.SearchResults[1].length;$(This.PaginateContainer).empty();$(This.ListingContainer).empty();This.paginateSearchResults(0);This.typesetSearchResults(0);if(sfield.match(/klass/i)){var arra=new Array();$(This.ClassContainer).empty();$(This.SearchResults[1]).each(function(){arra.push({id:this.klassid,clang1:this.klass});});klassArray=This.uniqueKlassArray(arra);This.TypesetClassifications(This.BookName,klassArray);$(document.createElement('a')).attr('href','#').addClass('mclite-class-item').click(function(){This.getClassifications(This.BookName);return false;}).text('Show All').appendTo($(This.ClassContainer));}else{var arra=new Array();$(This.SearchResults[1]).each(function(){arra.push({id:this.klassid,clang1:this.klass});});klassArray=This.uniqueKlassArray(arra);}}
This.UpdateAdvertizements(klassArray);});}
JMCLite.prototype.UpdateAdvertizements=function(klassArray){var This=this;var url=This.SERVER_SCRIPT+'/sideadverts'
var dict;if(klassArray){var parray=new Array();$(klassArray).each(function(){parray.push(this.id);});if(This.PAID_ADS_ONLY){dict={book:This.BookName,klassonly:1,klass:parray,count:This.MAX_RANDOM_ADVERTS};}else{dict={book:This.BookName,klass:parray,count:This.MAX_RANDOM_ADVERTS};}}else{if(This.PAID_ADS_ONLY){dict={book:This.BookName,count:This.MAX_RANDOM_ADVERTS,klassonly:1};}else{dict={book:This.BookName,count:This.MAX_RANDOM_ADVERTS};}}
$.ajax({type:"GET",url:url,data:dict,success:function(res){This.AjaxCallback(null);$(This.AdvertContainer).html(res);$('.mclite-advert').click(function(){var rel=$(this).attr('rel');if(rel!="undefined"){var l={anchlink:rel};This.ShowDisplayAd(This.BookName,l);}}).css('cursor','pointer');}});}
JMCLite.prototype.paginateSearchResults=function(StartAt){var This=this;if(!This.SearchResults||!This.SearchResults.length||!This.SearchResults[0].total||This.SearchResults[0].total<This.MAX_LISTINGS)return false;if(StartAt>0){$(document.createElement('a')).attr('href','#').text(This.languageInfo[This.languageIndex].pagePrevious).css('margin-right','5px').click(function(){$(This.PaginateContainer).empty();$(This.ListingContainer).empty();This.paginateSearchResults(StartAt-This.MAX_LISTINGS);This.typesetSearchResults(StartAt-This.MAX_LISTINGS);This.updateAdsFromSearchResults();return false;}).appendTo($(This.PaginateContainer));}
if((StartAt+This.MAX_LISTINGS)<This.SearchResults[0].total){$(document.createElement('a')).attr('href','#').text(This.languageInfo[This.languageIndex].pageNext).css('margin-right','5px').click(function(){$(This.PaginateContainer).empty();$(This.ListingContainer).empty();This.paginateSearchResults(StartAt+This.MAX_LISTINGS);This.typesetSearchResults(StartAt+This.MAX_LISTINGS);This.updateAdsFromSearchResults();return false;}).appendTo($(This.PaginateContainer));}
$(document.createElement('label')).text(This.languageInfo[This.languageIndex].pageselectText).appendTo($(This.PaginateContainer));sel=document.createElement('select');$(sel).change(function(){var n=parseInt($('option:selected',this).text());n=(n-1)*This.MAX_LISTINGS;$(This.PaginateContainer).empty();$(This.ListingContainer).empty();This.paginateSearchResults(n);This.typesetSearchResults(n);return false;});for(var i=0;i<This.SearchResults[0].total;i+=This.MAX_LISTINGS){if(i!=StartAt){$(document.createElement('option')).text(((i/This.MAX_LISTINGS)+1).toString(10)).appendTo($(sel));}else{$(document.createElement('option')).attr('selected',true).text(((i/This.MAX_LISTINGS)+1).toString(10)).appendTo($(sel));}}
$(sel).appendTo($(This.PaginateContainer));$(This.PaginateContainer).appendTo($(This.ListingContainer));return false;}
JMCLite.prototype.updateAdsFromSearchResults=function(){var This=this;if(This.SearchResults&&This.SearchResults.length>1){var tmp1=new Array();$(This.SearchResults[1]).each(function(){if(this.klassid&&this.klass){tmp1.push({id:this.klassid,clang1:this.klass});}});var tmp2=This.uniqueKlassArray(tmp1);This.UpdateAdvertizements(tmp2);}}
JMCLite.prototype.typesetSearchResults=function(StartAt){var This=this;var i;if(!This.SearchResults||!This.SearchResults.length||!This.SearchResults[0].total)return false;for(i=StartAt;i<(StartAt+This.MAX_LISTINGS);i++){if(i>=This.SearchResults[0].total)break;This.TypesetYellowListing(This.SearchResults[1][i],This.BookName,null);}
return false;}
JMCLite.prototype.uniqueKlassArray=function(inp){var a=[];var l=inp.length;for(var i=0;i<l;i++){for(var j=i+1;j<l;j++){if(inp[i].id==inp[j].id)
j=++i;}
a.push(inp[i]);}
return a;}
