// Generic round function which takes a number, and number of decimal points
function round(number, decimals)
{
	var mult = 10;

	for (decimals; decimals > 1; decimals--)
	{
		mult *= mult;
	}
	var x = Math.round(number*mult)/mult;
	x = Math.ceil(x);
	return x;
}

// F-Prot Antivirus for windows commercial license
function calc_win_comm(numfield, pricefield)
{
	var multip = 1;
	var subtotal = 0;
	var fpwincomm = parseInt(document.form1[numfield].value);
	if (multiplier)
	{
		multip = multiplier;
	}

	if (fpwincomm > 0)
	{
		if (fpwincomm > 2500)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza di F-Prot Antivirus per Windows commerciale,  per pių di 2500 computers.");
			document.form1[numfield].value = 2500;
			fpwincomm = 2500;
		}
		
		subtotal = 0;
		if (fpwincomm > 100)
		{
			subtotal += 50;
			fpwincomm -= 10;

			subtotal += 40*4;
			fpwincomm -= 40;

			subtotal += 50*3;
			fpwincomm -= 50;

			subtotal += fpwincomm*2;
		}
		else if (fpwincomm > 50)
		{
			subtotal += 50;
			fpwincomm -= 10;

			subtotal += 40*4;
			fpwincomm -= 40;

			subtotal += fpwincomm*3;
		}
		else if (fpwincomm > 10)
		{
			subtotal += 50;
			fpwincomm -= 10;

			subtotal += fpwincomm*4;
		}
		else if (fpwincomm < 11)
		{
			subtotal += 50;
		}
		
		//alert(subtotal)
		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}

