
var OnKeyUp = new function()
{
	this.OnLoad = function(){
	}
	
	this.HandleKeyUp = function(numDaysId, numMachinesId, labelId, price1, price2, price3, priceModel){
	    
	    var numDays = document.getElementById(numDaysId);
	    
	    var numMachines = document.getElementById(numMachinesId);
	    
	    var label = document.getElementById(labelId);
	    var regExp = new RegExp(/[^0-9]/);
	    
	    if (regExp.test(numDays.value) == true){ 
	        numDays.value = 1;
	    }
	    if (regExp.test(numMachines.value) == true){
	        numMachines.value = 1;
	    }
		var result = numMachines.value * this.PricePerDay(numDays.value, price1, price2, price3, priceModel) * numDays.value;
	    label.innerHTML = Math.round(result * 100) / 100;
	}
	
	this.PricePerDay = function(days, price1, price2, price3, priceModel){
	    var pricePerDay;
	  
        if (priceModel == "threePriceModel") {
            if (days < 6){
		    pricePerDay = price1;
		    }
		    else if(days > 5 && days < 22){
		        pricePerDay = ((5 * price1) + ((days - 5) * price2)) / days;
		    }
		    else {
		        pricePerDay = ((5 * price1) + (16 * price2) + ((days - 21) * price3)) / days;
		    }
        } else if (priceModel == "twoPriceModel") {
            if (days < 2){
                pricePerDay = price1;
            } else {
                pricePerDay = (Number(price1) + ((days - 1) * Number(price2))) / days;
            }
        } else { //default - one price model
            pricePerDay = price1;
        }
		return pricePerDay;
	}
	
};


