Dragger=function(o,a){
this.handleStart=this.start.bind(this);
this.handleStop=this.stop.bind(this);
this.handleUpdate=this._updateMouse.bind(this);
o.style.position="absolute";
this.object=o;
this.d={x:0,y:0};
this.f=[];
if(a){
Event.observe(o,"mousedown",this.handleStart,false);
o.onmousedown=function(){
if(browser=="Safari"){
return true;
}
return false;
};
Event.observe(document,"mouseup",this.handleStop,false);
}
if(!Dragger.updatingMouse){
Event.observe(document,"mousemove",this.handleUpdate,false);
Dragger.updatingMouse=true;
}
};
with({p:Dragger.prototype,c:Dragger}){
p._updateMouse=function(e){
var w=window,b=document.body;
p.mouse={x:e.clientX+(w.scrollX||b.scrollLeft||b.parentNode.scrollLeft||0),y:e.clientY+(w.scrollY||b.scrollTop||b.parentNode.scrollTop||0)};
};
p.mouse={x:0,y:0};
p.dragging=false;
p.setonbeforestart=function(_6){
this["onbeforestart"]=_6;
this.object.onmousedown=function(e){
if(this.callEvent("onbeforestart",e)){
if(browser=="Safari"){
return true;
}
return false;
}
}.bind(this);
};
p.start=function(e,_9){
if(this["onbeforestart"] instanceof Function&&!this.callEvent("onbeforestart",e)){
}else{
var r,$=this,m=$.mouse,o=$.object;
for(var r={l:o.offsetLeft,t:o.offsetTop,w:o.offsetWidth,h:o.offsetHeight};o=o.offsetParent;r.l+=o.offsetLeft,r.t+=o.offsetTop){
}
!$.dragging&&($.dragging=true,o=$.object,$.d=_9&&(m.x<r.l||m.x>r.l+r.w||m.y<r.t||m.y>r.t+r.h)?{x:r.w/2,y:r.h/2}:{x:m.x-o.offsetLeft,y:m.y-o.offsetTop},this.dragListener=this.drag.bindAsEventListener(this),Event.observe(document,"mousemove",this.dragListener,false),this.callEvent("onstart"));
}
};
p.drag=function(e){
if(browser=="IE"){
var _f=document.body.parentNode.scrollTop;
var _10=_f+document.body.parentNode.clientHeight;
var _11=event.clientY+_f;
}else{
var _f=window.scrollY;
var _10=window.scrollY+window.innerHeight;
var _11=e.pageY;
}
if(_11>(_10-10)){
window.scrollBy(0,6);
}else{
if(_11>(_10-25)){
window.scrollBy(0,4);
}else{
if(_11>(_10-50)){
window.scrollBy(0,2);
}else{
if(_11<(_f+10)){
window.scrollBy(0,-6);
}else{
if(_11<(_f+25)){
window.scrollBy(0,-4);
}else{
if(_11<(_f+50)){
window.scrollBy(0,-2);
}
}
}
}
}
}
var i,p,$=this,o=$.object,m=($._updateMouse(e),(m=$.mouse).x-=$.d.x,m.y-=$.d.y,m);
for(i=$.f.length;i;$.f[--i]&&$.f[i][0].apply(m,$.f[i][1])){
}
if(o.style.posLeft){
o.style.posLeft=m.x,o.style.posTop=m.y;
}else{
o.style.left=m.x+"px",o.style.top=m.y+"px";
}
return !!this.callEvent("ondrag",e);
};
p.stop=function(){
this.dragging=false;
this.dragListener&&(Event.stopObserving(document,"mousemove",this.dragListener,false));
this.callEvent("onstop");
};
p.addFilter=function(f,_18,_19,_1a,_1b){
this.f[this.f.length]=[f,[].slice.call(arguments,1)];
};
p.callEvent=function(e){
return this[e] instanceof Function?this[e].apply(this,[].slice.call(arguments,1)):undefined;
};
}
Dragger.prototype.disable=function(o){
Event.stopObserving(o,"mousedown",this.handleStart,false);
Event.stopObserving(document,"mouseup",this.handleStop,false);
Event.stopObserving(document,"mousemove",this.handleUpdate,false);
if(this.dragListener){
Event.stopObserving(document,"mousemove",this.dragListener,false);
}
};
Dragger.prototype.enable=function(o){
Event.observe(o,"mousedown",this.handleStart,false);
Event.observe(document,"mouseup",this.handleStop,false);
Event.observe(document,"mousemove",this.handleUpdate,false);
};
Dragger.filters=new function(){
function lineLength(x,y,x0,y0){
return Math.sqrt((x-=x0)*x+(y-=y0)*y);
};
function dotLineLength(x,y,x0,y0,x1,y1,o){
if(o&&!(o=function(x,y,x0,y0,x1,y1){
if(!(x1-x0)){
return {x:x0,y:y};
}else{
if(!(y1-y0)){
return {x:x,y:y0};
}
}
var _30,tg=-1/((y1-y0)/(x1-x0));
return {x:_30=(x1*(x*tg-y+y0)+x0*(x*-tg+y-y1))/(tg*(x1-x0)+y0-y1),y:tg*_30-tg*x+y};
}(x,y,x0,y0,x1,y1),o.x>=Math.min(x0,x1)&&o.x<=Math.max(x0,x1)&&o.y>=Math.min(y0,y1)&&o.y<=Math.max(y0,y1))){
var l1=lineLength(x,y,x0,y0),l2=lineLength(x,y,x1,y1);
return l1>l2?l2:l1;
}else{
var a=y0-y1,b=x1-x0,c=x0*y1-y0*x1;
return Math.abs(a*x+b*y+c)/Math.sqrt(a*a+b*b);
}
};
this.SQUARE=function(x,y,w,h){
this.x=this.x<x?x:this.x>x+w?x+w:this.x,this.y=this.y<y?y:this.y>y+h?y+h:this.y;
};
this.CIRCLE=function(x,y,ray){
var tg;
lineLength(this.x,this.y,x+=ray,y+=ray)>ray&&(this.x=Math.cos(tg=Math.atan2(this.y-y,this.x-x))*ray+x,this.y=Math.sin(tg)*ray+y);
};
this.LINE=function(x,y,_41){
if(!(_41%90)){
return this.x=x;
}
var tg=Math.tan(-_41*Math.PI/180);
Math.sin(45*Math.PI/180)>=Math.sin(_41*Math.PI/180)?this.y=(this.x-x)*tg+y:this.x=(this.y-y)/tg+x;
};
this.POLY=function(x0,y0,x1,y1,_47,_48,_49){
for(var a=[].slice.call(arguments,0),_4b=[];a.length>3;_4b[_4b.length]={y1:a.pop(),x1:a.pop(),y0:a.pop(),x0:a.pop()}){
}
if(!_4b.length){
return;
}
for(var l,i=_4b.length-1,o=_4b[i],_4f={i:i,l:dotLineLength(this.x,this.y,o.x0,o.y0,o.x1,o.y1,1)};i--;_4f.l>(l=dotLineLength(this.x,this.y,(o=_4b[i]).x0,o.y0,o.x1,o.y1,1))&&(_4f={i:i,l:l})){
}
this.y<Math.min((o=_4b[_4f.i]).y0,o.y1)?this.y=Math.min(o.y0,o.y1):this.y>Math.max(o.y0,o.y1)&&(this.y=Math.max(o.y0,o.y1));
this.x<Math.min(o.x0,o.x1)?this.x=Math.min(o.x0,o.x1):this.x>Math.max(o.x0,o.x1)&&(this.x=Math.max(o.x0,o.x1));
Math.abs(o.x0-o.x1)<Math.abs(o.y0-o.y1)?this.x=(this.y*(o.x0-o.x1)-o.x0*o.y1+o.y0*o.x1)/(o.y0-o.y1):this.y=(this.x*(o.y0-o.y1)-o.y0*o.x1+o.x0*o.y1)/(o.x0-o.x1);
};
};
function toggleStats(e,id){
var tar=Event.element(e);
var _53=$("authorcenter_pane");
if(tar.showing_stats){
Element.hide(_53);
Element.update(tar,tar.showing_stats);
tar.showing_stats=false;
}else{
var _54=function(req){
Element.show(_53);
tar.showing_stats=tar.innerHTML;
Element.update(tar,"hide stats");
tip_init();
};
var _56=new Ajax.Updater({success:"authorcenter_pane"},"/xml/articlestats.php",{onComplete:_54,parameters:$H({art_id:id}).toQueryString(),onFailure:reportError});
}
return false;
};
function toggleUserStats(e,id){
var tar=Event.element(e);
var _5a=$("usercenter_pane");
if(tar.showing_stats){
Element.hide(_5a);
Element.update(tar,tar.showing_stats);
tar.showing_stats=false;
}else{
var _5b=function(req){
Element.show(_5a);
tar.showing_stats=tar.innerHTML;
Element.update(tar,"hide stats");
};
var _5d=new Ajax.Updater({success:"usercenter_pane"},"/xml/userstats.php",{onComplete:_5b,parameters:$H({user_id:id}).toQueryString(),onFailure:reportError});
}
return false;
};
function toggleRequestStats(e,id){
var tar=Event.element(e);
var _61=$("requestcenter_pane");
if(tar.showing_stats){
Element.hide(_61);
Element.update(tar,tar.showing_stats);
tar.showing_stats=false;
}else{
var _62=function(req){
Element.show(_61);
tar.showing_stats=tar.innerHTML;
Element.update(tar,"hide stats");
};
var _64=new Ajax.Updater({success:"requestcenter_pane"},"/xml/requeststats.php",{onComplete:_62,parameters:$H({request_id:id}).toQueryString(),onFailure:reportError});
}
return false;
};
function toggleCategoryStats(e,id){
var tar=Event.element(e);
var _68=$("authorcenter_pane");
if(tar.showing_stats){
Element.hide(_68);
Element.update(tar,tar.showing_stats);
tar.showing_stats=false;
}else{
var _69=function(req){
Element.show(_68);
tar.showing_stats=tar.innerHTML;
Element.update(tar,"hide stats");
};
var _6b=new Ajax.Updater({success:"authorcenter_pane"},"/xml/categorystats.php",{onComplete:_69,parameters:$H({category_id:id}).toQueryString(),onFailure:reportError});
}
return false;
};
function toggleMyAccountHelp(){
var _6c=$("show_myhelp");
var _6d=$("myhelp");
if(_6c.innerHTML=="help"){
Element.show(_6d);
Element.update(_6c,"hide");
}else{
Element.hide(_6d);
Element.update(_6c,"help");
}
return false;
};
function showDupeHistory(){
var _6e=$("toggle_history");
var _6f=$("dupe_history");
if(_6e.innerHTML=="hide history"){
Element.hide(_6f);
Element.update(_6e,"show history");
}else{
Element.show(_6f);
Element.update(_6e,"hide history");
}
return false;
};
function updateDupes(e,_71){
var tar=Event.element(e);
var _73=$("dupe_history");
var _74=$("toggle_history");
Element.update(tar,"processing");
var _75=function(req){
Element.show(_73);
Element.update(tar,"check");
Element.update(_74,"hide history");
};
var _77=new Ajax.Updater({success:"dupe_history"},"/xml/dupecheck.php",{onComplete:_75,parameters:$H({articleId:_71}).toQueryString(),onFailure:reportError});
return false;
};
function request_reviewed(id){
var _79=new Ajax.Updater({success:"request_reviewed"},"/xml/request_reviewed.php",{parameters:$H({req_id:id}).toQueryString(),onFailure:reportError});
};
function article_reviewed(id){
var _7b=new Ajax.Updater({success:"article_reviewed"},"/xml/article_reviewed.php",{parameters:$H({art_id:id}).toQueryString(),onFailure:reportError});
return false;
};
function user_reviewed(id){
var _7d=new Ajax.Updater({success:"user_reviewed"},"/xml/user_reviewed.php",{parameters:$H({user_id:id}).toQueryString(),onFailure:reportError});
return false;
};
function article_sensitive(id){
var _7f=new Ajax.Updater({success:"article_sensitive"},"/xml/article_sensitive.php",{parameters:$H({art_id:id}).toQueryString(),onFailure:reportError});
return false;
};
function article_learn(_80,key){
if($("learn").style.display=="block"&&$("learn").descendantOf("learnlink_"+key)){
$("learn").style.display="none";
}else{
var _82=new Ajax.Updater({success:"learn"},"/xml/authorcenter_learn.php",{parameters:$H({artId:_80,key:key}).toQueryString(),onFailure:reportError});
$("learnlink_"+key).appendChild($("learn"));
$("learn").style.display="block";
}
};
function moderate_comment(_83,_84,_85){
if(!_83||!_84||!_85){
return;
}
ccId="cc_"+_83+"_"+_84;
var req={mod_id:_83,comment_id:_84,action:_85};
var _87=$H(req).toQueryString();
var _88=new Ajax.Updater({success:ccId},"/xml/modcom.php",{parameters:_87,onFailure:reportError});
return false;
};
function moderate_fanmail(_89,_8a,_8b){
if(!_89||!_8a){
return;
}
ccId="fanmail__"+_89+"__"+_8a;
var _8c=$(ccId);
if(!_8c){
return;
}
var req={fan_id:_89,comment_id:_8a,action:_8b};
var _8e=$H(req).toQueryString();
var _8f=new Ajax.Updater({success:ccId},"/xml/modfanmail.php",{parameters:_8e,onFailure:reportError});
return false;
};
function save_aff(aff,val){
if(!aff){
return;
}
var req={aff:aff,v:val};
var _93=$H(req).toQueryString();
var _94=new Ajax.Request("/xml/userprofile.php",{parameters:_93,onFailure:reportError,onComplete:function(_95){
var _96=_95.responseText;
if(_96=="Banned"){
alert("Sorry, because of prior HubPages Terms of Service violations associated with the affiliate id that you entered, it is no longer allowed to be used on HubPages.  If you have any questions you may contact us at team@hubpages.com.");
_96="Not Set";
}else{
var _97=$(aff+"_code_status");
Element.update(_97,"Saved");
if(_96!="Set"&&_96!="Not Set"){
_96="Error";
}
}
var _98=new fx.Text(_97,{duration:500,onComplete:function(){
this.custom(1.6,1);
this.options.onComplete=function(){
Element.update(_97,_96);
};
}});
_98.custom(1,1.6);
}.bind(aff)});
return false;
};
function ignoreBrokenLink(_99,_9a,tag){
ajax=new Ajax.Request("/xml/removelinkwarning.php",{parameters:"urlId="+_9a+"&articleId="+_99,onFailure:reportError,onComplete:function(req){
$(tag).parentNode.update("<span class='recorded ignored'>ignored</span>");
}});
return false;
};
function toggleActivityPrefs(){
var _9d=$("edit_button");
var _9e=$("filter").value;
var _9f="edit";
if(_9d.innerHTML=="save changes"){
_9f="save";
}
if(_9f=="save"){
var _a0=0;
var _a1=document.getElementsByClassName("ht_box");
for(var j=0;j<_a1.length;j++){
if(_a1[j].checked){
_a0+=Number(_a1[j].name.substr(3));
}
}
var _a3=$("current_prefs");
if(_a0!=_a3.value){
var _a4=function(){
Element.update(_9d,"saved");
_9d.style.background="#ebb";
var _a5=new fx.Text(_9d,{duration:400,onComplete:function(){
this.custom(1.3,1);
this.options.onComplete=function(){
Element.update($("edit_button"),"edit preferences");
$("edit_button").style.background="#999";
};
}});
_a5.custom(1,1.3);
};
var _a6=new Ajax.Updater({success:"content"},"/xml/activityPref.php",{parameters:$H({prefs:_a0,filter:_9e}).toQueryString(),onComplete:_a4});
_a3.value=_a0;
}else{
Element.update(_9d,"no changes");
_9d.style.background="#ebb";
_9d.style.text_decoration="none";
var _a7=new fx.Text(_9d,{duration:400,onComplete:function(){
this.custom(1.3,1);
this.options.onComplete=function(){
Element.update($("edit_button"),"edit preferences");
$("edit_button").style.background="#999";
};
}});
_a7.custom(1,1.3);
}
}
var _a8=document.getElementsByClassName("ht_cur");
var _a9="";
for(var i=0;i<_a8.length;i++){
_a9=_a8[i].className;
}
var _ab=document.getElementsByClassName("ht_pref");
for(var i=0;i<_ab.length;i++){
if(_9f=="edit"){
if(_a9=="ht_all ht_cur"){
_ab[i].style.display="block";
}else{
if(_ab[i].parentNode.className==_a9){
_ab[i].style.display="block";
}
}
}else{
_ab[i].style.display="none";
}
}
if(_9f=="edit"){
_9d.innerHTML="save changes";
}
return false;
};
function updateAdLevelOptions(){
isCommercial=document.getElementById("isCommercial");
adLevelSelect=document.getElementById("adLevelSelect");
if(isCommercial.checked){
for(i=adLevelSelect.length-2;i>=0;i--){
adLevelSelect.options[i].disabled=true;
adLevelSelect.selectedIndex=adLevelSelect.length-1;
}
}else{
for(i=adLevelSelect.length-1;i>=0;i--){
adLevelSelect.options[i].disabled=false;
}
}
};
function requestStatus(id,_ad,_ae){
var uri=$H({a:id,v:_ae}).toQueryString();
var _b0=new Ajax.Updater({success:_ad},"/xml/request.php",{parameters:uri,onFailure:reportError});
return false;
};
function ModuleEdit(id){
this.data={id:id,mod_data_id:null,div_id:null,art_id:null,type:null,links_json:"",images_json:"",quiz_json:"",map_json:"",links_added:0,position:0};
this.state={video_type:null,video_current_css:null,quiz_type:0,select_id:null,images_removed:[],links:null,tiny_mce_editor:null,origtext_width:0,origtext_height:0,last_hide:null,last_position:-1,delete_confirm_text:"Are you sure you want to delete this capsule?",map_state:null,map_listeners:[],map_marker_index:0,inserting:false,answers_added:0,questions_added:0,results_added:0,questions_removed:[],truncated_question_length:60,quiz_score_ranges:new Array(30,60,80,90,100),select_result_id:null,content_id:"modcont_"+id,rss_results_id:id+"_rss_results",rss_edit_id:id+"_rss",amazon_numbered_id:id+"_numbered",amazon_numbered_div_id:id+"_numberedDiv",amazon_searchindex_id:id+"_searchIndex",amazon_searchtype_id:id+"_searchType",amazon_results_id:id+"_amazon_results",amazon_asin_input_id:id+"_asin",amazon_asin_div_id:id+"_asinDiv",amazon_asin_search_div_id:id+"_asinSearchDiv",amazon_keyword_search_div_id:id+"_keywordSearchDiv",amazon_max_display_div_id:id+"_maxDisplayDiv",amazon_description_id:id+"_description",amazon_description_div_id:id+"_descriptionDiv",amazon_description_link_id:id+"_descriptionLink",amazon_searchtype_div_id:id+"_searchTypeDiv",poll_question_id:id+"_question",poll_answers_id:id+"_answers",poll_answer_id:id+"_answer_",poll_answer_li_id:id+"_answer_li_",poll_answer_class:id+"_answer",poll_results_id:id+"_poll_results",poll_status_id:id+"_status_",comment_edit_id:id+"_comment",comment_moderated_id:id+"_moderated",comment_emailme_id:id+"_emailme",comment_noanonymous_id:id+"_anonymous",comment_max_id:id+"_max",comment_reversed_id:id+"_reversed",text_div_id:"txtd_"+id,code_div_id:"code_d_"+id,code_textarea_id:"code_txt_area_"+id,code_type_id:id+"_code_type",code_include_line_numbers_id:id+"_code_lines",code_display_size_id:id+"_code_display_size",code_max_size_id:id+"_code_max_size",code_size_left_id:"codesize_numcharsvalue_"+id,link_search_id:id+"_link_search",link_search_type:"del",link_results_id:id+"_link_search_results",link_edit_id:id+"_link",link_display_id:id+"_link_results",links_list:id+"_linkitem",link_url_id:id+"_url",link_search_term_id:id+"_search_term",link_title_id:id+"_link_title",link_desc_id:id+"_desc",link_desc_len_id:id+"_len",link_submit_button:id+"_submit_button",link_edit_box:id+"_link_edit_box",link_status_id:"test_status_"+id,link_status_button_id:"test_status_button_"+id,link_findbox_id:"link_findbox_"+id,link_show_add_field:"link_show_add_field_"+id,link_show_search_field:"link_show_search_field_"+id,link_add_field:"link_add_field_"+id,link_search_field:"link_search_field_"+id,quiz_rendered_id:"rendered_quiz_"+id,quiz_results_id:"results_"+id,quiz_question_drag_area_id:"question_drag_"+id,quiz_edit_id:"edit_quiz_"+id,quiz_json_id:"quiz_json_"+id,quiz_result_add_input_id:"question_add_result_"+id,quiz_question_add_input_id:"question_add_input_"+id,quiz_type_name_id:"quiz_type_"+id,quiz_type_form_id:"quiz_type_form"+id,quiz_result_sentence_id:"quiz_result_sentence_"+id,quiz_form_id:"quiz_form_"+id,quiz_edit_question_id:id+"_edit_question_",quiz_done_question_id:id+"_done_question_",quiz_edit_result_id:id+"_edit_result_",quiz_done_result_id:id+"_done_result_",quiz_question_span_id:id+"_question_span_",quiz_value_id:id+"_value_",quiz_value_label_id:id+"_value_label_",quiz_question_id:id+"_question_",quiz_answer_id:id+"_answer_",quiz_answer_list_id:id+"_answer_list_",quiz_answer_li_id:id+"_answer_item_",quiz_answer_area_id:id+"_answer_area_",quiz_result_id:id+"_result_",quiz_result_values_id:id+"_result_values_",quiz_result_area_id:id+"_result_area_",quiz_result_description_id:id+"_result_description_",quiz_result_span_id:id+"_result_span_",quiz_result_name_id:id+"_result_name_",quiz_question_input_id:id+"_question_input_",map_edit_id:id+"_map",map_canvas_id:"map_canvas_"+id,map_json_id:"map_json_"+id,map_type_select_id:"map_type_select_"+id,map_geocode_address_id:"geocode_address_"+id,map_geocode_search_id:"geocode_search_"+id,map_geocode_results_id:"geocode_results_"+id,map_markers_reorder_id:"map_markers_reorder_"+id,map_legend_id:"map_legend_"+id,map_bounds_id:"map_bounds_"+id,map_adjusting_id:"map_adjusting_"+id,feed_id:id+"_feed",keywords_id:id+"_keywords",max_id:id+"_max",max_max_id:id+"_max_max",mode_id:id+"_mode",colorbar_id:"colorbar_"+id,hidebar_id:"hidebar_"+id,titlebar_id:"titlebar_"+id,title_id:id+"_title",title_input_id:id+"_titleinput",modal_id:id+"_modal",hide_id:id+"_hide",hide_text_id:id+"_hidetext",empty_notification_id:"modempty_"+id};
this.editting=false;
this.autoSavePeriodicalExecuter=null;
this.checkNetworkPeriodicalExecuter=null;
this.cleanUpRules=null;
this.layout={topleft:[15,150],bottomright:[15+450,150+600],width:450,height:600};
this.resources={edit_button_id:"edit_"+id,edit_link_id:"editlink_"+id,discard_button_id:"discard_"+id,up_button_id:"up_"+id,down_button_id:"down_"+id,position_id:id+"_position",amazon_edit_id:id+"_amazon",poll_edit_id:id+"_poll",quiz_edit_id:id+"_quiz",draft_notice_id:"draft_notice",draft_revert_id:"draft_revert",json_links_id:"json_links_"+id,max_results_id:"max_"+id,inserter_cancel_id:"capsule_inserter_cancel_"+id,capsule_inserter_id:"capsule_inserter_"+id,inserter_id:"inserter_"+id,chooser_id:"capsule_chooser_"+id,link_edit_url:id+"_url_edit",link_edit_title:id+"_link_title",link_edit_desc:id+"_desc",link_edit_desc_len:id+"_len",link_drag_section:"link_drag_"+id,link_drag_title:"link_drag_txt_"+id,image_edit_id:"image_"+id,image_caption_input:"descinput_"+id,image_size_input:"sizeinput_"+id,image_display_style_id:"dispstyle_"+id,image_popup_id:"fullsize_"+id,image_upload_gif_id:"upload_gif_"+id,image_upload_status_id:"upload_status_"+id,image_upload_target_id:"upload_target_"+id,image_load_form_id:"add_image_form_"+id,image_import_id:"url_"+id,image_upload_id:"file_"+id,image_import_section_id:"image_import_"+id,image_upload_section_id:"image_upload_"+id,image_queue_id:"url_import_list_"+id,image_drag_section:"image_drag_"+id,image_drag_title:"image_drag_txt_"+id,image_selection_id:"image_selected_"+id,image_load_id:"image_load_"+id,image_web_radio_id:"image_web_radio_"+id,image_computer_radio_id:"image_computer_radio_"+id,image_viewer_display:"slide_display_"+id,image_viewer_caption:"slide_desc_"+id,video_edit_id:"video_"+id,video_url_input_id:"video_url_"+id,video_key_id:"video_key_"+id,video_type_id:"video_type_"+id,video_results_id:"video_results_"+id,text_edit_id:"txte_"+id,code_edit_id:"code_e_"+id,table_view_id:"div_table_view_"+id,table_edit_id:"div_table_edit_"+id,table_edit_content_id:"table_edit_"+id,table_view_content_id:"table_view_"+id,table_view_thead_id:"thead_view_"+id,table_view_tbody_id:"tbody_view_"+id,table_edit_thead_id:"thead_edit_"+id,table_edit_tbody_id:"tbody_edit_"+id,table_edit_form_id:"form_table_"+id,table_file_id:"file_"+id,table_url_id:"url_"+id,table_loading_id:"div_loading_"+id,table_action1_id:"table_action1_"+id,table_action2_id:"table_action2_"+id,table_action3_id:"table_action3_"+id,table_style_id:"table_style_"+id,table_loading_status_id:"div_loading_status_"+id,table_radio_current_id:"radio_current_"+id,table_radio_url_id:"radio_url_"+id,table_radio_pc_id:"radio_pc_"+id,table_div_current_id:"div_radio_current_"+id,table_div_url_id:"div_radio_url_"+id,table_div_pc_id:"div_radio_pc_"+id,table_previous_element:null,table_max_rows_id:"max_rows_"+id,table_max_cols_id:"max_cols_"+id,table_checkbox_sortable_id:"checkbox_sortable_"+id,table_caption_id:"table_caption_"+id,ebay_edit_id:id+"_ebay",ebay_results_id:id+"_ebay_results",ebay_preview_id:"preview_"+id,ebay_keywords_id:"keywords_"+id,ebay_seller_id:"seller_"+id};
};
ModuleEdit.Manager=null;
ModuleEdit.options={capsule_edit_reposition_duration:600,upload_status_hide_timeout:8*1000,drag_enabled:true,drag_reorder_enabled:true};
ModuleEdit.prototype.addNewAbove=function(_b2){
$(this.resources.chooser_id).hide();
$(this.resources.inserter_cancel_id).hide();
this.state.inserting=false;
ModuleEdit.Manager.addNew(_b2,this.data.position);
};
ModuleEdit.prototype.capsuleInsert=function(){
$(this.resources.chooser_id).show();
$(this.resources.inserter_cancel_id).show();
$(this.resources.inserter_id).hide();
this.state.inserting=true;
};
ModuleEdit.prototype.cancelCapsuleInsert=function(){
$(this.resources.chooser_id).hide();
$(this.resources.inserter_cancel_id).hide();
this.state.inserting=false;
};
ModuleEdit.prototype.toggleInserter=function(_b3){
if(this.state.inserting||ModuleEdit.Manager.editting){
return;
}
if(_b3){
$(this.resources.inserter_id).show();
}else{
$(this.resources.inserter_id).hide();
}
};
ModuleEdit.prototype.cleanUp=function(){
ModuleEdit.Manager=null;
this.editting=null;
this.data=null;
this.state=null;
};
ModuleEdit.make=function(_b4,_b5,_b6,_b7){
var _b8=new Ajax.Request("/xml/modules.php",{method:"post",parameters:"new=1&art_id="+_b5+"&type="+_b4+"&position="+_b6,onFailure:reportError,onComplete:_b7});
};
ModuleEdit.toggleIcon=function(ele,_ba){
ele=$(ele);
if(!ele){
return;
}
if(_ba){
ModuleEdit.disableIcon(ele);
}else{
ModuleEdit.reenableIcon(ele);
}
};
ModuleEdit.disableIcon=function(ele){
ele=$(ele);
if(!ele){
return;
}
ele.className="disabledicon";
var _bc=ele.firstChild;
if(!_bc.disabled){
var _bd=function(){
return false;
};
if(_bc.href&&_bc.href!="#"){
_bc.bhref=_bc.href;
}
if(_bc.onclick){
_bc.bonclick=_bc.onclick;
}
if(_bc.alt){
_bc.balt=_bc.alt;
}
if(_bc.title){
_bc.btitle=_bc.title;
}
_bc.alt="";
_bc.title="";
_bc.href="#";
_bc.onclick=_bd;
_bc.disabled=true;
}
};
ModuleEdit.reenableIcon=function(ele){
ele=$(ele);
if(!ele){
return;
}
ele.className="icon";
var _bf=ele.firstChild;
if(_bf.disabled){
if(_bf.bhref){
_bf.href=_bf.bhref;
}
if(_bf.bonclick){
_bf.onclick=_bf.bonclick;
}
if(_bf.balt){
_bf.alt=_bf.balt;
}
if(_bf.btitle){
_bf.title=_bf.btitle;
}
_bf.disabled=false;
}
};
ModuleEdit.getFromJSON=function(_c0){
var _c1=new ModuleEdit(_c0.data.mod_id);
Object.extend(_c1.data,_c0.data);
Object.extend(_c1.state,_c0.state);
return _c1;
};
ModuleEdit.toggleCurtain=function(){
var _c2=$("modalarea");
if(!_c2){
var _c3=new Insertion.Bottom(document.body,"<iframe class=\"modalarea\" style=\"display:none\" frameborder=\"0\" id=\"addcaps_modalarea\" src=\"about:blank\"></iframe>");
}
if(_c2&&_c2.style.display!="block"){
_c2.style.display="block";
_c2.style.left="0px";
_c2.style.top="0px";
ModuleEdit.stretchCurtain();
this.stretchListener=ModuleEdit.stretchCurtain.bindAsEventListener(this);
Event.observe(window,"resize",this.stretchListener,false);
}else{
_c2.style.display="none";
Event.stopObserving(window,"resize",this.stretchListener,false);
this.stretchListener=null;
}
};
ModuleEdit.stretchCurtain=function(){
var _c4=$("modalarea");
var _c5=20;
var _c6=Element.getHeight("content");
var _c7=Element.getHeight("sidebar");
_c4.style.width=(Element.getWidth("container")+_c5)+"px";
_c4.style.height=((_c6>_c7)?_c6:_c7)+"px";
};
ModuleEdit.prototype.toggle=function(){
if(!this.edditing&&this.data.type=="Table"){
$(this.resources.table_view_id).hide();
}
if(!this.editting&&this.data.type=="Poll"){
var _c8=$(this.data.mod_data_id+"_pollVotes");
if(null!=_c8){
var _c9=_c8.value;
if(_c9>0){
var _ca;
if(_c9==1){
_ca="1 vote that has been counted will be deleted.";
}else{
_ca=_c9+" votes that have been counted will be deleted.";
}
var _cb=confirm("Are you sure that you want to edit this poll? \n\nIf you make changes to the question or answer choices in this capsule, then the "+_ca);
if(!_cb){
return false;
}
}
}
}
this.editting=!this.editting;
if(this.editting){
this.state.original_html=$(this.data.div_id).innerHTML;
this.state.original_form=(this.data.type=="Text")?"":Form.serialize($(this.data.div_id),true);
this.data.hide=$(this.state.hide_id).checked;
this.state.original_hide=this.data.hide;
}
this._toggleTitle();
this._toggleBorder();
this._toggleEditButton();
this._toggleDiscardButton();
this._toggleDeleteButton();
this._toggleCapsuleInserter();
this._toggleZIndex();
this._toggleSize();
this._toggleDrag();
this._toggleEmptyNotification();
switch(this.data.type){
case "Text":
this.toggleText();
break;
case "Ebay":
this.toggleEbay();
break;
case "Amazon":
this.toggleAmazon();
break;
case "Rss":
this.toggleRss();
break;
case "News":
this.toggleNews();
break;
case "Link":
this.toggleLink();
break;
case "Image":
this.toggleImage();
break;
case "Video":
this.toggleVideo();
break;
case "Comment":
this.toggleComment();
break;
case "Poll":
this.togglePoll();
break;
case "Code":
this.toggleCode();
break;
case "Table":
this.toggleTable();
break;
case "Quiz":
this.toggleQuiz();
break;
case "Map":
this.toggleMap();
break;
}
if(this.editting){
this.setDirty();
}else{
this.save();
}
this.render();
return true;
};
ModuleEdit.prototype._toggleCapsuleInserter=function(){
if(this.editting){
$(this.resources.capsule_inserter_id).hide();
}else{
$(this.resources.capsule_inserter_id).show();
}
};
ModuleEdit.prototype._toggleZIndex=function(){
var _cc=this.state.div_ele;
if(this.editting){
_cc.style.zIndex="10";
}else{
_cc.style.zIndex="1";
}
};
ModuleEdit.prototype._toggleSize=function(){
var _cd=$(this.data.div_id);
if(this.editting){
var _ce=5;
var _cf=102;
var _d0=0.15;
var _d1=ModuleEdit.options.capsule_edit_reposition_duration;
var _d2=$("modules");
var _d3=Position.positionedOffset(_cd);
var _d4=620+(_ce*2);
var _d5=ModuleEdit.Manager.layout;
var _d6=_d5.viewportScroll[1]+(_d5.viewportSize[1]*_d0);
_cd.style.width=_d4+"px";
var _d7=new fx.Position(_cd,{duration:_d1});
_cd.style.position="absolute";
Position.set(_cd,_d3);
_d7.move(_d3,[_cf,_d6]);
this.computeState();
}else{
_cd.style.display="inline";
_cd.style.position="static";
_cd.style.width="auto";
_cd.style.top=_cd.style.left="0px";
}
};
ModuleEdit.prototype._toggleDrag=function(){
var _d8=$(this.data.div_id);
var _d9=$("dragbar_"+this.data.id);
if(ModuleEdit.options.drag_enabled&&this.editting){
var d=new Dragger(_d8,false);
_d9.style.cursor="move";
Event.observe(_d9,"mousedown",(function(){
d.start();
return false;
}).bind(d),false);
Event.observe(document,"mouseup",d.stop.bind(d),false);
}else{
_d9.style.cursor="default";
}
};
ModuleEdit.prototype._toggleEmptyNotification=function(){
if(this.editting&&this.data.div_id){
Element.hide(this.state.empty_notification_id);
}
};
ModuleEdit.prototype._toggleTitle=function(){
var _db=$(this.state.title_id);
if(!_db){
return;
}
if(this.editting){
$(this.state.title_input_id).value=$(this.state.title_id).innerHTML;
}else{
this.data.title=$F(this.state.title_input_id).replace(/<[^>]+(>|$)/g,"");
if(this.data.title!==null){
Element.update(this.state.title_id,this.data.title);
if(this.data.title==""){
$(this.state.title_id).style.display="none";
}else{
$(this.state.title_id).style.display="";
}
}
}
this.toggleDisplay(this.state.colorbar_id);
this.toggleDisplay(this.state.hidebar_id);
this.toggleDisplay(this.state.titlebar_id);
this.toggleDisplay(_db,!this.editting);
};
ModuleEdit.prototype.toggleQuiz=function(){
if(this.editting){
$(this.state.content_id).hide();
this.state.questions_removed=[];
this.state.quiz=JSONstring.toObject($(this.state.quiz_json_id).innerHTML);
this.quizBuildInterface();
if($(this.state.quiz_question_drag_area_id)&&!this.state.reorder){
this.quizCreateContentReorder();
}
var _dc=$H(this.state.quiz.questions).values();
var _dd=new Array();
_dc.each(function(q){
_dd[q.position]=q;
});
_dd.each(function(q){
if(!q.id){
return;
}
this.quizBuildQuestion(q.question,q.id);
var _e0=$H(q.answers).values();
_e0.each(function(a,_e2){
if(!a.id){
return;
}
this.quizBuildAnswerChoice(q.id,a.id,_e2>2,a.value,a.answer,a.resultValues);
}.bind(this));
}.bind(this));
}else{
$(this.state.content_id).show();
if(this.data.dirty&&this.state.quiz.quizTypeId>0){
if(this.state.select_id){
this.toggleAnswersForQuizQuestion(null,this.state.select_id,0);
}
if(this.state.select_result_id){
this.toggleQuizResult(null,this.state.select_result_id,0);
}
var _e3=this.state.reorder.getitemstate();
_e3.each(function(_e4){
this.state.quiz.questions[_e4.id].position=_e4.position;
}.bind(this));
this.state.questions_removed.each(function(_e5){
this.state.quiz.questions[_e5].position=-1;
}.bind(this));
var _e6=this.state.quiz.quizTypeId;
if(_e6==1||_e6==2){
this.state.quiz.resultSentence=$F(this.state.quiz_result_sentence_id);
var _e7=$A();
var _e8=$A();
var _dc=$H(this.state.quiz.questions).values();
_dc.each(function(q){
if(!q.id||q.position==-1){
return;
}
var _ea=$H(q.answers).values();
minQuestionScore=9999;
_ea.each(function(an){
if(an.id&&!an.isDeleted){
minQuestionScore=Math.min(minQuestionScore,an.value);
}
});
maxQuestionScore=-9999;
_ea.each(function(an){
if(an.id&&!an.isDeleted){
maxQuestionScore=Math.max(maxQuestionScore,an.value);
}
});
_e7.push(minQuestionScore);
_e8.push(maxQuestionScore);
});
var _ed=_e7.inject(0,function(acc,n){
return acc+(+n);
});
var _f0=_e8.inject(0,function(acc,n){
return acc+(+n);
});
this.state.quiz.minimumScore=_ed;
this.state.quiz.maximumScore=_f0;
var _f3=_f0-_ed;
var _f4=$H(this.state.quiz.results).values();
i=0;
var _f5=_ed;
_f4.each(function(r){
if(!r.id){
return;
}
var _f7=this.state.quiz_score_ranges[i];
var _f8;
if(_f7==100){
_f8=_f0;
}else{
_f8=Math.floor(_f7*_f3/100+_ed);
}
this.state.quiz.results[r.id]={id:r.id,minimumValue:_f5,maximumValue:_f8,description:$F(this.state.quiz_result_description_id+r.id),result:"",isDeleted:r.isDeleted};
_f5=_f8;
i++;
}.bind(this));
}
this.data.quiz_json=JSONstring.make(this.state.quiz);
$(this.state.quiz_json_id).innerHTML=this.data.quiz_json;
}
$(this.state.quiz_edit_id).innerHTML="";
delete this.state.reorder;
}
this.toggleDisplay(this.resources.quiz_edit_id);
};
ModuleEdit.prototype._renderQuiz=function(){
if(!$(this.state.quiz_json_id)){
return;
}
this.state.quiz=JSONstring.toObject($(this.state.quiz_json_id).innerHTML);
var _f9=$(this.state.quiz_rendered_id);
_f9.innerHTML="";
if(this.state.quiz.quizTypeId==0){
return;
}
if(this.state.quiz.error){
_f9.innerHTML="<p class=\"error\">"+this.state.quiz.error+" No one will be able to take your quiz until you fix the problem.</p>";
return;
}
var _fa=0;
var _fb=$H(this.state.quiz.questions).values();
if(this.state.floatright){
_fb.each(function(q){
if(!q.id){
return;
}
var _fd=Math.ceil(q.question.length/22)+2;
var _fe=$H(q.answers).values();
_fe.each(function(a){
if(!a.id){
return;
}
_fd+=1+Math.ceil(a.answer.length/25);
});
if(_fd>_fa){
_fa=_fd;
}
});
var _100=9+_fa;
if(this.state.quiz.quizTypeId==1){
_100+=3;
}
}else{
_fb.each(function(q){
if(!q.id){
return;
}
var _102=Math.ceil(q.question.length/75)+2;
var _103=$H(q.answers).values();
_103.each(function(a){
if(!a.id){
return;
}
_102+=1+Math.ceil(a.answer.length/75);
});
if(_102>_fa){
_fa=_102;
}
});
var _100=9+_fa;
if(this.state.quiz.quizTypeId==1){
_100+=2;
}
}
var _105=0;
var _106=$H(this.state.quiz.results).values();
if(this.state.floatright){
_106.each(function(r){
if(!r.id){
return;
}
var _108=Math.ceil(r.description.length/32);
if(_108>_105){
_105=_108;
}
});
var _109=Math.ceil(this.state.quiz.resultSentence.length/17*1.6);
var _10a=_105+_109+13;
if(this.state.quiz.quizTypeId==1){
_10a+=3;
}
}else{
_106.each(function(r){
if(!r.id){
return;
}
var _10c=Math.ceil(r.description.length/75);
if(_10c>_105){
_105=_10c;
}
});
var _109=Math.ceil(this.state.quiz.resultSentence.length/56*1.6);
var _10a=_105+_109+13;
if(this.state.quiz.quizTypeId==1){
_10a+=2;
}
}
var _10d=Math.max(_100,_10a);
_10d=Math.max(18,_10d);
height=14*_10d;
var _10e=this.state.floatright?240:520;
var _10f="color0";
if(this.state.floatright){
var _110=$w($(this.state.content_id).className);
_110.each(function(_111){
if(_111.indexOf("color")!=-1){
_10f=_111;
throw $break;
}
});
}
_f9.innerHTML="<embed src=\"/quizwidget/Widget.swf\" width=\""+_10e+"\" height=\""+height+"\" align=\"middle\" name=\"Widget"+this.data.id+"\" wmode=\"opaque\" play=\"true\" loop=\"false\" quality=\"high\" flashvars=\"id="+this.data.mod_data_id+"&cssClass="+_10f+"\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\"></embed>";
};
ModuleEdit.prototype.quizUpdateType=function(){
var _112=Form.getInputs(this.state.quiz_type_form_id,"radio",this.state.quiz_type_name_id).find(function(_113){
return _113.checked;
}).value;
this.state.quiz.quizTypeId=_112;
this.quizBuildInterface();
};
ModuleEdit.prototype.quizBuildInterface=function(){
var _114=new Array();
_114[1]="Add some questions and answer choices to your quiz. Mark the correct answer to each question by checking the radio button next to the right answer. Click on the edit quiz results link to change the messages that are displayed to people when they are done taking your quiz.";
_114[2]="Add some questions and answer choices to your quiz. For each answer choice, decide how many points that answer choice is worth (between -5 and +5) and select that number from the menu. Click on the edit quiz results link to change the messages that are displayed to people when they are done taking your quiz.";
_114[3]="Add a result for each possible outcome of your quiz. For example, if your quiz tells someone whether they are type A or type B, add one result called \"type A\" and another result called \"type B.\" Then add some questions and answer choices. For each answer choice, decide how many points are contributed to each result possibility when someone chooses that answer. At the end of the quiz, the result with the largest number of points will be the one that is displayed to the quiz taker.";
var _115=$(this.state.quiz_edit_id);
_115.innerHTML="";
var _116=this.state.quiz.quizTypeId;
if(_116==0){
var _117=new Array();
_117[1]="<strong>Option 1.</strong> Every question has exactly one correct answer. <div class=\"quizTypeDescription\">* Good for fact-based quizzes such as a movie trivia quiz.</div>";
_117[2]="<strong>Option 2.</strong> Every answer choice is worth a different numbers of points. <div class=\"quizTypeDescription\">* Good for quizzes that measure where someone falls between two extremes, such as: How liberal are you?</div>";
_117[3]="<strong>Option 3.</strong> A quiz with multiple possible results. <div class=\"quizTypeDescription\">* Good for quizzes that tell someone what type they are, such as what political party they identify most with.</div>";
var _118=$(document.createElement("form"));
_118.name=this.state.quiz_type_form_id;
_118.id=this.state.quiz_type_form_id;
var ul=$(document.createElement("ul"));
ul.addClassName("quizTypeList");
for(var i=1;i<=3;i++){
var li=$(document.createElement("li"));
var name=this.state.quiz_type_name_id;
var _11d="<input type=\"radio\" name=\""+name+"\" value=\""+i+"\"/>";
var div=$(document.createElement("div"));
div.className="quizType";
div.innerHTML=_117[i];
li.innerHTML=_11d;
li.appendChild(document.createTextNode(" "));
li.appendChild(div);
ul.appendChild(li);
}
var _11f=$(document.createElement("input"));
_11f.type="button";
_11f.value="Next step &raquo;".unescapeHTML();
_11f.observe("click",this.quizUpdateType.bind(this));
_118.appendChild(ul);
_118.appendChild(_11f);
var h2=$(document.createElement("h2"));
h2.appendChild($(document.createTextNode("What type of quiz do you want to make?")));
_115.appendChild(h2);
_115.appendChild(_118);
return;
}else{
var _121=$(document.createElement("p"));
_121.appendChild($(document.createTextNode(_114[_116])));
var _122=$(document.createElement("h3"));
_122.appendChild($(document.createTextNode("Instructions")));
_115.appendChild(_122);
_115.appendChild(_121);
}
var _123=$(document.createElement("div"));
_123.id=this.state.quiz_results_id;
_123.addClassName("resultArea");
_115.appendChild(_123);
if(_116==1||_116==2){
this.quizBuildResultBar(0,"Quiz Results",0);
this.quizBuildResultsByPercentageScore(0);
}else{
if(_116==3){
var _124=$H(this.state.quiz.results).values();
_124.each(function(r){
if(!r.id){
return;
}
this.quizBuildResult(r.id,r.result,r.description);
}.bind(this));
var _126=$(document.createElement("form"));
var _127=$(document.createElement("label"));
_127.htmlFor=this.state.quiz_result_add_input_id;
_127.appendChild($(document.createTextNode("Name of Result: ")));
var _128=$(document.createElement("input"));
_128.type="text";
_128.id=this.state.quiz_result_add_input_id;
_128.addClassName("quizResultInput");
_128.maxLength=120;
var _129=$(document.createElement("input"));
_129.type="button";
_129.value="Add Result";
_129.observe("click",this.quizAddResult.bind(this));
_126.observe("submit",function(e){
Event.stop(e);
this.quizAddResult();
return false;
}.bindAsEventListener(this));
_126.appendChild(_127);
_126.appendChild(_128);
_126.appendChild(_129);
_115.appendChild(_126);
}
}
var _12b=$(document.createElement("form"));
var _12c=$(document.createElement("label"));
_12c.htmlFor=this.state.quiz_question_add_input_id;
_12c.appendChild($(document.createTextNode("Question: ")));
var _12d=$(document.createElement("input"));
_12d.type="text";
_12d.id=this.state.quiz_question_add_input_id;
_12d.addClassName("quizQuestionInput");
_12d.maxLength=120;
var _11f=$(document.createElement("input"));
_11f.type="button";
_11f.value="Add Question";
var _12e=$(document.createElement("div"));
_12e.addClassName("questionDragArea");
_12e.id=this.state.quiz_question_drag_area_id;
var _12f=$(document.createElement("small"));
_12f.appendChild($(document.createTextNode("*Drag and drop questions to reorder them.")));
_115.appendChild(_12e);
_12b.appendChild(_12c);
_12b.appendChild(_12d);
_12b.appendChild(_11f);
_115.appendChild(_12b);
_115.appendChild(_12f);
_11f.observe("click",this.quizAddQuestion.bind(this));
_12b.observe("submit",function(e){
Event.stop(e);
this.quizAddQuestion();
}.bind(this));
this.quizCreateContentReorder();
};
ModuleEdit.prototype.quizBuildResultsByPercentageScore=function(id){
var _132=$(document.createElement("div"));
_132.id=this.state.quiz_result_area_id+id;
_132.addClassName("editResultArea");
var _133=$(document.createElement("p"));
_133.appendChild($(document.createTextNode("Choose the message that will be displayed when someone is done taking your quiz. Any occurrence of the characters #% will be replaced with the person's percentage score. For example, \"You scored #% on the intelligence test!\" might become \"You scored 87% on the intelligence test!\"")));
var _134=$(document.createElement("label"));
_134.appendChild($(document.createTextNode("Message: ")));
var _135=$(document.createElement("input"));
_135.type="text";
_135.value=this.state.quiz.resultSentence.unescapeHTML();
_135.id=this.state.quiz_result_sentence_id;
_135.addClassName("quizResultSentence");
_135.maxLength=120;
var _136=$(document.createElement("p"));
_136.appendChild($(document.createTextNode("You can display a custom message depending on how someone scores on your quiz. Type your custom messages in the boxes below.")));
_132.appendChild(_133);
_132.appendChild(_134);
_132.appendChild(_135);
_132.appendChild(_136);
var _137=this.state.quiz_score_ranges;
var _138=0;
var i=0;
var list=$(document.createElement("ol"));
list.addClassName("messageByPercent");
var _13b=$H(this.state.quiz.results).values();
_13b.each(function(r){
if(!r.id){
return;
}
var item=$(document.createElement("li"));
var _13e=_137[i];
var _13f=$(document.createElement("label"));
_13f.htmlFor=this.state.quiz_result_description_id+r.id;
_13f.appendChild(document.createTextNode("For a score between "+_138+"% and "+_13e+"%: "));
item.appendChild(_13f);
var _140=$(document.createElement("textarea"));
_140.appendChild($(document.createTextNode(r.description.unescapeHTML())));
_140.id=this.state.quiz_result_description_id+r.id;
item.appendChild(_140);
list.appendChild(item);
_138=_13e;
i++;
}.bind(this));
for(;i<_137.length;i++){
var item=$(document.createElement("li"));
var _142="new"+i;
score=_137[i];
var _134=$(document.createElement("label"));
_134.htmlFor=this.state.quiz_result_description_id+_142;
_134.appendChild(document.createTextNode("For a score between "+_138+"% and "+score+"%:"));
item.appendChild(_134);
var _143=$(document.createElement("textarea"));
_143.id=this.state.quiz_result_description_id+_142;
item.appendChild(_143);
list.appendChild(item);
_138=score;
this.state.quiz.results[_142]={id:_142,description:"",result:"",minimumValue:0,maximumValue:0,isDeleted:0};
}
_132.appendChild(list);
_132.hide();
$(this.state.quiz_results_id).appendChild(_132);
};
ModuleEdit.prototype.quizBuildResult=function(id,_145,_146,_147){
_145=_145.unescapeHTML();
_146=_146.unescapeHTML();
this.quizBuildResultBar(id,_145,_147);
var _148=$(document.createElement("div"));
_148.id=this.state.quiz_result_area_id+id;
_148.addClassName("editResultArea");
var _149=$(document.createElement("label"));
_149.appendChild($(document.createTextNode("Result Name: ")));
_149.htmlFor=this.state.quiz_result_name_id+id;
var _14a=$(document.createElement("input"));
_14a.type="text";
_14a.value=_145;
_14a.addClassName("quizResultInput");
_14a.id=this.state.quiz_result_name_id+id;
_14a.observe("keyup",function(id){
$(this.state.quiz_result_span_id+id).innerHTML=$F(this.state.quiz_result_name_id+id);
}.bind(this,id));
var _14c=$(document.createElement("label"));
_14c.appendChild($(document.createTextNode("Explain the meaning of this result: ")));
_14c.htmlFor=this.state.quiz_result_description_id+id;
var _14d=$(document.createElement("textarea"));
_14d.appendChild($(document.createTextNode(_146)));
_14d.id=this.state.quiz_result_description_id+id;
var _14e=$(document.createElement("p"));
var _14f=$(document.createElement("small"));
_14f.appendChild($(document.createTextNode("This will be the payoff for taking your quiz, so make it good!")));
_14e.appendChild(_14f);
_148.appendChild(_149);
_148.appendChild(_14a);
_148.appendChild(_14c);
_148.appendChild(_14d);
_148.appendChild(_14e);
_148.hide();
$(this.state.quiz_results_id).appendChild(_148);
this.state.quiz.results[id]={id:id,result:_145,description:_146,minimumValue:0,maximumValue:0,isDeleted:0};
};
ModuleEdit.prototype.quizAddResult=function(){
if(this.state.select_id){
this.toggleAnswersForQuizQuestion(null,this.state.select_id,0);
}
var _150="new"+this.state.results_added;
this.state.results_added++;
var _151=$F(this.state.quiz_result_add_input_id);
$(this.state.quiz_result_add_input_id).value="";
this.quizBuildResult(_150,_151,"",1);
this.quizUpdateResultSelectors();
this.toggleQuizResult(null,_150,1);
};
ModuleEdit.prototype.quizUpdateResultSelectors=function(){
var _152=$H(this.state.quiz.questions).values();
var _153=$H(this.state.quiz.results).values();
_152.each(function(q){
if(!q.id||q.position==-1){
return;
}
var _155=$H(q.answers).values();
_155.each(function(a){
if(!a.id||a.isDeleted){
return;
}
_153.each(function(r){
if(!r.id){
return;
}
var _158=$(this.state.quiz_value_id+a.id+"_"+r.id);
if(r.isDeleted&&_158){
$(this.state.quiz_value_label_id+a.id+"_"+r.id).remove();
Element.remove(_158);
return;
}
if(!r.isDeleted&&!_158){
var _159=$(this.state.quiz_result_values_id+a.id);
var _158=$(document.createElement("select"));
_158.id=this.state.quiz_value_id+a.id+"_"+r.id;
var _15a=$(document.createElement("label"));
_15a.htmlFor=_158.id;
_15a.appendChild(document.createTextNode(r.result+": "));
_15a.id=this.state.quiz_value_label_id+a.id+"_"+r.id;
for(var i=5;i>=-5;i--){
var _15c=$(document.createElement("option"));
_15c.value=i;
_15c.appendChild($(document.createTextNode(i>0?"+"+i:i)));
_158.appendChild(_15c);
if(0==i){
_15c.selected="selected";
}
}
_159.appendChild(_15a);
_159.appendChild(_158);
_159.appendChild($(document.createTextNode(" ")));
this.state.quiz.questions[q.id].answers[a.id].resultValues["rv"+r.id]=0;
}
}.bind(this));
}.bind(this));
}.bind(this));
};
ModuleEdit.prototype.toggleQuizResult=function(e,id,show){
if(show){
$(this.state.quiz_result_area_id+id).show();
$(this.state.quiz_edit_result_id+id).hide();
$(this.state.quiz_done_result_id+id).show();
if(this.state.select_result_id){
this.toggleQuizResult(null,this.state.select_result_id,0);
}
this.state.select_result_id=id;
}else{
$(this.state.quiz_result_area_id+id).hide();
$(this.state.quiz_edit_result_id+id).show();
$(this.state.quiz_done_result_id+id).hide();
if(this.state.select_result_id&&this.state.select_result_id==id){
this.state.select_result_id=null;
}
if(this.state.quiz.quizTypeId==3){
this.state.quiz.results[id].description=$F(this.state.quiz_result_description_id+id);
this.state.quiz.results[id].result=$F(this.state.quiz_result_name_id+id);
}
}
if(e){
Event.stop(e);
}
};
ModuleEdit.prototype.quizBuildResultBar=function(id,_161,_162){
var _163=$(this.state.quiz_results_id);
var _164=$(document.createElement("div"));
_164.addClassName("resultBar");
_164.id=this.state.quiz_result_id+id;
var _165=$(document.createElement("span"));
_165.appendChild($(document.createTextNode(_161)));
_165.id=this.state.quiz_result_span_id+id;
var _166=$(document.createElement("ul"));
_166.addClassName("quizButtons");
var _167=$(document.createElement("li"));
var _168=$(document.createElement("a"));
var _169=$(document.createElement("img"));
_169.src="/x/hubtool_discard_tag.gif";
_169.alt="delete";
_168.title="delete";
_168.href="#";
_168.appendChild(_169);
Event.observe(_168,"click",this.quizDeleteResult.bindAsEventListener(this,id));
_167.appendChild(_168);
_166.appendChild(_167);
var _16a=$(document.createElement("li"));
_16a.id=this.state.quiz_edit_result_id+id;
var _16b=$(document.createElement("a"));
_16b.appendChild($(document.createTextNode("edit")));
_16b.href="#";
Event.observe(_16b,"click",this.toggleQuizResult.bindAsEventListener(this,id,1));
_16a.appendChild(_16b);
_166.appendChild(_16a);
var _16c=$(document.createElement("li"));
_16c.id=this.state.quiz_done_result_id+id;
var _16d=$(document.createElement("a"));
_16d.href="#";
_16d.appendChild($(document.createTextNode("done")));
Event.observe(_16d,"click",this.toggleQuizResult.bindAsEventListener(this,id,0));
_16c.hide();
_16c.appendChild(_16d);
_166.appendChild(_16c);
_164.appendChild(_166);
_164.appendChild(_165);
_163.appendChild(_164);
};
ModuleEdit.prototype.quizCreateContentReorder=function(){
this.state.reorder=new ModuleContentReorder(this.state.quiz_question_drag_area_id,1,550,20);
};
ModuleEdit.prototype.quizBuildAnswerChoice=function(_16e,_16f,_170,_171,_172,_173){
_172=_172.unescapeHTML();
var item=$(document.createElement("li"));
item.id=this.state.quiz_answer_li_id+_16f;
item.addClassName("quizAdded");
var _175=this.state.quiz.quizTypeId;
if(_175==1){
var name=this.state.quiz_value_id+_16e;
var id=this.state.quiz_value_id+_16f;
var _178=(_171>0)?"checked=\"checked\"":"";
var _179="<input type=\"radio\" name=\""+name+"\" id=\""+id+"\" class=\"correctAnswerRadio\" "+_178+"/>";
}else{
if(_175==2){
var _17a=$(document.createElement("select"));
_17a.id=this.state.quiz_value_id+_16f;
for(var i=5;i>=-5;i--){
var _17c=$(document.createElement("option"));
_17c.value=i;
_17c.appendChild($(document.createTextNode((i>0?"+":"")+i)));
if(_171==i){
_17c.selected="selected";
}
_17a.appendChild(_17c);
}
}else{
if(_175==3){
var _17d=$H(this.state.quiz.results).values();
var _17e=$(document.createElement("div"));
_17e.id=this.state.quiz_result_values_id+_16f;
_17d.each(function(r){
if(!r.id){
return;
}
var _180=$(document.createElement("select"));
_180.id=this.state.quiz_value_id+_16f+"_"+r.id;
var _181=$(document.createElement("label"));
_181.htmlFor=_180.id;
_181.appendChild(document.createTextNode(r.result+": "));
_181.id=this.state.quiz_value_label_id+_16f+"_"+r.id;
for(var i=5;i>=-5;i--){
var _183=$(document.createElement("option"));
_183.value=i;
_183.appendChild($(document.createTextNode(i>0?"+"+i:i)));
_180.appendChild(_183);
if(_173&&_173["rv"+r.id]==i){
_183.selected="selected";
}
}
_17e.appendChild(_181);
_17e.appendChild(_180);
_17e.appendChild($(document.createTextNode(" ")));
}.bind(this));
}
}
}
var _184=$(document.createElement("input"));
_184.type="text";
_184.id=this.state.quiz_answer_id+_16f;
_184.value=_172;
_184.addClassName("quizAnswerInput");
_184.maxLength=120;
if(_175==1){
item.innerHTML=_179;
}
item.appendChild(_184);
if(_175==2){
item.appendChild(_17a);
}
if(_170){
var _185=$(document.createElement("a"));
var _186=$(document.createElement("img"));
_185.href="#";
_185.title="delete";
_185.addClassName("quizDeleteAnswer");
_186.src="/x/hubtool_discard_tag.gif";
_186.alt="delete";
_185.appendChild(_186);
item.appendChild(_185);
Event.observe(_185,"click",this.quizDeleteAnswer.bindAsEventListener(this,_16e,_16f));
}
if(_175==3){
item.appendChild(_17e);
}
$(this.state.quiz_answer_list_id+_16e).appendChild(item);
if(!_172){
_172="";
}
if(!_173){
_173={};
}
this.state.quiz.questions[_16e].answers[_16f]={id:_16f,answer:_172,value:_171,resultId:0,isDeleted:0,resultValues:_173};
};
ModuleEdit.prototype.quizAddAnswerChoice=function(_187,_188,_189){
var _18a="new"+this.state.answers_added;
this.state.answers_added++;
if(this.state.quiz.quizTypeId==3){
var _18b=$H(this.state.quiz.results).values();
var _18c={};
_18b.each(function(r){
if(!r.id||r.isDeleted){
return;
}
_18c["rv"+r.id]=0;
});
}
this.quizBuildAnswerChoice(_187,_18a,_188,_189,"",_18c);
};
ModuleEdit.prototype.quizDeleteAnswer=function(e,_18f,_190){
if(this.state.quiz.quizTypeId==1&&$(this.state.quiz_value_id+_190).checked){
var _191=$H(this.state.quiz.questions[_18f].answers).values();
_191.each(function(an){
if(!an.id||an.isDeleted){
return;
}
$(this.state.quiz_value_id+an.id).checked="checked";
throw $break;
}.bind(this));
}
$(this.state.quiz_answer_li_id+_190).remove();
this.state.quiz.questions[_18f].answers[_190].isDeleted=1;
if(e){
Event.stop(e);
}
};
ModuleEdit.prototype.quizDeleteResult=function(e,_194){
if(this.state.select_result_id==_194){
this.state.select_result_id=null;
}
$(this.state.quiz_result_id+_194).remove();
$(this.state.quiz_result_area_id+_194).remove();
this.state.quiz.results[_194].isDeleted=1;
this.quizUpdateResultSelectors();
if(e){
Event.stop(e);
}
};
ModuleEdit.prototype.quizDeleteQuestion=function(e,_196){
if(this.state.select_id==_196){
this.state.select_id=null;
}
this.state.reorder.remove(_196);
this.state.questions_removed.push(_196);
$(this.state.quiz_answer_area_id+_196).remove();
if(e){
Event.stop(e);
}
};
ModuleEdit.prototype.quizBuildQuestion=function(_197,_198){
_197=_197.unescapeHTML();
var _199=$(document.createElement("div"));
_199.addClassName("draggableQuestionBar");
_199.id=this.state.quiz_question_id+_198;
_199.onclick=function(){
};
var _19a=$(document.createElement("div"));
_19a.addClassName("editAnswerArea");
_19a.hide();
_19a.id=this.state.quiz_answer_area_id+_198;
var _19b=$(document.createElement("ul"));
_19b.addClassName("quizButtons");
var _19c=$(document.createElement("li"));
var _19d=$(document.createElement("a"));
var _19e=$(document.createElement("img"));
_19e.src="/x/hubtool_discard_tag.gif";
_19e.alt="delete";
_19d.title="delete";
_19d.href="#";
_19d.appendChild(_19e);
Event.observe(_19d,"click",this.quizDeleteQuestion.bindAsEventListener(this,_198));
_19c.appendChild(_19d);
_19b.appendChild(_19c);
var _19f=$(document.createElement("li"));
_19f.id=this.state.quiz_edit_question_id+_198;
var _1a0=$(document.createElement("a"));
_1a0.appendChild($(document.createTextNode("edit")));
_1a0.href="#";
Event.observe(_1a0,"click",this.toggleAnswersForQuizQuestion.bindAsEventListener(this,_198,1));
_19f.appendChild(_1a0);
_19b.appendChild(_19f);
var _1a1=$(document.createElement("li"));
_1a1.id=this.state.quiz_done_question_id+_198;
var _1a2=$(document.createElement("a"));
_1a2.href="#";
_1a2.appendChild($(document.createTextNode("done")));
Event.observe(_1a2,"click",this.toggleAnswersForQuizQuestion.bindAsEventListener(this,_198,0,1));
_1a1.hide();
_1a1.appendChild(_1a2);
_19b.appendChild(_1a1);
var _1a3=$(document.createElement("span"));
_1a3.appendChild($(document.createTextNode(_197.truncate(this.state.truncated_question_length))));
_1a3.id=this.state.quiz_question_span_id+_198;
var _1a4=$(document.createElement("label"));
_1a4.appendChild(document.createTextNode("Question: "));
var _1a5=$(document.createElement("input"));
_1a5.type="text";
_1a5.id=this.state.quiz_question_input_id+_198;
_1a5.hide();
_1a5.value=_197;
_1a5.maxLength=120;
_1a5.addClassName("quizQuestionInput");
_199.appendChild(_19b);
_199.appendChild(_1a3);
var _1a6=$(document.createElement("ol"));
_1a6.id=this.state.quiz_answer_list_id+_198;
_1a6.addClassName("quizAnswerList");
var _1a7=$(document.createElement("input"));
_1a7.type="button";
_1a7.value="add new answer choice";
_19a.appendChild(_1a4);
_19a.appendChild(_1a5);
_19a.appendChild(_1a6);
_19a.appendChild(_1a7);
_1a7.observe("click",function(_1a8){
this.quizAddAnswerChoice(_1a8,1,0);
this.quizRearrangeItems(_1a8);
}.bind(this,_198));
_1a5.observe("keyup",function(_1a9){
$(this.state.quiz_question_span_id+_1a9).innerHTML=$F(this.state.quiz_question_input_id+_1a9).truncate(this.state.truncated_question_length);
}.bind(this,_198));
var _1aa=$(this.state.quiz_question_drag_area_id);
_1aa.appendChild(_199);
_1aa.appendChild(_19a);
var _1ab=new ModuleContentReorderItem(this.state.quiz_question_id+_198,_198,this.state.reorder);
this.state.reorder.add(_1ab);
this.state.reorder.relayout();
this.state.quiz.questions[_198]={id:_198,question:_197,answers:{}};
};
ModuleEdit.prototype.quizAddQuestion=function(){
var _1ac="new"+this.state.questions_added;
this.state.questions_added++;
var _1ad=$F(this.state.quiz_question_add_input_id);
$(this.state.quiz_question_add_input_id).value="";
this.quizBuildQuestion(_1ad,_1ac);
for(var i=0;i<2;i++){
this.quizAddAnswerChoice(_1ac,0,i==0&&this.state.quiz.quizTypeId==1?1:0);
}
this.toggleAnswersForQuizQuestion(null,_1ac,1);
};
ModuleEdit.prototype.updateQuizStateForQuestion=function(_1af){
var _1b0=this.state.quiz.questions[_1af];
_1b0.question=$F(this.state.quiz_question_input_id+_1af);
var _1b1=$H(_1b0.answers).values();
_1b1.each(function(_1b2,a){
if(!a.id||a.isDeleted){
return;
}
this.state.quiz.questions[_1b2].answers[a.id].answer=$F(this.state.quiz_answer_id+a.id);
var _1b4=this.state.quiz.quizTypeId;
if(_1b4==1){
this.state.quiz.questions[_1b2].answers[a.id].value=$(this.state.quiz_value_id+a.id).checked?1:0;
}else{
if(_1b4==2){
this.state.quiz.questions[_1b2].answers[a.id].value=$(this.state.quiz_value_id+a.id).value;
}else{
if(_1b4==3){
var _1b5=$H(this.state.quiz.results).values();
resultValues={};
var i=0;
_1b5.each(function(r){
if(!r.id||r.isDeleted){
return;
}
var val=$F(this.state.quiz_value_id+a.id+"_"+r.id);
resultValues["rv"+r.id]=val;
}.bind(this));
this.state.quiz.questions[_1b2].answers[a.id].resultValues=resultValues;
}
}
}
}.bind(this,_1af));
};
ModuleEdit.prototype.quizRearrangeItems=function(_1b9){
var _1ba=_1b9;
var _1bb=this.state.reorder.items;
var _1bc=this.state.reorder.options;
var _1bd=this.state.reorder.canvas;
var i=0;
var item=_1bb[0];
while(item.item_id!=_1ba){
item=_1bb[++i];
}
var _1c0=$(this.state.quiz_answer_area_id+_1ba);
var rows=Math.ceil(_1bb.length/_1bc.num_cols);
var _1c2=(rows*(_1bc.ele_space_per_v))+_1c0.getHeight()+_1bc.ele_buffer_v;
if(_1c2!=parseInt(_1bd.style.height,10)){
_1bd.style.height=_1c2+"px";
}
var top=(Math.floor((i+1)/_1bc.num_cols))*_1bc.ele_space_per_v;
_1c0.setStyle({position:"absolute",top:top+"px"});
offset=_1c0.getHeight()+_1bc.ele_buffer_v+_1bc.offset_v;
for(i++;i<_1bb.length;i++){
item=_1bb[i];
var _1c4=Math.floor(i/_1bc.num_cols);
var top=(_1c4*_1bc.ele_space_per_v)+offset;
$(this.state.quiz_question_id+item.item_id).setStyle({top:top+"px"});
}
};
ModuleEdit.prototype.toggleAnswersForQuizQuestion=function(e,_1c6,show,_1c8){
if(show){
if(this.state.select_id){
this.toggleAnswersForQuizQuestion(null,this.state.select_id,0,0);
}
this.quizRearrangeItems(_1c6);
$(this.state.quiz_answer_area_id+_1c6).show();
$(this.state.quiz_question_input_id+_1c6).show();
$(this.state.quiz_edit_question_id+_1c6).hide();
$(this.state.quiz_done_question_id+_1c6).show();
this.state.select_id=_1c6;
this.state.reorder.disable();
}else{
this.state.reorder.relayout();
$(this.state.quiz_answer_area_id+_1c6).hide();
$(this.state.quiz_question_input_id+_1c6).hide();
$(this.state.quiz_edit_question_id+_1c6).show();
$(this.state.quiz_done_question_id+_1c6).hide();
this.updateQuizStateForQuestion(_1c6);
this.state.select_id=null;
if(_1c8){
this.state.reorder.enable();
}
}
if(e){
Event.stop(e);
}
return false;
};
function implode(elts,glue){
var str="";
elts.each(function(elt){
str+=elt.value+glue;
});
if(str!=""){
str=str.substring(0,str.length-glue.length);
}
return str;
};
ModuleEdit.prototype.togglePoll=function(){
this.toggleDisplay(this.resources.poll_edit_id);
if(!this.state.next_poll_question_id&&this.editting){
this.state.next_poll_question_id=$$("."+this.state.poll_answer_class).size();
}
if(this.editting){
$(this.state.poll_results_id).hide();
}else{
$(this.state.poll_results_id).show();
this.data.question=$F(this.state.poll_question_id);
this.keepPollChanges();
var _1cd=$$("."+this.state.poll_answer_class);
this.data.answers=implode(_1cd,"%*%");
if(!this.data.discard){
this.onclickPollPreview();
}else{
this.data.discard=false;
}
}
};
ModuleEdit.prototype.keepPollChanges=function(){
elts=$$(".answerLi");
elts.each(function(elt){
var _1cf=$(elt.id.replace("answer_li","status"));
switch(_1cf.value){
case "1":
_1cf.value=0;
break;
case "2":
elt.remove();
break;
}
});
};
ModuleEdit.prototype.discardPollChanges=function(){
this.data.discard=true;
elts=$$(".answerLi");
elts.each(function(elt){
var _1d1=$(elt.id.replace("answer_li","status"));
switch(_1d1.value){
case "1":
elt.remove();
break;
case "2":
elt.show();
_1d1.value=0;
break;
}
});
};
ModuleEdit.prototype.onclickPollPreview=function(){
eval("pm_"+this.data.mod_data_id+" = new PollManager("+this.data.id+","+this.data.mod_data_id+");");
var _1d2=$H({question:this.data.question,answers:this.data.answers,modId:this.data.id,modDataId:this.data.mod_data_id}).toQueryString();
var ajax=new Ajax.Updater({success:this.state.poll_results_id},"/xml/pollresults.php",{parameters:_1d2,onFailure:reportError,onComplete:function(){
}});
};
function pollHandler(e){
var data=$A(arguments);
data.shift();
this.deletePollChoice(data[0]);
Event.stop(e);
};
ModuleEdit.prototype.newPollChoice=function(){
var _1d6=document.createElement("li");
var link=document.createElement("a");
link.href="#";
link.title="delete this choice";
var _1d8=document.createElement("img");
_1d8.src="http://x.hubpages.com/x/hubtool_discard_tag.gif";
_1d8.alt="delete choice";
$(_1d8).addClassName("delete");
link.appendChild(_1d8);
var _1d9=document.createElement("input");
_1d9.type="text";
$(_1d9).addClassName("textInput");
$(_1d9).addClassName(this.data.id+"_answer");
_1d9.tabIndex=this.state.next_poll_question_id+2;
_1d9.id=this.state.poll_answer_id+this.state.next_poll_question_id;
_1d9.name=this.state.poll_answer_id+this.state.next_poll_question_id;
var _1da=document.createElement("input");
_1da.type="hidden";
_1da.value=1;
_1da.id=this.state.poll_status_id+this.state.next_poll_question_id;
_1da.name=_1da.id;
$(_1d6).addClassName("answerLi");
_1d6.appendChild(_1d9);
_1d6.appendChild(_1da);
_1d6.appendChild(link);
_1d6.id=this.state.poll_answer_li_id+this.state.next_poll_question_id;
$(this.state.poll_answers_id).appendChild(_1d6);
$(link).observe("click",pollHandler.bindAsEventListener(this,this.state.next_poll_question_id));
this.state.next_poll_question_id+=1;
};
ModuleEdit.prototype.deletePollChoice=function(i){
var _1dc=$(this.state.poll_status_id+i);
var _1dd=$(this.state.poll_answer_li_id+i);
if(_1dc.value==1){
_1dd.remove();
}else{
_1dd.hide();
_1dc.value=2;
}
};
ModuleEdit.prototype.toggleAmazon=function(){
this.toggleDisplay(this.resources.amazon_edit_id);
if(this.editting){
this.displayCorrectAmazonType();
this.changeNumDisplayedAmazon();
}
if(!this.editting){
if($(this.state.amazon_searchindex_id)){
this.data.searchtype=$F(this.state.amazon_searchtype_id);
this.data.searchindex=$F(this.state.amazon_searchindex_id);
this.data.maxitems=$F(this.state.max_id);
this.data.keywords=$F(this.state.keywords_id);
this.data.asins=this.implodeAsins();
this.data.descriptions=this.implodeDescriptions();
this.data.numbered=($F(this.state.amazon_numbered_id)=="on")?1:0;
}
this.onclickAmazonPreview();
}
};
ModuleEdit.prototype.toggleComment=function(){
this.toggleDisplay(this.state.comment_edit_id);
if(!this.editting){
if($(this.state.comment_moderated_id)){
this.data.moderated=$(this.state.comment_moderated_id).checked;
this.data.emailme=$(this.state.comment_emailme_id).checked;
this.data.anonymous=$(this.state.comment_noanonymous_id).checked;
this.data.reversed=$(this.state.comment_reversed_id).checked;
this.data.max=$F(this.state.comment_max_id);
}
}
};
ModuleEdit.prototype.buildCsv=function(_1de,_1df){
var csv=new StringBuffer();
var _1e1=_1de.rows.length;
var _1e2=_1de.rows[0].cells.length;
if(!_1de.rows[0].cells[0].hasClassName){
Element.extend(_1de.rows[0].cells[0]);
}
var _1e3=(_1de.rows[0].cells[0].hasClassName("extraCell"))?1:0;
this.resources.table_previous_element=null;
for(var row=_1e3;row<_1e1;row++){
if(!_1de.rows[row].cells[0].hasClassName){
Element.extend(_1de.rows[row].cells[0]);
}
if(!_1de.rows[row].cells[0].hasClassName("extraCell")){
for(var col=0;col<_1e2;col++){
if(!_1de.rows[row].cells[col].hasClassName){
Element.extend(_1de.rows[row].cells[col]);
}
if(!_1de.rows[row].cells[col].hasClassName("extraCell")){
if(col>0){
csv.append(",");
}
var cell=_1de.rows[row].cells[col];
var _1e7="";
for(var i=0;i<cell.childNodes.length;i++){
var _1e9=cell.childNodes[i];
if(_1e9.tagName&&_1e9.tagName.toLowerCase()=="div"){
_1e7=_1e9.innerHTML;
break;
}else{
if(_1e9.tagName&&_1e9.tagName.toLowerCase()=="input"){
_1e7=_1e9.value.escapeHTML();
var div=document.createElement("div");
div.innerHTML=_1e7;
_1e9.parentNode.removeClassName("selectedCell");
if(!_1e9.parentNode.hasClassName("tableCell")){
_1e9.parentNode.addClassName("tableCell");
}
_1e9.parentNode.replaceChild(div,_1e9);
break;
}
}
}
if(!cell.hasClassName){
Element.extend(cell);
}
var bold=(cell.hasClassName("boldCell"))?"b":"n";
var _1ec="c";
if(!cell.hasClassName("centerCell")){
_1ec=(cell.hasClassName("leftCell"))?"l":"r";
}
var _1ed=cell.parentNode.parentNode.tagName.toLowerCase();
_1e7=_1e7.replace(/(,|")/g,function(_1ee,part){
if(part==","){
return "^COMMA^";
}else{
if(part=="\""){
return "^QUOTE^";
}else{
return part;
}
}
});
csv.append("[").append(bold.substring(0,1)).append(_1ec.substring(0,1)).append(_1ed.substring(1,2)).append("]\"").append(_1e7).append("\"");
}
}
csv.append("\n");
}
}
return csv.toString();
};
ModuleEdit.prototype.insertExtraCell=function(row){
var cell=(row.parentNode.tagName.toLowerCase()=="thead")?document.createElement("th"):document.createElement("td");
row.appendChild(cell);
cell.className="extraCell centerCell";
if(cell.tagName.toLowerCase()=="th"){
cell.className+=" boldCell";
}
cell.innerHTML="<div></div>";
};
ModuleEdit.prototype.isExtraCell=function(cell){
if(!cell.hasClassName){
Element.extend(cell);
}
return cell.hasClassName("extraCell");
};
ModuleEdit.prototype.getTableNumCols=function(_1f3){
return (_1f3.rows.length==0)?0:_1f3.rows[0].cells.length;
};
ModuleEdit.prototype.updateEditTable=function(_1f4,_1f5){
var _1f6=$(this.resources.table_edit_thead_id);
var _1f7=$(this.resources.table_edit_tbody_id);
if(!_1f6.update){
Element.extend(_1f6);
}
if(!_1f7.update){
Element.extend(_1f7);
}
_1f6.update();
_1f7.update();
var tr=_1f6.insertRow(0);
var _1f9=this.getTableNumCols(_1f4.parentNode);
var _1fa=$(_1f5).rows.length;
var _1fb=$(this.resources.table_max_rows_id).value;
var _1fc=$(this.resources.table_max_cols_id).value;
if(_1f4.rows.length>0){
for(var col=0;col<_1f9;col++){
var cell=document.createElement("th");
tr.appendChild(cell);
if(!cell.update){
Element.extend(cell);
}
cell.update(_1f4.rows[0].cells[col].innerHTML);
cell.className=_1f4.rows[0].cells[col].className;
cell.noWrap=true;
}
if(_1f9<_1fc){
this.insertExtraCell(tr);
}
}else{
if(_1f5.rows.length>0){
for(col=0;col<_1f9;col++){
this.insertExtraCell(tr);
}
if(_1f9<_1fc){
this.insertExtraCell(tr);
}
}else{
this.insertExtraCell(tr);
}
}
if(_1fa>0&&$(_1f5).rows[0].cells.length>0){
for(var row=0;row<_1fa;row++){
tr=_1f7.insertRow(row);
tr.className=_1f5.rows[row].className;
for(col=0;col<_1f9;col++){
cell=tr.insertCell(col);
if(!cell.update){
Element.extend(cell);
}
cell.update(_1f5.rows[row].cells[col].innerHTML);
cell.className=_1f5.rows[row].cells[col].className;
cell.noWrap=true;
}
if(_1f9<_1fc){
this.insertExtraCell(tr);
}
}
}
if(_1fa<_1fb-1){
tr=$(_1f7).insertRow($(_1f7).rows.length);
for(col=0;col<_1f9;col++){
this.insertExtraCell(tr);
}
if(_1f9<_1fc){
this.insertExtraCell(tr);
}
}
$(this.resources.table_edit_content_id).observe("click",function(evt){
var elm=Event.element(evt);
if(elm.tagName.toLowerCase()=="td"||elm.tagName.toLowerCase()=="th"){
var divs=elm.getElementsByTagName("div");
if(divs.length>0){
this.selectCell(divs[0]);
}
}else{
if(elm.tagName.toLowerCase()=="div"&&elm.parentNode!=null&&elm.parentNode.tagName!=null){
if(elm.parentNode.tagName.toLowerCase()=="td"||elm.parentNode.tagName.toLowerCase()=="th"){
this.selectCell(elm);
}
}
}
}.bind(this));
};
ModuleEdit.prototype.updateViewTable=function(_203,_204){
var _205=$(this.resources.table_view_thead_id);
var _206=$(this.resources.table_view_tbody_id);
if(!_205.update){
Element.extend(_205);
}
if(!_206.update){
Element.extend(_206);
}
_205.update();
_206.update();
var _207=this.getTableNumCols(_203.parentNode);
if(this.hasTableHeader(_203.parentNode)){
var tr=_205.insertRow(0);
for(var col=0;col<_207;col++){
if(!_203.rows[0].cells[col].hasClassName){
Element.extend(_203.rows[0].cells[col]);
}
if(!_203.rows[0].cells[col].hasClassName("extraCell")){
var cell=document.createElement("th");
tr.appendChild(cell);
if(!cell.update){
Element.extend(cell);
}
cell.update(_203.rows[0].cells[col].innerHTML);
if(cell.innerHTML.trim().toLowerCase()=="<div></div>"){
cell.update("<div>&nbsp;</div>");
}
cell.className=_203.rows[0].cells[col].className;
if(col==0){
cell.addClassName("firstCell");
}else{
cell.removeClassName("firstCell");
}
cell.removeClassName("lastCell");
}
}
if(cell.addClassName){
cell.addClassName("lastCell");
}
}
if(_204.rows.length>1){
for(var row=0;row<_204.rows.length;row++){
if(!_204.rows[row].cells[0].hasClassName){
Element.extend(_204.rows[row].cells[0]);
}
if(!_204.rows[row].cells[0].hasClassName("extraCell")){
tr=_206.insertRow(row);
tr.className=_204.rows[row].className;
for(col=0;col<_204.rows[row].cells.length;col++){
if(!_204.rows[row].cells[col].hasClassName){
Element.extend(_204.rows[row].cells[col]);
}
if(!_204.rows[row].cells[col].hasClassName("extraCell")){
cell=document.createElement("td");
tr.appendChild(cell);
if(!cell.update){
Element.extend(cell);
}
cell.update(_204.rows[row].cells[col].innerHTML);
if(cell.innerHTML.trim().toLowerCase()=="<div></div>"){
cell.update("<div>&nbsp;</div>");
}
cell.className=_204.rows[row].cells[col].className;
if(col==0&&!cell.hasClassName("firstCell")){
cell.addClassName("firstCell");
}else{
if(cell.hasClassName("firstCell")){
cell.removeClassName("firstCell");
}
}
if(cell.hasClassName("lastCell")){
cell.removeClassName("lastCell");
}
}
}
}
if(cell.addClassName){
cell.addClassName("lastCell");
}
}
}
};
ModuleEdit.prototype.showTableView=function(evt){
$(this.resources.table_loading_status_id).hide();
if(evt){
var elm=Event.element(evt);
if(elm.id!=this.resources.table_radio_current_id){
$(this.resources.table_radio_current_id).checked=false;
}
}
if(!$(this.resources.table_radio_current_id).checked){
$(this.resources.table_div_current_id).hide();
}else{
$(this.resources.table_div_current_id).show();
}
if(!$(this.resources.table_radio_url_id).checked){
$(this.resources.table_div_url_id).hide();
$(this.resources.table_url_id).value="";
}else{
$(this.resources.table_div_url_id).show();
}
if(!$(this.resources.table_radio_pc_id).checked){
$(this.resources.table_div_pc_id).hide();
$(this.resources.table_file_id).value="";
}else{
$(this.resources.table_div_pc_id).show();
}
};
ModuleEdit.prototype.showTableStatusMessage=function(_20e){
$(this.resources.table_loading_status_id).update(_20e);
$(this.resources.table_loading_status_id).show();
};
ModuleEdit.prototype.hideTableStatusMessage=function(){
$(this.resources.table_loading_status_id).hide();
};
ModuleEdit.prototype.handleSelectionsForTable=function(evt){
var elm=Event.element(evt);
if(elm.id!=this.resources.table_action1_id){
$(this.resources.table_action1_id).value=0;
}
if(elm.id!=this.resources.table_action2_id){
$(this.resources.table_action2_id).value=0;
}
if(elm.id!=this.resources.table_action3_id){
$(this.resources.table_action3_id).value=0;
}
};
ModuleEdit.prototype.hasTableHeader=function(_211){
if(_211.rows.length==0||_211.rows[0].cells.length==0){
return false;
}
var test=_211.rows[0].cells[0];
if(!test.hasClassName){
Element.extend(test);
}
return (!test.hasClassName("extraCell"));
};
ModuleEdit.prototype.updateTableRowClasses=function(_213){
for(var row=0;row<_213.rows.length;row++){
var tr=_213.rows[row];
if(!tr.hasClassName){
Element.extend(tr);
}
tr.className=(row%2==0)?"oddRow":"evenRow;";
}
};
ModuleEdit.prototype.handleTableActions=function(){
if(this.resources.table_previous_element==null||this.resources.table_previous_element.parentNode==null){
alert("You need to select a column or row before hitting the 'update' button.");
return;
}
var _216=$(this.resources.table_max_rows_id).value;
var _217=$(this.resources.table_max_cols_id).value;
var cell=this.resources.table_previous_element.parentNode;
var col=$(cell).cellIndex;
var row=$(cell).parentNode.rowIndex;
var _21b=$(this.resources.table_edit_content_id);
var _21c=$(this.resources.table_edit_thead_id);
var _21d=$(this.resources.table_edit_tbody_id);
var _21e=_21b.rows.length;
var _21f=this.getTableNumCols(_21b);
var _220=parseInt($(this.resources.table_action1_id).value)+parseInt($(this.resources.table_action2_id).value)+parseInt($(this.resources.table_action3_id).value);
switch(_220){
case 1:
if(row!=0&&row<_21e-1||row==_21e-1&&_21e==_216){
var _221=(_21e==_216&&!this.isExtraCell(_21b.rows[_21e-1].cells[0]));
_21b.deleteRow(row);
if(_221){
var tr=_21b.insertRow(_21e-1);
for(col=0;col<_21f;col++){
this.insertExtraCell(tr);
}
}
this.updateTableRowClasses(_21d);
}else{
if(row==0){
alert("You are not able to delete the header row");
}else{
alert("You are not able to delete the extra row");
}
}
break;
case 2:
if(_21f>2&&col<_21f-1||col==_21f-1&&_21f==_217){
var _221=(_21f==_217&&!this.isExtraCell(_21b.rows[0].cells[_21f-1]));
for(row=0;row<_21e;row++){
_21b.rows[row].deleteCell(col);
if(_221){
this.insertExtraCell(_21b.rows[row]);
}
}
}else{
if(_21f==2&&col==0){
alert("You must have at least one column.");
}else{
alert("You are not able to delete the extra column");
}
}
break;
case 4:
if(row<_21e-1){
row++;
}
case 3:
if(row==0){
alert("Rows above the header row are not alloweed");
}else{
if(_21e==_216){
alert("You have reached the maximum number of rows");
}else{
_21b.insertRow(row);
for(var i=0;i<_21f;i++){
cell=(_21b.rows[row].parentNode==_21c)?document.createElement("th"):document.createElement("td");
_21b.rows[row].appendChild(cell);
cell.className=(i==_21f-1)?"extraCell":"tableCell";
cell.style.width="200px";
cell.innerHTML="<div></div>";
}
this.updateTableRowClasses(_21d);
this.selectCell(_21b.rows[row].cells[col]);
}
}
break;
case 6:
if(col<_21f-1){
col++;
}
case 5:
if(_21f==_217){
alert("You have reached the maximum number of columns");
}else{
for(i=0;i<_21e;i++){
var _224=(i==_21e-1)?"extraCell":"tableCell";
if(i!=0||!this.hasTableHeader(_21b)){
cell=document.createElement("td");
}else{
cell=document.createElement("th");
}
_21b.rows[i].insertBefore(cell,_21b.rows[i].cells[col]);
cell.className=_224;
cell.innerHTML="<div></div>";
}
this.selectCell(_21b.rows[row].cells[col]);
}
break;
case 16:
case 14:
for(i=0;i<_21f;i++){
cell=_21b.rows[row].cells[i];
var _225=(_220==14)?"boldCell":"unboldCell";
var _226=(_220==14)?"unboldCell":"boldCell";
if(!cell.hasClassName){
Element.extend(cell);
}
if(!cell.hasClassName(_225)){
cell.removeClassName(_226);
cell.addClassName(_225);
}
}
break;
case 15:
case 13:
for(i=0;i<_21e;i++){
if(i!=0||!this.hasTableHeader(_21b)){
cell=_21b.rows[i].cells[col];
_225=(_220==13)?"boldCell":"unboldCell";
_226=(_220==13)?"unboldCell":"boldCell";
if(!cell.hasClassName(_225)){
cell.removeClassName(_226);
cell.addClassName(_225);
}
}
}
break;
case 7:
case 8:
case 9:
var _227,not1,not2;
if(_220==7){
_227="centerCell";
not1="leftCell";
not2="rightCell";
}else{
if(_220==8){
_227="rightCell";
not1="leftCell";
not2="centerCell";
}else{
if(_220==9){
_227="leftCell";
not1="rightCell";
not2="centerCell";
}
}
}
for(i=0;i<_21e;i++){
if(i!=0||!this.hasTableHeader(_21b)){
cell=_21b.rows[i].cells[col];
if(!cell.hasClassName){
Element.extend(cell);
}
if(!cell.hasClassName(_227)){
cell.addClassName(_227);
cell.removeClassName(not1);
cell.removeClassName(not2);
}
}
}
break;
case 10:
case 11:
case 12:
if(_220==10){
_227="centerCell";
not1="leftCell";
not2="rightCell";
}else{
if(_220==11){
_227="rightCell";
not1="leftCell";
not2="centerCell";
}else{
if(_220==12){
_227="leftCell";
not1="rightCell";
not2="centerCell";
}
}
}
for(i=0;i<_21f;i++){
cell=_21b.rows[row].cells[i];
if(!cell.hasClassName){
Element.extend(cell);
}
if(!cell.hasClassName(_227)){
cell.addClassName(_227);
cell.removeClassName(not1);
cell.removeClassName(not2);
}
}
break;
case 17:
this.resources.table_previous_element.value="";
break;
case 18:
for(i=0;i<_21d.rows.length;i++){
if(i==row&&cell.tagName.toLowerCase()!="th"){
this.resources.table_previous_element.value="";
}else{
var curr=_21d.rows[i].cells[col];
if(!curr.hasClassName){
Element.extend(curr);
}
if(!curr.hasClassName("extraCell")){
curr.update("<div></div>");
}
}
}
break;
case 19:
for(i=0;i<_21f;i++){
if(i==col){
this.resources.table_previous_element.value="";
}else{
curr=_21b.rows[row].cells[i];
if(!curr.update){
Element.extend(curr);
}
if(!curr.hasClassName("extraCell")){
curr.update("<div></div>");
}
}
}
break;
case 20:
case 21:
case 22:
if(_220==20){
_227="centerCell";
not1="rightCell";
not2="leftCell";
}else{
if(_220==21){
_227="rightCell";
not1="centerCell";
not2="leftCell";
}else{
if(_220==22){
_227="leftCell";
not1="rightCell";
not2="centerCell";
}
}
}
if(!cell.hasClassName){
Element.extend(cell);
}
if(!cell.hasClassName(_227)){
cell.removeClassName(not1);
cell.removeClassName(not2);
cell.addClassName(_227);
}
break;
case 23:
case 24:
_227=(_220==23)?"boldCell":"unboldCell";
not1=(_220==23)?"unboldCell":"boldCell";
if(!cell.hasClassName){
Element.extend(cell);
}
if(!cell.hasClassName(_227)){
cell.removeClassName(not1);
cell.addClassName(_227);
}
break;
}
};
ModuleEdit.prototype.tableHandleTabsAndArrows=function(evt){
var elm=Event.element(evt);
if(!elm.tagName||elm.tagName.toLowerCase()!="input"||elm.parentNode.tagName.toLowerCase()!="td"&&elm.parentNode.tagName.toLowerCase()!="th"){
return true;
}
if(!checkTabKeyAlone(evt)&&!checkShiftTabKey(evt)&&evt.keyCode!=Event.KEY_UP&&evt.keyCode!=Event.KEY_DOWN){
return true;
}
var cell=elm.parentNode;
var col=cell.cellIndex;
var row=cell.parentNode.rowIndex;
var _230=$(this.resources.table_edit_content_id);
var _231=_230.rows.length;
var _232=(_231==0)?0:_230.rows[0].cells.length;
if(checkTabKeyAlone(evt)){
if(col<_232-1||row<_231-1){
if(col==_232-1){
this.selectCell(_230.rows[row+1].cells[0]);
}else{
this.selectCell(_230.rows[row].cells[col+1]);
}
}
Event.stop(evt);
return false;
}else{
if(checkShiftTabKey(evt)){
if(col!=0||row!=0){
if(col==0){
this.selectCell(_230.rows[row-1].cells[_232-1]);
}else{
this.selectCell(_230.rows[row].cells[col-1]);
}
}
Event.stop(evt);
return false;
}else{
if(evt.keyCode==Event.KEY_UP){
if(row>0){
this.selectCell(_230.rows[row-1].cells[col]);
Event.stop(evt);
return false;
}
}else{
if(evt.keyCode==Event.KEY_DOWN){
if(row<_231-1){
this.selectCell(_230.rows[row+1].cells[col]);
Event.stop(evt);
return false;
}
}
}
}
}
return true;
};
ModuleEdit.prototype.selectCell=function(elm){
var _234=this.resources.table_previous_element;
if(!elm||!elm.parentNode||!elm.tagName||_234==elm||_234!=null&&_234.parentNode==elm){
return;
}
if(_234!=null&&_234.parentNode!=null){
var _235=_234.value.escapeHTML();
_234=_234.parentNode;
_234.innerHTML="<div>"+_235+"</div>";
if(!_234.removeClassName){
Element.extend(_234);
}
_234.removeClassName("selectedCell");
}
if(elm.tagName.toLowerCase()!="div"){
list=elm.getElementsByTagName("div");
if(list.length==0){
return;
}
elm=list[0];
}
var _236=$(this.resources.table_max_rows_id).value;
var _237=$(this.resources.table_max_cols_id).value;
_235=elm.innerHTML;
elm=elm.parentNode;
var _238=elm.offsetWidth;
if(!elm.update){
Element.extend(elm);
}
elm.update();
elm.addClassName("selectedCell");
var _239=document.createElement("input");
_239.type="text";
_239.value=_235.unescapeHTML().strip();
_239=elm.appendChild(_239);
var _23a=elm.offsetWidth;
var _23b=_239.offsetWidth;
if(_23a<_238){
_239.style.width=(_238-_23a+_23b)+"px";
}
_239.focus();
setTimeout(function(){
_239.focus();
},10);
this.resources.table_previous_element=_239;
if(!_239.observe){
Element.extend(_239);
}
_239.onkeydown=function(evt){
evt=getEvent(evt);
return this.tableHandleTabsAndArrows(evt);
}.bind(this);
_239.onkeypress=function(evt){
evt=getEvent(evt);
if(checkTabKeyAlone(evt)||checkShiftTabKey(evt)){
Event.stop(evt);
return false;
}else{
if(evt.keyCode!=Event.KEY_BACKSPACE&&evt.keyCode!=Event.KEY_LEFT&&evt.keyCode!=Event.KEY_RIGHT&&evt.keyCode!=Event.KEY_UP&&evt.keyCode!=Event.KEY_DOWN){
var _23e=Event.element(evt);
var cell=_23e.parentNode;
var col=cell.cellIndex;
var tr=cell.parentNode;
var row=tr.rowIndex;
var _243=$(this.resources.table_edit_content_id);
var _244=_243.rows.length;
var _245=_243.rows[0].cells.length;
if(row==0&&cell.hasClassName("extraCell")){
for(var i=0;i<_245;i++){
cell=tr.cells[i];
if(!cell.hasClassName){
Element.extend(cell);
}
if(i<_245-1||_245==_237){
cell.removeClassName("extraCell");
cell.addClassName("tableCell");
cell.addClassName("boldCell");
cell.addClassName("centerCell");
}
}
}
if(col==_245-1){
for(i=0;i<_244;i++){
var _247=_243.rows[i];
if(i<_244-1||i==_244-1&&_244>=_236-1){
cell=_247.cells[_245-1];
if(!cell.removeClassName){
Element.extend(cell);
}
cell.removeClassName("extraCell");
cell.addClassName("tableCell");
var divs=cell.getElementsByTagName("div");
if(divs!=null&&divs.length>0){
var div=divs[0];
div.style.minWidth="200px";
div.style.width="200px";
}
if(i==0){
cell.addClassName("boldCell");
}
}
if(_245<_237){
this.insertExtraCell(_247);
}
}
_245++;
}
if(row==_244-1){
var tr2;
if(_244<_236){
tr2=_243.insertRow(row+1);
}
for(i=0;i<_245;i++){
if(_244<_236){
this.insertExtraCell(tr2);
}
if(i<_245-1||_245==_237){
if(!tr.cells[i].removeClassName){
Element.extend(tr.cells[i]);
}
tr.cells[i].removeClassName("extraCell");
tr.cells[i].addClassName("tableCell");
}
}
tr.className=(_244%2==0)?"oddRow":"evenRow";
}
}
}
return true;
}.bind(this);
};
ModuleEdit.prototype.toggleTable=function(){
this.toggleDisplay(this.resources.table_edit_id);
if(this.editting){
this.showTableView();
var _24b=$(this.resources.table_view_thead_id);
var _24c=$(this.resources.table_view_tbody_id);
this.updateEditTable(_24b,_24c);
}else{
if(this.data.dirty){
var csv=this.buildCsv($(this.resources.table_edit_content_id));
this.data.content=csv;
this.data.tableStyle=$(this.resources.table_style_id).value;
this.data.sortable=$(this.resources.table_checkbox_sortable_id).checked?1:0;
this.data.caption=$(this.resources.table_caption_id).value;
_24b=$(this.resources.table_edit_thead_id);
_24c=$(this.resources.table_edit_tbody_id);
this.updateViewTable(_24b,_24c);
$(this.resources.table_view_content_id).className=this.data.tableStyle;
this.data.numRows=$(this.resources.table_view_tbody_id).rows.length+1;
this.data.numCols=$(this.resources.table_view_thead_id).rows[0].cells.length;
$(this.resources.table_view_id).show();
}else{
$(this.resources.table_view_id).show();
}
}
};
ModuleEdit.prototype.toggleCode=function(){
this.toggleDisplay(this.resources.code_edit_id);
var _24e=-2;
var _24f=-20;
var _250=150;
var _251=10;
var _252=0.5*((window.innerHeight||document.documentElement.clientHeight)-_251);
var _253=$(this.state.code_div_id);
if(this.editting){
_253=$(this.state.code_div_id);
var text=$(_253.id).innerHTML;
$(_253.id).innerHTML="<textarea id=\""+this.state.code_textarea_id+"\" class=\"moduleCodeEdit\" rows=\"10\">"+text+"</textarea>";
var _255=text.length;
var _256=this.state.code_textarea_id;
checkCharCount($F(this.state.code_max_size_id),this.state.code_textarea_id,this.state.code_size_left_id);
$(this.state.code_textarea_id).onkeypress=function(evt){
if(browser=="Opera"){
if(checkTabKeyAlone(evt)||checkShiftTabKey(evt)){
Event.stop(evt);
return false;
}
}
return true;
};
Event.observe(this.state.code_textarea_id,"keydown",function(evt){
evt=getEvent(evt);
var s;
if(checkTabKeyAlone(evt)){
s=getSelectionProperties(evt);
s.addTab();
Event.stop(evt);
return false;
}else{
if(checkShiftTabKey(evt)){
s=getSelectionProperties(evt);
s.removeTab();
Event.stop(evt);
return false;
}
}
return true;
});
this.state.origtext_width=parseFloat(Element.getWidth(this.data.div_id))+_24e+(this.state.floatright&&!_253.parentNode.hasClassName("color0")?_24f:0);
this.state.origtext_height=parseFloat(Element.getHeight(_253));
var _25a=(this.state.origtext_height<_250)?_250:this.state.origtext_height;
if(_252>_250&&_25a>_252){
_25a=_252;
}
_25a+=_251;
_253.style.height=_25a+"px";
_253.style.width=this.state.origtext_width+"px";
_253.style.padding="13px";
$(_253.id).show();
}else{
_253=$(this.state.code_div_id);
this.data.content=$(this.state.code_textarea_id).value;
this.data.codeTypeId=$(this.state.code_type_id).value;
this.data.includeLineNumbers=$(this.state.code_include_line_numbers_id).checked?1:0;
this.data.codeDisplaySize=$(this.state.code_display_size_id).value;
var _25b=document.createTextNode(this.data.content);
$(_253).update();
$(_253).appendChild(_25b);
_253.style.display="";
_253.style.width="auto";
_253.style.height="auto";
delete this.state.origtext_width;
delete this.state.origtext_height;
}
};
ModuleEdit.prototype.toggleEbay=function(){
this.toggleDisplay(this.resources.ebay_edit_id);
if(this.editting){
Event.observe($(this.resources.ebay_preview_id),"click",this.onclickEbayPreview.bindAsEventListener(this),false);
}else{
this.data.keywords=$F(this.resources.ebay_keywords_id);
this.data.seller=$F(this.resources.ebay_seller_id);
this.data.maxitems=$F(this.resources.max_results_id);
this.onclickEbayPreview();
}
};
ModuleEdit.prototype.toggleLink=function(){
this.toggleDisplay(this.state.link_edit_id);
if(this.editting){
this.state.select_id=null;
Element.hide(this.state.link_display_id);
if(!this.state.links){
this.loadLinkState();
}
this.state.reorder=new ModuleContentReorder(this.resources.link_drag_section,1,150,24);
$H(this.state.links.links).values().each(function(link){
if(!link.id){
return;
}
this.addLinkDragElement(link.id,link.name,false);
}.bind(this));
this.state.reorder.relayout();
if($(this.state.link_show_search_field).checked){
this.linkDisplay("link_search_field");
}else{
this.linkDisplay("link_add_field");
}
}else{
Element.show(this.state.link_display_id);
$(this.state.links_list).innerHTML="";
this.state.reorder.items.each(function(item){
var link=this.state.linkIndex[item.item_id];
var url=link.url;
var desc=link.description;
var _261=link.name;
var _262=document.createElement("li");
_262.id="linkitem_"+item.item_id;
_262.innerHTML="<a class=\"link_hub\" target=\"new\" href="+url+">"+_261+"</a><p>"+desc+"</p>";
$(this.state.links_list).appendChild(_262);
}.bind(this));
var _263=this.state.reorder.getitemstateRec();
for(pos in this.state.links.links){
var link=this.state.links.links[pos];
if(!link.id||!_263[link.id]){
continue;
}
var _265=_263[link.id].position;
if(_265!=pos||link.isnew){
link.move=true;
link.newpos=_265;
link.dirty=true;
}
}
this.data.links_json=JSONstring.make(this.state.links);
this.linkDisplay("link_add_field");
$(this.resources.link_drag_title).hide();
this.stretched=false;
$(this.resources.link_drag_section).innerHTML="";
delete this.state.reorder;
}
};
ModuleEdit.prototype.loadLinkState=function(){
if($(this.resources.json_links_id)){
this.state.links=JSONstring.toObject($(this.resources.json_links_id).innerHTML);
this.state.linkIndex=Object();
var _266=$H(this.state.links.links).values();
_266.each(function(link){
if(!link.id){
return;
}
this.state.linkIndex[link.id]=link;
}.bind(this));
}
};
ModuleEdit.prototype.toggleImage=function(){
this.toggleDisplay(this.resources.image_edit_id);
if(!this.editting){
if(this.data.dirty){
this.updateImageData();
var _268=this.state.reorder.getitemstate();
_268.each(function(_269){
_269.caption=this.state.photoData[_269.id].caption;
_269.maxSize=this.state.photoData[_269.id].maxSize;
}.bind(this));
this.state.images_removed.each(function(id){
_268.push({id:id,caption:"",position:-1});
});
this.data.images_json=JSONstring.make(_268);
if($(this.resources.image_display_style_id)){
this.data.dispTypeId=$F(this.resources.image_display_style_id);
var elem=$(this.resources.image_display_style_id);
this.state.image_ctrl.displayStatus=elem.options[elem.selectedIndex].text;
}
if($(this.resources.image_popup_id)){
this.data.showFullSize=($F(this.resources.image_popup_id)=="on")?1:0;
}
this.state.image_ctrl.clear();
this.state.reorder.items.each(function(item){
this.state.image_ctrl.addPhoto(this.state.photoData[item.item_id]);
}.bind(this));
this.updateImageControlHeight();
this.state.image_ctrl.render();
}
this.state.image_ctrl.toggleViewer();
Element.show(this.state.content_id);
Element.hide(this.resources.image_selection_id);
$(this.resources.image_selection_id).innerHTML="";
$(this.resources.image_drag_section).innerHTML="";
delete this.state.reorder;
delete this.state.photoData;
}else{
$(this.resources.image_computer_radio_id).checked=false;
$(this.resources.image_web_radio_id).checked=false;
$(this.resources.image_import_section_id).hide();
$(this.resources.image_upload_section_id).hide();
$(this.resources.image_load_id).hide();
$(this.resources.image_upload_target_id).style.height="0px";
Element.hide(this.state.content_id);
Element.show(this.resources.image_selection_id);
if(!this.state.image_ctrl){
eval("this.state.image_ctrl = imgCtrl_"+this.data.id);
}
this.state.image_ctrl.stopTimer();
this.state.reorder=new ModuleContentReorder(this.resources.image_drag_section,1,300,85);
this.state.photoData=new Object();
this.state.image_ctrl.photoOrder.each(function(_26d){
var rec=this.state.image_ctrl.photoData[_26d];
this.state.photoData[_26d]={};
for(key in rec){
this.state.photoData[_26d][key]=rec[key];
}
this.addImageDragElement(_26d,rec.urlThumb,rec.caption);
}.bind(this));
this.state.reorder.relayout();
}
};
ModuleEdit.prototype.updateImageControlHeight=function(){
$newHeight=this.state.image_ctrl.getMaxDisplayHeight();
$(this.resources.image_viewer_display).style.height=$newHeight+"px";
this.state.image_ctrl.setMaxHeight($newHeight);
};
ModuleEdit.prototype.toggleVideo=function(){
this.toggleDisplay(this.resources.video_edit_id);
if(this.editting){
this.onclickVideoPreview();
}else{
var size=(this.state.floatnone)?"Big":"Small";
this.onclickVideoPreview(size);
if($(this.resources.video_url_input_id)){
this.data.url=$F(this.resources.video_url_input_id);
}
}
};
ModuleEdit.prototype.toggleRss=function(){
this.toggleDisplay(this.state.rss_edit_id);
if(!this.editting){
if($(this.state.feed_id)){
this.data.feed=$F(this.state.feed_id);
this.data.maxitems=$F(this.state.max_id);
this.data.mode=$F(this.state.mode_id);
}
this.onclickRssPreview("rss");
}
};
ModuleEdit.prototype.toggleNews=function(){
this.toggleDisplay(this.state.rss_edit_id);
if(!this.editting){
if($(this.state.keywords_id)){
this.data.keywords=$F(this.state.keywords_id);
this.data.maxitems=$F(this.state.max_id);
}
this.onclickRssPreview("news");
}
};
ModuleEdit.prototype.getContent=function(_270){
if(_270.getContent){
return _270.getContent();
}else{
return _270.activeEditor.getContent();
}
};
ModuleEdit.prototype.toggleText=function(){
var _271=-2;
var _272=-20;
var _273=150;
var _274=75;
var _275=0.5*((window.innerHeight||document.documentElement.clientHeight)-_274);
var _276=$(this.state.text_div_id);
var inst;
if(this.editting){
_276=$(this.state.text_div_id);
_276.innerHTML=_276.innerHTML.replace(/<\s*p\s*>\s*<\s*\/\s*p\s*>/gi,"");
this.state.origtext_width=parseFloat(Element.getWidth(this.data.div_id))+_271+(this.state.floatright&&!_276.parentNode.hasClassName("color0")?_272:0);
this.state.origtext_height=parseFloat(Element.getHeight(_276));
var _278=(this.state.origtext_height<_273)?_273:this.state.origtext_height;
if(_275>_273&&_278>_275){
_278=_275;
}
_278+=_274;
_276.style.height=_278+"px";
_276.style.width=this.state.origtext_width+"px";
if(browser=="Konqueror"){
Element.update(_276.id,"<textarea id=\"txta_konqueror\" rows=\"10\" cols=\"80\">"+_276.innerHTML+"</textarea>");
}else{
tinyMCE.execCommand("mceAddControl",false,_276.id);
inst=tinyMCE.getInstanceById(_276.id);
if(inst){
if(inst.getWin&&inst.getWin()){
this.state.mce_ele_id=inst.getWin().id;
}else{
this.state.mce_ele_id=inst.id;
tinyMCE.execInstanceCommand(inst.id,"FormatBlock",false,"p");
}
}
}
}else{
if(browser=="Konqueror"){
this.data.content=$("txta_konqueror").value;
Element.update(this.state.text_div_id,this.data.content);
}else{
inst=tinyMCE.getInstanceById(this.state.text_div_id);
if(inst){
if($(this.state.mce_ele_id)){
if(inst.contentDocument){
inst.contentWindow=$(this.state.mce_ele_id).contentWindow;
inst.contentWindow.document.body.innerHTML=inst.contentDocument.body.innerHTML;
}else{
inst.contentWindow=$(this.state.mce_ele_id).contentWindow;
inst.getWin().document.body.innerHTML=inst.getDoc().body.innerHTML;
}
}
tinyMCE.triggerSave(false,true);
if(tinyMCE.activeEditor){
this.needsHtmlCleanUp=true;
this.data.content=this._cleanUpHtml(this.tiny_mce_editor,this.getContent(tinyMCE),false);
}else{
this.data.content=this.getContent(tinyMCE);
}
if(this.data.content==""){
var _279=new Date();
while(true){
var _27a=new Date();
if(_27a.getTime()>_279.getTime()){
break;
}
}
this.data.content=this.getContent(tinyMCE);
}
if(tinyMCE.activeEditor){
try{
tinyMCE.execCommand("mceCloseHubHtmlEditor",false,null);
}
catch(e){
}
try{
tinyMCE.execCommand("mceCloseHubLink",false,null);
}
catch(e){
}
try{
tinyMCE.execCommand("mceCloseHubDraft",false,null);
}
catch(e){
}
}
tinyMCE.execCommand("mceRemoveControl",false,this.state.text_div_id);
}
_276=$(this.state.text_div_id);
if(_276.nodeName.toLowerCase()=="input"){
_276.parentNode.removeChild(_276);
}
}
_276=$(this.state.text_div_id);
Element.update(_276,this.data.content);
_276.style.display="";
_276.style.width="auto";
_276.style.height="auto";
delete this.state.origtext_width;
delete this.state.origtext_height;
}
};
ModuleEdit.prototype.discard=function(){
this.setClean();
if(this.data.type=="Poll"){
this.discardPollChanges();
}else{
if(this.data.type=="Image"){
this.clearImageUploadForm();
}else{
if(this.data.type=="Map"){
this.loadMapState();
}
}
}
if(this.data.type=="Text"){
if(this.tiny_mce_editor.isDirty()){
var _27b=$H({id:this.data.id,save:1,art_id:this.data.art_id,content:this.getContent(tinyMCE)});
var ajax=new Ajax.Request("/xml/textdraft.php",{parameters:_27b.toQueryString(),onFailure:function(_27d){
},onSuccess:function(_27e){
if(!_27e.responseText){
}else{
var resp=JSONstring.toObject(_27e.responseText);
if(!resp||resp.result!="success"){
}
}
}});
}
}
if(this.data.type!="Text"&&this.data.type!="Code"){
Form.unserialize($(this.data.div_id),this.state.original_form);
this.data.hide=this.state.original_hide;
ModuleEdit.Manager.toggle(this.data.id);
}else{
this.data.hide=this.state.original_hide;
ModuleEdit.Manager.toggle(this.data.id);
$(this.data.div_id).innerHTML=this.state.original_html.replace(/(<[^<>]+)\s+_extended="true"/ig,"$1");
}
this.state.original_html=null;
this.state.original_form=null;
delete this.state.original_html;
delete this.state.original_form;
if(this.data.type=="Link"){
this.loadLinkState();
this.onclickCapsuleRenderFromDB(this.state.link_display_id);
}
};
ModuleEdit.prototype.computeState=function(){
var _280=this.getHoriz();
this.state.floatleft=(_280<2)?true:false;
this.state.floatright=(_280>2)?true:false;
this.state.floatnone=(_280==2)?true:false;
var _281=this.state.div_ele=$(this.data.div_id);
if(this.editting){
var l=this.layout;
l.topleft=Position.cumulativeOffset(_281);
l.height=Element.getHeight(_281);
l.width=Element.getWidth(_281);
l.bottomright=[l.topleft[0]+l.width,l.topleft[1]+l.height];
}
};
ModuleEdit.prototype.toggleDisplay=function(item,_284){
item=$(item);
var show;
if(_284!=null){
show=_284;
}else{
show=this.editting;
}
if(item){
var _286=item.style.display;
if(show&&_286=="none"){
item.style.display="";
}else{
if(!show&&_286!="none"){
item.style.display="none";
}
}
}
};
ModuleEdit.prototype.setDirty=function(){
this.data.dirty=true;
};
ModuleEdit.prototype.setClean=function(_287,json){
this.data.dirty=false;
if(this.data.type=="Link"){
if(json){
$(this.resources.json_links_id).innerHTML=JSONstring.make(json);
this.loadLinkState();
}
}else{
if(this.data.type=="Map"){
if(json){
$(this.state.map_json_id).innerHTML=JSONstring.make(json);
this.loadMapState();
}
}else{
if(this.data.type=="Text"){
if(_287&&_287.responseText){
this.needsHtmlCleanUp=false;
var resp=JSONstring.toObject(_287.responseText);
if(resp.cleanedText){
this.data.content=resp.cleanedText;
var _28a=$(this.state.text_div_id);
}
}
}
}
}
};
ModuleEdit.prototype.getHoriz=function(){
return (this.isLast())?2:this.data.horiz_id;
};
ModuleEdit.prototype.setHoriz=function(_28b){
this.data.horiz_id=_28b;
};
ModuleEdit.prototype.isLast=function(){
return this.state.is_last;
};
ModuleEdit.prototype.isFloated=function(){
return (this.getHoriz()!=2);
};
ModuleEdit.prototype.renderExhaustive=function(){
if(this.data.type=="Image"){
this.adjustImageWidth();
}else{
if(this.data.type=="Map"){
this.mapResized();
}
}
this.computeState();
this._renderFloat();
this.render();
};
ModuleEdit.prototype.setColorbar=function(pos){
if(this.data.type=="Image"||this.data.type=="Video"||this.data.type=="Map"||this.data.type=="Comment"){
return;
}
if(pos==3){
$("nocolor_"+this.data.id).style.display="none";
$("yescolor_"+this.data.id).style.display="";
}else{
$("nocolor_"+this.data.id).style.display="";
$("yescolor_"+this.data.id).style.display="none";
}
};
ModuleEdit.prototype.adjustImageWidth=function(){
if(this.data.type!="Image"){
return;
}
if(!this.state.image_ctrl){
eval("this.state.image_ctrl = imgCtrl_"+this.data.id);
}
if(this.data.horiz_id>2&&!this.isLast()){
if(this.state.image_ctrl.floatStatus=="none"){
this.state.image_ctrl.floatStatus="right";
this.updateImageControlHeight();
$(this.resources.image_viewer_caption).className="caption_half";
}
}else{
if(this.state.image_ctrl.floatStatus=="right"){
this.state.image_ctrl.floatStatus="none";
this.updateImageControlHeight();
$(this.resources.image_viewer_caption).className="caption_full";
}
}
var _28d=this.state.image_ctrl.displayStatus;
if(_28d=="No Border"||_28d=="With Border"){
this.state.image_ctrl.renderInlineImages();
}else{
this.state.image_ctrl.loadSlide(this.state.image_ctrl.viewer_id);
}
};
ModuleEdit.prototype._cleanUpHtml=function(ed,_28f,tidy){
var t=this;
_28f=_28f.replace(/<\s*a\s+([^>]+\s+)?href\s*=\s*('[^']*'|"[^"]*")(\\s[^>]*)>/ig,function(_292,_293,href,_295){
_293=(!_293)?" ":" "+_293.strip()+" ";
_295=(!_295)?"":" "+_295.strip();
return "<a"+_293+"href="+href+_295+">";
}.bind(this));
_28f=_28f.replace(/<\s*span\s*[^>]*style=([^>]*)>([^<]*)<\s*\/span\s*>/ig,function(_296,_297,_298){
var _299="",_29a="";
if(_297.match(/font-weight:\s*bold(\s+|;|'|")/ig)){
_299+="<strong>";
_29a="</strong>"+_29a;
}
if(_297.match(/font-style:\s*italic(\s+|;|'|")/ig)){
_299+="<em>";
_29a="</em>"+_29a;
}
if(_297.match(/text-decoration:\s*underline(\s+|;|'|")/ig)){
_299+="<u>";
_29a="</u>"+_29a;
}
return _299+_298+_29a;
});
_28f=_28f.replace(/<\s*pre\s*>([\s\S]*)<\s*\/pre\s*>/ig,function(_29b,_29c){
return "<pre>"+_29c.replace(/(<\s*br\s*>|<\s*br\s*\/\s*>)/ig,"\n")+"</pre>";
});
if(tidy){
_28f=_28f.replace(/(<\s*pre\s*>([\s\S]*)<\s*\/\s*pre\s*>\s*)+/ig,function(_29d){
return "<pre>"+_29d.replace(/<\s*\/\s*pre\s*><\s*pre\s*>/ig,"\n").replace(/<\s*\/?\s*pre\s*>/ig,"")+"</pre>";
});
}
_28f=_28f.replace(/<\s*p\s*>(\s|&nbsp;)*<\s*\/\s*p\s*>/ig,"");
if(this.cleanUpRules){
if(this.cleanUpRules.emptyReg){
_28f=_28f.replace(this.cleanUpRules.emptyReg,function(_29e,tag){
var _2a0=this.cleanUpRules.value["$"+tag.toLowerCase()];
return (_2a0=="-")?"":(_2a0=="+")?"<"+tag+">&nbsp;</"+tag+">":"<"+tag+"/>";
}.bind(this));
}
if(this.cleanUpRules.synReg){
_28f=_28f.replace(this.cleanUpRules.synReg,function(_2a1,_2a2,tag,_2a4){
if(_2a4==undefined||_2a4==null){
_2a4="";
}
return "<"+_2a2+this.cleanUpRules.value[tag.toLowerCase()]+" "+_2a4+">";
}.bind(this));
}
}
if(!this.needsHtmlCleanUp){
return _28f;
}
var _2a5=$H({content:_28f,tidy:tidy});
var ajax=new Ajax.Request("/xml/verifyhtml.php",{parameters:_2a5.toQueryString(),asynchronous:false,onFailure:function(_2a7){
},onSuccess:function(_2a8){
if(_2a8.responseText){
var resp=JSONstring.toObject(_2a8.responseText);
_28f=resp.cleanedText;
_28f=_28f.replace(/<\s*p\s*>(\s|&nbsp;)*<\s*\/\s*p\s*>/ig,"");
_28f=_28f.replace(/<\s*a[^>]*>(\s|&nbsp;|<\s*br\s*\/?\s*>|<[^>]*>)*<\s*\/\s*a\s*>/ig,"");
this.needsHtmlCleanUp=false;
}
}.bind(this)});
return _28f;
};
ModuleEdit.prototype._handleAutoSave=function(){
if(!this.editting||!this.tiny_mce_editor||!this.tiny_mce_editor.getDoc()){
if(this.autoSavePeriodicalExecuter!=null){
this.autoSavePeriodicalExecuter.stop();
this.autoSavePeriodicalExecuter=null;
}
return null;
}
var _2aa=this;
if(this.tiny_mce_editor.isDirty()){
var msg=tinymce.DOM.get("editor_status_"+this.data.id);
tinymce.DOM.setHTML(msg,"Saving draft...");
var _2ac=$H({id:this.data.id,save:1,art_id:this.data.art_id,content:this.getContent(tinyMCE)});
var ajax=new Ajax.Request("/xml/textdraft.php",{parameters:_2ac.toQueryString(),onFailure:function(_2ae){
$("editor_status_"+_2ac.id).update("Autosave failed: will try again later.");
},onSuccess:function(_2af){
if(!_2af.responseText){
$("editor_status_"+_2ac.id).update("Autosave failed: will try again later.");
}else{
var resp=JSONstring.toObject(_2af.responseText);
if(resp&&resp.result=="success"){
var t=new Date();
var ampm="AM";
var h=t.getHours();
var m=(t.getMinutes()<10)?("0"+t.getMinutes()):t.getMinutes();
var d=t.getDate();
var y=t.getFullYear();
var mon=["Jan","Feb","Mar","Apr","May","Jun","July","Aug","Sept","Oct","Nov","Dec"][t.getMonth()];
var ampm=(t.getHours()>=12)?"PM":"AM";
var h=(t.getHours()%12==0)?12:(t.getHours()%12);
$("editor_status_"+_2ac.id).update("Draft saved at "+h+":"+m+" "+ampm+" on "+mon+" "+d+", "+y+"!");
if(_2aa&&_2aa.tiny_mce_editor){
_2aa.tiny_mce_editor.isNotDirty=1;
}
_2aa._activateRecoverButton();
}else{
$("editor_status_"+_2ac.id).update("Autosave failed: will try again later.");
}
}
}});
}
};
ModuleEdit.prototype._checkNetworkConnection=function(_2b8,_2b9){
if(!this.editting||!this.tiny_mce_editor||!this.tiny_mce_editor.getDoc()){
if(this.checkNetworkPeriodicalExecutor!=null){
this.checkNetworkPeriodicalExecuter.stop();
this.checkNetworkPeriodicalExecuter=null;
}
return null;
}
var _2ba=this.tiny_mce_editor.id+"_network_indicator";
if(this.tiny_mce_editor.isDirty()){
var _2bb=$H({check:"ping"});
var ajax=new Ajax.Request("/xml/verifynetwork.php",{parameters:_2bb.toQueryString(),onFailure:function(_2bd){
$(_2ba).src=_2b9.src;
$(_2ba).title=_2b9.title;
},onSuccess:function(_2be){
if(!_2be.responseText){
$(_2ba).src=_2b9.src;
$(_2ba).title=_2b9.title;
}else{
var resp=JSONstring.toObject(_2be.responseText);
if(resp&&resp.result=="success"){
$(_2ba).src=_2b8.src;
$(_2ba).title=_2b8.title;
}else{
$(_2ba).src=_2b9.src;
$(_2ba).title=_2b9.title;
}
}
}});
}
};
ModuleEdit.prototype._activateRecoverButton=function(){
$(this.tiny_mce_editor.id+"_recover_button").show();
};
ModuleEdit.prototype._initializeTinyMCE=function(){
this.tiny_mce_editor=tinyMCE.activeEditor;
var _2c0=this;
var _2c1=new Image();
var _2c2=new Image();
_2c1.src="http://x.hubpages.com/x/icon_internet_on.gif";
_2c2.src="http://x.hubpages.com/x/icon_internet_off.gif";
_2c1.title="The network connection is good.";
_2c2.title="The network connection is bad.";
this.needsHtmlCleanUp=false;
this.tiny_mce_editor.onChange.add(function(ed,l,um){
if(this.needsHtmlCleanUp){
ed.setContent(this._cleanUpHtml(ed,ed.getContent(),false));
}
}.bind(this));
this.tiny_mce_editor.addCommand("hp_html_cleanup",function(ui,_2c7){
this.needsHtmlCleanUp=true;
return this._cleanUpHtml(this.tiny_mce_editor,_2c7,false);
}.bind(this));
this.tiny_mce_editor.addCommand("hp_html_tidy",function(ui,_2c9){
this.needsHtmlCleanUp=true;
return this._cleanUpHtml(this.tiny_mce_editor,_2c9,true);
}.bind(this));
var _2ca="";
this.tiny_mce_editor.addCommand("mceHubHtmlEditorContent",function(_2cb,_2cc){
if(_2cc!=null){
_2ca=_2cc;
return _2ca;
}else{
if(_2ca==""){
return null;
}else{
return _2ca;
}
}
}.bind(this));
if(!tinymce.DOM.get(this.tiny_mce_editor.id+"_network_indicator")){
var p=tinymce.DOM.get(this.tiny_mce_editor.id+"_path_row");
tinymce.DOM.add(p,"img",{id:this.tiny_mce_editor.id+"_network_indicator",src:_2c1.src,title:_2c1.title});
tinymce.DOM.add(p,"span",{},"&nbsp;");
var a=tinymce.DOM.add(p,"a",{id:this.tiny_mce_editor.id+"_recover_button",style:{"display":"none","margin-left":"10px","padding":"1px","font-size":"12px","font-weight":"bold","color":"#297ccf","cursor":"pointer"},title:"Press this button to recover using an autosaved draft",href:"#"},"recover draft");
tinymce.dom.Event.add(a,"click",function(e){
tinyMCE.execCommand("mceHubDraft",false,this.data.id);
this.tiny_mce_editor.selection.collapse();
tinymce.dom.Event.stop(e);
return false;
}.bind(this));
var _2d0=$H({id:_2c0.data.id,check:1});
var ajax=new Ajax.Request("/xml/checkifdrafts.php",{parameters:_2d0.toQueryString(),onFailure:function(_2d2){
},onSuccess:function(_2d3){
if(_2d3&&_2d3.responseText){
var resp=JSONstring.toObject(_2d3.responseText);
if(resp&&resp.result=="success"){
_2c0._activateRecoverButton();
}
}
}});
tinymce.DOM.add(p,"span",{style:"padding-left:1em;",id:"editor_status_"+this.data.id},"&nbsp;");
}
var _2d5=this.tiny_mce_editor.getParam("tiny_mce_autosave_period",0);
var _2d6=this.tiny_mce_editor.getParam("tiny_mce_check_network_period",0);
if(_2d5>0&&this.autoSavePeriodicalExecuter==null){
this.autoSavePeriodicalExecuter=new PeriodicalExecuter(function(pe){
this._handleAutoSave(this);
}.bind(this),_2d5);
}
if(_2d6>0&&this.checkNetworkPeriodicalExecuter==null){
this.checkNetworkPeriodicalExecuter=new PeriodicalExecuter(function(pe){
this._checkNetworkConnection(_2c1,_2c2,this);
}.bind(this),_2d6);
}
if(this.cleanUpRules==null){
this.cleanUpRules={value:{},syn:null,empty:null,synReg:null,emptyReg:null};
function concat_with_separator(_2d9,str,_2db){
if(str){
return str+_2d9+_2db;
}
return _2db;
};
this.tiny_mce_editor.settings.valid_elements.split(",").each(function(s){
var t=s.split("/");
var key1=t[0].replace(/^[\-#]/,"");
var _2df=null;
if(t.length>1){
var key2=t[1].replace(/^[\-#]/,"");
_2c0.cleanUpRules.value[key2.toLowerCase()]=key1;
_2c0.cleanUpRules.syn=concat_with_separator("|",_2c0.cleanUpRules.syn,key2);
_2df=(t[1].charAt(0)=="#")?"+":(t[1].charAt(0)=="-")?"-":null;
if(_2df){
_2c0.cleanUpRules.empty=concat_with_separator("|",_2c0.cleanUpRules.empty,key2);
_2c0.cleanUpRules.value["$"+key2.toLowerCase()]=_2df;
}
}
_2df=(t[0].charAt(0)=="#")?"+":(t[0].charAt(0)=="-")?"-":null;
if(_2df){
_2c0.cleanUpRules.empty=concat_with_separator("|",_2c0.cleanUpRules.empty,key1);
_2c0.cleanUpRules.value["$"+key1.toLowerCase()]=_2df;
}
});
if(this.cleanUpRules.syn){
this.cleanUpRules.synReg=new RegExp("<\\s*(/?)\\s*("+this.cleanUpRules.syn+")(\\s[^>]*)?>","ig");
}
if(this.cleanUpRules.empty){
this.cleanUpRules.emptyReg=new RegExp("<\\s*("+this.cleanUpRules.empty+")\\s*/\\s*>","ig");
}
}
};
ModuleEdit.prototype._cleanupTinyMCE=function(){
if(this.checkNetworkPeriodicalExecuter){
this.checkNetworkPeriodicalExecuter.stop();
}
if(this.autoSavePeriodicalExecuter){
this.autoSavePeriodicalExecuter.stop();
}
this.cleanUpRules=null;
this.needsHtmlCleanUp=false;
this.autoSavePeriodicalExecuter=null;
this.checkNetworkPeriodicalExecuter=null;
};
ModuleEdit.prototype.render=function(){
this.computeState();
this._renderSize();
this._renderHide();
this._renderBackground();
this._renderTypeSpecific();
this._renderMoveButtons();
this._renderFloatButtons();
if(this.data.type=="Text"){
if(this.editting&&tinyMCE.activeEditor){
this._initializeTinyMCE();
}else{
if(this.tiny_mce_editor){
this._cleanupTinyMCE();
}
}
}
};
ModuleEdit.prototype._renderSize=function(){
var _2e1=this.state.div_ele;
_2e1.style.height="auto";
};
ModuleEdit.prototype._renderFloat=function(){
var _2e2=this.state.div_ele;
if(!this.editting){
if(!this.state.floatnone){
_2e2.style.display="inline-block";
}else{
_2e2.style.display="block";
}
}
};
ModuleEdit.prototype._renderTypeSpecific=function(){
switch(this.data.type){
case "Video":
this._renderVideo();
break;
case "Quiz":
this._renderQuiz();
break;
}
};
ModuleEdit.prototype._renderHide=function(){
var cont=$(this.state.content_id);
if(!cont){
return;
}
if(null==this.data.hide){
return;
}
$(this.state.hide_text_id).style.textDecoration=(this.data.hide?"line-through":"none");
};
ModuleEdit.prototype._toggleBorder=function(){
var ele=$(this.data.div_id);
if(!ele){
return;
}
var _2e5=(this.editting)?"solid 1px #ccc":"none";
ele.style.borderRight=_2e5;
ele.style.borderLeft=_2e5;
ele.style.borderBottom=_2e5;
};
ModuleEdit.prototype._renderBackground=function(){
var ele=$(this.state.content_id);
if(!ele){
return;
}
var _2e7=-1;
if(this.data.color!=null){
_2e7=ModuleEdit._getBackgroundColor("color"+this.data.color);
}
if(!this.state.current_color){
this.state.current_color=Element.getCurrentStyle(ele).backgroundColor;
}
if(this.state.current_color&&_2e7!=-1&&_2e7!=this.state.current_color){
var _2e8=$(this.state.text_div_id+"_tbl");
if(_2e8){
var _2e9=-20;
if(this.data.color=="0"){
var _2ea=Element.getWidth(_2e8)-_2e9;
_2e8.style.width=_2ea+"px";
}else{
if(Element.hasClassName(ele,"color0")){
var _2ea=Element.getWidth(_2e8)+_2e9;
_2e8.style.width=_2ea+"px";
}
}
}
Element.removeClassName(ele,"color0");
Element.removeClassName(ele,"color1");
Element.removeClassName(ele,"color2");
Element.addClassName(ele,"color"+this.data.color);
this.state.current_color=_2e7;
}
};
ModuleEdit._getBackgroundColor=function(_2eb){
var eles=document.getElementsByClassName(_2eb);
if(eles.length>0){
var _2ed=Element.getCurrentStyle(eles.first());
return _2ed.backgroundColor;
}else{
return null;
}
};
ModuleEdit.prototype._renderMoveButtons=function(){
ModuleEdit.toggleIcon(this.resources.up_button_id,(this.editting||this.data.position==0));
ModuleEdit.toggleIcon(this.resources.down_button_id,(this.editting||this.isLast()));
};
ModuleEdit.prototype._renderFloatButtons=function(){
if(this.data.type=="Comment"){
ModuleEdit.toggleIcon("cent_"+this.data.id,true);
ModuleEdit.toggleIcon("rt_"+this.data.id,true);
return;
}
var _2ee=(this.editting||this.state.floatnone);
ModuleEdit.toggleIcon("cent_"+this.data.id,_2ee);
_2ee=(this.editting||this.state.floatright||this.isLast());
ModuleEdit.toggleIcon("rt_"+this.data.id,_2ee);
};
ModuleEdit.prototype._toggleDeleteButton=function(){
ModuleEdit.toggleIcon(this.data.id+"_delete",(this.editting));
};
ModuleEdit.prototype._toggleDiscardButton=function(){
this.toggleDisplay(this.resources.discard_button_id);
};
ModuleEdit.prototype._toggleEditButton=function(){
$(this.resources.edit_button_id).className=(this.editting)?"savebtn":"editbtn";
$(this.resources.edit_button_id).innerHTML=(this.editting)?"save&nbsp;":"edit&nbsp;";
$(this.resources.edit_link_id).title=(this.editting)?"Save this Capsule":"Edit this Capsule";
};
ModuleEdit.prototype._renderPosition=function(){
alert("renderPosition deprecated?");
var _2ef=this.data.position+1;
if(this.state.last_position!=_2ef){
Element.update(this.resources.position_id,String(_2ef));
this.state.last_position=_2ef;
}
};
ModuleEdit.prototype._renderVideo=function(){
var size=(this.state.floatnone)?"Big":"Small";
var css="video"+this.state.video_type+size;
if(this.state.video_css_class!=css){
var _2f2=$(this.resources.video_results_id);
if(_2f2){
var _2f3=_2f2.getElementsByTagName("embed")[0];
}
if(_2f3){
if(_2f3.className!=css){
_2f3.className=css;
}
this.state.video_css_class=css;
}
}
};
ModuleEdit.prototype.unselectDragElements=function(){
this.state.reorder.items.each(function(item){
item.ele.style.backgroundColor="";
});
};
ModuleEdit.prototype.wireLinkCtrlHandlers=function(){
var eles=document.getElementsByClassName("link_add_button",this.data.div_id);
eles.each(function(ele){
ele.onclick=this.onclickLinkFindAdd.bindAsEventListener(this);
}.bind(this));
};
ModuleEdit.prototype.onclickLinkFindAdd=function(_2f7){
_2f7=_2f7||window.event;
var elem=Event.findElement(_2f7,"div");
var _2f9=document.getElementsByClassName("link_hub",elem)[0];
$(this.state.link_status_id).update("");
this.addLink(_2f9.href,_2f9.innerHTML,_2f9.title);
Element.remove(elem);
return false;
};
ModuleEdit.prototype.onclickLinkAddInfo=function(){
var url=$F(this.state.link_url_id).trim().toString();
var _2fb=$F(this.state.link_title_id).trim().toString();
var desc=$F(this.state.link_desc_id).trim().toString();
regex=/^(ftp|https?):\/\/.+/;
if(!regex.test(url.toLowerCase())){
url="http://"+url;
}
this.addLink(url,_2fb,desc);
};
ModuleEdit.prototype.addLink=function(url,_2fe,desc){
if(url.trim().length===0){
return;
}
if(_2fe.length===0){
_2fe=url;
}
var l_id="";
this.data.links_added++;
l_id="n"+(this.data.links_added-1);
_2fe=_2fe.replace(/(\s|&nbsp;|\xA0)+/g," ");
desc=desc.replace(/(\s|&nbsp;|\xA0)+/g," ");
this.state.links.links[l_id]={id:l_id,dirty:true,isnew:true,url:url.stripScripts().stripTags(),name:_2fe.escapeHTML(),description:desc.escapeHTML()};
this.state.linkIndex[l_id]=this.state.links.links[l_id];
this.addLinkDragElement(l_id,_2fe.toString(),true);
this.state.reorder.relayout();
Field.clear(this.state.link_url_id);
Field.clear(this.state.link_title_id);
Field.clear(this.state.link_desc_id);
Field.clear(this.state.link_desc_len_id);
if(this.state.reorder.items.length>1){
Element.show(this.resources.link_drag_title);
}else{
Element.hide(this.resources.link_drag_title);
}
this.openEditBox(l_id);
};
ModuleEdit.prototype.onclickLinkUrlUpdate=function(){
this.linkHide(this.state.link_status_id);
};
ModuleEdit.prototype.onclickLinkUpdate=function(){
var url=$F(this.resources.link_edit_url).trim().stripScripts().stripTags();
var _302=$F(this.resources.link_edit_title).trim().escapeHTML();
var desc=$F(this.resources.link_edit_desc).trim().escapeHTML();
if(url.length===0){
return;
}
if(_302.length===0){
_302=url;
}
var l_id=this.state.select_id;
var html=$("link_name_"+l_id);
var rec=this.state.linkIndex[l_id];
rec.dirty=true;
rec.url=url.toString();
rec.name=_302.toString();
rec.description=desc.toString();
var _307=rec.name.replace(/\<[^>]*\>/gi,"");
$("link_name_"+l_id).update(ellipse(_307,60));
};
ModuleEdit.prototype.onclickLinkSelect=function(_308){
if(this.state.select_id!=_308){
this.state.select_id=_308;
this.unselectDragElements();
$("linkdrg_"+_308).style.backgroundColor="#ffc";
var link=this.state.linkIndex[_308];
this.populateLinkEdit(link.url,link.name,link.description);
}
if(_308){
this.linkDisplay("link_edit_box");
}
};
ModuleEdit.prototype.populateLinkEdit=function(href,text,desc){
if(href==text){
text="";
}
desc=desc.unescapeHTML().substring(0,250);
$(this.resources.link_edit_url).value=href;
$(this.resources.link_edit_title).value=text.unescapeHTML();
$(this.resources.link_edit_desc).value=desc.unescapeHTML();
$(this.resources.link_edit_desc_len).value=250-desc.length;
};
ModuleEdit.prototype.onclickLinkRemove=function(id){
var _30e=id;
this.state.linkIndex[_30e].deleted=true;
this.state.linkIndex[_30e].dirty=true;
this.state.reorder.remove(_30e);
Field.clear(this.resources.link_edit_url);
Field.clear(this.resources.link_edit_title);
Field.clear(this.resources.link_edit_desc);
if(this.state.reorder.items.length>0){
Element.show(this.resources.link_drag_title);
}else{
Element.hide(this.resources.link_drag_title);
}
this.state.reorder.relayout(true);
if(this.state.select_id!=id&&this.state.select_id!=null){
this.openEditBox(this.state.select_id);
}else{
this.state.select_id=null;
}
};
ModuleEdit.prototype.onclickLinkFind=function(){
this.state.link_search_id=this.state.link_search_term_id;
this.state.link_search_type="hub";
if(!$(this.state.link_search_id)){
return;
}
$(this.state.link_results_id).innerHTML="Searching...";
this.linkDisplay("link_find_box");
var _30f=$F(this.state.link_search_id);
var _310=this.state.link_search_type;
var _311=_30f+"_"+_310;
var _312=$H({search:_30f,maxitems:10,type:this.state.link_search_type}).toQueryString();
var ajax=new Ajax.Updater({success:this.state.link_results_id},"/xml/linkresults.php",{method:"post",parameters:_312,onFailure:reportError,onComplete:function(){
if($(this.state.link_results_id).innerHTML==""){
$(this.state.link_results_id).innerHTML="No results found.";
}
this.wireLinkCtrlHandlers();
}.bind(this)});
};
ModuleEdit.prototype.onclickLinkTab=function(_314){
if(!_314){
return;
}
var eles=document.getElementsByClassName("findtaba");
if($(_314+"_findtab")){
var tab=$(_314+"_findtab");
eles.each(function(ele){
ele.className="findtab";
});
tab.className="findtaba";
this.state.link_search_type=_314;
}
if($F(this.state.link_search_id)){
this.onclickLinkFind();
}
};
ModuleEdit.prototype.onclickLinkAdd=function(_318,url,_31a){
if(!_31a&&this.state.select_id){
this.closeEditBox(this.state.select_id);
}
if(!_318){
_318=this.renderLinkAdd.bind(this);
}
if(!url){
url=$F(this.state.link_url_id);
}
if(!url||url.trim().length==0){
return false;
}
var _31b="url="+url;
var ajax=new Ajax.Request("/xml/checklink.php",{method:"get",parameters:_31b,onFailure:reportError,onComplete:_318});
};
ModuleEdit.prototype.onclickLinkTest=function(){
this.onclickLinkAdd(this.renderLinkTest.bind(this),$F(this.resources.link_edit_url),1);
};
ModuleEdit.prototype.renderLinkAdd=function(req){
$(this.state.link_title_id).value="";
$(this.state.link_desc_id).value="";
try{
var j=JSONstring.toObject(req.responseText);
}
catch(e){
}
if(j){
if(j.valid){
(j.title&&j.title.length>0)&&($(this.state.link_title_id).value=j.title.unescapeHTML());
(j.desc&&j.desc.length>0)&&($(this.state.link_desc_id).value=j.desc.unescapeHTML());
$(this.state.link_desc_len_id).value=(j.desc!=null)?250-j.desc.length:250;
}
}
return this.onclickLinkAddInfo();
};
ModuleEdit.prototype.renderLinkTest=function(req){
try{
var j=JSONstring.toObject(req.responseText);
}
catch(e){
}
if(j){
if(j.status&&j.status.length>0){
$(this.state.link_status_id).update(j.status);
this.linkShow(this.state.link_status_id);
}
}
};
ModuleEdit.prototype.linkHide=function(_321){
switch(_321){
case this.state.link_add_field:
$(this.state.link_add_field).hide();
break;
case this.state.link_search_field:
$(this.state.link_findbox_id).hide();
$(this.state.link_search_field).hide();
break;
case this.state.link_edit_box:
$(this.state.link_edit_box).hide();
this.closeEditBox(this.state.select_id);
break;
case this.state.link_status_id:
$(this.state.link_status_id).hide();
$(this.state.link_status_button_id).show();
break;
}
};
ModuleEdit.prototype.linkShow=function(_322){
switch(_322){
case this.state.link_add_field:
$(this.state.link_add_field).show();
break;
case this.state.link_search_field:
$(this.state.link_search_field).show();
break;
case this.state.link_edit_box:
$(this.state.link_edit_box).show();
break;
case this.state.link_findbox_id:
$(this.state.link_findbox_id).show();
break;
case this.state.link_status_id:
$(this.state.link_status_id).show();
$(this.state.link_status_button_id).hide();
break;
}
};
ModuleEdit.prototype.linkDisplay=function(type){
if(type=="link_add_field"){
this.linkHide(this.state.link_search_field);
}
if(type=="link_search_field"){
this.linkHide(this.state.link_add_field);
}
if(type!="link_edit_box"){
this.linkHide(this.state.link_edit_box);
}
switch(type){
case "link_add_field":
this.linkShow(this.state.link_add_field);
break;
case "link_search_field":
this.linkShow(this.state.link_search_field);
break;
case "link_edit_box":
this.linkShow(this.state.link_edit_box);
break;
case "link_find_box":
this.linkShow(this.state.link_findbox_id);
break;
}
};
ModuleEdit.prototype.getElementPosition=function(id){
var _325=0;
var _326=0;
var _327=document.getElementById(id);
while(_327){
_325+=_327.offsetLeft;
_326+=_327.offsetTop;
_327=_327.offsetParent;
}
return {left:_325,top:_326};
};
ModuleEdit.prototype.closeEditBox=function(id){
if(id){
this.displayLinkDragElement(id,"edit link");
this.state.select_id=id;
this.onclickLinkUpdate();
}
$(this.state.link_edit_box).hide();
this.state.reorder.enable();
this.state.reorder.relayout(true);
this.state.select_id=null;
return false;
};
ModuleEdit.prototype.displayLinkDragElement=function(id,text,_32b,item){
if(_32b){
bgColor="#ffc";
}else{
bgColor="#e5e5e5";
}
$("linkedit_"+id+"_span").update(text);
$("linkdrg_"+id).style.backgroundColor=bgColor;
if(item){
var ele=$(item.ele);
ele.style.top=item.startY+"px";
}
};
ModuleEdit.prototype.openEditBox=function(id){
var _32f=this.state.reorder.items;
var _330=this.state.reorder.options;
var _331=this.state.reorder.canvas;
var i,item=_32f[0];
if(item.id!=id){
for(i=0;item.item_id!=id&&i<_32f.length;i++,item=_32f[i]){
this.displayLinkDragElement(item.item_id,"edit link");
}
}
if(item.item_id==id){
this.displayLinkDragElement(item.item_id,"done",true);
var rows=Math.ceil(_32f.length/_330.num_cols);
var _335=(rows*(_330.ele_space_per_v))+$(this.state.link_edit_box).getHeight()+_330.ele_buffer_v;
if(_335!=parseInt(_331.style.height,10)){
_331.style.height=_335+"px";
}
this.state.select_id=item.item_id;
this.linkHide(this.state.link_status_id);
var link=this.state.linkIndex[item.item_id];
this.populateLinkEdit(link.url,link.name,link.description);
var top=(Math.floor((i+1)/_330.num_cols))*_330.ele_space_per_v-1;
$(this.state.link_edit_box).style.top=top+"px";
$(this.state.link_edit_box).show();
var _338=$(this.state.link_edit_box).getHeight()+_330.ele_buffer_v;
var _339=new fx.Height(this.state.link_edit_box,{duration:250});
var _33a=$(this.state.link_edit_box).getHeight()-_330.ele_buffer_v;
_339.hide();
_339.custom(0,_33a);
}
if(i<_32f.length){
for(i++,item=_32f[i];i<_32f.length;i++,item=_32f[i]){
var _33b=Math.floor(i/_330.num_cols);
item.startY=(_33b*_330.ele_space_per_v)+_338;
this.displayLinkDragElement(item.item_id,"edit link",false,item);
}
}
this.state.reorder.disable();
this.linkDisplay("link_edit_box");
return false;
};
ModuleEdit.prototype.addLinkDragElement=function(id,name,top){
if(!this.state.reorder){
return;
}
name=ellipse(name,60);
name=name.replace(/\<[^>]*\>/gi,"");
var _33f=document.createElement("div");
_33f.id="linkdrg_"+id;
_33f.className="reorderableLinkWrapper";
_33f.style.zIndex=1;
_33f.style.overflow="hidden";
_33f.onclick=function(){
return false;
}.bind(this);
_33f.onselectstart=function(){
return false;
};
var _340="linkedit_"+id;
var _341="linkremove_"+id;
this.edit="<li><a id=\""+_340+"\" href=\"#\"><span id=\""+_340+"_span\" class=\"editbtn\">edit link</span></a></li>";
this.remove="<li style=\"padding-left:18px\"><a title=\"delete\" id=\""+_341+"\" href=\"#\"><img alt=\"delete\" src=\"/x/hubtool_discard_tag.gif\"></a></li>";
_33f.innerHTML="<span class=\"linkname\" id=\"link_name_"+id+"\" style=\"float: left;\">"+name+"</span>"+" <ul class=\"linkButtons\">"+this.remove+this.edit+"</ul>";
if(top){
$(this.resources.link_drag_section).insertBefore(_33f,$(this.resources.link_drag_section).firstChild);
}else{
$(this.resources.link_drag_section).appendChild(_33f);
}
$(_341).onclick=function(){
$(this.state.link_edit_box).hide();
this.onclickLinkRemove(id);
return false;
}.bind(this);
$(_340).onclick=function(){
this.state.reorder.relayout(true);
if($("linkedit_"+id+"_span").innerHTML=="done"){
this.closeEditBox(id);
}else{
this.openEditBox(id);
}
return false;
}.bind(this);
this.state.reorder.add(new ModuleContentReorderItem("linkdrg_"+id,id,this.state.reorder),top);
$(this.resources.link_drag_title).show();
};
ModuleEdit.prototype.onclickImageAddUpload=function(){
var _342=document.createElement("input");
_342.type="file";
_342.className="upload";
_342.name=this.resources.image_upload_id+(new Date()).getTime().toString().substr(3);
var _343=$(this.resources.image_upload_section_id).getElementsByTagName("div")[0];
_343.appendChild(_342);
};
ModuleEdit.prototype.onclickImageAddImport=function(){
var div=document.createElement("div");
div.className="import";
var _345=document.createElement("label");
var url=document.createTextNode("Url: ");
_345.appendChild(url);
var _347=document.createElement("input");
_347.type="text";
_347.name=this.resources.image_import_id+(new Date()).getTime().toString().substr(3);
div.appendChild(_345);
div.appendChild(_347);
var _348=$(this.resources.image_import_section_id).getElementsByTagName("div")[0];
_348.appendChild(div);
};
ModuleEdit.prototype.onclickCsvLoad=function(){
if($F(this.resources.table_file_id).strip()!=""||$F(this.resources.table_url_id).strip()!=""){
Element.show(this.resources.table_loading_id);
$(this.resources.table_edit_form_id).submit();
}
};
ModuleEdit.prototype.onclickImageLoad=function(){
Element.show(this.resources.image_upload_gif_id);
$(this.resources.image_upload_target_id).style.height="0px";
if($(this.resources.image_upload_target_id)){
$(this.resources.image_load_form_id).submit();
}
};
ModuleEdit.prototype.imageLoadComplete=function(){
this.clearImageUploadForm();
Element.hide(this.resources.image_upload_gif_id);
$(this.resources.image_upload_target_id).style.height="60px";
if(this.state.reorder.items.length>1){
Element.show(this.resources.image_drag_title);
}else{
Element.hide(this.resources.image_drag_title);
}
};
ModuleEdit.prototype.clearImageUploadForm=function(){
var _349=function(elt){
elt.remove();
};
var _34b=$$("#"+this.resources.image_import_section_id+" input");
_34b.each(_349);
var _34c=$$("#"+this.resources.image_import_section_id+" label");
_34c.each(_349);
this.onclickImageAddImport();
var _34d=$$("#"+this.resources.image_upload_section_id+" input");
_34d.each(_349);
this.onclickImageAddUpload();
};
ModuleEdit.prototype.addImageDragElement=function(_34e,_34f,cap){
var _351=$(document.createElement("img"));
_351.id="image_tn_"+_34e;
_351.src=_34f;
_351.alt=cap;
_351.title=cap;
Event.observe(_351,"selectstart",function(){
return false;
});
var _352=document.createElement("div");
_352.id="image_tn_wrapper_"+_34e;
_352.className="reorderableImageWrapper";
Event.observe(_352,"click",function(_353){
if(null!=_353&&(Event.element(_353).tagName=="A"||Event.element(_353).tagName=="SELECT"||Event.element(_353).tagName=="TEXTAREA")){
return;
}else{
$("image_caption_"+_34e).focus();
}
}.bind(this));
_352.onclick=function(){
};
var _354=$(document.createElement("a"));
Event.observe(_354,"click",function(_355){
this.onclickImageRemove(_34e);
}.bind(this));
_354.appendChild(document.createTextNode("Delete"));
_354.setStyle({cursor:"pointer"});
var _356=$(document.createElement("div"));
_356.appendChild(_351);
_356.appendChild(document.createElement("br"));
_356.appendChild(_354);
_352.appendChild(_356);
var _357=$(document.createElement("label"));
_357.appendChild(document.createTextNode("Caption: "));
var _358=$(document.createElement("textarea"));
_358.name="image_caption_"+_34e;
_358.id="image_caption_"+_34e;
_358.setAttribute("wrap","virtual");
if(undefined!=this.state.photoData&&undefined!=this.state.photoData[_34e]){
_358.value=this.state.photoData[_34e].caption;
}
captionDiv=$(document.createElement("div"));
captionDiv.appendChild(_357);
captionDiv.appendChild(document.createElement("br"));
captionDiv.appendChild(_358);
_352.appendChild(captionDiv);
var _359=$(document.createElement("label"));
_359.appendChild(document.createTextNode("Image size: "));
var size=$(document.createElement("select"));
size.id="image_size_"+_34e;
Event.observe(size,"focus",function(){
this.state.reorder.disable();
}.bind(this));
Event.observe(size,"blur",function(){
this.state.reorder.enable();
}.bind(this));
var _35b=new Array("Full Width","Half Width","Quarter Width");
["Full Width","Half Width","Quarter Width"].each(function(_35c){
var _35d=document.createElement("option");
_35d.appendChild(document.createTextNode(_35c));
size.appendChild(_35d);
});
size.setStyle({verticalAlign:"middle"});
if(undefined!=this.state.photoData&&undefined!=this.state.photoData[_34e]){
size.selectedIndex=this.state.photoData[_34e].maxSize;
}
var _35e=document.createElement("div");
_35e.appendChild(_359);
_35e.appendChild(document.createElement("br"));
_35e.appendChild(size);
_352.appendChild(_35e);
$(this.resources.image_drag_section).appendChild(_352);
var _35f=new ModuleContentReorderItem("image_tn_wrapper_"+_34e,_34e,this.state.reorder);
_35f.setBeforeStartCallback(imageDraggableBeforeStartCallback);
this.state.reorder.add(_35f);
};
function imageDraggableBeforeStartCallback(e){
if(null!=e&&Event.element(e).tagName=="TEXTAREA"){
return false;
}else{
return true;
}
};
ModuleEdit.prototype.unselectImageThumbnails=function(){
var _361=$(this.resources.image_drag_section).getElementsByTagName("img");
$A(_361).each(function(ele){
ele.style.backgroundColor="";
});
};
ModuleEdit.prototype.updateImageData=function(){
var _363=$(this.resources.image_drag_section).getElementsByTagName("img");
var _364=this.state.photoData;
$A(_363).each(function(im){
var num=im.id.substring(9);
var _367=$("image_caption_"+num).value.replace(/<[^>]+(>|$)/g,"");
_367=_367.replace(/\n+/g," ");
_364[num].caption=_367;
if($("image_size_"+num).selectedIndex!=_364[num].maxSize){
_364[num].maxSize=$("image_size_"+num).selectedIndex;
}
});
};
ModuleEdit.prototype.onclickImageRemove=function(_368){
this.state.images_removed.push(_368);
delete this.state.photoData[_368];
var _369=$("image_tn_wrapper_"+_368);
var _36a=_369.nextSibling?_369.nextSibling:_369.previousSibling;
var _36b=-1;
if(null!=_36a&&_36a.id){
_36b=_36a.id.match(/[0-9]+/g)[0];
}
this.state.reorder.remove(_368);
this.state.reorder.relayout();
if(this.state.reorder.items.length>1){
Element.show(this.resources.image_drag_title);
}else{
Element.hide(this.resources.image_drag_title);
}
};
ModuleEdit.prototype.onclickEbayPreview=function(){
var _36c=$H({search:$F(this.resources.ebay_keywords_id),seller:$F(this.resources.ebay_seller_id),maxitems:$F(this.resources.max_results_id)}).toQueryString();
var ajax=new Ajax.Updater({success:this.resources.ebay_results_id},"/xml/ebayresults.php",{parameters:_36c,onFailure:reportError,onComplete:function(){
}});
};
ModuleEdit.prototype.clearAmazonAsin=function(i){
$(this.state.amazon_asin_input_id+i).value="";
$(this.state.amazon_description_id+i).value="";
$(this.state.amazon_description_link_id+i).style.display="inline";
Element.hide($(this.state.amazon_description_div_id+i));
};
ModuleEdit.prototype.changeNumDisplayedAmazon=function(){
if($F(this.state.amazon_searchtype_id)=="Keyword"){
return;
}
var max=$F(this.state.max_max_id);
var num=$F(this.state.max_id);
var i;
var _372;
for(i=1;i<=max;i+=1){
if(i<=num){
Element.show($(this.state.amazon_asin_div_id+i));
}else{
Element.hide($(this.state.amazon_asin_div_id+i));
this.clearAmazonAsin(i);
}
}
};
ModuleEdit.prototype.displayAmazonKeywordUI=function(){
Element.hide($(this.state.amazon_searchtype_div_id));
Element.hide($(this.state.amazon_asin_search_div_id));
Element.show($(this.state.amazon_keyword_search_div_id));
Element.show($(this.state.amazon_max_display_div_id));
Element.hide($(this.state.amazon_numbered_div_id));
};
ModuleEdit.prototype.displayAmazonAsinUI=function(){
Element.hide($(this.state.amazon_searchtype_div_id));
Element.show($(this.state.amazon_asin_search_div_id));
Element.hide($(this.state.amazon_keyword_search_div_id));
Element.show($(this.state.amazon_max_display_div_id));
Element.show($(this.state.amazon_numbered_div_id));
};
ModuleEdit.prototype.displayAmazonUndecidedUI=function(){
Element.show($(this.state.amazon_searchtype_div_id));
Element.hide($(this.state.amazon_asin_search_div_id));
Element.hide($(this.state.amazon_keyword_search_div_id));
Element.hide($(this.state.amazon_max_display_div_id));
Element.hide($(this.state.amazon_numbered_div_id));
};
ModuleEdit.prototype.displayCorrectAmazonType=function(){
var type=this.data.searchtype;
if(type=="Keyword"&&this.data.keywords==""){
type="Undecided";
}
if(type=="Asin"&&this.data.asins==""){
type="Undecided";
}
switch(type){
case "Keyword":
this.displayAmazonKeywordUI();
break;
case "Asin":
this.displayAmazonAsinUI();
break;
case "Undecided":
this.displayAmazonUndecidedUI();
}
};
ModuleEdit.prototype.setAmazonSearchType=function(type){
$(this.state.amazon_searchtype_id).value=type;
switch(type){
case "Keyword":
this.displayAmazonKeywordUI();
break;
case "Asin":
this.displayAmazonAsinUI();
break;
}
};
ModuleEdit.prototype.amazonStartOver=function(){
var max=$F(this.state.max_max_id);
var i;
for(i=1;i<=max;i+=1){
this.clearAmazonAsin(i);
}
$(this.state.max_id).value=4;
$(this.state.amazon_numbered_id).checked=false;
this.changeNumDisplayedAmazon();
$(this.state.keywords_id).value="";
$(this.state.amazon_searchindex_id).value="All";
$(this.state.amazon_results_id).innerHTML="";
this.displayAmazonUndecidedUI();
};
ModuleEdit.prototype.addAmazonDescription=function(_377){
Element.hide($(this.state.amazon_description_link_id+_377));
Element.show($(this.state.amazon_description_div_id+_377));
};
ModuleEdit.prototype.getSafeAsin=function(i){
var asin=$F(this.state.amazon_asin_input_id+i);
asin=asin.replace(/\s+/g,"");
return asin;
};
ModuleEdit.prototype.getSafeDescription=function(i){
var des=$F(this.state.amazon_description_id+i);
des=des.replace(/%\*%/g,"");
return des;
};
ModuleEdit.prototype.implodeAsins=function(){
var max=$F(this.state.max_max_id);
var _37d=/amazon/i;
var _37e="";
var i;
for(i=1;i<=max;i+=1){
var _380=this.getSafeAsin(i);
var _381=(_37d.test(_380))?/\/[A-Z0-9]{10}/:/[A-Z0-9]{10}/;
var asin=(_381.test(_380))?_380.match(_381)[0].replace(/\//g,""):_380;
if(asin!=""){
$(this.state.amazon_asin_input_id+i).value=asin;
_37e+=asin+"\n";
}
}
return _37e;
};
ModuleEdit.prototype.implodeDescriptions=function(){
if($F(this.state.amazon_searchtype_id)=="Keyword"){
return "";
}
var num=$F(this.state.max_id);
var _384=/amazon/i;
var _385="";
var i;
for(i=1;i<=num;i+=1){
var asin=this.getSafeAsin(i);
_385+=asin+":"+this.getSafeDescription(i);
if(i!=num){
_385+="%*%";
}
}
return _385;
};
ModuleEdit.prototype.onclickAmazonPreview=function(){
var _388=this.implodeAsins();
var _389=this.implodeDescriptions();
var _38a=($F(this.state.amazon_numbered_id)=="on")?1:0;
var _38b=$H({search:$F(this.state.keywords_id),maxitems:$F(this.state.max_id),searchIndex:$F(this.state.amazon_searchindex_id),searchType:$F(this.state.amazon_searchtype_id),asins:_388,descriptions:_389,numbered:_38a}).toQueryString();
var ajax=new Ajax.Updater({success:this.state.amazon_results_id},"/xml/amazonresults.php",{parameters:_38b,onFailure:reportError,onComplete:function(){
}});
};
ModuleEdit.prototype.toggleMap=function(){
this.toggleDisplay(this.state.map_edit_id);
if(this.editting){
if(!this.state.map_state){
Event.observe(this.state.map_type_select_id,"change",this.changeMapType.bind(this));
Event.observe(this.state.map_geocode_search_id,"click",this.geocodeSearch.bind(this));
Event.observe(this.state.map_bounds_id,"click",function(_38d){
this.updateMapBounds();
var adj=$(this.state.map_adjusting_id);
adj.show();
var fade=new fx.Opacity(adj,{duration:1500,transition:fx.cubic});
fade.toggle();
Event.stop(_38d);
}.bind(this));
this.loadMapState();
this.state.reorder=new ModuleContentReorder(this.state.map_markers_reorder_id,1,150,24);
this.state.reorder.setonchangecallback(function(){
this.updateMapMarkerProperties();
this.renderMap(true);
}.bind(this));
}
this.state.reorder.removeAll();
for(var i=0;i<this.state.map_state.markers.length;i++){
this.renderMapMarkerEditor(this.state.map_state.markers[i]);
}
this.renderMap();
$(this.state.map_type_select_id).value=this.state.map_state.mapType;
this.state.map_listeners.push(google.maps.event.addListener(this.getMap(),"zoom_changed",function(_391){
this.state.map_state.zoom=this.getMap().getZoom();
}.bind(this)));
this.state.map_listeners.push(google.maps.event.addListener(this.getMap(),"center_changed",function(_392){
var _393=this.getMap().getCenter();
this.state.map_state.lat=_393.lat();
this.state.map_state.lng=_393.lng();
}.bind(this)));
}else{
if(this.data.dirty){
this.updateMapMarkerProperties();
this.saveMapState();
}
this.removeMapListeners();
this.renderMap(true);
}
};
ModuleEdit.prototype.getMap=function(){
return mm.getMapById(this.data.id).map;
};
ModuleEdit.prototype.updateMapMarkerProperties=function(){
var _394=[];
this.state.map_state.markers=[];
$$("#"+this.state.map_markers_reorder_id+" .map_marker_reorder").each(function(elt){
_394.push([parseInt(elt.getStyle("top")),elt]);
});
_394.sort(function(a,b){
return a[0]-b[0];
});
for(var i=0;i<_394.length;i++){
elt=_394[i][1];
var m={lat:$F(elt.down("input[name=lat]")),lng:$F(elt.down("input[name=lng]")),position:i,name:$F(elt.down("input[name=name]")),address:$F(elt.down("input[name=address]")),description:$F(elt.down("textarea")),id:$F(elt.down("input[name=id]"))};
this.state.map_state.markers.push(m);
elt.down("strong.marker_letter").innerHTML=mapLetterFromPosition(i)+".";
}
};
ModuleEdit.prototype.geocodeSearch=function(_39a){
var _39b=$F(this.state.map_geocode_address_id).strip();
if(_39b==""){
$(this.state.map_geocode_results_id).innerHTML="<p>Please type an address to search for.</p>";
return;
}
if(!this.state.geocoder){
this.state.geocoder=new google.maps.Geocoder();
}
this.state.geocoder.geocode({"address":_39b},function(_39c,_39d){
if(_39d==google.maps.GeocoderStatus.OK){
this.state.geocode_results=_39c;
this.state.geocode_search_phrase=_39b;
var html="<ol>";
for(var i=0;i<_39c.length;i++){
var r=_39c[i];
if(this.state.map_state.markers.length){
html+="<li><strong>"+r.formatted_address+"</strong> - <a href=\"#\" class=\"add_marker\" title=\"add location to map\" onclick=\"man.getById("+this.data.id+").addMapResultMarker("+i+"); return false;\">Pin a marker</a></li>";
}else{
html+="<li><strong>"+r.formatted_address+"</strong> - <a href=\"#\" onclick=\"man.getById("+this.data.id+").addMapResultMarker("+i+"); return false;\">Pin a marker</a> or <a href=\"#\" onclick=\"man.getById("+this.data.id+").mapResult("+i+"); return false;\">just go to this location</a>.</li>";
}
}
html+="</ol>";
$(this.state.map_geocode_results_id).innerHTML=html;
}else{
if(_39d==google.maps.GeocoderStatus.ZERO_RESULTS){
$(this.state.map_geocode_results_id).innerHTML="<p>No results found for '"+_39b+"'. Please try again.</p>";
}else{
$(this.state.map_geocode_results_id).innerHTML="<p>Uh oh! There was a problem. Please contact team@hubpages.com for assistance.</p>";
}
}
}.bind(this));
};
ModuleEdit.prototype.mapResult=function(_3a1){
$(this.state.map_geocode_address_id).value="";
var r=this.state.geocode_results[_3a1];
if(!r){
return;
}
this.getMap().setCenter(r.geometry.location);
this.getMap().fitBounds(r.geometry.viewport);
$(this.state.map_geocode_results_id).innerHTML="";
};
ModuleEdit.prototype.addMapResultMarker=function(_3a3){
$(this.state.map_geocode_address_id).value="";
var r=this.state.geocode_results[_3a3];
if(!r){
return;
}
var _3a5=mm.getMapById(this.data.id);
var _3a6=this.state.map_state.markers.length;
if(_3a6>=10){
alert("Sorry, you can't have more than 10 markers on your map!");
return;
}
var loc=r.geometry.location;
var _3a8={name:this.state.geocode_search_phrase,address:r.formatted_address,description:"",lat:loc.lat(),lng:loc.lng(),id:"new_"+this.state.map_marker_index++};
this.state.map_state.markers.push(_3a8);
this.renderMap(true);
if(_3a6==0){
this.getMap().fitBounds(r.geometry.viewport);
}else{
this.updateMapBounds();
}
$(this.state.map_geocode_results_id).innerHTML="";
this.renderMapMarkerEditor(_3a8,true);
};
ModuleEdit.prototype.renderMapMarkerEditor=function(m,open){
var _3ab=$(this.state.map_markers_reorder_id).immediateDescendants().size();
var _3ac=60;
var _3ad=$(document.createElement("div"));
_3ad.addClassName("map_marker_drag_bar");
var _3ae="<ul class=\"map_buttons\">";
_3ae+="<li><a href=\"#\" title=\"delete\" class=\"marker_delete\"><img src=\"/x/hubtool_discard_tag.gif\" alt=\"delete\"/></a></li>";
_3ae+="<li><a href=\"#\" class=\"marker_edit\">edit</a></li>";
_3ae+="<li><a href=\"#\" class=\"marker_done\" style=\"display: none;\">done</a></li>";
_3ae+="</ul>";
_3ae+="<strong class=\"marker_letter\">"+mapLetterFromPosition(_3ab)+".</strong> ";
_3ae+="<span class=\"marker_name\">"+m.name.truncate(_3ac)+"</span>";
_3ad.innerHTML=_3ae;
var _3af=$(document.createElement("div"));
_3af.addClassName("map_marker");
_3af.setStyle({display:"none"});
var _3b0="marker_des_"+m.id;
var _3b1="marker_chars_"+m.id;
var _3b2="charCounter('"+_3b0+"','"+_3b1+"',150);";
var _3b3="<label>Location name:</label><br/>";
_3b3+="<input type=\"text\" name=\"name\" maxlength=\"100\" value=\""+m.name+"\"/><br/>";
_3b3+="<label>Address:</label><br/>";
_3b3+="<input type=\"text\" name=\"address\" maxlength=\"100\" value=\""+m.address+"\"/><br/>";
_3b3+="<label>Description:</label><br/>";
_3b3+="<textarea name=\"description\" id=\""+_3b0+"\" onkeyup=\""+_3b2+"\" onkeydown=\""+_3b2+"\" onchange=\""+_3b2+"\">"+m.description+"</textarea>";
_3b3+="<input type=\"text\" id=\""+_3b1+"\" class=\"chars_left\" value=\""+(150-m.description.length)+"\" /> characters left";
_3b3+="<p>The location name will be displayed when a user's mouse hovers over the marker. When clicked, the full description will be displayed.</p>";
_3b3+="<input name=\"id\" type=\"hidden\" value=\""+m.id+"\"/>";
_3b3+="<input name=\"lat\" type=\"hidden\" value=\""+m.lat+"\"/>";
_3b3+="<input name=\"lng\" type=\"hidden\" value=\""+m.lng+"\"/>";
_3af.innerHTML=_3b3;
var _3b4=$(document.createElement("div"));
_3b4.id="map_marker_reorder_"+m.id;
_3b4.addClassName("map_marker_reorder");
_3b4.appendChild(_3ad);
_3b4.appendChild(_3af);
_3b4.onclick=function(){
};
if(_3ab==0){
$$("#"+this.state.map_edit_id+" .map_marker_present").each(function(elt){
elt.show();
});
}
if(_3ab==1){
$$("#"+this.state.map_edit_id+" .multiple_map_markers").each(function(elt){
elt.show();
});
}
$(this.state.map_markers_reorder_id).appendChild(_3b4);
var _3b7=new ModuleContentReorderItem(_3b4.id,m.id,this.state.reorder);
this.state.reorder.add(_3b7);
this.state.reorder.relayout();
_3af.down("input").observe("keyup",function(e){
var _3b9=Event.findElement(e,"input");
_3b9.up(".map_marker_reorder").down(".map_marker_drag_bar").down(".marker_name").innerHTML=$F(_3b9).truncate(_3ac);
});
_3ad.down("a.marker_delete").observe("click",function(e){
var _3bb=Event.findElement(e,"a");
var _3bc=_3bb.up(".map_marker_reorder");
if(_3bc.down(".map_marker").visible()){
var done=_3bb.up("li").next().next().down("a");
this.doneEditingMarker(done);
}
var _3be=this.state.reorder.getitemstate();
_3ab=0;
for(var i=0;i<_3be.length;i++){
if("map_marker_reorder_"+_3be[i].id==_3bc.id){
_3ab=_3be[i].position;
break;
}
}
var _3c0=this.state.map_state.markers.splice(_3ab,1);
this.state.reorder.remove(_3c0[0].id);
for(i=_3ab+1;i<_3be.length;i++){
var m=$("map_marker_reorder_"+_3be[i].id);
m.setStyle({top:(parseInt(m.getStyle("top"),10)-this.state.reorder.options.ele_space_per_v)+"px"});
m.down(".marker_letter").innerHTML=mapLetterFromPosition(i-1)+".";
}
this.renderMap(true);
this.updateMapBounds();
if(this.state.map_state.markers.length==0){
$$("#"+this.state.map_edit_id+" .map_marker_present").each(function(elt){
elt.hide();
});
}
if(this.state.map_state.markers.length<2){
$$("#"+this.state.map_edit_id+" .multiple_map_markers").each(function(elt){
elt.hide();
});
}
Event.stop(e);
}.bind(this));
_3ad.down("a.marker_edit").observe("click",function(e){
var _3c5=Event.findElement(e,"a");
this.editMapMarker(_3c5);
Event.stop(e);
}.bind(this));
_3ad.down("a.marker_done").observe("click",function(e){
var _3c7=Event.findElement(e,"a");
var mmr=_3c7.up(".map_marker_reorder");
var _3c9=mmr.down("input[name=name]");
if($F(_3c9).strip()==""){
var _3ca=mmr.previousSiblings().size();
var _3cb=this.state.map_state.markers[_3ca].name;
_3c9.value=_3cb;
mmr.down(".marker_name").innerHTML=_3cb.truncate(60);
}
this.updateMapMarkerProperties();
this.renderMap();
this.doneEditingMarker(_3c7);
this.state.reorder.enable();
jQuery(".map_marker_drag_bar").each(function(){
this.setStyle({cursor:"move"});
});
Event.stop(e);
}.bind(this));
if(open){
this.editMapMarker(_3ad.down("a.marker_edit"));
}
};
ModuleEdit.prototype.editMapMarker=function(_3cc){
var li=_3cc.up("li");
var _3ce=li.up(".map_marker_drag_bar");
var _3cf=_3ce.up(".map_marker_reorder");
var edit=_3ce.next();
_3cf.siblings().each(function(elt){
var done=elt.down(".marker_done");
if(done.visible()){
this.doneEditingMarker(done);
throw $break;
}
}.bind(this));
var _3d3=[];
$$("#"+this.state.map_markers_reorder_id+" .map_marker_reorder").each(function(elt){
_3d3.push([parseInt(elt.getStyle("top")),elt]);
});
_3d3.sort(function(a,b){
return a[0]-b[0];
});
var _3d7=_3ce.getHeight();
var _3d8=edit.getHeight();
var _3d9=false;
var _3da=100;
for(var _3db=0;_3db<_3d3.length;_3db++){
if(_3d9){
var _3dc=(parseInt(_3d3[_3db][1].getStyle("top"),10)+_3d8+10);
_3d3[_3db][1].setStyle({top:_3dc+"px"});
_3da=_3dc+_3d7;
}else{
if(_3d3[_3db][1]==_3cf){
_3d9=true;
}
_3da=parseInt(_3d3[_3db][1].getStyle("top"),10)+_3d7+_3d8;
}
}
$(this.state.map_markers_reorder_id).setStyle({height:_3da+"px"});
_3cc.hide();
li.next().down(".marker_done").show();
edit.show();
this.state.reorder.disable();
jQuery(".map_marker_drag_bar").each(function(){
this.setStyle({cursor:"default"});
});
};
ModuleEdit.prototype.doneEditingMarker=function(_3dd){
_3dd.hide();
var li=_3dd.up("li");
li.previous().down(".marker_edit").show();
_3dd.up(".map_marker_drag_bar").next().hide();
this.state.reorder.relayout();
};
ModuleEdit.prototype.updateMapBounds=function(){
var _3df=this.state.map_state.markers;
if(_3df.length==0){
return;
}
if(_3df.length==1){
this.getMap().setCenter(new google.maps.LatLng(_3df[0].lat,_3df[0].lng));
}else{
var n,s,e,w;
var lat0=_3df[0].lat*1;
var lat1=_3df[1].lat*1;
if(lat0<lat1){
s=lat0;
n=lat1;
}else{
s=lat1;
n=lat0;
}
var lng0=_3df[0].lng*1;
var lng1=_3df[1].lng*1;
if((lng0>lng1&&lng0-lng1<=180)||(lng0<lng1&&180<=lng1-lng0)){
e=lng0;
w=lng1;
}else{
e=lng1;
w=lng0;
}
var sw=new google.maps.LatLng(s,w);
var ne=new google.maps.LatLng(n,e);
var _3ea=new google.maps.LatLngBounds(sw,ne);
for(var i=2;i<_3df.length;i++){
_3ea.extend(new google.maps.LatLng(_3df[i].lat,_3df[i].lng));
}
this.getMap().fitBounds(_3ea);
}
};
ModuleEdit.prototype.mapResized=function(){
google.maps.event.trigger(mm.getMapById(this.data.id).map,"resize");
this.renderMap();
};
ModuleEdit.prototype.changeMapType=function(){
this.state.map_state.mapType=$F(this.state.map_type_select_id);
this.getMap().setMapTypeId(google.maps.MapTypeId[this.state.map_state.mapType]);
};
ModuleEdit.prototype.renderMap=function(_3ec){
if(!this.state.map_state){
this.loadMapState();
}
var data=Object.clone(this.state.map_state);
data.hubtool=true;
renderMapFromData(this.data.id,data,_3ec);
};
ModuleEdit.prototype.removeMapListeners=function(){
for(var i=0;i<this.state.map_listeners.length;i++){
google.maps.event.removeListener(this.state.map_listeners[i]);
}
this.state.map_listeners=[];
};
ModuleEdit.prototype.loadMapState=function(){
this.state.map_state=JSONstring.toObject($(this.state.map_json_id).innerHTML);
};
ModuleEdit.prototype.saveMapState=function(){
this.data.map_json=JSONstring.make(this.state.map_state);
$(this.state.map_json_id).innerHTML=this.data.map_json;
};
ModuleEdit.prototype.onclickRssPreview=function(type){
var _3f0=$H({maxitems:$F(this.state.max_id)}).toQueryString();
if($(this.state.mode_id)){
_3f0+="&mode="+$F(this.state.mode_id);
}
if($(this.state.feed_id)){
_3f0+="&feed="+encodeURIComponent($F(this.state.feed_id));
}else{
if($(this.state.keywords_id)){
_3f0+="&keywords="+$F(this.state.keywords_id);
}
}
if(type){
_3f0+="&type="+type;
}
var ajax=new Ajax.Updater({success:this.state.rss_results_id},"/xml/rssresults.php",{parameters:_3f0,onFailure:reportError,onComplete:function(){
}});
};
ModuleEdit.prototype.onclickCapsuleRenderFromDB=function(_3f2){
var _3f3=$H({art_id:this.data.art_id,id:this.data.id}).toQueryString();
var ajax=new Ajax.Updater({success:_3f2},"/xml/capsule_render.php",{parameters:_3f3,onFailure:reportError,onComplete:function(){
}});
};
ModuleEdit.prototype.onclickVideoPreview=function(size){
if(!size){
size="Big";
}
var _3f6=$H({url:$F(this.resources.video_url_input_id),size:size}).toQueryString();
var ajax=new Ajax.Updater({success:this.resources.video_results_id},"/xml/videoresults.php",{parameters:_3f6,onFailure:reportError,onComplete:function(_3f8,json){
if(json){
var _3fa=(json.key=="Unrecognized URL");
hpFormHandler.lightEle(this.resources.video_key_id,_3fa);
hpFormHandler.lightEle(this.resources.video_type_id,_3fa);
Element.update(this.resources.video_key_id,json.key);
Element.update(this.resources.video_type_id,json.type);
this.state.video_type=json.type;
if(json.showPreview){
insertVideo(json.type,json.key,json.cssClass,"",this.resources.video_results_id);
}
}
}.bind(this)});
};
ModuleEdit.prototype.setHide=function(){
if($(this.state.hide_id)){
this.data.hide=$(this.state.hide_id).checked;
}
this.render();
};
ModuleEdit.prototype.setColor=function(_3fb){
this.data.color=String(_3fb);
var eles=document.getElementsByClassName("selected","colorbar_"+this.data.id);
Element.removeClassName(eles.first(),"selected");
Element.addClassName(eles.first(),"unselected");
var _3fd=$(this.data.id+"_color"+_3fb);
Element.addClassName(_3fd,"selected");
Element.removeClassName(_3fd,"unselected");
this.render();
};
ModuleEdit.prototype.load=function(){
var _3fe=$H(this.data).merge($H({load:true}));
var _3ff=_3fe.toQueryString();
var ajax=new Ajax.Updater({success:this.data.div_id},"/xml/modules.php",{method:"post",parameters:_3ff,evalScripts:true,onFailure:reportError,onComplete:this.render.bind(this)});
};
ModuleEdit.prototype.save=function(){
if(!this.data.dirty){
return;
}
if(this.tiny_mce_editor){
this.needsHtmlCleanUp=false;
this.data.content=this._cleanUpHtml(this.tiny_mce_editor,this.data.content,false);
}
var _401=this.data.moveHoriz;
if(this.data.type=="Quiz"&&!this.data.deleted){
var ajax=new Ajax.Request("/xml/modules.php",{method:"post",parameters:$H(this.data).toQueryString(),onFailure:this.reportSaveError.bind(this),onComplete:function(_403,json){
this.setClean();
if(!_401&&json){
$(this.state.quiz_json_id).innerHTML=JSONstring.make(json);
this._renderQuiz();
}
}.bind(this)});
}else{
var ajax=new Ajax.Request("/xml/modules.php",{method:"post",parameters:$H(this.data).toQueryString(),onFailure:this.reportSaveError.bind(this),onComplete:this.setClean.bind(this)});
}
};
ModuleEdit.prototype.animateHoriz=function(){
if(this.data.horiz_id==2){
var div=$(this.data.div_id);
var _406=Element.getWidth(div)*2;
var _407=new fx.Combo(div,{duration:300,width:true,height:true,opacity:false,onComplete:function(){
this.render();
}.bind(this)});
_407.customSize(Element.getHeight(div),_406);
_407.toggle();
}else{
this.render();
}
};
ModuleEdit.prototype.scrollTo=function(){
var _408=new fx.Scroll({duration:100});
_408.scrollTo(this.data.div_id);
};
ModuleEdit.prototype.remove=function(_409){
if(_409){
this.data.deleted=true;
this.setDirty();
this.save();
var _40a=new fx.Height(this.data.div_id,{duration:500,transition:fx.backIn,onComplete:function(){
Element.remove(this.data.div_id);
ModuleEdit.Manager.render();
}.bind(this)});
_40a.toggle();
}else{
Element.remove(this.data.div_id);
}
};
ModuleEdit.prototype.reportSaveError=function(req,e){
alert("Ooops!\r\nThere was an error saving this capsule.  Please click EDIT and then SAVE to try again.  This error will be reported to the HubPages engineering team.  We thank you for your patience and understanding.");
var _40d=$H({response:req.responseText,status:req.status,headers:req.getAllResponseHeaders()}).toQueryString();
var _40e=new Ajax.Request("/xml/reporterror.php",{method:"post",parameters:_40d+"&hubtoolsave=1"});
};
var ModuleManager=Class.create();
ModuleManager.prototype={initialize:function(_40f,_410,_411){
insideHubEditor=true;
this.div_id=$(_40f).id;
this.art_id=_410;
this.modules_by_order=[];
this.modules_by_id=[];
this.layout={};
this.editting=false;
ModuleEdit.Manager=this;
if(_411){
var _412=JSONstring.toObject(_411);
_412.each(function(_413){
var _414=ModuleEdit.getFromJSON(_413);
this.add(_414,false,true);
}.bind(this));
}
this._renumber();
this.render();
},getLength:function(){
return this.modules_by_order.length;
},add:function(_415,_416,bulk){
_416+="";
if(_416=="false"||_416.toLowerCase()=="bottom"){
_415.data.position=this.getLength();
}else{
if(_416.toLowerCase()=="top"){
_415.data.position=0;
}else{
_415.data.position=Math.min(this.getLength(),parseInt(_416));
}
}
this.modules_by_order.splice(_415.data.position,0,_415);
this.modules_by_id[_415.data.id]=_415;
if(!bulk){
if(ModuleEdit.options.drag_reorder_enabled){
var _418=_415.data.display_type.toLowerCase();
var _419="<b>"+_418+"</b>";
var html="<div class=\"reorder_bar\" id=\"caps_reorder_"+_415.data.id+"\" "+"style=\"width: 100%; height:25px; bottom: 0px; line-height:25px; z-index: 1; "+"background: url(/x/hubtool_"+_418+".gif) 2px 50% no-repeat #e5e5e5; cursor:move;\" "+"onselectstart=\"return false\">"+_419+"</div>";
var pole=new Insertion.Bottom("caps_reorder_canvas",html);
var _41c="caps_reorder_"+_415.data.id;
var _41d=_415.data.type=="Comment"?false:true;
var _41e=new ReorderItem(_41c,_415.data.id,_415.isFloated(),_41d);
_41e.repaint();
this.reorder.add(_41e);
this.reorder.relayout();
}
this._renumber();
}
},addNew:function(type,_420){
if(undefined==_420){
_420=this.getLength();
}
addTime=new Timer();
ModuleEdit.make(type,this.art_id,_420,this._handleAddNewResponse.bind(this,_420));
},getByPosition:function(_421){
return this.modules_by_order[_421];
},getById:function(id){
return this.modules_by_id[id];
},getPosition:function(_423){
return this.modules_by_order.indexOf(_423);
},getPositionById:function(id){
var _425=this.modules_by_id[id];
return this.getPosition(_425);
},removeById:function(id,_427){
var _428=this.modules_by_id[id];
if(_428.editting){
return;
}
var _429=($(_428.state.empty_notification_id).style.display!="none"||(_428.data.type=="Comment"&&isNewHub))?true:false;
if(!_429&&!confirm(_428.state.delete_confirm_text)){
return;
}
delete this.modules_by_id[id];
this.modules_by_order=this.modules_by_order.reject(function(o){
return (o.data.id==_428.data.id);
});
_428.remove(_427);
this._renumber();
if(ModuleEdit.options.drag_reorder_enabled){
this.reorder.remove(_428.data.id);
this.reorder.relayout();
}
},removeByPosition:function(_42b){
var _42c=this.getByPosition(_42b);
if(_42c.editting){
return;
}
_42c=this.modules_by_order.splice(_42b,1);
delete this.modules_by_id[_42c.data.id];
_42c.remove(false);
this._renumber();
},renderExhaustive:function(){
this._renderFloatDivs();
this.modules_by_order.each(function(_42d){
Position.set($(_42d.data.div_id),[0,0]);
_42d.renderExhaustive();
});
this._sweepDeadWrappers();
},render:function(){
this._renderFloatDivs();
this.modules_by_order.each(function(_42e){
_42e.render();
});
this._sweepDeadWrappers();
},toggle:function(id){
this.editting=!this.editting;
var mod=this.getById(id);
if(this.editting){
if($("floating_menu")){
$("floating_menu").hide();
}
this.computeState();
this.computeListener=this.computeState.bindAsEventListener(this);
Event.observe(window,"resize",this.computeListener,false);
}else{
_floatMenu();
Event.stopObserving(window,"resize",this.computeListener,false);
this.computeListener=null;
}
var _431=mod.toggle();
if(_431){
this.displayCurtain(mod.state.modal_id);
}
},moveLeft:function(id){
this.moveHoriz(id,1);
},moveCenter:function(id){
this.moveHoriz(id,2);
},moveRight:function(id){
this.moveHoriz(id,3);
},moveHoriz:function(id,_436){
var _437=this.getById(id);
if(_437.editting){
return;
}
_437.setColorbar(_436);
_437.setHoriz(_436);
_437.setDirty();
_437.data.moveHoriz=true;
_437.save();
_437.data.moveHoriz=false;
this.renderExhaustive();
this.callEvent("onmove",this.modules_by_order);
},moveUp:function(id){
this.moveVert(id,0);
},moveDown:function(id){
this.moveVert(id,1);
},moveVert:function(id,_43b){
this._sweepDeadWrappers();
var _43c=this.getById(id);
var _43d=this.getPosition(_43c);
var _43e=this.getLength();
var _43f=(_43b*2)-1;
if(_43d===0&&_43b===0){
return;
}
if(_43d==_43e-1&&_43b==1){
return;
}
if(_43c.editting){
return;
}
var _440=(_43b==1)?_43d:_43d-1;
var _441=(_43b==1)?_43d+1:_43d;
var _442=this.getByPosition(_43f+_43d);
var _443=this.getByPosition(_440);
this.modules_by_order.splice(_440,1);
this.modules_by_order.splice(_441,0,_443);
this._saveSwap(_43c,_442);
this._renumber();
if(_43c.data.type=="Image"){
_43c.adjustImageWidth();
}
if(_442.data.type=="Image"){
_442.adjustImageWidth();
}
this._animateSwap(_43c,_442,_43f);
this.callEvent("onmove",this.modules_by_order);
},_sweepDeadWrappers:function(){
setTimeout(this._sweepDeadWrappersHandler.bind(this),500);
},_sweepDeadWrappersHandler:function(){
var eles=document.getElementsByClassName("modfloat","modules");
if(eles.length!=1){
eles.each(function(ele){
if(!ele.hasChildNodes()){
Element.remove(ele);
}
});
}
var eles=document.getElementsByClassName("floatclear","modules");
eles.each(function(ele){
if(!ele.nextSibling||ele.nextSibling.nodeName!="DIV"){
Element.remove(ele);
}
});
},load:function(){
this.modules_by_order.each(function(_447){
_447.load();
});
},save:function(){
this.modules_by_order.each(function(_448){
_448.save();
});
},cleanUp:function(){
this.modules_by_order.each(function(m){
m.cleanUp();
});
this.div_id=null;
this.art_id=null;
this.modules_by_id=null;
this.modules_by_order=null;
},computeState:function(){
this.layout.documentSize=[Position.getDocumentWidth(),Position.getDocumentHeight()];
this.layout.viewportSize=[Position.getViewportWidth(),Position.getViewportHeight()];
this.layout.viewportScroll=[Position.getViewportScrollX(),Position.getViewportScrollY()];
},displayCurtain:function(_44a){
ModuleEdit.toggleCurtain();
},toggleAutoSummary:function(){
var _44b=$("autoSummary").checked;
$("articleSummary").readOnly=_44b?"none":"";
$("articleSummary").style.color=_44b?"#aaa":"#000";
},_saveSwap:function(_44c,_44d){
var _44e=$H({swap:1,art_id:_44c.data.art_id,id:_44c.data.id,id2:_44d.data.id}).toQueryString();
var ajax=new Ajax.Request("/xml/modulesswap.php",{parameters:_44e,onFailure:reportError,onComplete:function(){
}});
},_animateSwap:function(_450,_451,_452){
var _453=$(_450.data.div_id);
var _454=$(_451.data.div_id);
Element.makePositioned(_453);
Element.makePositioned(_454);
var _455=Position.cumulativeOffset(_453);
var _456=Position.cumulativeOffset(_454);
var _457=[(_456[0]-_455[0])/3,(_452)*Element.getHeight(_454)];
var _458=[(_455[0]-_456[0])/3,-1*(_452)*Element.getHeight(_453)];
var _459=400;
var _45a=new fx.Position(_453,{duration:_459,transition:fx.backIn,onComplete:function(){
Element.undoPositioned(_453);
Element.undoPositioned(_454);
this.render();
}.bind(this)});
var _45b=new fx.Position(_454,{duration:_459,transition:fx.backIn,onComplete:function(){
}.bind(this)});
_453.style.zIndex="2";
_45a.move([0,0],[_457[0],_457[1]]);
_45b.move([0,0],[_458[0],_458[1]]);
},_renumber:function(){
var _45c=this.getLength();
this.modules_by_order.each(function(o,idx){
o.data.position=idx;
o.state.is_last=(idx==_45c-1);
});
},_renderFloatDivs:function(){
var _45f="first";
var _460;
var _461=$("modules");
var _462=_461.firstChild;
this.modules_by_order.each(function(_463,idx){
var _465=$(_463.data.div_id);
var _466=_463.getHoriz();
if(_463.isLast()){
_466=2;
}
if(_466!=_45f){
var _467=["modfloat"];
switch(_466){
case 1:
_467.push("left");
break;
case 3:
_467.push("right");
break;
case 2:
_467.push("full");
break;
}
if(_45f!="first"&&_460){
if(_45f==3){
breakDiv=document.createElement("br");
breakDiv.className="floatclear";
_461.insertBefore(breakDiv,_462);
}
_461.insertBefore(_460,_462);
}
_460=document.createElement("div");
_460.className=_467.join(" ");
}
_45f=_466;
if((_463.data.type=="Comment"||_463.data.type=="Poll"||_463.data.type=="Quiz"||_463.data.type=="Image"||_463.data.type=="Video"||_463.data.type=="Code"||_463.data.type=="Table"||_463.data.type=="Map")&&_466==2){
breakDiv=document.createElement("br");
breakDiv.className="floatclear";
_460.appendChild(breakDiv);
}
_460.appendChild(_465);
if(_463.isLast()){
_461.insertBefore(_460,_462);
}
});
},_handleAddNewResponse:function(_468,req,json){
var _46b=req.responseText.match(/ id="(.*?)" /);
var _46c=(_46b&&_46b.length>1)?_46b[1]:false;
if(_46c&&json){
var pole=new Insertion.Bottom("modules",req.responseText);
var _46e=ModuleEdit.getFromJSON(json);
this.add(_46e,_468);
if(_468==this.getLength()-1&&!Position.withinViewport(_46c)&&!$("ind")){
this._drawPointerInd("<b><img src=\"http://x.hubpages.com/i/dn-w.gif\" style=\"width: 11px; height: 10px;\" /> Added capsule below</b>");
}
_46e.load();
}
this.render();
},_drawPointerInd:function(_46f){
var _470="<div id=\"ind\"><div>"+_46f+"</div></div>";
var pole=new Insertion.Bottom("modules",_470);
if(!window.ActiveXObject){
$("ind").style.position="fixed";
}
setTimeout("if ($('ind')) Element.remove('ind');",3500);
},callEvent:function(e){
return this[e] instanceof Function?this[e].apply(this,[].slice.call(arguments,1)):undefined;
}};
function prompt_navigate_away(_473){
if(promptEnabled){
return "\n\nAre you sure you want to leave the Hubtool now?\nYou may lose some or all of your work.\n\n";
}
};
var ModuleReorder=Class.create();
ModuleReorder.prototype={initialize:function(_474){
ReorderItem.reorder=this;
this.art_id=_474;
this.canvas=$("caps_reorder_canvas");
this.items=[];
this.options={border_repaint_delay:800,filter_additional_overhang:40,empty_space_at_top:10,ele_height:25,ele_float_bump:10,ele_float_width:130,ele_full_width:240};
this.options.ele_space_per=this.options.empty_space_at_top+this.options.ele_height;
},add:function(item){
this.items.push(item);
},remove:function(_476){
var _477=this.items.findAll(function(o){
return (o.mod_id==_476);
});
if(_477&&_477.length>0){
_477=_477[0];
this.items=this.items.reject(function(o){
return (o.mod_id==_476);
});
Element.remove(_477.ele);
}
},findById:function(_47a){
return this.items.detect(function(item){
return (item.mod_id==_47a);
});
},save:function(){
this._getorder();
var _47c=this.items.collect(function(item){
return {id:item.mod_id,floated:item.floated};
});
var _47e=JSONstring.make(_47c);
var _47f=new Ajax.Request("/xml/modulesreorder.php",{parameters:"art_id="+this.art_id+"&json="+_47e,onFailure:reportError,onComplete:this.onsavedone.bind(this)});
},onsavedone:function(){
window.onbeforeunload=Prototype.emptyFunction;
location.reload();
},ondragdone:function(){
this._getorder();
this.relayout();
},resetorder:function(_480){
var _481=[];
_481=_480.collect(function(mod,i){
var _484=this.findById(mod.data.id);
_484.floated=mod.isFloated();
return _484;
}.bind(this));
this.items=_481;
this.relayout(true);
},_getorder:function(){
this.items=this.items.sortBy(function(node,i){
return parseInt(node.ele.style.top,10);
});
},relayout:function(_487){
var i=1;
this.items.each(function(cap){
var ele=$(cap.ele);
var _48b=(cap.floated)?this.options.ele_float_bump:0;
var top=(i*this.options.ele_space_per)+_48b;
ele.style.bottom="";
ele.style.top=top+"px";
i++;
}.bind(this));
if(_487){
this.items.each(function(cap){
cap.repaint();
});
}
var _48e=(this.items.length+2)*(this.options.ele_height+10);
$("caps_reorder_canvas").style.height=_48e+"px";
}};
var ReorderItem=Class.create();
ReorderItem.reorder=null;
ReorderItem.prototype={initialize:function(ele,_490,_491,_492){
ele=$(ele);
this.mod_id=_490;
this.ele=ele;
this.opts=ReorderItem.reorder.options;
this.floated=_491;
this.floatable=_492;
this.dragged=false;
var d=new Dragger(ele,true);
var loc=[0,0];
var dim=Element.getDimensions(ReorderItem.reorder.canvas);
var _496=this.opts.filter_additional_overhang;
d.addFilter(Dragger.filters.SQUARE,loc[0]-_496,loc[1],dim.width-_496,dim.height-this.opts.ele_height);
d.onstop=this.ondragdone.bind(this);
d.ondrag=this.ondrag.bind(this);
this.ondblclickListener=this.ondblclick.bindAsEventListener(this);
this.ele.ondblclick=this.ondblclickListener;
},ondblclick:function(e){
if(!this.floatable){
return;
}
e=e||window.event;
var ele=Event.element(e);
this.floated=!this.floated;
this.repaint();
ReorderItem.reorder.ondragdone();
},ondrag:function(e){
this.dragged=true;
this.ele.style.zIndex="100";
this.ele.style.border="solid 2px #c00";
},ondragdone:function(){
if(this.dragged){
this.repaint();
this.dragged=false;
ReorderItem.reorder.ondragdone();
}
},width:function(){
return this.floated?this.opts.ele_float_width:this.opts.ele_full_width;
},height:function(){
return this.opts.ele_height;
},zindex:function(){
return this.floated?"2":"1";
},repaint:function(){
if(browser!="IE"){
Field.focus(this.ele);
}
this.ele.style.left="";
this.ele.style.right="5px";
this.ele.style.zIndex=this.zindex();
this.ele.style.width=this.width()+"px";
setTimeout("$('"+this.ele.id+"').style.border = 'solid 1px #aaa'",this.opts.border_repaint_delay);
}};
ReorderItem.make=function(mod){
var _49b="<b>"+mod.data.display_type+"</b>";
var html="<div class=\"dragbar\" id=\"caps_reorder_"+mod.data.id+"\" "+"style=\"width:100%; height:25px; bottom:0px; "+"border:solid 1px #999; font-size:9px; padding:1px; "+"overflow:hidden; right:5px; z-index:1;"+"cursor:pointer\" onselectstart=\"return false\">"+_49b+"</div>";
var pole=new Insertion.Bottom("caps_reorder_canvas",html);
var _49e="caps_reorder_"+mod.data.id;
var _49f=mod.data.type=="Comment"?false:true;
var ri=new ReorderItem(_49e,mod.data.id,mod.isFloated(),_49f);
ri.repaint();
return ri;
};
var ModuleContentReorder=Class.create();
ModuleContentReorder.prototype={disabled:false,initialize:function(_4a1,_4a2,_4a3,_4a4){
this.canvas=$(_4a1);
this.items=[];
this.options={num_cols:_4a2,filter_additional_overhang:40,ele_buffer_v:10,ele_buffer_h:10,ele_height:_4a4,ele_width:_4a3,offset_v:5,offset_h:0};
this.options.ele_space_per_v=this.options.ele_buffer_v+this.options.ele_height;
this.options.ele_space_per_h=this.options.ele_buffer_h+this.options.ele_width;
},add:function(item,top){
if(top){
this.items.unshift(item);
}else{
this.items.push(item);
}
},enable:function(){
if(!this.disabled){
return true;
}
this.items.each(function(item){
item.ele.ondblclick=item.ondblclickListener;
item.ele.setStyle({cursor:"move"});
item.d.enable(item.ele);
}.bind(this));
this.disabled=false;
},disable:function(){
this.items.each(function(item){
item.d.disable(item.ele);
item.ele.ondblclick=function(){
return false;
};
item.ele.setStyle({cursor:"default"});
}.bind(this));
this.disabled=true;
},remove:function(_4a9){
this.items=this.items.reject(function(item){
if(item.item_id==_4a9){
Element.remove(item.ele);
return true;
}else{
return false;
}
});
},removeAll:function(){
this.items.each(function(item){
Element.remove(item.ele);
});
this.items=[];
},setonchangecallback:function(_4ac){
this.onchangecallback=_4ac;
},ondragdone:function(){
this._getorder(true);
this.relayout();
},_getorder:function(_4ad){
var _4ae=this.items.sortBy(function(item,i){
if(this.options.num_cols==1){
return parseInt(item.ele.style.top,10);
}
var vIdx=parseInt(item.ele.style.top,10);
var hIdx=parseInt(item.ele.style.left,10);
var _4b3=Math.round((vIdx-this.options.offset_v)/this.options.ele_space_per_v);
var _4b4=Math.round((hIdx-this.options.offset_h)/this.options.ele_space_per_h);
if(item.dropped){
if(_4b4<0){
_4b4=0;
}
if(_4b4>=this.options.num_cols){
_4b4=this.options.num_cols-1;
}
var _4b5=Math.round((item.startY-this.options.offset_v)/this.options.ele_space_per_v);
var _4b6=Math.round((item.startX-this.options.offset_h)/this.options.ele_space_per_h);
if((_4b5<_4b3)||(_4b5==_4b3&&_4b6<_4b4)){
_4b4+=0.5;
}else{
_4b4-=0.5;
}
}
return (_4b3*this.options.num_cols)+_4b4;
}.bind(this));
if(_4ad&&this.onchangecallback){
var _4b7=false;
if(_4ae.length!=this.items.length){
_4b7=true;
}else{
for(var i=0;i<_4ae.length;i++){
if(_4ae[i]!=this.items[i]){
_4b7=true;
break;
}
}
}
if(_4b7){
this.onchangecallback();
}
}
this.items=_4ae;
},relayout:function(_4b9){
var i=0;
this.items.each(function(item){
var ele=$(item.ele);
var _4bd=Math.floor(i/this.options.num_cols);
var _4be=i%this.options.num_cols;
item.startY=(_4bd*this.options.ele_space_per_v)+this.options.offset_v;
item.startX=(_4be*this.options.ele_space_per_h)+this.options.offset_h;
ele.style.bottom="";
ele.style.top=item.startY+"px";
ele.style.left=item.startX+"px";
i++;
}.bind(this));
if(_4b9){
this.items.each(function(item){
item.repaint();
});
}
var rows=Math.ceil(this.items.length/this.options.num_cols);
var _4c1=(rows*(this.options.ele_space_per_v))+10;
if(_4c1!=parseInt(this.canvas.style.height,10)){
this.canvas.style.height=_4c1+"px";
}
},getitemstate:function(){
this._getorder();
items_state=Array();
var pos=0;
this.items.each(function(item){
items_state.push({id:item.item_id,position:pos++});
});
return items_state;
},getitemstateRec:function(){
this._getorder();
items_state=Object();
var pos=0;
this.items.each(function(item){
items_state[item.item_id]={id:item.item_id,position:pos++};
});
return items_state;
}};
var ModuleContentReorderItem=Class.create();
ModuleContentReorderItem.prototype={initialize:function(_4c6,_4c7,_4c8){
var ele=$(_4c6);
this.item_id=_4c7;
this.ele=ele;
this.reorder=_4c8;
this.opts=this.reorder.options;
this.dragged=false;
this.dropped=false;
this.startX=0;
this.startY=0;
this.d=new Dragger(ele,true);
this.d.onstart=this.onstart.bind(this);
this.d.onstop=this.ondragdone.bind(this);
this.ondblclickListener=this.ondblclick.bindAsEventListener(this);
this.ele.ondblclick=this.ondblclickListener;
this.d.setonbeforestart(function(){
return !this.reorder.disabled;
}.bind(this));
},ondblclick:function(e){
},setBeforeStartCallback:function(_4cb){
this.d.setonbeforestart(_4cb);
},onstart:function(e){
this.ele.onclick();
this.dragged=true;
this.ele.style.zIndex="100";
},ondrag:function(e){
},ondragdone:function(){
if(this.dragged){
this.repaint();
this.dragged=false;
this.dropped=true;
this.reorder.ondragdone();
this.dropped=false;
}
},repaint:function(){
if(browser!="IE"){
Field.focus(this.ele);
}
this.ele.style.zIndex=1;
}};
var GroupReorder=Class.create();
GroupReorder.prototype={initialize:function(_4ce){
GroupReorderItem.reorder=this;
this.firstGroupId=_4ce;
this.canvas=$("grp_reorder_canvas");
this.items=[];
this.options={filter_additional_overhang:40,empty_space_at_top:5,ele_height:20};
this.options.ele_space_per=this.options.empty_space_at_top+this.options.ele_height;
},add:function(item){
this.items.push(item);
},remove:function(_4d0){
this.items=this.items.reject(function(item){
if(item.hp_id==_4d0){
Element.remove(item.ele);
return true;
}else{
return false;
}
});
},removegroup:function(_4d2){
targetItem=this.findById(_4d2);
if(targetItem.collapsed){
targetItem.hiddenChildren.each(function(_4d3){
_4d3.ele.style.display="";
this.items.push(_4d3);
}.bind(this));
}else{
flag=false;
offset=this.items.length+1;
this.items=this.items.sortBy(function(item,i){
if(!item.is_article){
flag=(_4d2==item.hp_id);
}
return flag?(i+offset):i;
});
}
if(_4d2==this.firstGroupId){
this.firstGroupId=this.items.first().hp_id;
}
this.remove(_4d2);
this.relayout();
},findById:function(_4d6){
return this.items.detect(function(item){
return (item.hp_id==_4d6);
});
},ondragdone:function(){
this._getorder();
this.relayout();
},toggleGroupById:function(_4d8){
targetItem=this.findById(_4d8);
this.toggleGroup(targetItem);
},toggleGroup:function(_4d9){
if(_4d9.collapsed){
this.expandGroup(_4d9);
}else{
this.hideGroup(_4d9);
}
},hideGroup:function(_4da){
var _4db=-1;
var res=this.items.partition(function(item){
if(!item.is_article){
_4db=item.hp_id;
}else{
if(_4db==_4da.hp_id){
item.ele.style.display="none";
return false;
}
}
return true;
});
this.items=res[0];
_4da.hiddenChildren=res[1];
_4da.ele.getElementsByTagName("span")[0].className="drop_right";
_4da.collapsed=true;
this.relayout();
},expandGroup:function(_4de){
this.items=this.items.inject(Array(),function(_4df,item,i){
_4df.push(item);
if(item==_4de){
_4de.hiddenChildren.each(function(_4e2){
_4e2.ele.style.display="";
_4df.push(_4e2);
});
}
return _4df;
});
_4de.hiddenChildren=null;
_4de.ele.getElementsByTagName("span")[0].className="drop_down";
_4de.collapsed=false;
this.relayout();
},hideAll:function(){
this.items.each(function(item){
if(!item.is_article&&!item.collapsed){
this.hideGroup(item);
}
}.bind(this));
},expandAll:function(){
this.items.each(function(item){
if(!item.is_article&&item.collapsed){
this.expandGroup(item);
}
}.bind(this));
},_getorder:function(){
this.items=this.items.sortBy(function(node,i){
return parseInt(node.ele.style.top,10);
});
},relayout:function(_4e7){
if(this.items.first().hp_id!=this.firstGroupId){
if(this.firstGroupId==0&&!this.items.first().is_article){
this.firstGroupId=this.items.first().hp_id;
}else{
groupItem=this.findById(this.firstGroupId);
this.items=this.items.reject(function(item){
return (item.hp_id==this.firstGroupId);
}.bind(this));
this.items.unshift(groupItem);
}
}
var i=1;
this.items.each(function(item){
ele=$(item.ele);
ele.style.bottom="";
ele.style.top=((i-0.5)*this.options.ele_space_per)+"px";
i++;
}.bind(this));
if(_4e7){
this.items.each(function(item){
item.repaint();
});
}
canvas_height=((this.items.length+0.5)*this.options.ele_space_per)+20;
this.canvas.style.height=canvas_height+"px";
},getitemstate:function(){
this._getorder();
items_state=Array();
pos=0;
this.items.each(function(item){
if(!item.is_article){
groupId=item.hp_id;
pos=0;
if(item.hiddenChildren){
item.hiddenChildren.each(function(_4ed){
items_state.push({id:_4ed.hp_id,group:groupId,pos:pos++});
});
}
}else{
if(groupId==0){
items_state.push({id:item.hp_id,group:0,pos:0});
}else{
items_state.push({id:item.hp_id,group:groupId,pos:pos++});
}
}
});
return items_state;
}};
var GroupReorderItem=Class.create();
GroupReorderItem.prototype={initialize:function(name,ele,_4f0,_4f1,_4f2){
ele=$(ele);
this.name=name;
this.hp_id=_4f0;
this.ele=ele;
this.is_article=_4f1;
this.showname=_4f2;
this.opts=GroupReorderItem.reorder.options;
this.dragged=false;
this.draggerObj=new Dragger(ele,true);
this.collapsed=false;
this.hiddenChildren=null;
loc=Position.realOffset(GroupReorderItem.reorder.canvas);
dim=Element.getDimensions(GroupReorderItem.reorder.canvas);
add_overhang=this.opts.filter_additional_overhang;
this.draggerObj.addFilter(Dragger.filters.SQUARE,loc[0]-add_overhang,loc[1],dim.width-add_overhang,dim.height-this.opts.ele_height);
this.draggerObj.onstop=this.ondragdone.bind(this);
this.draggerObj.ondrag=this.ondrag.bind(this);
this.ondblclickListener=this.ondblclick.bindAsEventListener(this);
this.ele.ondblclick=this.ondblclickListener;
},ondblclick:function(e){
GroupReorderItem.reorder.toggleGroup(this);
},ondrag:function(e){
if(!this.is_article){
this.draggerObj.stop();
this.repaint();
GroupReorderItem.reorder.relayout();
}else{
this.dragged=true;
this.ele.style.zIndex="100";
}
},ondragdone:function(){
if(this.dragged){
var _4f5=GroupReorderItem.reorder.items.first();
var top=parseInt(this.ele.style.top,10);
GroupReorderItem.reorder.items.detect(function(item){
if(parseInt(item.ele.style.top,10)>top){
return true;
}
_4f5=item;
});
if(_4f5.collapsed){
this.ele.style.display="none";
_4f5.hiddenChildren.push(this);
GroupReorderItem.reorder.items=GroupReorderItem.reorder.items.without(this);
}
this.repaint();
this.dragged=false;
GroupReorderItem.reorder.ondragdone();
}
},repaint:function(){
if(browser!="IE"){
Field.focus(this.ele);
}
this.ele.style.left="5px";
this.ele.style.right="";
this.ele.style.zIndex=1;
}};
var WidgetCanvas=Class.create();
WidgetCanvas.prototype={AJAX_TIMEOUT:10000,INACTIVITY_TIMEOUT:1800000,initialize:function(_4f8,_4f9,_4fa,_4fb,_4fc,_4fd){
this.userId=_4f8;
this.canvasId=_4f9;
this.element=$(_4f9);
this.column={};
this.numColumns=_4fa;
this.widget={};
this.horizSpace=_4fc;
this.height=$(_4f9).offsetHeight;
this.draggedId=null;
if(typeof _4fd=="undefined"){
_4fd="dottedBox";
}
this.DOTTEDBOX_ID=_4fd;
this.timestamp={};
this.lastActivity=(new Date()).getTime();
Event.observe(document,"mouseover",function(){
this.lastActivity=(new Date()).getTime();
}.bind(this));
this.dottedBox=$(this.DOTTEDBOX_ID);
if(!this.dottedBox){
this.element.innerHTML+="<div id='"+_4fd+"' style='display:none;'></div>";
}
this.width=this.element.offsetWidth;
this.startY=getElementTop(this.element)-100;
for(var c=0;c<_4fa;c++){
var _4ff=_4fb+"_"+c;
this.column[_4ff]=new WidgetColumn(_4ff,this);
}
this.widget[this.DOTTEDBOX_ID]=new Widget($(this.DOTTEDBOX_ID));
this.redraw();
},recentActivity:function(){
var time=(new Date()).getTime();
return ((time-this.lastActivity)<this.INACTIVITY_TIMEOUT);
},addWidget:function(_501,_502,_503){
this.widget[_501.getId()]=_501;
_502.add(_501,_503);
},fadeInEffect:function(_504){
var _505=$(_504);
_505.setStyle({backgroundColor:"#feffd6"});
setTimeout(function(){
var _506=new fx.Color(_505,{duration:700,fromColor:"#feffd7",toColor:"#ffffff"});
_506.toggle();
},200);
},disableDragAndDrop:function(id){
if(!Element.hasClassName($("title_"+id),"disableDragAndDrop")){
Element.addClassName($("title_"+id),"disableDragAndDrop");
}
},enableDragAndDrop:function(id){
if(Element.hasClassName($("title_"+id),"disableDragAndDrop")){
Element.removeClassName($("title_"+id),"disableDragAndDrop");
}
},addNewWidget:function(_509,_50a,_50b){
if(typeof _50a=="undefined"){
for(var prop in this.column){
_50a=prop;
break;
}
}
if(typeof _50b=="undefined"){
_50b=0;
}
var _50d=$H({action:"add",widgetTypeId:_509,userId:this.getUserId(),columnId:_50a,canvasId:this.canvasId,position:_50b}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_50d,onSuccess:function(_50f){
if(_50f.responseText){
var resp=JSONstring.toObject(_50f.responseText);
this.column[_50a].addWidgetHTML(resp.id,resp.widgetHTML,_50b,resp.refreshRate);
var _511=$(resp.id);
_511.setStyle({backgroundColor:"#feffd6"});
setTimeout(function(){
var _512=new fx.Color(_511,{duration:700,fromColor:"#feffd7",toColor:"#ffffff"});
_512.toggle();
},200);
}
}.bind(this)});
},changeLearnTopic:function(id,_514,_515){
if(typeof _515=="undefined"){
_515=false;
}
$("learn_section_"+id).value=_514;
this.saveWidgetConfig(id);
},handleCategorySelect:function(id,_517,i,_519){
if(typeof _519=="undefined"){
_519=10;
}
if(_517.value.substr(0,2)=="0_"){
$("hidden_category_"+id).value=_517.value.substr(2);
}else{
$("hidden_category_"+id).value=_517.value;
}
var _51a=Form.serialize($("form_"+id));
var tmp=_51a.split("&");
for(var j=tmp.length-1;j>=0;j--){
if(tmp[j].substr(0,_519)=="categoryid"){
var _51d=parseInt(tmp[j].substr(_519,1));
if(_51d>i){
tmp.splice(j,1);
}
}
}
_51a=tmp.join("&");
this.refreshWidgetConfig(id,_51a,true);
},handleHoverOn:function(div){
if(!Element.hasClassName($(div),"widgethover")){
Element.addClassName($(div),"widgethover");
}
},handleHoverOff:function(div){
if(Element.hasClassName($(div),"widgethover")){
Element.removeClassName($(div),"widgethover");
}
},handleAuthorSearch:function(id){
var text=$("author_search_"+id).value;
if(text.trim()!=""){
var _522=$H({action:"authorSearch",widgetId:id,userId:this.getUserId(),searchString:text}).toQueryString();
var ajax=new Ajax.Updater({success:"search_results_"+id},"/xml/widgets.php",{method:"post",parameters:_522,onComplete:function(){
$("edit_"+id).style.height="auto";
this.widget[id].getColumn().redraw();
}.bind(this)});
}
},handleAuthorAdd:function(_524,id){
var _526=new RegExp("^"+_524+"$|^"+_524+"_|_"+_524+"$|_"+_524+"(_)");
var list=$("hidden_authors_"+id).value.replace(_526,"$1");
list=(list.length==0)?_524:list+"_"+_524;
$("hidden_authors_"+id).value=list;
var _528=Form.serialize($("form_"+id));
this.saveWidgetConfig(id,true);
this.refreshWidgetConfig(id,_528,true);
},handleAuthorRemove:function(_529,id,_52b){
var _52c=new RegExp("^"+_529+"$|^"+_529+"_|_"+_529+"$|_"+_529+"(_)");
var list=$("hidden_authors_"+id).value.replace(_52c,"$1");
$("hidden_authors_"+id).value=list;
$("edit_"+id).style.height="auto";
var _52e=Form.serialize($("form_"+id));
this.saveWidgetConfig(id,true);
this.refreshWidgetConfig(id,_52e,true);
},checkHeight:function(_52f){
if(_52f>this.height){
this.element.style.height=_52f+"px";
this.height=_52f;
}
},widgetIsGone:function(id){
return (this.widget[id]==null);
},saveWidgetConfig:function(id,_532){
if(typeof _532=="undefined"){
_532=false;
}
var _533=id.split("_")[0];
if(_533=="Hubtivity"){
var _534=0;
var _535=$(id).getElementsByClassName("ht_box");
for(var j=0;j<_535.length;j++){
if(_535[j].checked){
_534+=Number(_535[j].value);
}
}
$("prefs_"+id).value=_534;
}
var _537=this.widget[id];
var _538=$H({action:"update",userId:this.getUserId(),formData:Form.serialize($("form_"+id)),widgetId:_537.getId(),refresh:!_532}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_538,onSuccess:function(_53a){
if(!_532){
if(!_53a.responseText){
document.location.reload();
}else{
var resp=JSONstring.toObject(_53a.responseText);
if(resp.id&&resp.widgetHTML){
_537.column.updateWidgetHTML(resp.id,resp.widgetHTML);
_537.makeDraggable();
scrollElementInView(_537.element);
var _53c="control_"+id;
this.fadeInEffect(_53c);
}else{
document.location.reload();
}
}
}
}.bind(this)});
},closeWidgetConfig:function(id){
var _53e="edit_"+id;
var _53f="control_"+id;
var _540=$(_53e).getHeight();
var _541="title_"+id;
var _542="footer_"+id;
var _543=$(_53f).getHeight();
$(_53e).hide();
$(_53f).show();
this.widget[id].getColumn().redraw();
var _544=getElementScreenTop();
var top=getElementTop(this.widget[id].element);
if(top<_544){
setElementScreenTop(top);
}
this.fadeInEffect(_53f);
},removeWidget:function(id){
var _547=this.widget[id];
var _548=$H({action:"remove",userId:this.getUserId(),canvasId:this.canvasId,widgetId:id}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_548,onFailure:function(){
document.location.reload();
},onSuccess:function(){
$(_547.getId()).hide();
$("edit_"+_547.getId()).hide();
_547.getColumn().remove(_547);
this.widget[id]=null;
}.bind(this)});
},loadPagesNext:function(id,_54b,_54c,size){
var _54e=_54b[0];
if((parseInt(_54b[1])-parseInt(_54b[0])+1)>_54c){
for(var i=_54b[0];i<parseInt(_54b[0])+size;i++){
var elm=$("content_page_"+id+"_"+i);
if(elm!=null){
var _551=elm.parentNode;
_551.removeChild(elm);
}
}
_54e=parseInt(_54b[0])+size;
}
for(i=parseInt(_54b[1])-size+1;i<=_54b[1];i++){
elm=$("content_page_"+id+"_"+i);
if(elm!=null){
_551=elm.parentNode;
_551.removeChild(elm);
}
}
if(_54e!=_54b[0]){
_54b[0]=_54e;
$("content_range_"+id).value=_54b.join("_");
}
var _552=$H({action:"loadWidgetPages",userId:this.getUserId(),pageNum:parseInt(_54b[1])-size+1,widgetId:id}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_552,onSuccess:function(_554){
if(!_554.responseText){
document.location.reload();
}else{
var _555=$("content_range_"+id).value.split("_");
if(_555[0]==_54b[0]&&_555[1]==_54b[1]&&$("content_page_"+id+"_"+_54b[1])==null){
Element.update($("content_"+id),$("content_"+id).innerHTML+_554.responseText);
}
}
}});
},loadPagesPrevious:function(id,_557,_558,size,_55a){
var _55b=_557[1];
if((parseInt(_557[1])-parseInt(_557[0])+1)>_558){
for(var i=_557[1];i>(parseInt(_557[1])-size);i--){
var elm=$("content_page_"+id+"_"+i);
if(elm!=null){
var _55e=elm.parentNode;
_55e.removeChild(elm);
}
}
_55b=parseInt(_557[1])-size;
}
for(i=_557[0];i<_557[0]+size;i++){
elm=$("content_page_"+id+"_"+i);
if(elm!=null){
_55e=elm.parentNode;
_55e.removeChild(elm);
}
}
var _55f=parseInt(_557[0]);
if(_55b!=_557[1]){
_557[1]=_55b;
$("content_range_"+id).value=_557.join("_");
}
var _560=$H({action:"loadWidgetPages",userId:this.getUserId(),pageNum:_55f,widgetId:id}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_560,onSuccess:function(_562){
if(!_562.responseText){
document.location.reload();
}else{
var _563=$("content_range_"+id).value.split("_");
if(_563[0]==_557[0]&&_563[1]==_557[1]&&$("content_page_"+id+"_"+_557[0])==null){
Element.update($("content_"+id),$("content_"+id).innerHTML+_562.responseText);
}
}
},onComplete:function(){
if(typeof _55a!="undefined"){
var _564=$("content_current_"+id).value;
var _565="content_page_"+id;
$(_565+"_"+_564).hide();
$(_565+"_"+_55a).show();
$("pagination_"+id).update($("pagination_saved_"+id+"_"+_55a).innerHTML);
this.widget[id].column.redraw();
scrollElementInView(element);
}
}.bind(this)});
},handlePage:function(_566,id,_568,_569,_56a,_56b){
_566=_566||window.event;
Event.stop(_566);
var _56c=$("content_range_"+id).value.split("_");
var _56d="content_page_"+id;
this.widget[id].pageNum=_568;
var _56e=_568+1;
if($(_56d+"_"+_568)&&Element.hasClassName($(_56d+"_"+_568),"widget_saved_view")){
this.timestamp[id]=(new Date()).getTime();
if(typeof _569=="undefined"){
_569=0;
}
if(typeof _56a=="undefined"){
_56a=1;
}
if(typeof _56b=="undefined"){
_56b=1;
}
var _56f=$("content_current_"+id).value;
Element.hide($(_56d+"_"+_56f));
Element.show($(_56d+"_"+_568));
$("content_current_"+id).value=_568;
$("pagination_"+id).update($("pagination_saved_"+id+"_"+_568).innerHTML);
this.widget[id].column.redraw();
scrollElementInView(this.widget[id].element);
if(_569!=0&&_568>=(_56c[1]-_569)){
_56c[1]=parseInt(_56c[1])+_56b;
$("content_range_"+id).value=_56c.join("_");
this.loadPagesNext(id,_56c,_56a,_56b);
}
if(_569!=0&&_568<=parseInt(_56c[0])+_569&&_56c[0]>1){
var _570=parseInt(_56c[0])-_56b;
if(_570<1){
_570=1;
}
_56c[0]=_570;
$("content_range_"+id).value=_56c.join("_");
this.loadPagesPrevious(id,_56c,_56a,_56b);
}
return false;
}else{
if(_56c[0]<=_568&&_568<=_56c[1]&&(typeof this.timestamp[id]!="undefined")){
var now=(new Date()).getTime();
if(now-this.timestamp[id]<this.AJAX_TIMEOUT){
return false;
}
}else{
if($(_56d+"_"+_56e)&&Element.hasClassName($(_56d+"_"+_56e),"widget_saved_view")){
if(typeof _569=="undefined"){
_569=0;
}
if(typeof _56a=="undefined"){
_56a=1;
}
if(typeof _56b=="undefined"){
_56b=1;
}
this.timestamp[id]=(new Date()).getTime();
_570=parseInt(_56c[0])-_56b;
if(_570<1){
_570=1;
}
_56c[0]=_570;
$("content_range_"+id).value=_56c.join("_");
this.loadPagesPrevious(id,_56c,_56a,_56b,_568);
return false;
}
}
}
_56c=[_568,_568+_56b-1];
$("content_range_"+id).value=_56c.join("_");
this.widget[id].refresh(_568);
scrollElementInView(this.widget[id].element);
return false;
},refreshWidgetConfig:function(id,_573,_574){
if(typeof _574=="undefined"){
_574=false;
}
var _575=$H({action:"refreshConfig",userId:this.getUserId(),widgetId:id,formData:_573}).toQueryString();
var ajax=new Ajax.Updater({success:"widget_config_form_"+id},"/xml/widgets.php",{method:"post",parameters:_575,onComplete:function(){
if(_574){
this.widget[id].getColumn().redraw();
}
}.bind(this)});
},handleWidgetConfig:function(id){
var _578="edit_"+id;
var _579="footer_"+id;
var _57a="control_"+id;
var _57b="config_"+id;
var _57c="title_"+id;
var _57d=$(id).getHeight()-$(_57c).getHeight()-$(_579).getHeight()-10;
var _57e=$(_578).getHeight();
if(_57d<_57e){
this.checkHeight(_57e);
}
$(_57a).toggle();
$(_578).toggle();
this.widget[id].getColumn().redraw();
var _57f=getElementScreenTop();
var top=getElementTop($(_578));
if(top<_57f){
setElementScreenTop(top);
}
this.fadeInEffect(id);
},makeDraggable:function(_581){
if(this.draggedId!=null){
return false;
}
this.draggedId=_581.getId();
return true;
},beingDragged:function(_582){
return this.draggedId==_582.getId();
},doneBeingDragged:function(){
this.draggedId=null;
},getUserId:function(){
return this.userId;
},getNumColumns:function(){
return this.numColumns;
},getCanvasId:function(){
return this.canvasId;
},getCurrentColumnId:function(_583){
var _584=this.widget[_583.getId()].getColumnId();
var _585=(window.pageYOffset)?window.pageYOffset:(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop;
for(var _586 in this.column){
var last=this.column[_586].order.length-1;
var _588=(last==-1)?(getElementBottom($("addWidgetButton"))>_585):(getElementBottom(this.column[_586].order[last].element)>_585);
if(this.column[_586].containsElement(_583,_584)&&_588){
return _586;
}
}
return _584;
},getStartY:function(){
return this.startY;
},getHorizSpace:function(){
return this.horizSpace;
},hideDottedBox:function(){
$(this.DOTTEDBOX_ID).hide();
},drawDottedBox:function(top,left,_58b,_58c){
$(this.DOTTEDBOX_ID).hide();
$(this.DOTTEDBOX_ID).style.top=top+"px";
$(this.DOTTEDBOX_ID).style.left=left+"px";
$(this.DOTTEDBOX_ID).style.height=_58b+"px";
$(this.DOTTEDBOX_ID).className=_58c;
$(this.DOTTEDBOX_ID).show();
},swapColumns:function(_58d,_58e,_58f){
this.widget[_58d.getId()].setColumn(this.column[_58f]);
this.column[_58e].remove(_58d);
this.column[_58f].add(_58d);
},columnBefore:function(_590,_591){
return this.column[_590].getStartX()<this.column[_591].getStartX();
},columnAfter:function(_592,_593){
return this.column[_592].getStartX()>this.column[_593].getStartX();
},redraw:function(){
var _594=0;
for(var _595 in this.column){
this.column[_595].redraw();
if(this.column[_595].getHeight()>_594){
_594=this.column[_595].getHeight();
}
}
this.height=_594;
this.element.style.height=_594+"px";
}};
var WidgetColumn=Class.create();
WidgetColumn.prototype={CLASSNAME:"reorderWidget",initialize:function(_596,_597){
this.element=$(_596);
this.canvas=_597;
this.width=this.element.offsetWidth;
this.height=this.element.offsetHeight;
this.startX=this.element.offsetLeft;
this.order=[];
this.columnId=_596;
this.stopX=this.startX+this.width;
this.element.getElementsBySelector("div."+this.CLASSNAME).each(function(elem){
this.makeWidget(elem,this.order.length,true,$F("r_"+elem.id));
}.bind(this));
},makeWidget:function(elem,_59a,_59b,_59c){
if(typeof _59b=="undefined"){
_59b=true;
}
if(typeof _59c=="undefined"){
_59c=0;
}
var _59d=new Widget(elem,this,_59b,_59a,_59c);
this.canvas.addWidget(_59d,this,_59a);
},getColumnId:function(){
return this.element.id;
},getCanvas:function(){
return this.canvas;
},getHeight:function(){
return this.height;
},getStartX:function(){
return this.startX;
},containsElement:function(_59e,_59f){
var l=_59e.getLeft();
var r=_59e.getRight();
if(this.element.id==_59f){
return (l>=this.startX&&r<=this.stopX);
}else{
return (l<(this.stopX-0.6*this.width)&&this.canvas.columnBefore(this.element.id,_59f)||r>(this.startX+0.6*this.width+10)&&this.canvas.columnAfter(this.element.id,_59f));
}
},remove:function(_5a2){
var tmp=[];
for(var i=0;i<this.order.length;i++){
if(this.order[i]!=_5a2){
this.updatePosition(tmp,this.order[i]);
}
}
this.order=tmp;
this.redraw();
},addWidgetHTML:function(id,_5a6,_5a7,_5a8){
var _5a9=document.createElement("div");
if(!_5a9.update){
Element.extend(_5a9);
}
_5a9.id=id;
_5a9.className=this.CLASSNAME;
_5a9.update(_5a6);
this.element.appendChild(_5a9);
_5a9.onmouseover=function(){
this.canvas.handleHoverOn(id);
}.bind(this);
_5a9.onmouseout=function(){
this.canvas.handleHoverOff(id);
}.bind(this);
var elem=$(id);
this.makeWidget(elem,_5a7,true,_5a8);
this.redraw();
},updateWidgetHTML:function(id,_5ac){
var _5ad=$(id);
_5ad.update(_5ac);
this.redraw();
},updatePosition:function(_5ae,_5af){
_5af.setPosition(_5ae.length);
_5ae[_5ae.length]=_5af;
},add:function(_5b0,_5b1){
var tmp=[];
var done=false;
if(_5b1){
for(var i=0;i<this.order.length;i++){
if(_5b1==0){
this.updatePosition(tmp,_5b0);
done=true;
}
this.updatePosition(tmp,this.order[i]);
_5b1--;
}
if(!done){
this.updatePosition(tmp,_5b0);
}
this.order=tmp;
this.redraw();
return;
}
for(i=0;i<this.order.length;i++){
if(this.order[i]!=_5b0){
if(done||this.order[i].getTop()<_5b0.getTop()){
this.updatePosition(tmp,this.order[i]);
}else{
this.updatePosition(tmp,_5b0);
this.updatePosition(tmp,this.order[i]);
done=true;
}
}
}
if(!done){
this.updatePosition(tmp,_5b0);
}
this.order=tmp;
setTimeout(function(){
this.redraw();
}.bind(this),100);
},redraw:function(){
var th=this.canvas.getStartY();
for(var i=0;i<this.order.length;i++){
var _5b7=this.order[i];
var h=_5b7.getHeight();
if(_5b7.isSelected()){
this.canvas.drawDottedBox(th,this.startX,h,this.columnId);
}else{
_5b7.setDimensions({top:th,left:this.startX,columnId:this.columnId});
}
th+=parseInt(h)+parseInt(this.canvas.getHorizSpace());
}
this.height=th-this.canvas.getStartY()+this.canvas.getHorizSpace();
this.canvas.checkHeight(this.height);
}};
var Widget=Class.create();
Widget.prototype={initialize:function(_5b9,_5ba,_5bb,_5bc,_5bd){
if(typeof _5bb=="undefined"){
_5bb=false;
}
if(typeof _5bc=="undefined"){
_5bc=0;
}
if(typeof _5ba=="undefined"){
_5ba=null;
}
if(typeof _5bd=="undefined"){
_5bd=0;
}
this.element=_5b9;
this.id=_5b9.id;
this.column=_5ba;
this.draggable=_5bb;
this.position=_5bc;
this.refreshRate=_5bd;
this.pageNum=1;
if(_5bb){
this.makeDraggable();
if(_5bd!=0&&_5bd<45){
_5bd=45;
}
if(_5bd!=0){
if(typeof this.intervalId!="undefined"){
clearInterval(this.intervalId);
}
var _5be=Math.floor(60*Math.random())*1000+10000;
window.setTimeout(function(){
this.intervalId=setInterval(this.pollForRefresh.bind(this),_5bd*1000);
}.bind(this),_5be);
}
}
},pollForRefresh:function(){
if(this.getCanvas().widgetIsGone(this.id)){
clearInterval(this.intervalId);
}else{
if(this.pageNum==1&&!$("edit_"+this.id).visible()){
if(this.getCanvas().recentActivity()){
this.refresh(1,function(){
clearInterval(this.intervalId);
}.bind(this));
}
}
}
},makeDraggable:function(){
this.dragger=new Dragger(this.element,false);
this.dragger.ondrag=this.ondrag.bind(this);
this.dragger.onstop=this.onstop.bind(this);
this.dragger.onstart=this.onstart.bind(this);
var _5bf=$("title_"+this.element.id);
Event.observe(_5bf,"mousedown",function(_5c0){
if(!_5bf.hasClassName("disableDragAndDrop")){
this.dragger.handleStart(_5c0);
}
}.bind(this));
_5bf.onmousedown=function(){
if(!_5bf.hasClassName("disableDragAndDrop")){
if(browser=="Safari"){
return false;
}else{
return true;
}
}
};
Event.observe(document,"mouseup",function(_5c1){
if(!_5bf.hasClassName("disableDragAndDrop")){
this.dragger.handleStop(_5c1);
}
}.bind(this));
},getColumnId:function(){
return this.column.getColumnId();
},getColumn:function(){
return this.column;
},setColumn:function(_5c2){
this.column=_5c2;
},getPosition:function(){
return this.postion;
},setPosition:function(_5c3){
this.position=_5c3;
},getTop:function(){
return parseInt(removePXFromSize(this.element.style.top));
},getLeft:function(){
return parseInt(removePXFromSize(this.element.style.left));
},getRight:function(){
return this.getLeft()+this.element.getWidth();
},getHeight:function(){
var _5c4="edit_"+this.getId();
if($(_5c4).visible()&&$(_5c4).getHeight()>this.element.getHeight()){
return $(_5c4).getHeight();
}
return this.element.getHeight();
},getCanvas:function(){
return this.column.getCanvas();
},getId:function(){
return this.element.id;
},setDimensions:function(dim){
for(var prop in dim){
switch(prop){
case "top":
this.element.style.top=dim.top+"px";
break;
case "left":
this.element.style.left=dim.left+"px";
break;
case "columnId":
this.element.className="reorderWidget "+dim.columnId;
break;
}
}
},save:function(){
var _5c7=$H({action:"savePosition",columnId:this.getColumnId(),canvasId:this.getCanvas().getCanvasId(),position:this.position,widgetId:this.getId(),userId:this.getCanvas().getUserId()}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_5c7,onSuccess:function(_5c9){
if(!_5c9.responseText){
document.location.reload();
}
}});
},refresh:function(_5ca,_5cb){
if(typeof _5ca=="undefined"){
_5ca=1;
}
if(typeof _5cb=="undefined"){
_5cb=function(){
};
}
if(typeof postFunc=="undefined"){
postFunc=null;
}
var _5cc=$("last_update_"+this.getId()).value;
this.pageNum=_5ca;
var _5cd=$H({action:"refresh",widgetId:this.getId(),pageNum:_5ca,userId:this.getCanvas().getUserId()}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_5cd,onFailure:_5cb,onSuccess:function(_5cf){
if(!_5cf.responseText){
_5cb();
document.location.reload();
}else{
var _5d0=$("last_update_"+this.getId()).value;
if(_5d0==_5cc){
var resp=JSONstring.toObject(_5cf.responseText);
this.column.updateWidgetHTML(resp.id,resp.widgetHTML);
this.makeDraggable();
}
}
}.bind(this)});
},ondrag:function(){
if(!this.getCanvas().beingDragged(this)){
return;
}
var _5d2=this.column.getColumnId();
var _5d3=this.column.getCanvas();
var _5d4=_5d3.getCurrentColumnId(this);
if(_5d2!=_5d4){
_5d3.swapColumns(this,_5d2,_5d4);
}else{
this.column.add(this);
}
},onstop:function(){
if(!this.getCanvas().beingDragged(this)){
return;
}
if(Element.hasClassName(this.element,"opaque")){
Element.removeClassName(this.element,"opaque");
}
this.column.getCanvas().hideDottedBox();
this.column.add(this);
this.save();
this.getCanvas().doneBeingDragged();
this.column.redraw();
},isSelected:function(){
return Element.hasClassName(this.element,"opaque");
},onstart:function(){
if(!this.getCanvas().makeDraggable(this)){
return;
}
if(!Element.hasClassName(this.element,"opaque")){
Element.addClassName(this.element,"opaque");
}
this.column.redraw();
}};
function switchHomePage(_5d5,_5d6){
if(_5d6.value==0){
return;
}
var _5d7=$H({action:"switchHomePage",userId:_5d5,target:_5d6.value}).toQueryString();
var ajax=new Ajax.Request("/xml/widgets.php",{method:"post",parameters:_5d7,onSuccess:function(_5d9){
if(_5d9.responseText){
var resp=JSONstring.toObject(_5d9.responseText);
if(_5d6.value!=resp.oldValue){
location.replace("/");
}
}
}});
};
var DISLIKE_LINKS_WITHIN_CHARS=200;
var DISALLOW_LINKS_WITHIN_CHARS=20;
var SUGGESTIONS_LEFT=20;
var SUGGESTIONS_WIDTH=400;
var showingLinks=0;
jQuery(function(){
jQuery("#admincenter .show_keywords").click(function(){
var mode=jQuery(this).html();
if(mode=="suggest links"){
showConnectivityDetails=1;
if(showingLinks){
jQuery(this).html("hide links");
jQuery("#authorcenter .show_keywords").html("suggest links");
return false;
}
jQuery(this).addClass("loading");
showSuggestedLinks(this,"hide links");
showingLinks=1;
}else{
jQuery(this).html("suggest links");
hideSuggestedLinks();
}
return false;
});
jQuery("#keyword_instructions_popup .stop_suggesting").live("click",function(){
jQuery(showConnectivityDetails?"#admincenter .show_keywords":"#authorcenter .show_keywords").triggerHandler("click");
return false;
});
jQuery("#authorcenter .show_keywords").click(function(){
var mode=jQuery.trim(jQuery(this).html());
if(mode=="suggest links"){
if(showingLinks){
showConnectivityDetails=0;
jQuery(this).html("hide links");
jQuery("#admincenter .show_keywords").html("suggest links");
return false;
}
jQuery(this).addClass("loading");
showSuggestedLinks(this,"hide links");
showingLinks=1;
}else{
jQuery(this).html("suggest links");
hideSuggestedLinks();
}
return false;
});
jQuery("#connectivity_center #show_conn_score").click(function(){
jQuery("#connectivity_center #wait").show();
jQuery.ajax({url:"/xml/connectivity/show_score.php?articleId="+articleId,success:function(msg){
jQuery("#connectivity_center #wait").hide();
alert(msg);
}});
return false;
});
jQuery("a.keyword, a.custom_keyword").live("click",function(){
var _5de=jQuery(this);
_5de.addClass("active_keyword");
_5de.addClass("loading");
var _5df=_5de.text().replace(/[\.,']/g,"");
jQuery.ajax({url:"/xml/connectivity/map_keyword_to_search_terms.php?articleId="+articleId+"&keyword="+_5df+"&details="+showConnectivityDetails,success:function(msg){
_5de.removeClass("loading");
popupSearchSuggestions(_5de,msg);
tip_init();
}});
return false;
});
jQuery("#keyword_searches_popup a.vote").live("click",function(){
var _5e1=jQuery(this);
var tr=_5e1.closest("tr");
jQuery.ajax({url:"/xml/connectivity/suggestion_vote.php",data:{articleId:articleId,toArticleId:tr.attr("id"),numSearches:jQuery("td.num_searches",tr).html(),isFanOf:jQuery("td.is_fan",tr).html(),categorySimilarity:jQuery("td.category_similarity",tr).html(),keyword:jQuery("#keyword_searches_popup").data("keyword"),searchTerm:jQuery("td.search_term",tr).html(),index:jQuery("td.index",tr).html(),vote:jQuery(this).html()},success:function(msg){
_5e1.css("font-weight","bold").css("color","green");
alert(msg);
}});
return false;
});
jQuery("#keyword_searches_popup a.make_link").live("click",function(){
var _5e4=jQuery("#keyword_searches_popup");
var tr=showConnectivityDetails?jQuery(this).closest("tr"):jQuery(this).closest("li");
var _5e6=_5e4.data("keywordEleWrapper");
var _5e7=_5e4.data("moduleId");
jQuery.ajax({url:"/xml/connectivity/make_link.php",data:{articleId:articleId,moduleId:_5e7,toArticleId:tr.attr("id"),keyword:jQuery("#keyword_searches_popup").data("keyword"),keywordIndex:jQuery("#keyword_searches_popup").data("keywordIndex")},success:function(msg){
jQuery("#keyword_searches_popup").hide();
jQuery("#connectivity_line").hide();
var txtd=jQuery("#txtd_"+_5e7);
txtd.html(msg);
showKeywords();
}});
return false;
});
jQuery("a.make_category_link").live("click",function(_5ea){
var _5eb=jQuery(this);
_5eb.addClass("active_keyword");
var _5ec=jQuery("#keyword_searches_popup");
if(_5ec.length==0){
jQuery("#container").append("<div id=\"keyword_searches_popup\"></div><div id=\"connectivity_line\" style=\"display: none;\"></div>");
_5ec=jQuery("#keyword_searches_popup");
}
popupHtml="<a href=\"#\" class=\"close\" onClick=\"return closeKeywordSearchesPopup();\">X</a>";
popupHtml+="  <div id=\"popup_content\"><ul><li><a href=\"#\" class=\"make_link_cat\" onclick=\"makeCategoryLink(); jQuery('#keyword_searches_popup').hide(); return false;\">make link</a> <a href=\""+_5eb.attr("href")+"\" target=\"_blank\">"+_5eb.attr("title")+"</a> community page</li></ul></div>";
_5ec.html(popupHtml);
var _5ed=_5eb.closest(".moduleText");
var _5ee=_5ed.attr("id").substring(4);
_5ec.data("moduleId",_5ee);
_5ec.data("keyword",_5eb.text());
_5ec.data("keywordIndex",_5eb.data("keywordIndex"));
_5ec.data("href",_5eb.attr("href"));
var pos=_5eb.position();
var _5f0=browser=="Opera"?16:_5eb.height();
var _5f1=pos.left-SUGGESTIONS_LEFT-SUGGESTIONS_WIDTH;
if(_5f1>0){
_5ec.css({"left":SUGGESTIONS_LEFT+"px","top":pos.top+"px"});
jQuery("#connectivity_line").css({"left":SUGGESTIONS_WIDTH+"px","top":pos.top+"px","width":_5f1+"px","display":"block"});
}else{
_5ec.css({"left":SUGGESTIONS_LEFT+"px","top":(pos.top+_5f0+1)+"px"});
jQuery("#connectivity_line").hide();
}
_5ec.show();
return false;
});
jQuery("#keyword_searches_popup a#user_mode").live("click",function(){
jQuery("#keyword_searches_popup .admin").hide();
return false;
});
jQuery("#keyword_searches_popup a#admin_mode").live("click",function(){
jQuery("#keyword_searches_popup .admin").show();
return false;
});
jQuery(".connectivity_dimmed").live("mousedown",function(){
return false;
});
jQuery(".connectivity_dimmed").live("click",function(){
return false;
});
return false;
});
function showSuggestedLinks(link,txt){
jQuery.ajax({url:"/xml/connectivity/show_keywords.php?articleId="+articleId,success:function(msg){
jQuery(".module").each(function(){
if(!jQuery(this).hasClass("moduleText")){
jQuery(this).addClass("connectivity_dimmed");
}
});
jQuery("#sidebar, .moduleText .subtitle").addClass("connectivity_dimmed");
jQuery(link).removeClass("loading");
jQuery(link).html(txt);
showKeywords(msg);
jQuery(".moduleText").bind("mouseup",phraseHighlightHandler);
jQuery(".moduleText").bind("mousedown",recordMouseDown);
}});
};
function showKeywords(_5f5){
jQuery(".keyword_wrapper").each(function(){
var _5f6=jQuery(".keyword, .custom_keyword, .make_category_link",jQuery(this));
jQuery(this).replaceWith(_5f6.html());
});
var _5f7=_5f5?true:false;
if(_5f7){
var _5f8=eval("("+_5f5+")");
searchArr=_5f8["search"];
for(var i=0;i<searchArr.length;i++){
keywordArr.push(searchArr[i].word);
keywordFreq[searchArr[i].word]=searchArr[i].freq;
}
categoryArr=_5f8["category"];
}
if(keywordArr.length==0&&categoryArr.length==0){
popupConnectivityInstructions(false);
return false;
}
var data={"already_used":[],"keyword_counts":[],"suggested_count":0};
jQuery(".moduleText .txtd a").each(function(){
data["already_used"].push(jQuery(this).text().trim().toLowerCase());
});
var _5fb=!_5f7;
var y=0;
jQuery(".moduleText .txtd").each(function(){
var _5fd=false;
var wrap=[];
jQuery(this).contents().each(function(){
if(this.nodeType==3){
_5fd=true;
wrap.push(this);
}else{
if(this.nodeType==1){
if(this.tagName&&-1!=jQuery.inArray(this.tagName,["A","SPAN","EM","STRONG","I","B","U"])){
_5fd=true;
wrap.push(this);
}else{
if(_5fd){
jQuery(wrap).wrapAll("<p></p>");
wrap=[];
_5fd=false;
}
}
}
}
});
if(_5fd){
jQuery(wrap).wrapAll("<p></p>");
wrap=[];
_5fd=false;
}
jQuery(this).html(removeEmptyTags(jQuery(this).html()));
jQuery(this).children().each(function(){
data=showBestKeywords(this,data);
if(data["suggested_count"]&&!_5fb){
_5fb=true;
y=jQuery(this).offset().top-100;
jQuery("html,body").animate({scrollTop:y},500);
}
});
data["keyword_counts"]=[];
});
if(_5f7&&data["suggested_count"]==0){
popupConnectivityInstructions(false);
}else{
if(_5f7){
popupConnectivityInstructions(true,y);
}
}
};
function showBestKeywords(elt,data){
var html=jQuery(elt).html();
html=html.replace(new RegExp("(</[p|li|h2|h3|h4|pre][^>]*>)","ig"),"$1 \n");
var _602=regSplitOffsetCapture(html,new RegExp("<[^>]*>","g"));
var _603=_602.parts;
var _604=_602.offsets;
var _605=_603.join("");
var _606=[];
for(var i=0;i<_603.length;i++){
_606.push(i==0?0:_606[i-1]+_603[i-1].length);
}
var _608=[];
var _609=[];
var _60a=0;
var _60b={};
var _60c={};
for(var i=0;i<categoryArr.length;i++){
_60d=categoryArr[i].keyword;
if(_60c[_60d]!=undefined){
continue;
}
var _60e="(\\b)("+_60d.replace(" ","\\s+").replace("-","\\-").replace("+","\\+")+")(\\b)";
var _60f=_605.match(new RegExp(_60e,"ig"));
var _610=regOffsetCapture(_605,new RegExp(_60e,"i"));
if(!_610){
continue;
}
_60b[_60d]=_610.length;
if(jQuery.inArray(_60d.toLowerCase(),data["already_used"])==-1){
_60a+=_610.length;
_60c[_60d]=_610;
_608[_60d.toLowerCase()]=categoryArr[i].url;
_609[_60d.toLowerCase()]=categoryArr[i].name;
}
}
for(var i=0;i<keywordArr.length;i++){
var _60d=keywordArr[i];
if(_60c[_60d]!=undefined){
continue;
}
var _60e="(\\b)("+_60d.replace(/ /g,"\\s+").replace(/-/g,"\\-")+")(\\b)";
var _60f=_605.match(new RegExp(_60e,"ig"));
var _610=regOffsetCapture(_605,new RegExp(_60e,"i"));
if(!_610){
continue;
}
_60b[_60d]=_610.length;
if(jQuery.inArray(_60d.toLowerCase(),data["already_used"])==-1){
_60a+=_610.length;
_60c[_60d]=_610;
}
}
var _611=[];
if(_60a){
var _612=jQuery.extend({},data["keyword_counts"]);
while(_611.length<Math.min(12,_60a)){
var _613=9999999999;
jQuery.each(_60c,function(_614,_615){
for(var i=0;i<_615.length;i++){
var pos=_615[i];
if(pos<_613){
_613=pos;
best_keyword=_614;
}
}
});
var _618=translateCoordinates(_613,_606,_604);
var _619=translateCoordinates(_613+best_keyword.length-1,_606,_604);
var _61a=(_612[best_keyword]==undefined)?0:_612[best_keyword];
_611.push({keyword:best_keyword,start_index:_618,end_index:_619,keywordIndex:_61a,url:_608[best_keyword.toLowerCase()]?_608[best_keyword.toLowerCase()]:"",name:_609[best_keyword.toLowerCase()]});
_612[best_keyword]=_61a+1;
_60c[best_keyword].splice(_60c[best_keyword].indexOf(_613),1);
}
var _61b=Math.pow(2,_611.length);
var _61c=-9999999999;
var _61d=0;
for(var c=0;c<_61b;c++){
var _61f=scoreKeywordCombo(_611,html,c);
if(_61f>_61c){
_61c=_61f;
_61d=c;
}
}
}
var i=0;
var _620=0;
var _621=[];
while(_61d){
if(_61d&1){
var _622=_611[i];
_621.push(_622);
data["suggested_count"]++;
var _623=_622.start_index+_620;
var _624=_622.end_index+_620;
var _60d=_622.keyword;
var _625=html.length;
var _626="</a></span>";
if(_622["url"]!=""){
var _627="<span class=\"keyword_wrapper\"><a class=\"make_category_link newkeyword\" href=\""+_622["url"]+"\" title=\""+_622["name"]+"\">";
}else{
var _627="<span class=\"keyword_wrapper\"><a class=\"keyword newkeyword\" href=\"#\">";
}
html=safeLinkInsert(html,_623,_624,_627,_626,false);
_620+=(html.length-_625);
data["already_used"].push(_60d.toLowerCase());
}
_61d=_61d>>1;
i++;
}
if(_621.length){
jQuery(elt).html(html.replace(" \n"," "));
jQuery("a.newkeyword",elt).each(function(i){
jQuery(this).data("keywordIndex",_621[i]["keywordIndex"]).removeClass("newkeyword");
});
}
jQuery.each(_60b,function(_629,_62a){
data["keyword_counts"][_629]=data["keyword_counts"][_629]==null?_62a:data["keyword_counts"][_629]+_62a;
});
return data;
};
function scoreKeywordCombo(_62b,html,c){
if(!c){
return 0;
}
var _62e=[];
var _62f=c;
var i=0;
while(c){
if(c&1){
_62e.push(_62b[i]);
}
c=c>>1;
i++;
}
var _631=[];
for(i=0;i<_62e.length;i++){
if(_631[_62e[i].keyword]!=undefined){
return -9999999999;
}
_631[_62e[i].keyword]=1;
}
for(i=0;i<_62e.length-1;i++){
if(_62e[i+1].start_index<=_62e[i].end_index){
return -9999999999;
}
}
var _632=0;
for(i=0;i<_62e.length;i++){
var _633=_62e[i];
if(_633.url==""){
_632+=12*Math.exp(-0.017*Math.sqrt(keywordFreq[_633.keyword]));
}else{
_632+=30;
}
}
for(i=0;i<_62e.length;i++){
var _634=computeAnchorDistance(html,_62e[i].start_index,_62e[i].end_index);
var _635=i==0?_634.left:Math.min(_634.left,_62e[i].start_index-_62e[i-1].end_index);
var _636=_634.right;
if(_635<DISALLOW_LINKS_WITHIN_CHARS||_636<DISALLOW_LINKS_WITHIN_CHARS){
return -999999999;
}
if(_635<DISLIKE_LINKS_WITHIN_CHARS){
_632-=(DISLIKE_LINKS_WITHIN_CHARS-_635)/10;
}
if(_636<DISLIKE_LINKS_WITHIN_CHARS){
_632-=(DISLIKE_LINKS_WITHIN_CHARS-_636)/10;
}
}
return _632;
};
function hideSuggestedLinks(){
jQuery("#keyword_instructions_popup, #keyword_searches_popup, #connectivity_line").hide();
jQuery(".keyword_wrapper").each(function(){
var _637=jQuery(".keyword, .custom_keyword, .make_category_link",jQuery(this));
jQuery(this).replaceWith(_637.html());
});
jQuery("#sidebar, .module, .moduleText .subtitle").each(function(){
jQuery(this).removeClass("connectivity_dimmed");
});
showConnectivityDetails=0;
keywordArr=[];
keywordFreq=[];
categoryArr=[];
showingLinks=0;
recentMouseDown=null;
jQuery(".moduleText").unbind("mouseup",phraseHighlightHandler);
jQuery(".moduleText").unbind("mousedown",recordMouseDown);
};
function popupConnectivityInstructions(_638,_639){
var _63a=jQuery("#keyword_instructions_popup");
if(_63a.length==0){
var _63b="<div id=\"keyword_instructions_popup\">";
_63b+="<h2>Instructions</h2>";
_63b+="<p>You have <span class=\"connectivity_score\">"+hubKarma+"</span> HubKarma. This tool can help you increase your HubKarma. <a href=\"/faq/#hubkarma\">[learn more]</a></p>";
_63b+=(_638?"<p>Click on a <span class=\"highlight_example\">highlighted phrase</span> to see link suggestions for that phrase. Click on the plus icon next to a link suggestion to add the link to your Hub.</p>":"<p class=\"none_found\">No link suggestions were found.</p>");
_63b+="<p>To see suggestions for any phrase up to six words long, select the phrase with your mouse.</p>";
_63b+="<a class=\"stop_suggesting\" href=\"#\">stop suggesting links</a>";
_63b+="</div>";
jQuery("#container").append(_63b);
_63a=jQuery("#keyword_instructions_popup");
}
_63a.show();
};
function popupSearchSuggestions(_63c,_63d){
var _63e=jQuery("#keyword_searches_popup");
if(_63e.length==0){
jQuery("#container").append("<div id=\"keyword_searches_popup\"></div><div id=\"connectivity_line\" style=\"display: none;\"></div>");
_63e=jQuery("#keyword_searches_popup");
}
popupHtml="<a href=\"#\" class=\"close\" onClick=\"return closeKeywordSearchesPopup();\">X</a>";
if(showConnectivityDetails){
popupHtml+="  mode: <a id=\"admin_mode\" href=\"#\">admin</a> | <a id=\"user_mode\" href=\"#\">user</a>";
}
popupHtml+="  <div id=\"popup_content\" class=\""+(showConnectivityDetails?"detailed":"")+"\"></div>";
_63e.html(popupHtml);
_63e.data("keyword",_63c.text());
_63e.data("keywordIndex",_63c.data("keywordIndex"));
_63e.data("keywordEleWrapper",_63c.closest("span.keyword_wrapper"));
_63e.data("moduleId",_63c.closest(".moduleText").attr("id").substring(4));
var _63f=jQuery("#popup_content",_63e);
_63f.html(_63d);
var pos=_63c.position();
var _641=browser=="Opera"?16:_63c.height();
var _642=pos.left-SUGGESTIONS_LEFT-SUGGESTIONS_WIDTH;
if(_642>0){
_63e.css({"left":SUGGESTIONS_LEFT+"px","top":pos.top+"px"});
jQuery("#connectivity_line").css({"left":SUGGESTIONS_WIDTH+"px","top":pos.top+"px","width":_642+"px","display":"block"});
}else{
_63e.css({"left":SUGGESTIONS_LEFT+"px","top":(pos.top+_641+1)+"px"});
jQuery("#connectivity_line").hide();
}
if(showConnectivityDetails){
_63e.addClass("connectivity_detailed");
}else{
_63e.removeClass("connectivity_detailed");
}
_63e.show();
};
function closeKeywordSearchesPopup(){
jQuery("#keyword_searches_popup").hide();
jQuery("#connectivity_line").hide();
var _643=jQuery(".active_keyword");
if(_643){
if(_643.hasClass("custom_keyword")){
_643.parent().replaceWith(_643.html());
document.body.normalize();
showKeywords();
}else{
_643.removeClass("active_keyword");
}
}
return false;
};
function makeCategoryLink(url){
var _645=jQuery("#keyword_searches_popup").data("moduleId");
var url=url?url:jQuery("#keyword_searches_popup").data("href");
jQuery.ajax({url:"/xml/connectivity/make_link.php",data:{articleId:articleId,toArticleId:0,moduleId:_645,keyword:jQuery("#keyword_searches_popup").data("keyword"),keywordIndex:jQuery("#keyword_searches_popup").data("keywordIndex"),url:url},success:function(msg){
jQuery("#keyword_searches_popup").hide();
jQuery("#connectivity_line").hide();
var txtd=jQuery("#txtd_"+_645);
txtd.html(msg);
showKeywords();
}});
return false;
};
var recordMouseDown=function(_648){
recentMouseDown={top:_648.pageY,left:_648.pageX,target:_648.target};
};
var phraseHighlightHandler=function(_649){
var _64a=false;
var txt="";
if(window.getSelection){
txt=window.getSelection();
}else{
if(document.getSelection){
txt=document.getSelection();
}else{
if(document.selection){
txt=document.selection.createRange().text;
}
}
}
txt=jQuery.trim(txt+"");
if(txt!=""){
var html=getSelectionHTML();
var div=jQuery("<div></div>");
div.html(html);
var _64e=false;
div.find("a").each(function(){
if(!jQuery(this).hasClass("keyword")){
alert("You cannot get link suggestions for a phrase that already contains a link.");
deselectSelection();
_64e=true;
return false;
}
});
if(_64e){
return false;
}
var _64f=txt.split(/[\s\-]+/g);
if(_64f.length>=1){
if(_64f.length>6){
alert("You cannot select more than six words for link suggestions");
}else{
if(txt.match(/^[\w\s\-\.,']+$/)){
if(recentMouseDown){
var x,y;
var _652=recentMouseDown.left<_649.pageX&&recentMouseDown.top-_649.pageY<18;
var _653=_649.pageY-recentMouseDown.top>12;
if(_652){
x=recentMouseDown.left;
y=recentMouseDown.top;
}else{
if(_653){
x=jQuery("#content").offset().left;
y=recentMouseDown.top;
}else{
if(recentMouseDown.top-_649.pageY>12){
x=jQuery("#content").offset().left;
y=_649.pageY;
}else{
x=_649.pageX;
y=_649.pageY;
}
}
}
_64a=showClosestOccurrence(txt,recentMouseDown.target,x,Math.max(0,y-6));
}
}else{
alert("Your phrase must contain only letters, numbers, periods, commas, apostrophes, and hyphens");
deselectSelection();
return;
}
}
}
}
deselectSelection();
};
function showClosestOccurrence(_654,_655,x,y){
var _658=jQuery(_655).closest(".moduleText .txtd");
if(!_658){
return false;
}
var _659=null;
jQuery(_655).closest("p,li,h2,h3,h4,pre",_658).each(function(){
_659=jQuery(this);
});
if(!_659){
return false;
}
jQuery(_659).addClass("closest_node");
showOccurrences(_658,_654);
var _65a=jQuery(".savekeyword",jQuery(".closest_node"));
var _65b=9999999999;
_65a.each(function(){
var _65c=jQuery(this).offset();
var dist=Math.pow(x-_65c.left,2)+Math.pow(y-_65c.top,2);
if(dist<_65b){
_65b=dist;
}
});
var _65e=null;
_65a.each(function(){
var _65f=jQuery(this).offset();
var dist=Math.pow(x-_65f.left,2)+Math.pow(y-_65f.top,2);
if(Math.abs(dist-_65b)<1){
_65e=jQuery(this);
}
});
if(_65e){
_65e.removeClass("savekeyword");
}
jQuery(".savekeyword").each(function(){
var _661=jQuery(this).html();
jQuery(this).parent().replaceWith(_661);
});
jQuery(".closest_node").each(function(){
jQuery(this).removeClass("closest_node");
});
if(_65e){
_65e.click();
return true;
}
return false;
};
function showOccurrences(elt,_663){
var html=jQuery(elt).html();
html=html.replace(new RegExp("(</[p|li|h2|h3|h4|pre][^>]*>)","ig"),"$1\n");
var _665=regSplitOffsetCapture(html,new RegExp("<[^>]*>","g"));
var _666=_665.parts;
var _667=_665.offsets;
var _668=_666.join("");
var _669=[];
for(var i=0;i<_666.length;i++){
_669.push(i==0?0:_669[i-1]+_666[i-1].length);
}
var _66b="(\\b)("+_663.replace(/ /g,"\\s+").replace(/-/g,"\\-")+")(\\b)";
var _66c=_668.match(new RegExp(_66b,"ig"));
var _66d=regOffsetCapture(_668,new RegExp(_66b,"i"));
if(!_66c){
return;
}
var _66e=[];
var _66f=[];
for(var i=0;i<_66c.length;i++){
_66e.push(translateCoordinates(_66d[i],_669,_667));
_66f.push(translateCoordinates(_66d[i]+_66c[i].length-1,_669,_667));
}
if(!_66c.length){
return;
}
var _670=0;
var _671=[];
for(var i=0;i<_66e.length;i++){
var _672=_670+_66e[i];
var _673=_670+_66f[i];
var _674="<span class=\"keyword_wrapper\"><a class=\"custom_keyword newkeyword\" href=\"#\">";
var _675="</a></span>";
var _676=html.length;
html=safeLinkInsert(html,_672,_673,_674,_675,true);
var _677=html.length-_676;
_670+=_677;
if(_677){
_671.push(i);
}
}
jQuery(elt).html(html.replace("\n",""));
var k=0;
var _679=jQuery(elt).parent();
jQuery("a.newkeyword",_679).each(function(){
jQuery(this).data("keywordIndex",_671[k]).addClass("savekeyword").removeClass("newkeyword");
k++;
});
};
function safeLinkInsert(html,_67b,_67c,_67d,_67e,_67f){
if(overlapsLink(html,_67b,_67c)){
if(_67f){
var _680=html.length;
var _681=removeOverlappingLinkSuggestion(html,_67b,_67c);
_67b=_681.startPos;
_67c=_681.endPos;
if(_680==_681.html.length||overlapsNonSuggestedLink(html,_67b,_67c)){
return html;
}
html=_681.html;
}else{
return html;
}
}
var _682=html.substr(_67b,_67c-_67b+1);
var _683=extraTags(html.substr(0,_67b));
var _684=extraTags(html.substr(_67b,_67c-_67b+1));
var _685=_683.openTags;
var _686=_684.openTags;
var _687=_684.closeTags;
var _688=[];
for(var j=_685.length-1;j>=0;j--){
var utci=_687.shift();
if(utci&&utci==_685[j]){
_688.push(_685[j]);
}
}
_688=_688.reverse();
var _68b="";
for(var j=_688.length-1;j>=0;j--){
_68b+="</"+_688[j]+">";
}
_68b+=_67d;
for(var j=0;j<_688.length;j++){
_68b+="<"+_688[j]+">";
}
_68b+=_682;
for(var j=_686.length-1;j>=0;j--){
_68b+="</"+_686[j]+">";
}
_68b+=_67e;
for(var j=0;j<_686.length;j++){
_68b+="<"+_686[j]+">";
}
html=html.substr(0,_67b)+_68b+html.substr(_67c+1);
html=removeEmptyTags(html);
return html;
};
function removeEmptyTags(html){
var _68d=html.length;
var tags=["em","strong","i","b","u"];
for(var i=0;i<tags.length;i++){
var t=tags[i];
html=html.replace(new RegExp("<"+t+"></"+t+">","ig"),"");
html=html.replace(new RegExp("</"+t+"><"+t+">","ig"),"");
}
if(_68d==html.length){
return html;
}else{
return removeEmptyTags(html);
}
};
function removeOverlappingLinkSuggestion(html,_692,_693){
var _694=new RegExp("<span class=\"?keyword_wrapper\"?[^>]*><a class=\"?keyword\"?[^>]*>","i");
var _695=new RegExp("</a></span>","i");
var _696=html.substr(0,_692);
var _697=html.substr(_692,_693-_692+1);
var _698;
var _699=-1;
var _69a=_697.match(_694);
if(_69a){
_699=_696.length+_69a.index;
_698=_69a[0].length;
}else{
var _69b=regOffsetCaptureWithMatches(_696,_694);
var _69c=_69b.offsets;
var _69d=_69b.matches;
var _69e=regOffsetCapture(_696,_695);
if(_69c&&!_69e){
_699=_69c[_69c.length-1];
_698=_69d[_69d.length-1].length;
}else{
if(_69c&&_69e&&(_69c[_69c.length-1]>_69e[_69e.length-1])){
_699=_69c[_69c.length-1];
_698=_69d[_69d.length-1].length;
}
}
}
if(_699!=-1){
matchedEndPosition=html.substr(_699).match(_695).index+_699;
var _69f="</a></span>".length;
var _6a0=_699+_698;
var _6a1=html.substr(_6a0,matchedEndPosition-_6a0);
html=html.substr(0,_699)+_6a1+html.substr(matchedEndPosition+_69f);
startBefore=_692<_699;
endAfter=_693>matchedEndPosition;
if(startBefore&&!endAfter){
_693-=_698;
}else{
if(startBefore&&endAfter){
_693=_693-_698-_69f;
}else{
if(!startBefore&&!endAfter){
_692-=_698;
_693-=_698;
}else{
_692-=_698;
_693=_693-_698-_69f;
}
}
}
}
return {html:html,startPos:_692,endPos:_693};
};
function getSelectionHTML(){
try{
var _6a2;
if(window.getSelection){
_6a2=window.getSelection();
if(_6a2.getRangeAt){
var _6a3=_6a2.getRangeAt(0);
}else{
var _6a3=document.createRange();
_6a3.setStart(_6a2.anchorNode,_6a2.anchorOffset);
_6a3.setEnd(_6a2.focusNode,_6a2.focusOffset);
}
var _6a4=_6a3.cloneContents();
var div=document.createElement("div");
div.appendChild(_6a4);
return div.innerHTML;
}else{
if(document.selection){
_6a2=document.selection.createRange();
return _6a2.htmlText;
}else{
return "";
}
}
}
catch(err){
return "";
}
};
function deselectSelection(){
if(document.selection){
document.selection.empty();
}else{
if(window.getSelection){
window.getSelection().removeAllRanges();
}
}
};
function extraTags(s){
var _6a7=[];
var _6a8=[];
var _6a9=s.match(/<\/?[a-z]+[^>]*>/ig);
if(_6a9){
for(var i=0;i<_6a9.length;i++){
var _6ab=_6a9[i].match(/<(\/?)([a-z]+)[^>]*>/i);
if(_6ab){
if(_6ab[1]=="/"){
var t=_6a7.pop();
if(t&&t!=_6ab[2].toLowerCase()){
_6a7.push(t);
}else{
if(!t){
var _6ad=_6ab[2].toLowerCase();
if(jQuery.inArray(_6ad,["em","strong","i","b","u"])){
_6a8.push(_6ad);
}
}
}
}else{
var t=_6ab[2].toLowerCase();
if(jQuery.inArray(t,["em","strong","i","b","u"])!=-1){
_6a7.push(_6ab[2].toLowerCase());
}
}
}
}
}
return {openTags:_6a7,closeTags:_6a8};
};
function overlapsLink(html,_6af,_6b0){
return overlapsTag(html,_6af,_6b0,"<a[^>]*>","</a>");
};
function overlapsNonSuggestedLink(html,_6b2,_6b3){
return overlapsTag(html,_6b2,_6b3,"<a [^class=\"custom_keyword savekeyword\"][^>]*>","</a>");
};
function overlapsTag(html,_6b5,_6b6,_6b7,_6b8){
var _6b9=new RegExp(_6b7,"i");
var _6ba=new RegExp(_6b8,"i");
var _6bb=html.substr(_6b5,_6b6-_6b5+1);
if(_6bb.search(_6b9)!=-1){
return true;
}
if(_6bb.search(_6ba)!=-1){
return true;
}
var _6bc=html.substr(0,_6b5);
var _6bd=regOffsetCapture(_6bc,_6b9);
var _6be=regOffsetCapture(_6bc,_6ba);
if(_6bd&&!_6be){
return true;
}
if(_6bd&&_6be&&(_6bd[_6bd.length-1]>_6be[_6be.length-1])){
return true;
}
return false;
};
function computeAnchorDistance(html,_6c0,_6c1){
if(overlapsLink(html,_6c0,_6c1)){
return {left:0,right:0};
}
var _6c2=html.substr(0,_6c0).split("").reverse().join("").substr(0,DISLIKE_LINKS_WITHIN_CHARS);
var _6c3=html.substr(_6c1+1,DISLIKE_LINKS_WITHIN_CHARS);
var _6c4=_6c2.match(new RegExp(">a/<","i"));
var l=_6c4?_6c4.index-1:99999;
var _6c6=_6c3.match(new RegExp("<a[^>]*>","i"));
var r=_6c6?_6c6.index:99999;
return {left:l,right:r};
};
function translateCoordinates(pos,_6c9,_6ca){
var ret=pos;
for(var node=0;node<_6c9.length;node++){
if(_6c9[node]>pos){
break;
}
offset=pos-_6c9[node];
ret=_6ca[node]+offset;
}
return ret;
};
function regOffsetCapture(s,reg){
var _6cf=[];
var _6d0=0;
while(true){
var _6d1=s.match(reg);
if(_6d1){
_6cf.push(_6d0+_6d1.index);
var _6d2=_6d1.index+_6d1[0].length+(_6d1[1]?_6d1[1].length:0);
s=s.substr(_6d2);
_6d0+=_6d2;
continue;
}
break;
}
if(_6cf.length==0){
return false;
}
return _6cf;
};
function regOffsetCaptureWithMatches(s,reg){
var _6d5=[];
var _6d6=[];
var _6d7=0;
while(true){
var _6d8=s.match(reg);
if(_6d8){
_6d5.push(_6d7+_6d8.index);
_6d6.push(_6d8[0]+(_6d8[1]?_6d8[1]:""));
var _6d9=_6d8.index+_6d8[0].length+(_6d8[1]?_6d8[1].length:0);
s=s.substr(_6d9);
_6d7+=_6d9;
continue;
}
break;
}
if(_6d5.length==0){
_6d5=false;
}
return {offsets:_6d5,matches:_6d6};
};
var regSplitParts;
var regSplitOffsets;
var nextStartPos=null;
function regSplitOffsetCapture(s,reg){
regSplitParts=[];
regSplitOffsets=[];
previousMatch=null;
previousOffset=null;
s.replace(reg,splitAndSaveOffset);
if(regSplitOffsets.length){
var _6dc=nextStartPos;
regSplitOffsets.push(_6dc);
regSplitParts.push(s.substr(_6dc));
}else{
regSplitOffsets.push(0);
regSplitParts.push(s);
}
return {parts:regSplitParts,offsets:regSplitOffsets};
};
function splitAndSaveOffset(str,_6de,s){
if(regSplitOffsets.length){
var _6e0=nextStartPos;
regSplitOffsets.push(_6e0);
regSplitParts.push(s.substr(_6e0,_6de-_6e0));
}else{
regSplitParts.push(s.substr(0,_6de));
regSplitOffsets.push(0);
}
nextStartPos=_6de+str.length;
return str;
};


