<?php $lang=Yii::app()->session['lang'] ;
if (!isset($lang))
{$lang = 'ar';}
header('Content-Type:text/javascript'); 
?>
// $('#exchange').on('change', function() {
// var selectedItem= $(this).find(":selected").attr("data-max-value");
// $('#time').attr("max",selectedItem); 
// alert(selectedItem);
// });
function checkVal(){   
//  var maxValue=  $("#time").attr("max");
// $('#exchange').on('change', function() {
var selectedItem= $('#exchange').find(":selected").val();
$('#time').attr("max",selectedItem); 
// alert(selectedItem);

var insertedValue = $("#time").val();
//if(!insertedValue)
if(!insertedValue || !$.isNumeric(insertedValue) || insertedValue<0 || insertedValue.indexOf('-') == 0){
  var chack_insertedValue='false';
    alert('<?php echo($lang=='en'?'Please enter the funding duration':'الرجاء ادخال مدة التمويل') ?>');
}else{chack_insertedValue='true';}
 var maxValue=[<?php 
                $finances=CalculatorFinance::model()->findAll();
                foreach($finances as $finance)
                {
                  echo "['".$finance->finance_type."','".$finance->finance_type_en."',".$finance->max_duration_months.",],";
                }
                  ?>
                ];
var MessageError='';
MessageError=<?php echo($lang=='en'?'"This duration value is invalid the max value is:  "':'"هذه المدة غير متاحة إن القيمة الاعلى لمدة التمويل هي: "'); ?>;
var Month='';
Month="<?php echo($lang=='en'?'Month':'شهر');?>";
for (i = 0; i < maxValue.length; i++) 
{
  if((maxValue[i][0]== selectedItem || maxValue[i][1]== selectedItem) && maxValue[i][2] < insertedValue)
  {
        alert(MessageError+' '+maxValue[i][2]+' '+Month);
  }
}
 
  //   var MessageError=''
  // MessageError=<?php //echo($lang=='ar'?'"هذه المدة غير متاحة إن القيمة الاعلى لمدة التمويل هي: "':'"this duration value is invalid the max value is:  "'); ?>;
  // var MessageAndMaxValue =MessageError + ' ' +maxValue;
if( $("#time").val()>$("#time").attr("max")){
//alert(MessageAndMaxValue );
}
//  });    
} 
 

     
    $( window ).ready (function(){
        
    $(function() {
    var div = $('#menu1');
    var win = $(window)
    var height = div.outerHeight()  ; 
  
        $('.calculator-section1 ul.nav.nav-pills.main-nav li:first-child').css('height', (height+2)/2 );
        $('.calculator-section1 ul.nav.nav-pills.main-nav li:last-child').css('height', (height+2)/2 );
        $('#menu1').css('height', height );
        $('#menu2').css('height', height );
    });    
  
    $( window ).resize(function() {   
    var height2 =  $('#menu2').height() ;  
    $('.calculator-section1 ul.nav.nav-pills.main-nav li').css('height', (height2+2.9)/2 );
    console.log((height2+2.9)/2 );
    $('#menu1').css('height', height2 );  
    $('#menu2').css('height', height2 );  
    }); 
     
    $(document).on('input', '#time', function(){   
//        if ( $.browser.webkit || $.browser.msie)
		{
        var thumbwidth =40,
        valuechange = $(this).val();
        var month = valuechange*3 ;
        var pos = (valuechange - $('#time').attr('min'))/($('#time').attr('max') - $('#time').attr('min'));
        var thumbCorrect = thumbwidth * (pos- 0.3) * -1,
            titlepos = Math.round( ( pos *  $('#time').width() ) - thumbwidth/4 + thumbCorrect );  
          $('.range-value').html( month+"شهر");
          $('.range-value').css({'right':titlepos});  
        }
           
      });  
        $(document).on('mouseup', '#time', function(){   
           var thumbwidth1 =40,
        valuechange1 = $(this).val();
        var month1 = valuechange1*3 ;
        var pos1 = (valuechange1 - $('#time').attr('min'))/($('#time').attr('max') - $('#time').attr('min'));
        var thumbCorrect1 = thumbwidth1 * (pos1- 0.3) * -1,
            titlepos1 = Math.round( ( pos1 *  $('#time').width() ) - thumbwidth1/4 + thumbCorrect1 );  
          $('.range-value').html( month1+"شهر");     
        });
    });



