function Comma(number) {
	number = '' + number;
	if (number.length > 3) {
	var mod = number.length % 3;
	var output = (mod > 0 ? (number.substring(0,mod)) : '');
	for (i=0 ; i < Math.floor(number.length / 3); i++) {
	if ((mod == 0) && (i == 0))
	output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
	else
	output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
	}
	return (output);
	}
	else return number;
}


<!--Hide JavaScript from Java-Impaired Browsers
var irate, mi, cmi, years, tprinc, princ, paym, cpaym, osp,v,downp,downr,comp;

function calcPaym(cdn){
   tprinc1 =  document.smpc.tprinc.value.replace(/\,/g,'');
   downp1  =  document.smpc.downp.value.replace(/\,/g,'');
   tprinc = round2d(parseFloat(tprinc1));
   downp = .01*parseFloat(downp1);
   downr = ceil2d(downp*tprinc);
   princ = tprinc-downr;

   document.smpc.princ.value = Comma(fmt2d(princ,0)).replace(',.','.');
   document.smpc.downr.value = Comma(fmt2d(downr,0)).replace(',.','.');

   if(cdn)comp="Canadian"; else comp="U.S";
   document.smpc.comp.value = comp;

   irate = .01*parseFloat(document.smpc.percent.value);
   years=parseFloat(document.smpc.years.value);
   term = parseFloat(document.smpc.term.value);
   if(term > years)term=years;

   if (term==0 || years==0||irate<.0001||princ<1)
   {alert("values must be numeric");}
   else 
   {
       if(cdn)mi = Math.pow(1+ irate/2,1/6) 
       else   mi = 1+(irate/12);
       v = 1/mi;
       paym = ceil2d(princ*(mi-1)/(1-Math.pow(mi,-(years*12))));
       osp = (princ-(v*paym*(1-Math.pow(v,12*term)))/(1-v))/Math.pow(v,12*term);
       if(osp<0)osp = 0;

       document.smpc.paym.value=Comma(fmt2d(paym,0)).replace(',.','.');
       document.smpc.owed.value = fmt2d(osp,0);
   }
}

function round2d(n){return(.01* Math.round(100*n));}
function floor2d(n){return(.01* Math.floor(100*n));}
function ceil2d(n){return(.01* Math.ceil(100*n));}
// format number n as string width w with 2 decimal places

function fmt2d(n,w)
{
   var work,dp,sl,dl;
   
   work = ""+floor2d(n); // force only 2 decimals
   sl=work.length;

  if(-1 == (dp = work.indexOf(".")))work=work+".00";
   else if(3 > sl-dp)work = work+".00".substring(sl-dp,3);
   sl = work.length;
   if(0 != w && w !=sl)
      if(w<sl){work = "*";for(sl=1;sl<w;sl++)work=work+"*";}
      else for(;sl<w;sl++)work=" "+work; 
   return work;
}

function MM_validateForm_calc_ca() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_calc_ca.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors='- Fields must contain numbers.\n Please use . (dots) for decimal numbers';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors = '- you have to complete all fields.\n'; }
    } if (errors) {
		alert('The following error(s) occurred:\n'+errors);
		return false;
	}
    document.MM_returnValue = (errors == '');
} }


