/***************************************************************************
 [ChatService.js]

 Copyright (C) 2004 Next IT Corporation, Inc. Spokane, WA. All Rights Reserved. 
 This document is confidential work and intellectual property of Next IT 
 Corporation. Permission to copy, distribute or use any portion of this file 
 is prohibited without the express written consent of Next IT Corporation.

*****************************************************************************/

var _chatWebService;

function ChatService( url )
{
	_chatWebService = new WebServiceManager(url);
	_chatWebService.Async = false;
	
	this.CheckServer = function( id )
	{	
		var r = _chatWebService.InvokeMethod( "GetImpasseResponse", null, id );
		if( r.error )
		{
			this.AlertError( "CheckServer", r );
		}
		else
			return this.GetObject( r );						
	};
	
	this.EndChat = function( id )
	{
		var r = _chatWebService.InvokeMethod( "EndImpasse", null, id );
		if( r.error )
		{
			this.AlertError( "EndChat", r );
		}
		else
			return this.GetObject( r );
	};
	
	this.StartChat = function( id, url, cb )
	{
		var r = null;
		if (cb)
		{
			_chatWebService.Async = true;
			r = _chatWebService.InvokeMethod( "DoImpasse", cb, id, url );
			_chatWebService.Async = false;
		}
		else
		{
			r = _chatWebService.InvokeMethod( "DoImpasse", null, id, url );
		}
		
		if( r.error )
		{
			this.AlertError( "StartChat", r );
		}
		else
		{
			return this.GetObject( r );
		}
	};
	
	this.SendUserResponse = function( userInput )
	{
		var r = _chatWebService.InvokeMethod( "SendImpasseResponse", null, userInput );
		if( r.error )
		{
			this.AlertError( "SendUserResponse", r );
		}
		else
			return this.GetObject( r );
	};
	
	this.CreateID = function()
	{
		var r = _chatWebService.InvokeMethod( "CreateBrainID", null );
		if( r.error )
		{
			this.AlertError( "CreateID", r );
		}
		else
			return this.GetObject( r );
	};

	this.AlertError = function( methodName, er )
	{
		//alert( 'ERROR in method: ' + methodName + '\nCode: ' + er.errorDetail.code + '\nString: ' + er.errorDetail.string );
	};
	
	this.GetObject = function( r )
	{
		var o = new Object();
		if( r.value != null )
		{
			o = r.value;
			return o;
		}
		else
			return null;
	};
	
	this.GetCyberInfo = function( id )
	{
		var r = _chatWebService.InvokeMethod( "GetCyberInfo", null, id );
		if( r.error )
		{
			this.AlertError( "GetCyberInfo", r );
		}
		else
			return this.GetObject( r );		
	};	
};