// <!-- ----------------------------------------احتساب الأرباح------------------------------------- -->
/////// عدد ايام الربط/////////
function number_of_binding_days(date)
{
    // var date=$("#date").attr('value');
    var dateResult = new Date(date);
    var day = dateResult.getDate();
    var month = dateResult.getMonth();
    var year = dateResult.getFullYear();
    var LastDay = new Date(year, month + 1, 0);
    var ld=LastDay.getDate();
    var remainderDayOfInputMonth = ld-day;
    var inputMonth=month+1;
    var monthArray=[1,2,3,4,5,6,7,8,9,10,11,12];

    var first_quarter=[1,2,3];
    var second_quarter=[4,5,6];
    var third_quarter=[7,8,9];
    var fourth_quarter=[10,11,12];

      if(inputMonth<=3)
      {
        var Number_of_days_of_deposit=0;//عدد ايام ربط الوديعة
        for(var i=0; i<first_quarter.length; i++) {
            if (first_quarter[i] == inputMonth) 
            {
              var fres=3-first_quarter[i];
              if(fres==2)
              {
                var fresLastDay=new Date(year, fres , 0);
                var fld=fresLastDay.getDate();
                var fresLastDay2=new Date(year, fres + 1 , 0);
                var fld2=fresLastDay2.getDate();
                Number_of_days_of_deposit=fld+fld2+remainderDayOfInputMonth;
              }
              else if(fres==1)
              {  
                var fresLastDay2=new Date(year, fres + 2 , 0);
                var fld2=fresLastDay2.getDate();
                Number_of_days_of_deposit=fld2+remainderDayOfInputMonth;
              }
            else if(fres==0)
              {  
                Number_of_days_of_deposit=remainderDayOfInputMonth;
              }
            }
            
        }
      }
      if(inputMonth<=6)
      {
      for(var i=0; i<second_quarter.length; i++) {
            if (second_quarter[i] == inputMonth) 
            {
              var sres=6-second_quarter[i];
              if(sres==2)
                {
                var sresLastDay=new Date(year, sres+3 , 0);
                var sld=sresLastDay.getDate();
                var sresLastDay2=new Date(year, sres + 4 , 0);
                var sld2=sresLastDay2.getDate();
                Number_of_days_of_deposit=sld+sld2+remainderDayOfInputMonth;
              }
              else if(sres==1)
              {  
                var sresLastDay2=new Date(year, sres + 5 , 0);
                var sld2=sresLastDay2.getDate();
                Number_of_days_of_deposit=sld2+remainderDayOfInputMonth; 
              }
              else if(sres==0)
              {  
                Number_of_days_of_deposit=remainderDayOfInputMonth;
              }
            }
        }
      }
      if(inputMonth<=9)
      {
      for(var i=0; i<third_quarter.length; i++) {
            if (third_quarter[i] == inputMonth) 
            {
              var thres=9-third_quarter[i];
              if(thres==2)
                {
                var thresLastDay=new Date(year, thres+6 , 0);
                var thld=thresLastDay.getDate();
                var thresLastDay2=new Date(year, thres + 7 , 0);
                var thld2=thresLastDay2.getDate();
                Number_of_days_of_deposit=thld+thld2+remainderDayOfInputMonth
              }
              else if(thres==1)
              {  
                var thresLastDay2=new Date(year, thres + 8 , 0);
                var thld2=thresLastDay2.getDate();
                Number_of_days_of_deposit=thld2+remainderDayOfInputMonth;
              } 
              else if(thres==0)
              { 
                Number_of_days_of_deposit=remainderDayOfInputMonth;
              }
            }
        }
      }
      if(inputMonth<=12)
      {
      for(var i=0; i<fourth_quarter.length; i++) {
            if (fourth_quarter[i] == inputMonth) 
            {
              var fores=12-fourth_quarter[i];
              if(fores==2)
                {
                var foresLastDay=new Date(year, fores + 9 , 0);
                var fold=foresLastDay.getDate();
                var foresLastDay2=new Date(year, fores + 10 , 0);
                var fold2=foresLastDay2.getDate();
                Number_of_days_of_deposit=fold+fold2+remainderDayOfInputMonth;
              }
              else if(fores==1)
              {  
                var foresLastDay2=new Date(year, fores + 11 , 0);
                var fold2=foresLastDay2.getDate();
                Number_of_days_of_deposit=fold2+remainderDayOfInputMonth;
              }
              else if(fores==0)
              {  
                Number_of_days_of_deposit=remainderDayOfInputMonth;
              }
            }
          }
        return Number_of_days_of_deposit;
        
      }
 }

