
var phpService = {

	serviceCall : function () {
		var method = '';
		var params = [];
		var callback = function () { return; };
		if( arguments.length > 2 ) {
			method = arguments[0];
			for( var i = 1; i < arguments.length - 1; i++ ) {
				params.push( arguments[i] );
			}
			callback = arguments[i];
		} else if( arguments.length == 2 ) {
			method = arguments[0];
			callback = arguments[1];
		} else if( arguments.length == 1 ) {
			callback = arguments[0];
		} else {
			onErr( 'No method name supplied' );
		}
		new Ajax.Request(
			'/jsphpremoting/phpService.php',
			{
				evalJSON : true,
				method : 'post',
				postBody : 'method=' + method + '&arguments=' + encodeURIComponent( params.toJSON() ),
				onSuccess : function ( transport ) {
					if( transport.responseJSON.status ) {
						callback( transport.responseJSON.result );
					} else {
						onErr( transport.responseJSON.result.exception );
					}
				},
				onFailure : function () {
					onErr(  );
				}
			}
		);
	},

	setOnFailure : function ( func ) {
		if( func ) {
			onErr = func;
		}
	},

	onErr : function ( e ) {
		alert( e );
	}	,

	getArray : function ( callback ) {
		this.serviceCall( 'getArray', callback );
	},

	echoBack : function ( theySaid, callback ) {
		this.serviceCall( 'echoBack', theySaid, callback );
	},

	echoBackWithChange : function ( theySaid, callback ) {
		this.serviceCall( 'echoBackWithChange', theySaid, callback );
	},

	addThreeNumbers : function ( a, b, c, callback ) {
		this.serviceCall( 'addThreeNumbers', a, b, c, callback );
	},

	getPrivateVar : function ( callback ) {
		this.serviceCall( 'getPrivateVar', callback );
	},

	getAnAssociative : function ( callback ) {
		this.serviceCall( 'getAnAssociative', callback );
	},

	showProperty : function ( obj, propName, callback ) {
		this.serviceCall( 'showProperty', obj, propName, callback );
	}

}; // end of service class definition