// F-Prot Antivirus for windows personal license
function calc_win_pers(numfield, pricefield)
{
	var multip = 1;
	var subtotal = 0;
	var fpwinpers = parseInt(document.form1[numfield].value);
	if (multiplier)
	{
		multip = multiplier;
	}

	if (fpwinpers > 0)
	{
		if (fpwinpers > 9)
		{
			document.form1[numfield].value = 9;
			fpwinpers = 9;
		}
		subtotal = 0;
		subtotal += fpwinpers*29;

		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}

// F-Prot Antivirus for Exchange Commercial license
function calc_exch_c(numfield, pricefield)
{
	var subtotal = 0;
	var fpexchc = parseInt(document.form1[numfield].value);
	var multip = 1;
	if (multiplier)
	{
		multip = multiplier;
	}

	if (fpexchc > 0)
	{
		if (fpexchc > 500)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza di F-Prot Antivirus per Exchange per pių di 500 caselle e-mail.");
			document.form1[numfield].value = 500;
			fpexchc = 500;
		}


		subtotal = 0;
		if (fpexchc > 0 && fpexchc < 6)
		{
			subtotal = 190;
			document.form1[numfield].value = 5;
		}
		else if (fpexchc > 5 && fpexchc < 11)
		{
			subtotal = 350;
		}
		else if (fpexchc > 10 && fpexchc < 25)
		{
			subtotal = 580;
		}
		else if (fpexchc > 24 && fpexchc < 50)
		{
			subtotal = 860;
		}
		else if (fpexchc > 49 && fpexchc < 75)
		{
			subtotal = 1100;
		}
		else if (fpexchc > 74 && fpexchc < 100)
		{
			subtotal = 1650;
		}
		else if (fpexchc > 99 && fpexchc < 200)
		{
			subtotal = 2200;
		}
		else if (fpexchc > 199 && fpexchc < 300)
		{
			subtotal = 3400;
		}
		else if (fpexchc > 299 && fpexchc < 400)
		{
			subtotal = 4300;
		}
		else if (fpexchc > 399 && fpexchc < 500)
		{
			subtotal = 4990;
		}
		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}

// F-Prot Antivirus for DOS Commercial license
function calc_dos_c(numfield, pricefield)
{
	var subtotal = 0;
	var fpdoscomm = parseInt(document.form1[numfield].value);
	var multip = 1;
	if (multiplier)
	{
		multip = multiplier;
	}

	if (fpdoscomm > 0)
	{
		if (fpdoscomm > 2500)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza commerciale F-Prot Antivirus per Dos per pių di 2500 computers.");
			document.form1[numfield].value = 2500;
			fpdoscomm = 2500;
		}

		subtotal = 0;
		if (fpdoscomm < 20)
		{
			subtotal += 29;
		}
		else
		{
			subtotal += 29;
			fpdoscomm -= 20;

			subtotal += fpdoscomm;
		}
		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}

// F-Prot Antivirus for Linux Fileserver
function calc_lin_f(numfield, pricefield)
{
	var subtotal = 0;
	var fplinf = parseInt(document.form1[numfield].value);
	var multip = 1;
	if (multiplier)
	{
		multip = multiplier;
	}
	var prices = Array();
	
	prices[0] = -1;
	prices[1] = 299;
	prices[2] = 580;
	prices[3] = 820;
	prices[4] = 999;
	prices[5] = 1200;

	if (fplinf > 0)
	{
		if (fplinf > 5)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza F-Prot Antivirus per Linux/BSD/Solaris File Server per pių di 5 servers.");
			document.form1[numfield].value = 5;
			fplinf = 5;
		}

		subtotal = prices[fplinf];
		subtotal = round(subtotal*multip, 2);

		document.form1[pricefield].value = subtotal;
		document.form1[numfield].value = fplinf;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}


function calc_lin_m(numfield, pricefield)
{
	var subtotal = 0;
	var fplinm = parseInt(document.form1[numfield].value);
	var multip = 1;
	if (multiplier)
	{
		multip = multiplier;
	}
	var prices = Array(0, 297, 297, 297, 297, 297, 297, 297, 297, 297,
			   297, 297, 297, 297, 297, 297, 297, 297, 297,
			   297, 297, 297, 297, 297, 297, 297, 302, 306,
			   311, 316, 320, 325, 330, 335, 340, 345, 351,
			   356, 361, 367, 373, 378, 384, 390, 396, 402,
			   408, 414, 420, 427, 433, 440, 447, 453, 460,
			   467, 474, 482, 489, 496, 504, 512, 520, 527,
			   535, 544);
	if (fplinm > 0)
	{
		if (fplinm > 300)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza F-Prot Antivirus per Linux/BSD/Solaris Mail Server license per pių di 300 mailboxes.");
			document.form1[numfield].value = 300;
			fplinm = 300;
		}

		if (fplinm < 10)
		{
			alert("Il minimo di licenze F-Prot Antivirus per Linux/BSD Mail Server č per 10 mailboxes.");
			document.form1[numfield].value = 10;
			fplinm = 10;
		}
		switch(fplinm)
		{
			case 10:
				subtotal = 130;
				break;
			case 24:
				subtotal = 250;
				break;
			case 49:
				subtotal = 399;
				break;
			case 99:
				subtotal = 499;
				break;
			case 199:
				subtotal = 799;
				break;
			case 299:
				subtotal = 1099;
				break;
			default:
				alert("fplinm = " + fplinm);
				break;
		}
		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{

		document.form1[pricefield].value = 0;
		document.form1[numfield].value = 0;
	}
	return subtotal;
}

function calc_lin_w(numfield, pricefield)
{
	var subtotal = 0;
	var fplinw = parseInt(document.form1[numfield].value);
	var multip = 1;
	if (multiplier)
	{
		multip = multiplier;
	}
	var prices = Array();
	prices[1] = 29;
	prices[3] = 75;
	prices[5] = 120;
	prices[10] = 180;
	prices[25] = 370;
	prices[50] = 730;
	prices[100] = 1190;
	prices[200] = 1900;

	if (fplinw > 0)
	{
		if (fplinw > 200)
		{
			alert("Contattaci direttamente al seguente indirizzo info@f-prot.it per acquistare una licenza F-Prot Antivirus per Linux/BSD/Solaris Workstation per pių di 200 workstations.");
			document.form1[numfield].value = 200;
			fplinw = 200;
		}

		if (fplinw > 100) {
			subtotal = prices[200];
		}
		else if (fplinw > 50) {
			subtotal = prices[100];
		}
		else if (fplinw > 25) {
			subtotal = prices[50];
		}
		else if (fplinw > 10) {
			subtotal = prices[25];
		}
		else if (fplinw > 5) {
			subtotal = prices[10];
		}
		else if (fplinw > 3) {
			subtotal = prices[5];
		}
		else if (fplinw > 1) {
			subtotal = prices[3];
		}
		else if (fplinw == 1) {
			subtotal = prices[1];
		}
		subtotal = round(subtotal*multip, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}



function calc_cd(numfield, pricefield)
{
	var subtotal = 0;
	var valore = parseInt(document.form1[numfield].value);
	if (valore > 0)
	{
		subtotal = 0;
		subtotal = round(valore*costocd, 2);
		document.form1[pricefield].value = subtotal;
	}
	else
	{
		document.form1[numfield].value = 0;
		document.form1[pricefield].value = 0;
	}
	return subtotal;
}

function calc_bsd_f(numfield, pricefield)
{
	return calc_lin_f(numfield, pricefield);
}

function calc_bsd_m(numfield, pricefield)
{
	return calc_lin_m(numfield, pricefield);
}
function calc_bsd_w(numfield, pricefield)
{
	return calc_lin_w(numfield, pricefield);
}

function calc_sol_f(numfield, pricefield)
{
	return calc_lin_f(numfield, pricefield);
}
function calc_sol_m(numfield, pricefield)
{
	return calc_lin_m(numfield, pricefield);
}
function calc_sol_w(numfield, pricefield)
{
	return calc_lin_w(numfield, pricefield);
}

