function s(num, val) {
amount = num * 1; // amount is the num or NaN
sum = (!num ? 0 : num) * val;  // the sum for that bill or coin

if (isNaN(amount)) { // if the entire is not a number

alert(
"' " + num + " ' is not a valid entry and that field will "
+ "not be included in the total money calculation."
);

return 0;
}
else
return sum; // if it is OK, send sum back
}

// -----------------------------------------------------------------------------------
function SumPriorBalance(form) {
pricash  = s(form.BalPriorCash.value, 1);
priaccts = s(form.BalPriorAccts.value, 1);
priinv   = s(form.BalPriorInventory.value, 1);
priassets= s(form.BalPriorAssets.value, 1);

var priortotal = pricash + priaccts + priinv + priassets;

priortotal = "" + ((Math.round(priortotal * 100)) / 100);

dec1 = priortotal.substring(priortotal.length-3, priortotal.length-2);
dec2 = priortotal.substring(priortotal.length-2, priortotal.length-1);

if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') priortotal += "0";
else priortotal += ".00";
}

form.BalPriorTot1.value = priortotal; // display total amount
document.forms[0].BalPriorTot1.real = document.forms[0].BalPriorTot1.value;

form.BalPriorTot.value = parseFloat(form.BalPriorTot1.value) + parseFloat(form.BalPriorTot2.value);
form.BalPriorTot.value = formatStr(form.BalPriorTot.value);
document.forms[0].BalPriorTot.real = document.forms[0].BalPriorTot.value;
return 0;
}

// ------------------------------------------------------------------------------------
function SumNCBalance(form) {
curland    = s(form.BalCurLand.value, 1);
curequip   = s(form.BalCurEquip.value, 1);
curother   = s(form.BalCurOtherAssets.value, 1);


var priortotal = curland + curequip + curother;

priortotal = "" + ((Math.round(priortotal * 100)) / 100);

dec1 = priortotal.substring(priortotal.length-3, priortotal.length-2);
dec2 = priortotal.substring(priortotal.length-2, priortotal.length-1);

if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') priortotal += "0";
else priortotal += ".00";
}

form.BalCurTot2.value = priortotal; // display total amount
document.forms[0].BalCurTot2.real = document.forms[0].BalCurTot2.value;

form.BalCurTot.value = parseFloat(form.BalCurTot1.value) + parseFloat(form.BalCurTot2.value);
form.BalCurTot.value = formatStr(form.BalCurTot.value);
document.forms[0].BalCurTot.real = document.forms[0].BalCurTot.value;
return 0;
}

// ------------------------------------------------------------------------------------
function SumNCPriorBalance(form) {
priland = s(form.BalPriorLand.value, 1);
priequip = s(form.BalPriorEquip.value, 1);
priother   = s(form.BalPriorOtherAssets.value, 1);


var priorNCtotal = priland + priequip + priother;

priorNCtotal = "" + ((Math.round(priorNCtotal * 100)) / 100);

dec1 = priorNCtotal.substring(priorNCtotal.length-3, priorNCtotal.length-2);
dec2 = priorNCtotal.substring(priorNCtotal.length-2, priorNCtotal.length-1);

if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') priorNCtotal += "0";
else priorNCtotal += ".00";
}

form.BalPriorTot2.value = priorNCtotal; // display total amount
document.forms[0].BalPriorTot2.real = document.forms[0].BalPriorTot2.value;

form.BalPriorTot.value = parseFloat(form.BalPriorTot1.value) + parseFloat(form.BalPriorTot2.value);
form.BalPriorTot.value = formatStr(form.BalPriorTot.value);
document.forms[0].BalPriorTot.real = document.forms[0].BalPriorTot.value;
return 0;
}
// ------------------------------------------------------------------------------------

function SumBalance(form) {
curcash  = s(form.BalCurCash.value, 1); // Each amount is the returned value
curaccts = s(form.BalCurAccts.value, 1);  // for the amount in the s() function
curinv   = s(form.BalCurInventory.value, 1);
curassets = s(form.BalCurAssets.value, 1);


// add up all the amounts
var ttl = curcash + curaccts + curinv + curassets;

// rounds total to two decimal places

ttl = "" + ((Math.round(ttl * 100)) / 100);

dec1 = ttl.substring(ttl.length-3, ttl.length-2);
dec2 = ttl.substring(ttl.length-2, ttl.length-1);

if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') ttl += "0";
else ttl += ".00";
}

form.BalCurTot1.value = ttl; // display total amount
document.forms[0].BalCurTot1.real = document.forms[0].BalCurTot1.value;

