/************************************Quick Contact Start***********/
function hideAlerts()
{	
		document.getElementById("NameValidator").style.visibility = "hidden";	
		document.getElementById("NameValidator").style.display = "none";
		document.getElementById("EmailValidator1").style.visibility = "hidden";	;	
		document.getElementById("EmailValidator1").style.display = "none";	
		document.getElementById("EmailValidator2").style.visibility = "hidden";	
		document.getElementById("EmailValidator2").style.display = "none";	
		document.getElementById("PhoneValidator1").style.visibility = "hidden";		
        document.getElementById("PhoneValidator1").style.display = "none";	
		document.getElementById("PhoneValidator2").style.visibility = "hidden";		
        document.getElementById("PhoneValidator2").style.display = "none";	
		document.getElementById("WanttoValidator").style.visibility = "hidden";		
		document.getElementById("WanttoValidator").style.display = "none";	
		document.getElementById("ProtypeValidator").style.visibility = "hidden";	
		document.getElementById("ProtypeValidator").style.display = "none";	
		document.getElementById("LocationValidator").style.visibility = "hidden";	
		document.getElementById("LocationValidator").style.display = "none";	
		document.getElementById("DescValidator").style.visibility = "hidden";	
		document.getElementById("DescValidator").style.display = "none";	
}
function submitQForm()
{
	hideAlerts();	
	var flag = true;
	var theForm = document.qForm;
	
	if(trim(theForm.yName.value) == "")
	{
		document.getElementById("NameValidator").style.visibility = "visible";	
		document.getElementById("NameValidator").style.display = "block";	
		
		flag = false;
	}
	if(trim(theForm.yEmail.value) == "")
	{
		document.getElementById("EmailValidator1").style.visibility = "visible";	;	
		document.getElementById("EmailValidator1").style.display = "block";	
		flag = false;
	}
	else if(!isValidEmail(theForm.yEmail.value))
	{
		document.getElementById("EmailValidator2").style.visibility = "visible";	
		document.getElementById("EmailValidator2").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yPhone.value) == "")
	{
		document.getElementById("PhoneValidator1").style.visibility = "visible";		
        document.getElementById("PhoneValidator1").style.display = "block";	
		flag = false;
	}
	else if(!isValidPhone(theForm.yPhone.value))
	{
		document.getElementById("PhoneValidator2").style.visibility = "visible";		
        document.getElementById("PhoneValidator2").style.display = "block";	
		flag = false;
	}
	if((theForm.yWantto.value) == "")
	{
		document.getElementById("WanttoValidator").style.visibility = "visible";		
		document.getElementById("WanttoValidator").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yProtype.value) == "")
	{
		document.getElementById("ProtypeValidator").style.visibility = "visible";	
		document.getElementById("ProtypeValidator").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yLocation.value) == "")
	{
		document.getElementById("LocationValidator").style.visibility = "visible";	
		document.getElementById("LocationValidator").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yDesc.value) == "")
	{
		document.getElementById("DescValidator").style.visibility = "visible";	
		document.getElementById("DescValidator").style.display = "block";	
		flag = false;
	}
	if(flag)
	{		
		theForm.submit();
	}
	else
	{		
		return flag;
	}

}

function hideEMIAlerts()
{	
		document.getElementById("NameValidator").style.visibility = "hidden";	
		document.getElementById("NameValidator").style.display = "none";
		document.getElementById("EmailValidator1").style.visibility = "hidden";	;	
		document.getElementById("EmailValidator1").style.display = "none";	
		document.getElementById("EmailValidator2").style.visibility = "hidden";	
		document.getElementById("EmailValidator2").style.display = "none";			
}

function sendEmail()
{	
	hideEMIAlerts();	
	var flag = true;
	var theForm = document.loanForm;
	
	if(trim(theForm.yName.value) == "")
	{
		document.getElementById("NameValidator").style.visibility = "visible";	
		document.getElementById("NameValidator").style.display = "block";	
		
		flag = false;
	}
	if(trim(theForm.yEmail.value) == "")
	{
		document.getElementById("EmailValidator1").style.visibility = "visible";	;	
		document.getElementById("EmailValidator1").style.display = "block";	
		flag = false;
	}
	else if(!isValidEmail(theForm.yEmail.value))
	{
		document.getElementById("EmailValidator2").style.visibility = "visible";	
		document.getElementById("EmailValidator2").style.display = "block";	
		flag = false;
	}
	if(flag)
	{		
		theForm.monthlyR.value = document.getElementById("mainContent").innerHTML;		
		theForm.submit();
	}
	else
	{		
		return flag;
	}


}
/************************************Quick Contact Ends***********/

