Ext.ns("Highline.main");

Ext.Panel.prototype.setTabTip = function(msg) {
  var tabPanel = this.findParentByType(Ext.TabPanel);
  if (tabPanel) {
    var tabEl = Ext.fly(tabPanel.getTabEl(this).id);
    if (tabEl) {
      var tsTxt = tabEl.child('span.x-tab-strip-text', true);
    if (tsTxt)
      tsTxt.qtip = msg.toString();
    }
  }
};

Highline.main.Util = {};

Highline.main.Util.iconnewer=function()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.newer)
    {
        contentframe.low.newer();
    }
    else if (contentframe.middle && contentframe.middle.newer)
    {
        contentframe.middle.newer();
    }
    else
    {
        Ext.Msg.alert("Not Supported","New is not supported for this page");
    }
}
Highline.main.Util.earlyLink=function(type,title)
{
    Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListActive.do?companyType='+type+'&tp=EARLY',title,null,true);
}
Highline.main.Util.earlyCommonLink=function(type,title)
{
    Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListCommonActive.do?companyType='+type+'&tp=EARLY',title,null,true);
}
Highline.main.Util.currentCommonLink=function(type,title)
{
    Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListCommonActive.do?companyType='+type+'&tp=CURRQ',title,null,true);
}
Highline.main.Util.singleHelpLink=function(id,entityType,truepopup)
{
    if (truepopup)
        {
    window.open('/bats/showSingleDefinition.do?'+Ext.urlEncode({id:id,entityType:entityType}),"help", 'menubar=yes,toolbar=yes,location=yes,width=780,height=500,scrollbars=yes,resizable=yes,directories=yes');
        }
        else
            {
    Highline.main.Util.popupWindow(240,40,800,200,'/bats/showSingleDefinition.do?'+Ext.urlEncode({id:id,entityType:entityType}),"Definition Help", 'help','',true);
            }
}
Highline.main.Util.liHelpLink=function(params)
{

     Highline.main.Util.popupNoBarWindow(240,100,800,300,'/bats/reports/lineItemInfo.jsp?'+Ext.urlEncode(params),"Line Item Info", 'lihelp','',false);

}
Highline.main.Util.printWindow=function(href)
{

      var printwindow = window.open(href ,'printWindow','menubar=yes,toolbar=yes,location=yes,width=600,height=440,scrollbars=yes,resizable=yes,directories=yes');
  printwindow.print();

//             var printiframe=new Ext.ux.ManagedIframePanel({loadMask:true,autoLoad:false,frameStyle:'background-color:white',frame:false,border:false,defaultSrc:href});
//        printiframe.on("documentloaded",Highline.main.Util.printIFrame);
//        printiframe.load();
//    var mywin=new Ext.Window({
//        constrain:true,
//        title:'Printer Friendly',
//        x:200,
//        y:100,
//        width:475,
//        height:400,
//        layout:'fit',
//        items:printiframe
//    });
//    mywin.show();
}
Highline.main.Util.printIFrame=function(obj)
{
    obj.print();
}