///////// الارباع///////
function quarter(date)
{
    var dateResult = new Date(date);
    var day = dateResult.getDate();
    var month = dateResult.getMonth();
    var RealMonth = month +1;
    var quarterResult='';
    if(RealMonth<=3)
    {
      quarterResult=<?php echo($lang=='ar'?'"الربع الرابع"':'"forth quarter"'); ?>;
      
    }
    else if(RealMonth<=6)
    {
       quarterResult=<?php echo($lang=='ar'?'"الربع الاول"':'"first quarter"'); ?>;
     
    }
    else if(RealMonth<=9)
    {
      quarterResult=<?php echo($lang=='ar'?'"الربع الثاني"':'"second quarter"'); ?>;
     
    }
    else if(RealMonth<=12)
    {
      quarterResult=<?php echo($lang=='ar'?'"الربع الثالث"':'"third quarter"'); ?>;
     
    }
  return quarterResult;
}

/////////////////////////////////////////////////////////// الارباح///////////////////////////////////////////
$("#earningsResult").click(function(){
    var duration=$('.calculator #menu1 .duration input:checked').val();
    var amount=$('.calculator #menu1 .third-part-content .form-control').val();
    var currency=$('#currencymenu1').val();
    var date=$("#date").val();
    var dateResult = new Date(date);

if(!duration){
    alert('<?php echo($lang=='ar'?'الرجاء اختيار مدة':'Please choose a duration') ?>');
}
if(!amount || !$.isNumeric(amount)){
    alert('<?php echo($lang=='ar'?'الرجاء ادخال المبلغ':'Please enter the amount') ?>');
}
if(!date){
    alert('<?php echo($lang=='ar'?'الرجاء ادخال التاريخ':'Please select the date') ?>');
}

if(date && amount){
    var month = dateResult.getMonth();
    var RealMonth = month +1;
    if(RealMonth<=3)
    {
    var yearF = dateResult.getFullYear();
    var year = yearF - 1
    }else{

    var year = dateResult.getFullYear();
    }
 
  var quarterll=quarter(date);
  //  alert(quarterll);
    var profit=[<?php
    $currencies=CalculatorAverageProfitRate::model()->findAll();                                     
    foreach($currencies as $currency)                                  
      {
        echo "['".$currency->calculator_currency."',".$currency->profit_month.",".$currency->profit_3month.",".$currency->profit_6month.",".$currency->profit_12month.",".$currency->profit_24month.",'".$currency->calculator_currency_en."'],";
      }
      ?>];

    for (var i = 0; i < profit.length; i++) { 
        if((profit[i][<?php echo($lang=='ar'?0:6); ?>] == currency) && (duration == 1))
          {
            var profit_percentage=profit[i][1]/100;
            var result_profit=(amount*number_of_binding_days(date)* profit_percentage )/365;
            $("#total_profit").html(' '+(result_profit).toFixed(2));
            $("#quarter_result").html(quarterll);
            $("#currency_result").html(profit[i][<?php echo($lang=='ar'?0:6); ?>]);
            
            $("#note").html("<?php echo($lang=='ar'?" تم احتساب الربح المتوقع بناءً على وسطي نسبة الربح الموزعة عن ":"The expected profit is calculated based on the average profit rate distributed "); ?>"+quarterll+"<?php echo($lang=='ar'?" لعام ":" for year ") ?>"+year+"<?php echo".<br>"; echo($lang=='ar'?"هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.":" This calculator offers approximate values and may be subject to change without notice."); ?>");
          }
          else if((profit[i][<?php echo($lang=='ar'?0:6); ?>] == currency) && (duration == 3))
          {
            var profit_percentage=profit[i][2]/100;
            var result_profit=(amount*number_of_binding_days(date)*profit_percentage)/365;
            $("#total_profit").html((result_profit).toFixed(2));
            $("#quarter_result").html(quarterll);
            $("#currency_result").html(profit[i][<?php echo($lang=='ar'?0:6); ?>]);
           $("#note").html("<?php echo($lang=='ar'?" تم احتساب الربح المتوقع بناءً على وسطي نسبة الربح الموزعة عن ":"The expected profit is calculated based on the average profit rate distributed "); ?>"+quarterll+"<?php echo($lang=='ar'?" لعام ":" for year ") ?>"+year+"<?php echo".<br>"; echo($lang=='ar'?"هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.":" This calculator offers approximate values and may be subject to change without notice."); ?>");
          }
          else if((profit[i][<?php echo($lang=='ar'?0:6); ?>] == currency) && (duration == 6))
          {
            var profit_percentage=profit[i][3]/100;
            var result_profit=(amount*number_of_binding_days(date)*profit_percentage)/365;
            $("#total_profit").html((result_profit).toFixed(2));
            $("#quarter_result").html(quarterll);
            $("#currency_result").html(profit[i][<?php echo($lang=='ar'?0:6); ?>]);
           $("#note").html("<?php echo($lang=='ar'?" تم احتساب الربح المتوقع بناءً على وسطي نسبة الربح الموزعة عن ":"The expected profit is calculated based on the average profit rate distributed "); ?>"+quarterll+"<?php echo($lang=='ar'?" لعام ":" for year ") ?>"+year+"<?php echo".<br>"; echo($lang=='ar'?"هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.":" This calculator offers approximate values and may be subject to change without notice."); ?>");
          }
          else if((profit[i][<?php echo($lang=='ar'?0:6); ?>] == currency) && (duration == 12))
          {
            var profit_percentage=profit[i][4]/100;
            var result_profit=(amount*number_of_binding_days(date)*profit_percentage)/365;
            $("#total_profit").html((result_profit).toFixed(2));
            $("#quarter_result").html(quarterll);
            $("#currency_result").html(profit[i][<?php echo($lang=='ar'?0:6); ?>]);
           $("#note").html("<?php echo($lang=='ar'?" تم احتساب الربح المتوقع بناءً على وسطي نسبة الربح الموزعة عن ":"The expected profit is calculated based on the average profit rate distributed "); ?>"+quarterll+"<?php echo($lang=='ar'?" لعام ":" for year ") ?>"+year+"<?php echo".<br>"; echo($lang=='ar'?"هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.":" This calculator offers approximate values and may be subject to change without notice."); ?>");
          }
          else if((profit[i][<?php echo($lang=='ar'?0:6); ?>] == currency) && (duration == 24))
          {
            var profit_percentage=profit[i][5]/100;
            var result_profit=(amount*number_of_binding_days(date)*profit_percentage)/365;
            $("#total_profit").html((result_profit).toFixed(2));
            $("#quarter_result").html(quarterll);
            $("#currency_result").html(profit[i][<?php echo($lang=='ar'?0:6); ?>]);
           $("#note").html("<?php echo($lang=='ar'?" تم احتساب الربح المتوقع بناءً على وسطي نسبة الربح الموزعة عن ":"The expected profit is calculated based on the average profit rate distributed "); ?>"+quarterll+"<?php echo($lang=='ar'?" لعام ":" for year ") ?>"+year+"<?php echo".<br>"; echo($lang=='ar'?"هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.":" This calculator offers approximate values and may be subject to change without notice."); ?>");
          }
     
}
}
});