form.BalCurTot.value = parseFloat(form.BalCurTot1.value) + parseFloat(form.BalCurTot2.value);
form.BalCurTot.value = formatStr(form.BalCurTot.value);
document.forms[0].BalCurTot.real = document.forms[0].BalCurTot.value;
}
//  End -->


// ------------------------------------------------------------------------------------------------
function formatStr(theStr)
  {
  theStr = "" + ((Math.round(theStr * 100)) / 100);

dec1 = theStr.substring(theStr.length-3, theStr.length-2);
dec2 = theStr.substring(theStr.length-2, theStr.length-1);

if (dec1 != '.') { // adds trailing zeroes if necessary
if (dec2 == '.') ttl += "0";
else theStr += ".00";
}
return theStr;
  }

//-------------------------------------------------------------------------------------------------
function SumAssets(form) {
mystr = parseFloat(form.BalCurTot1.value) + parseFloat(form.BalCurTot2.value);

form.BalCurTot.value = formatStr(mystr);
document.forms[0].BalCurTot.real = document.forms[0].BalCurTot.value
}

// -------------------------------------------------------------------------------------------------
function SumPriorAssets(form) {

mystr =  parseFloat(form.BalPriorTot1.value) + parseFloat(form.BalPriorTot2.value);
form.BalPriorTot.value = formatStr(mystr);
document.forms[0].BalPriorTot.real = document.forms[0].BalPriorTot.value;

}


// --------------------------------------------------------------------------------------------------
function SumLia(form) {
val = s(form.LiaCurAccounts.value, 1) + s(form.LiaCurAccrued.value, 1) + s(form.LiaCurLngDebit.value, 1) + s(form.LiaCurOthers.value, 1);
form.LiaCurTot1.value = formatStr(val);

val = s(form.LiaPriorAccounts.value, 1) + s(form.LiaPriorAccrued.value, 1) + s(form.LiaPriorLngDebit.value, 1) + s(form.LiaPriorOthers.value, 1);
form.LiaPriorTot1.value = formatStr(val);

document.forms[0].LiaCurTot1.real = document.forms[0].LiaCurTot1.value;
document.forms[0].LiaPriorTot1.real = document.forms[0].LiaPriorTot1.value;

form.LiaCurTot.value = parseFloat(form.LiaCurTot1.value) + parseFloat(form.LiaCurTot2.value);
form.LiaPriorTot.value = parseFloat(form.LiaPriorTot1.value) + parseFloat(form.LiaPriorTot2.value);

// add up liability + equity
form.EqLiaTotCur.value   = parseFloat(form.LiaCurTot.value) + parseFloat(form.EqCurTot.value);
form.EqLiaTotPrior.value = parseFloat(form.LiaPriorTot.value) + parseFloat(form.EqPriorTot.value);
document.forms[0].EqLiaTotCur.real   = document.forms[0].EqLiaTotCur.value;
document.forms[0].EqLiaTotPrior.real = document.forms[0].EqLiaTotPrior.value;
form.EqLiaTotCur.value   = formatStr(form.EqLiaTotCur.value);
form.EqLiaTotPrior.value = formatStr(form.EqLiaTotPrior.value);


form.LiaCurTot.value = formatStr(form.LiaCurTot.value);
form.LiaPriorTot.value = formatStr(form.LiaPriorTot.value);

document.forms[0].LiaPriorTot.real = document.forms[0].LiaPriorTot.value;
document.forms[0].LiaCurTot.real = document.forms[0].LiaCurTot.value;



}


