
function getValues() {
  
document.getElementById("b5").value = window.opener.document.getElementById("b5").value;
document.getElementById("b6").value = window.opener.document.getElementById("b6").value;
document.getElementById("b8").value = window.opener.document.getElementById("b8").value;
document.getElementById("b9").value = window.opener.document.getElementById("b9").value;
document.getElementById("b10").value = window.opener.document.getElementById("b10").value;
document.getElementById("b12").value = window.opener.document.getElementById("b12").value;
document.getElementById("b13").value = window.opener.document.getElementById("b13").value;
document.getElementById("b18").value = window.opener.document.getElementById("b18").value;
document.getElementById("b19").value = window.opener.document.getElementById("b19").value;
document.getElementById("b20").value = window.opener.document.getElementById("b20").value;
document.getElementById("b21").value = window.opener.document.getElementById("b21").value;
document.getElementById("b22").value = window.opener.document.getElementById("b22").value;
document.getElementById("b23").value = window.opener.document.getElementById("b23").value;
document.getElementById("b25").value = window.opener.document.getElementById("b25").value;
document.getElementById("b26").value = window.opener.document.getElementById("b26").value;
document.getElementById("b28").value = window.opener.document.getElementById("b28").value;
document.getElementById("b29").value = window.opener.document.getElementById("b29").value;
document.getElementById("b31").value = window.opener.document.getElementById("b31").value;

}


function printIt(){
win=window.open();
win.focus();

win.document.write('<html><head><LINK href="/css/agent.css" type=text/css rel=stylesheet><script language="JavaScript" src="/js/ReturnOnMarketing.js" type="text/JavaScript"></script></head>\n');
win.document.write('<body onLoad="getValues(); this.focus(),window.print();">');
win.document.write('<div align="center"><table><tr><td align="left"><img src="/images/Agent-Insider-Logo.gif" width="204" height="39"><br /><br /></td></tr><TR><TD class=myaccountDivider width=680 bgColor=#e4e4e4 height=24><SPAN class=headerDarkLarge>&nbsp;Return on Marketing Calculator </SPAN></TD><TD width=10>&nbsp;</TD></TR></table><br /><br />\n\n');
win.document.write(document.getElementById("print_area2").innerHTML + '</table><br /><br />\n\n');
win.document.write(document.getElementById("print_area3").innerHTML + '</div>');
win.document.write('</body></html>');
win.document.close();
}

function removeCommas(aNum) {

//remove any commas

aNum=aNum.replace(/,/g,"");

//remove any spaces

aNum=aNum.replace(/\s/g,"");

return aNum;

}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

var errorVal = 0;

function errorValue(error, set) {

  var error;

  if (set == 1)  {
  errorVal = error;
  }

  return errorVal;
}

function checkNum(aNum) {

var isOK=0;

var aNum=aNum+"";

//if the number has one or none decimal points, lastIndexOf and indexOf

//will give the same answer

if (aNum.lastIndexOf(".")!=aNum.indexOf("."))

isOK=1;

else

//here a regular expression is used to check for numbers and decimals

if (aNum.match(/[^0-9.]/))

isOK=2;

//checks to see if a 0 has been entered

if (aNum == 0)

isOK=3;

return isOK;

}

function checkNum2(aNum) {

var isOK=0;

var aNum=aNum+"";

//if the number has one or none decimal points, lastIndexOf and indexOf

//will give the same answer

if (aNum.lastIndexOf(".")!=aNum.indexOf("."))

isOK=1;

else

//here a regular expression is used to check for numbers and decimals

if (aNum.match(/[^0-9.]/))

isOK=2;

//This function is like checkNum but also makes sure the value entered
//is not less that one

if (aNum < 1)

isOK=3;

return isOK;

}

function checkNum3(aNum) {
//This function like checkNum but allows for 0's to be entered

var isOK=0;

var aNum=aNum+"";

//if the number has one or none decimal points, lastIndexOf and indexOf

//will give the same answer

if (aNum.lastIndexOf(".")!=aNum.indexOf("."))

isOK=1;

else

//here a regular expression is used to check for numbers and decimals

if (aNum.match(/[^0-9.]/))

isOK=2;

return isOK;

}

function roundNumber(rnum) {
  var rnum;
  var rlength = 2; // The number of decimal places to round to

  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);

  return newnumber;
}


function Mycalculate(objRef) {
  if (errorValue(0, 0) == 0) {
		objRef.b18.value = addCommas(roundNumber(parseFloat(objRef.b6.value)*parseInt(objRef.b5.value)));
		objRef.b19.value = roundNumber((parseInt(objRef.b8.value)*100)/parseInt(objRef.b5.value));
		objRef.b20.value = roundNumber((parseInt(objRef.b9.value)*100)/parseInt(objRef.b8.value));
		objRef.b21.value = addCommas(roundNumber(parseFloat(objRef.b10.value)*(parseInt(objRef.b8.value)+parseInt(objRef.b9.value))));
		objRef.b22.value = addCommas(roundNumber(parseFloat(removeCommas(objRef.b21.value))*(parseFloat(objRef.b12.value)/100)));
		objRef.b23.value = addCommas(roundNumber(parseFloat(removeCommas(objRef.b22.value))-parseFloat(removeCommas(objRef.b18.value))));
		objRef.b25.value = roundNumber((1/(1-parseFloat(objRef.b13.value)/100)));//Math.round(100*(X))/100
		b25b = 1/(1-parseFloat(objRef.b13.value)/100);
		objRef.b26.value = addCommas(roundNumber(parseFloat(b25b)*parseFloat(removeCommas(objRef.b22.value))));
		objRef.b28.value = addCommas(roundNumber(parseFloat(removeCommas(objRef.b22.value))/parseFloat(removeCommas(objRef.b18.value))*100));
		objRef.b29.value = addCommas(roundNumber(parseFloat(removeCommas(objRef.b26.value))/parseFloat(removeCommas(objRef.b18.value))*100));
		objRef.b31.value = addCommas(roundNumber(parseFloat(removeCommas(objRef.b18.value))/parseFloat(removeCommas(objRef.b26.value))*100));
  }
  
  else {
		objRef.b18.value = "";
		objRef.b19.value = "";
		objRef.b20.value = "";
		objRef.b21.value = "";
		objRef.b22.value = "";
		objRef.b23.value = "";
		objRef.b25.value = "";
		objRef.b26.value = "";
		objRef.b28.value = "";
		objRef.b29.value = "";
		objRef.b31.value = "";
  }

}