Highline.main.Util.popupWindow=function(x,y,width,height,href,title,name,tabicon,printer)
{
        var existpopup=Ext.getCmp(name+"popup");
        if (existpopup)
            {
                existpopup.close();
            }
    var printbutton=new Ext.Button({
        name:'iconprinter',
        hidden:(!printer),
        tooltip:'Print',
        cls:'x-btn-icon bmenu',
        icon:'/banking/images/printer_icon.gif',
        handler:Highline.main.Util.iconprinter
        });
    var icontoolbar=new Ext.Toolbar({
        height:25,
        hideMode:'display',
        items:[{
            xtype:'tbfill'
        }
        ,printbutton
        ]
        });
        if (!printer)
            {
                icontoolbar.setVisible(false)
            }
    var iframe=new Ext.ux.ManagedIframePanel({
        draggable:false,
        tabTip:title,
        loadMask:true,
        closable:true,
        defaultSrc:href,
        id:name+"tab",
        tbar:icontoolbar
    });
    if (tabicon){
        iframe.setIconClass(tabicon);
    }
    printbutton.iframe=iframe;
    var mywin=new Ext.Window({
        constrain:true,
        x:x,
        y:y,
        title:title,
        width:width,
        height:height,
        layout:'fit',
        items:iframe,
        iframe:iframe,
        id:name+'popup'
    });
    mywin.show();
    return mywin;
}
Highline.main.Util.popupNoBarWindow=function(x,y,width,height,href,title,name,tabicon)
{
        var existpopup=Ext.getCmp(name+"popup");
        if (existpopup)
            {
                existpopup.close();
            }
    var iframe=new Ext.ux.ManagedIframePanel({
        draggable:false,
        tabTip:title,
        closable:true,
        defaultSrc:href,
        id:name+"tab"
    });
    if (tabicon){
        iframe.setIconClass(tabicon);
    }
    var mywin=new Ext.Window({
        constrain:true,
        x:x,
        y:y,
        title:title,
        width:width,
        height:height,
        layout:'fit',
        items:iframe,
        iframe:iframe,
        id:name+'popup'
    });
    mywin.show();
    return mywin;
}
Highline.main.Util.currentLink=function(type,title)
{
    Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListActive.do?companyType='+type+'&tp=CURRQ',title,null,true);
}
Highline.main.Util.ptbLink=function(is_early,slash_date)
{
     Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListActivePTB.do?companyType=PTB&early='+is_early+'&date='+slash_date,'Publicly Traded Banking Companies',null,true);
}
Highline.main.Util.reitLink=function(is_early,slash_date)
{
     Highline.Util.getTop().Highline.main.Util.newTab('/bats/external/ListActiveREIT.do?companyType=REIT&early='+is_early+'&date='+slash_date,'Publicly Traded REITs',null,true);
}
Highline.main.Util.showIcons=function(name)
{
    var currenttab=Ext.getCmp("mainwindow").getActiveTab();//.getTopToolbar().items;
    Highline.main.Util.showIconsTab(name,currenttab);
}
Highline.main.Util.showIconsTab=function(name,mytab)
{
    Highline.main.Util.clearIconsTab(mytab);
    var iconslist=name.split(",");
    var baritems=mytab.getTopToolbar().items;
    if (name!="")
        {
    for (var i=0;i<iconslist.length;i++)
    {
                Highline.main.Util.showIcon("icon"+iconslist[i],baritems);
            }
    }
        }
Highline.main.Util.showIcon=function(name,items)
{
    var icon=items.find(function(item){
        if (item.name==name)
        {
            return true;
        }
        return false;
    });
    if (icon!=null) icon.show();
}
Highline.main.Util.clearIcon=function(name,items)
{
    var icon=items.find(function(item){
        if (item.name==name)
        {
            return true;
        }
        return false;
    });
    if (icon!=null)
        icon.hide();
}
Highline.main.Util.clearIconsTab=function(mytab)
{
    var baritems=mytab.getTopToolbar().items;
    Highline.main.Util.clearIcon("iconnewer",baritems);
    Highline.main.Util.clearIcon("icongrapher",baritems);
    Highline.main.Util.clearIcon("iconprinter",baritems);
    Highline.main.Util.clearIcon("iconexporter",baritems);
    Highline.main.Util.clearIcon("iconopener",baritems);
    Highline.main.Util.clearIcon("iconsaver",baritems);
    Highline.main.Util.clearIcon("iconpdfer",baritems);
    Highline.main.Util.clearIcon("iconpdferchart",baritems);
    Highline.main.Util.clearIcon("iconhelper",baritems);
    Highline.main.Util.clearIcon("iconhires",baritems);
    Highline.main.Util.clearIcon("iconstock",baritems);
    Highline.main.Util.clearIcon("iconbblite",baritems);
}

