$(document).ready(function(){
if(iq_l){
health.init();
listingEdit.init();
listingTools.init();
imageGallery.init();
writeReview.init();
removePageHeader();
setEditThisListingLink();
}
});
function removePageHeader(){
$('#pageHeader').remove();
}
var listingEdit={
init:function(){
this.edit($('#listingName'));
this.edit($('#street-address'),$('#address'));
this.edit($('#area-address'),$('#address'));
},
addEditEvent:function(el,marker){
if(!marker)$(el).addClass('marker');
else $(marker).addClass('marker');
tooltip.showListingInfo(el);
},
removeEditEvent:function(el,marker){
if(!marker)$(el).removeClass('marker');
else $(marker).removeClass('marker');
tooltip.hide();
},
show:function(){
tooltip.hide();
popup.showListingEdit();
loadEditListingMap();
},
edit:function(el,marker){
el.mouseover(function(){
listingEdit.addEditEvent(this,marker);
});
el.mouseout(function(){
listingEdit.removeEditEvent(this,marker);
});
el.click(function(){
listingEdit.show();
});
}
};
var listingTools={
init:function(){
this.e=document.getElementById("listingTools");
var u=document.location.href.substr(ROOT.length-1).slice(0,-4);
this.appendBubble($bookmark,jL('bookmarkPage()'),function(){showBubble(this,$bookmarkDesc);});
this.appendBubble($viewAsContact,ROOT+'vcf'+u+'vcf',function(){showBubble(this,$viewAsContactDesc);});
this.appendBubble($viewAsText,ROOT+'txt'+u+'txt',function(){showBubble(this,$viewAsTextDesc);});
this.appendBubble($tellAFriend,jL('bubble.freeze()'),function(){sendMailBubble(this);});
this.appendBubble($helpImprove,jL('bubble.freeze()'),function(){improveBubble(this);});
this.appendItem(mydir.contains(iq_l)?$removeFromMyDirectory:$addToMyDirectory,jL('mydir.load('+iq_l+')'),"mydir"+iq_l,null,null);
this.appendItem($editListing,'javascript:listingEdit.show();',"editListing"+iq_l,null,null);
this.e.appendChild(ce('div','','clear'));
},
appendBubble:function(text,href,mOver){
this.appendItem(text,href,null,mOver,function(){bubble.hide();})
},
appendItem:function(text,href,id,mOver,mOut){
var a=ce('a',id,'',text),n=ce('li');
a.href=href;
a.onmouseover=mOver;
a.onmouseout=mOut;
n.appendChild(a);
this.e.appendChild(n);
}
};
function ratingReview(el){
bubble.title=$writeReview;
bubble.width=400;
bubble._loading=true;
bubble.show(el,null);
bubble.freeze();
bubble.formAction='rev.yolx';
var d=getFormValues(document.getElementById("ratingForm"));
var f=function(x){bubble.onSubmit(x);};
var a=new Ajax(bubble.formAction,f,null,d);
bubble.onSubmitSuccess=function(x){user.load(false,true);};
return false;
}
var health={
init:function(){
var r=new Ajax('chealth.yolx',health.load,null,"listingCode="+iq_l);
},
load:function(x){
var l=$('li',document.getElementById('communication'));
if(x){
health.data=[];
var hx=x.childNodes[2].childNodes;
for(var i=0;i<hx.length;i++){
var n=hx[i];
var h=["h30","h21","h20","h11","h10"];
var hlth=[];
hlth.push(n.getAttribute("type"));
hlth.push(n.getAttribute("id"));
var t=0;
for(var j=0;j<h.length;j++){
var hi=parseInt(n.getAttribute(h[j]));
hlth.push(hi);
t+=hi;
}
health.data.push(hlth);
if(l[i].lastChild.className!='healthBars'){
l[i].innerHTML+='<span class="healthBars"></span>';
}
if(hlth[0]!="na"){
l[i].id='line'+i;
l[i].onmouseover=function(){health.showBubble(this);$(this).addClass("marker");};
l[i].onmouseout=function(){health.hideBubble(this);$(this).removeClass("marker");};
l[i].lastChild.innerHTML=health.createBar('green',hlth[2],t)+health.createBar('yellow',hlth[3]+hlth[4],t)+health.createBar('red',hlth[5]+hlth[6],t);
}
}
}
},
createBar:function(color,health,totalHealth){
var w=totalHealth?health/totalHealth*30:0;
return'<span class="healthBar '+color+'" style="width:'+w+'px"></span>';
},
createBarInput:function(color,label,healthCode,healthValue,totalHealth,isTel){
var width=totalHealth?healthValue/totalHealth*80:0;
var votes=healthValue?'('+healthValue+')':'';
return'<tr><th align="right"><label for="h'+healthCode+'">'+label+'</label></th><td class="mid"><input type="radio" name="health" value="'+healthCode+'" id="h'+healthCode+'" onclick="window.health.selectInput(this);" /></td><td><span id="h'+healthCode+'bar" class="'+color+'" style="width:'+width+'px"></span> '+votes+'</td></tr>';
},
selectInput:function(el){
document.getElementById('healthComment').style.display="block";
bubble.freeze();
},
showBubble:function(el){
var h=health.data[parseInt(el.id.substr(4))];
var t=h[2]+h[3]+h[4]+h[5]+h[6];
var title=$('.value',el)[0].firstChild;
bubble.title=(title.nodeValue)?title.nodeValue:title.innerHTML;
var inputs;
var comment="";
switch(h[0]){
case't':
inputs=health.createBarInput('green',$numberOk,30,h[2],t,1)+health.createBarInput('yellow',$alwaysBusy,21,h[3],t,1)+health.createBarInput('yellow',$noAnswer,20,h[4],t,1)+health.createBarInput('red',$wrongNumber,11,h[5],t,1)+health.createBarInput('red',$notWorking,10,h[6],t,1);
if(PNCODES){
comment+='<select name="from"><option value="">'+$callingFrom+'</option>';
for(var i=0;i<PNCODES.length;i++){
comment+='<option value="'+PNCODES[i]+'">'+PNCODES[i]+'</option>';
}
comment+='</select>';
}
break;
case'e':
inputs=health.createBarInput('green',$emailOk,30,h[2],t)+health.createBarInput('red',$notWorking,10,h[6],t);
break;
case'w':
inputs=health.createBarInput('green',$websiteOk,30,h[2],t)+health.createBarInput('red',$notWorking,10,h[6],t);
break;
}
comment='<div id=\"healthComment\">'+comment+'<p>'+$commentOptional+'<input type="text" name="comment" maxlength="255" /></p></div>';
bubble.content='<div id="healthForm"><table cellpadding="0" cellspacing="0"><tbody>'+inputs+'</tbody></table>'+comment+'</div><input type="hidden" name="comm_id" id="comm_id" value="'+h[1]+'" />';
bubble.formAction='chealth.yolx';
bubble.onSubmitSuccess=function(x){health.load(x);};
bubble.width=300;
bubble.show(el,-25,true);
el.style.fontSize='1.3em';
},
hideBubble:function(el){
el.style.fontSize='1em';
bubble.hide();
}
};
function showBubble(el,message,width,form,action,title,xMod){
bubble.title=title?title:el.innerHTML;
bubble.width=(width)?width:300;
bubble.content=bubble.createContent(message,form);
bubble.formAction=action;
bubble.show(el,xMod);
}
function sendMailBubble(el){
var f=[new BubbleTxtBox($emailTo,"_emailTo"),new BubbleTxtBox($message,"_message",4,$sendMailDefaultText)];
showBubble(el,null,400,f,'listingmail.yolx');
}
function improveBubble(el){
var f=(user.id==0)?[new BubbleTxtBox($yourName,"name"),new BubbleTxtBox($yourEmail,"email")]:[];
f.push(new BubbleTxtBox($message,"_message",4));
showBubble(el,$helpImproveDesc,400,f,'helpimprove.yolx');
}
var imageGallery={
init:function(){
$('.gallery li').hover(function(){
var el=$(this);
var maxTitleLength=15;
var title=el.children('a').children().attr('alt');
if(title.length>maxTitleLength)
title=title.substring(0,maxTitleLength)+'...';
el.children('a').children().addClass('over');
el.append('<span>'+title+'</span>');
},function(){
$('.gallery li span').remove();
$('.gallery li img').removeClass('over');
});
}
};
var writeReview={
init:function(){
var btn=document.getElementById('ratingOk');
$('#commentTextBox').keyup(function(){
btn.className=btn.disabled=($(this).val()!=''&&$('#bubble_stars_rating').attr('class')!='r0')?"":"disabled";
});
$('p.rating').click(function(){
btn.className=btn.disabled=($('#commentTextBox').val()!=$('#commentTextBox').attr('title')&&$('#commentTextBox').val()!='')?"":"disabled";
$('#commentTextBox').focus();
});
}
};
function setEditThisListingLink(){
$.getJSON(ROOT+'user.json',function(x){
if(x.id!=0&&x.isOperator=='True'){
$("#editListing"+iq_l).attr('href',mainROOT+'CMS/listing_general.aspx?code='+iq_l+'&directory_id='+directory_id);
$("#editListing"+iq_l).attr("target","_blank");
}
});
}
function getListingStatistic(){
bubble._renderer.toggleOverlay(true);
$.getJSON(ROOT+'listingstatistics.json?code='+iq_l,function(x){
popup.showListingStats(x);
});
}