/************************************Quick Residential Form Start***********/

function hideResAlerts()
{	
		document.getElementById("WanttoValidator").style.visibility = "hidden";	
		document.getElementById("WanttoValidator").style.display = "none";
		document.getElementById("ProtypeValidator").style.visibility = "hidden";	;	
		document.getElementById("ProtypeValidator").style.display = "none";	
		document.getElementById("CityValidator").style.visibility = "hidden";	
		document.getElementById("CityValidator").style.display = "none";	
		document.getElementById("StateValidator").style.visibility = "hidden";		
        document.getElementById("StateValidator").style.display = "none";	
		document.getElementById("DescValidator").style.visibility = "hidden";		
        document.getElementById("DescValidator").style.display = "none";	
		document.getElementById("NameValidator").style.visibility = "hidden";		
		document.getElementById("NameValidator").style.display = "none";	
		document.getElementById("EmailValidator1").style.visibility = "hidden";	
		document.getElementById("EmailValidator1").style.display = "none";	
		document.getElementById("EmailValidator2").style.visibility = "hidden";	
		document.getElementById("EmailValidator2").style.display = "none";	
		document.getElementById("PhoneValidator1").style.visibility = "hidden";	
		document.getElementById("PhoneValidator1").style.display = "none";	
		document.getElementById("PhoneValidator2").style.visibility = "hidden";	
		document.getElementById("PhoneValidator2").style.display = "none";	
		document.getElementById("CityValidator1").style.visibility = "hidden";	
		document.getElementById("CityValidator1").style.display = "none";	
		document.getElementById("StateValidator1").style.visibility = "hidden";	
		document.getElementById("StateValidator1").style.display = "none";	
		document.getElementById("CountryValidator").style.visibility = "hidden";	
		document.getElementById("CountryValidator").style.display = "none";	
		document.getElementById("ContactMethodValidator").style.visibility = "hidden";	
		document.getElementById("ContactMethodValidator").style.display = "none";	
}

function submitResForm()
{
	hideResAlerts();	
	var flag = true;
	var theForm = document.resForm;

	if(theForm.cWantto.value == "")
	{
		document.getElementById("WanttoValidator").style.visibility = "visible";	
		document.getElementById("WanttoValidator").style.display = "block";			
		flag = false;
	}

	if(theForm.cProtype.value == "")
	{
		document.getElementById("ProtypeValidator").style.visibility = "visible";	
		document.getElementById("ProtypeValidator").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.cCity.value) == "")
	{
		document.getElementById("CityValidator").style.visibility = "visible";	
		document.getElementById("CityValidator").style.display = "block";			
		flag = false;
	}
	if(trim(theForm.cState.value) == "")
	{
		document.getElementById("StateValidator").style.visibility = "visible";	
		document.getElementById("StateValidator").style.display = "block";			
		flag = false;
	}
	if(trim(theForm.yName.value) == "")
	{
		document.getElementById("NameValidator").style.visibility = "visible";	
		document.getElementById("NameValidator").style.display = "block";			
		flag = false;
	}
	if(trim(theForm.yEmail.value) == "")
	{
		document.getElementById("EmailValidator1").style.visibility = "visible";	;	
		document.getElementById("EmailValidator1").style.display = "block";	
		flag = false;
	}
	else if(!isValidEmail(theForm.yEmail.value))
	{
		document.getElementById("EmailValidator2").style.visibility = "visible";	
		document.getElementById("EmailValidator2").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yPhone.value) == "")
	{
		document.getElementById("PhoneValidator1").style.visibility = "visible";		
        document.getElementById("PhoneValidator1").style.display = "block";	
		flag = false;
	}
	else if(!isValidPhone(theForm.yPhone.value))
	{
		document.getElementById("PhoneValidator2").style.visibility = "visible";		
        document.getElementById("PhoneValidator2").style.display = "block";	
		flag = false;
	}
	if((theForm.yCity.value) == "")
	{
		document.getElementById("CityValidator1").style.visibility = "visible";		
		document.getElementById("CityValidator1").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yState.value) == "")
	{
		document.getElementById("StateValidator1").style.visibility = "visible";	
		document.getElementById("StateValidator1").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yCountry.value) == "")
	{
		document.getElementById("CountryValidator").style.visibility = "visible";	
		document.getElementById("CountryValidator").style.display = "block";	
		flag = false;
	}
	if(trim(theForm.yContactMethod.value) == "")
	{
		document.getElementById("ContactMethodValidator").style.visibility = "visible";	
		document.getElementById("ContactMethodValidator").style.display = "block";	
		flag = false;
	}
	if(flag)
	{		
		theForm.submit();
	}
	else
	{		
		return flag;
	}

}

