/*

Copyright (C) 2004 MX Logic, Inc.  All rights reserved.

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

*/


//                      Aust   Cana   Euro   Japan   Mexi   GrBr   USA    Braz   SAfr   India   Unkn
//                      ----   ----   ----   -----   ----   ----   ----   ----   ----   ----    ----
var gCConv = new Array( 1.75,  1.52,  1.03,  121.90, 9.87,  0.67,  1.00,  2.77,  10.30,  49.00, -1    );
var gCName = new Array( "AUD", "CAD", "EUR", "JPY",  "MXP", "GBP", "USD", "BRL", "ZAR", "INR",  "???" );
var	gROIMax;
var	w2;

// {{{ fixValue()

function fixValue(rawValue, iRightOfDecimal ) {
   	var iCents   = 100*(rawValue-Math.floor(rawValue))+0.5;
   	var newValue = Math.floor(rawValue);
	
	if (iRightOfDecimal == 0) {
		return newValue;
	}

	newValue = newValue + ".";
	newValue += Math.floor(iCents/10);

	if (iRightOfDecimal == 1) {
		return newValue;
	}

	newValue += Math.floor(iCents%10);

   	return newValue;
}

// }}}
// {{{ calcROI()

function calcROI( iSeats, iTimePeriod, iIndex, iRightOfDecimal ){
	var i;
	var iLicense;
	var iROIMax = 0;

	if      (iSeats > 0       && iSeats <= 2500   ) { p=3;    }
	else if (iSeats > 2500    && iSeats <= 5000   ) { p=2.50; }
	else if (iSeats > 5000    && iSeats <= 10000  ) { p=2;    }
	else if (iSeats > 10000   && iSeats <= 100000 ) { p=1.50; }

	iLicense = iSeats * p * 12;
	iROIMax= gCConv[iIndex] * (iLicense/iTimePeriod);
	iROIMax= fixValue(iROIMax, iRightOfDecimal);

	return iROIMax;
}

// }}}
// {{{ showHide()

function showHide(item) {
	switch (item) {
		case 'calc_form': {
			document.getElementById(item).style.visibility      = 'hidden';
			document.getElementById('results').style.visibility = 'visible';
			break;
		}
		case 'results': {
			document.getElementById(item).style.visibility        = 'hidden';
			document.getElementById('calc_form').style.visibility = 'visible';
			break;
		}
	}
}

// }}}
// {{{ spamCalculator()

function spamCalculator(f){
	var iIndex          = 6;
	var iSpamPerDay  	= document.getElementById('scSpamPerDay').options[document.getElementById('scSpamPerDay').selectedIndex].text;
	var iSpamSeconds	= document.getElementById('scSpamSeconds').options[document.getElementById('scSpamSeconds').selectedIndex].text;
	var iEMailEmployees	= document.getElementById('scEmailEmployees').value;
	var iWorkDay	    = document.getElementById('scWorkdays').value;
	var iSalary			= document.getElementById('scSalary').value;
	var iCost 			= (iEMailEmployees * iSpamPerDay * iWorkDay) * (iSalary * (iSpamSeconds/3600));		
	var szPeriod;

	document.getElementById('scYSpamCostCompany').value  = " $" + fixValue(iCost,2);
	document.getElementById('scYSpamCostEmployee').value = " $" + fixValue((iCost/iEMailEmployees), 2);
	document.getElementById('scDSpamCostCompany').value  = " $" + fixValue((iCost/iWorkDay),2);
	document.getElementById('scDSpamCostEmployee').value = " $" + fixValue(((iCost/iEMailEmployees)/iWorkDay),2);
	
	var i = fixValue((iEMailEmployees * (iSpamSeconds/3600) * (iSpamPerDay*365)), 2);
	
	if (i <= 250) {
		szPeriod = "Hours";
	} else {
		i = fixValue((i/24), 2);
		szPeriod = "Days";
	}
		
	document.getElementById('YCProductivity').value = " " + i + " " + szPeriod;	
	document.getElementById('YEProductivity').value = " " + fixValue(((iSpamSeconds/3600) * (iSpamPerDay*365)), 2) + " Hours";
		
	gROIMax = calcROI(iEMailEmployees, (iCost/iWorkDay), iIndex, 0);
	
	if (gROIMax < 1) {
		document.getElementById('szROICompany').value = "MX Logic pays for itself in less than 1 day";
	} else {
		document.getElementById('szROICompany').value = "MX Logic pays for itself in " + gROIMax + " days or less";
	}
}

// }}}
