function open_window(URL,Name) {
	h = screen.availHeight;
    w = screen.availWidth;
	//window.open(URL , Name ,'resizable=1, toolbar=0, location=0, scrollbar=1,menubar=0, status=0, width=100, height=100);
	window.open(URL,"","resizable=yes,toolbar=no,locationbar=no,menubar=no,scrollbars=yes,status=no,height="+h+",width="+w);
}

function pp_details() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('request_info').style.display="none";
	document.getElementById('refer_client').style.display="none";
	document.getElementById('property_details').style.display="block";
}

function show_refer() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('request_info').style.display="none";
	document.getElementById('refer_client').style.display="block";
	document.getElementById('property_details').style.display="none";
}

function send_to_friend() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="block";
	document.getElementById('request_info').style.display="none";
	document.getElementById('refer_client').style.display="none";
	document.getElementById('property_details').style.display="none";
}

function send_to_fr() {
    document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="block";
	document.getElementById('show_calendar').style.display="none";
	document.getElementById('details').style.display="none";
	document.getElementById('contact_form').style.display="none";
}

function show_photos1() {
    document.getElementById('show_gallery').style.display="block";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('show_calendar').style.display="none";
	document.getElementById('details').style.display="none";
	document.getElementById('contact_form').style.display="none";
}

function show_calendar() {
	document.getElementById('details').style.display="none";
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('show_calendar').style.display="block";
	document.getElementById('contact_form').style.display="none";
}

function show_details() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('show_calendar').style.display="none";
	document.getElementById('details').style.display="block";
	document.getElementById('contact_form').style.display="none";
}

function show_contact() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('show_calendar').style.display="none";
	document.getElementById('details').style.display="none";
	document.getElementById('contact_form').style.display="block";
}

function show_photos() {
	document.getElementById('show_gallery').style.display="block";
	document.getElementById('request_info').style.display="none";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('refer_client').style.display="none";
	document.getElementById('property_details').style.display="none";
}

function show_request() {
	document.getElementById('show_gallery').style.display="none";
	document.getElementById('request_info').style.display="block";
	document.getElementById('send_to_friend').style.display="none";
	document.getElementById('refer_client').style.display="none";
	document.getElementById('property_details').style.display="none";
}

function show_transfer() {
	document.getElementById('mortgage').style.display="none";
	document.getElementById('land_transfer').style.display="block";
}

function show_mortgage() {
	document.getElementById('mortgage').style.display="block";
	document.getElementById('land_transfer').style.display="none";
}

function roundTowardsZero(X) {
    return (X < 0 ? -1 : 1) * Math.floor(Math.abs(X));
}

function num_check(myid) {
	var myval    = document.getElementById(myid).value; 
	var nocommas =  myval.replace(/\,/g,'');
	//alert(nocommas.search(/\./g));
	//var intvalue = roundTowardsZero(nocommas);
	if (nocommas.search(/\./g) == "-1" )
	{
		number = '' + nocommas;
		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);
		}
		document.getElementById(myid).value = output;
		}
		else document.getElementById(myid).value = number; 
	}
	//if (thisvalue.length == 3) 
	//{
	//	alert ('buhuhu');	
	//} 
}

function show_search(name, path, type)
{
// schimbare de buton

	if (type == 0)
	{
		document.getElementById("address_button").src = path+"/images/address-off.gif"; 
		document.getElementById("agent_button").src = path+"/images/agent-off.gif"; 
		document.getElementById("advanced_button").src = path+"/images/advanced-off.gif"; 
		document.getElementById(name+"_button").src = path+"/images/"+name+"-on.gif";
	}
	else
	{
	document.getElementById("address_button").src = path+"/images/address-off.gif"; 
	document.getElementById("agent_button").src = path+"/images/agent-off.gif"; 
	document.getElementById("advanced_button").src = path+"/images/advanced-off.gif"; 
	}

//afisare search
document.getElementById('address_searchbox').style.display = "none"; 
document.getElementById("agent_searchbox").style.display = "none"; 
document.getElementById("advanced_searchbox").style.display = "none"; 
document.getElementById("vacation_searchbox").style.display = "none"; 
document.getElementById(name+"_searchbox").style.display = "block";


//afisare de continut - content sau citylist 
if (name == "advanced")
    {
    document.getElementById("list").style.display = "none";
    document.getElementById("city_list").style.display = "block";
    }
else
    {
    document.getElementById("list").style.display = "block";
    document.getElementById("city_list").style.display = "none";
    }
}

/*
Div:
address_button
<a href="#" onclick="show_search('address')"><img src="address-on.jpg" 
id="address-button" name="address-button" /></a> agent_button advanced_button address_searchbox agent_searchbox advanced_searchbox content city_list */ 

function MM_validateForm_ctc() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_ctc.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else document.forms['contact'].submit();
    document.MM_returnValue = (errors == '');
} }