/************************************Quick Residential Form Ends***********/



// Removes leading whitespaces
  function LTrim( value ) 
  {    	
     	var re = /\s*((\S+\s*)*)/;
     	return value.replace(re, "$1");     	
   }
    
    // Removes ending whitespaces
    function RTrim( value ) 
	{    	
    	var re = /((\s*\S+)*)\s*/;
    	return value.replace(re, "$1");    	
    }
    
    // Removes leading and ending whitespaces
    function trim( value ) 
	{    	
    	return LTrim(RTrim(value));    	
    }
	
	function isValidEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		   
		    return false
		 }
		 if (str.indexOf(dot,(lat+2))==-1){		    
		    return false
		 }		
		 if (str.indexOf(" ")!=-1)
		 {		   
		    return false
		 }

 		 return true					
	}

	function isValidPhone(s)
	{  
		var i;
		for (i = 0; i < s.length; i++)
		{   		
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}		
		return true;
}

function get_figure_round(X) { return Math.round(X*100)/100 }

function isValidNumber(inpString) {	
   return /^[-+]?\d+(\.\d+)?$/.test(trim(inpString));
}

function showmessage() {
var allValid = true;
thisStaticDiv = document.getElementById('loanAmount').innerHTML ='';
thisStaticDiv = document.getElementById('interestRate').innerHTML ='';
thisStaticDiv = document.getElementById('monthsTenure').innerHTML ='';

if (document.loanForm.loan.value == '' || !isValidNumber(document.loanForm.loan.value))
{
	var thisStaticDiv = document.getElementById('loanAmount');
	thisStaticDiv.innerHTML ='<font color=red>Please enter a valid Loan Amount</font>';
	allValid = false;
}
if (document.loanForm.rate.value == '' || !isValidNumber(document.loanForm.rate.value))
{
	var thisStaticDiv = document.getElementById('interestRate');
	thisStaticDiv.innerHTML ='<font color=red>Please enter a valid Interest Rate</font>';
	allValid = false;
}
if (document.loanForm.months.value == '' || !isValidNumber(document.loanForm.months.value))
{
	var thisStaticDiv = document.getElementById('monthsTenure');
	thisStaticDiv.innerHTML ='<font color=red>Please enter a valid Loan Tenure</font>';
	allValid = false;
}
else if (document.loanForm.months.value > 360)
{
	var thisStaticDiv = document.getElementById('monthsTenure');
	thisStaticDiv.innerHTML ='<font color=red>Please enter a Loan Tenure not exceeding 360 months</font>';
	allValid = false;
}
	

 if (!allValid)
 { 
 document.loanForm.pay.value = "Incomplete data";
document.loanForm.tot_amount.value = "Incomplete data";
document.loanForm.tot_interest.value = "Incomplete data";
document.loanForm.yearly_interest.value = "Incomplete data";
document.loanForm.interest_pa.value = "Incomplete data";
document.loanForm.interest_pm.value = "Incomplete data";
document.getElementById('showChartLink').style.display="none";
document.getElementById('showEmailLink').style.display="none";
document.getElementById('hideEmailLink').style.display="none";
document.getElementById('mainContent').style.display="none";	
document.getElementById('hideChartLink').style.display="none";
 }
else
 {
 var princ = document.loanForm.loan.value;
 var term  = document.loanForm.months.value;
 var intr   = document.loanForm.rate.value / 1200;
 var yrs   = document.loanForm.months.value / 12;
 document.loanForm.pay.value = get_figure_round(princ * intr / (1 - (Math.pow(1/(1 + intr), term))));
 document.loanForm.tot_amount.value = get_figure_round(document.loanForm.pay.value * term);
 document.loanForm.tot_interest.value = get_figure_round(document.loanForm.tot_amount.value - princ);
 document.loanForm.yearly_interest.value = get_figure_round(document.loanForm.tot_interest.value / yrs);
 document.loanForm.interest_pa.value = get_figure_round(document.loanForm.yearly_interest.value / princ * 100);
 document.loanForm.interest_pm.value = get_figure_round((document.loanForm.yearly_interest.value / princ * 100)/12);
 var htmlt = '<TABLE cellSpacing=0 cellPadding=4 width=500 align=center border=1 id=home-loan-TBL-EMI-Cal><tr bgcolor=orange><td><B>Months</B></td><td><B>Opening</B></td><td><B>Interest</B></td><td><B>Principal</B></td><td><B>Closing</B></td></tr>'
 	
	var emiCal = document.loanForm.pay.value;
	var princal = 0;
	var intrest = 0;
	var  principal = 0;
	var  prinLast = 0;

 for(var n=1; n<=term; n++)
 { 

	htmlt = htmlt + '<tr>';
	htmlt = htmlt + '<td>' +n+'</td>' ;
	if(n==1)
	{
		princal = princ;	
	}
	else
	{
		princal = prinLast;
	}

   htmlt = htmlt + '<td>' +roundOff(princal)+'</td>' ;
	intrest = princal* intr;
	htmlt = htmlt + '<td>' +roundOff(intrest)+'</td>' ;

	principal = emiCal - intrest;
	 htmlt = htmlt + '<td>' +roundOff(principal)+'</td>' ;

	 prinLast =princal - principal;
	 htmlt = htmlt + '<td>' +roundOff(prinLast)+'</td>' ;
	 htmlt = htmlt + '</tr>';
 }
 htmlt = htmlt + '</table>';
 var thisStaticDiv = document.getElementById('mainContent');
thisStaticDiv.innerHTML = htmlt;
document.getElementById('showChartLink').style.display="block";
document.getElementById('hideChartLink').style.display="none";
document.getElementById('mainContent').style.display="none";
document.getElementById('showEmailInput').style.display="none";
document.getElementById('showEmailLink').style.display="block";
document.getElementById('hideEmailLink').style.display="none";
 }
}
function showEmailInputs()
{
	document.getElementById('showEmailInput').style.display="block";
	document.getElementById('showEmailLink').style.display="none";
	document.getElementById('hideEmailLink').style.display="block";
}