Highline.main.Util.clearIcons=function ()
{
    var currenttab=Ext.getCmp("mainwindow").getActiveTab();
    Highline.main.Util.clearIconsTab(currenttab);
    //    current.getTopToolbar().items;
    //    Highline.main.Util.clearIcon("iconnewer",currentbaritems);
    //    Highline.main.Util.clearIcon("icongrapher",currentbaritems);
    //    Highline.main.Util.clearIcon("iconprinter",currentbaritems);
    //    Highline.main.Util.clearIcon("iconexporter",currentbaritems);
    //    Highline.main.Util.clearIcon("iconopener",currentbaritems);
    //    Highline.main.Util.clearIcon("iconsaver",currentbaritems);
}
Highline.main.Util.closeTab=function(name)
{
    var mainwindow=Ext.getCmp("mainwindow");
        if (name)
    {
        var existframe=Ext.getCmp(name+"tab");    
        if (existframe)
        {
            existframe.on("beforeremove",function(p){return true});
            mainwindow.remove(existframe);
        }
    }
}
Highline.main.Util.nextTab=function()
{
    var mainwindow=Ext.getCmp("mainwindow");
    var activetab=mainwindow.getActiveTab();
    var tabitems=mainwindow.items.items;
    for (var i=0;i<tabitems.length;i++)
        {
            var thistab=tabitems[i];
            if (thistab==activetab)
                {
                    var tabtoactivate=i+1;
                    if (tabtoactivate >= tabitems.length)
                        {
                            tabtoactivate=0;
                        }
                        mainwindow.activate(tabitems[tabtoactivate]);
                        
                }
        }
}
Highline.main.Util.previousTab=function()
{
    var mainwindow=Ext.getCmp("mainwindow");
    var activetab=mainwindow.getActiveTab();
    var tabitems=mainwindow.items.items;
    for (var i=0;i<tabitems.length;i++)
        {
            var thistab=tabitems[i];
            if (thistab==activetab)
                {
                    var tabtoactivate=i-1;
                    if (tabtoactivate < 0)
                        {
                            tabtoactivate=tabitems.length-1;
                        }
                         mainwindow.activate(tabitems[tabtoactivate]);
                        
                }
        }
};

Highline.main.Util.findTab=function(name)
{
   var existframe=Ext.getCmp(name+"tab");    
   return existframe;
};

