/**
 * @author buenger
 */


function LeasingService (a_serviceUrl) {
	
	var serviceUrl = a_serviceUrl;
	
	
	var km;
	var carType;
	var make;
	var runtime;
	var decliningBalanceType;
	var price;
	var rateExclVAT;
	var depositExclVAT;
	var decliningBalance;
	
	var _self = this;
	
	this.setCarType = function  (a_carType) {
		carType = a_carType;
	}
	
	this.setKm = function  (a_km) {
		km = a_km;
	}
	
	this.setMake = function  (a_make) {
		make = a_make;
	}
	
	this.setRuntime = function  (a_runtime) {
		runtime = a_runtime;
	}
	
	this.setDecliningBalanceType = function  (a_decliningBalanceType) {
		decliningBalanceType = a_decliningBalanceType;
	}
	
	this.setDecliningBalance = function  (a_decliningBalance) {
		decliningBalance = a_decliningBalance;
	}
	
	this.setPrice = function  (a_price) {
		price = a_price;
	}
	
	this.setRateExclVAT = function  (a_rateExclVAT) {
		rateExclVAT = a_rateExclVAT;
	}
	
	this.setDepositExclVAT = function  (a_depositExclVAT) {
		depositExclVAT = a_depositExclVAT;
	}
//-----------------------------------------------------------------------------------//
	
	this.getCarType = function  () {
		getRequest().send('method=getCarType');
	}
	
	this.getMake = function () {
		getRequest().send('method=getMake&carType='+carType);
	}
	
	this.searchMake = function (a_string) {
		getRequest().send('method=searchMake&carToken='+a_string);
	}
	
	this.getCarData = function () {
		getRequest().send('method=getCarData&carType='+carType+'&make='+make);
	}
	
	this.getDecliningBalance = function () {
		getRequest().send('method=getDecliningBalance&decliningBalanceType='+decliningBalanceType+'&runtime='+runtime+'&km='+km);
	}
	
	this.getEffInterest = function () {
		getRequest().send('method=getEffInterest&runtime='+runtime+'&rateExclVAT='+rateExclVAT+'&depositExclVAT='+depositExclVAT+'&price='+price+'&decliningBalance='+decliningBalance);
	}
	
	function getRequest() {
		return new Service({
			method: 'post',
			url: serviceUrl,
			onFailure: handleFailure,
			onSuccess: handleSuccess
		})
	}
	
	function handleSuccess (a_responseText, a_responseXML) {
		var obj = JSON.decode(a_responseText);
		_self.fireEvent("success", obj);
	}
	
	function handleFailure (a_code) {
		debug (a_code)
	}
	
	//Event extension (mootools 1.2)
	$extend(this, new Events());
}
