var repository_listing={};var cached_client_id={};var file_extensions={};var new_filename="";var cached_id;var cached_repo_id;var repository_client=(function(){var a="2.0";var d=(10*2);function b(){alert(a)}function c(h,f){if(YAHOO.env.ua.ie==6){var g=document.getElementById("file-picker-"+h);g.style.width=f}}function e(){this.create_filepicker=function(o){var m=(YAHOO.env.ua.ie&&document.compatMode=="BackCompat");var j=(YAHOO.env.ua.ie==6||(YAHOO.env.ua.ie==7&&m));var n={label:fp_lang.listview,value:"l",onclick:{fn:repository_client.view_as_list,obj:o}};var f={label:fp_lang.thumbview,value:"t",onclick:{fn:repository_client.view_as_icons,obj:o}};var h=document.createElement("DIV");h.id="file-picker-"+o;h.className="file-picker";this.client_id=o;document.body.appendChild(h);this.filepicker=new YAHOO.widget.Panel("file-picker-"+o,{draggable:true,close:true,underlay:"none",zindex:666666,xy:[50,YAHOO.util.Dom.getDocumentScrollTop()+20]});var l="";this.filepicker.client_id=o;this.filepicker.setHeader(fp_lang.title);this.filepicker.setBody('
');this.filepicker.beforeRenderEvent.subscribe(function(){YAHOO.util.Event.onAvailable("layout-"+o,function(){l=new YAHOO.widget.Layout("layout-"+o,{height:480,width:700,units:[{position:"top",height:32,resize:false,body:'
',gutter:"2"},{position:"left",width:200,resize:true,scroll:true,body:'',gutter:"0 5 0 2",minWidth:150,maxWidth:300},{position:"center",body:'
',scroll:true,gutter:"0 2 0 0"}]});l.render()})});var g=new YAHOO.util.Resize("file-picker-"+o,{handles:["br"],autoRatio:true,status:true,minWidth:680,minHeight:400});c(o,"680px");g.on("resize",function(q){var r=q.height;var p=this.header.offsetHeight;var t=(r-p);var s=(m)?t:t-d;YAHOO.util.Dom.setStyle(this.body,"height",s+"px");c(this.client_id,"680px");if(j){this.sizeUnderlay();this.syncIframe()}l.set("height",s);l.set("width",(q.width-d));l.resize()},this.filepicker,true);repository_client.fp[o].viewbar=new YAHOO.widget.ButtonGroup({id:"btngroup-"+o,name:"buttons",disabled:true,container:"repo-viewbar-"+o});repository_client.fp[o].viewbar.addButtons([f,n]);this.print_listing();this.filepicker.render()};this.init_search=function(){var f=document.getElementById("search-div-"+this.client_id);f.innerHTML='";var g=new YAHOO.util.Element("search-btn-"+this.client_id);g.client_id=this.client_id;var h=new YAHOO.util.Element("search-input-"+this.client_id);h.client_id=this.client_id;g.fnSearch=function(o){var m=new YAHOO.util.Element("search-input-"+this.client_id);var j=m.get("value");var n=repository_client.fp[this.client_id];var p=[];p.s=j;p.env=n.env;p.accepted_types=n.accepted_types;p.sesskey=moodle_cfg.sesskey;p.ctx_id=fp_config.contextid;p.client_id=this.client_id;repository_client.loading(this.client_id,"load");var l=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=gsearch",this.search_cb,repository_client.postdata(p))};g.on("contentReady",function(){g.on("click",this.fnSearch,this.input_keyword)});g.search_cb={success:function(p){var n=repository_client.parse_json(p.responseText,"global_search_cb");var j=new YAHOO.util.Element("panel-"+n.client_id);if(!n.list||n.list.length<1){j.get("element").innerHTML=fp_lang.noresult;return}var m=repository_client.fp[n.client_id];m.view_staus=0;m.fs=n.list;if(n.gsearch){m.gsearch=true}if(m.view_staus){repository_client.view_as_list(n.client_id,n.list)}else{repository_client.view_as_icons(n.client_id,n.list)}var l=new YAHOO.util.Element("search-input-"+n.client_id);l.set("value","")}};h.on("contentReady",function(){var j=document.getElementById("search-input-"+this.client_id);var l=new YAHOO.util.KeyListener(j,{keys:13},{fn:function(){this.fnSearch()},scope:g,correctScope:true});l.enable()})};this.print_listing=function(){var f=new YAHOO.util.Element("repo-list-"+this.client_id);f.set("innerHTML","");f.on("contentReady",function(){this.init_search();for(var m in repository_listing[this.client_id]){var l=repository_listing[this.client_id][m];var o=false;if(this.env=="editor"&&this.accepted_types!="*"){if(l.supported_types!="*"){for(var h in l.supported_types){if(mdl_in_array(l.supported_types[h],this.accepted_types)){o=true}}}}else{o=true}if(l.supported_types=="*"||o){var g=document.createElement("li");g.id="repo-"+this.client_id+"-"+l.id;var n=document.createElement("img");n.src=l.icon;n.width="16";n.height="16";var p=document.createElement("a");p.href="###";p.id="repo-call-"+this.client_id+"-"+l.id;p.appendChild(n);p.className="fp-repo-name";p.innerHTML+=" "+l.name;p.onclick=function(){var s=new RegExp("repo-call-(\\w+)-(\\d+)","i");var j=this.id.match(s);var v=j[1];var r=j[2];for(var u in repository_listing[v]){var t="repo-call-"+v+"-"+u;var q=document.getElementById(t);if(q){q.style.background="transparent"}}this.style.background="#CCC";repository_client.req(v,r,"")};g.appendChild(p);f.appendChild(g);l=null}}},this,true)};this.show=function(){this.print_listing();var f=new YAHOO.util.Element("panel-"+this.filepicker.client_id);f.get("element").innerHTML="";this.filepicker.show()};this.hide=function(){this.filepicker.hide()}}e.fp={};return e})();repository_client.req=function(g,f,d,c){repository_client.loading(g,"load");this.fp[g].viewbar.set("disabled",false);var b=repository_client.fp[g];var e=[];e.p=d;e.env=b.env;e.sesskey=moodle_cfg.sesskey;e.ctx_id=fp_config.contextid;e.client_id=g;e.repo_id=f;if(!!c){e.page=c}e.accepted_types=b.accepted_types;var a=YAHOO.util.Connect.asyncRequest("POST",moodle_cfg.wwwroot+"/repository/ws.php?action=list",this.req_cb,this.postdata(e))};repository_client.req_cb={success:function(d){var c=repository_client.parse_json(d.responseText,"req_cb");var b=repository_client.fp[c.client_id];b.viewbar.set("disabled",false);var a=new YAHOO.util.Element("panel-"+c.client_id);if(c&&c.e){a.get("element").innerHTML=c.e;return}b.fs=c;if(!c){return}else{if(c.msg){repository_client.print_msg(c.msg)}else{if(c.iframe){repository_client.view_iframe(c.client_id)}else{if(c.login){b.viewbar.set("disabled",true);repository_client.print_login(c.client_id,c)}else{if(c.list){if(b.view_status){repository_client.view_as_list(c.client_id,c.list)}else{repository_client.view_as_icons(c.client_id,c.list)}}}}}}}};repository_client.view_iframe=function(c){var a=repository_client.fp[c].fs;var b=new YAHOO.util.Element("panel-"+c);b.get("element").innerHTML='