/////////////////////////////////////////////////////////////آلية حساب وديعة الدخل الشهري///////////////////////////////////////////////
function number_of_binding_days_of_deposit(date)
{
    var dateResult = new Date(date);
    var day = dateResult.getDate();
    var month = dateResult.getMonth();
    var year = dateResult.getFullYear();
    var RealMonth=month+1;
    var ld=0;
    if(RealMonth==12)
    {
      var LastDay = new Date(year+1, 1, 0);
      var ld=LastDay.getDate();
    }
    else{
      var LastDay = new Date(year+1, RealMonth+1, 0);
      var ld=LastDay.getDate();
    }
    return ld;
}

function preventNonNumericalInput(e) {
  e = e || window.event;
  var charCode = (typeof e.which == "undefined") ? e.keyCode : e.which;
  // if(typeof e.which == "undefined" || typeof e.which == 46)
  // {
  //   var charCode = e.keyCode
  // }else
  // {
  //   var charCode = e.which
  // }
  var charStr = String.fromCharCode(charCode);

  // if (!charStr.match(/^[0-9]+$/))
  // if (!charStr.match(/^[0-9]+\.$/))
  if (!charStr.match(/^(\d*\.)?\d+$/))
  
    e.preventDefault();
}
function first_date_advance_deposit(date)
{
    var dateResult = new Date(date);
    var day = dateResult.getDate();
    var month = dateResult.getMonth();
    var year = dateResult.getFullYear();
    var RealMonth=month+1;
    var res='';
    if(RealMonth==11)
    {
      var next_year=year+1
      res='1'+'-'+'1'+'-'+next_year;
    }else if(RealMonth==12)
    {
      var next_year=year+1
      res='1'+'-'+'2'+'-'+next_year;
    }
    else{
     var next_month=RealMonth+2;
      res='1'+'-'+next_month+'-'+year;
    }
    return res;
}

