function replaceSign(entry) {
	out = "$";
	add = "";
	temp = "" + entry;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add +
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function replacePct(entry) {
	out = "%";
	add = "";
	temp = "" + entry;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add +
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function replaceCommas(entry) {
	out = ",";
	add = "";
	temp = "" + entry;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add +
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function formatCurrency(num) {
    num=replaceSign(num);
    num=replaceCommas(num);
    num = num.toString().replace(/$|,/g,'');
    if(isNaN(num)) num = "0";
    num = Math.floor(num).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	  num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
    return ('$' + num );
}

function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}


function isMoney(val) {
	tmp = replaceCommas(val);
	var moneyReg = /^\$?\d+$/;
        if ( !tmp.match(moneyReg) ) {
	      return false;
	}
	return true;
}

function isNumber(val){
	var intReg = /^\d+$/;
	if ( !val.match(intReg) ) {
	      return false;
	}
	return true;
}

function isPct(val) {

	var pctReg = /^\d+\.?\d*\%?$/;

	if ( !val.match(pctReg) ) {
		return false;
		}
	return true;
}

function addPct(pct) {
     //if ( isPct(pct) ) {
	pct=replacePct(pct);
	pct=parseFloat(pct);
	return (pct + '%');
     //}
}


function checkForm() {
    var err = "";
       
    if 	( document.findRateFrm.loanPurpose.value == "")
    {
    	  err += "Please select a loan purpose.\n";	  
    }
    
    if 	( document.findRateFrm.state.value == "")
    {
    	  err += "Please select a property location.\n";	  
    }
    
    if 	( !isNumber(document.findRateFrm.propertyValue.value) || document.findRateFrm.propertyValue.value.length ==0) {
    	  err += "Please enter a valid property value.\n";	  
    }
    
    if ( !isNumber(document.findRateFrm.loanAmount.value) || document.findRateFrm.loanAmount.value.length ==0) {
    	  err += "Please enter a valid loan amount.\n";	
    }

    if (err == "") { return true; }
    else {
	  alert(err);
	  return false;
    }
}

