function setCheck(obj)
{
if (obj.checked)
     {
          obj.firstChild.innerHTML = ""
     }
     else
     {
          obj.firstChild.innerHTML = "a"
     }
obj.checked =!obj.checked;
}

//format the number
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	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 (((sign)?'':'-') + '$' + num + '.' + cents);
}

function round(number,X) {
	//round number to X decimal places, defaults to 2
	if (X != 0)
		X = (!X ? 2 : X);
	//alert(parseInt(number))
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function commaFormat(num) {
	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; //(((sign)?'':'-') + num + '.' + cents);
}

function showhide(id){ 
if (document.getElementById){ 
obj = document.getElementById(id); 
if (obj.style.display == "none"){ 
obj.style.display = ""; 
} else { 
obj.style.display = "none"; 
} 
} 
} 

function hide(id){ 
if (document.getElementById){ 
obj = document.getElementById(id); 
obj.style.display = "none"; 
} 
} 

function show(id){ 
if (document.getElementById){ 
obj = document.getElementById(id); 
obj.style.display = ""; 
} 
} 


		function IsNum( numstr ) {
			var downPaymentResult = document.getElementById("downPaymentResult");
			var mortgageAmountResult = document.getElementById("mortgageAmountResult");
			var paymentAmount = document.getElementById("paymentAmount");
			var totalInterest = document.getElementById("totalInterest");

			// Return immediately if an invalid value was passed in
			if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
				return false;
			var isValid = true;
			var decCount = 0;		
			
			numstr += "";	
			// Loop through string and test each character. If any
			// character is not a number, return a false result.
 			// Include special cases for negative numbers (first char == '-')
			// and a single decimal point (any one char in string == '.').
			for (i = 0; i < numstr.length; i++) {
				// track number of decimal points
				if (numstr.charAt(i) == ".")
					decCount++;
    			if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") ||
						(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
       			isValid = false;
       			break;
				} else if ((numstr.charAt(i) == "-" && i != 0) ||
						(numstr.charAt(i) == "." && numstr.length == 1) ||
					(numstr.charAt(i) == "." && decCount > 1)) {
       			isValid = false;
       			break;
				}         	         				
				//if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9")) ||
			} // END for
   			return isValid;
			}  
			// end IsNum


function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
}

//Trims spaces on right side of the string
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}

//Trims spaces on either side of the string
function Trim(str){
	return LTrim(RTrim(str));
}
