
/**
 * Common utilities for EasyTalk
 * @author Raj
 * (c) Impiger Technologies, 2009
 */
 
var WSURL = "ws/endpoint.php";

var sucess = function(response, opts) {
      
         if ( typeof response != 'undefined' && typeof response.responseText != 'undefined' )
      	{
      		resp = Ext.util.JSON.decode(response.responseText);
      		if ( resp.success == true )
      		{
      			Ext.Msg.alert('Success', resp.result);
      		}
      		else
      		{
      			Ext.Msg.alert('Error', resp.result);
      		}
      	}
      	else
      	{
      		Ext.Msg.alert('Error', "couldn't get server response");
      	}
         /*if (respObj.success) {
            if (successCallback) {
                successCallback(respObj.result);
            };
         } else {
            // failed!
            if (failCallback) { 
               failCallback(respObj.result);
            } else {
               alert("Error! - " + respObj.result);
            };            
         }*/

      }

/**
 * Invoke a webservice.
 * @param service Name of service
 * @param method 
 * @param data Data object. This will be serialized as JSON and sent out.
 */
/**
 * Invoke a webservice.
 * @param service Name of service
 * @param method 
 * @param data Data object. This will be serialized as JSON and sent out.
 */
function invokeWS(method, params, successCallback, scope, url) {
   success = successCallback || sucess;
   url     = url || WSURL;
   Ext.Ajax.request({
					url:url,
					methos: method || 'POST',
					params: params || {},
					success: success,
					failure: function(response) {
			      	if ( typeof response != 'undefined' && typeof response.responseText != 'undefined' )
			      	{
			      		resp = Ext.util.JSON.decode();
			      		Ext.Msg.alert('Error', resp.result);
			      	}
			      	else
			      	{
			      		Ext.Msg.alert('Error', "There was a problem communicating with server!");
			      	}
			      },
					scope: scope || this
				});
   
   //return request;
}

	var ajax_loading_callback = function() {
	    Ext.MessageBox.wait('Processing Data...', 'Please wait');
	}
	
	var ajax_loaded_callback = function() {
	    Ext.MessageBox.hide();
	}
