function checkFields(){
	state=document.getElementById("state").value;
	loanAmount=document.getElementById("loanAmount").value;
	loanAmount = loanAmount.replace(/\,/g,"");
	loanAmount = loanAmount.replace("$","");
	errorFlag=false;
	document.getElementById("loanAmount").value=loanAmount;
	
	document.getElementById("state-error").innerHTML="";
	document.getElementById("loanAmount-error").innerHTML="";
	
	if(state==""){
		document.getElementById("state-error").innerHTML="&nbsp;Required Field";
		errorFlag=true;
	}	
	if(loanAmount==""){	
		document.getElementById("loanAmount-error").innerHTML="&nbsp;Required Field";
		errorFlag=true;
	}else if(isNaN(loanAmount.replace(",",""))){
		document.getElementById("loanAmount-error").innerHTML="&nbsp;Invalid Loan Amount";
		errorFlag=true;
	}
	
	if(errorFlag==true)
		return false;
	else
		return true;
}
function formatDollarAmount(/*String number*/ str)
{
	str = str.replace(/[^0-9.]/g, "");
	num = parseFloat(str);
	if(!isNaN(num)){
		num = Math.round(num);
		str = num+"";
		var RE = /(\d+)(\d{3})/;
		while (RE.test(str)){
			str = str.replace(RE, '$1' + ',' + '$2');
		}
		return "$"+str;
	}
	else
		return "";
}

function formatLoanAmount(/*Form input object*/ obj)
{
	if(obj.value && obj.value.length > 3){
		obj.value = formatDollarAmount(obj.value);
	}
}