Highline.main.Util.newTab=function(href,title,name,switchto,tabicon,singleonly)
{
    var iframe;
    var insertpoint=0;
    var printbutton=new Ext.Button({name:'iconprinter',hidden:true,tooltip:'Print',cls:'x-btn-icon bmenu',icon:'/banking/images/printer_icon.gif',handler:Highline.main.Util.iconprinter});
    var icontoolbar=new Ext.Toolbar({height:25,hideMode:'visibility',items:[{xtype:'tbfill'}
            ,new Ext.Button({name:'iconnewer',hidden:true,tooltip:'Create New',cls:'x-btn-icon bmenu',icon:'/banking/images/newer_icon.gif',handler:Highline.main.Util.iconnewer})
            ,new Ext.Button({name:'iconopener',hidden:true,tooltip:'Open',cls:'x-btn-icon bmenu',icon:'/banking/images/opener_icon.gif',handler:Highline.main.Util.iconopener})
            ,new Ext.Button({name:'iconsaver',hidden:true,tooltip:'Save',cls:'x-btn-icon bmenu',icon:'/banking/images/saver_icon.gif',handler:Highline.main.Util.iconsaver})
            ,printbutton
            ,new Ext.Button({name:'iconexporter',hidden:true,tooltip:'Export To Excel',cls:'x-btn-icon bmenu',icon:'/banking/images/exporter_icon.gif',handler:Highline.main.Util.iconexporter})
            ,new Ext.Button({name:'icongrapher',hidden:true,tooltip:'Graph Settings',cls:'x-btn-icon bmenu',icon:'/banking/images/grapher_icon.gif',handler:Highline.main.Util.icongrapher})
            ,new Ext.Button({name:'iconpdfer',hidden:true,tooltip:'Export to PDF',cls:'x-btn-icon bmenu',icon:'/banking/images/pdf_icon.gif',handler:Highline.main.Util.iconpdfer})
            ,new Ext.Button({name:'iconpdferchart',hidden:true,tooltip:'Export to PDF',cls:'x-btn-icon bmenu',icon:'/banking/images/pdf_icon.gif',handler:Highline.main.Util.iconpdferchart})
            ,new Ext.Button({name:'iconhelper',hidden:true,tooltip:'Report Help',cls:'x-btn-icon bmenu',icon:'/banking/images/helper_icon.gif',handler:Highline.main.Util.iconhelper})
            ,new Ext.Button({name:'iconstock',hidden:true,tooltip:'Stock Chart',cls:'x-btn-icon bmenu',icon:'/bats/images/graph_icon.jpg',handler:Highline.main.Util.iconstock})
             ,new Ext.Button({name:'iconbblite',hidden:true,tooltip:'BB Lite',cls:'x-btn-icon bmenu',icon:'/bats/briefingbook/image/BriefingBook2.gif',handler:Highline.main.Util.iconbblite})
			,new Ext.Button({name:'iconhires',hidden:true,tooltip:'Save Hi-Resolution Map',cls:'x-btn-icon bmenu',icon:'/banking/images/map_icon.gif',handler:Highline.main.Util.iconhires})
        ]});
    var mainwindow=Ext.getCmp("mainwindow");
    var createnew=true;
    if (name)
    {
        var existframe=Ext.getCmp(name+"tab");    
        if (existframe)
        {
            if (!singleonly)
                {
            mainwindow.remove(existframe);
            //iframe.close();
//            iframe.setSrc(href,false);
//            iframe.setTitle(title);
//            Highline.main.Util.clearIconsTab(iframe);
//            if (tabicon){Ext.get(mainwindow.getTabEl(iframe)).child('.x-tab-strip-text').replaceClass(iframe.iconCls,tabicon);
//            iframe.setIconClass(tabicon);}
                }
        else
            {
                iframe=existframe;
                createnew=false;
            }

        }
        if (createnew)
            {
            iframe=new Ext.ux.ManagedIframePanel({draggable:false,tabTip:title,title:title,closable:true,
                defaultSrc:href,id:name+"tab",tbar:icontoolbar});
            if (tabicon){iframe.setIconClass(tabicon);}
            mainwindow.insert(0,iframe);
            }
    }
    else
    { 
        iframe=new Ext.ux.ManagedIframePanel({draggable:false,tabTip:title,title:title,closable:true,
            defaultSrc:href,tbar:icontoolbar});
        if (tabicon){iframe.setIconClass(tabicon);}
        mainwindow.insert(0,iframe);
    }
    if (!title)
    {
        iframe.setTitle("Loading...");
           
        iframe.on("documentloaded",function(){
            this.setTitle(this.getFrameWindow().document.title);
        },iframe);
    }
    printbutton.iframe=iframe;
    if (switchto==false)
      Ext.get(Ext.getCmp("mainwindow").getTabEl(iframe)).frame("ffffff",1,{duration:2});
    else mainwindow.activate(iframe);
    //var currenttab=mainwindow.getActiveTab();
    //iframe.show();
    // mainwindow.activate(iframe);
    //       mainwindow.activate(currenttab);
    //tab=mainwindow.geiframe.render(mainwindow);
    //iframe.setSrc(href,false);
    //iframe.fireEvent('activate', iframe);
    // iframe.doLayout();
    //iframe.render();

}
Highline.main.Util.logout=function()
{
   // top.location.href="/bats/Logout.do?url=/";
   top.location.href="/highline/c/portal/logout";
}
clearIcons=Highline.main.Util.clearIcons;
showIcons=Highline.main.Util.showIcons;
newTab=Highline.main.Util.newTab;
closeTab=Highline.main.Util.closeTab;
popupWindow=Highline.main.Util.popupWindow;
Highline.main.Util.beforeremove=function(c,p)
{
    var contentframe=p.getFrameWindow();
    if (!contentframe)
        return true;
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.Title && contentframe.Title.beforeclose)
    {
        var returned=contentframe.Title.beforeclose();
        return returned;
    }
    else if (contentframe.low && contentframe.low.beforeclose)
    {
        contentframe.low.beforeclose();
    }
    else if (contentframe.middle && contentframe.middle.beforeclose)
    {
        contentframe.middle.beforeclose();
    }
    return true;
}
Highline.main.Util.iconprinter=function ()
{
    var contentframe=this.iframe.getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.printer)
    {
        contentframe.low.printer();
    }
    else if (contentframe.middle && contentframe.middle.printer)
    {
        contentframe.middle.printer();
    }
    else if (contentframe.printer)
    {
        contentframe.printer();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Printing is not supported for this page");
    }
}

