/*global Ext*/

// Create user extensions namespace (Ext.ux.form)
Ext.ns('Ext.ux.form');
 
/**
  * Ext.ux.form.BaseField Extension Class
  * @class Ext.ux.form.BaseField
  * @extends Ext.form.Field
  * @constructor
  * @param {Object} config Configuration options
  */

Ext.ux.form.BaseField = function (config) {
  var protocol;
  protocol = document.location.protocol;
  
  if (protocol === 'http:')
  {
    this.http = 'http://';
  }
  // for secured url
  if (protocol === 'https:')
  {
    this.http = 'https://';
  }
  // call parent constructor
  Ext.ux.form.BaseField.superclass.constructor.call(this, config);
};

Ext.extend(Ext.ux.form.BaseField, Ext.form.Field, {
  /*
   * @http - http protocol (http or https)
  */
  http: 'https://',
  /*
   * @serverName - name/ip of the server 
  */
  serverName: 'mbdevweb5.mblast.com',
  /*
   * @applicationName - name of the application directory
  */
  applicationName:  'Ext.NET',
  /*
   * @handlerName - name of the webservice handler
  */
  handlerName: 'mBJSONService.ashx',
  /*
   * @loadingImage - loading image path to be shown during ajax call
  */
  loadingImage: '/images/spinner.gif', 
  /*
   * @loadingText - loading message text to be shown along with the loading image
  */
  loadingText: 'Please wait...',
  // {{{
  /**
    * private
    * function for ext-ajax call 
    */
  ajaxRequest: function (o) {
    Ext.Ajax.request(
    {
      ownerCt: this,
      url: o.url,
      success: o.success,
      failure: o.failure
    });
	  return null;
  }, // eo ajaxRequest
  //}}}
  // {{{
  /**
    * private
    * function to enable body masking masking during ajax call 
    */
  enableBodyMask: function () {
    this.loadingHtml = '<img src="' + this.loadingImage + '" border="0" align="middle" alt="">&nbsp;&nbsp;' + this.loadingText;
    Ext.getBody().mask(this.loadingHtml);
  }, // eo enableBodyMask
  //}}}
  // {{{
  /**
    * private
    * function to disable body masking after ajax call completes
    */
  disableBodyMask: function () {
    Ext.getBody().unmask(); 
  }, // eo disableBodyMask
  //}}}
  // {{{
  /**
    * private
    * function to decode json string
    */
  jsonDecoder: function (dataString) {
    return Ext.util.JSON.decode(dataString);
  }, // eo jsonDecoder
  //}}}
  // {{{
  /**
    * private
    * function to display the loading image 
    */
  showLoadingImage: function () {
    Ext.get(this.id + '_loading-symbol').dom.style.display = 'block';
  }, // eo showLoadingImage
  //}}}
  // {{{
  /**
    * private
    * function to hide the loading image
    */
  hideLoadingImage: function () {
    Ext.get(this.id + '_loading-symbol').dom.style.display = 'none';
  } // eo hideLoadingImage
  //}}}
});
