/* - - - - - - - - - - - - - - - - - - - - -

Title : supportCalc.js
Description : Displays a specified quantity of random testimonials.
If passed a two letter state abbreviation, will display a testimonial 
named with that abbreviation. If none exists, a random one is displayed.

URL : http://www.supportcollectors.com/_js/supportCalc.js

Created : 06-01-2007
Modified : 06-01-2007

- - - - - - - - - - - - - - - - - - - - - */
function isInt(string)
{
	var valu=parseInt(string);
	if (string=='')
		return true;
	else
		return (valu>=0);
};
function isFloat(string)
{
	var valu=parseFloat(string);
	if (string=='')
		return true;
	else
		return (valu>=0);
};

function calculate() {

	var nA=new String(document.forms[0].txtA.value);
	var nB=new String(document.forms[0].txtB.value);
	var nC;
	var nE;

//get rid of commas, they're just trouble
	nA=nA.replace(',','');
	nB=nB.replace(',','');

//get the Frequency into a number
   if (document.forms[0].txtC.selectedIndex==0) //12 - Monthly
		nC=parseInt('12');
	else
	if (document.forms[0].txtC.selectedIndex==1) //26 - Bi-Weekly
		nC=parseInt('26');
	else
	if (document.forms[0].txtC.selectedIndex==2) //52 - Weekly
		nC=parseInt('52');


//get the number part
	nA=parseFloat(nA);
	nB=parseFloat(nB);
	nC=parseFloat(nC);

	nC=Math.round(nC);

	if (document.forms[0].selState.selectedIndex==0) //alabama
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==1) //alaska
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==2) //arizona
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==3) //arkansas
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==4) //cal
		nE=parseFloat('0.0975');
	else
	if (document.forms[0].selState.selectedIndex==5) //colo
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==6) //conn
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==7) //del
		nE=parseFloat('0.1025');
	else
	if (document.forms[0].selState.selectedIndex==8) //dc
		nE=parseFloat('0.06');
	else
	if (document.forms[0].selState.selectedIndex==9) //fla
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==10) //ga
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==11) //hawaii
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==12) //idaho
		nE=parseFloat('0.10125');
	else
	if (document.forms[0].selState.selectedIndex==13) //illinois
		nE=parseFloat('0.09');
	else
	if (document.forms[0].selState.selectedIndex==14) //indiana
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==15) //iowa
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==16) //kan
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==17) //ky
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==18) //louisiana
		nE=parseFloat('0.0673');
	else
	if (document.forms[0].selState.selectedIndex==19) //maine
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==20) //maryland
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==21) //mass
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==22) //mich
		nE=parseFloat('0.0606');
	else
	if (document.forms[0].selState.selectedIndex==23) //minn
		nE=parseFloat('0.05');
	else
	if (document.forms[0].selState.selectedIndex==24) //mississippi
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==25) //missouri
		nE=parseFloat('0.09');
	else
	if (document.forms[0].selState.selectedIndex==26) //montana
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==27) //nebraska
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==28) //nevada
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==29) //n hampshire
		nE=parseFloat('0.0695');
	else
	if (document.forms[0].selState.selectedIndex==30) //n jersey
		nE=parseFloat('0.05');
	else
	if (document.forms[0].selState.selectedIndex==31) //n mexico
		nE=parseFloat('0.0875'); 
	else

	if (document.forms[0].selState.selectedIndex==32) //ny
		nE=parseFloat('0.09');
	else
	if (document.forms[0].selState.selectedIndex==33) //n carolina
		nE=parseFloat('0.08');
	else
	if (document.forms[0].selState.selectedIndex==34) //n dakota
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==35) //ohio
		nE=parseFloat('0.0');
	else
	if (document.forms[0].selState.selectedIndex==36) //ok
		nE=parseFloat('0.0873');
	else
	if (document.forms[0].selState.selectedIndex==37) //oregon
		nE=parseFloat('0.09');
	else
	if (document.forms[0].selState.selectedIndex==38) //penn
		nE=parseFloat('0.06');
	else
	if (document.forms[0].selState.selectedIndex==39) //puerto rico
		nE=parseFloat('0.0875');
	else
	if (document.forms[0].selState.selectedIndex==40) //rhode island
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==41) //s carolina
		nE=parseFloat('0.14');
	else
	if (document.forms[0].selState.selectedIndex==42) //s dakota
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==43) //tenn
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==44) //tex
		nE=parseFloat('0.06');
	else
	if (document.forms[0].selState.selectedIndex==45) //utah
		nE=parseFloat('0.06513');
	else
	if (document.forms[0].selState.selectedIndex==46) //vermont
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==47) //virg
		nE=parseFloat('0.09');
	else
	if (document.forms[0].selState.selectedIndex==48) //wash
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==49) //w virginia
		nE=parseFloat('0.1');
	else
	if (document.forms[0].selState.selectedIndex==50) //wisc
		nE=parseFloat('0.12');
	else
	if (document.forms[0].selState.selectedIndex==51) //wyom
		nE=parseFloat('0.1');

	
	var nIPPayment=parseFloat((nB*nE)/nC);
	var nPayments=parseFloat(((nA/nB)*((nA/nB)+parseInt("1")))/parseInt("2"));
	var nIOwed=parseFloat(nIPPayment * nPayments);
	var nArreage=parseFloat(nIOwed + nA);

	
	if (!isFloat(document.forms[0].txtA.value) || !isFloat(document.forms[0].txtB.value) || (document.forms[0].txtA.value=='' || document.forms[0].txtB.value==''))
	{
		alert('Please enter ONLY POSITIVE NUMBERS into the text boxes.');
	}
	else	
	{	
		document.forms[0].txtA.value=nA;
		document.forms[0].txtB.value=nB;
		<!-- document.forms[0].txtC.value=nC; -->
		document.forms[0].txtF.value="$"+Math.round(nIPPayment*100)/100;
		document.forms[0].txtG.value=Math.round(nPayments*100)/100;
		document.forms[0].txtH.value="$"+Math.round(nIOwed*100)/100;
		document.forms[0].txtI.value="$"+Math.round(nArreage*100)/100;
		alert('New values calculated!');
	}
}