/*
 * Copyright 2009 Palm, Inc. All rights reserved.
 */
/*global Mojo, Class, $L, AppAssistant, ConnectionWidget, HelpAssistant, WebViewHelper */
/*jslint rhino:true, undef:true */

var ChatAssistant = Class.create(HelpAssistant, {
  initialize: function($super, url) {
    $super();

    this.turnOffRotation = true; // HelpAssistant uses this in base_setup

    var params =
    {
        "url": url,
        "assistant": this,
        "hidePageControls": true,
        "isChatWindow": true
    };

    this.webViewHelper = new WebViewHelper(params);
  },
  setup:function() {
    this.base_setup( );
    this.setSpin(true);

  },
  cleanup: function(event) {
    this.base_cleanup();
  },
  activate: function(event) {
    this.base_activate();
  },
  ready: function() {
    this.base_ready( );
  },
  deactivate: function(event) {
    this.base_deactivate();
  },

    gotNetworkStatus: function(response) 
    {
        Mojo.Log.info("chat: @@@ Got network status: online=", response.isInternetConnectionAvailable);

        // On first launch we alway attempt to connect to the network if we are not online.
        var self = this;
        if (!AppAssistant.Network.online) 
        {
            ConnectionWidget.connect({
                type: 'data',
                onSuccess: function(response) 
                    {
                        // If the connection widget was previously cancelled and we
                        // are under its internal timeout limit then popup the network
                        // alert dialog.
                        if (response === "WiFi-UserCancelled") 
                        {
                            if (self.base_connectionAlert) {
                                self.base_connectionAlert();
							} else {
                                Mojo.Log.info("Connection alert not implemented");
							}
                        }
                    }
            }, self.controller.stageController);
        }
        else
        {
            this.hideLoadFailed();
        }
    },

  hideLoadFailed: function( ) {

    this.controller.get('web-view-help').show();
    var failedElem = this.controller.get('load-failed-message');
    failedElem.hide();
  },

  setupAppMenu: function($super) {
	$super(true);
  }

});
