// Lokad.com, Copyright 2007-2009

var EurInAud = 1.7;
var EurInCad = 1.5;
var EurInChf = 1.6;
var EurInGbp = 0.8;
var EurInJpy = 160.0;
var EurInUsd = 1.5;
var EurInMxn = 17.5;

var CostPerForecast = 0.15; // USD
var Power = 2.0 / 3.0;

function CalculateMonthlyForecastsForSales(numberOfSkus, numberOfRefreshs, numberOfForecastPoints) {
	var forecastsPerMonth = numberOfSkus * numberOfRefreshs * numberOfForecastPoints;
	
	return forecastsPerMonth;
}

function CalculateMonthlyForecastsForCalls(numberOfQueues, numberOfRefreshs, numberOfWeeks, quarter) {
	var forecastsPerMonth = numberOfQueues * 7 * 24 * numberOfRefreshs * numberOfWeeks * (quarter ? 4 : 1);
	
	return forecastsPerMonth;
}

// returns price in USD
function CalculateMonthlyCost(numberOfForecasts) {
	return RoundPrice(Math.pow(numberOfForecasts, Power) * CostPerForecast);
}

function RoundPrice(value) {
	return Math.round(value * 100.0) / 100.0
}

function ConvertCurrency(priceInUsd, currency) {
	var priceInEur = priceInUsd / EurInUsd;

	switch(currency.toLowerCase()) {
		case 'usd': return RoundPrice(priceInUsd);
		case 'eur': return RoundPrice(priceInEur);
		case 'aud': return RoundPrice(priceInEur * EurInAud);
		case 'cad': return RoundPrice(priceInEur * EurInCad);
		case 'chf': return RoundPrice(priceInEur * EurInChf);
		case 'gbp': return RoundPrice(priceInEur * EurInGbp);
		case 'jpy': return RoundPrice(priceInEur * EurInJpy);
                case 'mxn': return RoundPrice(priceInEur * EurInMxn);
		default: return 0;
	}
}

function CalcSells(currency) {
	if(typeof currency == "undefined") currency = 'usd';

	var noForecasts = CalculateMonthlyForecastsForSales(
		document.getElementById("sells_skuCount").value,
		document.getElementById("sells_refreshCount").value,
		document.getElementById("sells_forecastPointCount").value);
	var price = CalculateMonthlyCost(noForecasts);
	price = ConvertCurrency(price, currency);
	
	$("#sells_price").html(price);
	$("#sells_forecasts").html(noForecasts);
}

function CalcCalls(currency) {
	if(typeof currency == "undefined") currency = 'usd';

	var noForecasts = CalculateMonthlyForecastsForCalls(
		document.getElementById("calls_queueCount").value,
		document.getElementById("calls_refreshCount").value,
		document.getElementById("calls_weekCount").value,
		document.getElementById("calls_quarter").checked == true);
	var price = CalculateMonthlyCost(noForecasts);
	price = ConvertCurrency(price, currency);
	
	$("#calls_price").html(price);
	$("#calls_forecasts").html(noForecasts);
}

function CalculatePriceGeneral() {
	var currency = $("#general_currency").get(0).value;
	var noForecasts = document.getElementById("general_forecastCount").value;
	
	var price = CalculateMonthlyCost(noForecasts);
	var outputPrice = ConvertCurrency(price, currency);
	
	$("#general_result").html(outputPrice);
	
	return false;
}