// ----------------------------------------------------------------------------------------------------
function SumLTLia(form) {
val = s(form.LiaCurLngDebit2.value, 1) + s(form.LiaCurDiffTaxes.value, 1) + s(form.LiaCurOthers2.value, 1);
form.LiaCurTot2.value = formatStr(val);

val = s(form.LiaPriorLngDebit2.value, 1) + s(form.LiaPriorDiffTaxes.value, 1) + s(form.LiaPriorOthers2.value, 1);
form.LiaPriorTot2.value = formatStr(val);

document.forms[0].LiaCurTot2.real = document.forms[0].LiaCurTot2.value;
document.forms[0].LiaPriorTot2.real = document.forms[0].LiaPriorTot2.value;


form.LiaCurTot.value = s(form.LiaCurTot1.value) + s(form.LiaCurTot2.value);
form.LiaPriorTot.value = s(form.LiaPriorTot1.value) + s(form.LiaPriorTot2.value);

//alert(form.LiaCurTot1.value);
								
form.LiaCurTot.value = parseFloat(form.LiaCurTot1.value) + parseFloat(form.LiaCurTot2.value);
form.LiaPriorTot.value = parseFloat(form.LiaPriorTot1.value) + parseFloat(form.LiaPriorTot2.value);

// add up liability + equity
form.EqLiaTotCur.value   = parseFloat(form.LiaCurTot.value) + parseFloat(form.EqCurTot.value);
form.EqLiaTotPrior.value = parseFloat(form.LiaPriorTot.value) + parseFloat(form.EqPriorTot.value);
document.forms[0].EqLiaTotCur.real   = document.forms[0].EqLiaTotCur.value;
document.forms[0].EqLiaTotPrior.real = document.forms[0].EqLiaTotPrior.value;
form.EqLiaTotCur.value   = formatStr(form.EqLiaTotCur.value);
form.EqLiaTotPrior.value = formatStr(form.EqLiaTotPrior.value);

form.LiaCurTot.value = formatStr(form.LiaCurTot.value);
form.LiaPriorTot.value = formatStr(form.LiaPriorTot.value);
document.forms[0].LiaPriorTot.real = document.forms[0].LiaPriorTot.value;
document.forms[0].LiaCurTot.real = document.forms[0].LiaCurTot.value;
}


// -------------------------------------------------------------------------------------------------
function SumEquity(form) {
var val = s(form.EqCurStock.value, 1) + s(form.EqCurCapital.value, 1) + s(form.EqCurRetEarnings.value, 1);

form.EqCurTot.value = formatStr(val);

val = s(form.EqPriorStock.value, 1) + s(form.EqPriorCapital.value, 1) + s(form.EqPriorRetEarnings.value, 1);

form.EqPriorTot.value = formatStr(val);

// add up liability + equity
form.EqLiaTotCur.value   = parseFloat(form.LiaCurTot.value) + parseFloat(form.EqCurTot.value);
form.EqLiaTotPrior.value = parseFloat(form.LiaPriorTot.value) + parseFloat(form.EqPriorTot.value);
document.forms[0].EqLiaTotCur.real   = document.forms[0].EqLiaTotCur.value;
document.forms[0].EqLiaTotPrior.real = document.forms[0].EqLiaTotPrior.value;
form.EqLiaTotCur.value   = formatStr(form.EqLiaTotCur.value);
form.EqLiaTotPrior.value = formatStr(form.EqLiaTotPrior.value);

document.forms[0].EqPriorTot.real = document.forms[0].EqPriorTot.value;
document.forms[0].EqCurTot.real = document.forms[0].EqCurTot.value;

}


// -------------------------------------------------------------------------------------------------
function SumIncome(form) {
var val = s(form.InCurRev.value, 1) + s(form.InCurDep.value, 1) + s(form.InCurOperaEx.value, 1) + 
          s(form.InCurOperaIn.value, 1) + s(form.InCurPlusIn.value, 1) + s(form.InCurLsEx.value, 1) + 
		  s(form.InCurBeforeTax.value, 1) + s(form.InCurrent.value, 1) + 
		  s(form.InCurDiffered.value, 1);
form.InCurTot.value = formatStr(val);

val = s(form.InPriorRev.value, 1) + s(form.InPriorDep.value, 1) + s(form.InPriorOperaEx.value, 1) + 
          s(form.InPriorOperaIn.value, 1) + s(form.InPriorPlusIn.value, 1) + s(form.InPriorLsEx.value, 1) + 
		  s(form.InPriorBeforeTax.value, 1) + s(form.InPrior.value, 1) + 
		  s(form.InPriorDiffered.value, 1);
form.InPriorTot.value = formatStr(val);
document.forms[0].InPriorTot.real = document.forms[0].InPriorTot.value;
document.forms[0].InCurTot.real = document.forms[0].InCurTot.value;
}


// Update Firm Name
function UpdateFirmname(form) {
if (form.FirmName.value != "")
  form.BakFirmName.value = form.FirmName.value;
}

