if ((top.ServerCallServiceInit == "undefined") || (top.ServerCallServiceInit != true))
{

	/**
	 *
	 * ServerCallService CLASS definition.
	 *
	 */
	
	function ServerCallService()
	{
		this.actionParameter = null;

	}
	ServerCallService.callList = new Array();
	ServerCallService.callResponseList = new Array();
	
	ServerCallService.finishCall = function(id)
	{
		var owner = ServerCallService.callList[id].getOwner();
		var operation = ServerCallService.callList[id].getOperation();
		
		owner.handleCall(operation, ServerCallService.callResponseList[id]);
	}
	
	ServerCallService.prototype.getActionParameter = function()
	{
		return this.actionParameter;
	}
	
	ServerCallService.prototype.setActionParameter = function(actionParameterArg)
	{
		this.actionParameter = actionParameterArg;
	}
	
	ServerCallService.addCallResponse = function(id, func)
	{
		ServerCallService.callResponseList[id] = func;
	}
	
	// GET METHOD
	ServerCallService.prototype.serverCallGet = function(sc)
	{
		if(!(sc instanceof ServerCall))
		{
			return;
		}
		ServerCallService.callList[sc.getCallId()] = sc;

		var url = this.buildURL(sc);			
		channelService = sc.getChannelService();
		channel = channelService.getChannel();

		channel.setVisibility(false);
		channel.setChannelSource(url);		
	}
	
	// GET METHOD
	ServerCallService.prototype.buildURL = function(sc) { 
		var returnValue = sc.getResource() + "?" + this.getActionParameter() + "=" + sc.operation; 

		var params = [];
		for (x in sc.parameterTable) {
			if (typeof sc.parameterTable[x] == 'function') 
				continue;
			if (typeof sc.parameterTable[x] == 'number' || typeof sc.parameterTable[x] == 'string' || sc.parameterTable[x] == null ) 
				params.push(x+'='+sc.parameterTable[x]);
		}
		returnValue = returnValue + "&" + params.join('&');

		return returnValue; 
	}

	// POST METHOD
	ServerCallService.prototype.serverCall = function(sc)
	{
		if(!(sc instanceof ServerCall))
		{
			return;
		}
		ServerCallService.callList[sc.getCallId()] = sc;

		var channelInnerHTML = this.buildInnerHTML(sc);
		channelService = sc.getChannelService();
		channel = channelService.getChannel();

		channel.setVisibility(false);
		channel.setChannelInnerHTML(channelInnerHTML);
	}

	// POST METHOD
	ServerCallService.prototype.buildInnerHTML = function(sc) { 
		var innerHTML = '<form method="post" action="' + sc.getResource() + '">\n';
		
		// Add the ACTION parameter
		innerHTML += '<input type="hidden" name="' + this.getActionParameter() + '" value="' + sc.operation + '">\n';

		// Add the OTHER parameters
		for (x in sc.parameterTable) {
			if (typeof sc.parameterTable[x] == 'function') 
				continue;
			if (typeof sc.parameterTable[x] == 'number' || typeof sc.parameterTable[x] == 'string' || sc.parameterTable[x] == null ) 
				innerHTML += '<input type="hidden" name="' + x + '" value="' + sc.parameterTable[x] + '">\n';
		}

		// Add the FILE parameters
		for (x in sc.fileParameterTable) {
			if (typeof sc.fileParameterTable[x] == 'function') 
				continue;
			if (typeof sc.fileParameterTable[x] == 'number' || typeof sc.fileParameterTable[x] == 'string' || sc.fileParameterTable[x] == null ) 
				innerHTML += '<input type="file" name="' + x + '" value="' + sc.fileParameterTable[x] + '">\n';
		}

		innerHTML += '</form>\n';
		
		//alert(innerHTML);
		return innerHTML; 		
	}
      
	//////////////////////////////////////

	top.ServerCallServiceInit = true;
}
