function value_pass()
{
	var wind;
    var a;
    a="xxxxxxxx";

	wind=window.open("whataremypaymentswith_1_2_mortgage_p.php?y="+document.form1.fst_amount.value+a+document.form1.fst_int.value+a+document.form1.fst_term.value+a+document.form1.snd_amount.value+a+document.form1.snd_rate.value+a+document.form1.snd_term.value+a+document.form1.result1.value+a+document.form1.result2.value+a+document.form1.result3.value+a+document.form1.result4.value+a,"aa","location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=612,height=792");


}



function tt()
{

var fst_amount=convertIt(document.form1.fst_amount.value);

var fst_int=convertIt_per(document.form1.fst_int.value);

var fst_term=document.form1.fst_term.value;
var snd_amount=convertIt(document.form1.snd_amount.value);
var snd_rate=convertIt_per(document.form1.snd_rate.value);
var snd_term=document.form1.snd_term.value;
var ll= fst_pmt(fst_amount,fst_int,fst_term); //first payment
//alert(ll);

var xx=snd_pmt(snd_amount,snd_rate,snd_term);//second payment
//alert(xx);
var add_payment=ll+(+xx);
//alert(add_payment);
var f =fst_amount*(fst_int/100);

var f409=f/12;
//alert(f409);
var s=snd_amount*(snd_rate/100);
var f410=s/12;
//alert(f410);
//alert(f410);
var f411=f409+(+f410);
//alert(f411);
var fst_amount1=parseInt(fst_amount);
var snd_amount1=parseInt(snd_amount);
var tnd_amount=fst_amount1+snd_amount1;
//var tot_amnt= fst_amount+(+snd_amount);
//alert(tot_amnt);
//alert(tnd_amount);
var fper=f411*12;
//alert(fper);
var percent=fper/tnd_amount;
//alert(percent);
var pcent=percent*100;
//alert(pcent);
var pcent1=trunc2(pcent, true)
//alert(pcent1);
percent1=trunc2(percent, true)
//alert(percent1);
var percent1=(percent-(+1));
//alert(percent1);
var ll1=trunc2(ll, true)
//first_pmt.innerText=formatCurrency(ll1);
document.getElementById("first_pmt").innerHTML=formatCurrency(ll1);
document.form1.result1.value=formatCurrency(ll1);
var xx1=trunc2(xx, true)
//second_pmt.innerText=formatCurrency(xx1);
document.getElementById("second_pmt").innerHTML=formatCurrency(xx1);
document.form1.result2.value=formatCurrency(xx1);
add_payment1=trunc2(add_payment, true)
//tot_mort.innerText=formatCurrency(add_payment1);
document.getElementById("tot_mort").innerHTML=formatCurrency(add_payment1);
document.form1.result3.value=formatCurrency(add_payment1);
//mess.style.display="none";
//mes.innerText="";
//mes.innerText="Since you have two loans with two different interest rates, you will also have what is called a blended (or effective) interest rate which is "+pcent1+ "%.If this rate is too high, you can consider refinancing to save money";
total_percent.innerText=" "+formatCurrency_per(pcent1);
document.getElementById("total_percent").innerHTML=" "+formatCurrency_per(pcent1);
document.form1.result4.value=" "+formatCurrency_per(pcent1);

function trunc2(vally, floater) // truncate to two places to the right of the decimal point
			{
			
			var xxx;
			var lenny;
			var decpt;
			var atright;
			

				xxx = (Math.round(vally * 100)) / 100.0; // round to two places to the right
				xxx = xxx + " "; // convert to string
				xxx = xxx.substring(0, (xxx.length - 1)); // truncate the trailing space
				lenny = xxx.length;
				decpt = xxx.indexOf(".")
				if (floater) { // we want a decimal point
					if (decpt == -1)
						xxx = xxx + ".00";
					else { // there is a dec pt in the string
						atright = (lenny - decpt) - 1; // num digits to the right of the dec pt
						if (atright == 0)
							xxx = xxx + "00";
						else if (atright == 1)
							xxx = xxx + "0";
						}
					}
				else { // we want no decimal point
					if (decpt == -1)
						xxx = xxx + ""; // pad val at end with three spaces
					else // there is a dec pt, so kill it and pad with three spaces
						xxx = xxx.substring(0, (decpt - 1)) + " ";
					}
				lenny = xxx.length;
				if (lenny < 10)
					for (j = 1; j < 10 - lenny; j++) // pad string with leading spaces
						xxx = "" + xxx;
				return xxx;
			}//Ending of the trunc2()
			/* b = pmt;
				document.write("" + trunc2(b, true));
    
		   */

}


function fst_pmt(fst_amount,fst_int,fst_term)//function for the first pmt
  {
     
    var prin=fst_amount;
	var rate=fst_int / 1200;
	var snd_rate;
	
        var pmt;
       
        var mons1
		var pmt1;
		              
		   mons1=fst_term*12;
                 
                
           
               
	            if(rate >0)
                      	
			fst_pmt1 = (+prin * +rate * Math.pow((+rate + 1.0), +mons1)) / (Math.pow((+rate + 1.0), +mons1) - 1.0);
		        
                
                   else
                        
            
       		fst_pmt1 = +prin/+mons1;
            pmt1=Math.round(pmt);    
            
                

		 
return fst_pmt1;


  
    }

function snd_pmt(snd_amount,snd_rate,snd_term)

{


 var prin=snd_amount;
	var rate=snd_rate / 1200;
	
	
        var pmt;
       var snd_pmt1
        var mons1
		var pmt1;
		              
		   mons1=snd_term*12;
                 
                
           
               
	            if(rate >0)
                      	
			snd_pmt1 = (+prin * +rate * Math.pow((+rate + 1.0), +mons1)) / (Math.pow((+rate + 1.0), +mons1) - 1.0);
		        
                
                   else
                        
            
       		snd_pmt1 = +prin/+mons1;
            pmt1=Math.round(pmt);    
            
                

		 
return snd_pmt1;







   }

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 convertIt(numstring)
{

  var retval="";
  var arr=numstring.split(""); 
  for(var i=0; i< arr.length;i++)
  {
    
    if(arr[i].search(/[$ ,]/) == -1)
	{
	  
      retval += arr[i].toString();
	}
  }
 var z=parseInt(retval);
 var z1=parseFloat(retval);
 //alert(z);
 //alert(z1);
  return retval;

}

function formatCurrency_per(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 convertIt_per(numstring)
{

  var retval="";
  var arr=numstring.split(""); 
  for(var i=0; i< arr.length;i++)
  {
    
    if(arr[i].search(/[% ,]/) == -1)
	{
	  
      retval += arr[i].toString();
	}
  }
 var z=parseInt(retval);
 var z1=parseFloat(retval);
 //alert(z);
 //alert(z1);
  return retval;

}