// ------------------------------------------------------------------------------------------------
function ValidateForm(form) {
	if (document.appForm.CreditAmount.value == "")
	{
	alert("Credit Amount is required!");
	document.appForm.CreditAmount.focus();
	return false;
	}
	if (document.appForm.FirmName.value=="")
	{
	alert("Firm Name is required!");
	document.appForm.FirmName.focus();
	return false;
	}
	if (document.appForm.FirmStreet.value == "")
	{
	alert("Firm Street Address is required!");
	document.appForm.FirmStreet.focus();
	return false;
	}
	if (document.appForm.FirmCity.value == "")
	{
	alert("Firm City Address is required!");
	document.appForm.FirmCity.focus();
	return false;
	}
	if (document.appForm.FirmState.value == "")
	{
	alert("Firm State is required!");
	document.appForm.FirmState.focus();
	return false;
	}
	if (document.appForm.FirmZip.value == "")
	 {
	 alert("Firm ZIP Code is required!");
	 document.appForm.FirmZip.focus();
	 return false;
	 }
	if (document.appForm.FirmPhone.value == "")
	 {
	 alert("Firm Phone Number is required!");
	 document.appForm.FirmPhone.focus();
	 return false;
	 }
	if (document.appForm.FirmFax.value == "")
	  {
	  alert("Firm Fax is required!");
	  document.appForm.FirmFax.focus();
	  return false;
	  }
	if (document.appForm.FirmEmail.value == "")
	  {
	  alert("Firm Email is required!");
	  document.appForm.FirmEmail.focus();
	  return false;
	  }
	if (document.appForm.DateOwnerShip.value == "")
	{
	alert("Date of Ownership is required!");
	document.appForm.DateOwnerShip.focus();
	return false;
	}
	
	if (document.appForm.BankName.value == "")
	{
	alert("Bank Name is required!");
	document.appForm.BankName.focus();
	return false;
	}
	
	if (document.appForm.BankCity.value == "")
	{
	alert("Bank City Address is required!");
	document.appForm.BankCity.focus();
	return false;
	}
	
	if (document.appForm.BankState.value == "")
	{
	alert("Bank State is required!");
	document.appForm.BankState.focus();
	return false;
	}
	
	if (document.appForm.BankPhone.value == "")
	{
	alert("Bank Phone Number is required!");
	document.appForm.BankPhone.focus();
	return false;
	}
	
	if (document.appForm.IncorpState.value == "") {
	  alert("Incorpated State is required!");
	  document.appForm.IncorpState.focus();
	  return false;
	  }
	  
	if (document.appForm.Bankruptcy[0].checked)
	{
	if (document.appForm.DateFiled.value == "") {
	  alert("Enter the filing date for your bankruptcy!");
	  document.appForm.DateFiled.focus();
	  return false;
	  }
	}
	
	
	if (document.appForm.Subsidiary[0].checked)
	{
	if (document.appForm.SubParentName.value =="") {
	alert("Subsidiary Parent Name is required!");
	document.appForm.SubParentName.focus();
	return false;
	} 
	if (document.appForm.SubOwnDate.value == "") {
	  alert("Subsidiary Ownership Date is required!");
	  document.appForm.SubOwnDate.focus();
	  return false;
	  }
	if (document.appForm.SubStreet.value == "") {
	 alert("Subsidiary Street Address is required!");
	 document.appForm.SubStreet.focus();
	 return false;
	 }
	if (document.appForm.SubCity.value == "") {
	 alert("Subsidiary City Name is required!");
	 document.appForm.SubCity.focus();
	 return false;
	 }
	if (document.appForm.SubState.value == "") {
	 alert("Subsidiary State is required!");
	 document.appForm.SubState.focus();
	 return false;
	 }
	if (document.appForm.SubPhone.value == "") {
	 alert("Subsidiary Phone Number is required!");
	 document.appForm.SubPhone.focus();
	 return false;
	 }
	}  

if (CheckPPP() == false)
  return false;

return true;
}


// -------------------------------------------------------------------------------------------------
function CheckPPP() {

if ((document.appForm.Guarantor.value != "")&&(document.appForm.Guarantor.value != " "))
   {
   if (document.appForm.PartOwened.value == "") {
      alert("Percent Owned is required!");
	  document.appForm.PartOwened.focus();
	  return false;
	  }
	if (document.appForm.PartStreet.value == "") {
	   alert("Proprietor's Street Address is required!");
	   document.appForm.PartStreet.focus();
	   return false;
	   }
	if (document.appForm.PartCity.value == "") {
	  alert("Proprietor's City is required!");
	  document.appForm.PartCity.focus();
	  return false;
	  }
	if (document.appForm.PartState.value == "") {
	  alert("Proprietor's State is required!");
	  document.appForm.PartState.focus();
	  return false;
	  }
	if (document.appForm.PartZip.value == "") {
	  alert("Proprietor's Zip code is required!");
	  document.appForm.PartZip.focus();
	  return false;
	  }
	if (document.appForm.YrsAtAddress.value == "") {
	  alert("Proprietor's Years at Address is required!");
	  document.appForm.YrsAtAddress.focus();
	  return false;
	  }
    
	}
  return true;
  }
	

// -------------------------------------------------------------------------------------------------
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