$("#depositResult").click(function(){
  var depositAmount=$("#depositAmount").val();
  var depositDuration=$("#depositDuration").val();
  var date=$("#depositDate").val();
  
  if(depositDuration==0){
    alert('<?php echo($lang=='ar'?'الرجاء اختيار مدة':'Please choose a duration') ?>');
}
if(!depositAmount || !$.isNumeric(depositAmount)){
    alert('<?php echo($lang=='ar'?'الرجاء ادخال المبلغ':'Please enter the amount') ?>');
}
if(depositAmount < 250000)
{
	alert('<?php echo($lang=='ar'?'الرجاء ادخال قيمة المبلغ أكثر من 250,000':'Please enter the amount above than 250,000') ?>');
}
if(!date){
    alert('<?php echo($lang=='ar'?'الرجاء ادخال التاريخ':'Please select the date') ?>');
}
if(depositAmount && date){
  var profit=[<?php
    $currencies=CalculatorAverageProfitRate::model()->findAll();                                     
    foreach($currencies as $currency)      	                             
      {
        echo "['".$currency->calculator_currency."',".$currency->profit_month.",".$currency->profit_3month.",".$currency->profit_6month.",".$currency->profit_12month.",".$currency->profit_24month.",'".$currency->calculator_currency_en."'],";
      }
      ?>];
      // for (var i = 0; i < profit.length; i++) { 
        if(depositDuration == 6)
          {
            var profit_percentage=profit[0][3]/100;
            var ratio=80/100;
            var result_profit_modify=(depositAmount*ratio*profit_percentage)/12;
            //var result_profit=(depositAmount*number_of_binding_days_of_deposit(date)*profit_percentage)/365;
            $("#amount_of_the_monthly_advance").html((((result_profit_modify/1000).toPrecision(2))*1000)+'<?php echo($lang=='ar'?' ليرة سوري ':' Syrian Pound ') ?> ');
            
            $("#first_date_advance_deposit").html(first_date_advance_deposit(date)); 
          }
            else if(depositDuration == 12)
              {
                var profit_percentage=profit[0][4]/100;
                var ratio=80/100;
                var result_profit_modify=(depositAmount*ratio*profit_percentage)/12;
                
                //var result_profit=(depositAmount*number_of_binding_days_of_deposit(date)*profit_percentage)/365;
                // console.log(((result_profit_modify).toPrecision(2))*1000);
                $("#amount_of_the_monthly_advance").html((((result_profit_modify/1000).toPrecision(2))*1000)+'<?php echo($lang=='ar'?' ليرة سوري ':' Syrian Pound ') ?>');
                
                $("#first_date_advance_deposit").html(first_date_advance_deposit(date));
              }
             else if(depositDuration == 24)
              {
                var profit_percentage=profit[0][5]/100;
                var ratio=80/100;
                var result_profit_modify=(depositAmount*ratio*profit_percentage)/12;
                //var result_profit=(depositAmount*number_of_binding_days_of_deposit(date)*profit_percentage)/365;
                $("#amount_of_the_monthly_advance").html((((result_profit_modify/1000).toPrecision(2))*1000)+'<?php echo($lang=='ar'?' ليرة سوري ':' Syrian Pound ') ?>');
                
                $("#first_date_advance_deposit").html(first_date_advance_deposit(date));
              }
       
       }
});