function check_data(){
	prop_val1 = document.forms['calculator'].property_value.value;
	prop_val  = prop_val1.replace(/\,/g,'');
	prov = document.forms['calculator'].province.options[document.forms['calculator'].province.selectedIndex].value;
	error_message  = 'Please enter a property value!';
	error_message2 = 'Please choose a property value over $100!';
	error_message3 = 'Please choose a province!';

	if(prop_val == 0){
		alert("Error: " + error_message);
	}else if(prop_val > 0 && prop_val <= 100){
		alert("Error: " + error_message2);
	}else{
		if(prov == "Alberta"){
			if(prop_val != 0){
				transfer_tax1 = ((0.001 * prop_val) + 35);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "British Columbia"){   					// RIGHT!
			if(prop_val <= 200000){
				transfer_tax1 = (0.01 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 200000){
				transfer_tax1 = ((0.02 * prop_val) - 2000);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Manitoba"){						   		// RIGHT!
			if(prop_val <= 30000){
				transfer_tax1 = "0";
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 30000 && prop_val <= 90000){
				transfer_tax1 = ((0.005 * prop_val) - 110);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 90000 && prop_val <= 150000){
				transfer_tax1 = ((0.01 * prop_val) - 560);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 150000){
				transfer_tax1 = ((0.015 * prop_val) - 1350);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "New Brunswick"){				  		// RIGHT!
			if(prop_val != 0){
				transfer_tax1 = ((0.0025 * prop_val) + 55);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Newfoundland"){		   				// RIGHT!
			if(prop_val != 0){
				transfer_tax1 = ((0.004 * prop_val) + 50);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Northwest Territories"){
			if(prop_val <= 1000000){
				transfer_tax1 = ((0.0015 * prop_val) + 40);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;

			} else if(prop_val > 1000000){
				transfer_tax1 = (0.001 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Nova Scotia, Halifax County"){
			if(prop_val != 0){
				transfer_tax1 = (0.015 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} 
		}else if(prov == "Nova Scotia, not Halifax County"){
			if(prop_val != 0){
				transfer_tax1 = (0.0005 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}

/*

if Halifax County	(0.015 x price) + 45   // RIGHT!

else				0.0005 x price 

*/
		}else if(prov == "Ontario"){								// RIGHT!
			if(prop_val != 0){
					price = prop_val;
					leftt = price;
					total_tax = 0;
					toronto_tax = 0;
					if (price > 55000){
						tmp_tax = 55000 * 0.005;
						total_tax += tmp_tax;
						price -= 55000;
					} else {
						tmp_tax = price * 0.005;
						total_tax += tmp_tax;
						price = 0;
					}
					if (price > 195000){
						tmp_tax = 195000 * 0.01;
						total_tax += tmp_tax;
						price -= 195000;
					} else {
						tmp_tax = price * 0.01;
						total_tax += tmp_tax;
						price = 0;
					}
				
				if (price > 150000){
						tmp_tax = 150000 * 0.015;
						total_tax += tmp_tax;
						price -= 150000;
					} else {
						tmp_tax = price * 0.015;
						total_tax += tmp_tax;
						price = 0;
					}
					if (price > 0){
						tmp_tax = price * 0.02;
						total_tax += tmp_tax;
						price = 0;
					}

				if (document.calculator.firsttimehomebuyer.checked==true){
						if (total_tax > 2000)
							total_tax = total_tax - 2000;
						else
							total_tax = 0;
					}
					total_tax = Math.round(total_tax);
					if (document.calculator.torontopurchase.checked==true){
						if (leftt > 55000){
							toronto_tax = 275;
							leftt = leftt - 55000;
						} else {
							toronto_tax = leftt * .005;
							leftt = 0;
						}

						if (leftt > 345000){
							toronto_tax = toronto_tax + 3450;
							leftt = leftt - 345000;
						} else {
							toronto_tax = toronto_tax + (leftt * .01);
							leftt = 0;
						}
				
					if (document.calculator.firsttimehomebuyer.checked==true)
							toronto_tax = 0;

					if (leftt > 0){
							toronto_tax = toronto_tax + (leftt * .02);
						}
						toronto_tax = Math.round(toronto_tax);
						total_tax = total_tax + toronto_tax;
					}

					transfer_tax  = Math.round(total_tax*100)/100;
					if (transfer_tax > 1000)
					document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
					else 
					document.calculator.land_tax.value = transfer_tax;
			}

			/*if(prop_val <= 55000){
				transfer_tax1 = (0.005 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 55000 && prop_val <= 250000){
				transfer_tax1 = ((0.01 * prop_val) - 275);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 250000 && prop_val <= 400000){
				transfer_tax1 = ((0.015 * prop_val) - 1525);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 400000){
				transfer_tax1 = ((0.02 * prop_val) - 3525);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} */

		}else if(prov == "Prince Edward Island"){
			if(prop_val > 500){
				transfer_tax1 = (0.01 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}else{
				transfer_tax1 = 0;
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Quebec"){ 					 		 // RIGHT!
			if(prop_val <= 50000){
				transfer_tax1 = (0.005 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 50000 && prop_val <= 250000){
				transfer_tax1 = ((0.01 * prop_val) - 250);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 250000){
				transfer_tax1 = ((0.015 * prop_val) - 1500);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Saskatchewan"){					 		 // RIGHT!
			if(prop_val <= 1000){
				transfer_tax1 = "0";
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 1000){
				transfer_tax1 = ((0.0015 * prop_val) + 15);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else if(prov == "Yukon"){
			if(prop_val <= 10000){
				transfer_tax1 = (0.001 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			} else if(prop_val > 10000 && prop_val <= 25000){
				transfer_tax1 = (0.005 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
		} else if(prop_val > 25000){
				transfer_tax1 = (0.0025 * prop_val);
				transfer_tax  = Math.round(transfer_tax1*100)/100;
				if (transfer_tax > 1000)
				document.calculator.land_tax.value = Comma(transfer_tax).replace(',.','.');
				else 
				document.calculator.land_tax.value = transfer_tax;
			}
		}else{
			alert("Error: " + error_message3);
		}
	}
}



function check_ontario() {
	province = document.forms['calculator'].province.value;
	if (province == 'Ontario')  document.getElementById('ontario_features').style.display = '';
	else document.getElementById('ontario_features').style.display = 'none';
}


