function MyCheckEnteredValue(element) {
	var lField = ltrim(rtrim(String(element.value)));

    myReg=new RegExp("^[0-9]*\\.?[0-9]*$"); 
        if (!(myReg.test(lField) && lField!='.')) {
			alert("Please enter valid numerical data in all fields!");
			return false;
		}

	element.value=lField; 
	return true;
}


function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }
  return argvalue;
}

function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }
    return argvalue;
}

 function trim(str)
{
     return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}  

function count(form) 
{
var tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp11
  if ( trim(document.getElementById('income').value) != "" &&  trim(document.getElementById('other').value) != "" &&  trim(document.getElementById('taxes').value) != "" &&  trim(document.getElementById('insurance').value) != "" &&  trim(document.getElementById('auto').value) != "" &&  trim(document.getElementById('cards').value) != "" &&  trim(document.getElementById('term').value) != "" &&  trim(document.getElementById('rate').value) != ""){
									 
    tmp12 = Math.round(eval(document.getElementById('income').value * .28) + eval(document.getElementById('other').value * .28) - document.getElementById('taxes').value - document.getElementById('insurance').value);

    tmp13 = Math.round(eval(document.getElementById('income').value * .36) + eval(document.getElementById('other').value * .36) - document.getElementById('taxes').value -  document.getElementById('insurance').value - document.getElementById('auto').value - document.getElementById('cards').value);

      if (tmp12>tmp13) {
      document.getElementById('payment').value = tmp13
      }
      else {
        document.getElementById('payment').value= tmp12
      }

    tmp1 = parseFloat(document.getElementById('rate').value);
	if (isNaN(tmp1)) tmp1=0;
    tmp2 = parseFloat(document.getElementById('term').value);
	if (isNaN(tmp2)) tmp2=0;
    tmp3 = parseFloat(document.getElementById('payment').value);
	if (isNaN(tmp3)) tmp3=0;
    tmp4 = parseFloat(tmp1 / 1200); 
    tmp5 = parseFloat(tmp2 * 12);
    tmp6 = parseFloat(1 + tmp4);
    tmp7 = parseFloat(Math.pow(tmp6, tmp5));
    tmp8 = parseFloat(1 / tmp7);
    tmp9 = parseFloat(1 - tmp8);
    tmp10 = parseFloat(tmp9 / tmp4);
    tmp11 = parseFloat(tmp3 * tmp10);
    document.getElementById('amount').value = Math.round(tmp11);

    }
else
	{
		alert("Please enter valid numerical data in all fields!");
		return false;
	}
}

function newWindow() {     window.open("explain.html","Window4","toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=0,copyhistory=0,width=500,height=250");    }

