<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function adCalc(form) {
var ok = 0;

var pci = form.pci.value;
var ctr = form.ctr.value;
ctr = (ctr / 100);
var impressions = form.impressions.value;

var complete = "It looks like you entered all the information already!  With this calculator, you just enter two of the fields and it automatically creates the final field.";

var incomplete = "Oops!  It doesn't appear you entered enough information.  Please follow the instructions to the left to calculate";

if (impressions != "" && ctr != "" && pci != "") {
	//form.ctr.value = ctr;
	yourincome = (impressions * ctr);
	form.income.value = yourincome ;
	yourincome = (yourincome * pci);
	form.income.value =  addSeparatorsNF(Math.round((form.income.value * pci)), '.', '.', ',');

	ctr = (ctr * 2);
	form.income2.value = (impressions * ctr);
	form.income2.value = (form.income2.value * pci);
	form.incomem2.value = addSeparatorsNF(Math.round((form.income2.value - yourincome)), '.', '.', ',');
	form.income2.value =  addSeparatorsNF(Math.round(form.income2.value), '.', '.', ',');
	ctr = (ctr / 2);

	ctr = (ctr * 3);
	form.income3.value = (impressions * ctr);
	form.income3.value = (form.income3.value * pci);
	form.incomem3.value = addSeparatorsNF(Math.round((form.income3.value - yourincome)), '.', '.', ',');
	form.income3.value =  addSeparatorsNF(Math.round(form.income3.value), '.', '.', ',');
	ctr = (ctr / 3);

	ctr = (ctr * 4);
	form.income4.value = (impressions * ctr);
	form.income4.value = (form.income4.value * pci);
	yearly = "<center><br><font size=5 color=red><b>Your annual income<br><u>could</u> be " + addSeparatorsNF(Math.round((form.income4.value * 12)), '.', '.', ',') + "!</b></font></center><br>";
	Yearly.innerHTML = yearly;
	form.incomem4.value = addSeparatorsNF(Math.round((form.income4.value - yourincome)), '.', '.', ',');
	form.income4.value =  addSeparatorsNF(Math.round(form.income4.value), '.', '.', ',');
	ctr = (ctr / 4);
	ok++;
}

if (!ok) alert(incomplete);  // they did not enter at least 2 fields

function addSeparatorsNF(nStr, inD, outD, sep)
{
	dollar = '$';
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return dollar + nStr + nStrEnd;
}
}
//  End -->

