if ((top.OneRateServiceInit == "undefined") || (top.OneRateServiceInit != true))
{

	/*************************************************************************
	 *
	 * Home Buyers Service CLASS definition. Makes Server Data Requests - through a Channel
	 *
	 */
	function OneRateService(_stateCode)
	{
		this.uiService;
		this.resource = "index.hbc";
		this.actionParameter = "action";

		this.stateCode = _stateCode;
		this.county = "Orange";
		this.purchasePrice = 0;
		this.includeEscrowFees = "INCLUDE_ESCROW_YES";
		this.callIdParameter = "CALL_ID_REQUEST_PARAMETER";
		this.firstLoanIncluded = false;
		this.secondLoanIncluded = false;
		this.loan = 0;
	}

	OneRateService.prototype = new ServerCallService();
	OneRateService.prototype.constructor = OneRateService;

	OneRateService.prototype.setUIService = function(uiServiceArg){
		this.uiService = uiServiceArg;
	}

	OneRateService.prototype.setCounty = function(value){
		this.county = value;
	}
	
	OneRateService.prototype.setPurchasePrice = function(value){
		this.purchasePrice = top.Formatter.unFormat(value);
	}

	OneRateService.prototype.setIncludeEscrow = function(value){
		if(value == "true"){
			this.includeEscrowFees = "INCLUDE_ESCROW_YES";
		} else{
			this.includeEscrowFees = "INCLUDE_ESCROW_NO";
		}
	}

	OneRateService.prototype.setFirstLoanIncluded = function(included){
		this.firstLoanIncluded = included;
	}

	OneRateService.prototype.setSecondLoanIncluded = function(included){
		this.secondLoanIncluded = included;
	}
	
	OneRateService.prototype.setLoanAmount = function(loanAmount){
		this.loan = loanAmount;
	}

 	OneRateService.prototype.getLoanCount = function(){
 		var loanCount = 0;
 		if(this.firstLoanIncluded){
 			loanCount = 1;
 			if(this.secondLoanIncluded){
 				loanCount = 2;
 			}
 		}
 		return loanCount;
 	}


	/**
	 * Business Methods
	 */
	OneRateService.prototype.newServerCall = function(){
		sc = new ServerCall(this);
		sc.setCallIdParameter(this.callIdParameter);
		sc.setResource(this.resource);
		return sc;
	}

	OneRateService.prototype.doGetQuote = function()	{
		sc = this.newServerCall();

		sc.setOperation("HBC_WEB_APP_ACTION_GET_QUOTE");
		sc.addParameter("CALCULATOR_KEY_REQUEST_PARAMETER", this.stateCode);
		sc.addParameter("INCLUDE_ESCROW_REQUEST_PARAMETER", this.includeEscrowFees);
		sc.addParameter("PURCHASE_PRICE_REQUEST_PARAMETER", this.purchasePrice);
		sc.addParameter("COUNTY_REQUEST_PARAMETER", this.county);
		sc.addParameter("LOAN_COUNT_REQUEST_PARAMETER", this.getLoanCount());
		sc.addParameter("LOAN_AMOUNT_REQUEST_PARAMETER", this.loan);
		this.serverCall(sc);
	}
	
	OneRateService.prototype.doGetRefinanceQuote = function()	{
		sc = this.newServerCall();

		sc.setOperation("HBC_WEB_APP_ACTION_GET_REFINANCE_QUOTE");
		sc.addParameter("CALCULATOR_KEY_REQUEST_PARAMETER", this.stateCode + "Refinance");
		sc.addParameter("PURCHASE_PRICE_REQUEST_PARAMETER", this.purchasePrice);
		sc.addParameter("COUNTY_REQUEST_PARAMETER", this.county);
		this.serverCall(sc);
	}

 	OneRateService.prototype.handleCall = function(operation, func){
		data = func();
		if(operation == "HBC_WEB_APP_ACTION_GET_QUOTE"){
			this.uiService.displayQuote(data);
		}
		else if(operation == "HBC_WEB_APP_ACTION_GET_REFINANCE_QUOTE"){
			this.uiService.displayQuote(data);
		}
	}
	
  	
	//////////////////////////////////////
	
	top.OneRateServiceInit = true;
}