<!-- calculate the price based on selections of duration and packages selected
function CalcPrice()
{
var sels,i,mult,years,months,price,total,yeartotal;
// Loop through all select statements, check if the variable name begins with packagevar
	sels=document.getElementsByTagName('select');
	total = yeartotal = 0;

	var period=document.getElementById(timevar);
	months = parseInt(period.value);
	if (!months)											// in case it is already a number
		months = period.value;
	mult = this.GetMult(months);
	if (mult != undefined && months)
	{
		if (!packagevar)
			total = 'Error Package';
		else
		{
			for(i=0;i<sels.length;i++)
			{
				if (sels[i].id.substring(0, packagevar.length) == packagevar)
				{
					price = packagelist[sels[i].value];
					if (price == undefined)
					{
						total = 'Error Package';
						break;
					}
					months = Math.round((months+.00049) * 1000) / 1000;	// round to the nearest thousands
					years = months / 12;
					years = Math.round((years+.00049) * 1000) / 1000;	// round to the nearest thousands
					price *= years * (1 + mult);	// modify by the multiplier
					price *= discount;
					total += Math.round((price+.0049) * 100) / 100;
				}
			}
			yeartotal = total * (12 / months);
		}
	}
	else
		total = 'Error Months ' + months + ':' + mult;
	if (!textname)											// if no place to store the text, pop up a message
		alert('Error Text');
	document.getElementById(textname).innerHTML = ToDollar(total);
	if (showyear)
		document.getElementById(showyear).innerHTML = ToDollar(yeartotal);
}

function ShowPrice()
{
var mult,years,months, total,yeartotal;
// Loop through all select statements, check if the variable name begins with packagevar
	total = yeartotal = 0;
	var period=document.getElementById(timevar);
	months = parseInt(period.value);
	if (!months)											// in case it is already a number
		months = period.value;
	mult = this.GetMult(months);
	var price=fixedprice;
	if (mult != undefined && months)
	{
		months = Math.round((months+.00049) * 1000) / 1000;	// round to the nearest thousands
		years = months / 12;
		years = Math.round((years+.00049) * 1000) / 1000;	// round to the nearest thousands
		price *= years * (1 + mult);	// modify by the multiplier
		price *= discount;
		yeartotal = price * (12 / months);
	}
	else
		price = 'Error Months ' + months + ':' + mult;
	if (!textname)											// if no place to store the text, pop up a message
		alert('Error Text');
	document.getElementById(textname).innerHTML = ToDollar(price);
	if (showyear)
		document.getElementById(showyear).innerHTML = ToDollar(yeartotal);
}

function GetMult(months)
{
	months = parseFloat(months);
	months += parseFloat(timeleft);					// add in the current time for the multiple
	mult = 1;
	if (months >= 3)
		mult = 3;
	if (months >= 9)
		mult = 12;
	if (months >= 12+6)
		mult = 24;
	if (months >= 24+6)
		mult = 36;
	return timelist[mult];
}

function ToDollar(num)
{
	if (isNaN(num)) return(num); 						// if not a number, return the string
	var dollarstring = new String(num);				// get ready to add trailing zeros
	if (Number(num) || dollarstring == '0')
	{
		var minus = num < 0 ? '-' : '';
		num = Math.abs(num);
		num = Math.round(num * 100) / 100;			// trim to 2 decimal places
		var dollarstring = new String(num);			// get ready to add trailing zeros
		// make sure that there are trailing zeros after the decimal point
		if (((num*100) % 100) < .1)
			dollarstring += '.00';
		else
			if (((num*100) % 10) < .1)
				dollarstring += '0';
		dollarstring = minus + dollarstring;
	}
	return '$'+CommaSeparate(dollarstring);
}

function CommaSeparate(amount)
{
	var delimiter = ","; 								// replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(!d || d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

//-->

