/* Copyright 2009 Wondermill Webworks Inc. */var Ask500;if(typeof Ask500=='undefined'){Ask500={}}Object.extend(Ask500,{Constants:{CookieName:'ASKTOOL',LoginURL:'/users/login',BootFrom:'boot__',Mu:{Root:'muObj',Key:'muKey',Value:'muValue',Stop:'muStop'},DOM:{GeneratedIDPrefix:'lambda__'}},Globals:{DOM:{GeneratedIDSufix:0}},$_:function(element){if(element&&typeof element.down==='function'){return true}return false},readCookie:function(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length)}if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length)}}return null},createCookie:function(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString()}else var expires="";document.cookie=name+"="+value+expires+"; path=/"},eraseCookie:function(name){Ask500.createCookie(name,"",-1)},decodeJSON:function(json_str,supress_status_check){var eval_failed=false;var json;try{json=json_str.evalJSON()}catch(e){eval_failed=true}if(!eval_failed){if(supress_status_check||(typeof json.status!='undefined'&&typeof json.status.code!='undefined')){return json}}},decodeEmbeddedJSON:function(element,supress_status_check){var json_str=Ask500.collectCDATAFromElement(element);if(json_str.startsWith('<!--')){json_str=json_str.substr(4,json_str.length-7).strip()}return Ask500.decodeJSON(Ask500.Base64.decode(json_str),supress_status_check)},decodeEmbeddedJSONFast:function(element,supress_status_check){var json_str=Ask500.collectCDATAFromElement(element);if(json_str.startsWith('<!--')){json_str=json_str.substr(4,json_str.length-7).strip()}return Ask500.decodeJSON(json_str,supress_status_check)},getDummyNode:function(){var dummy=$("dummy_node");if(dummy){return dummy}dummy=$(document.createElement('div'));dummy.id="dummy_node";dummy.hide();document.body.appendChild(dummy);return dummy},getDummyTableNode:function(){var dummy=$("dummy_table_node");if(dummy){return dummy.down('tbody')}dummy=Ask500.getDummyNode().update('<table id="dummy_table_node"><tbody></tbody></table>').remove();document.body.appendChild(dummy);return dummy.down('tbody')},HTMLToDOM:function(html){if(typeof html=='string'&&html!=''){var dummy;var tr_regex=/^\s*(<!--\C*-->)*\s*<tr[ >]/i;if(tr_regex.exec(html)!==null){dummy=Ask500.getDummyTableNode();dummy.update(html);return dummy.down('tr').up().immediateDescendants().reduce()}else{dummy=Ask500.getDummyNode();dummy.update(html);return dummy.immediateDescendants().reduce()}}},timeAgo:function(s_ago){var rounded=s_ago;var human_ago='';if(rounded<=1){human_ago='1 sec ago';return human_ago}if(rounded<60){human_ago=rounded+' sec ago';return human_ago}var m_ago=s_ago/60;rounded=Math.round(m_ago);if(rounded<=1){human_ago='1 min ago';return human_ago}if(rounded<60){human_ago=rounded+' min ago';return human_ago}var h_ago=m_ago/60;rounded=Math.round(h_ago);if(rounded<=1){human_ago='1 hour ago';return human_ago}if(rounded<24){human_ago=rounded+' hours ago';return human_ago}var d_ago=h_ago/24;rounded=Math.round(d_ago);if(rounded<=1){human_ago='1 day ago';return human_ago}if(rounded<365){human_ago=rounded+' days ago';return human_ago}var y_ago=d_ago/365;rounded=Math.round(y_ago);if(rounded<=1){human_ago='1 year ago';return human_ago}human_ago=rounded+' years ago';return human_ago},loggedIn:function(){return false},collectCDATAFromElement:function(element,deep){if(typeof element!='undefined'){var node=element.firstChild;var content='';while(typeof node!='undefined'&&node){if(node.nodeType==3||node.nodeType==8){content+=node.data;node=node.nextSibling}else if(deep){if(node.nodeType==1){content+=Ask500.collectCDATAFromElement(node,true)}node=node.nextSibling}else{node=false}}return content}},ping:function(){new Ajax.Request('/main_page_campaigns/ping',{onComplete:Ask500.pingCallback})},pingCallback:function(){setTimeout(Ask500.ping,180000)},muFormatParse:function(root){var obj=null;if(Ask500.$_(root)){var mu=Ask500.Constants.Mu;if(root.hasClassName(mu.Stop)){return obj}var all_elements=root.getElementsBySelector('.'+mu.Value+',.'+mu.Key);var root_values=[];var root_keys=[];for(var i=0;i<all_elements.length;i++){var key=all_elements[i].up('.'+mu.Key);var value=all_elements[i].up('.'+mu.Value);if((!Ask500.$_(key)||!key.descendantOf(root))&&(!Ask500.$_(value)||!value.descendantOf(root))){if(all_elements[i].hasClassName(mu.Value)){root_values.push(all_elements[i])}else if(all_elements[i].hasClassName(mu.Key)){root_keys.push(all_elements[i])}}}if(root_keys.length>0&&root_values.length==0){obj={};for(var i=0;i<root_keys.length;i++){var key=Ask500.muReadText(root_keys[i]);if(typeof key=='string'&&key!==''){obj[key]=Ask500.muFormatParse(root_keys[i])}}}else if(root_keys.length==0&&root_values.length>0){obj=[];for(var i=0;i<root_values.length;i++){var value=Ask500.muFormatParse(root_values[i]);obj.push(value)}}else if(root_values.length==0&&root_keys.length==0){obj=Ask500.muReadText(root)}if(obj&&typeof obj=='object'&&typeof obj.push=='function'){return obj.reduce()}return obj}return obj},muReadText:function(element){var str=Ask500.collectCDATAFromElement(element).strip();if(str.substr(0,4)==='<!--'&&str.substr(-3)==='-->'){str=str.substr(4,-3)}return str},callbackBind:function(func,start_callback,finish_callback){if(typeof func=='function'){if(typeof start_callback=='function'&&typeof finish_callback=='function'){return function(){start_callback.apply(this,arguments);func.apply(this,arguments);finish_callback.apply(this,arguments)}}else if(typeof start_callback=='function'){return function(){start_callback.apply(this,arguments);func.apply(this,arguments)}}else if(typeof finish_callback=='function'){return function(){func.apply(this,arguments);finish_callback.apply(this,arguments)}}return func}},yield:function(func){window.setTimeout(func,1)},benchmark:function(callback){var date=new Date();var start_time=date.getTime();var results=callback();date=new Date();var stop_time=date.getTime();Ask500.log(stop_time-start_time);return results},log:function(msg){if(typeof console!='undefined'&&typeof console.log=='function'){console.log(msg)}else{alert(msg)}},insertAfter:function(element,neighbor){var next=neighbor.next();if(Ask500.$_(next)){neighbor.parentNode.insertBefore(element,next)}else{neighbor.parentNode.appendChild(element)}},generateDOMID:function(){var dom_id;do{dom_id=Ask500.Constants.DOM.GeneratedIDPrefix+Ask500.Globals.DOM.GeneratedIDSufix;Ask500.Globals.DOM.GeneratedIDSufix++}while(Ask500.$_($(dom_id)));return dom_id},currentFragment:function(){var location=window.location.toString();var hash_pos=location.lastIndexOf('#');if(hash_pos!=-1){return location.substr(hash_pos+1)}},currentLocation:function(exclude_fragment){var location=window.location.toString();if(exclude_fragment){var fragment=Ask500.currentFragment();if(fragment){return location.substr(0,location.length-(fragment.length+1))}}return location}});if(typeof Ask500.EventHandler=='undefined'){Ask500.EventHandler=Class.create();Ask500.EventHandler.prototype={initialize:function(element,event_type,callback){var been_registered=false;this.register=function(){if(been_registered==false){Event.observe(element,event_type,callback);been_registered=true}return this};this.clear=function(){if(been_registered==true){Event.stopObserving(element,event_type,callback);been_registered=false}return this};this.fire=function(){if(been_registered==true){return callback(null)}};this.element=function(){return element};element=$(element);if(typeof element=='undefined'){throw Ask500.EventHandler.Exceptions.BadElement}}};Object.extend(Ask500.EventHandler,{Exceptions:{BadElement:{type:"Ask500.EventHandler.Exceptions.BadElement"}}})}if(typeof Ask500.Base64=='undefined'){Object.extend(Ask500,{Base64:{_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=Ask500.Base64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3)){enc4=64}output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4)}return output},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2)}if(enc4!=64){output=output+String.fromCharCode(chr3)}}output=Ask500.Base64._utf8_decode(output);return output},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c)}else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128)}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128)}}return utftext},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++}else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}return string}}})}Event.observe(window,'load',function(){var boot_from=$(Ask500.Constants.BootFrom);if(typeof boot_from!='undefined'&&boot_from){var json=Ask500.decodeEmbeddedJSON(boot_from);if(typeof json!='undefiend'){if(json.logged_in){Ask500.loggedIn=function(){return true}}if(json.next_ping){var now=new Date();var ping_delay=(json.next_ping*1000)-now.getTime();if(ping_delay<=0||ping_delay>180000){ping_delay=180000}window.setTimeout(Ask500.ping,ping_delay)}}}});var Ask500;if(typeof Ask500.LoginOverlay=='undefined'){Ask500.LoginOverlay=Class.create();Ask500.LoginOverlay.prototype={initialize:function(){var that=this;var overlay;var action;var event_handler;function closeEvent(event){Event.stop(event);overlay.remove()};this.display=function(for_element,for_action){if(overlay.up()){overlay.remove()}action.update(for_action);var parent_span=for_element.up('span');var insert_before;if(parent_span){insert_before=parent_span.next();if(insert_before){parent_span.up().insertBefore(overlay,insert_before)}else{parent_span.up().appendChild(overlay)}}else{insert_before=for_element.next();if(insert_before){for_element.up().insertBefore(overlay,insert_before)}else{for_element.up().appendChild(overlay)}}return overlay};this.getElement=function(){return overlay};overlay=Ask500.HTMLToDOM('<div class="login_overlay_container" style="position: relative"><div class="login_overlay"><a class="close_overlay" href="#"><img src="/img/general/login_overlay_close.png" alt="Close Overlay" title="Close Overlay"></a>To <span>Add 1 to</span> questions you first need to <a href="/users/login">login</a>. Don’t have an account? <a href="/signup">Sign up now</a></div></div>');action=overlay.down('span');event_handler=new Ask500.EventHandler(overlay.down('a.close_overlay'),'click',closeEvent);event_handler.register();overlay.remove()}};Object.extend(Ask500.LoginOverlay,{GlobalInstance:null})}Event.observe(window,'load',function(){if(Ask500.LoginOverlay.GlobalInstance===null){Ask500.LoginOverlay.GlobalInstance=new Ask500.LoginOverlay()}});var Ask500;if(typeof Ask500.QuestionOptionManager=='undefined'){Ask500.QuestionOptionManager=Class.create();Ask500.QuestionOptionManager.prototype={initialize:function(){var that=this;var overlay;var Constants=Ask500.QuestionOptionManager.Constants;var abuse_checkbox;var email_commented_on_checkbox;var options;var loading=true;var loading_overlay;var options_overlay;var options_dom;var last_id=0;function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200){return true}}catch(e){}return false};function elementToId(element){if(typeof element!='undefined'&&typeof element.hasClassName=='function'){if(element.hasClassName(Constants.DOM.OptionsLinkClass)){return Ask500.muFormatParse(element)}else{return Ask500.muFormatParse(element.up('.'+Constants.DOM.OptionsLinkClass))}}};function loadingStart(id){loading=id;loading_overlay.show();options_overlay.hide()};function loadingFinished(){loading=false;loading_overlay.hide();options_overlay.show()};function getOptions(id){new Ajax.Request('/campaigns/get_options',{parameters:{'id':id},onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)&&loading==this.id){last_id=this.id;options=json;delete options.status;var has_options=false;if(typeof options.show_on_profile=='undefined'){options_dom.show_on_profile.li.hide()}else{if(options.show_on_profile!==true){options_dom.show_on_profile.checkbox.checked=false}else{options_dom.show_on_profile.checkbox.checked=true}has_options=true;options_dom.show_on_profile.li.show()}if(typeof options.abuse_report=='undefined'){options_dom.inappropriate.li.hide()}else{if(options.abuse_report!==true){options_dom.inappropriate.checkbox.checked=false}else{options_dom.inappropriate.checkbox.checked=true}has_options=true;options_dom.inappropriate.li.show()}if(typeof options.notifications=='undefined'){options_dom.notifications.container.hide()}else{var has_notifications=false;if(typeof options.notifications.commented_on=='undefined'){options_dom.notifications.commented_on.li.hide()}else{if(options.notifications.commented_on!==true){options_dom.notifications.commented_on.checkbox.checked=false}else{options_dom.notifications.commented_on.checkbox.checked=true}has_options=true;has_notifications=true;options_dom.notifications.commented_on.li.show()}if(has_notifications){options_dom.notifications.container.show()}else{options_dom.notifications.container.hide()}}if(!has_options){options_dom.no_options.show()}else{options_dom.no_options.hide()}loadingFinished()}}.bind({'id':id})})};function setOptions(id){var params={'id':id};var should_send=false;if(typeof options.abuse_report!='undefined'){if(options_dom.inappropriate.checkbox.checked!=options.abuse_report){if(options_dom.inappropriate.checkbox.checked){params['abuse']='report'}else{params['abuse']='undo'}should_send=true}}if(typeof options.show_on_profile!='undefined'){if(options_dom.show_on_profile.checkbox.checked!=options.show_on_profile){if(options_dom.show_on_profile.checkbox.checked){params['profile']='true'}else{params['profile']='false'}should_send=true}}if(typeof options.notifications!='undefined'){if(typeof options.notifications.commented_on!='undefined'){if(options_dom.notifications.commented_on.checkbox.checked!=options.notifications.commented_on){if(options_dom.notifications.commented_on.checkbox.checked){params['notifications[commented_on]']='true'}else{params['notifications[commented_on]']='false'}should_send=true}}}if(should_send){new Ajax.Request('/campaigns/update_options',{parameters:params})}delete options};function clickHandler(event){var srcElement=Event.element(event);if(srcElement.hasClassName(Constants.DOM.OptionsLinkClass)){if(!Ask500.loggedIn()){Ask500.LoginOverlay.GlobalInstance.display(srcElement,'modify options for');Event.stop(event);return}var id=elementToId(srcElement);if(overlay.up()!==null){if(!loading){setOptions(last_id)}overlay.remove()}loadingStart(id);if(srcElement.nextSibling){srcElement.parentNode.insertBefore(overlay,srcElement.nextSibling)}else{srcElement.parentNode.appendChild(overlay)}getOptions(id);Event.stop(event)}else if(srcElement.hasClassName(Constants.DOM.DoneLinkClass)){if(!loading){setOptions(last_id)}overlay.remove();Event.stop(event)}};overlay=$(Ask500.HTMLToDOM(Ask500.QuestionOptionManager.Templates.overlay.evaluate()));options_dom={inappropriate:{li:$('inappropriate_li'),checkbox:$('inappropriate')},show_on_profile:{li:$('showonprofile_li'),checkbox:$('showonprofile')},notifications:{container:$('notification_options'),commented_on:{li:$('email_commented_on_li'),checkbox:$('email_commented_on')}},no_options:$('no_options')};loading_overlay=overlay.down('.'+Constants.DOM.OverlayLoadingClass);options_overlay=overlay.down('.'+Constants.DOM.OverlayOptionsClass);overlay.remove();Event.observe(document.body,'click',clickHandler)}};Object.extend(Ask500.QuestionOptionManager,{Constants:{DOM:{OptionsLinkClass:'moreoptions',OverlayClass:'moreoptions_overlay_container',DoneLinkClass:'moreoptions_done',OverlayLoadingClass:'moreoptions_overlay_loading',OverlayOptionsClass:'moreoptions_overlay_options'}},Templates:{},GlobalInstance:false});Event.observe(window,'load',function(){Ask500.QuestionOptionManager.GlobalInstance=new Ask500.QuestionOptionManager()})}var Ask500;if(typeof Ask500.CommentManager=='undefined'){Ask500.CommentManager=Class.create();Ask500.CommentManager.prototype={initialize:function(container,counter,campaign,just_count){var that=this;container=$(container);counter=$(counter);var campaign_id=false;var update_in_progress=false;function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200&&typeof json.comments!='undefined'){return true}}catch(e){}return false};function isValidFlagReply(json){try{if(typeof json!='undefined'&&json.status.code==200){return true}}catch(e){}return false};function isFloodReply(json){try{if(typeof json!='undefined'&&json.status.code==503&&typeof json.flood_interval!='undefined'){return true}}catch(e){}return false};function replyForElement(element){if(typeof element!='undefined'){return replyForComment(findComment(element))}return element};function editForElement(element){if(typeof element!='undefined'){return editForComment(findComment(element))}return element};function replyForComment(comment){if(typeof comment!='undefined'&&comment.hasClassName('comment')){return comment.down('.comment_reply')}return comment};function editForComment(comment){if(typeof comment!='undefined'&&comment.hasClassName('comment')){var edit=comment.down('.comment_edit');return edit}return comment};function buildEditForComment(comment){if(typeof comment!='undefined'&&comment.hasClassName('comment')){var edit=editForComment(comment);if(typeof edit=='undefined'){var reply=replyForComment(comment);edit=$(reply.cloneNode(true));edit.removeClassName('comment_reply');edit.addClassName('comment_edit');edit.hide();reply.up().insertBefore(edit,reply);var button=edit.down('input[type=submit]');var cancel=edit.down('a.comment_reply_cancel');if(typeof button!='undefined'){button.removeClassName('comment_reply_submit');button.addClassName('comment_edit_submit');button.value='Submit Edit'}if(typeof cancel!='undefined'){cancel.removeClassName('comment_reply_cancel');cancel.addClassName('comment_edit_cancel')}}return edit}};function commentToId(comment){if(typeof comment!='undefined'&&comment.hasClassName('comment')){return comment.id.substr(comment.id.lastIndexOf('_')+1)}return comment};function commentToContent(comment){if(typeof comment!='undefined'&&comment.hasClassName('comment')){var body=comment.down('.comment_body');if(typeof body!='undefined'){var children=body.childElements();var content='';for(var i=0;i<children.length;i++){if(children[i].hasClassName('metadata')){break}else{content+=Ask500.collectCDATAFromElement(children[i],true)+'\n\n'}}return content.strip()}}};function findComment(element){element=$(element);if(typeof element!='undefined'){return element.up('.comment')}return element};function postComment(commentContent,replyTo){var params={c:campaign_id,comment:commentContent};if(typeof replyTo!='undefined'){params.r=replyTo}new Ajax.Request('/comments/post',{parameters:params,onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)){container.update(json.comments.list);if(counter){counter.update(json.comments.count)}}else if(isFloodReply(json)){alert("Sorry, you triggered our flood prevention.  Please wait "+json.flood_interval+" seconds between comments.")}}})};function deleteComment(comment_id){var params={c:comment_id};new Ajax.Request('/comments/delete',{parameters:params,onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)){container.update(json.comments.list);if(counter){counter.update(json.comments.count)}}}})};function editComment(comment_id,comment_content){var params={c:comment_id,comment:comment_content};new Ajax.Request('/comments/edit',{parameters:params,onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)){container.update(json.comments.list);if(counter){counter.update(json.comments.count)}}}})};function updateComments(){var on_complete;var params={};var extra_args=arguments.length-updateComments.length;if(extra_args>0){on_complete=arguments[arguments.length-1]}if(just_count){params['just_count']=1}if(campaign_id!==false){new Ajax.Request('/comments/view/'+campaign_id,{method:'get',parameters:params,onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)){if(!just_count){container.update(json.comments.list)}if(counter){counter.update(json.comments.count)}}if(typeof on_complete=='function'){on_complete()}},onComplete:on_complete})}else{if(typeof on_complete=='function'){on_complete()}}};function undoVote(comment,vote){var backup=arrow_selected(comment);arrow(comment,false);new Ajax.Request('/comments/undo_vote',{parameters:{id:commentToId(comment)},onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidFlagReply(json)){var link=comment.down('.comment_points');if(typeof comment!='undefined'){var point_str='point';if(json.vote_score!=1){point_str+='s'}link.update('['+json.vote_score+' '+point_str+']')}}else{arrow(comment,backup)}}})};function vote(comment,vote){var backup=arrow_selected(comment);arrow(comment,vote);new Ajax.Request('/comments/vote',{parameters:{id:commentToId(comment),vote:vote},onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(isValidFlagReply(json)){var link=comment.down('.comment_points');if(typeof comment!='undefined'){var point_str='point';if(json.vote_score!=1){point_str+='s'}link.update('['+json.vote_score+' '+point_str+']')}}else{arrow(comment,backup)}}})};function arrow(comment,way){if(!way){var link=comment.down('.comment_voteup_selected');if(typeof link!='undefined'){link.removeClassName('comment_voteup_selected');link.addClassName('comment_voteup')}var link=comment.down('.comment_votedown_selected');if(typeof link!='undefined'){link.removeClassName('comment_votedown_selected');link.addClassName('comment_votedown')}}else{var link=comment.down('.comment_vote'+way);if(typeof link!='undefined'){link.removeClassName('comment_vote'+way);link.addClassName('comment_vote'+way+'_selected')}way=(way=='up')?'down':'up';var link=comment.down('.comment_vote'+way+'_selected');if(typeof link!='undefined'){link.removeClassName('comment_vote'+way+'_selected');link.addClassName('comment_vote'+way)}}};function arrow_selected(comment){var link=comment.down('.comment_voteup_selected');if(typeof link!='undefined'){return'up'}var link=comment.down('.comment_votedown_selected');if(typeof link!='undefined'){return'down'}return false};function replyToggle(srcElement){var reply=replyForElement(srcElement);if(typeof reply!='undefined'){var edit=editForElement(srcElement);if(typeof edit!='undefined'){edit.hide()}reply.toggle();if(reply.visible()){var field=reply.down('textarea');if(typeof field!='undefined'){field.focus()}}}};function clickHandler(event){var srcElement=Event.element(event);var comment;var commentContent;var action;var parameter;if(srcElement.hasClassName('comment_reply_link')||srcElement.hasClassName('comment_reply_cancel')){action='reply_toggle'}else if(srcElement.hasClassName('comment_reply_submit')){action='reply_submit'}else if(srcElement.hasClassName('comment_add_link')||srcElement.hasClassName('comment_add_cancel')||srcElement.hasClassName('comment_add_arrow')){action='add_toggle'}else if(srcElement.hasClassName('comment_add_submit')){action='add_submit'}else if(srcElement.hasClassName('comment_edit_link')){action='edit_toggle'}else if(srcElement.hasClassName('comment_delete_link')){action='delete_link'}else if(srcElement.hasClassName('comment_edit_submit')){action='edit_submit'}else if(srcElement.hasClassName('comment_edit_cancel')){action='edit_cancel'}else if(srcElement.hasClassName('show_comment_link')){action='show_comment'}else if(srcElement.hasClassName('comment_voteup')){action='vote';parameter='up'}else if(srcElement.hasClassName('comment_voteup_selected')){action='undo_vote';parameter='up'}else if(srcElement.hasClassName('comment_votedown')){action='vote';parameter='down'}else if(srcElement.hasClassName('comment_votedown_selected')){action='undo_vote';parameter='down'}else{return}if(action!='show_comment'&&action!='undo_vote'&&action!='vote'&&campaign_id==false){return}if(action!='show_comment'&&!Ask500.loggedIn()){Ask500.LoginOverlay.GlobalInstance.display(srcElement,'comment on');Event.stop(event);return}if(action=='reply_toggle'){replyToggle(srcElement);Event.stop(event)}else if(action=='reply_submit'){comment=findComment(srcElement);if(typeof comment!='undefined'){var commentContent=replyForElement(srcElement);if(typeof commentContent!='undefined'){commentContent=commentContent.down('textarea');if(typeof commentContent!='undefined'){postComment($F(commentContent),commentToId(comment))}}}Event.stop(event)}else if(action=='add_toggle'){var reply=srcElement.up('.add_comment');var arrow=reply.down('.comment_add_arrow');if(typeof reply!='undefined'){reply=reply.down('.comment_reply');if(typeof reply!='undefined'){reply.toggle();if(reply.visible()){var field=reply.down('textarea');if(typeof field!='undefined'){field.focus()}}if(typeof arrow!='undefined'){if(reply.visible()){arrow.setAttribute('src',arrow.readAttribute('src').sub('arrow_closed','arrow_open',1))}else{arrow.setAttribute('src',arrow.readAttribute('src').sub('arrow_open','arrow_closed',1))}}}}Event.stop(event)}else if(action=='add_submit'){comment=srcElement.up('.add_comment');if(typeof comment!='undefined'){commentContent=comment.down('textarea');if(typeof comment!='undefined'){postComment($F(commentContent))}}Event.stop(event)}else if(action=='edit_toggle'){comment=findComment(srcElement);var edit=buildEditForComment(comment);var reply=replyForComment(comment);if(typeof edit!='undefined'){reply.hide();edit.toggle();if(edit.visible()){var field=edit.down('textarea');if(typeof field!='undefined'){if($F(field)==''){field.value=commentToContent(comment)}field.focus()}}}Event.stop(event)}else if(action=='delete_link'){if(confirm("Are you sure you want to delete this comment?")){comment=findComment(srcElement);if(typeof comment!='undefined'){deleteComment(commentToId(comment))}}Event.stop(event)}else if(action=='edit_submit'){comment=findComment(srcElement);if(typeof comment!='undefined'){var commentContent=editForElement(srcElement);if(typeof commentContent!='undefined'){commentContent=commentContent.down('textarea');if(typeof commentContent!='undefined'){editComment(commentToId(comment),$F(commentContent))}}}Event.stop(event)}else if(action=='edit_cancel'){var content=commentToContent(findComment(srcElement));var edit=editForElement(srcElement);if(typeof edit!='undefined'){var field=edit.down('textarea');if(content!=$F(field)){if(confirm("Are you sure you want to leave the comment as is? (Any edits you have made will be lost.)")){edit.hide();field.value=content}}else{edit.hide()}}Event.stop(event)}else if(action=='show_comment'){comment=findComment(srcElement);var body=comment.down('.comment_body');var link=comment.down('.show_comment_link');if(typeof body!='undefined'){body.toggle();if(typeof link!='undefined'){if(body.visible()){link.update('Hide Comment')}else{link.update('Show Comment')}}}Event.stop(event)}else if(action=='undo_vote'){comment=findComment(srcElement);if(typeof comment!='undefined'){undoVote(comment,parameter)}Event.stop(event)}else if(action=='vote'){comment=findComment(srcElement);if(typeof comment!='undefined'){vote(comment,parameter)}Event.stop(event)}};this.releaseCampaign=function(){campaign_id=false};this.bindCampaign=function(campaign_to_bind){if(campaign_id!==false){this.releaseCampaign()}if(campaign_to_bind=='undefined'||campaign_to_bind==null||!campaign_to_bind){campaign_id=false}else if(typeof campaign_to_bind=='object'){campaign_id=campaign_to_bind.id}else{campaign_id=campaign_to_bind}};this.getContainer=function(){return container};this.setJustCount=function(new_val){if(new_val){just_count=true}else{just_count=false}};this.updateComments=updateComments;this.setJustCount(just_count);this.bindCampaign(campaign);Event.observe(container,'click',clickHandler);var location=window.location.toString();var hash_pos=location.lastIndexOf('#');if(hash_pos!=-1&&location.substr(-5)=='reply'){var anchor_fragment=location.substr(hash_pos+1);var anchor=$(anchor_fragment);if(typeof anchor!='undefined'){replyToggle(anchor)}}}};Object.extend(Ask500.CommentManager,{Constants:{DOM:{ReplyBaseId:'ask_comment_reply_'}}})}/* Copyright 2009 Wondermill Webworks Inc. */
Ask500.QuestionOptionManager.Templates.overlay = new Template('<span class=\"moreoptions_overlay_container\">&nbsp;\n\t<span class=\"moreoptions_overlay\">\n\t\t<span class=\"moreoptions_overlay_loading\" id=\"more_options_loading\" style=\"display: none;\">\n\t\t\t<img src=\"/img/general/loader_big.gif\" />\n\t\t\t<span>Loading...</span>\n\t\t</span>\n\t\t<span class=\"moreoptions_overlay_options\">\n\t\t\t<span id=\"question_options\">\n\t\t\t\t<ul>\n\t\t\t\t\t<li id=\"inappropriate_li\"><input id=\"inappropriate\" type=\"checkbox\" name=\"inappropriate\" value=\"inappropriate\" /> <label for=\"inappropriate\">Mark as inappropriate</label></li>\n\t\t\t\t\t<li id=\"showonprofile_li\"><input id=\"showonprofile\" type=\"checkbox\" name=\"showonprofile\" value=\"showonprofile\" /> <label for=\"showonprofile\">Show on Profile</label></li>\n\t\t\t\t</ul>\n\t\t\t</span>\n\t\t\t<span id=\"no_options\">\n\t\t\t\t<ul>\n\t\t\t\t\t<li>No options are available for this question.</li>\n\t\t\t\t</ul>\n\t\t\t</span>\n\t\t\t<span id=\"notification_options\">\n\t\t\t\t<ul>\n\t\t\t\t\t<li id=\"email_commented_on_li\"><input id=\"email_commented_on\" type=\"checkbox\" name=\"email_commented_on\" value=\"email_commented_on\" /> <label for=\"email_commented_on\">Email me comments</label></li>\n\t\t\t\t</ul>\n\t\t\t</span>\n\t\t\t<a href=\"#\" class=\"moreoptions_done\">Done</a>\n\t\t</span>\n\t</span>\n</span>');
