var application_bridge=new Class({Implements:Events,REPORTS_CONFIG:{str_frame_menu:"reportmenu",str_frame_form:"reportform"},SEARCH_CONFIG:{arr_frame_root_path:[],arr_frame_sub_path:[],str_form_url:"",str_input_selector:"",str_form_selector:""},CONDITION_WAIT_DELAY:100,TAB_APPLICATION_ID:"tab_application",str_iframe_id:null,obj_tabs:null,initialize:function(B,A){this.str_iframe_id=B;this.obj_tabs=A;this.add_listener_if_exists($(document.body).getElement(".media-reports .reports"),"click",this._load_report.bindWithEvent(this));$(document.body).getElements(".tab").addEvent("click",this._event_custom_application_close.bindWithEvent(this));$(window).addEvent("resize",this.resize_custom_application_overlay.bindWithEvent(this))},get_frame:function(F){var H=F?$splat(F):[];var G=$(this.str_iframe_id);if(H.length==0){return G.contentWindow}var I=G;try{for(var D=0,B=H.length;D<B;D++){var C=D==0?"contentWindow":"window";var A=H[D];I=I[C].frames[A]}}catch(E){I=null}return I},switch_tab:function(A){return this.obj_tabs.switch_tab(A)},set_frame_url:function(C,D){var B=this.get_frame(C);try{if(B){B.document.location=D;return true}}catch(A){this.set_frame_url.delay(500,this,[C,D])}return false},add_listener_if_exists:function(A,B,D){var C=$(A);if(C&&!C.match(".inactive")){C.addEvent(B,D)}},run_when_condition_met:function(C,D){var B=false;try{B=C()}catch(A){B=false}if(B){D()}else{this.run_when_condition_met.delay(this.CONDITION_WAIT_DELAY,this,[C,D])}},_load_report:function(A){var B=$(A.target).get("rel");if(B){A.stop();var C=B.split("|");if(C.length==2){var D=C[0];if(D==this.str_iframe_id){B=C[1]}else{return }}this.load_report(B)}},load_report:function(A){this.switch_tab(this.TAB_APPLICATION_ID);this.run_when_condition_met((function(B){return this.get_frame(this.REPORTS_CONFIG.str_frame_menu)&&$(this.get_frame(this.REPORTS_CONFIG.str_frame_menu).document.body).getElement("a")&&this.get_frame(this.REPORTS_CONFIG.str_frame_form)&&this.get_frame(this.REPORTS_CONFIG.str_frame_form).document.location}).bind(this),(function(F){var H=this.get_frame(this.REPORTS_CONFIG.str_frame_menu);var E=$(H.document.body).getElement("a[href="+F+"]");if(E){try{E.onclick()}catch(D){}var G=E.get("href");if(!G.contains("http://")){var C=this.get_frame(this.REPORTS_CONFIG.str_frame_menu).location;var I=C.protocol+"//"+C.host+"/";if(G.charAt(0)!="/"){var B=C.pathname;B=B.replace(/(\/[a-zA-Z0-9]+\.[a-zA-Z0-9]{3,4})$/,"");I+=B+"/"}I+=G;G=I}this.set_frame_url(E.get("target"),G)}}).bind(this,A))},open_reports:function(){this.switch_tab(this.TAB_APPLICATION_ID)},load_search:function(A){A.stop();this.switch_tab(this.TAB_APPLICATION_ID);this.run_when_condition_met(this.get_frame.bind(this,this.SEARCH_CONFIG.arr_frame_root_path[0]),(function(){var B=$(A.target).getElement("#search").value;this.set_frame_url(this.SEARCH_CONFIG.arr_frame_root_path,this.SEARCH_CONFIG.str_form_url);this._load_search(B)}).bind(this))},_load_search:function(B){try{var D=this.get_frame(this.SEARCH_CONFIG.arr_frame_sub_path);var C=$(D.document.body).getElement(this.SEARCH_CONFIG.str_input_selector);C.set("value",B)}catch(A){this._load_search.delay(this.CONDITION_WAIT_DELAY,this,B)}try{$(D.document.body).getElement(this.SEARCH_CONFIG.str_form_selector).submit(true)}catch(A){}this.fireEvent("search",B)},show_custom_application_overlay:function(A,B){var C=A?"block":"none";$("custom_application_overlay_iframe").setStyle("display",C);$("custom_application_overlay_iframe").set("src",B?B:"");if(A){this.resize_custom_application_overlay()}},is_custom_application_overlay_visible:function(){if($("custom_application_overlay_iframe").getStyle("display")=="block"){return true}return false},resize_custom_application_overlay:function(){var A=$(document.body).getElement(".application_iframe");if(A){var B=A.getCoordinates();$("custom_application_overlay_iframe").setStyles({top:B.top,left:B.left,width:B.width,height:B.height-(Browser.Engine.trident?2:0)});$("custom_application_overlay_iframe").width=B.width;$("custom_application_overlay_iframe").height=B.height}},_event_custom_application_close:function(A){this.show_custom_application_overlay(false)}});