function MM_validateForm_vstep1() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_vstep1.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else {
		document.getElementById('next_step').value = '1';	
		document.forms['step1'].submit();
	}
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_refer() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_refer.arguments;
	if (document.getElementById('i_agree').checked == false) errors += '- you have to agree with our condition.\n';
    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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; } 
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else
	document.forms['refer'].submit();
    document.MM_returnValue = (errors == '');
} }


function MM_validateForm_link() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_link.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else document.forms['send_link'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_request() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_request.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else
	document.forms['info_request'].submit();
    document.MM_returnValue = (errors == '');
} }


function MM_validateForm_contact() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_contact.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else document.forms['send-message'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_list() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_list.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else 
	  {
		document.getElementById('send').value = 'send';
	  	document.forms['list-prop'].submit();
	  }
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_agent() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_agent.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else document.forms['featured-agent'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_photo() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_photo.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else
	  document.forms['photo_nedded'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_worth() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_worth.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else document.forms['home_worth'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_ag() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_ag.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else document.forms['order_agent'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_advertise() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_advertise.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else  document.forms['advertise'].submit();
    document.MM_returnValue = (errors == '');
} }
function check_ontario() {
	province = document.forms['calculator'].province.value;
	if (province == 'Ontario')  document.getElementById('calc_exception').style.display = 'block';
	else document.getElementById('calc_exception').style.display = 'none';
}


// M O R T G A G E    C A L C U L A T O R

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 CSClickReturn () {
	var bAgent = window.navigator.userAgent; 
	var bAppName = window.navigator.appName;
	if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
		return true; // dont follow link
	else return false; // dont follow link
}

CSStopExecution = false;
function CSAction(array) { 
	return CSAction2(CSAct, array);
}

function CSAction2(fct, array) { 
	var result;
	for (var i=0;i<array.length;i++) {
		if(CSStopExecution) return false; 
		var actArray = fct[array[i]];
		if (actArray == null) return false;
		var tempArray = new Array;
		for(var j=1;j<actArray.length;j++) {
			if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
				if(actArray[j][0] == "VAR") {
					tempArray[j] = CSStateArray[actArray[j][1]];
				}
				else {
					if(actArray[j][0] == "ACT") {
						tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
					}
				else
					tempArray[j] = actArray[j];
				}
			}
			else
				tempArray[j] = actArray[j];
		}			
		result = actArray[0](tempArray);
	}
	return result;
}

CSAct = new Object;

CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
function IsIE() { return CSAg.indexOf("MSIE") > 0;}
function CSIEStyl(s) { return document.all.tags("div")[s].style; }
function CSNSStyl(s) { return CSFindElement(s,0); }
function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
	var curDoc = ly ? ly.document : document; var elem = curDoc[n];
	if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
		elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
	return elem;
}

function CSSetImageURL(action) {
	var img = null;
	if (document.images) {
		if (!IsIE()) img = CSFindElement(action[1],0);
		else img = document.images[action[1]];
		if (img) img.src = action[2];
	}
}

function CSCallFunction(action)
{
	var str = action[1];
	str += "(";
	str += action[2];
	str += ");"
	return eval(str);
}

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 MM_validateForm_dream() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_dream.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	else
	document.forms['dream_home'].submit();
    document.MM_returnValue = (errors == '');
} }

function MM_validateForm_riders() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm_riders.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+='- '+nm+' must contain a number.\n';
          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 += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
	  else document.forms['riders'].submit();
    document.MM_returnValue = (errors == '');
} }

function checkAddress()
{
	address = document.getElementById('address').value;
	if (address.length < 3) 
	{
		alert ('Your search string must be longer then 3 characters!');
		return false;
	}
	var iChars = "~\`!@$%^&*()+=[]\\\';,./{}|\":<>?_";
	for (var i = 0; i < address.length; i++)
	{
		if (iChars.indexOf(address.charAt(i)) != -1) {
			alert ("Special characters are NOT allowed.\n Please remove them and search again...");
			return false;
		}
	}
	document.forms['search-by-address'].submit();
}


function checkAgent()
{
	agent = document.getElementById('agent').value;
	if (agent.length < 3) 
	{
		alert ('Your search string must be longer then 3 characters!');
		return false;
	}

	var iChars = "~\`!@#$%^&*()+=-[]\\\';,./{}|\":<>?_";
	for (var i = 0; i < agent.length; i++)
	{
		if (iChars.indexOf(agent.charAt(i)) != -1) {
			alert ("Special characters are NOT allowed.\n Please remove them and search again...");
			return false;
		}
	}
	document.forms['search-by-agent'].submit();
}

var prop_val;
var prov;
var error_message, error_message2, error_message3;
var transfer_tax;

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 numberFilter (s) {
filteredValues = "1234567890";     // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) != -1) returnString += c;
}
	return returnString;
}

function calculate(){
	price = numberFilter(document.calculator.price.value);
	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;
	}
	document.calculator.tax.value = total_tax;
}


function countText(obj,maxChars){
	if (obj.value.length>maxChars){
		obj.value = obj.value.substring(0,maxChars);
		}
	document.getElementById(obj.name+"_display").innerHTML = "Characters: " + obj.value.length + " out of " + maxChars;
	}