function roundOff(num,decimalplaces){
decimalplaces = 0;
var decimalfactor = Math.pow(10,decimalplaces);
var roundedValue = Math.round(num*decimalfactor)/decimalfactor;
return roundedValue;
}

function showChart(action)
{
	document.getElementById('hideChartLink').style.display="block";
	document.getElementById('showChartLink').style.display="none";	
	document.getElementById('mainContent').style.display="block";
	
}
function hideChart()
{
	document.getElementById('hideChartLink').style.display="none";
	document.getElementById('showChartLink').style.display="block";
	document.getElementById('mainContent').style.display="none";	
}

function hideEmailForm()
{
	document.getElementById('showEmailInput').style.display="none";	
	document.getElementById('showEmailLink').style.display="block";
	document.getElementById('hideEmailLink').style.display="none";
}

function clearValues()
{
 hideAlertsSpan();
  document.getElementById("loanTenure").value = "";
  document.getElementById("interestRate").value = "";
  document.getElementById("txtSumValue").value = "";
  document.getElementById("monthlyIncome").value = "";
  document.getElementById("otherObligation").value = "";
  document.getElementById("co_monthlyIncome").value = "";
  document.getElementById("co_otherObligation").value = "";  
}
 
function fillBlank(objectParam)
{
  if(objectParam.value == "")
  {
   objectParam.value = "0";
  }
}
function hideAlertsSpan()
{ 
  document.getElementById("errorMessage").innerHTML ='';  
  document.getElementById("interestRateSpan").innerHTML ='';  
  document.getElementById("loanTenureSpan").innerHTML ='';   
  document.getElementById("monthlyIncomeSpan").innerHTML ='';  
  document.getElementById("otherObligationSpan").innerHTML ='';        
  document.getElementById("CoMonthlyIncomeSpan").innerHTML ='';       
  document.getElementById("CoOtherObligationSpan").innerHTML ='';   
}
 
