function validate()
{
var intMthGoal=document.getElementById("MthGoal").value;
var intAvgCommission=document.getElementById("AvgCommission").value;
var intEvyRequest=document.getElementById("EvyRequest").value;
var intEvyAppointment=document.getElementById("EvyAppointment").value;

intMthGoal = trimAll ( intMthGoal ) ;
intAvgCommission = trimAll ( intAvgCommission ) ;
intEvyRequest = trimAll ( intEvyRequest ) ;
intEvyAppointment = trimAll ( intEvyAppointment ) ;

if (IsNumeric(intMthGoal) ==false)
{
alert("Enter a valid number in 12 Month Goal of Prospects/Clients entered into e-Relationship");
return false;
}
if (IsNumeric(intAvgCommission) ==false)
{
alert("Enter a valid number in Average Commission per Sale ");
return false;
}
if (IsNumeric(intEvyRequest) ==false)
{
alert("Enter a valid number in From every 10 requests for info, how many appointments do you expect to make? (How good is your phone script?)");
return false;
}
if (IsNumeric(intEvyAppointment) ==false)
{
alert("Enter a valid number in From every 10 appointments, how many casess do you usually sell? (How good is your closing technique?)");
return false;
}
var intest_response=0.0;
var intInc_Appointments=0.0;
var intRoi=0.0;
var intInc_Paid=0.0;
var places=100;

intest_response=intMthGoal*12*0.025;
intInc_Appointments=intest_response*intEvyRequest/10;
intInc_Paid=intInc_Appointments*intEvyAppointment/10;
intRoi=intInc_Paid*intAvgCommission;

intest_response=Math.round(intest_response*places)/places;
intInc_Appointments=Math.round(intInc_Appointments*places)/places;
intInc_Paid=Math.round(intInc_Paid*places)/places;
intRoi=Math.round(intRoi*places)/places;

intest_response=addCommas(intest_response);
intInc_Appointments=addCommas(intInc_Appointments);
intInc_Paid=addCommas(intInc_Paid);
intRoi=addCommas(intRoi);

document.getElementById("est_response").value=intest_response;
document.getElementById("Inc_Appointments").value=intInc_Appointments;
document.getElementById("Roi").value=intRoi;
document.getElementById("Inc_Paid").value=intInc_Paid;
return false;
}
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;
}
function IsNumeric(strString)
{
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	return objRegExp.test(strString);
 }

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
} 
function ClearData()
{
document.getElementById("MthGoal").value="";
document.getElementById("AvgCommission").value="";
document.getElementById("EvyRequest").value="";
document.getElementById("EvyAppointment").value="";
document.getElementById("est_response").value="";
document.getElementById("Inc_Appointments").value="";
document.getElementById("Roi").value="";
document.getElementById("Inc_Paid").value="";
return false;
}
