/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var releaseNote;
var aboutMCare;
var showInfo;

var showAbout = function(){
//if(!helpWin){
var  helpWin = new Ext.Window({
        width:500,
        id:'autoload-win',
        height:350,
        layout:'fit',
        autoScroll:true,
        //modal: true,
        plain: true,
        html: '<iframe src="html/about_mc.htm" style="width:100%;height:100%;border:none;"></iframe>',
        title:'About MaintenanceCare',
        listeners:{
            show:function() {
                this.loadMask = new Ext.LoadMask(this.body, {
                    msg:'Loading. Please wait...'
                });
            }
        }
    });
//}
helpWin.show();
};  // end of about function

var jasperReport = function(){
//if(!helpWin){
var  jasperWin = new Ext.Window({
        width:750,
        id:'autoload-jasper',
        height:550,
        layout:'fit',
        autoScroll:true,
        //modal: true,
        minimizable: true,
        maximizable: true,
        html: '<iframe src="http://www.gnxcor.com/jasperserver/login.html" style="width:100%;height:100%;border:none;"></iframe>',
        plain: true,
//        autoLoad:{url:'html/releaseNotes.htm'},
        title:'GNX Report System',
        listeners:{
            show:function() {
                this.loadMask = new Ext.LoadMask(this.body, {
                    msg:'Loading. Please wait...'
                });
            }
        }
    });
//}
jasperWin.show();
}; // end of jasper function


function ShowScreen(screenPath)
{
   windowprops = "height=820,width=872,location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes";
   picwindow = window.open(screenPath , "screencontent", windowprops);
   picwindow.focus();
   return true;
}

function openPopup(docPath, height, width, lookup)
{
   var left = Math.floor( (screen.width - width) / 2 + 50);
   var top = Math.floor( (screen.height - height) / 2);
   windowprops = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width + ",location=no,scrollbars=yes,menubars=no,toolbars=no,dependent=yes,resizable=yes";
   lookupwindow2=window.open(docPath ,lookup, windowprops);
   lookupwindow2.focus();
}

var supportMsg = "<b>Welcome to Maintenance Care</b><br/>"+
           "Web-based facility management membership <br/>"+
           "with Asset Management and Scheduled Maintenance. "+
	       "<hr/>"+
	       "<b>Known Issues:</b><br/>"+
	       "<ul>"+
	       "<li>&nbsp;- Not fully tested with IE 6.0/7.0/8.0</li>"+
	       "</ul><br/>"+
	       "<b>Tech Support:</b><br/>"+
	       "<ul>"+
	       "<li>Call&nbsp;&nbsp;&nbsp;&nbsp; - 1.888.222.0206 Ext. 2 </li>"+
	       "<li>Email&nbsp; - support@maintenancecare.com</li>"+
	       "</ul>";

aboutMCare = function(){
    Ext.Msg.show({
        title: "MaintenanceCare",
        msg: supportMsg,
        buttons: Ext.Msg.OK,
        animEl: this.getEl(),
        minWidth: 500,
        modal: false,
        icon: Ext.MessageBox.INFO
    });
};
var showUserGuide = function(){
    ShowScreen('http://www.maintenancecare.com/training_index.htm')
}
var showTrainingGuide = function(){
    ShowScreen('http://www.maintenancecare.com/mwiki/index.php/Maintenance_Care_User_Guide')
}
var showForum = function(){
    openPopup('http://www.maintenancecare.com/mwiki/index.php/Special:AWCforum/sc/id3/Maintenance_Care_Forum.html', 560, 980, "external");
}

Ext.namespace('Gnx.mc.util');
Gnx.mc.util.showMsg = function(msg) {
   new Ext.ux.Notification({
            title:  'Confirmation',
            html: msg || 'No information available',
            autoDestroy: true,
            alignTo: 'portletHeader',
            hideDelay:  2000
        }).show(document);
    }



Ext.onReady(function(){
var helpButton = new Ext.SplitButton({
    baseCls: 'x-plain',
    cls: 'btn-panel',
    renderTo : 'help_button',
    text: '&nbsp;HELP&nbsp;',
    iconCls: 'help',
    scale: 'small',
//    handler: showAbout,
    handler: function(btn){btn.showMenu();},
    menu : {items: [
            {text:'User Guide',iconCls:'guide', handler: showTrainingGuide},
            {text:'Training',iconCls:'training', handler: showUserGuide},
            {text:'Support',iconCls:'support', handler:aboutMCare},
            {text:'Forum',iconCls:'chat', disabled : false, handler: showForum},
//            {text:'Jasper',iconCls:'chat', handler: jasperReport},
            {text:'About',iconCls:'info', handler: showAbout}]},
    split: true
});


//var fLink1 = Ext.get('about-gnx');
//fLink1.on('click', onClick, {tabIndex : 0});
//
//Ext.get('gnx-change-country').on('click', function(){
//    Ext.MessageBox.show({
//        title: 'Language Support',
//        msg: 'Your user profile does not support other languges.',
//        buttons: Ext.MessageBox.OK,
//        icon: Ext.MessageBox.INFO
//    });
//});

releaseNote = function(){
    var win = new Ext.Window({
        width:540
        ,id:'autoload_01'
        ,height:380
        ,layout:'fit'
        ,autoScroll:true
        ,plain: true
        ,html: '<iframe src="html/releaseNotes.htm" style="width:100%;height:100%;border:none;"></iframe>'
        ,title:'MaintenanceCare Release Notes'
        ,listeners:{show:function() {
            this.loadMask = new Ext.LoadMask(this.body, {
                msg:'Loading. Please wait...'
            });
        }}
    });
    win.show();
};  // end of releaseNote function

//remove loading image
setTimeout(function(){
    Ext.get('loading').remove();
    Ext.get('loading-mask').fadeOut({remove:true});
  }, 250);

//detect and redirect to login screen on session timeout
Ext.util.Observable.observeClass(Ext.data.Connection);
Ext.data.Connection.on('requestcomplete', function (con, response, options) {
    var dResponse = Ext.util.JSON.decode(response.responseText);
    if (dResponse.success === false && dResponse.errorInfo === 'TimeOut') {
        window.location.replace('login');
    }
});
Gnx.BASE_URL = (Ext.get('gnxBaseURL')).getAttribute("href");
});

