/**
 * file Tiper.js with class for tips
 * @author Janusz Rygał
 * @date 24.09.2008
 */

/**
 * @class Tiper class
 */
Tiper = function(){

    this.body = null;
    this.lastTip = null;

    this.displayDetails = function(){
        var body = "<div>";
                body += "<div>";
                    body += context.translator.translate('help_title_'+context.tiper.lastTip);
                body += "</div> <br/> <br />";

                body += "<div>";
                    body += context.translator.translate('help_body_'+context.tiper.lastTip);
                body += "</div>";

            body += "</div>";

        var win = new Ext.Window({
                        title: context.translator.translate('tip_for_you'),
                        height: 300,
                        width:  500,
                        modal: true,
                        iconCls: 'tip',
                        html: body
                  });
        win.show();
    }

    this.incrementTip = function(){
        Ext.Ajax.request({
								url: project_url + 'IncrementTip',
								method: 'GET'
                        });
    }

    this.displayTip = function(){
        context.tiper.lastTip = context.user.preferences.getCurrTip();
        Ext.example.msg( "<img src='../images/omsImages/main/icons/tip.png'/> "+context.translator.translate('tip_for_you'),  context.tiper.body, 'b-r', 10, 500);
        context.tiper.incrementTip();
    }

    this.init = function(){
        var currTip = context.user.preferences.getCurrTip();

            context.tiper.body = "<div style='width: 200px;'>";

                context.tiper.body += "<div style='cursor: pointer; color: red;' onclick='context.tiper.displayDetails()'>";
                    context.tiper.body += context.translator.translate('help_title_'+currTip);
                context.tiper.body += "</div>";

                context.tiper.body += "<div style='cursor: pointer;' onclick='context.tiper.displayDetails()'>";
                    context.tiper.body += context.translator.translate('help_head_'+currTip);
                context.tiper.body += "</div> <br /> <br />";

                context.tiper.body += "<div style='cursor: pointer;' onclick='context.tiper.disableTips()'>";
                    context.tiper.body += context.translator.translate('disable_tips');
                context.tiper.body += "</div>";

            context.tiper.body += "</div>";
    }

    this.disableTips = function(){
        if (context.user.getUserSystemPosition() != 3){
				var desktop_img = context.user.preferences.getDesktopIdByName( context.user.preferences.getDesktopImage() );

                var g_levels    = context.user.preferences.preferencesLoader.getAt(0).get('graphic_level');
                var s_news     = context.user.preferences.preferencesLoader.getAt(0).get('show_news');
				var s_reminder  = context.user.preferences.preferencesLoader.getAt(0).get('show_reminder');
                var s_tips      = 0;

                if(s_news == 1)
					s_news = 'on';
                else
                    s_news = 'off';

                if(s_reminder == 1)
					s_reminder = 'on';
                else
                    s_reminder = 'off';

                if(s_tips == 1)
					s_tips = 'on';
                else
                    s_tips = 'off';

				Ext.Ajax.request({
								url: project_url + 'SaveScreenSettings',
								method: 'GET',
							   	params: { background_image: desktop_img,
                                          show_clock: 0,
                                          show_news: s_news,
                                          graphic_levels: g_levels,
                                          show_reminder: s_reminder,
                                          show_tips: s_tips
                                       }
							});
			}
    }

}

