//How to call the tools :
//<iframe src="financial-adviser-tool.php" width="520px"  height="305px"scrolling="auto" frameborder="0">financial-adviser-tool</iframe> 

function displayOnTop(self)
{
	if (self != top) top.location = self.location;
}


function reload_chart()
{
   
  var d, n = 0;
  //
  d = Number(document.frm.input_value.value.replace(/\,/g,'')); // convert field value to a number
  //var num = input.value.;
  if (isNaN(d)) d = 0; // if not a number, use zero
  n = d;
  var year;
  
  
  
 
  
  

// update form value 
  var num = new Number(n);
  //var maxN=75000;
  var maxN=250000;
  if (n<=20000) year=3;
  if (n>20000) year=5;
  
    
  for (i=1;i<9;i++){	
   repid='yearperiod_'+i;
   element = document.getElementById(repid);
   element.innerHTML = year;
  }
  
  
   // update chart 
  tmp = findSWF("chart");
  //alert(tmp);
  //m=tmp;
  
  //
  // reload the data:
  //
  var str;
  str="chart-data.php?v="+n+"&y="+year+"&m="+maxN;
  setTimeout("tmp.reload('"+str+"')", 1);
  //tmp.reload(str);
  
//Option #1: Repay Debt on Your Own
//
//- Interest rate: 18%?
//- Interest calculation: Compounded Annually? 
//- Repayment period: 5 years?
//- % of amount to payback: 100%
num=n* Math.pow(1+0.18,year) /(year*12);
document.frm2.option_1.value ="$"+num.toFixed(2); 
document.frm2.option_1.size=document.frm2.option_1.value.length-2;

//Option #2: Debt Consolidation
//
//- Interest rate: 12%
//- Interest calculation: Compounded Annually?   yes
//- Repayment period: 5 years?
//- % of amount to payback: 100%
num=n* Math.pow(1+0.12,year) /(year*12);
document.frm2.option_2.value ="$"+num.toFixed(2); 
document.frm2.option_2.size=document.frm2.option_2.value.length-2;

//Option #3: Credit Counselling
//
//- Interest rate: No interest?
//- Interest calculation: n/a?
//- Repayment period: 5 years?
//- % of amount to payback: 100%

num=n/(year*12);
document.frm2.option_3.value ="$"+num.toFixed(2); 
document.frm2.option_3.size=document.frm2.option_3.value.length-2;

//Option #4: Debt Settlement
//
//- Interest rate: 18%?
//- Interest calculation: Compounded Annually? 
//- Repayment period: 5 years?
//- % of amount to payback: 100%
num=n* (0.5) /(year*12);
document.frm2.option_4.value ="$"+num.toFixed(2); 
document.frm2.option_4.size=document.frm2.option_4.value.length-2;

//Option #5: Consumer Proposal
//
//- Interest rate: No interest?
//- Interest calculation: n/a?
//- Repayment period: 5 years?
//- % of amount to payback: 30%
if (n<=maxN && n>=6000){


element = document.getElementById('consumerpro');


if(n>20000){
	element.innerHTML = "<div class='value' id='consumerpvalue'><input name='option_5' type='text' size='3' onkeypress='return checkEnter(event)' value='0.00' readonly='readonly' class='readonlynumber'  /><span class='smallfont2'><br />Per month,<br />over "+year+" years</span> </div>" +"<div class='detail' id='consumerp'><ul><li>Assume that you will need to pay back only 35% of your total unsecured debt</li><li>Pay back period: "+year+"-year </li><li>Interest rate: none</li></ul></div>";
	num=(n*0.35)/(year*12);
}
else 
{
	element.innerHTML = "<div class='value' id='consumerpvalue'><input name='option_5' type='text' size='3' onkeypress='return checkEnter(event)' value='0.00' readonly='readonly' class='readonlynumber'  /><span class='smallfont2'><br />Per month,<br />over "+year+" years</span> </div>" +"<div class='detail' id='consumerp'><ul><li>Assume you will need to repay a minimum of 35% of your total unsecured debt</li><li>Pay back period: "+year+"-year </li><li>Interest rate: none</li></ul></div>";
	num=6000/(year*12);
}



  

//num=(n*0.3)/(year*12);
document.frm2.option_5.value ="$"+num.toFixed(2); 
document.frm2.option_5.size=document.frm2.option_5.value.length-2;
  
}
else 
{
	element = document.getElementById('consumerpro');
  
	if(n<6000){
	element.innerHTML = "<div class='detail' id='long'>In general, a Consumer Proposal is a suitable option in situations when a person's debts exceed $6,000, to a maximum of $250,000. Since your debts are less than $6,000, a Consumer Proposal is likely not the best option for you.</div>";
	}
	else {
	element.innerHTML = "<div class='detail' id='long'>Under current rules Consumer Proposal can only be filed if debt not including mortgage is less than $250,000. Since you exceed this limit, please <a href='/emailUs.htm'  target='_top'>click here to arrange for an initial free consultation with a licensed trustee</a> who can explain your other options, including a Division 1 Proposal.</div>";
	}
  
   
//document.frm2.option_4.value ="N/A"; 
//document.frm2.option_4.size=document.frm2.option_4.value.length-2;
	
}


  //  must use setTimeout  work in FireFox
  //x = tmp.reload(str);
  
  //x = tmp.reload();
  
  //
  // to load from a specific URL:
  // you may need to 'escape' (URL escape, i.e. percent escape) your URL if it has & in it
  //
  //x = tmp.reload("gallery-data-32.php?beer=1");
  
  //
  // do NOT show the 'loading...' message:
  //
  //x = tmp.reload("gallery-data-32.php?beer=1", false);
}

function findSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window["ie_" + movieName];
  } else {
    return document[movieName];
  }
}


function openlink(urlstr) {
	///window.open(urlstr);   open a new window 
	//window.location.href=urlstr;  /
	top.window.location.href=urlstr;  // open link at same window , and jump out of link
	
}


// update form calculated field  


// load other page in a page , cannot access accross domain
function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

/// show popup window 

var illLargeCurrent = null;
var illLargeNew = null;
var illSmallCurrent = null;
var illSmallNew = null;


function showIllustration(frm) 
{
    illLargeNew = document.getElementById('form-options');
    if(illLargeNew != illLargeCurrent) 
    {
        if(illLargeCurrent) 
        {
            illLargeCurrent.style.display = 'none';
        }
        if(illLargeNew) 
        {
            illLargeNew.style.display = 'block';
            illLargeCurrent = illLargeNew;
		    
        }
	   
    }
	//repositionBlock('form-options');
    updateform(frm);
}

function closeIllustration() 
{
    illLargeCurrent = document.getElementById('form-options');
    illLargeCurrent.style.display = 'none';
    illLargeCurrent = null;
}


function repositionBlock(div_id)
{
    
	div_left = document.getElementById("panelcontent").offsetLeft;
    div_top = document.getElementById("panelcontent").offsetTop;
	el=document.getElementById("panelcontent");
	div_left=findPos(el)[0];
	div_top=findPos(el)[1]-80;
	
  
    if(div_top < 0)
        div_top = 200;
    if(div_left < 0)
        div_left = 0;
	// check scroll bar position , if the form is not visible , scroll
	m_scrolltop=f_scrollTop();
	//var str="div:"+div_top+ "scroll top:"+m_scrolltop;
	//alert(str);
	if ((m_scrolltop>div_top) || (m_scrolltop<div_top-250) )  
     window.scrollTo(0,div_top); 
    //document.getElementById(div_id).style.left = div_left + 'px';
    //document.getElementById(div_id).style.top = div_top + 'px';
}

// get a object position 
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {

	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
	}
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function removeDoubleCLick()
{
 theObjects = document.getElementsByTagName("object");
 
 for (var i = 0; i < theObjects.length; i++) 
 {
  theObjects[i].outerHTML = theObjects[i].outerHTML;
 }
}