Highline.main.Util.iconhires=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.hires)
    {
        contentframe.low.hires();
    }
    else if (contentframe.middle && contentframe.middle.hires)
    {
        contentframe.middle.hires();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Hiresing is not supported for this page");
    }
}
Highline.main.Util.iconpdferchart=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
   //var contentframe=this.iframe.getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.pdfer)
    {
        contentframe.low.pdferchart();
    }
    else if (contentframe.middle && contentframe.middle.pdferchart)
    {
        contentframe.middle.pdferchart();
    }
    else if (contentframe.pdferchart)
    {
        contentframe.pdferchart();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Exporting to PDF is not supported for this page");
    }
}

Highline.main.Util.iconpdfer=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
	this.loadMask = new Ext.LoadMask(Ext.getCmp("mainwindow").getActiveTab().id,{msg: 'Please wait...'});
	if( this.loadMask ){
      this.loadMask.show();
    }
    
	var reportId;
    var viewValue = "0";
    var pageSize;
    var pageOrientation;
    if (contentframe.low && contentframe.low.pdfer && contentframe.low.getReportID){
      reportId = contentframe.low.getReportID(contentframe.low.isNav4);
      if( contentframe.low.getViewValue ){
        viewValue = contentframe.low.getViewValue(contentframe.low.isNav4); // Company
      }
      else if( contentframe.low.getReportView ) {
        viewValue = contentframe.low.getReportView(contentframe.middle.document.forms[0]); // Market
        pageSize=	contentframe.low.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.low.getPageOrientation(reportId,viewValue);
      }
      else {
        viewValue=0;
        pageSize=	contentframe.low.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.low.getPageOrientation(reportId,viewValue);
      }
    }
    else if (contentframe.middle && contentframe.middle.pdfer && contentframe.middle.getReportID ){
      reportId = contentframe.middle.getReportID(contentframe.middle.isNav4);
      if( contentframe.middle.getViewValue ){
        viewValue = contentframe.middle.getViewValue(contentframe.low.isNav4); // Company
      }
      else if( contentframe.middle.getReportView ) {
        viewValue = contentframe.middle.getReportView(contentframe.middle.document.forms[0]); // Market
        pageSize=	contentframe.middle.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.middle.getPageOrientation(reportId,viewValue);
      }
      else {
        viewValue=0;
		pageSize=	contentframe.middle.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.middle.getPageOrientation(reportId,viewValue);
      }
    }
    else if (contentframe.pdfer && contentframe.getReportID ){
      reportId = contentframe.getReportID(contentframe.isNav4);
      if( contentframe.getViewValue ){
        viewValue = contentframe.getViewValue(contentframe.low.isNav4); // Company
        pageSize=	contentframe.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.getPageOrientation(reportId,viewValue);
      }
      else if( contentframe.getReportView ){
        viewValue = contentframe.getReportView(contentframe.middle.document.forms[0]); // Market
        pageSize=	contentframe.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.getPageOrientation(reportId,viewValue);
      }
      else {
        viewValue=0;
        pageSize=	contentframe.getPageSize(reportId,viewValue);
        pageOrientation=contentframe.getPageOrientation(reportId,viewValue);
      }
    }
    else {
      Ext.Msg.alert("Not Supported","Exporting to PDF is not supported for this page");
      if( this.loadMask ){
        this.loadMask.hide();
      }
      return;
    }
	
	/*Ext.Ajax.request({
      url: '/bats/briefbook/JSONReportList.do',
      scope: this,          
      success: function(result, request){
      	//var resultsObj = Ext.util.JSON.decode(result.responseText); 
      	var resultsObj = eval('(' + result.responseText + ')');
		var iViewValue = parseInt(viewValue);
		var reports = resultsObj.reports;
		var report = reports[0];		
        var pageSize;
        if( report.pageSize && report.pageSize[iViewValue] ){
          pageSize = report.pageSize[iViewValue];
        }
        else {  
          pageSize = 'LETTER';
        }  
          
        var pageOrientation;
        if( report.pageOrientation && report.pageOrientation[iViewValue] ){
          pageOrientation = report.pageOrientation[iViewValue];
        }
        else {
          pageOrientation = 'PORTRAIT';
        }  */
        
        if( this.loadMask ){
          this.loadMask.hide();
        }        

        // This just creates a window to wrap the login form. 
        // The login object is passed to the items collection.       
        var win = new Ext.Window({
          layout:'fit',
          width:265,
          height:120,
          closable: false,
          resizable: false,
          plain: true,
          border: false,
          title: 'PDF Page Settings',
          defaults: {
	        bodyStyle:'margin:0px,0px,0px,0px; background:#F0F0F0;'
          },
          items: [          
            new Ext.Panel({
               layout:'form',
               labelPad:25,
               bodyStyle: 'margin:30px,30px,30px,30px; background:#F0F0F0;',
               border: false,
               items:[{
                 xtype: 'combo',            
                 name: 'pageSize',
                 //id: 'PDFPageSize',
                 width:120,
                 fieldLabel:'&nbsp;&nbsp;Page Size',
                 boxLabel:'Page Size',     
                 store : new Ext.data.SimpleStore({
                   fields: ['value','text'],
                   data: [['LETTER','Letter'],['LEGAL','Legal'],['CUSTOM','Report Default']]
                 }),
                 valueField: 'value',
                 displayField: 'text',
                 typeAhead: true,	
                 mode: 'local',
                 triggerAction:'all',
                 emptyText:'Page Size...',
                 selectOnFocus:true,
                 listWidth: 120,
                 height:   30,
                 labelSeparator:'',
                 value: pageSize      	  
               },
               {
                 xtype: 'combo',            
                 name: 'orientation',
                 //id: this.id+'orientation',
                 width:120,
                 fieldLabel:'&nbsp;&nbsp;Orientation',
                 boxLabel:'Page Orientation',     
                 store : new Ext.data.SimpleStore({
                   fields: ['value','text'],
                   data: [['LANDSCAPE','Landscape'],['PORTRAIT','Portrait'],['CUSTOM','Report Default']]
                 }),
                 valueField: 'value',
                 displayField: 'text',
                 typeAhead: true,	
                 mode: 'local',
                 triggerAction:'all',
                 emptyText:'Page Size...',
                 selectOnFocus:true,
                 listWidth: 120,
                 height:   30,
                 labelSeparator:'',
                 value: pageOrientation    	  
               }],
               buttonAlign: 'center',
               buttons:[{
                 text: 'OK',
                 handler: function(btn,e){
                   var pageSize = this.ownerCt.items.get(0).getValue();
                   if( pageSize && pageSize === "" ){
                      pageSize = null;
                   }
                   
                   var orientation = this.ownerCt.items.get(1).getValue();
                   if( orientation && orientation === "" ){
                      orientation = null;
                   }
 
                   if (contentframe.low && contentframe.low.pdfer){
                     contentframe.low.pdfer(pageSize,orientation);
                   }
                   else if (contentframe.middle && contentframe.middle.pdfer){
                     contentframe.middle.pdfer(pageSize,orientation);
                   }
                   else if (contentframe.pdfer){
                     contentframe.pdfer(pageSize,orientation);
                   }
                   else {
                     Ext.Msg.alert("Not Supported","Exporting to PDF is not supported for this page");
                   }
                   btn.ownerCt.ownerCt.close();
                 }
               },
               {
                 text: 'Cancel',
                 handler: function(btn,e){
                    btn.ownerCt.ownerCt.close();
                 }
               }]
            })
          ]
	    });
	    win.show();      	
  /*    },
      failure: function(result, request){
        if( this.loadMask ){
          this.loadMask.hide();
        }              
      },
      params: { reportid: reportId }
    });*/
}
Highline.main.Util.iconstock=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
   //var contentframe=this.iframe.getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.stock)
    {
        contentframe.low.stock();
    }
    else if (contentframe.middle && contentframe.middle.stock)
    {
        contentframe.middle.stock();
    }
    else if (contentframe.stock)
    {
        contentframe.stock();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Stock is not supported for this page");
    }
}
Highline.main.Util.iconbblite=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
   //var contentframe=this.iframe.getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.bblite)
    {
        contentframe.low.bblite();
    }
    else if (contentframe.middle && contentframe.middle.bblite)
    {
        contentframe.middle.bblite();
    }
    else if (contentframe.bblite)
    {
        contentframe.bblite();
    }
    else
    {
        Ext.Msg.alert("Not Supported","BBLite is not supported for this page");
    }
}

