/* 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.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_'}}})}var Ask500;if(typeof Ask500.Flash=='undefined'){Ask500.Flash=Class.create();Ask500.Flash.prototype={initialize:function(message,insert_before,root,tag_name,tag_class){var flash_node;var events=[];this.addEvent=function(event){if(typeof event!='undefined'){event.register();events.push(event)}return event};this.removeEvents=function(){var old_events=events;events=[];old_events.invoke('clear');return old_events};this.remove=function(){if(typeof flash_node!='undefined'){this.removeEvents();return flash_node.remove()}};this.getElement=function(){return flash_node};if(typeof tag_name=='undefined'){tag_name=Ask500.Flash.Constants.DOM.TagName}if(typeof tag_class=='undefined'){tag_class=Ask500.Flash.Constants.DOM.ClassName}insert_before=$(insert_before);root=$(root);flash_node=$(document.createElement(tag_name));if(typeof flash_node!='undefined'){flash_node.addClassName(tag_class);flash_node.update(message);if(typeof insert_before!='undefined'){insert_before.parentNode.insertBefore(flash_node,insert_before)}else if(typeof root!='undefined'){root.appendChild(flash_node)}else{throw Ask500.Flash.Exceptions.BadInsertLocation}}else{throw Ask500.Flash.Exceptions.NodeCreateFailed}}};Object.extend(Ask500.Flash,{Constants:{DOM:{ClassName:'flash_alert',TagName:'div'}},Exceptions:{BadInsertLocation:{type:"Ask500.Flash.Exceptions.BadInsertLocation"},NodeCreateFailed:{type:"Ask500.Flash.Exceptions.NodeCreateFailed"}},LoginOverlay:Class.create()})}var Ask500;if(typeof Ask500.UpvoteManager=='undefined'){Ask500.UpvoteManager=Class.create();Ask500.UpvoteManager.prototype={initialize:function(){var that=this;var links;function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200&&typeof json.campaign!='undefined'){return true}}catch(e){}return false};function linkToId(link){if(typeof link!='undefined'&&link.hasClassName(Ask500.UpvoteManager.Constants.DOM.UpvoteLinkClass)){return link.id.substr(link.id.lastIndexOf('_')+1)}};function showOverlay(after_element,html,campaign_id){var overlay_element;if(!Ask500.$_(after_element)){return false}overlay_element=Ask500.HTMLToDOM('<div class="login_overlay_container"><div class="login_overlay"><a class="close_overlay" href="#close"><img src="/img/general/login_overlay_close.png" alt="Close Overlay" title="Close Overlay"></a>'+html+'</div></div>');new Ask500.EventHandler(overlay_element.down('a.close_overlay'),'click',overlayClickCallback.bindAsEventListener(this,campaign_id,overlay_element)).register();overlay_element.remove();Ask500.insertAfter(overlay_element,after_element)};function overlayClickCallback(event,campaign_id,overlay){overlay.remove();links[campaign_id].overlay=false;Event.stop(event)};function upvote(link,campaign_id){if(links[campaign_id].overlay){return}var points=link.up('.'+Ask500.UpvoteManager.Constants.DOM.PointsCellClass);if(!points){points=link.up('td.'+Ask500.UpvoteManager.Constants.DOM.PointsClass)}if(!points){return}points=points.down('.'+Ask500.UpvoteManager.Constants.DOM.PointsClass);if(!points){return}points.update(parseInt(Ask500.collectCDATAFromElement(points))+1);var image=link.down('img');var old_image_src=image.src;image.src=Ask500.UpvoteManager.Constants.DOM.AddedImageUrl;image.remove();link.parentNode.insertBefore(image,link);link.remove();new Ajax.Request('/campaigns/upvote',{parameters:{id:campaign_id},onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(!isValidReply(json)){points.update(parseInt(Ask500.collectCDATAFromElement(points))-1);var image_parent=image.parentNode;image.src=old_image_src;image.remove();image_parent.appendChild(link);link.appendChild(image);showOverlay(link,Ask500.UpvoteManager.Constants.Errors.UpvoteFailed,campaign_id);links[campaign_id].overlay=true}else{links[campaign_id].clear();links[campaign_id]=undefined}},onFailure:function(){showOverlay(image,Ask500.UpvoteManager.Constants.Errors.ConnectionFailed)}})};function clickCallback(event){var link=Event.element(event);if(link.tagName!='A'){link=link.up('a')}var id=linkToId(link);if(typeof id!='undefined'){upvote(link,id)}Event.stop(event)};this.searchForLinks=function(){var taints=new Hash();links.each(function(pair){if(typeof pair.value!='undefined'){taints[pair.key]=true}});$$('a.'+Ask500.UpvoteManager.Constants.DOM.UpvoteLinkClass).each(function(link){var id=linkToId(link);if(typeof links[id]=='undefined'){links[id]=new Ask500.EventHandler(link,'click',clickCallback);links[id].register()}else{if(links[id].element()!==link){links[id].clear();links[id]=new Ask500.EventHandler(link,'click',clickCallback);links[id].register()}taints[id]=false}});taints.each(function(pair){if(pair.value==true){links[pair.key].clear();links[pair.key]=undefined}})};links=new Hash();this.searchForLinks()}};Object.extend(Ask500.UpvoteManager,{Constants:{DOM:{UpvoteLinkClass:'upvote_link',PointsClass:'points',PointsCellClass:'points_cell',OverlayClass:'login_overlay_container',AddedImageUrl:'/img/external/added.gif'},Errors:{UpvoteFailed:"It looks like you (or someone else at your IP address) voted on this question already.  If you log in (you may need to create an account) you'll be able to see your previous votes as you navigate the site.",ConnectionFailed:"Sorry, we couldn't reach the Ask500 servers. Maybe your intenet is down?"}}});Event.observe(window,'load',function(){Object.extend(Ask500.UpvoteManager,{GlobalInstance:new Ask500.UpvoteManager()})})}var Ask500;if(typeof Ask500.VoteManager=='undefined'){Ask500.VoteManager=Class.create();Ask500.VoteManager.prototype={initialize:function(){var that=this;var questions;var Constants=Ask500.VoteManager.Constants;var voteCallback;function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200){return true}}catch(e){}return false};function optionToId(option){return parseInt(option.id.substr(Constants.DOM.OptionIDRoot.length))};function questionToId(question){var q=Ask500.decodeEmbeddedJSONFast(question.down('.'+Constants.DOM.JSONClass),true);return q.campaign_id};function idToQuestion(id){if(typeof questions[id]!='undefined'){return questions[id].question.element}};function clearVoteVisually(question,option_id){var question_element=idToQuestion(question.campaign_id);switch(question.type){case'yesno':case'text':question_element.getElementsBySelector('.'+Constants.DOM.OptionClass).each(function(option){if(optionToId(option)==option_id){option.removeClassName('chosen')}});break;case'image':question_element.getElementsBySelector('.'+Constants.DOM.OptionClass).each(function(option){if(optionToId(option)==option_id){option.removeClassName('chosen')}else{option.removeClassName('notchosen')}});break;case'range_good':case'range_agree':case'range_like':case'range_likely':case'range_star':question_element.getElementsBySelector('input[type=radio]').each(function(radio){if(radio.value==option_id){if(question.type!='range_star'){var label_span=question_element.down('label[for='+radio.id+'] span');label_span.up('th').removeClassName('chosen');label_span.remove()}else{var label=question_element.down('label[for='+radio.id+']');label.up('th').removeClassName('chosen')}}radio.removeAttribute("disabled");radio.checked=false});break}var action_votes=$('question_'+question.campaign_id+'_action_votecount');if(Ask500.$_(action_votes)){action_votes.update(parseInt(Ask500.collectCDATAFromElement(action_votes))-1)}var points_votes=$('question_'+question.campaign_id+'_points_votecount');if(Ask500.$_(points_votes)){points_votes.update(parseInt(Ask500.collectCDATAFromElement(points_votes))-1)}};function displayVoteVisually(question,option_id){var question_element=idToQuestion(question.campaign_id);switch(question.type){case'yesno':case'text':question_element.getElementsBySelector('.'+Constants.DOM.OptionClass).each(function(option){if(optionToId(option)==option_id){option.addClassName('chosen')}});break;case'image':question_element.getElementsBySelector('.'+Constants.DOM.OptionClass).each(function(option){if(optionToId(option)==option_id){option.addClassName('chosen')}else{option.addClassName('notchosen')}});break;case'range_good':case'range_agree':case'range_like':case'range_likely':case'range_star':question_element.getElementsBySelector('input[type=radio]').each(function(radio){if(radio.value==option_id){radio.removeAttribute("disabled");radio.checked=true;if(question.type!='range_star'){var label=question_element.down('label[for='+radio.id+']');label.innerHTML=label.innerHTML+'<span class="highlighted_option">'+label.innerHTML+'</span>';label.up('th').addClassName('chosen')}}else{radio.checked=false}});break}var action_votes=$('question_'+question.campaign_id+'_action_votecount');if(Ask500.$_(action_votes)){action_votes.update(parseInt(Ask500.collectCDATAFromElement(action_votes))+1)}var points_votes=$('question_'+question.campaign_id+'_points_votecount');if(Ask500.$_(points_votes)){points_votes.update(parseInt(Ask500.collectCDATAFromElement(points_votes))+1)}};function radioDisableCallback(question){var question_element=idToQuestion(question.campaign_id);question_element.getElementsBySelector('input[type=radio]').each(function(radio){if(!radio.checked){radio.setAttribute("disabled","disabled")}})};function showOverlay(after_element,html,binds){};function showQuestionOverlay(question,html){var q=idToQuestion(question.campaign_id);var overlay_at=q.down('a.question');if(!Ask500.$_(overlay_at)){overlay_at=q.down('span.question')}if(!Ask500.$_(overlay_at)){overlay_at=q.down('div.hint_voting')}if(question.overlay){question.overlay.clear();question.overlay.element().remove();question.overlay=false}var overlay_element;overlay_element=Ask500.HTMLToDOM('<div class="login_overlay_container"><div class="login_overlay"><a class="close_overlay" href="#close"><img src="/img/general/login_overlay_close.png" alt="Close Overlay" title="Close Overlay"></a>'+html+'</div></div>');question.overlay=new Ask500.EventHandler(overlay_element,'click',overlayClickCallback.bindAsEventListener(this,question)).register();overlay_element.remove();Ask500.insertAfter(overlay_element,overlay_at)};function overlayClickCallback(event,question){var srcElement=Event.element(event);var anchorTag;if(srcElement.tagName.toLowerCase()=='a'){anchorTag=srcElement}else{anchorTag=srcElement.up('a')}if(Ask500.$_(anchorTag)&&anchorTag.href.substr(anchorTag.href.length-6)=='#close'){anchorTag.up("."+Constants.DOM.OverlayClass).remove();question.overlay=false;Event.stop(event)}};function displayCantRecordVote(question){if(Ask500.loggedIn()){showQuestionOverlay(question,"We weren't able to record your vote because too many people have voted already from your location.")}else{showQuestionOverlay(question,'Sorry, we were unable to record your vote. This is probably because you\'ve already voted on this question. (An Ask500People account isn\'t required to vote.)')}};function clickCallback(event){var srcElement=Event.element(event);var tagName=srcElement.tagName.toLowerCase();var parentAnchor;var option_id;var question_element;var option;var question;if(tagName=='input'||(tagName=='a'&&!srcElement.hasClassName(Constants.DOM.QuestionClass))||(Ask500.$_(parentAnchor=srcElement.up('a'))&&!parentAnchor.hasClassName(Constants.DOM.QuestionClass))||(tagName=='td'&&srcElement.className==''&&Ask500.$_(parentAnchor=srcElement.down('a'))&&!parentAnchor.hasClassName(Constants.DOM.QuestionClass))){question_element=srcElement.up('.'+Constants.DOM.QuestionContainerClass);if(!question_element){question_element=srcElement.up('.'+Constants.DOM.QuestionContainerClass+'_results')}question=questions[questionToId(question_element)].question;if(tagName!='input'){if(srcElement.hasClassName(Constants.DOM.OptionClass)){option=srcElement}else{option=srcElement.up('td.'+Constants.DOM.OptionClass)}option_id=optionToId(option);Event.stop(event)}else{option_id=srcElement.getValue()}if(question.can_vote_on==0){if(question.can_change_vote==0&&!question.is_voting){if(question.voted_for!=option_id&&question.voted_for){showQuestionOverlay(question,"Sorry, its too late to change that vote.")}Event.stop(event);return}else if(question.voted_for==option_id||question.is_voting){if(question.is_voting){switch(question.type){case'range_good':case'range_agree':case'range_like':case'range_likely':case'range_star':question_element.getElementsBySelector('input[type=radio]').each(function(radio){if(radio.value==question.is_voting){radio.checked=true}else{radio.checked=false}});break}}Event.stop(event);return}else{question.is_voting=true;clearVoteVisually(question,question.voted_for);displayVoteVisually(question,option_id);new Ajax.Request(Constants.URL.ChangeVote,{parameters:{v:question.can_change_vote,o:option_id},onSuccess:function(response){question.is_voting=false;var json=Ask500.decodeJSON(response.responseText);if(!isValidReply(json)){clearVoteVisually(question,option_id);displayVoteVisually(question,question.voted_for);showQuestionOverlay(question,"We weren't able to change your vote. Votes can only be changed for a brief period after voting.")}else{question.voted_for=option_id;if(typeof voteCallback=='function'){voteCallback('change',option_id)}}},onFailure:function(){question.is_voting=false;clearVoteVisually(question,option_id);displayVoteVisually(question,question.voted_for);showQuestionOverlay(question,"We could not connect to Ask500People to change your vote. Either Ask500People is down or there is a problem with your internet connection.")}});var message_container=question_element.down('div.demographic_message_container');if(message_container){message_container.hide()}return}}displayVoteVisually(question,option_id);question.can_vote_on=0;question.is_voting=option_id;new Ajax.Request(Constants.URL.FastVote,{parameters:{i:question.campaign_id,o:option_id},onSuccess:function(response){question.is_voting=false;var json=Ask500.decodeJSON(response.responseText);if(!isValidReply(json)){clearVoteVisually(question,option_id);question.can_vote_on=1;displayCantRecordVote(question)}else{question.can_change_vote=json.visitor.id;question.voted_for=option_id;var change_disable=function(){question.can_change_vote=0;question.change_timer=false;switch(question.type){case'range_good':case'range_agree':case'range_like':case'range_likely':case'range_star':radioDisableCallback(question);break}};if(question.campaign_id==Constants.SpecialSponsor.Tolkien.question_id){change_disable();if(option_id==Constants.SpecialSponsor.Tolkien.option_id){var html=Constants.SpecialSponsor.Tolkien.html;question.element.update(html)}}else if(question.campaign_id==Constants.SpecialSponsor.Freedback.question_id){change_disable();if(option_id==Constants.SpecialSponsor.Freedback.option_id){var html=Constants.SpecialSponsor.Freedback.html;question.element.update(html)}}else{question.change_timer=setTimeout(change_disable,Constants.VoteChangeInterval)}if(json.demographic_similarity!==false){message_container=idToQuestion(question.campaign_id).down('div.demographic_message_container');if(message_container){message_container.down('span').update(json.demographic_similarity);message_container.show()}}if(typeof voteCallback=='function'){voteCallback('set',option_id)}}},onFailure:function(){question.is_voting=false;question.can_vote_on=1;clearVoteVisually(question,option_id);showQuestionOverlay(question,"We could not connect to Ask500People to record your vote. Either Ask500People is down or there is a problem with your internet connection.")}})}};this.searchForQuestions=function(){var taints=new Hash();questions.each(function(pair){if(typeof pair.value!='undefined'){taints[pair.key]=true}});$$('td.'+Constants.DOM.QuestionContainerClass+', div.'+Constants.DOM.QuestionContainerClass+'_results').each(function(question){if(question.hasClassName('yourquestions_empty')){return}if(question.hasClassName('nav_tags')){return}var json_store=question.firstDescendant();var question_object=Ask500.decodeEmbeddedJSONFast(json_store,true);question_object.element=question;var id=question_object.campaign_id;var options_table;if(question_object.type.substr(0,6)=='range_'){options_table=question.down('table.'+Constants.DOM.RangeAnswerClass)}else{options_table=question.down('table.'+Constants.DOM.AnswerClass)}if(typeof questions[id]=='undefined'){questions[id]=new Ask500.EventHandler(options_table,'click',clickCallback);questions[id].register();questions[id].question=question_object;questions[id].question.overlay=false;questions[id].question.is_voting=false;questions[id].question.change_timer=false}else{if(questions[id].question.element!==question){var old_question=questions[i].question;questions[id].clear();questions[id]=new Ask500.EventHandler(options_table,'click',clickCallback);questions[id].register();questions[id].question=old_question}taints[id]=false}});taints.each(function(pair){if(pair.value==true){questions[pair.key].clear();questions[pair.key]=undefined}})};this.setCallback=function(callback){voteCallback=callback};questions=new Hash();this.searchForQuestions()}};Object.extend(Ask500.VoteManager,{Constants:{DOM:{QuestionClass:'question',QuestionContainerClass:'question_container',OptionClass:'optionRoot',JSONClass:'jsonData',OptionIDRoot:'qlist_option_',OverlayClass:'login_overlay_container',RangeAnswerClass:'range_answers',AnswerClass:'answers_grid'},URL:{FastVote:'/campaigns/fastvote',ChangeVote:'/campaigns/change_vote'},CookieName:'vote_count',AnonymousVoteWarnThreshold:2,VoteChangeInterval:180000,SpecialSponsor:{Tolkien:{question_id:34088,option_id:129947,html:'<span style="color: #000;" class="question">Did you know J.R.R. Tolkien released a new book in 2007?</span><div style="text-align: center; margin-top: 13px;"><a style="color: #3366BB;" href="http://www.amazon.com/gp/product/0547086059?ie=UTF8&amp;tag=ask500-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0547086059"><img src="http://ecx.images-amazon.com/images/I/51R-A5DRbWL._SL160_AA115_.jpg" /></a><div style="margin-top: 13px; font-size: 120%; line-height: 1.5em;">Check out <a style="color: #3366BB;" href="http://www.amazon.com/gp/product/0547086059?ie=UTF8&amp;tag=ask500-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0547086059">The Children of Húrin</a><img src="http://www.assoc-amazon.com/e/ir?t=ask500-20&amp;l=as2&amp;o=1&amp;a=0547086059" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> available now on Amazon.com.</div></div><div class="demographic_message_container"></div>'},Freedback:{question_id:34089,option_id:129945,html:'<span class="question" style="color: #000;">Did you know you\'ll get less spam with a professional contact form than by posting your email address on your site?</span><a style="color: #3366BB; font-weight: bold; font-family: \'Lucida Grande\'; font-size: 130%; margin-top: 15px; margin-bottom: 15px; display: block;" href="http://www.freedback.com/ask">Get a free contact form now</a><span style="color: #888888; margin-bottom: 25px; font-size: 110%;">(No HTML knowledge required)</span><div class="demographic_message_container"></div>'}}}});Event.observe(window,'load',function(){Object.extend(Ask500.VoteManager,{GlobalInstance:new Ask500.VoteManager()})})}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.PeriodicalExecuter=='undefined'){Ask500.PeriodicalExecuter=Class.create();Ask500.PeriodicalExecuter.prototype={initialize:function(callback,period){var that=this;var interval;this.isStopped=function(){return(typeof interval=='undefined')};this.stop=function(){if(typeof interval!='undefined'){interval=clearInterval(interval)}return that};this.start=function(){if(typeof interval=='undefined'){interval=setInterval(callback,period*1000)}return that};this.changePeriod=function(new_period){period=new_period;if(!that.isStopped()){that.stop();that.start()}return that};this.getPeriod=function(){return period};this.start()}}}if(typeof Ask500.PeriodicAjaxCall=='undefined'){Ask500.PeriodicAjaxCall=Class.create();Ask500.PeriodicAjaxCall.prototype={initialize:function(beforeCall,period){var executer;var calling=false;var holding=false;var encapsulated_onComplete;function callComplete(response){if(!holding&&typeof encapsulated_onComplete=='function'){encapsulated_onComplete(response)}calling=false};function execute(){if(!calling&&!holding){calling=true;var parameters=beforeCall();if(typeof parameters!='object'||typeof parameters.url=='undefined'){calling=false;return}else{encapsulated_onComplete=false;if(typeof parameters.options!='undefined'){if(typeof parameters.options.onComplete=='function'){encapsulated_onComplete=parameters.options.onComplete}}else{parameters.options={}}}parameters.options.onComplete=callComplete;new Ajax.Request(parameters.url,parameters.options)}};this.hold=function(){if(!holding){holding=true}};this.release=function(){if(holding){holding=false}};this.isHolding=function(){return holding};this.stop=function(){if(typeof executer!='undefined'&&typeof executer.stop=='function'){executer.stop()}executer=null;encapsulated_onComplete=null};this.makeCallNow=function(){execute()};executer=new PeriodicalExecuter(execute,period)}}}var Ask500;if(typeof Ask500.ViewersManager=='undefined'){Ask500.ViewersManager=Class.create();Ask500.ViewersManager.prototype={initialize:function(ping_url,container,clients_count,guests_count,initial_state,short_ping){var that=this;var templates=Ask500.ViewersManager.Templates;var users=new Array();var guests=0;var executer;var first_load=true;function firstLoad(){if(first_load){first_load=false;var children=container.childElements();for(var i=0;i<children.length;i++){if(children[i].hasClassName("viewer_row")){children[i].remove()}}}};function findAndDisposeUser(user){for(var i=users.length-1;i>=0;i--){if(users[i].user_name==user.user_name){user=users[i];if(user.element.up()){user.element.remove()}delete user.element;users.splice(i,1);delete user;break}}};function removeLastViewerElement(preserve_row){var row=and_guests.previous(".viewer_row");if(typeof row!='undefined'){var children=row.childElements();var viewer=children.last();if(typeof viewer!='undefined'){viewer.remove()}if(children.length<=1&&row!=preserve_row){row.remove()}return viewer}};function updateState(json){firstLoad();var dummy_node=Ask500.getDummyNode();var taints=new Hash();var add_pool=new Array();var remove_pool=new Array();for(var i=0;i<users.length;i++){taints[users[i].user_name]=true};for(var i=0;i<json.users.length;i++){if(taints[json.users[i].user_name]===true){taints[json.users[i].user_name]=false}else{var user=json.users[i];if(user.display_as.length<=9){user.display_as_short=user.display_as}else{user.display_as_short=user.display_as.substr(0,8)+'...'}user.element=dummy_node.update(templates.user.evaluate(user)).down().remove();add_pool.push(user)}};taints.each(function(pair){if(pair.value===true){for(var i=users.length-1;i>=0;i--){if(users[i].user_name==pair.key){remove_pool.push(users[i])}}}});var length=add_pool.length;for(var i=0;i<length;i++){var old_user=null;if(remove_pool.length>0){var new_user=add_pool.shift();old_user=remove_pool.shift();old_user.element.up().replaceChild(new_user.element,old_user.element);findAndDisposeUser(old_user);users.push(new_user)}else{break}};length=remove_pool.length;if(length>0){for(var i=0;i<length;i++){var user=remove_pool.shift();var parent_node=user.element.up();findAndDisposeUser(user);var last_viewer=removeLastViewerElement(parent_node);if(typeof last_viewer!='undefined'){parent_node.appendChild(last_viewer)}}}var rows=container.getElementsByClassName('viewer_row');for(var i=0;i<rows.length;i++){if(rows[i].childElements().length==0){rows[i].remove()}}last_row=and_guests.previous('.viewer_row');if(typeof last_row!='undefined'){var last_row_free=4-last_row.childElements().length;length=add_pool.length;for(var i=0;i<length;i++){if(last_row_free>0){var user=add_pool.shift();last_row.appendChild(user.element);users.push(user);last_row_free--}else{break}}}length=add_pool.length;var row;for(var i=0;i<length;i++){var user=add_pool.shift();if(i%4==0){row=Ask500.HTMLToDOM('<div class="viewer_row"></div>');container.insertBefore(row,and_guests)}row.appendChild(user.element);users.push(user)}guests=json.clients-users.length;clients_count.update(json.clients);guests_count.update(guests)};function ping(on_complete){var params={};if(short_ping){params['short']=1}new Ajax.Request(ping_url,{asynchronous:true,method:'get',parameters:params,onSuccess:function(response){var json=Ask500.decodeJSON(response.responseText);if(typeof json!='undefined'){updateState(json)}},onComplete:on_complete})};function setShortPing(use_short_ping){short_ping=use_short_ping};this.ping=ping;this.setShortPing=setShortPing;if(typeof short_ping=='undefined'){setShortPing(false)}container=$(container);clients_count=$(clients_count);guests_count=$(guests_count);and_guests=container.down('.and_guests');window.setTimeout(function(){executer=new PeriodicalExecuter(function(){ping()},Ask500.ViewersManager.Constants.poll_interval)},Math.floor((Math.random()*10))*1000);if(typeof initial_state!='undefined'){updateState(initial_state)}}};Object.extend(Ask500.ViewersManager,{Templates:{},Constants:{poll_interval:60}})}var Ask500;if(typeof Ask500.HoverTab=='undefined'){Ask500.HoverTab=Class.create();Ask500.HoverTab.prototype={initialize:function(tab,overlay){var that=this;var enter_event;var exit_event;var mouse_is_over=false;function hoverStart(event){var element;if(typeof event!='undefined'){element=Event.element(event)}else{element=false}if(mouse_is_over==false&&enter_event.element()!=element){mouse_is_over=true;tab.addClassName("tab_hovered");tab.down().addClassName("tab_inner");overlay.show()}};function hoverStop(event){var element;if(typeof event!='undefined'){element=Event.element(event)}else{element=false}if(mouse_is_over==true&&exit_event.element()!=element){mouse_is_over=false;overlay.hide();tab.removeClassName("tab_hovered");tab.down().removeClassName("tab_inner")}};this.register=function(){if(typeof tab!='undefined'&&typeof overlay!='undefined'&&typeof enter_event=='undefined'&&typeof exit_event=='undefined'){enter_event=new Ask500.EventHandler(tab.up(),'mouseover',hoverStart);exit_event=new Ask500.EventHandler(tab.up(),'mouseout',hoverStop);enter_event.register();exit_event.register()}return that};this.unregister=function(){if(typeof tab!='undefined'&&typeof overlay!='undefined'&&typeof enter_event!='undefined'&&typeof exit_event!='undefined'){hoverStop();enter_event.clear();exit_event.clear();enter_event=undefined;exit_event=undefined}return that};tab=$(tab);overlay=$(overlay);this.register()}}}var Hideable=Class.create();Hideable.prototype={initialize:function(element){element=$(element);this.box=element;var id_pos=element.id.lastIndexOf('_');this.id=element.id.slice(id_pos+1);this.id_namespace=element.id.slice(0,id_pos+1);this.arrow=$(this.id_namespace+'arrow_'+this.id);this.arrow_link=$(this.id_namespace+'arrow_link_'+this.id);this.link=$(this.id_namespace+'link_'+this.id);this.checkbox=$(this.id_namespace+'checkbox_'+this.id);this.radiobutton=$(this.id_namespace+'radiobutton_'+this.id);this.label=$(this.id_namespace+'label_'+this.id);this.cancel=$(this.id_namespace+'cancel_'+this.id);if(this.arrow_link){Event.observe(this.arrow_link,'click',this.onClick.bindAsEventListener(this))}if(this.cancel){Event.observe(this.cancel,'click',this.onClick.bindAsEventListener(this))}if(this.link){Event.observe(this.link,'click',this.onClick.bindAsEventListener(this))}if(this.checkbox){Event.observe(this.checkbox,'click',this.onClick.bindAsEventListener(this))}if(this.radiobutton){Event.observe(this.radiobutton,'click',this.onClick.bindAsEventListener(this))}if(this.label){Event.observe(this.label,'click',function(event){var element=$(Event.element(event));if(element.tagName!='A'){if(this.checkbox&&this.checkbox.readAttribute('disabled')){Event.stop(event);return}if(this.radiobutton&&this.radiobutton.readAttribute('disabled')){Event.stop(event);return}this.onClick(event);Event.stop(event)}}.bindAsEventListener(this))}Hideable.Lists.all_hideables.push(this)},otherRadiobuttons:function(){if(this.radiobutton){var name=this.radiobutton.readAttribute('name');return $$('input[name="'+name+'"]')}return[]},onClick:function(event){if(this.box.visible()){var from='arrow_open';var to='arrow_closed';if(this.checkbox){this.checkbox.checked=false;this.checkbox.setAttribute('checked',false)}if(this.radiobutton){Event.stop(event);return}}else{var to='arrow_open';var from='arrow_closed';if(this.checkbox){this.checkbox.checked=true;this.checkbox.setAttribute('checked',true)}if(this.radiobutton){var buttons=this.otherRadiobuttons();buttons.each(function(item){if(item.checked){item.checked=false;item.setAttribute('checked',false)}var id=item.id.slice(this.id_namespace.length+'radiobutton_'.length);var element=$(this.id_namespace+id);if(element.visible()){element.hide();$(this.id_namespace+'arrow_'+id).setAttribute('src',this.arrow.readAttribute('src').sub('arrow_open','arrow_closed',1))}}.bind(this));this.radiobutton.checked=true;this.radiobutton.setAttribute('checked',true)}}this.arrow.setAttribute('src',this.arrow.readAttribute('src').sub(from,to,1));this.box.toggle();if(Event.element(event).readAttribute('type')!='radio'&&Event.element(event).readAttribute('type')!='checkbox'){Event.stop(event)}}};Object.extend(Hideable,{Lists:{all_hideables:[]}});addEvent(window,'DOMContentLoaded',function(){var hideable_elements=document.getElementsByClassName('hideable');hideable_elements.each(function(item){new Hideable(item)})});var Ask500;if(typeof Ask500.FavoriteManager=='undefined'){Ask500.FavoriteManager=Class.create();Ask500.FavoriteManager.prototype={initialize:function(){var that=this;var links;var constants=Ask500.FavoriteManager.Constants;function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200){return true}}catch(e){}return false};function linkToId(link){if(typeof link!='undefined'&&link.hasClassName(constants.DOM.FavoriteLinkClass)){return link.id.substr(link.id.lastIndexOf('_')+1)}};function showOverlay(after_element,html,campaign_id){var overlay_element;if(!Ask500.$_(after_element)){return false}if(Ask500.$_(links[campaign_id].overlay)){links[campaign_id].overlay.remove();links[campaign_id].overlay=false;links[campaign_id].overlay_event.clear()}overlay_element=Ask500.HTMLToDOM('<div class="login_overlay_container"><div class="login_overlay"><a class="close_overlay" href="#close"><img src="/img/general/login_overlay_close.png" alt="Close Overlay" title="Close Overlay"></a>'+html+'</div></div>');links[campaign_id].overlay=overlay_element;links[campaign_id].overlay_event=new Ask500.EventHandler(overlay_element.down('a.close_overlay'),'click',overlayClickCallback.bindAsEventListener(this,campaign_id)).register();overlay_element.remove();Ask500.insertAfter(overlay_element,after_element)};function overlayClickCallback(event,campaign_id){links[campaign_id].overlay.remove();links[campaign_id].overlay=false;links[campaign_id].overlay_event.clear();Event.stop(event)};function clickCallback(event){var link=Event.element(event);if(link.tagName.toLowerCase()!='a'){link=link.up('a')}var id=linkToId(link);Event.stop(event);if(!Ask500.loggedIn()){Ask500.LoginOverlay.GlobalInstance.display(links[id].link.element(),'mark a question as a favorite');return}var favored=false;if(typeof links[id]!='undefined'){if(links[id].star_image.src.substr(links[id].star_image.src.length-constants.DOM.ActiveStarSrc.length)==constants.DOM.ActiveStarSrc){favored=true}}var url='/campaigns/mark_favorite';if(favored){url='/campaigns/clear_favorite';links[id].star_image.src=constants.DOM.InactiveStarSrc}else{links[id].star_image.src=constants.DOM.ActiveStarSrc}var failureCallback=function(err){if(favored){links[id].star_image.src=constants.DOM.ActiveStarSrc}else{links[id].star_image.src=constants.DOM.InactiveStarSrc}showOverlay(links[id].link.element(),err,id)};new Ajax.Request(url,{parameters:{i:id},onSuccess:function(xhr){var json=Ask500.decodeJSON(xhr.responseText);if(!isValidReply(json)){failureCallback("An unknown error prevented us from marking this question as a favorite. Please try again.")}},onFailure:failureCallback.bind(that,"Sorry, we couldn't reach the Ask500 servers. Maybe your intenet is down?")})};this.searchForLinks=function(){var taints=new Hash();links.each(function(pair){if(typeof pair.value!='undefined'){taints[pair.key]=true}});$$('a.'+constants.DOM.FavoriteStarClass).each(function(link){var id=linkToId(link);if(typeof links[id]=='undefined'){links[id]={star:new Ask500.EventHandler(link,'click',clickCallback),link:new Ask500.EventHandler(constants.DOM.FavoritePrefix+'_'+id,'click',clickCallback),star_image:link.down('img'),overlay:false,overlay_event:false};links[id].star.register();links[id].link.register()}else{if(links[id].star.element()!==link){links[id].star.clear();links[id].link.clear();links[id]={star:new Ask500.EventHandler(link,'click',clickCallback),link:new Ask500.EventHandler(constants.DOM.FavoritePrefix+'_'+id,'click',clickCallback),star_image:link.down('img'),overlay:false,overlay_event:false};links[id].star.register();links[id].link.register()}taints[id]=false}});taints.each(function(pair){if(pair.value==true){links[pair.key].star.clear();links[pair.key].link.clear();links[pair.key]=undefined;if(Ask500.$_(links[pair.key].overlay)){links[pair.key].overlay.remove();links[pair.key].overlay=false;links[pair.key].overlay_event.clear()}}})};links=new Hash();this.searchForLinks()}};Object.extend(Ask500.FavoriteManager,{Constants:{DOM:{FavoriteLinkClass:'favorite_toggle',FavoriteStarClass:'favorite_star',FavoritePrefix:'favorite',InactiveStarSrc:'/img/general/star_inactive.gif',ActiveStarSrc:'/img/general/star.gif'},Errors:{}}});Event.observe(window,'load',function(){Object.extend(Ask500.FavoriteManager,{GlobalInstance:new Ask500.FavoriteManager()})})}var Ask500;if(typeof Ask500.ResultsManager=='undefined'){Ask500.ResultsManager={}}if(typeof Ask500.ResultsManager.Public=='undefined'){Ask500.ResultsManager.Public=Class.create();Ask500.ResultsManager.Public.prototype={initialize:function(){var that=this;var $_=Ask500.$_;var Constants=Ask500.ResultsManager.Public.Constants;var campaigns={upvoting:new Array(),upcoming:new Array(),previous:new Array(),running:false};var google_map;var map_pan=true;var dom_nodes=new Hash({map:$("map"),status:$("status"),vote_list:$("votes"),response_count:$("response_count"),response_info:$("response_info"),range_results:{main:$("range_results"),high:$("range_results_high"),low:$("range_results_low"),marker:$("range_results_marker")},voting:{overlay_overflow:$('vote_overlay_overflow'),overlay:$('vote_overlay'),frame:$('vote_frame'),cancel:$('vote_cancel'),tab:$('vote_tab'),fake_overlay:$('vote_fake_overlay'),fake_tab:$('vote_fake_tab')},results_tab:{country:$('results_by_country'),community:$('results_by_community')},results:$("results_sidebar"),overlay:$("map_overlay"),empty_overlay:$("empty_overlay"),overlay_background:$('countdown_background'),previous:$("previous_campaigns"),previous_ref:$("previous_campaigns"),upcoming:$("upcoming_campaigns"),title:$("page_title"),results_and_votes:$("results_and_votes"),missing_flash:$('missing_flash'),countdown:{text:$("countdown_text"),time:$("countdown_time"),responses:$("countdown_responses"),question:$("countdown_question")},tabs:{viewers:{tab:$('viewers'),control:$("viewers_tab"),loading:false,loaded:false},comments:{tab:$('comments'),control:$("comments_tab"),loading:false,loaded:false},upcoming:{tab:$('upcoming'),control:$("upcoming_tab"),loading:false,loaded:false},results:{tab:$('results'),control:$("results_tab"),loading:false,loaded:false}},demographic_tabs:{overview:{tab:$('demographic_overview_results'),control:$("demographic_overview"),loading:false,loaded:false},gender:{tab:$('demographic_gender_results'),control:$("demographic_gender"),loading:false,loaded:false},age:{tab:$('demographic_age_results'),control:$("demographic_age"),loading:false,loaded:false},income:{tab:$('demographic_income_results'),control:$("demographic_income"),loading:false,loaded:false},team:{tab:$('demographic_team_results'),control:$("demographic_team"),loading:false,loaded:false},education:{tab:$('demographic_education_results'),control:$("demographic_education"),loading:false,loaded:false},country:{tab:$('demographic_country_results'),control:$("demographic_country"),loading:false,loaded:false}},map_tab:$('map_tab'),demographic_tab:$('demographic_tab'),comments:{contents:$('comments_contents'),count:$('comments_count')},viewers:{clients:$('clients'),clients_guests:$('clients_guests')},tab_loading:$('tab_loading_panel')});var epoch=0;var ticks=0;var comments=false;var votes={count:0,deleted_count:0,recent:new Array(),pending:new Array(),others:new Array(),info_bubbled:false,early:false,waiting_for_early:false,early_on_map:false};var options=new Array();var threads={campaigns:false,votes:false,clock:false,map:false};var templates=Ask500.ResultsManager.Public.Templates;var tab_controller=false;var demographic_tabs=false;var rocket;var comment_flash;var viewers;var launching_campaign=false;var launch_supervisor;var vote_tab_open=false;var vote_tab_option_fx=new Array();var results_by_country=new Hash();var results_by_community=new Hash({independent:{community:'Independent',option_counts:{},option_percents:{},total_votes:0},community:{community:'Community',option_counts:{},option_percents:{},total_votes:0}});var results_by_country_even=false;var viewer_init_state;var init_done=false;var fake_vote={'voted_for':'fake','short_city':'Portland','country_name':'United States','country_code':'us','seconds_ago':300,'arrived_tick':0};var ResultsTab={isVisible:function(){if(dom_nodes.tabs.viewers.loaded&&tab_controller!==false&&tab_controller.getValue()=='viewers'){return true}return false},cleanResults:function(){var campaign=campaigns.running;if(!campaign){return}if($_(dom_nodes.results_tab.country)){dom_nodes.results_tab.country.immediateDescendants().invoke('remove');dom_nodes.results_tab.country.appendChild(ResultsTab.renderToHeaderRow(campaign));results_by_country.each(function(pair){if(typeof pair.value!='undefined'){dom_nodes.results_tab.country.appendChild(ResultsTab.renderToCountryRow(campaign,pair.value,results_by_country_even));results_by_country_even=!results_by_country_even}})}if($_(dom_nodes.results_tab.community)){dom_nodes.results_tab.community.immediateDescendants().invoke('remove');dom_nodes.results_tab.community.appendChild(ResultsTab.renderToHeaderRow(campaign));var even=false;results_by_community.each(function(pair){if(typeof pair.value!='undefined'){for(var i=0;i<campaign.options.length;i++){var opt_id=campaign.options[i].id;if(typeof pair.value.option_counts[opt_id]=='undefined'){pair.value.option_counts[opt_id]=0;pair.value.option_percents[opt_id]=0}}dom_nodes.results_tab.community.appendChild(ResultsTab.renderToCommunityRow(campaign,pair.value,even));even=!even}})}},renderToCountryRow:function(campaign,row_details,even){if(even){even='even'}else{even=''}var row_html_parts={country_cell:templates.ResultsTab.Cells.country.evaluate({country:row_details.country,country_code:row_details.country_code.toLowerCase()}),total_votes_cell:templates.ResultsTab.Cells.total_votes.evaluate({count:row_details.total_votes}),option_vote_cells:'','even':even};for(var i=0;i<campaign.options.length;i++){var opt_class='';if(campaign.type=='yesno'){opt_class=campaign.options[i].media.toLowerCase()}else if(campaign.type.substr(0,6)=='range_'){opt_class='range'+(i+1)}else if(campaign.type=='text'){opt_class=String.fromCharCode('a'.charCodeAt(0)+i)}row_html_parts.option_vote_cells+=templates.ResultsTab.Cells.option_votes.evaluate({count:row_details.option_counts[campaign.options[i].id],percent:row_details.option_percents[campaign.options[i].id],'class':opt_class})}var row_html=templates.ResultsTab.Rows.country.evaluate(row_html_parts);row_details.elements={row:false,total_votes:false,option_counts:new Hash(),option_percents:new Hash()};row_details.elements.row=Ask500.HTMLToDOM(row_html);row_details.elements.total_votes=row_details.elements.row.down('.total_votes');var elements=row_details.elements.row.childElements();for(var i=2;i<elements.length;i++){row_details.elements.option_counts[campaign.options[i-2].id]=elements[i].down('.vote_count');row_details.elements.option_percents[campaign.options[i-2].id]=elements[i].down('.vote_percent')}return row_details.elements.row.remove()},renderToCommunityRow:function(campaign,row_details,even){if(even){even='even'}else{even=''}var row_html_parts={community_cell:templates.ResultsTab.Cells.community.evaluate({community:row_details.community}),total_votes_cell:templates.ResultsTab.Cells.total_votes.evaluate({count:row_details.total_votes}),option_vote_cells:'','even':even};for(var i=0;i<campaign.options.length;i++){var opt_class='';if(campaign.type=='yesno'){opt_class=campaign.options[i].media.toLowerCase()}else if(campaign.type.substr(0,6)=='range_'){opt_class='range'+(i+1)}else if(campaign.type=='text'){opt_class=String.fromCharCode('a'.charCodeAt(0)+i)}row_html_parts.option_vote_cells+=templates.ResultsTab.Cells.option_votes.evaluate({count:row_details.option_counts[campaign.options[i].id],percent:row_details.option_percents[campaign.options[i].id],'class':opt_class})}var row_html=templates.ResultsTab.Rows.community.evaluate(row_html_parts);row_details.elements={row:false,total_votes:false,option_counts:new Hash(),option_percents:new Hash()};row_details.elements.row=Ask500.HTMLToDOM(row_html);row_details.elements.total_votes=row_details.elements.row.down('.total_votes');var elements=row_details.elements.row.childElements();for(var i=2;i<elements.length;i++){row_details.elements.option_counts[campaign.options[i-2].id]=elements[i].down('.vote_count');row_details.elements.option_percents[campaign.options[i-2].id]=elements[i].down('.vote_percent')}return row_details.elements.row.remove()},renderToHeaderRow:function(campaign){var option_html={option_1:null,option_2:null,option_3:null,option_4:null,option_5:null};if($A(['image','range_star','yesno']).indexOf(campaign.type)!=-1){for(var i=0;i<campaign.options.length;i++){var opt_class='';var title='Image '+(i+1);if(campaign.type=='yesno'){opt_class=campaign.options[i].media.toLowerCase();title=campaign.options[i].media}else if(campaign.type=='range_star'){title=(i+1)+' Stars'}option_html['option_'+(i+1)]=templates.ResultsTab.Cells.header_image.evaluate({'class':opt_class,id:campaign.options[i].id,'title':title})}}else{for(var i=0;i<campaign.options.length;i++){var opt_class='range'+(i+1);var split_text=campaign.options[i].truncated_media;if(campaign.type=='text'){opt_class=String.fromCharCode('a'.charCodeAt(0)+i);var pos=split_text.indexOf('...');if(pos!=-1){split_text=split_text.substr(0,pos)+'<br />'+split_text.substr(pos)}}option_html['option_'+(i+1)]=templates.ResultsTab.Cells.header_text.evaluate({'class':opt_class,full_text:campaign.options[i].media,short_text:split_text})}}var row_html=templates.ResultsTab.Rows.header.evaluate(option_html);return Ask500.HTMLToDOM(row_html).remove()}};var View={updateRangeResults:function(){if(campaigns.running!=false&&$_(dom_nodes.range_results.marker)){var p_score=Campaign.calcPercentageScore(campaigns.running);if(typeof p_score=='undefined'){p_score=0}dom_nodes.range_results.marker.setStyle({'width':(Math.round(p_score*0.94)+1)+'px'})}},updateResponseCount:function(){if(campaigns.running!=false){if($_(dom_nodes.response_count)){dom_nodes.response_count.update(campaigns.running.response_count)}}},displayInfoBubble:function(vote){votes.info_bubbled=vote;vote.marker.openInfoWindowHtml(templates.Vote.info_bubble.evaluate({'option_id':vote.voted_for,'city':vote.city,'country_name':vote.country_name,'country_code':vote.country_code,'human_ago':Ask500.timeAgo(vote.seconds_ago+(ticks-vote.arrived_tick))}),{maxWidth:400})},updateOptionResults:function(option){var total=votes.recent.length+votes.others.length+votes.deleted_count;var percent=0;if(total!=0){percent=Math.round((option.votes/total)*100)}if($_(option.percent_element)){option.percent_element.update(percent)}if($_(option.graph_element)){option.graph_element.setStyle({width:percent+'%'})}},updateVotesTimeAgo:function(){if(ticks%3==0){if(votes.info_bubbled!=false){Vote.updateTimeAgo(votes.info_bubbled)}for(var i=0;i<votes.recent.length;i++){if(votes.recent[i]!=votes.info_bubbled){Vote.updateTimeAgo(votes.recent[i])}}}},updateAbuseAndUpvote:function(){try{Ask500.UpvoteManager.GlobalInstance.searchForLinks()}catch(e){}},openVoteTab:function(){dom_nodes.voting.fake_overlay.hide();dom_nodes.voting.overlay_overflow.show();dom_nodes.voting.overlay.morph('top: 0px;',{duration:0.5})},closeVoteTab:function(){dom_nodes.voting.overlay.morph('top: '+(18-dom_nodes.voting.overlay_overflow.getHeight())+'px;',{duration:0.5,afterFinish:function(){dom_nodes.voting.fake_overlay.show();dom_nodes.voting.overlay_overflow.hide()}})}};var Callbacks={infoBubbleClosed:function(){votes.info_bubbled=false},highlightTransition:function(pos){if(pos==1){return 1}return 0},highlightAfter:function(obj){obj.element.setStyle({backgroundColor:'#ffffff'})},switchComments:function(event){comments.releaseCampaign();if(campaigns.running){comments.bindCampaign(campaigns.running);comments.updateComments()}else{var next=campaigns.upcoming.first();if(typeof next!='undefined'){comments.bindCampaign(next);comments.updateComments()}}comment_flash.remove();delete comment_flash;Event.stop(event)},voteTabClick:function(event){if(!dom_nodes.voting.tab.hasClassName('vote_tab_inactive')&&!dom_nodes.voting.fake_tab.hasClassName('vote_tab_inactive')){if(vote_tab_open){View.closeVoteTab()}else{View.openVoteTab()}vote_tab_open=!vote_tab_open}Event.stop(event)},voteCancelClick:function(event){if(vote_tab_open){View.closeVoteTab()}vote_tab_open=false;Event.stop(event)},voteClick:function(event){var node=Event.element(event).up('td.code_answer');var form;if(typeof node!='undefined'){form=node.down('form')}else{node=Event.element(event).up('form');if(typeof node!='undefined'){form=node}else{node=Event.element(event);if(node.tagName.toLowerCase()!='label'){node=node.up('label')}form=$(node.readAttribute('for')).up('form')}}var option_id=form.id.substr(4);var visitor_id=form.firstDescendant().getValue();new Ajax.Request(Constants.Urls.submit_vote,{method:'get',parameters:{k:'users',v:visitor_id,o:option_id}});if(votes.early!==false&&votes.early.voted_for===null){votes.early.voted_for=option_id;window.setTimeout(function(){votes.early.arrived_tick=ticks;votes.pending.push(votes.early);votes.count++;votes.early_on_map=true},2000);votes.waiting_for_early=true;votes.early_on_map=false}Callbacks.voteCancelClick(event);dom_nodes.voting.tab.addClassName('vote_tab_inactive');dom_nodes.voting.fake_tab.addClassName('vote_tab_inactive')}};var Vote={buildMapMarker:function(vote){if(typeof vote.marker=='undefined'){vote.marker=new GMarker(Vote.buildMapLocation(vote),Vote.buildMapIcon(vote));vote.marker_click_callback=GEvent.addListener(vote.marker,"click",View.displayInfoBubble.bind(this,vote))}return vote.marker},buildMapLocation:function(vote){return new GLatLng(parseFloat(vote.latitude),parseFloat(vote.longitude))},buildMapIcon:function(vote){var icon=new GIcon();icon.image=Constants.icon_url.evaluate({'option_id':vote.voted_for});icon.shadow="/img/results/shadow50.png";icon.iconSize=new GSize(20,33);icon.shadowSize=new GSize(37,34);icon.iconAnchor=new GPoint(10,33);icon.infoWindowAnchor=new GPoint(10,33);return icon},renderToRecentVotes:function(vote){var row_html=templates.Vote.recent_vote.evaluate({'option_id':vote.voted_for,'short_city':vote.short_city,'country_name':vote.country_name,'country_code':vote.country_code,'human_ago':Ask500.timeAgo(vote.seconds_ago+(ticks-vote.arrived_tick))});vote.recent_element=Ask500.getDummyNode().update(row_html).down();if(typeof vote.recent_element!='undefined'){vote.recent_click=new Ask500.EventHandler(vote.recent_element,'click',View.displayInfoBubble.bind(this,vote));vote.recent_click.register();vote.recent_element.remove()}return vote.recent_element},dispose:function(vote){if(typeof vote!='undefined'){if(typeof vote.recent_click!='undefined'){vote.recent_click.clear();delete vote.recent_click}if(typeof vote.recent_element!='undefined'){vote.recent_element.remove();delete vote.recent_element}if(typeof vote.marker_click_callback!='undefined'){GEvent.removeListener(vote.marker_click_callback);delete vote.marker_click_callback}if(typeof vote.marker!='undefined'){if(votes.info_bubbled==vote){votes.info_bubbled=false;google_map.closeInfoWindow()}google_map.removeOverlay(vote.marker);delete vote.marker}delete vote}},updateTimeAgo:function(vote){if(typeof vote!='undefined'){if(votes.info_bubbled==vote){$A(google_map.getInfoWindow().getContentContainers()).reduce().down('span.time').update(Ask500.timeAgo(vote.seconds_ago+(ticks-vote.arrived_tick)))}if(typeof vote.recent_element!='undefined'){vote.recent_element.down('span.time').update(Ask500.timeAgo(vote.seconds_ago+(ticks-vote.arrived_tick)))}}}};var Options={getID:function(option){if(typeof option=='object'){return option.id}},renderToResults:function(option,campaign){if(typeof option.sidebar_nodes!='undefined'){return option.sidebar_nodes}var option_html='';var text_row_html='';var numeric_row_html='';var visual_row_html='';var type_parts=campaign.type.split('_');var type=type_parts.first();var sub_type=type_parts.last();var index=0;var yesno_classes=['yes','no'];var classes='result';for(var i=0;i<campaign.options.length;i++){if(campaign.options[i]==option){index=i;break}}if(type=='text'){classes+=' text '+(String.fromCharCode(97+index))}else if(type==='yesno'){classes+=' '+yesno_classes[index]}else if(type=='range'){classes+=' text range'+(index+1)}if(type=='text'||type=='range'){var option_text_html='';if(type=='range'&&sub_type=='star'){option_text_html=templates.Option.text_range_star.evaluate({id:option.id,stars:index+1})}else{option_text_html=templates.Option.text_other.evaluate({'text':option.truncated_media,'full_text':option.media})}text_row_html=templates.Option.sidebar_text.evaluate({'option_text_html':option_text_html,'class':classes,'id':option.id})}var total=campaign.response_count;var percent=0;if(total!=0){percent=Math.round((option.votes/total)*100)}numeric_row_html=templates.Option.sidebar_numeric.evaluate({'class':classes,'id':option.id,'percentage_score':percent,'votes':option.votes});visual_row_html=templates.Option.sidebar_visual.evaluate({'class':classes,'id':option.id,'percentage_score':percent});option_html=templates.Option.sidebar.evaluate({'text_row_html':text_row_html,'numeric_row_html':numeric_row_html,'visual_row_html':visual_row_html});option.sidebar_nodes=Ask500.HTMLToDOM(option_html);var parent_node=option.sidebar_nodes.first().up();option.graph_element=parent_node.down('#option_graph_'+option.id);option.count_element=parent_node.down('#option_count_'+option.id);option.percent_element=parent_node.down('#option_percent_'+option.id);for(var i=0;i<option.sidebar_nodes.length;i++){option.sidebar_nodes[i].remove()}return option.sidebar_nodes}};var Campaign={beenUpvoted:function(campaign){if(typeof campaign=='object'){return campaign.upvoted}},getID:function(campaign){if(typeof campaign=='object'){return campaign.id}},setStatus:function(campaign,status){if(typeof campaign=='object'){if(campaign.status!=status){if(campaign==campaigns.running){if(status=='done'){campaign.finished_tick=ticks;threads.campaigns.makeCallNow()}}campaign.status=status}return campaign}},getStatus:function(campaign){if(typeof campaign=='object'){return campaign.status}},getResponseGoal:function(campaign){if(typeof campaign=='object'){return campaign.response_goal}},getQuestion:function(campaign){if(typeof campaign=='object'){return campaign.question}},getElement:function(campaign){if(typeof campaign=='object'){return campaign.element}},setResponseGoal:function(campaign,goal){if(typeof campaign=='object'){if(campaign.response_goal!=goal){if(campaign==campaigns.upcoming.first()&&$_(dom_nodes.countdown.responses)){dom_nodes.countdown.responses.update(goal)}campaign.response_goal=goal}return campaign}},findByUrlName:function(url_name,search_locations){if(typeof search_locations=='undefined'){search_locations=Object.values(campaigns)}for(var i=0;i<search_locations.length;i++){if(typeof search_locations[i].push=='function'){for(var j=search_locations[i].length-1;j>=0;j--){if(search_locations[i][j].url_name==url_name){return search_locations[i][j]}}}else if(search_locations[i].url_name==url_name){return search_locations[i]}}},taintHashByUrlName:function(search_locations){var taints=new Hash();if(typeof search_locations=='undefined'){search_locations=Object.values(campaigns)}for(var i=0;i<search_locations.length;i++){if(typeof search_locations[i].push=='function'){for(var j=search_locations[i].length-1;j>=0;j--){taints[search_locations[i][j].url_name]=true}}else{taints[search_locations[i].url_name]=true}}return taints},hasMoreOptions:function(campaign){if(campaign.breed=='link_to'&&campaign.user.client_owns){return true}if(campaign.breed=='main_page'&&!campaign.user.client_owns){return true}if(campaign.breed=='community'&&!campaign.user.client_owns){return true}return false},hasEmbedLink:function(campaign){if(campaign.breed=='link_to'&&campaign.user.client_owns){return true}if(campaign.breed=='main_page'){return true}return false},bindToMap:function(campaign){campaigns.running=campaign;if(campaign.loading){threads.map.changePeriod(Constants.Vote.loading_delay).start()}else{threads.map.changePeriod(Constants.Vote.running_delay).start()}if(typeof dom_nodes.response_info!='undefined'){for(var i=0;i<campaign.options.length;i++){Options.renderToResults(campaign.options[i],campaign);for(var j=0;j<campaign.options[i].sidebar_nodes.length;j++){dom_nodes.response_info.up().insertBefore(campaign.options[i].sidebar_nodes[j],dom_nodes.response_info)}}}Campaign.calcRecentVotesListSize(campaign);View.updateResponseCount();if(campaign.response_count>=Constants.max_votes_on_map){votes.count=campaign.response_count-Constants.max_votes_on_map;votes.deleted_count=campaign.response_count-Constants.max_votes_on_map}Campaign.setStatus(campaign,Campaign.getStatus(campaign));if(dom_nodes.tabs.results.loaded){ResultsTab.cleanResults()}if(campaign.type.substr(0,6)=='range_'){if($_(dom_nodes.range_results.high)){if(campaign.type=='range_star'){var opt=campaign.options.last();dom_nodes.range_results.high.update('<img src="'+opt.media+'" />')}else{var opt=campaign.options[3];dom_nodes.range_results.high.update(opt.media)}}if($_(dom_nodes.range_results.low)){if(campaign.type=='range_star'){var opt=campaign.options.first();dom_nodes.range_results.low.update('<img src="'+opt.media+'" />')}else{var opt=campaign.options[1];dom_nodes.range_results.low.update(opt.media)}}View.updateRangeResults();if($_(dom_nodes.range_results.main)){dom_nodes.range_results.main.show()}}threads.votes.release()},calcPercentageScore:function(campaign){if(campaign.type.substr(0,6)=='range_'){var total=0;var votes=0;var vote_value=0;for(var i=0;i<campaign.options.length;i++){total+=campaign.options[i].votes*vote_value;votes+=campaign.options[i].votes;vote_value++}if(votes!=0&&campaign.options.length!=0){total=(total/votes);total/=campaign.options.length-1;total=Math.round(total*100)}else{total=0}return total}},calcRecentVotesListSize:function(campaign){var size;var vote_list_height=0;var map_height=0;var results_height=0;var vote_height=46;if($_(dom_nodes.vote_list)){vote_list_height=dom_nodes.vote_list.getHeight();dom_nodes.vote_list.appendChild(fake_vote.recent_element);vote_height=fake_vote.recent_element.getHeight();fake_vote.recent_element.remove()}if($_(dom_nodes.map)){map_height=dom_nodes.map.up('.map').getHeight()}if($_(dom_nodes.results)){results_height=dom_nodes.results.getHeight()}campaign.recent_votes_list_size=Math.floor((map_height-(results_height+vote_list_height))/vote_height);if(campaign.recent_votes_list_size<0){campaign.recent_votes_list_size=0}return campaign.recent_votes_list_size},init:function(campaign){if(typeof campaign=='object'){campaign.loading=true;for(var i=0;i<campaign.options.length;i++){if(typeof campaign.options[i].votes=='undefined'){campaign.options[i].votes=0}}return campaign}}};function clockTick(){ticks++;if(campaigns.running){var campaign=campaigns.running;View.updateVotesTimeAgo()}};function initFetchVotes(){if(campaigns.running!==false){var count=votes.count;if(votes.waiting_for_early===true&&votes.early_on_map===true){count--}var parameters={url:Constants.Urls.votes_call,options:{asynchronous:true,method:'get',parameters:{c:Campaign.getID(campaigns.running),l:Constants.votes_returned_limit,o:count,s:Ask500.readCookie(Ask500.Constants.CookieName)},onSuccess:procVotesJSON}};return parameters}};function isValidReply(json){try{if(typeof json!='undefined'&&json.status.code==200){return true}}catch(e){}return false};function procVotesJSON(response){if(campaigns.running!==false){var json=Ask500.decodeJSON(response.responseText);if(isValidReply(json)){epoch=json.server_epoch;for(var i=0;i<json.votes.length;i++){if(votes.waiting_for_early&&votes.early.voted_for===json.votes[i].voted_for&&votes.early.latitude===json.votes[i].latitude&&votes.early.longitude===json.votes[i].longitude){votes.waiting_for_early=false}else{json.votes[i].arrived_tick=ticks;votes.pending.push(json.votes[i]);votes.count++}}Campaign.setStatus(campaigns.running,json.campaign.status)}}};function delayedVoteAdd(){if(!launching_campaign&&votes.pending.length>0){var vote=votes.pending.shift();if(campaigns.running!=false){votes.recent.push(vote);if(votes.recent.length==1&&typeof dom_nodes.vote_list!='undefined'&&!dom_nodes.vote_list.hasClassName('incomingvotes')){if(campaigns.running.recent_votes_list_size!=0){Campaign.calcRecentVotesListSize(campaigns.running);dom_nodes.vote_list.addClassName('incomingvotes');dom_nodes.vote_list.down('.divider').remove()}if($_(dom_nodes.tabs.results.control)){dom_nodes.tabs.results.control.show()}}if(votes.recent.length+votes.others.length+votes.deleted_count>campaigns.running.response_count){if(campaigns.running.loading){threads.map.changePeriod(Constants.Vote.running_delay);campaigns.running.loading=false}campaigns.running.response_count=votes.recent.length+votes.others.length+votes.deleted_count;var country_code='--';if(vote.country_code!=null){country_code=vote.country_code.toUpperCase()}var replace=true;var community=vote.community;if(typeof results_by_country[country_code]=='undefined'){results_by_country[country_code]={total_votes:0,option_percents:{},option_counts:{},country_code:country_code,country:(vote.country_code!=null?vote.country_name:'Unknown')};for(var i=0;i<campaigns.running.options.length;i++){var opt_id=campaigns.running.options[i].id;results_by_country[country_code].option_counts[opt_id]=0;results_by_country[country_code].option_percents[opt_id]=0}replace=false}results_by_country[country_code].option_counts[vote.voted_for]++;results_by_country[country_code].total_votes++;for(var i=0;i<campaigns.running.options.length;i++){var opt_id=campaigns.running.options[i].id;results_by_country[country_code].option_percents[opt_id]=Math.round((results_by_country[country_code].option_counts[opt_id]/results_by_country[country_code].total_votes)*100)}results_by_community[community].option_counts[vote.voted_for]++;results_by_community[community].total_votes++;for(var i=0;i<campaigns.running.options.length;i++){var opt_id=campaigns.running.options[i].id;results_by_community[community].option_percents[opt_id]=Math.round((results_by_community[community].option_counts[opt_id]/results_by_community[community].total_votes)*100)}if(dom_nodes.tabs.results.loaded){if($_(dom_nodes.results_tab.country)&&dom_nodes.demographic_tabs.country.loaded){if(replace){results_by_country[country_code].elements.total_votes.update(results_by_country[country_code].total_votes);for(var i=0;i<campaigns.running.options.length;i++){var opt_id=campaigns.running.options[i].id;results_by_country[country_code].elements.option_counts[opt_id].update(results_by_country[country_code].option_counts[opt_id]);results_by_country[country_code].elements.option_percents[opt_id].update(results_by_country[country_code].option_percents[opt_id]+'%')}}else{dom_nodes.results_tab.country.appendChild(ResultsTab.renderToCountryRow(campaigns.running,results_by_country[country_code],results_by_country_even));results_by_country_even=!results_by_country_even}}if($_(dom_nodes.results_tab.community)&&dom_nodes.demographic_tabs.country.loaded){results_by_community[community].elements.total_votes.update(results_by_community[community].total_votes);for(var i=0;i<campaigns.running.options.length;i++){var opt_id=campaigns.running.options[i].id;results_by_community[community].elements.option_counts[opt_id].update(results_by_community[community].option_counts[opt_id]);results_by_community[community].elements.option_percents[opt_id].update(results_by_community[community].option_percents[opt_id]+'%')}}}View.updateResponseCount()}if(!campaigns.running.loading){for(var i=0;i<campaigns.running.options.length;i++){if(vote.voted_for==campaigns.running.options[i].id){var option=campaigns.running.options[i];option.votes++;option.count_element.update(option.votes);new Effect.Highlight(option.count_element,{duration:0.5,startcolor:option.count_element.getStyle('color').parseColor(),endcolor:'#ffffff',transition:Callbacks.highlightTransition,afterFinish:Callbacks.hightlightAfter})}View.updateOptionResults(campaigns.running.options[i])}}if(votes.others.length+votes.recent.length>Constants.max_votes_on_map&&votes.others.length>0){Vote.dispose(votes.others.shift());votes.deleted_count++}if(typeof google_map!='undefined'){google_map.addOverlay(Vote.buildMapMarker(vote));if(!campaigns.running.loading&&map_pan){if(typeof vote.marker.getPoint=='function'){google_map.panTo(vote.marker.getPoint())}else{google_map.panTo(vote.marker.getLatLng())}}}View.updateRangeResults();if($_(dom_nodes.vote_list)){if(votes.recent.length>campaigns.running.recent_votes_list_size){var last_vote=votes.recent.shift();if(typeof last_vote.recent_element!='undefined'){last_vote.recent_element.remove();last_vote.recent_click.clear();delete last_vote.recent_click;delete last_vote.recent_element}votes.others.push(last_vote)}if(votes.recent.length>0){var row=Vote.renderToRecentVotes(vote);if(votes.recent.length>1){dom_nodes.vote_list.insertBefore(row,dom_nodes.vote_list.firstDescendant())}else{dom_nodes.vote_list.appendChild(row)}}}}}};function procLoadVote(response){if($_(dom_nodes.voting.overlay)){var voting_question=dom_nodes.voting.overlay.down('div.display_question');if($_(voting_question)){voting_question.replace(response.responseText)}else{var node=Ask500.HTMLToDOM(response.responseText);if(typeof node=='undefined'){return}node.remove();dom_nodes.voting.cancel.up().insertBefore(node,dom_nodes.voting.cancel)}cleanUpVoteOverlay();dom_nodes.voting.tab.removeClassName('vote_tab_inactive');dom_nodes.voting.fake_tab.removeClassName('vote_tab_inactive')}};function initLoadVote(){if(campaigns.running!==false){new Ajax.Request(Constants.Urls.ask.evaluate({campaign_id:campaigns.running.id}),{method:'get',onSuccess:procLoadVote})}};function cleanUpVoteOverlay(){vote_tab_option_fx.invoke('clear');vote_tab_option_fx.clear();if($_(dom_nodes.voting.overlay_overflow)){if($_(dom_nodes.voting.overlay)){dom_nodes.voting.overlay.setStyle({'top':(18-dom_nodes.voting.overlay_overflow.getHeight())+'px'});setTimeout(function(){dom_nodes.voting.overlay.setStyle({'top':(18-dom_nodes.voting.overlay_overflow.getHeight())+'px'})},10);var voting_question=dom_nodes.voting.overlay.down('div.display_question');if($_(voting_question)){var nodes=voting_question.getElementsBySelector('a[onclick]');for(var i=0;i<nodes.length;i++){nodes[i].onclick=null;vote_tab_option_fx.push(new Ask500.EventHandler(nodes[i],'click',Callbacks.voteClick).register())}var nodes=voting_question.getElementsBySelector('input[onclick]');for(var i=0;i<nodes.length;i++){nodes[i].onclick=null;vote_tab_option_fx.push(new Ask500.EventHandler(nodes[i],'click',Callbacks.voteClick).register())}}}}};function lazyLoadResultsTabs(tab_name){var tab_def=dom_nodes.demographic_tabs[tab_name];if(!tab_def.loaded){tab_def.loaded=true;switch(tab_name){case'country':Ask500.yield(function(){ResultsTab.cleanResults()});break}}};function lazyLoadTab(tab_name){var tab_def=dom_nodes.tabs[tab_name];if(!tab_def.loaded&&!tab_def.loading){var callback=finishLazyLoadTab.bind(this,tab_name);tab_def.tab.hide();tab_def.loading=true;if($_(dom_nodes.tab_loading)&&!dom_nodes.tab_loading.descendantOf(tab_def.control)){if($_(dom_nodes.tab_loading.up())){dom_nodes.tab_loading.remove()}tab_def.control.appendChild(dom_nodes.tab_loading)}switch(tab_name){case'upcoming':Ask500.yield(function(){Ask500.yield(callback)});break;case'results':Ask500.yield(callback);break;case'comments':callback();break;case'viewers':if(viewers){viewers.setShortPing(false);viewers.ping(callback)}else{callback()}break}}else if(tab_def.loading){tab_def.tab.hide();if($_(dom_nodes.tab_loading)&&!dom_nodes.tab_loading.descendantOf(tab_def.control)){if($_(dom_nodes.tab_loading.up())){dom_nodes.tab_loading.remove()}tab_def.control.appendChild(dom_nodes.tab_loading)}}else{if($_(dom_nodes.tab_loading)&&$_(dom_nodes.tab_loading.up())){dom_nodes.tab_loading.remove()}}};function finishLazyLoadTab(tab_name){var tab_def=dom_nodes.tabs[tab_name];tab_def.loaded=true;tab_def.loading=false;tab_def.tab.show();if($_(dom_nodes.tab_loading)&&$_(dom_nodes.tab_loading.up())){dom_nodes.tab_loading.remove()}};Vote.renderToRecentVotes(fake_vote);if($_(dom_nodes.comments.contents)&&$_(dom_nodes.comments.count)){comments=new Ask500.CommentManager(dom_nodes.comments.contents,dom_nodes.comments.count,null,false)}dom_nodes.each(function(pair){if(pair.value===null){delete dom_nodes[pair.key]}});if($_(dom_nodes.map)&&typeof GBrowserIsCompatible=='function'&&GBrowserIsCompatible()){google_map=new GMap2(dom_nodes.map);google_map.addControl(new GSmallMapControl());google_map.setCenter(new GLatLng(Constants.start_latitude,Constants.start_longitude),Constants.default_zoom_level);var mt=google_map.getMapTypes();GEvent.addListener(google_map,'infowindowclose',Callbacks.infoBubbleClosed);GEvent.addListener(google_map,'zoomend',function(old_level,new_level){if(new_level!=2){map_pan=false}else{map_pan=true}});for(var i=0;i<mt.length;i++){mt[i].getMinimumResolution=function(){return Constants.min_zoom_level};mt[i].getMaximumResolution=function(){return Constants.max_zoom_level}}}if($_(dom_nodes.previous_ref)){dom_nodes.previous_ref=dom_nodes.previous_ref.down('.header_row .subheader')}if($_(dom_nodes.upcoming)){try{var tbody=dom_nodes.upcoming.down('tbody');if(!$_(tbody)){tbody=document.createElement('tbody');dom_nodes.upcoming.appendChild(tbody)}dom_nodes.upcoming=$(tbody)}catch(e){}}if($_(dom_nodes.results_tab.country)){try{var tbody=dom_nodes.results_tab.country.down('tbody');if(!$_(tbody)){tbody=document.createElement('tbody');dom_nodes.results_tab.country.appendChild(tbody)}dom_nodes.results_tab.country=$(tbody)}catch(e){}}if($_(dom_nodes.results_tab.community)){try{var tbody=dom_nodes.results_tab.community.down('tbody');if(!$_(tbody)){tbody=document.createElement('tbody');dom_nodes.results_tab.community.appendChild(tbody)}dom_nodes.results_tab.community=$(tbody)}catch(e){}}threads.votes=new Ask500.PeriodicAjaxCall(initFetchVotes,Constants.visitor_poll_speed);threads.votes.hold();threads.campaigns=new Ask500.PeriodicAjaxCall(function(){if(tab_controller!==false&&tab_controller.getValue()!=='comments'&&comments!==false){comments.updateComments()}},Constants.queue_poll_speed);if(!$_(dom_nodes.upcoming)){threads.campaigns.stop()}threads.clock=new PeriodicalExecuter(clockTick,Constants.clock_speed);threads.map=new Ask500.PeriodicalExecuter(delayedVoteAdd,Constants.Vote.loading_delay);threads.map.stop();if(Ask500.hasFlash===true){Ask500.AdobeFlash.Rocket.addLoadedCallback(function(rocket){launching_campaign=true;rocket.addFadeOutCallback(function(rocket,event){if(event=='started'){dom_nodes.overlay_background.hide();launching_campaign=false}});rocket.show();rocket.play()})}else if(Ask500.hasFlash===false){dom_nodes.overlay_background.hide()}(function(){var init_json;var json_store=$('results_json_store');if($_(json_store)){init_json=Ask500.decodeEmbeddedJSONFast(json_store);if(typeof init_json!='undefined'){var campaign;viewer_init_state=init_json.viewers;if(init_json.visitor!==false){votes.early=init_json.visitor}if(init_json.campaigns.running!=false){if($_(dom_nodes.response_info)){dom_nodes.response_info.up().getElementsBySelector('.result').invoke('remove')}if(init_json.campaigns.running.status=='done'){init_json.campaigns.running.can_end=false;threads.campaigns.hold()}for(var i=0;i<init_json.campaigns.results.by_country.length;i++){results_by_country[init_json.campaigns.results.by_country[i].country_code]=init_json.campaigns.results.by_country[i]}for(var i=0;i<init_json.campaigns.results.by_community.length;i++){results_by_community[init_json.campaigns.results.by_community[i].community.toLowerCase()]=init_json.campaigns.results.by_community[i]}campaign=Campaign.init(init_json.campaigns.running);if(comments!==false){comments.bindCampaign(campaign)}Campaign.bindToMap(campaign);threads.votes.makeCallNow()}for(var i=0;i<init_json.campaigns.upcoming.length;i++){campaign=Campaign.init(init_json.campaigns.upcoming[i]);campaigns.upcoming.push(campaign)}for(var i=0;i<init_json.campaigns.upvoting.length;i++){campaign=Campaign.init(init_json.campaigns.upvoting[i]);campaigns.upvoting.push(campaign)}for(var i=0;i<init_json.campaigns.previous.length;i++){campaign=Campaign.init(init_json.campaigns.previous[i]);campaigns.previous.push(campaign)}if(dom_nodes.tabs.upcoming.loaded){}if($_(dom_nodes.previous_ref)){var nodes=dom_nodes.previous_ref.up().immediateDescendants();for(var i=1;i<nodes.length-1;i++){nodes[i].remove()}var ref=dom_nodes.previous_ref.next();for(var i=0;i<campaigns.previous.length;i++){dom_nodes.previous_ref.up().insertBefore(Campaign.renderToPrevious(campaigns.previous[i]),ref)}}if(campaigns.running==false){var next=campaigns.upcoming.first();if(typeof next!='undefined'&&comments!==false){comments.bindCampaign(next)}}else if(rocket){rocket.hide()}else if($_(dom_nodes.missing_flash)){dom_nodes.missing_flash.hide()}View.updateAbuseAndUpvote()}}})();if($_(dom_nodes.tabs.viewers.tab)&&$_(dom_nodes.viewers.clients)&&$_(dom_nodes.viewers.clients_guests)){viewers=new Ask500.ViewersManager('/main_page_campaigns/viewers',dom_nodes.tabs.viewers.tab,dom_nodes.viewers.clients,dom_nodes.viewers.clients_guests,viewer_init_state,true)}if($_(dom_nodes.voting.tab)){new Ask500.EventHandler(dom_nodes.voting.tab,'click',Callbacks.voteTabClick).register();new Ask500.EventHandler(dom_nodes.voting.fake_tab,'click',Callbacks.voteTabClick).register()}if($_(dom_nodes.voting.cancel)){new Ask500.EventHandler(dom_nodes.voting.cancel,'click',Callbacks.voteCancelClick).register()}if($_(dom_nodes.map_tab)){if(!$_(dom_nodes.tab_loading)){tab_loading=Ask500.HTMLToDOM(templates.Tab.loading.evaluate()).remove()}tab_controller=new Dynamic.Tabs(dom_nodes.map_tab,null,lazyLoadTab);tab_controller.addTabs(dom_nodes.tabs)}if($_(dom_nodes.demographic_tab)){demographic_tabs=new Dynamic.Tabs(dom_nodes.demographic_tab,null,lazyLoadResultsTabs);if(!Ask500.loggedIn()){dom_nodes.demographic_tabs['age'].tab=$('demographic_no_user');dom_nodes.demographic_tabs['income'].tab=$('demographic_no_user');dom_nodes.demographic_tabs['education'].tab=$('demographic_no_user');dom_nodes.demographic_tabs['team'].tab=$('demographic_no_user')}demographic_tabs.addTabs(dom_nodes.demographic_tabs)}if(Ask500.loggedIn()){$$('.nodemographics form').each(function(form){Event.observe(form,'submit',function(event){Event.stop(event);var err=form.down('.error_message');var save=form.down('.saving_loader');var inputs=form.getElementsBySelector('input[type!=image],select');if(inputs.detect(function(element){if(element.tagName.toLowerCase()=='select'&&element.id=='birthday_year'&&$F(element)!='0000'){return true}else if(element.type=='radio'&&element.checked){return true}return false})){err.hide();save.show();params=form.serialize(true);params['data[json]']=1;new Ajax.Request(form.action,{parameters:params,onSuccess:function(xhr){var json=Ask500.decodeJSON(xhr.responseText);if(typeof json!='undefined'&&json.status.code==200){var div=form.up('div.nodemographics');div.up().childElements().invoke('show');div.hide()}else{save.hide();err.update('An error occurred, please try again.&nbsp;&nbsp;');err.show()}},onFailure:function(){save.hide();err.update('An error occurred, please try again.&nbsp;&nbsp;');err.show()}})}else{save.hide();err.update('Please choose an option above.&nbsp;&nbsp;');err.show()}})})}else{if(Ask500.$_($('hideable_content_1'))){Event.observe('hideable_content_1','submit',function(){$('redirect_to_login').value=Ask500.currentLocation(true)+'#'+demographic_tabs.getValue()})}if(Ask500.$_($('signup_form'))){Event.observe('signup_form','submit',function(){$('redirect_to_signup').value=Ask500.currentLocation(true)+'#'+demographic_tabs.getValue()})}}var fragment=Ask500.currentFragment();if(fragment&&campaigns.running&&campaigns.running.response_count>0){switch(fragment){case'votes':tab_controller.fxToggleTabs(null,'results');break;case'gender':case'income':case'age':case'education':case'team':case'overview':case'country':tab_controller.fxToggleTabs(null,'results');demographic_tabs.fxToggleTabs(null,fragment);break}}cleanUpVoteOverlay();init_done=true}};Object.extend(Ask500.ResultsManager.Public,{Constants:{max_votes_on_map:80,visitor_poll_speed:5,queue_poll_speed:30,max_vote_list_size:10,cookie:'ASKTOOL',default_zoom_level:2,min_zoom_level:1,max_zoom_level:9,clock_speed:1,queue_lockdown_time:60,previous_offset:41.2,previous_queue_length:6,upcoming_queue_length:10,previous_slide_duration:2.0,results_fade_duration:1.3,results_fade_offset:0.6,start_latitude:'11.867350',start_longitude:'-39.375',votes_returned_limit:50,launch_time_offset:15,icon_url:new Template("/options/map_icon/#{option_id}.png"),Vote:{loading_delay:0.1,running_delay:1.0},Urls:{votes_call:'/visitors/gmap_json/',campaigns_call:'/main_page_campaigns/queue_json/',submit_vote:'/api/1.0/vote.js',ask:new Template('/campaigns/ask_raw/#{campaign_id}/0/0/users')}},Templates:{Vote:{},Option:{},ResultsTab:{Rows:{},Cells:{}},Tab:{}}});Object.extend(Ask500,{AdobeFlash:{getMovie:function(a_movie){if(window[a_movie]){return window[a_movie]}if(document.embeds){if(document.embeds[a_movie]){return document.embeds[a_movie]}for(var i=0;i<document.embeds.length;i++){if(document.embeds[i].name==a_movie){return document.embeds[i]}}}if(document[a_movie]){return document[a_movie]}return null},Rocket:{loaded:function(){this.flash_obj=Ask500.AdobeFlash.getMovie('rocket');this.fade_in={start:this.flash_obj.getFadeInFrame('start'),end:this.flash_obj.getFadeInFrame('end'),callbacks:[]};this.fade_out={start:this.flash_obj.getFadeOutFrame('start'),end:this.flash_obj.getFadeOutFrame('end'),callbacks:[]};if(typeof this.loaded_callbacks=='object'){this.loaded_callbacks.each(function(callback){callback(this)}.bind(this))}},fadeIn:function(event){this.fade_in.callbacks.each(function(callback){callback(this,event)}.bind(this))},fadeOut:function(event){this.fade_out.callbacks.each(function(callback){callback(this,event)}.bind(this))},toForeground:function(){$(this.flash_obj.parentNode).setStyle({'z-index':400,'position':'','margin-left':''})},toBackground:function(){$(this.flash_obj.parentNode).setStyle({'z-index':97,'position':'','margin-left':''})},show:function(){this.toBackground()},hide:function(){$(this.flash_obj.parentNode).setStyle({'z-index':-9999,'position':'absolute','margin-left':'-1000px'})},play:function(){if(this.flash_obj!='undefined'){this.flash_obj.gotoAndPlay(this.fade_in.start)}},reset:function(){if(this.flash_obj!='undefined'){this.flash_obj.gotoAndStop(2)}},addFadeInCallback:function(callback){this.fade_in.callbacks.push(callback);return callback},removeFadeInCallback:function(callback){this.fade_in.callbacks=this.fade_in.callbacks.without(callback);return callback},addFadeOutCallback:function(callback){this.fade_out.callbacks.push(callback);return callback},removeFadeOutCallback:function(callback){this.fade_out.callbacks=this.fade_out.callbacks.without(callback);return callback},addLoadedCallback:function(callback){if(typeof this.loaded_callbacks!='object'){this.loaded_callbacks=[]}this.loaded_callbacks.push(callback);if(typeof this.flash_obj!='undefined'){callback(this)}return callback},removeLoadedCallback:function(callback){this.loaded.callbacks=this.loaded.callbacks.without(callback);return callback}}}});Event.observe(window,'load',function(){Ask500.yield(function(){Object.extend(Ask500.ResultsManager.Public,{GlobalInstance:new Ask500.ResultsManager.Public()})})});Event.observe(window,'unload',function(){if(typeof GUnload=='function'){GUnload()}})}/* 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>');
/* Copyright 2009 Wondermill Webworks Inc. */
Ask500.ResultsManager.Public.Templates.Vote.info_bubble = new Template('<table class=\"bubble\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n\t<tr>\n\t\t<td class=\"icon\"><img src=\"/options/icon/#{option_id}.png\" /></td>\n\t\t<td class=\"location\">\n\t\t\t<span class=\"locality\">#{city}</span>\n\t\t  \t<span class=\"time\">#{human_ago}</span>\n\t\t</td>\n\t\t<td class=\"flag\"><img src=\"/img/general/flags/#{country_code}-t.gif\" alt=\"#{country_code}\" title=\"#{country_name}\" /></td>\n\t</tr>\n</table>');
Ask500.ResultsManager.Public.Templates.Vote.recent_vote = new Template('<!-- Top Rounded Corners -->\n<div class=\"vote small_topright\"  >\n\t<div class=\"small_topleft\"></div>\n\t<div class=\"small_bottomleft\">\n\t\t<div class=\"small_bottomright\">\n\t\t<!-- END Top Rounded Corners -->\n\t\t\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n\t<tr>\n\t\t<td class=\"icon\"><img src=\"/options/icon/#{option_id}.png\" style=\"width: 28px; height: 28px\"/></td>\n\t\t<td class=\"location\">\n\t\t\t<span class=\"locality\">#{short_city}</span><span class=\"time\">#{human_ago}</span>\n\t\t</td>\n\t\t<td class=\"flag\"><img src=\"/img/general/flags/#{country_code}-t.gif\" alt=\"#{country_code}\" title=\"#{country_name}\" /></td>\n\t</tr>\n</table>\n\t\t<!-- Bottom Rounded Corners -->\n\t\t</div>\n\t</div>\n</div>\n<!-- END Bottom Rounded Corners -->');
Ask500.ResultsManager.Public.Templates.Option.sidebar = new Template('\t#{text_row_html}\n\t#{visual_row_html}\n\t#{numeric_row_html}\n');
Ask500.ResultsManager.Public.Templates.Option.sidebar_numeric = new Template('<tr class=\"#{class}\" id=\"option_numerics_#{id}\">\n\t<td class=\"count\">\n\t\t<span class=\"vote_count\"><span id=\"option_count_#{id}\">#{votes}</span> votes</span>\n\t\t<span class=\"vote_percent\"><span id=\"option_percent_#{id}\">#{percentage_score}</span>%</span>\n\t</td>\n</tr>');
Ask500.ResultsManager.Public.Templates.Option.sidebar_visual = new Template('<tr class=\"#{class}\" id=\"option_visuals_#{id}\">\n\t<th rowspan=\"2\" class=\"icon\">\n\t\t<img src=\"/options/icon/#{id}.png\" />\n\t</th>\n\t<td class=\"graph\">\n\t\t<div class=\"bar\" id=\"option_graph_#{id}\" style=\"width: #{percentage_score}%;\">\n\t\t\t<div></div>\n\t\t</div>\n\t</td>\n</tr>');
Ask500.ResultsManager.Public.Templates.Option.sidebar_text = new Template('<tr class=\"#{class}\" id=\"option_text_#{id}\">\n\t<td colspan=\"2\" class=\"key\">\n\t\t\t\t\t#{option_text_html}\n\t\t\t</td>\n</tr>');
Ask500.ResultsManager.Public.Templates.Option.text_other = new Template('<span>#{full_text}</span>');
Ask500.ResultsManager.Public.Templates.Option.text_range_star = new Template('<img src=\"/options/ask_content/#{id}\" alt=\"#{stars} Stars\" title=\"#{stars} Stars\" />');
Ask500.ResultsManager.Public.Templates.ResultsTab.Rows.header = new Template('<tr>\n\t<th class=\"country\"></th>\n\t<th class=\"total_votes\">Total<br />Votes</th>\n\t\t\t#{option_1}\n\t\t#{option_2}\n\t\t#{option_3}\n\t\t#{option_4}\n\t\t#{option_5}\n\t</tr>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Rows.country = new Template('<tr class=\"#{even}\">\n\t\t\t#{country_cell}\n\t\t#{total_votes_cell}\n\t\t#{option_vote_cells}\n\t</tr>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Rows.community = new Template('<tr class=\"#{even}\">\n\t\t\t#{community_cell}\n\t\t#{total_votes_cell}\n\t\t#{option_vote_cells}\n\t</tr>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.country = new Template('<th class=\"country\"><img src=\"/img/general/flags/#{country_code}-t.gif\" /> #{country} </td>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.community = new Template('<th class=\"country\">#{community}</td>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.header_image = new Template('<th class=\"#{class}\"><img src=\"/options/icon/#{id}\" alt=\"#{title}\" title=\"#{title}\" /></th>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.header_text = new Template('<th class=\"#{class}\"><span title=\"#{full_text}\">#{short_text}</span></th>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.option_votes = new Template('<td class=\"#{class}\"><span class=\"vote_count\">#{count}</span> <span class=\"vote_percent\">#{percent}%</span></td>');
Ask500.ResultsManager.Public.Templates.ResultsTab.Cells.total_votes = new Template('<td class=\"total_votes\">#{count}</td>');
Ask500.ResultsManager.Public.Templates.Tab.loading = new Template('<span class=\"tab_loading\" id =\"tab_loading_panel\"><img src=\"/img/general/loader_small.gif\" /> Loading...</span>');
/* Copyright 2009 Wondermill Webworks Inc. */
Ask500.ViewersManager.Templates.user = new Template('\n<!-- Top Rounded Corners -->\n<div class=\"viewer medium_topright\"  >\n\t<div class=\"medium_topleft\"></div>\n\t<div class=\"medium_bottomleft\">\n\t\t<div class=\"medium_bottomright\">\n\t\t<!-- END Top Rounded Corners -->\n\t\t\t<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n\t<tr class=\"header_row\">\n\t\t<th colspan=\"2\"><img class=\"flag\" alt=\"#{country_code}\" title=\"#{country_name}\" src=\"/img/general/flags/#{country_code}-t.gif\" /> <a href=\"/profile/#{user_name}\" title=\"#{display_as}\"><span>#{display_as_short}</span></a></th>\n\n\t\t<!-- <th colspan=\"2\">Johnny</th> -->\n\t</tr><tr>\n\t\t<td class=\"profile_picture\">\n\t\t\t<a href=\"/profile/#{user_name}\" title=\"#{display_as}\"><img src=\"http://ask500.s3.amazonaws.com/img/profile/#{user_name}/large.png\" alt=\"#{display_as}&apos;s Profile Picture\"/></a>\t\t\t\t\t\t\t\t\n\t\t</td>\n\t</tr>\n</table>\n\t\t<!-- Bottom Rounded Corners -->\n\t\t</div>\n\t</div>\n</div>\n<!-- END Bottom Rounded Corners -->');