/////////////////////////////////////////////////////// احتساب التمويل /////////////////////////////////////////
$("#financeResult").click(function(){
  //  checkVal();

var selectedItem= $('#exchange').find(":selected").val();
 var yn= $('#exchange').find(":selected").attr("data-max-value")

$('#time').attr("max",selectedItem); 
// alert(selectedItem);

var insertedValue = $("#time").val();
//if(!insertedValue)
if(!insertedValue || !$.isNumeric(insertedValue) || insertedValue<0 || insertedValue.indexOf('-') == 0){
  var chack_insertedValue='false';
    alert('<?php echo($lang=='ar'?'الرجاء ادخال مدة التمويل':'Please enter the funding duration') ?>');
}else{chack_insertedValue='true';}
 var maxValue=[<?php 
                $finances=CalculatorFinance::model()->findAll();
                foreach($finances as $finance)
                {
                  echo "['".$finance->finance_type."','".$finance->finance_type_en."',".$finance->max_duration_months.",],";
                }
                  ?>
                ];
var MessageError='';
MessageError=<?php echo($lang=='ar'?'"هذه المدة غير متاحة إن القيمة الاعلى لمدة التمويل هي: "':'"This duration value is invalid the max value is:  "'); ?>;
var Month='';
Month="<?php echo($lang=='en'?'Month':'شهر');?>";
for (i = 0; i < maxValue.length; i++) 
{
  if((maxValue[i][0]== selectedItem || maxValue[i][1]== selectedItem) && maxValue[i][2] < insertedValue)
  {
        alert(MessageError+' '+maxValue[i][2]+' '+Month);
  }
}
var timeRange= $('#time').val();
if(timeRange==0){timeRange=1}
var range=timeRange*3;
var financing_type=$('.calculator #menu2 .menu2-first-part-form .form-control').val();
var amountmenu2=$('#amountmenu2').val();

if(!amountmenu2 || !$.isNumeric(amountmenu2) || amountmenu2<0 || amountmenu2.indexOf('-') == 0){
  var chack_amountmenu2='false';
    alert('<?php echo($lang=='ar'?'الرجاء ادخال المبلغ':'Please enter the amount') ?>');
}else{chack_amountmenu2='true';}

if(financing_type==0){
  var chack_financing_type='false';
    alert('<?php echo($lang=='ar'?'الرجاء ادخال طبيعة التمويل':'Please enter the transfer type') ?>');
}else{chack_financing_type='true'}
 
// var amountmenu22=$('#amount22').attr('value');
var currencymenu2=$('#currencymenu2').val();
 var financ=[<?php
  $finances=CalculatorFinance::model()->findAll();
  
	foreach($finances as $finance)                              
  {
	 echo "['".$finance->finance_type."',".$finance->minimum_first_payment.",".$finance->profit_ratio.",'".$finance->maximum_duration_of_finance."','".$finance->finance_type_en."','".$finance->maximum_duration_of_finance_en."'],";
   
  }
   ?>];
  // if((amountmenu2 || $.isNumeric(amountmenu2) || amountmenu2<0 || amountmenu2.indexOf('-') != 0) && !financing_type==0 && (insertedValue || $.isNumeric(insertedValue) || insertedValue<0 || insertedValue.indexOf('-') != 0))
  if(chack_amountmenu2=='true' && chack_financing_type=='true' && chack_insertedValue=='true')
  { 
    for(i = 0; i < financ.length; i++) 
    {
      if(financ[i][<?php echo($lang=='en'?4:0); ?>]== financing_type)
      {
        $("#amount_to_be_paid").html(financ[i][1]+'%');
        var financing_type_percentage=financ[i][1]/100;
        var funding_amount= amountmenu2 - (amountmenu2*financing_type_percentage);
        // alert(funding_value);
        $("#resault2").val(funding_amount.toFixed(2));
        $("#funding_amount").html(funding_amount.toFixed(2));
        $("#maximum_duration_of_funding").html(financ[i][<?php echo($lang=='en'?5:3) ?>]);
        $("#profit_ratio").html(financ[i][2]+'%');
        // var number_of_year= range/12;maxValue

        //  var number_of_year= yn/12;
         var number_of_year=insertedValue/12;

        var profit_ratio=financ[i][2]/100;
        var profit_amount =number_of_year*funding_amount*profit_ratio;
        // alert('profit_amount = '+number_of_year +' * '+funding_amount+' * '+profit_ratio+ '');
        // die;
        var debt_amount = funding_amount + profit_amount;

        // var monthly_installment = debt_amount / yn;
        var monthly_installment = debt_amount / insertedValue;

        var minimum_monthly_income_required=parseInt(monthly_installment)/0.4;
        $("#debt_amount").html(parseInt(monthly_installment.toFixed(2)));
        $("#profit_amount").html(profit_amount.toFixed(2));
        $("#monthly_installment").html(monthly_installment.toFixed(2));
        $("#minimum_monthly_income_required").html(parseInt(minimum_monthly_income_required.toFixed(2)));
        $("#profit_note").html('<?php echo($lang=='en'?'This calculator offers approximate values and may be subject to change without notice.':'هذه الحاسبة تقدِم قيم تقريبية، وقد تخضع لأي تعديلات دون إشعار مسبق.') ?>');
      }
    }
}
    
});