Highline.main.Util.iconhelper=function ()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.helper)
    {
        contentframe.low.helper();
    }
    else if (contentframe.middle && contentframe.middle.helper)
    {
        contentframe.middle.helper();
    }
    else if (contentframe.helper)
    {
        contentframe.helper();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Help is not supported for this page");
    }
}

Highline.main.Util.iconexporter=function()
{ 
   var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
   if((contentframe.low && contentframe.low.isCompanyReport &&contentframe.low.isCompanyReport())||(contentframe.middle && contentframe.middle.isCompanyReport&&contentframe.middle.isCompanyReport())||
   		( contentframe.isCompanyReport &&contentframe.isCompanyReport())){
       
    var reportId;
    var isExcelFormulaExport;
	this.loadMask = new Ext.LoadMask(Ext.getCmp("mainwindow").getActiveTab().id,{msg: 'Please wait...'});
	if( this.loadMask ){
      this.loadMask.show();
    }
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.exporter&& contentframe.low.getReportID)
    {
        reportId=contentframe.low.getReportID(contentframe.low.isNav4);
        isExcelFormulaExport=contentframe.low.getExcelFormulaExport(reportId);
       // contentframe.low.exporter(isExcelFormulaExport);
    }
    else if (contentframe.middle && contentframe.middle.exporter&& contentframe.middle.getReportID)
    {
     	reportId=contentframe.middle.getReportID(contentframe.middle.isNav4);
     	isExcelFormulaExport=contentframe.middle.getExcelFormulaExport(reportId);
       // contentframe.middle.exporter(isExcelFormulaExport);
    }
     else if (contentframe.exporter&& contentframe.getReportID)
    {
     	reportId=contentframe.getReportID(contentframe.isNav4);
     	isExcelFormulaExport=contentframe.getExcelFormulaExport(reportId);
       // contentframe.exporter(isExcelFormulaExport);
    }
    else
    {
        Ext.Msg.alert("Not Supported","Excel export is not supported for this page");
         if( this.loadMask ){
        this.loadMask.hide();
      }
    }
       if( this.loadMask ){
        this.loadMask.hide();
      }  
      function formulaexport(){
	  if(isExcelFormulaExport){
		return false;
	  }else{
		return true;
	  }
	}
		this.Value=new Ext.form.Radio({
            boxLabel: 'Values',
            name: 'Excelexport',
            inputValue:'0',
            checked:true
        });
        this.Formula=new Ext.form.Radio({
            boxLabel: 'Formulas',
            name: 'Excelexport',
            disabled:formulaexport(),
            inputValue:'1'
        });
        var headinggroup=new Ext.form.RadioGroup({
            xtype: 'radiogroup',
            fieldLabel: 'Export as',
            cls: 'RadiogroupCls',
            columns: 1,
            //disabled:true,
            items: [
            this.Value,
            this.Formula
            ]
        });
        // This just creates a window to wrap the login form. 
        // The login object is passed to the items collection.       
        var win = new Ext.Window({
          layout:'fit',
          width:375,
          height:150,
          closable: false,
          resizable: false,
          plain: true,
          border: false,
          title: 'Export to Excel Settings',
          defaults: {
	        bodyStyle:'margin:0px,0px,0px,0px; background:#F0F0F0;'
          },
          items: [          
            new Ext.Panel({
               layout:'form',
               labelPad:10,
               bodyStyle: 'margin:30px,30px,30px,30px; background:#F0F0F0;',
               border: false,
               items:[
                  headinggroup,
                  new Ext.Panel({
					border:false,
					id:'message',
					height:50,
					bodyStyle:'margin:0px,0px,0px,0px;font: 12px tahoma,arial,helvetica,sans-serif; background:#F0F0F0;',
					html:'The option to select formulas is not available for some reports.',
					anchor: '100%'
					
				})     	  
               ],
               buttonAlign: 'center',
               buttons:[{
                 text: 'OK',
                 handler: function(btn,e){
                   var isFormulaExport = this.ownerCt.items.get(0).items.get(0).getGroupValue();
                   if( isFormulaExport && isFormulaExport ==="1" ){
                      isFormulaExport = true;
                   }else{
                   	  isFormulaExport = false;
                   }
                   
                   if (contentframe.low && contentframe.low.exporter){
                     contentframe.low.exporter(isFormulaExport);
                   }
                   else if (contentframe.middle && contentframe.middle.exporter){
                     contentframe.middle.exporter(isFormulaExport);
                   }
                   else if (contentframe.exporter){
                     contentframe.exporter(isFormulaExport);
                   }
                   else {
                     Ext.Msg.alert("Not Supported","The option to select formulas in not available for this report");
                     if( this.loadMask ){
				        this.loadMask.hide();
				      }
                   }
                   btn.ownerCt.ownerCt.close();
                 }
               },
               {
                 text: 'Cancel',
                 handler: function(btn,e){
                    btn.ownerCt.ownerCt.close();
                 }
               }]
            })
          ]
	    });
	    win.show();   
	    }else{
	     //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.exporter)
    {
        contentframe.low.exporter();
    }
    else if (contentframe.middle && contentframe.middle.exporter)
    {
        contentframe.middle.exporter();
    }
     else if (contentframe.exporter)
    {
        contentframe.exporter();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Excel export is not supported for this page");
    }
    
    }
}
Highline.main.Util.icongrapher=function()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe.low && contentframe.low.grapher)
    {
        contentframe.low.grapher();
    }
    else if (contentframe.middle && contentframe.middle.grapher)
    {
        contentframe.middle.grapher();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Graph settings are not supported for this page");
    }
}
Highline.main.Util.iconopener=function()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe && contentframe.opener)
    {
        contentframe.opener();
    }
    else if (contentframe.low && contentframe.low.opener)
    {
        contentframe.low.opener();
    }
    else if (contentframe.middle && contentframe.middle.opener)
    {
        contentframe.middle.opener();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Opening is not supported for this page");
    }
}
Highline.main.Util.iconsaver=function()
{
    var contentframe=Ext.getCmp("mainwindow").getActiveTab().getFrameWindow();
    //var contentframe=Ext.getCmp('frame0').getFrameWindow();
    if (contentframe && contentframe.saver)
    {
        contentframe.saver();
    }
    else if (contentframe.low && contentframe.low.saver)
    {
        contentframe.low.saver();
    }
    else if (contentframe.middle && contentframe.middle.saver)
    {
        contentframe.middle.saver();
    }
    else
    {
        Ext.Msg.alert("Not Supported","Saving is not supported for this page");
    }
}

