MSG.doc_delete_confirm="Do you want to delete this doc?\n("+_MSG.cannot_undo+")";MSG.doc_deleted_ok="Doc deleted";MSG.doc_deleted_nok="Deletion has failed";MSG.album_creating="Creating album";MSG.album_created_ok="Album created";MSG.album_created_nok="Creating album has failed";var doc_batches=Class.create();doc_batches.prototype.initialize=function(d){if(!$("doc_batches")){return}if(typeof d!="object"){d={}}this.window_div=$("doc_batches");this.interface_div=$("doc_batches_interface");this.window_div.batch=this;this.tabs=["title","share","license","album"];this.tab="title";this.doc_id=0;this.doc_offset=0;this.doc={};this.field_changes={};this.changes_count=0;this.changes_count_before=0;this.doc_defaults={title:"",content:"",posted_at:0,created_at:0,share:31,com:7,tag:7,tagme:7,license:0};this.form_fields=["title","content","keywords","created_at_date","created_at_time","posted_at_date","posted_at_time","share","share_pub","share_fam","share_fri","com","tag","tagme","license"];this.debug_level=800;this.debug_scope="doc_batches";if(d.notabs){for(var c=0;c<d.notabs.length;c++){var b=d.notabs[c];this.tabs.splice(this.tabs.indexOf(b),1);$("doc_batch_tab_"+b).style.display="none"}}this.batch_ids=new Array();this.batch_count=0;for(var c=0;c<this.tabs.length;c++){var b=this.tabs[c];var e=$("doc_batch_tab_"+b);e.tab=b;var a=this;Event.observe(e,"click",function(g){var f=Event.element(g);a.show_tab(f.tab,f);Event.stop(g)})}this.window_div.style.display="none";this.is_shown=false;this.init_interface();IOL.debug("init","",this)};doc_batches.prototype.add_to_batch=function(a){if(a&&this.batch_ids.indexOf(a)<0){this.batch_ids.push(a);this.batch_count=this.batch_ids.length}IOL.debug("doc "+a+" added to batch","",this)};doc_batches.prototype.remove_from_batch=function(a){if(a&&this.batch_ids.indexOf(a)>=0){this.batch_ids.splice(this.batch_ids.indexOf(a),1);this.batch_count=this.batch_ids.length}IOL.debug("doc "+a+" removed from batch","",this)};doc_batches.prototype.reset_batch=function(){this.batch_ids.length=0;this.batch_count=0;
IOL.debug("batch reseted","",this)};doc_batches.prototype.open_only=function(a){if(this.batch_ids.indexOf(a)<0){this.only_id=a;this.add_to_batch(a)}this.open(a)};doc_batches.prototype.open=function(a){if(!this.batch_count){return}if(this.is_shown){return}if(a){this.doc_offset=this.batch_ids.indexOf(a);if(this.doc_offset<0){this.doc_offset=0}}else{this.doc_offset=0}this.doc_id=this.batch_ids[this.doc_offset];if(!this.win){this.win=new win(this.window_div,{zindex:1000,overlay:true})}this.window_div.style.display="none";this.interface_div.style.visibility="hidden";_hide_flash_players();this.show_interface();this.win.show();this.is_shown=true;this.changes_count_before=IOL.changes_count;IOL.debug("open","",this)};doc_batches.prototype.open_next=function(){if(this.changes_count&&!confirm(_MSG.discard_changes)){return}if(this.doc_offset<(this.batch_ids.length-1)){this.doc_offset++}else{this.doc_offset=0}this.doc_id=this.batch_ids[this.doc_offset];this.show_interface()};doc_batches.prototype.open_prev=function(){if(this.changes_count&&!confirm(_MSG.discard_changes)){return}if(this.doc_offset>0){this.doc_offset--}else{this.doc_offset=this.batch_ids.length-1}this.doc_id=this.batch_ids[this.doc_offset];this.show_interface()};doc_batches.prototype.show_date=function(e,c){e.blur();var d=e;while(d.nodeName!="DT"){d=d.parentNode}var b=d;while(b.nodeName!="DL"){b=b.parentNode}$A(d.getElementsByTagName("a")).each(function(f){f.style.color=(f==e)?"#000":""});var a=$A(b.getElementsByTagName("dd"));a[0].style.display=(c=="created")?"block":"none";a[1].style.display=(c=="posted")?"block":"none"};doc_batches.prototype.close=function(){if(this.changes_count&&!confirm(_MSG.discard_changes)){return}_hide_flash_players(1);this.win.hide(true);this.is_shown=false;if(this.only_id){this.batch_ids.splice(this.batch_ids.indexOf(this.only_id),1);this.only_id=undefined}IOL.changes_count=this.changes_count_before;IOL.debug("close","",this)};doc_batches.prototype.init_interface=function(){if(this.is_initialized){return}new cal(document.fbatch.created_at_date,"created");
new cal(document.fbatch.created_at_time,"time");new cal(document.fbatch.posted_at_date,"posted");new cal(document.fbatch.posted_at_time,"time");for(var c=0;c<this.form_fields.length;c++){var e=this.form_fields[c];var d=document.fbatch[e];var a=this;if(d.type=="select-one"){Event.observe(d,"change",function(f){a.check_changes(f)})}else{if(d.length&&d[0].type=="radio"){for(var b=0;b<d.length;b++){Event.observe(d[b],"click",function(f){Event.element(f).blur();a.check_changes(f)})}}else{if(d.type=="checkbox"){Event.observe(d,"click",function(f){Event.element(f).blur();a.check_changes(f)})}else{Event.observe(d,"focus",function(f){a.check_changes(f)});Event.observe(d,"change",function(f){a.check_changes(f)});Event.observe(d,"keyup",function(f){a.check_changes(f)})}}}}this.is_initialized=true;IOL.debug("interface initialized","",this)};doc_batches.prototype.save_initial_values=function(){for(var b=0;b<this.form_fields.length;b++){var d=this.form_fields[b];var c=document.fbatch[d];if(c.type=="select-one"){c.initial_value=c.selectedIndex}else{if(c.length&&c[0].type=="radio"){for(var a=0;a<c.length;a++){c[a].initial_value=c[a].checked}}else{if(c.type=="checkbox"){c.initial_value=c.checked}else{c.initial_value=c.value}}}c.field_name=d}this.changes_count=0;IOL.changes_count=0;this.field_changes={};$("doc_batch_submit").className="disabled";$("doc_batch_revert").style.visibility="hidden"};doc_batches.prototype.check_changes=function(f){if(window.window_is_unloading){return}try{Event.element(f)}catch(a){return}var c=Event.element(f);var d=0;if(c.nodeName=="SELECT"){if(c.selectedIndex!=c.initial_value){d=1}}else{if(c.type=="radio"||c.type=="checkbox"){if(c.checked!=c.initial_value){d=1}}else{if(c.value!=c.initial_value){d=1}}}this.field_changes[c.field_name]=d;this.changes_count=0;for(var b in this.field_changes){this.changes_count+=this.field_changes[b]}if(this.changes_count){$("doc_batch_submit").className="submit";$("doc_batch_revert").style.visibility="visible"}else{$("doc_batch_submit").className="disabled";$("doc_batch_revert").style.visibility="hidden"
}IOL.changes_count=this.changes_count};doc_batches.prototype.revert_changes=function(){for(var b=0;b<this.form_fields.length;b++){var d=this.form_fields[b];var c=document.fbatch[d];if(c.type=="select-one"){c.selectedIndex=c.inital_value}else{if(c.length&&c[0].type=="radio"){for(var a=0;a<c.length;a++){c[a].checked=c[a].initial_value}}else{if(c.type=="checkbox"){c.checked=c.initial_value}else{c.value=c.initial_value}}}}check_share("s",document.fbatch.share.value,true);this.changes_count=0;this.field_changes={};IOL.changes_count=0;$("doc_batch_submit").className="reset";$("doc_batch_revert").style.visibility="hidden"};doc_batches.prototype.show_interface=function(){var c=this.doc_id;if(Data.doc[c]==undefined||!Data.doc[c].is_loaded_for_batch){modal.say(_MSG.loading,{icon:"wait"});var b=this;IOL.API.request("doc.get",{doc_id:c,extra:"content,tag,album"},b);return}var f=Data.doc[c];this.doc=f;for(var a in this.doc_defaults){if(f[a]==undefined){f[a]=this.doc_defaults[a]}}this.show_thumbnail();IOL.debug("content = "+f.content);document.fbatch.title.value=f.title;document.fbatch.content.value=f.content;document.fbatch.keywords.value=f.keywords;document.fbatch.created_at_date.self.set_value_from_time(f.created_at);document.fbatch.created_at_time.self.set_value_from_time(f.created_at);document.fbatch.posted_at_date.self.set_value_from_time(f.posted_at);document.fbatch.posted_at_time.self.set_value_from_time(f.posted_at);check_share("s",f.share,true);_form_radio_set_value(document.fbatch.com,f.com,1);_form_radio_set_value(document.fbatch.tag,f.tag,1);_form_radio_set_value(document.fbatch.tagme,f.tagme,1);_form_radio_set_value(document.fbatch.license,f.license,1);this.save_initial_values();if(this.batch_ids.length>1){$("doc_batch_go_next").style.visibility="visible";$("doc_batch_nav").style.display="block";if(this.batch_ids.indexOf(c)>0){$("doc_batch_prev").style.visibility="visible"}else{$("doc_batch_prev").style.visibility="hidden"}if(this.batch_ids.indexOf(c)<(this.batch_ids.length-1)){$("doc_batch_next").style.visibility="visible"
}else{$("doc_batch_next").style.visibility="hidden"}$("doc_batch_nav_offset").innerHTML=this.doc_offset+1;$("doc_batch_nav_max").innerHTML=this.batch_ids.length}else{$("doc_batch_go_next").style.visibility="hidden";$("doc_batch_nav").style.display="none"}this.show_tab(this.tab);this.interface_div.style.visibility="visible";this.win.resize();if(this.tab=="title"){try{document.fbatch.title.focus();document.fbatch.title.select()}catch(d){}}};doc_batches.prototype.album_show_create=function(){$("doc_batch_album_choose").style.display="none";$("doc_batch_album_create").style.display="block";setTimeout("document.fbatch.album_title.focus()",500)};doc_batches.prototype.album_show_choose=function(){$("doc_batch_album_choose").style.display="block";$("doc_batch_album_create").style.display="none"};doc_batches.prototype.album_choose=function(){this.album_show_choose();var h=this.doc_id;if(!this.album_ids){this.album_ids=new Array();var f=IOL.API.request("album.search",{stp:200,arrback:1});var l=f[0];var m=f[1];if(!l){modal.say(_MSG.failed,{icon:"nok"},1);return}for(var e=0;e<m.albums.length;e++){var c=m.albums[e];IOL.Data.set("album",c.album_id,c);this.album_ids.push(c.album_id)}}if(this.album_ids.length==0){return this.album_show_create()}var a=$("doc_batch_album_list");a.innerHTML="";if(this.album_ids.length>10){a.style.height="220px";a.style.overflow="auto"}for(var e=0;e<this.album_ids.length;e++){var d=this.album_ids[e];var c=Data.album[d];var b=document.createElement("div");b.id="album_choose_"+c.album_id;var k=(c.doc_url)?c.doc_url+".t.jpg":URL.L+"/tool_menu/album_cover.png";k='<img src="'+k+'" width="20" height="20" alt="" align="absmiddle" style="margin-right:5px"/>';var g;var j=c.title.truncate_nice(25);if(Data.doc[h].album_ids.indexOf(d)>=0){g='<span class="block">'+k+j+' <a href="#" onclick="$(\'doc_batches\').batch.album_del_doc('+d+');return false;">[x]</a></span>'}else{g='<a href="#" class="block" onclick="$(\'doc_batches\').batch.album_add_doc('+d+');return false;">'+k+j+"</a>"}b.innerHTML=g;a.appendChild(b)}};
doc_batches.prototype.album_add_doc=function(a){var b=this;IOL.API.request("album.add.doc",{album_id:a,doc_id:this.doc_id},b)};doc_batches.prototype.album_add_doc_onApi=function(d,b,a,c){if(d){Data.doc[this.doc_id]["album_ids"].push(c.album_id);modal.say(_MSG.saved,{icon:"ok",timeout:1000})}else{modal.complain(b,{},1)}this.album_choose()};doc_batches.prototype.album_del_doc=function(a){var b=this;IOL.API.request("album.del.doc",{album_id:a,doc_id:this.doc_id},b)};doc_batches.prototype.album_del_doc_onApi=function(e,b,a,d){if(e){var c=Data.doc[this.doc_id]["album_ids"].indexOf(d.album_id);if(c>=0){Data.doc[this.doc_id]["album_ids"].splice(c,1)}modal.say(_MSG.saved,{icon:"ok",timeout:500})}else{modal.complain(b,{},1)}this.album_choose()};doc_batches.prototype.album_create=function(){var f=document.fbatch.album_title.value;var d=document.fbatch.album_content.value;if(!f){return}modal.say(MSG.album_creating,{waiting:1});var c=IOL.API.request("album.add",{title:f,content:d,arrback:1});var e=c[0];var b=c[1];if(!e){modal.say(MSG.album_created_nok,{icon:"nok"},{});return}Data.album[b.album.album_id]=b.album;this.album_ids.unshift(b.album.album_id);modal.say(MSG.album_created_ok,{icon:"ok",timeout:500});var a=b.album.album_id;this.album_add_doc(a)};doc_batches.prototype.delete_doc=function(b){if(!confirm(MSG.doc_delete_confirm)){return false}var a=this;IOL.API.request("doc.del",{doc_id:this.doc_id},a)};doc_batches.prototype.doc_del_onApi=function(f,c,b,e){if(f){modal.say(MSG.doc_deleted_ok,{icon:"ok",timeout:500});var d=e.doc_id;var a=[];this.remove_from_batch(d);this.changes_count=0;this.field_changes={};if(Data.doc[d].loc_id&&Data.loc[Data.doc[d].loc_id]){Data.loc[Data.doc[d].loc_id].doc_count--;a.push("loc")}Data.doc[e.doc_id]=undefined;if(typeof this.doc_ondelete=="function"){this.doc_ondelete(e.doc_id,a)}if(this.batch_ids.length){return this.open_next()}else{return this.close()}}else{modal.say(MSG.doc_deleted_nok,{icon:"nok"},1)}};doc_batches.prototype.show_tab=function(c,d){for(var b=0;b<this.tabs.length;b++){var a=this.tabs[b];
$("doc_batch_interface_"+a).style.display=(a==c)?"block":"none";$("doc_batch_tab_"+a).className=(a==c)?"on":""}if(d){d.blur()}this.tab=c;if(c=="album"){this.album_choose()}};doc_batches.prototype.doc_get_onApi=function(g,c,a,f){if(g&&c.doc!=undefined){modal.shutup();if(typeof c.doc.keyword_ids=="array"&&typeof c.keywords=="object"){var b=new Array;for(var d=0;d<c.doc.keyword_ids.length;d++){var e=c.doc.keyword_ids[d];if(c.keywords[e].match(/\s/)){b.push('"'+c.keywords[e]+'"')}else{b.push(c.keywords[e])}}c.doc.keywords=b.join(", ")}else{if(typeof c.doc.keyword_ids=="object"&&typeof c.keywords=="object"){var b=new Array;for(var e in c.doc.keyword_ids){if(c.keywords[e].match(/\s/)){b.push('"'+c.keywords[e]+'"')}else{b.push(c.keywords[e])}}c.doc.keywords=b.join(", ")}else{c.doc.keywords=""}}if(!c.doc.album_ids){c.doc.album_ids=[]}c.doc.is_loaded_for_batch=true;Data.doc[c.doc.doc_id]=c.doc;return this.show_interface()}else{modal.complain(c,{},1);return this.close()}};doc_batches.prototype.save=function(){if(!this.changes_count){return}var a=document.fbatch;if(a.keywords.value!=a.keywords.initial_value){if(a.keywords.value.trim()){var b={doc_id:this.doc_id,keywords:a.keywords.value,replace:true,callback:"doc_add_tag"};return IOL.API.request("doc.add.tag",b,this)}else{var b={doc_id:this.doc_id,keyword_id:"*",callback:"doc_add_tag"};return IOL.API.request("doc.del.tag",b,this)}}var b={doc_id:this.doc_id,title:a.title.value,content:a.content.value,posted_at:calendar_date2time(calendar_get_mysql_date(a.posted_at_date.value)+" "+a.posted_at_time.value),created_at:calendar_get_mysql_date(a.created_at_date.value)+" "+a.created_at_time.value,share:a.share.value,com:_form_radio_get_value(a.com),tag:_form_radio_get_value(a.tag),tagme:_form_radio_get_value(a.tagme),license:_form_radio_get_value(a.license)};modal.say(_MSG.saving,{icon:"wait"});IOL.API.request("doc.set",b,this)};doc_batches.prototype.doc_add_tag_onApi=function(g,b,a,f){if(g){var e=document.fbatch;if(f.replace){var d=[];for(var c=0;c<b.keywords.length;c++){d.push(b.keywords[c].title)
}e.keywords.value=d.join(", ")}else{e.keywords.value=""}Data.doc[this.doc_id]["keywords"]=e.keywords.value;e.keywords.initial_value=e.keywords.value;return this.save()}else{modal.complain(b,{},1);this.close()}};doc_batches.prototype.doc_set_onApi=function(e,b,a,d){if(e){modal.say(_MSG.saved,{icon:"ok",timeout:1000});for(var c in d){Data.doc[this.doc_id][c]=d[c]}Data.doc[this.doc_id]["created_at"]=b.doc.created_at;Data.doc[this.doc_id]["posted_at"]=b.doc.posted_at;this.save_initial_values();if(typeof this.doc_onupdate=="function"){this.doc_onupdate(d.doc_id)}else{IOL.debug("no CALL")}if($("doc_batch_go_next_cb").checked){this.open_next()}}else{modal.complain(b,{},1);this.close()}};doc_batches.prototype.show_thumbnail=function(){var c=this.doc;var d=$("doc_batch_interface_thumb");d.update();if(c.embed=="mp3"||c.embed=="flv"){var b=new Element("div",{id:"doc_batch_interface_player"});d.appendChild(b);if(c.embed=="mp3"){var a={file:c.embed_url,width:240,height:70,showeq:"true"};new mediaplayer("mp3","doc_batch_interface_player",a).build()}else{var a={file:c.embed_url,image:c.doc_url+".240.jpg",width:c.wh[240][0],height:c.wh[240][1],showeq:"true"};new mediaplayer("flv","doc_batch_interface_player",a).build()}}else{if(c.embed=="jpg"){d.update('<img src="'+c.doc_url+'.m.jpg" width="'+c.wh.m[0]+'" height="'+c.wh.m[1]+'" alt=""/>')}else{d.update('<p align="center"><img src="'+c.doc_url+'.t.jpg" width="75" height="75" alt=""/></p>')}}};function _hide_flash_players(a){if($("album_player")){$("album_player").style.display=(a)?"block":"none"}};