if ((top.TitleFeeServiceInit == "undefined") || (top.TitleFeeServiceInit != true))
{

	/*************************************************************************
	 *
	 * Title Fee Service CLASS definition. Makes Server Data Requests - through a Channel
	 *
	 */
	function TitleFeeService()
	{
		this.uiService;
		this.callIdParameter = "callId";
		this.resourceParameter = "./app/";
		this.actionParameter = "action";
	}

	TitleFeeService.prototype = new ServerCallService();
	TitleFeeService.prototype.constructor = TitleFeeService;

	TitleFeeService.prototype.setUIService = function(uiServiceArg){
		this.uiService = uiServiceArg;
	}


	TitleFeeService.prototype.getNewServerCall = function(){
		var sc = new ServerCall(this);
		sc.setCallIdParameter(this.callIdParameter);
		sc.setResource(this.resourceParameter);
		return sc;
	}


	/**
	 * Business Methods
	 */
	TitleFeeService.prototype.getState = function(stateCode)
	{
		var sc = this.getNewServerCall();
		
		sc.setOperation("TFC_WEB_APP_ACTION_GET_STATE");
		sc.addParameter("STATE_CODE", stateCode);
		
		this.serverCall(sc);
	}
	
	TitleFeeService.prototype.getQuestionTree = function(stateCode, countyGroupId)
	{
		var sc = this.getNewServerCall();
		
		sc.setOperation("TFC_WEB_APP_ACTION_GET_QUESTION_TREE");
		
		if (window.top.location.search.substring(1) == 'XX') {
			stateCode = 'XX';
		}
			
		sc.addParameter("STATE_CODE", stateCode);
		sc.addParameter("COUNTY_GROUP_ID", countyGroupId);
		
		this.serverCall(sc);
	}
			
	TitleFeeService.prototype.getPolicyRate = function(stateCode, countyId, questionParameters, endorsementParameters)
	{
		//alert("questionParameters=" + questionParameters);
		
		var sc = this.getNewServerCall();
		
		sc.setOperation("TFC_WEB_APP_ACTION_GET_POLICY_RATE");
		sc.addParameter("STATE_CODE", stateCode);
		sc.addParameter("COUNTY_ID", countyId);
		
		sc.addParameter("POLICY_PARAMETERS", questionParameters);
		
		if (endorsementParameters != "" && endorsementParameters != null)
			sc.addParameter("ENDORSEMENT_PARAMETERS", endorsementParameters);
		else
			sc.addParameter("ENDORSEMENT_PARAMETERS", null);
		
		this.serverCall(sc);
	}
	
	TitleFeeService.prototype.getEndorsementList = function(stateCode, policyTypeId)
	{
		var sc = this.getNewServerCall();

		sc.setOperation("TFC_WEB_APP_ACTION_GET_ENDORSEMENT_LIST");
		sc.addParameter("STATE_CODE", stateCode);
		sc.addParameter("POLICY_TYPE_ID", policyTypeId);
		
		this.serverCall(sc);
	}
	
	TitleFeeService.prototype.handleCall = function(operation, func){
		var data = func();
		if (data[0] == "SYSTEM_EXCEPTION") {
			this.uiService.displaySystemException(data[1]);
		}
		else if (data[0] == "BUSINESS_EXCEPTION") {
			this.uiService.displayBusinessException(data[1]);
		}
		else {
			if( operation == "TFC_WEB_APP_ACTION_GET_STATE" ) {
				this.uiService.reload(data);
			}
			else if( operation == "TFC_WEB_APP_ACTION_GET_QUESTION_TREE" ) {
				this.uiService.setQuestionTree(data[0]);
				this.uiService.displayFirstQuestion();	
			}
			else if( operation == "TFC_WEB_APP_ACTION_GET_ENDORSEMENT_LIST" ) {
				this.uiService.setEndorsementList(data);
				this.uiService.displayEndorsementsForm();
			}
			else if( operation == "TFC_WEB_APP_ACTION_GET_POLICY_RATE" ) {
				this.uiService.setRateList(data);
				if(this.uiService.hasSelectedEndorsements() && this.uiService.uiServiceStatus != 'TFC_UISERVICESTATUS_QUESTION') {
					this.uiService.displayFinalQuoteForm();
				}
				else {
					this.uiService.displayQuoteForm();
				}
			}
		}
	}
	
	//////////////////////////////////////
	
	top.TitleFeeServiceInit = true;
}