function calculateEligibility() {  
 hideAlertsSpan();
  var allValid = true;
  var rate_of_int = 0;
  var Tenure = 0;  
  var EMIamt = 0;
  var EliAmt = 0; 
  var RestType = "Yearly";  
  
  var restFrequency = document.getElementById("restFrequency");
  var loanTenure = document.getElementById("loanTenure");
  var interestRate = document.getElementById("interestRate");  
  var co_monthlyIncome = document.getElementById("co_monthlyIncome");
  var co_otherObligation = document.getElementById("co_otherObligation");
  var monthlyIncome = document.getElementById("monthlyIncome");
  var otherObligation = document.getElementById("otherObligation");      
  
  //var trEligibility = document.getElementById("trEligibility");
  
  if(loanTenure.value == "")
  {   
   var thisStaticDiv = document.getElementById('loanTenureSpan');
   thisStaticDiv.innerHTML ='<br><font color=red>Please Enter Loan Tenure (In Years)</font>';
   allValid = false;
  }
  else
  {
   if(isNaN(loanTenure.value))
   {    
    var thisStaticDiv = document.getElementById('loanTenureSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Tenure, Should be a valid Numbers</font>';
    allValid = false;
   }
  }  
  if(interestRate.value == "")
  {   
   var thisStaticDiv = document.getElementById('interestRateSpan');
   thisStaticDiv.innerHTML ='<br><font color=red>Please Enter Rate of Interest</font>';
   allValid = false;
  }
  else
  {
   if(isNaN(interestRate.value))
   {
    var thisStaticDiv = document.getElementById('interestRateSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Rate of Interest, Should be a valid Numbers</font>';
    allValid = false;
   }
  } 
   
  if(restFrequency.checked)
   RestType = "Yearly";
  else
   RestType = "Monthly";
     
  if(monthlyIncome.value != "")  
  {
   if(isNaN(monthlyIncome.value))
   {    
    var thisStaticDiv = document.getElementById('monthlyIncomeSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Net Income, Should be a valid Numbers</font>';
    allValid = false;
   }   
  }
  else
  {
   monthlyIncome.value = "0";
  } 
  
  if(otherObligation.value != "")  
  {
   if(isNaN(otherObligation.value))
   {
    var thisStaticDiv = document.getElementById('otherObligationSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Other obligation, Should be a valid Numbers</font>';
    allValid = false;
   }   
  } 
  else
  {
   otherObligation.value = "0";
  } 
  
  if(co_monthlyIncome.value != "")  
  {
   if(isNaN(co_monthlyIncome.value))
   {    
    var thisStaticDiv = document.getElementById('CoMonthlyIncomeSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Net Income, Should be a valid Numbers</font>';
    allValid = false;
   }   
  }
  else
  {
   co_monthlyIncome.value = "0";
  } 
  
  if(co_otherObligation.value != "")  
  {
   if(isNaN(co_otherObligation.value))
   {
    var thisStaticDiv = document.getElementById('CoOtherObligationSpan');
    thisStaticDiv.innerHTML ='<br><font color=red>Incorrect Net Income, Should be a valid Numbers</font>';
    allValid = false;
   }   
  }
  else
  {
   co_otherObligation.value = "0";
  } 
  
  if(!allValid)
  {
   var thisStaticDiv = document.getElementById("errorMessage");
   thisStaticDiv.innerHTML ='<font color=red><b>Please correct the below errors</b></font>';
    
   return false;
  }
  
  Tenure  = parseFloat(loanTenure.value);
  rate_of_int  = parseFloat(interestRate.value);
 
  var NetIncome = parseFloat(monthlyIncome.value) + parseFloat(co_monthlyIncome.value);
  var tempEligibility = calculateTempElig(parseFloat(NetIncome)); 
  
  var FixedObligation1 = parseFloat(co_otherObligation.value);
  var FixedObligation2 = parseFloat(otherObligation.value);
  var FixedObligation = FixedObligation1 + FixedObligation2;
  
  tempEligibility  = tempEligibility  - FixedObligation;
  
  var emival = CalEMI(100000,Tenure,rate_of_int/100,RestType);
  EMI = parseInt(Math.round(emival));
  if(EMI < emival)
  {
   EMI = EMI + 1;
  }
  EliAmt = tempEligibility / EMI * 100000 ;  
  EliAmt = Math.round(EliAmt);  
  EliAmt = formatCurrToStr(EliAmt,0,'INR');  
  document.getElementById("txtSumValue").value = EliAmt; 
  return true;
}
 
function calculateTempElig(TotalNAS) {     
  var iir = CalculateIIR(TotalNAS);  
  var tempEligibility = parseFloat(TotalNAS * iir/100);
  return tempEligibility;
}
 
function CalculateIIR(TotalNAS)
{
  if  (TotalNAS < 4000) {
   iir = 0;
  }
  else if  (TotalNAS >= 4000 && TotalNAS <= 10000){
   iir = 40;
  }
  else if  (TotalNAS >= 10001 && TotalNAS <= 20000) {
   iir = 45;
  }
  else if  (TotalNAS >= 20001 && TotalNAS <= 30000) {
   iir = 50;
  }
  else if  (TotalNAS >= 30001 && TotalNAS <= 50000) {
   iir = 55;
  }
  else  {
   iir = 60;
  }
  return iir;
}
 
function isNumeric(text) {
    if(text == "") {
   return true;
    }
    if(isNaN(text)) {
   
   return false;
   
    }
    else {
  return true;
    }
}
 
function putDecimal(thetext,decplace)      
{    
  if(isNaN(thetext)== false && (parseFloat(thetext)>=0) )
  {   
   thetext = "" + Math.round(parseFloat(thetext) * Math.pow(10,decplace)) /  Math.pow(10,decplace);
   
    if(thetext.indexOf('.') == -1 && decplace > 0)
   {
     thetext += "."; 
   }
      
   dectext = thetext.substring(thetext.indexOf('.')+1, thetext.length);
   var i=0;
   for(i = 0;i < (decplace) - (dectext.length) ; i++ )
   {
     thetext += "0";
   }   
  }
  return thetext;       
}
function CalEMI(Principal,Year,Rate,InterestRateType)  
{  
  var EMI_val = 0.0;    
  if(InterestRateType == 'Yearly')
  {   
   EMI_val = ((parseFloat(Rate)>0) & (parseFloat(Year)>0)) ? ((1/12) *(((Principal*Rate)*Math.pow((1+Rate),Year))/(Math.pow((1+Rate),Year)-1))) : (0)    
  }
  else
  {     
   EMI_val = ((parseFloat(Rate)>0) & (parseFloat(Year)>0))? ((((Principal*(Rate/12))*Math.pow((1+(Rate/12)),(Year*12)))/(Math.pow((1+(Rate/12)),(Year*12))-1))) : (0)    
  }
  return EMI_val;
}
 
function formatCurrToStr(number,decPlaces,format)
{
  var DecimalPlace=0;
  var hundreds="";
  var Paise="";
  var comma="";
  var comma1="";
  var ReturnValue="";
  number = number + "";
  var MyNumber=number.replace(/,/g,'');
  var TestN=0;
  var LenofCurrency=0;
  var Minus ="";
  if(number.indexOf("-") >= 0)
  {
     Minus = "-";
     MyNumber = MyNumber.substring(1);
  }
  
  if(!isNumeric(MyNumber))
  {
    return "0"
  }
  MyNumber = putDecimal(MyNumber,decPlaces);
  
  if(format == "INR")
  {
    
  DecimalPlace = MyNumber.lastIndexOf(".");
  LenofCurrency = MyNumber.length; 
  LenofCurrency = LenofCurrency - DecimalPlace;
  
  if(DecimalPlace > 0)
  {
  Paise = MyNumber.substring(MyNumber.indexOf("."));
  
   MyNumber = MyNumber.substring(0,DecimalPlace);
   
  }
  
  
  if (MyNumber.length <=3)
  {
   ReturnValue=MyNumber+Paise;
  } 
  if (MyNumber.length == 4)
  {
   hundreds = MyNumber.substring(MyNumber.length-3);
   MyNumber= MyNumber.substring(0,1);
   ReturnValue=MyNumber+","+ hundreds + Paise;
  } 
  if (MyNumber.length == 5)
  {
   hundreds = MyNumber.substring(MyNumber.length-3);
   MyNumber= MyNumber.substring(0,2);
   ReturnValue=MyNumber+","+ hundreds + Paise;
  } 
  if (MyNumber.length > 5)
  {
   hundreds = MyNumber.substring(MyNumber.length-3);
   DecimalPlace = DecimalPlace-2;
   
   MyNumber=MyNumber.substring(0,MyNumber.length-hundreds.length);
   
   TestN = MyNumber.length ;
   while(TestN > 2)
   {
    comma =  MyNumber.substring(TestN-2);
    comma1= "," + comma+comma1;
    TestN=TestN-2;
    MyNumber= MyNumber.substring(0,MyNumber.length-comma.length);
    ReturnValue=MyNumber+comma1 +","+ hundreds + Paise;
     
   }
  }
  number = Minus + ReturnValue;
    }   
    return number    
}