//*****************************************************************************
// Copyright 2007 Starscale Inc.

if(!ibi.YupNope){ibi.YupNope={};}
if(!ibi.YupNope.Templates){ibi.YupNope.Templates={};}
ibi.YupNope.Templates.deleteTmpl='<span class="icon" \
style="text-align: center" id="ThingDelete.%(Id)" title="Delete This Thing" \
onclick="deleteThing(%(Id));">\
<img src="/static/images/bin_closed.gif"/></span>\
<span id="ThingDeleteProgress.%(Id)" style="display: none;">\
<img src="/static/images/radar.gif"/></span>';ibi.YupNope.Templates.nopeButtonTmpl='<span xmlns="http://www.w3.org/1999/xhtml" class="icon" title="Change Your Vote To Yup" alt="Change Your Vote To Yup" onclick="javascript: showVoteChangeConfirm(%(Id), %(VoteStatus), Position.cumulativeOffset(this));"><img src="/static/images/cross.gif"/></span>';ibi.YupNope.Templates.yupButtonTmpl='<span xmlns="http://www.w3.org/1999/xhtml" class="icon" title="Change Your Vote To Nope" alt="Change Your Vote To Nope" onclick="javascript: showVoteChangeConfirm(%(Id), %(VoteStatus), Position.cumulativeOffset(this));"><img src="/static/images/tick.gif"/></span>';ibi.YupNope.Templates.bothButtonTmpl='<span title="Yup!" alt="Yup!" class="icon" onclick="javascript: %(yupAction)">\
<img src="/static/images/tick.gif"/></span> \
<span title="Nope" alt="Nope" class="icon" onclick="javscript: %(nopeAction)">\
<img src="/static/images/cross.gif"/></span>';ibi.YupNope.Templates.googleButtonTmpl='<a title="Google It" alt="Google It" class="imagehref" \
href="http://google.com/search?ie=utf-8&amp;q=%(urlContent)">\
<img src="/static/images/zoom.gif" style="padding-top: 2px; padding-left: 3px"/></a>';ibi.YupNope.Templates.linkButtonTmpl='<a title="Go" alt="Go" class="imagehref" href="%(linkContent)">\
<img src="/static/images/page_go.gif" style="position: relative; top: 2px;"/></a>';ibi.YupNope.ThingBuilder=Class.create({pro_enhanceThingData:function(thing){thing.CreationTime=(new Date(thing.CreationTime*1000)).toLocaleString();thing.LastVoteTime=(new Date(thing.LastVoteTime*1000)).toLocaleString();thing.urlContent=encodeURIComponent(thing.Content);thing.htmlContent=(thing.Content.escapeHTML());thing.Creator.Handle=thing.Creator.Handle.escapeHTML();thing.TotalVotes=thing.VotesYup+thing.VotesNope;thing.PercYup=(thing.VotesYup/thing.TotalVotes*100).toFixed(2);thing.PercNope=(thing.VotesNope/thing.TotalVotes*100).toFixed(2);},pro_buildDeleteButton:function(thing,memberId,successCallback){if(memberId&&thing.Deletable&&thing.Creator.Id==memberId){ibi.YupNope.DeleteCallback=successCallback;thing.deleteButton=ibi.Template.parse(ibi.YupNope.Templates.deleteTmpl,thing);}else{thing.deleteButton=" ";}},pro_buildVoteButtonsTmpl:function(thing,memberId){if(!memberId||thing['VoteStatus']==ibi.Phix.YupNope.Things.Const.VoteStatus.NoVote){thing.yupAction=this.pro_getButtonAction(memberId,thing.Id,1);thing.nopeAction=this.pro_getButtonAction(memberId,thing.Id,0);return ibi.YupNope.Templates.bothButtonTmpl;}
else if(thing.VoteStatus==ibi.Phix.YupNope.Things.Const.VoteStatus.Yup){return ibi.YupNope.Templates.yupButtonTmpl;}else{return ibi.YupNope.Templates.nopeButtonTmpl;}},pro_getButtonAction:function(memberId,id,vote){if(memberId){return'doVote('+id+","+vote+");";}
else{return'showGlobalError(\'You must be logged in to vote.\'); showLoginForm();'}},pro_buildGoogleButton:function(thing){thing.googleButton=ibi.Template.parse(ibi.YupNope.Templates.googleButtonTmpl,thing);},pro_buildLinkButton:function(thing){var regex=/((?:([hH][tT][tT][pP][sS]?:\/\/)(?:(?:[A-Za-z0-9\-\_\.\!\~\*\'\(\);:&=\+\$,]|%[A-Fa-f0-9]{2})*@)?((?:(?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]|[a-zA-Z0-9])\.)*(?:[a-zA-Z][a-zA-Z\-]*[a-zA-Z]|[a-zA-Z])\.?|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?::(\d{1,5})?)?)|((?:(?:(?:[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]|[a-zA-Z0-9])\.)+(?:[a-zA-Z][a-zA-Z\-]*[a-zA-Z]|[a-zA-Z])\.?|(?:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(?::(\d{1,5})?)?))(\/(?:[A-Za-z0-9\-\_\.\!\~\*\'\(\):@&=\+\$,]|%[A-Fa-f0-9]{2})*(?:;(?:[A-Za-z0-9\-\_\.\!\~\*\'\(\):@&=\+\$,]|%[A-Fa-f0-9]{2})*)*(?:\/(?:[A-Za-z0-9\-\_\.\!\~\*\'\(\):@&=\+\$,]|%[A-Fa-f0-9]{2})*(?:;(?:[A-Za-z0-9\-\_\.\!\~\*\'\(\):@&=\+\$,]|%[A-Fa-f0-9]{2})*)*)*)?(?:\?((?:[A-Za-z0-9\-\_\.\!\~\*\'\(\);\/\?\:@&=\+\$,]|%[A-Fa-f0-9]{2})*))?(?:#((?:[;\/\x3f:@&=\+\$,A-Za-z0-9\-\_\.\!\~\*\'\(\)]|%[A-Fa-f0-9]{2})*))?)/;var result=thing.Content.match(regex);if(result){thing.linkContent="";if(!result[2]){thing.linkContent+="http://";}
thing.linkContent+=result[1];thing.linkButton=ibi.Template.parse(ibi.YupNope.Templates.linkButtonTmpl,thing);}else{thing.linkButton='';}}});
