//global Object
var GRInvObj  = new ReturnInvestmentModule();
var GConObj  = new CommonConstants();


/*************************Main Object that holds all function and data related to the Module**************************/
function ReturnInvestmentModule(){
	try{
//[Common Variable Starts]	
	this.taxRate=11.33;
	this.rowId=0;//table row number
//[Common Variable Ends]	

//[Main Variable Starts]	
		this.v_main_schemetype=1;
		this.v_main_option=3;
		this.v_main_dtof_purch='';
		this.v_main_unit_purch=0;
		this.v_main_purch_cost=0;
		this.v_main_dtof_redemp='';
		this.v_main_redemp_val=0;
		this.taxrate_with_surcharge_indexed=0
		this.taxrate_without_surcharge_indexed=0
		this.taxrate_with_surcharge_nonindexed=0
		this.taxrate_without_surcharge_nonindexed=0
//[Main Variable Ends]	

//[Common Functions Starts]	
		this.getTotPurchaseCost = function(){
			return ( this.v_main_unit_purch * this.v_main_purch_cost );
		}

		this.getRedempVal =	function(){
			return ( this.v_main_unit_purch * this.v_main_redemp_val );
		}

		this.getCapGainVal = function(){
			return (this.v_main_redemp_val * this.v_main_unit_purch)-(this.v_main_unit_purch * this.v_main_purch_cost)			
		}

		this.getSalValDebtMF = function(){
			return (this.v_main_redemp_val * this.v_main_unit_purch)
		}
		
		this.getPurchCostDebtMF = function(){
			return (this.v_main_unit_purch * this.v_main_purch_cost)			
		}

		this.getIndexNoPurchYear =function(p_Date){
			if(p_Date != null && p_Date != 'undefined' && p_Date != ''){
				return getCostInflationIndex(getDateObject(p_Date,'dd/mm/yyyy'));		
			}else{
				return getCostInflationIndex(this.v_main_dtof_purch);		
			}
		}

		this.getIndexNoSaleYear =function(){
			return getCostInflationIndex(this.v_main_dtof_redemp);		
		}

		this.getCapitalGainTaxPay=function(p_SurchId){
			var	v_sale_deb_mf=this.getSalValDebtMF();   
			var	v_purch_cost_deb_mf=this.getPurchCostDebtMF(); 
			/******with Indexation start****/			
			var v_indexno_purch_year=this.getIndexNoPurchYear();
			var v_indexno_sale_year=this.getIndexNoSaleYear();
			var v_indexcost_of_purch=(v_purch_cost_deb_mf  *  v_indexno_sale_year / v_indexno_purch_year)
			var v_indexed_capgain_perloss= v_sale_deb_mf-v_indexcost_of_purch
			var v_taxrate_capgain_indexed=0			
			if(v_indexed_capgain_perloss>0){
				if($$(p_SurchId) == '1'){
					v_taxrate_capgain_indexed=this.taxrate_with_surcharge_indexed
				}else{					
					v_taxrate_capgain_indexed=this.taxrate_without_surcharge_indexed
				}				
			}else{
				v_taxrate_capgain_indexed=0
			}
			var v_indexed_capgain=v_indexed_capgain_perloss<0?0:(v_indexed_capgain_perloss * v_taxrate_capgain_indexed)
			/******with Indexation end****/			

			/******with Non Indexation start****/			
			var v_nonindexed_capgain_perloss= v_sale_deb_mf-v_purch_cost_deb_mf
			var v_taxrate_capgain_non_indexed=0			
			if(v_nonindexed_capgain_perloss>0){
				if($$(p_SurchId) == '1'){
					v_taxrate_capgain_non_indexed=this.taxrate_with_surcharge_nonindexed
				}else{					
					v_taxrate_capgain_non_indexed=this.taxrate_without_surcharge_nonindexed
				}				
			}else{
				v_taxrate_capgain_non_indexed=0
			}
			var v_non_indexed_capgain=(v_nonindexed_capgain_perloss * v_taxrate_capgain_non_indexed)
			/******with Non Indexation end****/			
			var v_final_capgain=0;
			if(v_non_indexed_capgain < v_indexed_capgain){
				v_final_capgain=Math.round(v_non_indexed_capgain); 
			}else{
				v_final_capgain=Math.round(v_indexed_capgain); 
			}
			return v_final_capgain;
		}


		this.getCapitalGainTaxPayOnDividend=function(p_module,p_rowId){
			/******with Indexation start****/			
			var v_indexno_purch_year=this.getIndexNoPurchYear(p_module+'_divdt'+p_rowId);
			var v_indexno_sale_year=this.getIndexNoSaleYear();
			var v_indexcost_of_purch=(($$(p_module+'_divamt'+p_rowId))  *  v_indexno_sale_year / v_indexno_purch_year)
			var temp_units_rec=$$(p_module+'_divamt'+p_rowId)/$$(p_module+'_divnav'+p_rowId)
			var v_indexed_capgain_perloss= [ temp_units_rec * this.v_main_redemp_val ] -v_indexcost_of_purch
			var v_taxrate_capgain_indexed=0			
			if(v_indexed_capgain_perloss>0){
				if($$(p_module+'_surch') == '1'){
					v_taxrate_capgain_indexed=22.44/100
				}else{					
					v_taxrate_capgain_indexed=20.4/100
				}				
			}else{
				v_taxrate_capgain_indexed=0
			}
			var v_indexed_capgain=v_indexed_capgain_perloss<0?0:(v_indexed_capgain_perloss * v_taxrate_capgain_indexed)
			/******with Indexation end****/			

			/******with Non Indexation start****/			
			var v_nonindexed_capgain_perloss= [ temp_units_rec * this.v_main_redemp_val ]-$$(p_module+'_divamt'+p_rowId)
			var v_taxrate_capgain_non_indexed=0			
			if(v_nonindexed_capgain_perloss>0){
				if($$(p_module+'_surch') == '1'){
					v_taxrate_capgain_non_indexed=11.22/100
				}else{					
					v_taxrate_capgain_non_indexed=10.2/100
				}				
			}else{
				v_taxrate_capgain_non_indexed=0
			}
			var v_non_indexed_capgain=(v_nonindexed_capgain_perloss * v_taxrate_capgain_non_indexed)
			/******with Non Indexation end****/			
			var v_final_capgain=0;
			if(v_non_indexed_capgain < v_indexed_capgain){
				v_final_capgain=Math.round(v_non_indexed_capgain); 
			}else{
				v_final_capgain=Math.round(v_indexed_capgain); 
			}
//			alert('v_final_capgain   '+v_final_capgain);
			return v_final_capgain;
		}

//[Common Functions Ends]	

//[Main Variable Starts]	
		this.populateAll = function (p_type){
			if(p_type == 'main'){
				if(populateReturnInvestment(p_type)){//returns TRUE if validation succeeds 
					return false;
				}else{
					return true;
				}
			}
		}

		this.resetAll = function (p_type,resetType){//resetType:both(fields and object) & resetType:fields(fields only) & & resetType:object(object only)
			if(p_type == 'main'){
				if(resetType == 'both'){
					resetReturnInvestment(p_type,resetType)																	
				}
			}
		}

//EQUITY STARTED
		this.calculateEQGRIt = function (){
			var capGainVal =this.getCapGainVal();			
			var dateFmt=GConObj.dtFmtStr1;
			$('eq_gr_it_capgainval').value=capGainVal ;			
			if( capGainVal >=0){
				$('eq_gr_it_capgain').innerHTML="You have made a Gain of Rs";			
			}else{
				$('eq_gr_it_capgain').innerHTML="You have made a Loss of Rs";			
			}
			var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal());
			var temp_dateArr = new Array();
			temp_dateArr[0]=this.v_main_dtof_purch;
			temp_dateArr[1]=this.v_main_dtof_redemp;
			$('eq_gr_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
		}

		this.calculateEQGRSt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			if(p_action == 'taxchange'){
				if(capGainVal <=0){
					$('eq_gr_st_taxpay').value='0'
				}else{
					$('eq_gr_st_taxpay').value=Math.round(capGainVal*this.taxRate/100)
				}
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),( this.getRedempVal() - Math.round(capGainVal*this.taxRate/100) ) );
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_gr_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_gr_st_annpostval').value>=300){
					$('diveq_gr_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
					$('diveq_gr_st_annpostval').innerHTML="";
				}
			}else{
				$('eq_gr_st_capgainval').value=capGainVal ;			
				if( capGainVal >=0){
					$('eq_gr_st_capgain').innerHTML="You have made a Gain of Rs";			
				}else{
					$('eq_gr_st_capgain').innerHTML="You have made a Loss of Rs";			
				}
				$('eq_gr_st_surch').value=1;
				$('eq_gr_st_taxrate').value="11.33"
				this.taxRate=11.33; 
				$('eq_gr_st_taxpay').value=Math.round(capGainVal*this.taxRate/100)

				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),( this.getRedempVal() - Math.round(capGainVal*this.taxRate/100) ) );
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_gr_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_gr_st_annpostval').value>=300){
					$('diveq_gr_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
					$('diveq_gr_st_annpostval').innerHTML="";
				}

			}		
		}

		this.calculateEQDivPoIt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				$('eq_divpo_it_capgainval').value=capGainVal ;			
				if( capGainVal >=0){
					$('eq_divpo_it_capgain').innerHTML="You have made a Gain of Rs";			
				}else{
					$('eq_divpo_it_capgain').innerHTML="You have made a Loss of Rs";			
				}
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal());
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_divpo_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_divpo_it_annpostval').value>=300){
					$('diveq_divpo_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
                }
				else{
					$('diveq_divpo_it_annpostval').innerHTML="";
				}
			 }else if(p_action == 'modType'){
				if(this.rowId >0){
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					for(var i=1;i<=this.rowId;i++){
						temp_cashFlowArr[temp_cashFlowArr.length]=$$('eq_divpo_it_divamt'+i);						
						temp_dateArr[temp_dateArr.length]=getDateObject('eq_divpo_it_divdt'+i,GConObj.dtFmtStr1) ;
					}
					temp_cashFlowArr[temp_cashFlowArr.length]=this.getRedempVal();
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_divpo_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('eq_divpo_it_annpostval').value>=300){
						$('diveq_divpo_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
                    }
					else{
							$('diveq_divpo_it_annpostval').innerHTML=""
					}
				}
			 }
		}

		this.calculateEQDivPoSt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				if(capGainVal <=0){
					$('eq_divpo_st_taxpay').value='0'
				}else{
					$('eq_divpo_st_taxpay').value=Math.round(capGainVal*this.taxRate/100)
				}
				$('eq_divpo_st_capgainval').value=capGainVal ;			
				if( capGainVal >=0){
					$('eq_divpo_st_capgain').innerHTML="You have made a Gain of Rs";			
				}else{
					$('eq_divpo_st_capgain').innerHTML="You have made a Loss of Rs";			
				}
				var temp_taxrate=0;
				if($$('eq_divpo_st_surch') == '1'){
					temp_taxrate=11.33;
				}else{
					temp_taxrate=10.3;
				}
				$('eq_divpo_st_taxrate').value=temp_taxrate
				$('eq_divpo_st_taxpay').value=Math.round(capGainVal*temp_taxrate/100)

				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),(this.getRedempVal() - Math.round(capGainVal*temp_taxrate/100) ));
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_divpo_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_divpo_st_annpostval').value>=300){
					$('diveq_divpo_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
                }
				else{
						$('diveq_divpo_st_annpostval').innerHTML="";
				}
			}else if(p_action == 'modType'){
				if(this.rowId >0){
					var temp_taxrate=0;
					if($$('eq_divpo_st_surch') == '1'){
						temp_taxrate=11.33;
					}else{
						temp_taxrate=10.3;
					}
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					for(var i=1;i<=this.rowId;i++){
						temp_cashFlowArr[temp_cashFlowArr.length]=$$('eq_divpo_st_divamt'+i);						
						temp_dateArr[temp_dateArr.length]=getDateObject('eq_divpo_st_divdt'+i,GConObj.dtFmtStr1) ;
					}
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() - Math.round(capGainVal*temp_taxrate/100) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_divpo_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('eq_divpo_st_annpostval').value>=300){
						$('diveq_divpo_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
					}
					else{
						$('diveq_divpo_st_annpostval').innerHTML="";
					}
				}
				else{
					this.calculateEQDivPoSt('mainType');//reset  chaged values
					return;
				}
			}
		}

		this.calculateEQReinvIt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				if( capGainVal  >=0){
					$('eq_reinv_it_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('eq_reinv_it_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('eq_reinv_it_capgainval').value=Math.round(capGainVal)
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal());
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_reinv_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_reinv_it_annpostval').value>=300){
					$('diveq_reinv_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
					$('diveq_reinv_it_annpostval').innerHTML="";
				}



				//@@@irr
			}else if(p_action == 'modType'){
				if(this.rowId >0){
					var temptaxSum=0;
					
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0
					var temp_sum_irr_2=0
					//@@@irr
					
					for(var i=1;i<=this.rowId;i++){
						var temp_unitrec=($$('eq_reinv_it_divamt'+i)/($$('eq_reinv_it_divnav'+i) == 0?1:$$('eq_reinv_it_divnav'+i)))
						var temp_nofunitrec=days_between(this.v_main_dtof_redemp , getDateObject('eq_reinv_it_divdt'+i,GConObj.dtFmtStr1) );
						var temp_taxrate=0;
						if(temp_nofunitrec>=365){
							temp_taxrate=0;
						}else if(temp_nofunitrec<365 && $$('eq_reinv_it_surch') == '1'){
							temp_taxrate=11.33;
						}else{
							temp_taxrate=10.30;
						}
						var temp_capgain=(temp_unitrec*this.v_main_redemp_val)-$$('eq_reinv_it_divamt'+(i))
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)
						
						$('eq_reinv_it_unitrec'+i).innerHTML=roundNumber(temp_unitrec,4)
						$('eq_reinv_it_nofunitrec'+i).innerHTML=temp_nofunitrec
						$('eq_reinv_it_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('eq_reinv_it_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('eq_reinv_it_tax'+i).innerHTML=roundNumber(temp_tax,4)
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(roundNumber(temp_unitrec,4) * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - temp_sum_irr_2);
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_reinv_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('eq_reinv_it_annpostval').value>=300){
						$('diveq_reinv_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
					}
					else{
						$('diveq_reinv_it_annpostval').innerHTML="";
					}

					//@@@irr 
					$('eq_reinv_it_capgainval').value=roundNumber((this.getCapGainVal()+temptaxSum),2);
				}else{
					this.calculateEQReinvIt('mainType');//reset  chaged values
					return;
				}
			}		
		}

		this.calculateEQReinvSt= function (p_action,p_XtraParam1){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				if($$('eq_reinv_st_surch') == '1'){
					temp_taxrate=11.33;
				}else{
					temp_taxrate=10.30;
				}
				if( capGainVal  >=0){
					$('eq_reinv_st_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('eq_reinv_st_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('eq_reinv_st_capgainval').value=Math.round(capGainVal)
				$('eq_reinv_st_capgainval_temp').innerHTML=Math.round(capGainVal)
				$('eq_reinv_st_taxrate_temp').innerHTML=temp_taxrate+'%';			
				$('eq_reinv_st_tax_temp').innerHTML=roundNumber( (temp_taxrate*capGainVal/100) ,4);			
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),(this.getRedempVal()) -  roundNumber( (temp_taxrate*capGainVal/100) ,4));
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_reinv_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_reinv_st_annpostval').value>=300){
						$('diveq_reinv_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
						$('diveq_reinv_st_annpostval').innerHTML="";
				}
				//@@@irr
			}else if(p_action == 'modType'){
				if(this.rowId >0){
					var temptaxSum=0;
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0
					var temp_sum_irr_2=0
					//@@@irr
					var temp_taxrate=0;
					for(var i=1;i<=this.rowId;i++){
						var temp_unitrec=($$('eq_reinv_st_divamt'+i)/($$('eq_reinv_st_divnav'+i) == 0?1:$$('eq_reinv_st_divnav'+i)))
						if($$('eq_reinv_st_surch') == '1'){
							temp_taxrate=11.33;
						}else{
							temp_taxrate=10.30;
						}
						var temp_capgain=(temp_unitrec*this.v_main_redemp_val)-$$('eq_reinv_st_divamt'+(i))
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)
						
						$('eq_reinv_st_unitrec'+i).innerHTML=roundNumber(temp_unitrec,4)
						$('eq_reinv_st_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('eq_reinv_st_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('eq_reinv_st_tax'+i).innerHTML=roundNumber(temp_tax,4)
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(roundNumber(temp_unitrec,4) * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - ( temp_sum_irr_2 + (capGainVal * temp_taxrate/100 ) ) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_reinv_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('eq_reinv_st_annpostval').value>=300){
						$('diveq_reinv_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
					}
					else{
						$('diveq_reinv_st_annpostval').innerHTML="";
					}
					//@@@irr 
					$('eq_reinv_st_capgainval').value=roundNumber((this.getCapGainVal()+temptaxSum),2);
				}else{
					this.calculateEQReinvSt('mainType');//reset  chaged values
					return;
				}
			}		
		}

		this.calculateEQBoIt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				if( capGainVal  >=0){
					$('eq_bonus_it_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('eq_bonus_it_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('eq_bonus_it_capgainval').value=Math.round(capGainVal)
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal());
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_bonus_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_bonus_it_annpostval').value>=300){
					$('diveq_bonus_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
					$('diveq_bonus_it_annpostval').innerHTML="";
				}

				//@@@irr
			}else if(p_action == 'modType'){
				if(this.rowId >0){
					var temptaxSum=0;
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0
					var temp_sum_irr_2=0
					//@@@irr
					for(var i=1;i<=this.rowId;i++){
						var temp_nofunitrec=days_between(this.v_main_dtof_redemp , getDateObject('eq_bonus_it_divdt'+i,GConObj.dtFmtStr1) );
						var temp_bon_unit_rec  =$$('eq_bonus_it_bon_unit_rec'+(i))
						var temp_taxrate=0;
						if(temp_nofunitrec>=365){
							temp_taxrate=0;
						}else if(temp_nofunitrec<365 && $$('eq_bonus_it_surch') == '1'){
							temp_taxrate=11.33;
						}else{
							temp_taxrate=10.30;
						}
						var temp_capgain=(temp_bon_unit_rec*this.v_main_redemp_val)
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)
						$('eq_bonus_it_nofunitrec'+i).innerHTML=temp_nofunitrec
						$('eq_bonus_it_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('eq_bonus_it_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('eq_bonus_it_tax'+i).innerHTML=roundNumber(temp_tax,4)
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(temp_bon_unit_rec * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - ( temp_sum_irr_2  ) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_bonus_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					//@@@irr 

					$('eq_bonus_it_capgainval').value=roundNumber((this.getCapGainVal()+temptaxSum),2);
				}else{
					this.calculateEQBoIt('mainType');//reset  chaged values
					return;
				}
			}		
		}

		this.calculateEQBoSt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				if($$('eq_bonus_st_surch') == '1'){
					temp_taxrate=11.33;
				}else{
					temp_taxrate=10.30;
				}
				if( capGainVal  >=0){
					$('eq_bonus_st_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('eq_bonus_st_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('eq_bonus_st_capgainval').value=Math.round(capGainVal)
				$('eq_bonus_st_capgainval_temp').innerHTML=Math.round(capGainVal)
				$('eq_bonus_st_taxrate_temp').innerHTML=temp_taxrate+'%';			
				$('eq_bonus_st_tax_temp').innerHTML=roundNumber( (temp_taxrate*capGainVal/100) ,4);			
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),(this.getRedempVal()) -  roundNumber( (temp_taxrate*capGainVal/100) ,4));
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('eq_bonus_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('eq_bonus_st_annpostval').value>=300){
						$('diveq_bonus_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
						$('diveq_bonus_st_annpostval').innerHTML="";
				}
				//@@@irr
		}else if(p_action == 'modType'){
				if(this.rowId >0){
					var temptaxSum=0;
					//@@@irr
					var temp_taxrate=0;
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0
					var temp_sum_irr_2=0
					//@@@irr
					for(var i=1;i<=this.rowId;i++){
						var temp_nofunitrec=days_between(this.v_main_dtof_redemp , getDateObject('eq_bonus_st_divdt'+i,GConObj.dtFmtStr1) );
						var temp_bon_unit_rec  =$$('eq_bonus_st_bon_unit_rec'+(i))
						if(temp_nofunitrec>=365){
							temp_taxrate=0;
						}else if(temp_nofunitrec<365 && $$('eq_bonus_st_surch') == '1'){
							temp_taxrate=11.33;
						}else{
							temp_taxrate=10.30;
						}
						var temp_capgain=(temp_bon_unit_rec*this.v_main_redemp_val)
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)

						$('eq_bonus_st_nofunitrec'+i).innerHTML=temp_nofunitrec
						$('eq_bonus_st_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('eq_bonus_st_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('eq_bonus_st_tax'+i).innerHTML=roundNumber(temp_tax,4)
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(temp_bon_unit_rec * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - ( temp_sum_irr_2 + (capGainVal * temp_taxrate/100 ) ) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('eq_bonus_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					//@@@irr 
					$('eq_bonus_st_capgainval').value=roundNumber((this.getCapGainVal()+temptaxSum),2);
				}else{
					this.calculateEQBoSt('mainType');//reset  chaged values
					return;
				}
			}		
		}
//EQUITY END


//DEBT START
		this.calculateDebtGRIt= function (){
			var capGainVal =this.getCapGainVal();			
			$('debt_gr_it_capgainval').value=capGainVal ;			
			if( capGainVal >=0){
				$('debt_gr_it_capgain').innerHTML="You have made a Gain of Rs";			
			}else{
				$('debt_gr_it_capgain').innerHTML="You have made a Loss of Rs";			
			}
			this.taxrate_with_surcharge_indexed=22.66/100
			this.taxrate_without_surcharge_indexed=20.6/100
			this.taxrate_with_surcharge_nonindexed=11.33/100
			this.taxrate_without_surcharge_nonindexed=10.3/100
			var v_Indexed_Capital_Gain=this.getCapitalGainTaxPay('debt_gr_it_surch')
			//@@@irr
			var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - v_Indexed_Capital_Gain);
			var temp_dateArr = new Array();
			temp_dateArr[0]=this.v_main_dtof_purch;
			temp_dateArr[1]=this.v_main_dtof_redemp;
			$('debt_gr_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
			if($('debt_gr_it_annpostval').value>=300){
						$('divdebt_gr_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
			}
			else{
						$('divdebt_gr_it_annpostval').innerHTML="";
			}

			//@@@irr
		}

		this.calculateDebtGRSt= function (p_type){
			if(p_type == 'mainType'){
				var capGainVal =this.getCapGainVal();			
				$('debt_gr_st_capgainval').value=capGainVal ;			
				if( capGainVal >=0){
					$('debt_gr_st_capgain').innerHTML="You have made a Gain of Rs";			
				}else{
					$('debt_gr_st_capgain').innerHTML="You have made a Loss of Rs";			
				}
				var v_taxpay = $$('debt_gr_st_taxpay') 
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - v_taxpay );
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_gr_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('debt_gr_st_annpostval').value>=300){
						$('divdebt_gr_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
						$('divdebt_gr_st_annpostval').innerHTML="";
				}
				//@@@irr
			}else if(p_type == 'modType'){
				var v_debt_gr_st_act_taxrate=$$('debt_gr_st_act_taxrate'); 
				$('debt_gr_st_taxpay').value=v_debt_gr_st_act_taxrate * this.getCapGainVal()/100

				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - $$('debt_gr_st_taxpay'));
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_gr_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('debt_gr_st_annpostval').value>=300){
						$('divdebt_gr_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
						$('divdebt_gr_st_annpostval').innerHTML="";
				}
				//@@@irr

				if($('debt_gr_st_act_taxrate').getAttribute('hasFocus') == 'true'){
					$('debt_gr_st_act_taxrate').focus();
				}
			}
		}

		this.calculateDebtDivPoIt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				$('debt_divpo_it_capgainval').value=capGainVal ;			
				if( capGainVal >=0){
					$('debt_divpo_it_capgain').innerHTML="You have made a Gain of Rs";			
				}else{
					$('debt_divpo_it_capgain').innerHTML="You have made a Loss of Rs";			
				}
				this.taxrate_with_surcharge_indexed=22.66/100
				this.taxrate_without_surcharge_indexed=20.6/100
				this.taxrate_with_surcharge_nonindexed=11.33/100
				this.taxrate_without_surcharge_nonindexed=10.3/100
				var v_Indexed_Capital_Gain=this.getCapitalGainTaxPay('debt_divpo_it_surch')
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - v_Indexed_Capital_Gain);
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_divpo_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				//alert("values is"+$('debt_divpo_it_annpostval').value)
				if($('debt_divpo_it_annpostval').value>=300){
					$('divdebt_divpo_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
				}
				else{
						$('divdebt_divpo_it_annpostval').innerHTML="";
				}

				//@@@irr
			 }else if(p_action == 'modType'){
				if(this.rowId >0){
					//@@@irr
					var v_Indexed_Capital_Gain=this.getCapitalGainTaxPay('debt_divpo_it_surch')
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					for(var i=1;i<=this.rowId;i++){
						temp_cashFlowArr[temp_cashFlowArr.length]=$$('debt_divpo_it_divamt'+i);						
						temp_dateArr[temp_dateArr.length]=getDateObject('debt_divpo_it_divdt'+i,GConObj.dtFmtStr1) ;
					}
					temp_cashFlowArr[temp_cashFlowArr.length]=this.getRedempVal() - v_Indexed_Capital_Gain;
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('debt_divpo_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('debt_divpo_it_annpostval').value>=300){
						$('divdebt_divpo_it_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%.</FONT>';
					}
					else{
						$('divdebt_divpo_it_annpostval').innerHTML="";
					}


					//@@@irr
				}
			 }
		}


	this.calculateDebtDivPoSt= function (p_action){
		var capGainVal =this.getCapGainVal();			
		 if(p_action == 'mainType'){
			var capGainVal =this.getCapGainVal();			
			var v_debt_divpo_st_act_taxrate=$$('debt_divpo_st_act_taxrate'); 
			var v_tax_pay=v_debt_divpo_st_act_taxrate * this.getCapGainVal()/100
			$('debt_divpo_st_capgainval').value=capGainVal ;			
			$('debt_divpo_st_taxpay').value=v_tax_pay;
			if( capGainVal >=0){
				$('debt_divpo_st_capgain').innerHTML="You have made a Gain of Rs";			
			}else{
				$('debt_divpo_st_capgain').innerHTML="You have made a Loss of Rs";			
			}
			//@@@irr
			var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - v_tax_pay);
			var temp_dateArr = new Array();
			temp_dateArr[0]=this.v_main_dtof_purch;
			temp_dateArr[1]=this.v_main_dtof_redemp;
			$('debt_divpo_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
			if($('debt_divpo_st_annpostval').value>=300){
					$('divdebt_divpo_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
			}
			else{
					$('divdebt_divpo_st_annpostval').innerHTML="";
			}
			//@@@irr
		 }else if(p_action == 'modType'){
				var v_debt_divpo_st_act_taxrate=$$('debt_divpo_st_act_taxrate'); 
				var v_tax_pay=v_debt_divpo_st_act_taxrate * this.getCapGainVal()/100
				$('debt_divpo_st_taxpay').value=v_tax_pay;
				if($('debt_divpo_st_act_taxrate').getAttribute('hasFocus') == 'true'){
					$('debt_divpo_st_act_taxrate').focus();
				}
				//@@@irr
				var temp_cashFlowArr= new Array();
				temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				if(this.rowId >0){
					for(var i=1;i<=this.rowId;i++){
						temp_cashFlowArr[temp_cashFlowArr.length]=$$('debt_divpo_st_divamt'+i);						
						temp_dateArr[temp_dateArr.length]=getDateObject('debt_divpo_st_divdt'+i,GConObj.dtFmtStr1) ;
					}
				}
				temp_cashFlowArr[temp_cashFlowArr.length]=this.getRedempVal() -v_tax_pay ;
				temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
				$('debt_divpo_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('debt_divpo_st_annpostval').value>=300){
					$('divdebt_divpo_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
				}
				else{
					$('divdebt_divpo_st_annpostval').innerHTML="";
				}
				//@@@irr
			 }
		}

		this.calculateDebtReinvIt= function (p_action){
			var capGainVal =0;
			 if(p_action == 'mainType'){
				if( capGainVal  >=0){
					$('debt_reinv_it_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('debt_reinv_it_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('debt_reinv_it_capgainval').value=Math.round(capGainVal)
				this.taxrate_with_surcharge_indexed=22.66/100
				this.taxrate_without_surcharge_indexed=20.6/100
				this.taxrate_with_surcharge_nonindexed=11.33/100
				this.taxrate_without_surcharge_nonindexed=10.3/100
				var v_Indexed_Capital_Gain_Org=this.getCapitalGainTaxPay('debt_reinv_it_surch')
//				alert('maintype v_final_capgain  '+v_Indexed_Capital_Gain_Org)
			}else if(p_action == 'modType'){
				var tempTaxgainDividendSum=0
				if( eval($('debt_reinv_it_act_taxrate').getAttribute('hasFocus'))){
					$('debt_reinv_it_act_taxrate').focus();
				}
				if(this.rowId >0){
					var temptaxgainSum=0;
					for(var i=1;i<=this.rowId;i++){
						var temp_unitrec=($$('debt_reinv_it_divamt'+i)/($$('debt_reinv_it_divnav'+i) == 0?1:$$('debt_reinv_it_divnav'+i)))
						var temp_nofunitrec=days_between(this.v_main_dtof_redemp , getDateObject('debt_reinv_it_divdt'+i,GConObj.dtFmtStr1) );
						var temp_LT_or_ST='';
						var temp_tax_on_ST=0;
						var temp_act_tax_rate=$$('debt_reinv_it_act_taxrate') == ''?0:$$('debt_reinv_it_act_taxrate')
						if(temp_nofunitrec>=365){
							temp_LT_or_ST='LT';
						}else{
							temp_LT_or_ST='ST';
						}
						if(temp_LT_or_ST == 'LT'){
							temp_tax_on_ST=0
						}else{
							temp_tax_on_ST=[ [(temp_unitrec * this.v_main_redemp_val)-$$('debt_reinv_it_divamt'+i)] *(temp_act_tax_rate/100) ]
						}
						var temp_capgain=(temp_unitrec*this.v_main_redemp_val)-$$('debt_reinv_it_divamt'+(i))
						$('debt_reinv_it_unitrec'+i).innerHTML=roundNumber(temp_unitrec,4)
						$('debt_reinv_it_capgain'+i).innerHTML=Math.round(temp_capgain)
						temptaxgainSum=temptaxgainSum+Math.round(temp_capgain);					
						tempTaxgainDividendSum =tempTaxgainDividendSum+this.getCapitalGainTaxPayOnDividend('debt_reinv_it',i)								
					}
					$('debt_reinv_it_capgainval').value=Math.round(temptaxgainSum,2);
					this.taxrate_with_surcharge_indexed=22.66/100
					this.taxrate_without_surcharge_indexed=20.6/100
					this.taxrate_with_surcharge_nonindexed=11.33/100
					this.taxrate_without_surcharge_nonindexed=10.3/100
					var v_Indexed_Capital_Gain_Org=this.getCapitalGainTaxPay('debt_reinv_it_surch')
					var v_final_capgain=v_Indexed_Capital_Gain_Org+tempTaxgainDividendSum
//					alert('modtype v_final_capgain  '+v_final_capgain)
				}
			}		
		}

		this.calculateDebtReinvSt= function (p_action,p_XtraParam1){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				var temp_taxrate=$$('debt_reinv_st_act_taxrate') == ''?0:$$('debt_reinv_st_act_taxrate');
				if( capGainVal  >=0){
					$('debt_reinv_st_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('debt_reinv_st_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('debt_reinv_st_capgainval').value=0//Math.round(capGainVal)
				$('debt_reinv_st_capgainval_temp').innerHTML=Math.round(capGainVal)
				$('debt_reinv_st_taxrate_temp').innerHTML=temp_taxrate+'%';			
				$('debt_reinv_st_tax_temp').innerHTML=roundNumber( (  [ (temp_taxrate*capGainVal/100)  <= 0?0: (temp_taxrate*capGainVal/100) ] ) ,4);			
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),(this.getRedempVal()) -  roundNumber( (temp_taxrate*capGainVal/100) ,4));
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_reinv_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('debt_reinv_st_annpostval').value>=300){
						$('divdebt_reinv_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
				}
				else{
						$('divdebt_reinv_st_annpostval').innerHTML="";
				}

				//@@@irr
			}else if(p_action == 'modType'){
				if( eval($('debt_reinv_st_act_taxrate').getAttribute('hasFocus'))){
					$('debt_reinv_st_act_taxrate').focus();
				}
				if(this.rowId >0){
					var temptaxSum=0;
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0;
					var temp_sum_irr_2=0;
					var temp_taxrate=0;
					//@@@irr
					for(var i=1;i<=this.rowId;i++){
						var temp_unitrec=($$('debt_reinv_st_divamt'+i)/($$('debt_reinv_st_divnav'+i) == 0?1:$$('debt_reinv_st_divnav'+i)))
						temp_taxrate=$$('debt_reinv_st_act_taxrate') == ''?0:$$('debt_reinv_st_act_taxrate');
						var temp_capgain=(temp_unitrec*this.v_main_redemp_val)-$$('debt_reinv_st_divamt'+(i))
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)
						
						$('debt_reinv_st_unitrec'+i).innerHTML=roundNumber(temp_unitrec,4)
						$('debt_reinv_st_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('debt_reinv_st_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('debt_reinv_st_tax'+i).innerHTML=roundNumber(temp_tax,4)
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(roundNumber(temp_unitrec,4) * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - ( temp_sum_irr_2 + (capGainVal * temp_taxrate/100 ) ) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('debt_reinv_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if($('debt_reinv_st_annpostval').value>=300){
						$('divdebt_reinv_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
					}
					else{
						$('divdebt_reinv_st_annpostval').innerHTML="";
					}
					//@@@irr 
//					this.calculateDebtReinvSt('mainType')
					$('debt_reinv_st_capgainval').value=roundNumber(temptaxSum,2);
				}else{
					this.calculateDebtReinvSt('mainType');//reset  chaged values
					return;
				}
			}		
		}

		this.calculateDebtBoIt= function (p_action){
			var capGainVal =this.getCapGainVal();
			 if(p_action == 'mainType'){
				if( capGainVal  >=0){
					$('debt_bonus_it_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('debt_bonus_it_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('debt_bonus_it_capgainval').value=Math.round(capGainVal);
				$('debt_bonus_it_capgainval_temp').innerHTML=Math.round(capGainVal);
				this.taxrate_with_surcharge_indexed=22.44/100
				this.taxrate_without_surcharge_indexed=20.4/100
				this.taxrate_with_surcharge_nonindexed=11.22/100
				this.taxrate_without_surcharge_nonindexed=10.2/100
				var v_Indexed_Capital_Gain_Org=this.getCapitalGainTaxPay('debt_bonus_it_surch')
//				alert('maintype v_final_capgain  '+v_Indexed_Capital_Gain_Org)
				//@@@irr
				var temp_cashFlowArr= new Array(-this.getTotPurchaseCost() ,this.getRedempVal() );
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_bonus_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				//@@@irr
			}else if(p_action == 'modType'){
				var tempTaxgainDividendSum=0
				if( eval($('debt_bonus_it_act_taxrate').getAttribute('hasFocus'))){
					$('debt_bonus_it_act_taxrate').focus();
				}
				if(this.rowId >0){
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0;
					//@@@irr
					var temptaxgainSum=0;
					var temp_tax_on_LT_Sum=0;
					var temp_tax_on_ST_Sum=0;
					for(var i=1;i<=this.rowId;i++){
						var temp_unitrec=$$('debt_bonus_it_unitrec'+i) ;
						var temp_nofunitrec=days_between(this.v_main_dtof_redemp , getDateObject('debt_bonus_it_divdt'+i,GConObj.dtFmtStr1) );
						var temp_LT_or_ST='';
						var temp_tax_on_ST=0;
						var temp_tax_on_LT=0;
						var temp_act_tax_rate=$$('debt_bonus_it_act_taxrate') == ''?0:$$('debt_bonus_it_act_taxrate')
						if(temp_nofunitrec>=365){
							temp_LT_or_ST='LT';
						}else{
							temp_LT_or_ST='ST';
						}
						if(temp_LT_or_ST == 'LT'){
							temp_tax_on_ST=0
						}else{
							temp_tax_on_ST=[ [(temp_unitrec* this.v_main_redemp_val)] *(temp_act_tax_rate/100) ]
						}
						
						if(temp_LT_or_ST == 'ST'){
							temp_tax_on_LT=0
						}else{
							if($$('debt_bonus_it_surch') == '1'){
								temp_tax_on_LT=[ [(temp_unitrec * this.v_main_redemp_val)] *(11.22/100) ]
							}else{
								temp_tax_on_LT=[ [(temp_unitrec * this.v_main_redemp_val)] *(10.2/100) ]
							}
						}
						
						var temp_capgain=(temp_unitrec*this.v_main_redemp_val)
						$('debt_bonus_it_nofunitrec'+i).innerHTML=temp_nofunitrec;
						$('debt_bonus_it_capgain'+i).innerHTML=temp_unitrec*this.v_main_redemp_val;
						temptaxgainSum=parseInt(temptaxgainSum)+parseInt(temp_capgain);
						temp_tax_on_LT_Sum= parseInt(temp_tax_on_LT_Sum) +parseInt(temp_tax_on_LT);
						temp_tax_on_ST_Sum= parseInt(temp_tax_on_ST_Sum )+ parseInt(temp_tax_on_ST);
//						alert('temp_tax_on_LT_Sum ='+temp_tax_on_LT_Sum   +' temp_tax_on_LT   ='+temp_tax_on_LT+'      temp_tax_on_LT_Sum + temp_tax_on_LT    '+(parseInt(temp_tax_on_LT_Sum) + parseInt(temp_tax_on_LT )));
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(roundNumber(temp_unitrec,4) * this.v_main_redemp_val )
						//@@@irr
					}
					var tot_Tax=temp_tax_on_LT_Sum+temp_tax_on_ST_Sum;
//					alert('tot_Tax   '+tot_Tax);
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - tot_Tax);
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('debt_bonus_it_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					//@@@irr 
					$('debt_bonus_it_capgainval').value=Math.round(temptaxgainSum+capGainVal,2);
				}
					this.taxrate_with_surcharge_indexed=22.44/100
					this.taxrate_without_surcharge_indexed=20.4/100
					this.taxrate_with_surcharge_nonindexed=11.22/100
					this.taxrate_without_surcharge_nonindexed=10.2/100
					var v_Indexed_Capital_Gain_Org=this.getCapitalGainTaxPay('debt_bonus_it_surch')
			}		
		}

		this.calculateDebtBoSt= function (p_action){
			var capGainVal =this.getCapGainVal();			
			 if(p_action == 'mainType'){
				var temp_taxrate=$$('debt_bonus_st_act_taxrate') == ''?0:$$('debt_bonus_st_act_taxrate') ;
				var v_tax_pay =roundNumber( (temp_taxrate*capGainVal/100) ,4);	
				if( capGainVal  >=0){
					$('debt_bonus_st_capgain').innerHTML="Your Capital Gain is  Rs";			
				}else{
					$('debt_bonus_st_capgain').innerHTML="Your Capital Loss is  Rs";			
				}
				$('debt_bonus_st_capgainval').value=Math.round(capGainVal)
				$('debt_bonus_st_capgainval_temp').innerHTML=Math.round(capGainVal)
				$('debt_bonus_st_taxrate_temp').innerHTML=temp_taxrate+'%';			
				$('debt_bonus_st_tax_temp').innerHTML=	v_tax_pay ;
				//@@@irr
				var temp_cashFlowArr= new Array(-( this.getTotPurchaseCost() ),this.getRedempVal() - v_tax_pay);
				var temp_dateArr = new Array();
				temp_dateArr[0]=this.v_main_dtof_purch;
				temp_dateArr[1]=this.v_main_dtof_redemp;
				$('debt_bonus_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
				if($('debt_bonus_st_annpostval').value>=300){
					$('divdebt_bonus_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
				}
				else{
						$('divdebt_bonus_st_annpostval').innerHTML="";
				}

				//@@@irr
		}else if(p_action == 'modType'){
				if( eval($('debt_bonus_st_act_taxrate').getAttribute('hasFocus'))){
					$('debt_bonus_st_act_taxrate').focus();
				}
				if(this.rowId >0){
					var temptaxSum=0;
					//@@@irr
					var temp_cashFlowArr= new Array();
					temp_cashFlowArr[0]=-this.getTotPurchaseCost() ;
					var temp_dateArr = new Array();
					temp_dateArr[0]=this.v_main_dtof_purch;
					var temp_sum_irr_1=0;
					var temp_sum_irr_2=0;
					var temp_taxrate=0;
					//@@@irr
					for(var i=1;i<=this.rowId;i++){
						var temp_bon_unit_rec  =$$('debt_bonus_st_bon_unit_rec'+(i))
						var temp_taxrate=0;
						temp_taxrate=$$('debt_bonus_st_act_taxrate') == ''?0:$$('debt_bonus_st_act_taxrate') ;
						var temp_capgain=(temp_bon_unit_rec*this.v_main_redemp_val)
						var temp_tax=temp_capgain<=0?0:(temp_capgain*temp_taxrate/100)

						$('debt_bonus_st_taxrate'+i).innerHTML=temp_taxrate+' %'
						$('debt_bonus_st_capgain'+i).innerHTML=Math.round(temp_capgain)
						$('debt_bonus_st_tax'+i).innerHTML=roundNumber(temp_tax,4)
						temptaxSum=temptaxSum+roundNumber(temp_capgain,4);					
						//@@@irr
						temp_sum_irr_1=temp_sum_irr_1+(roundNumber(temp_bon_unit_rec,4) * this.v_main_redemp_val )
						temp_sum_irr_2=temp_sum_irr_2+(roundNumber(temp_tax,4))						
						//@@@irr
					}
					//@@@irr
					temp_cashFlowArr[temp_cashFlowArr.length]=(this.getRedempVal() +temp_sum_irr_1 - ( temp_sum_irr_2 + (capGainVal * temp_taxrate/100 ) ) );
					temp_dateArr[temp_dateArr.length]=this.v_main_dtof_redemp;
					$('debt_bonus_st_annpostval').value= getXIRRPre(temp_cashFlowArr , temp_dateArr , 0.1);
					if(getXIRRPre.flag==true){
						alert("Calculation Can not Perfrom using XIIR so We use IRR Function ")
					}
					if($('debt_bonus_st_annpostval').value>=300){
						$('divdebt_bonus_st_annpostval').innerHTML='<FONT SIZE="1px" COLOR="#797979" FAMILY="Helvetica"  weight="normal">To calculate the annualised returns we have used the XIRR formula. There is a limitation in using this. The formula can not calculate return percentages over 300. So the returns currently shown are above 300%</FONT>.';
					}
					else{
						$('divdebt_bonus_st_annpostval').innerHTML="";
					}
					//@@@irr 
					$('debt_bonus_st_capgainval').value=roundNumber((this.getCapGainVal()+temptaxSum),2);
				}else{
					this.calculateDebtBoSt('mainType');//reset  chaged values
					return;
				}
			}		
		}

//DEBT END
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.ReturnInvestmentModule() "+err.description)
	}
}

/*************************All variable Population for return investment done here**************************/
function populateReturnInvestment(p_type){
	try{
			if(p_type == 'main'){
				if(validateReturnInvestment(p_type)){
				   return true;
				}else {
					GRInvObj.v_main_schemetype=$$('main_schemetype');
					GRInvObj.v_main_option=$$('main_option');
					GRInvObj.v_main_dtof_purch=getDateObject('main_dtof_purch',GConObj.dtFmtStr1);
					GRInvObj.v_main_unit_purch=$$('main_unit_purch');
					GRInvObj.v_main_purch_cost=$$('main_purch_cost');
					GRInvObj.v_main_dtof_redemp=getDateObject('main_dtof_redemp',GConObj.dtFmtStr1);
					GRInvObj.v_main_redemp_val=$$('main_redemp_val');
				}
			}
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.populateReturnInvestment() "+err.description)
	}
}

/*************************All validations for return investment done here**************************/
function validateReturnInvestment(p_type,p_Xtraparam1){
	try{
		if(p_type == 'main'){// MAIN
			var checkMainEmptStr='main_unit_purch#Units Purchased~main_purch_cost#Purchase Cost'+
														'~main_redemp_val#Redemption Value'

			var mainNumStr='main_unit_purch~main_purch_cost~main_redemp_val';
			
			var checkMainNumStr =checkNumericAll(mainNumStr);                 
			
			var mainDateStr='main_dtof_redemp~main_dtof_purch'
			var dateFmt=GConObj.dtFmtStr1;
				
			if ($$('main_dtof_purch') == ""){
				alert('Please Enter Date Of Purchase !');
				$('dob_But_purch').focus();
			   return true;
			}else if ($$('main_dtof_redemp') == ""){
				alert('Please Enter Date Of Redemption !');
				$('dob_But_redemp').focus();
			   return true;
			}else if(checkEmptyAll(checkMainEmptStr)){
			   return true;
			}else if(checkMainNumStr != ""){
				$(checkMainNumStr).focus();
				alert('Please Enter Numeric Value !')
			   return true;
			}else if(getDateObject('main_dtof_redemp',dateFmt) > GConObj.Current_Date ){
			    alert('Date of Redemption should be Lesser than Current Date !')
			   return true;
			}else if(checkBiggerDate(mainDateStr,dateFmt)){
			    alert('Date of Redemption should be greater than Date of Purchase !')
			   return true;
			}else{
				return false;
			}
		}
		else if(p_type == 'eq_reinv_it'){//REINV IT
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Dividend input
				alert('Please Add a Dividend first !');
				$('eq_reinv_it_add_new_div_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Dividend input
				return true;
			}
			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_reinv_it_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_reinv_it'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_reinv_it_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_reinv_it_divdt',totRows,'dob_But_eq_reinv_it1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_reinv_it')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_reinv_it_divnav'+(i+1)+'~eq_reinv_it_divamt'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
				if( IsNumeric($$('eq_reinv_it_divnav'+(i+1) ) ) &&  $$('eq_reinv_it_divnav'+(i+1)) <=0){
					alert('Please Enter Value Greater Than 0 !')
					$('eq_reinv_it_divnav'+(i+1)).focus();									
					return false; 
				}
			}			
//			alert('data validated')
			return true;
		}
		else if(p_type == 'eq_reinv_st'){//REINV IT
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Dividend input
				alert('Please Add a Dividend first !');
				$('eq_reinv_st_add_new_div_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Dividend input
				return true;
			}

			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_reinv_st_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_reinv_st'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_reinv_st_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_reinv_st_divdt',totRows,'dob_But_eq_reinv_st1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_reinv_st')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_reinv_st_divnav'+(i+1)+'~eq_reinv_st_divamt'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
				if( IsNumeric($$('eq_reinv_st_divnav'+(i+1) ) ) &&  $$('eq_reinv_st_divnav'+(i+1)) <=0){
					alert('Please Enter Value Greater Than 0 !')
					$('eq_reinv_st_divnav'+(i+1)).focus();									
					return false; 
				}
			}			
//			alert('data validated')
			return true;
		}
		else if(p_type == 'eq_bonus_it'){//BONUS IT
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consBonus'){//consider Bonus input
				alert('Please Add a Bonus first !');
				$('eq_bonus_it_add_new_bon_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreBonus'){//dont consider Bonus input
				return true;
			}

			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_bonus_it_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_bonus_it'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_bonus_it_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_bonus_it_divdt',totRows,'dob_But_eq_bonus_it1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_bonus_it')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_bonus_it_bon_unit_rec'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
			}			
//			alert('data validated')
			return true;
		} 
		else if(p_type == 'eq_bonus_st'){//BONUS ST
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consBonus'){//consider Bonus input
				alert('Please Add a Bonus first !');
				$('eq_bonus_st_add_new_bon_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreBonus'){//dont consider Bonus input
				return true;
			}
			var totRows = GRInvObj.rowId;
			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_bonus_st_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_bonus_st'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_bonus_st_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_bonus_st_divdt',totRows,'dob_But_eq_bonus_st1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_bonus_st')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_bonus_st_bon_unit_rec'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
			}			
//			alert('data validated')
			return true;
		}
		else if(p_type == 'eq_divpo_it'){//DIV PO IT
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Dividend input
				alert('Please Add a Dividend first !');
				$('eq_divpo_it_add_new_div_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Dividend input
				return true;
			}
			var totRows = GRInvObj.rowId;
			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_divpo_it_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_divpo_it'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_divpo_it_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_divpo_it_divdt',totRows,'dob_But_eq_divpo_it1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_divpo_it')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_divpo_it_divamt'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
			}			
//			alert('data validated')
			return true;
		}
		else if(p_type == 'eq_divpo_st'){//DIV PO ST
			var totRows = GRInvObj.rowId;
			if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Bonus input
				alert('Please Add a Dividends first !');
				$('eq_divpo_st_add_new_div_but').focus();
				return false;
			}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Bonus input
				return true;
			}

			var totRows = GRInvObj.rowId;
			var dateFmt=GConObj.dtFmtStr1;
			var temp_NumStr='';
			var checktemp_NumStr='';
			var checktemp_EmpStr='';
			for(var i=0;i<totRows;i++){
				if($$('eq_divpo_st_divdt'+(i+1)) == ''){
					alert('Please Enter Date First !')
					$('dob_But_eq_divpo_st'+(i+1)).focus();
					return false;
				}
			}				

			for(var i=0;i<totRows;i++){
				checktemp_EmpStr='eq_divpo_st_divdt'+(i+1)+'#Date'
				if(checkEmptyAll(checktemp_EmpStr)){
					return false;
				}				
			}

			if(!checkDateInSeries('eq_divpo_st_divdt',totRows,'dob_But_eq_divpo_st1')){/***************date series check [start]*******************/
				return false
			}
			if(!checkPurchRedmpDate('eq_divpo_st')){
				return false;
			}

			for(var i=0;i<totRows;i++){
				temp_NumStr='eq_divpo_st_divamt'+(i+1);
				checktemp_NumStr =checkNumericAll(temp_NumStr);                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}
			}			
//			alert('data validated')
			return true;
		}
			else if(p_type == 'debt_gr_st'){//Debt GrST //
				var checktemp_NumStr =checkNumericAll('debt_gr_st_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}else{
					return true;
				}
			}
			else if(p_type == 'debt_divpo_it'){//Debt DIV PO IT
				var totRows = GRInvObj.rowId;
				if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Bonus input
					alert('Please Add a Dividends first !');
					$('debt_divpo_it_add_new_div_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Bonus input
					return true;
				}

				var totRows = GRInvObj.rowId;
				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_divpo_it_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_divpo_it'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_divpo_it_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_divpo_it_divdt',totRows,'dob_But_debt_divpo_it1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_divpo_it')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_divpo_it_divamt'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
				}			
	//			alert('data validated')
				return true;
			}
			else if(p_type == 'debt_divpo_st'){//Debt DIV PO ST
				
				var checktemp_NumStr =checkNumericAll('debt_divpo_st_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				   $(checktemp_NumStr).value='0'
					return false;
				}

				var totRows = GRInvObj.rowId;
				if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Bonus input
					alert('Please Add a Dividends first !');
					$('debt_divpo_st_add_new_div_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Bonus input
					return true;
				}
				
				var totRows = GRInvObj.rowId;
				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_divpo_st_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_divpo_st'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_divpo_st_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_divpo_st_divdt',totRows,'dob_But_debt_divpo_st1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_divpo_st')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_divpo_st_divamt'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
				}			
	//			alert('data validated')
				return true;
			}
			else if(p_type == 'debt_reinv_it'){//Debt DIV PO ST
				//alert('san1 p_Xtraparam1  '+p_Xtraparam1 )
				var totRows = GRInvObj.rowId;
				var checktemp_NumStr =checkNumericAll('debt_reinv_it_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
				    $(checktemp_NumStr).value='0'
					 return false;
				}
				
				if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Bonus input
					alert('Please Add a Dividends first !');
					$('debt_reinv_it_add_new_div_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Bonus input
					return true;
				}
				
				var totRows = GRInvObj.rowId;
				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_reinv_it_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_reinv_it'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_reinv_it_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_reinv_it_divdt',totRows,'dob_But_debt_reinv_it1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_reinv_it')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_reinv_it_divamt'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
				}			
	//			alert('data validated')
				return true;
			}
			else if(p_type == 'debt_reinv_st'){//REINV ST
				var totRows = GRInvObj.rowId;
				var checktemp_NumStr =checkNumericAll('debt_reinv_st_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
					$(checktemp_NumStr).value='0'
					 return false;
				}

				if(totRows == 0 && p_Xtraparam1 == 'consDividend'){//consider Dividend input
					alert('Please Add a Dividend first !');
					$('debt_reinv_st_add_new_div_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreDividend'){//dont consider Dividend input
					return true;
				}

				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_reinv_st_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_reinv_st'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_reinv_st_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_reinv_st_divdt',totRows,'dob_But_debt_reinv_st1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_reinv_st')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_reinv_st_divnav'+(i+1)+'~debt_reinv_st_divamt'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
					if( IsNumeric($$('debt_reinv_st_divnav'+(i+1) ) ) &&  $$('debt_reinv_st_divnav'+(i+1)) <=0){
						alert('Please Enter Value Greater Than 0 !')
						$('debt_reinv_st_divnav'+(i+1)).focus();									
						return false; 
					}
				}			
	//			alert('data validated')
				return true;
			}
			else if(p_type == 'debt_bonus_it'){//BONUS ST
				var totRows = GRInvObj.rowId;
				var checktemp_NumStr =checkNumericAll('debt_bonus_it_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
					$(checktemp_NumStr).value='0'
					 return false;
				}
				
				if(totRows == 0 && p_Xtraparam1 == 'consBonus'){//consider Dividend input
					alert('Please Add a Bonus first !');
					$('debt_bonus_it_add_new_div_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreBonus'){//dont consider Dividend input
					return true;
				}

				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_bonus_it_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_bonus_it'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_bonus_it_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_bonus_it_divdt',totRows,'dob_But_debt_bonus_it1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_bonus_it')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_bonus_it_unitrec'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
				}			
	//			alert('data validated')
				return true;
			}
			else if(p_type == 'debt_bonus_st'){//BONUS ST
				var checktemp_NumStr =checkNumericAll('debt_bonus_st_act_taxrate');                 
				if(checktemp_NumStr  != ""){
					$(checktemp_NumStr).focus();
					alert('Please Enter Numeric Value !')
					$(checktemp_NumStr).value='0'
					 return false;
				}
				var totRows = GRInvObj.rowId;
				if(totRows == 0 && p_Xtraparam1 == 'consBonus'){//consider Bonus input
					alert('Please Add a Bonus first !');
					$('debt_bonus_st_add_new_bon_but').focus();
					return false;
				}else if(totRows == 0 && p_Xtraparam1 == 'ignoreBonus'){//dont consider Bonus input
					return true;
				}
				var totRows = GRInvObj.rowId;
				var dateFmt=GConObj.dtFmtStr1;
				var temp_NumStr='';
				var checktemp_NumStr='';
				var checktemp_EmpStr='';
				for(var i=0;i<totRows;i++){
					if($$('debt_bonus_st_divdt'+(i+1)) == ''){
						alert('Please Enter Date First !')
						$('dob_But_debt_bonus_st'+(i+1)).focus();
						return false;
					}
				}				

				for(var i=0;i<totRows;i++){
					checktemp_EmpStr='debt_bonus_st_divdt'+(i+1)+'#Date'
					if(checkEmptyAll(checktemp_EmpStr)){
						return false;
					}				
				}

				if(!checkDateInSeries('debt_bonus_st_divdt',totRows,'dob_But_debt_bonus_st1')){/***************date series check [start]*******************/
					return false
				}
				if(!checkPurchRedmpDate('debt_bonus_st')){
					return false;
				}

				for(var i=0;i<totRows;i++){
					temp_NumStr='debt_bonus_st_bon_unit_rec'+(i+1);
					checktemp_NumStr =checkNumericAll(temp_NumStr);                 
					if(checktemp_NumStr  != ""){
						$(checktemp_NumStr).focus();
						alert('Please Enter Numeric Value !')
					   $(checktemp_NumStr).value='0'
						return false;
					}
				}			
	//			alert('data validated')
				return true;
			}
			else{
				return true;
		}
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.validateReturnInvestment() "+err.description)
	}
}

/*************************All Transaction  for return investment done here**************************/
function transReturnInvestment(p_type ,p_action,p_Xtraparam1){
	var flag	=	false;
	try{
		if(p_type == 'main') {
			if(p_action == 'trans'){
					flag	=	false;
				if(GRInvObj.populateAll('main')){//redirection to a particular module
					var tmp_schType = GRInvObj.v_main_schemetype;
					var tmp_option = GRInvObj.v_main_option;
					var tmp_dtof_purch =GRInvObj.v_main_dtof_purch
					var tmp_dtof_redemp=GRInvObj.v_main_dtof_redemp
					var hideUnhideDivNames='eq_gr_it~eq_gr_st~eq_divpo_it~eq_divpo_st~eq_reinv_it~eq_reinv_st~eq_bonus_it~eq_bonus_st'+
																	   '~debt_gr_it~debt_gr_st~debt_divpo_it~debt_divpo_st~debt_reinv_it~debt_reinv_st'+
																		'~debt_bonus_it~debt_bonus_st';
					if (tmp_schType == "1"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 3){
						if($('eq_divpo_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_divpo_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_divpo_it')
						GRInvObj.calculateEQDivPoIt('mainType');						
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_divpo_it','trans');
						}else{
							transReturnInvestment('eq_divpo_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_divpo_it_blink_msg1')//blinker settings
						initBlinking('eq_divpo_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "1" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 3){
						if($('eq_divpo_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_divpo_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_divpo_st')
						GRInvObj.calculateEQDivPoSt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_divpo_st','trans');
						}else{
							transReturnInvestment('eq_divpo_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_divpo_st_blink_msg1')//blinker settings
						initBlinking('eq_divpo_st_blink_msg1')//blinker settings
					}else if (tmp_schType == "1"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 &&tmp_option == 2){
						if($('eq_reinv_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_reinv_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_reinv_it')
						GRInvObj.calculateEQReinvIt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_reinv_it','trans');
						}else{
							transReturnInvestment('eq_reinv_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_reinv_it_blink_msg1')//blinker settings
						initBlinking('eq_reinv_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "1" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 2){
						if($('eq_reinv_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_reinv_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_reinv_st')
						GRInvObj.calculateEQReinvSt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_reinv_st','trans');
						}else{
							transReturnInvestment('eq_reinv_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_reinv_st_blink_msg1')//blinker settings
						initBlinking('eq_reinv_st_blink_msg1')//blinker settings
					}else if (tmp_schType == "1"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 1){
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_gr_it')
						GRInvObj.calculateEQGRIt();						
					}else if(tmp_schType == "1" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 1){
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_gr_st')
						GRInvObj.calculateEQGRSt();						
					}else if (tmp_schType == "1"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 0){
						if($('eq_bonus_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_bonus_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_bonus_it')
						GRInvObj.calculateEQBoIt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_bonus_it','trans');
						}else{
							transReturnInvestment('eq_bonus_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_bonus_it_blink_msg1')//blinker settings
						initBlinking('eq_bonus_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "1" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 0){
						if($('eq_bonus_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('eq_bonus_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','eq_bonus_st')
						GRInvObj.calculateEQBoSt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('eq_bonus_st','trans');
						}else{
							transReturnInvestment('eq_bonus_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('eq_bonus_st_blink_msg1')//blinker settings
						initBlinking('eq_bonus_st_blink_msg1')//blinker settings
					}else if (tmp_schType == "0"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 3){
						if($('debt_divpo_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_divpo_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_divpo_it')
						GRInvObj.calculateDebtDivPoIt('mainType');						
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_divpo_it','trans');
						}else{
							transReturnInvestment('debt_divpo_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_divpo_it_blink_msg1')//blinker settings
						initBlinking('debt_divpo_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "0" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 3){
						if($('debt_divpo_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_divpo_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_divpo_st')
						GRInvObj.calculateDebtDivPoSt('mainType');						
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_divpo_st','trans');
						}else{
							transReturnInvestment('debt_divpo_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_divpo_st_blink_msg1')//blinker settings
						initBlinking('debt_divpo_st_blink_msg1')//blinker settings
					}else if (tmp_schType == "0"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 2){
						if($('debt_reinv_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_reinv_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_reinv_it')
						GRInvObj.calculateDebtReinvIt('mainType');						
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_reinv_it','trans');
						}else{
							transReturnInvestment('debt_reinv_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_reinv_it_blink_msg1')//blinker settings
						initBlinking('debt_reinv_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "0" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 2){
						if($('debt_reinv_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_reinv_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_reinv_st')
						GRInvObj.calculateDebtReinvSt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_reinv_st','trans');
						}else{
							transReturnInvestment('debt_reinv_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_reinv_st_blink_msg1')//blinker settings
						initBlinking('debt_reinv_st_blink_msg1')//blinker settings
					}else if (tmp_schType == "0"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 1){
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_gr_it')
						GRInvObj.calculateDebtGRIt();						
					}else if(tmp_schType == "0" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 1){
						if($('debt_gr_st').style.display != ''){
							transReturnInvestment('debt_gr_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_gr_st')
						GRInvObj.calculateDebtGRSt('mainType');						
						if($('debt_gr_st').style.display == ''){
							transReturnInvestment('debt_gr_st','trans');
						}
					}else if (tmp_schType == "0"   && days_between(tmp_dtof_purch,tmp_dtof_redemp) >= 365 && tmp_option == 0){
						if($('debt_bonus_it').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_bonus_it','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_bonus_it')
						GRInvObj.calculateDebtBoIt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_bonus_it','trans');
						}else{
							transReturnInvestment('debt_bonus_it','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_bonus_it_blink_msg1')//blinker settings
						initBlinking('debt_bonus_it_blink_msg1')//blinker settings
					}else if(tmp_schType == "0" && days_between(tmp_dtof_purch,tmp_dtof_redemp) < 365 && tmp_option == 0){
						if($('debt_bonus_st').style.display != ''){
							GRInvObj.rowId=0;
							transReturnInvestment('debt_bonus_st','reset');
						}
						hideUnhideFields(hideUnhideDivNames,'')
						hideUnhideFields('','debt_bonus_st')
						GRInvObj.calculateEQBoSt('mainType');
						if(GRInvObj.rowId >= 1){
							transReturnInvestment('debt_bonus_st','trans');
						}else{
							transReturnInvestment('debt_bonus_st','trans',p_Xtraparam1);//called when need to consider dividend calculation
						}
						stopBlinking('debt_bonus_st_blink_msg1')//blinker settings
						initBlinking('debt_bonus_st_blink_msg1')//blinker settings
					}
				}else{
					return false;				
				}
			}else if(p_action == 'reset'){
				GRInvObj.resetAll('main','both')
			}
		} else if(p_type == 'eq_gr_st') {
			if(p_action == 'taxratechange'){
				setTaxRate('eq_gr_st_surch','eq_gr_st_taxrate');
				GRInvObj.calculateEQGRSt('taxchange');
			}
		}else if(p_type == 'eq_reinv_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_reinv_it',p_Xtraparam1))	{
					GRInvObj.calculateEQReinvIt('modType');
					stopBlinking('eq_reinv_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_reinv_it','notboth');
			}
		}else if(p_type == 'eq_reinv_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_reinv_st',p_Xtraparam1))	{
					GRInvObj.calculateEQReinvSt('modType');
					stopBlinking('eq_reinv_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_reinv_st','notboth');
			}
		}else if(p_type == 'eq_bonus_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_bonus_it',p_Xtraparam1))	{
					GRInvObj.calculateEQBoIt('modType');
					stopBlinking('eq_bonus_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_bonus_it','notboth');
			}
		}else if(p_type == 'eq_bonus_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_bonus_st',p_Xtraparam1))	{
					GRInvObj.calculateEQBoSt('modType');
					stopBlinking('eq_bonus_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_bonus_st','notboth');
			}
		}else if(p_type == 'eq_divpo_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_divpo_it',p_Xtraparam1))	{
					GRInvObj.calculateEQDivPoIt('modType');
					stopBlinking('eq_divpo_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_divpo_it','notboth');
			}
		}else if(p_type == 'eq_divpo_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('eq_divpo_st',p_Xtraparam1))	{
					GRInvObj.calculateEQDivPoSt('modType');
					stopBlinking('eq_divpo_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('eq_divpo_st','notboth');
			}
		}else if(p_type == 'debt_gr_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_gr_st'))	{
					GRInvObj.calculateDebtGRSt('modType');
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_gr_st','notboth');
			}
		}else if(p_type == 'debt_divpo_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_divpo_it',p_Xtraparam1))	{
					GRInvObj.calculateDebtDivPoIt('modType');
					stopBlinking('debt_divpo_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_divpo_it','notboth');
			}
		}else if(p_type == 'debt_divpo_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_divpo_st',p_Xtraparam1))	{
					GRInvObj.calculateDebtDivPoSt('modType');
					stopBlinking('debt_divpo_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_divpo_st','notboth');
			}
		}else if(p_type == 'debt_reinv_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_reinv_it',p_Xtraparam1))	{
					GRInvObj.calculateDebtReinvIt('modType');
					stopBlinking('debt_reinv_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_reinv_it','notboth');
			}
		}else if(p_type == 'debt_reinv_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_reinv_st',p_Xtraparam1))	{
					GRInvObj.calculateDebtReinvSt('modType');
					stopBlinking('debt_reinv_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_reinv_st','notboth');
			}
		}else if(p_type == 'debt_bonus_it') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_bonus_it',p_Xtraparam1))	{
					GRInvObj.calculateDebtBoIt('modType');
					stopBlinking('debt_bonus_it_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_bonus_it','notboth');
			}
		}else if(p_type == 'debt_bonus_st') {
			 if (p_action == 'trans'){ 
				if(validateReturnInvestment('debt_bonus_st',p_Xtraparam1))	{
					GRInvObj.calculateDebtBoSt('modType');
					stopBlinking('debt_bonus_st_blink_msg1') //blinker settings
					return true;
				}
			}else if(p_action == 'reset'){
				resetReturnInvestment('debt_bonus_st','notboth');
			}
		}
	}catch(err){//
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.transReturnInvestment() "+err.description)
	}
}


/*************************All Resets for return investment done here**************************/
function resetReturnInvestment(p_type,resetType){
	try{
			if(p_type == 'main'){
				if(resetType == 'both'){
					var hideUnhideDivNames='eq_gr_it~eq_gr_st~eq_divpo_it~eq_divpo_st~eq_reinv_it~eq_reinv_st~eq_bonus_it~eq_bonus_st'+
																	   '~debt_gr_it~debt_gr_st~debt_divpo_it~debt_divpo_st~debt_reinv_it~debt_reinv_st'+
																		'~debt_bonus_it~debt_bonus_st';
					GRInvObj.v_main_schemetype=1;
					GRInvObj.v_main_option=3;
					GRInvObj.v_main_dtof_purch='';
					GRInvObj.v_main_unit_purch=0;
					GRInvObj.v_main_purch_cost=0;
					GRInvObj.v_main_dtof_redemp='';
					GRInvObj.v_main_redemp_val=0;
					var emptStr='main_dtof_purch~main_dtof_redemp';
					setClearField(emptStr);
					var defStr	='main_unit_purch~main_purch_cost~main_redemp_val'
					setDefaultValueAll(defStr	,'0')
					$('main_schemetype').value=1
					$('main_option').value=3
					hideUnhideFields(hideUnhideDivNames,'')
				} 
			} else if( p_type == 'eq_reinv_it' || 
							p_type == 'eq_bonus_it'      || p_type == 'eq_divpo_it'     ||
							p_type == 'eq_divpo_st'      || p_type == 'debt_divpo_it'  || 
							p_type == 'debt_divpo_st'  || p_type == 'debt_reinv_it' ){
				var temp_TbodyObj=$(p_type+'_div_tab').getElementsByTagName("TBODY")[0];
				var rowArrObj=temp_TbodyObj.childNodes; 
				if(document.getElementById(p_type+'_surch') != null ){//dont use $ here
					$(p_type+'_surch').value='1';
				}				
				if(document.getElementById(p_type+'_act_taxrate') != null ){//dont use $ here
					$(p_type+'_act_taxrate').value='0';
				}				
				if(resetType == 'notboth'){
					var temp_noOfRows=  rowArrObj.length;
					if(temp_noOfRows>=2){
						for (var i=1;i<temp_noOfRows ;i++ ){
							temp_TbodyObj.removeChild(rowArrObj[1])
						}
						GRInvObj.rowId=0;
					}
				}
			} else if( p_type == 'eq_reinv_st'         || 
							p_type == 'eq_bonus_st'      || p_type == 'debt_reinv_st'     ||
							p_type == 'debt_bonus_it'    || p_type == 'debt_bonus_st'  ){
				var temp_TbodyObj=$(p_type+'_div_tab').getElementsByTagName("TBODY")[0];
				var rowArrObj=temp_TbodyObj.childNodes; 
				if(document.getElementById(p_type+'_surch') != null){//dont use $ here
					$(p_type+'_surch').value='1';
				}				
				if(document.getElementById(p_type+'_act_taxrate') != null ){//dont use $ here
					$(p_type+'_act_taxrate').value='0';
				}				
				if(resetType == 'notboth'){
					var temp_noOfRows=  rowArrObj.length;
					if(temp_noOfRows>=3){
						for (var i=2;i<temp_noOfRows ;i++ ){
							temp_TbodyObj.removeChild(rowArrObj[2])
						}
						GRInvObj.rowId=0;
					}
				}
			}else if(p_type == 'debt_gr_st'){
				$('debt_gr_st_act_taxrate').value='0'
			}
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.resetReturnInvestment() "+err.description)
	}
}

//********************xtra common functions[START]****************************************/
function setTaxRate(comboId,fieldId){
	try{
		if($$(comboId) == '1'){
			GRInvObj.taxRate=11.33
			$(fieldId).value='11.33';		
		}else if($$(comboId) == '0'){
			GRInvObj.taxRate=10.30
			$(fieldId).value='10.30';		
		} 		
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.setTaxRate() "+err.description)
	}
}

function checkDateInSeries(p_id,p_totDates,p_focus_Id){
	try{
			var dateSerArr=new Array();
			for(var i=0;i<p_totDates;i++){
				if($$(p_id+(i+1)) != ''){
					dateSerArr[dateSerArr.length]=getDateObject(p_id+(i+1),GConObj.dtFmtStr1) 
				}								
			}

			if(dateSerArr.length>0){
				if(checkDateSeries(dateSerArr,'asc')){
					alert('Please Enter dates in Ascending order !')
					$(p_focus_Id).focus();
					return false;						
				}
			}	
		return true;						
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.checkDateInSeries() "+err.description)
	}
}

function checkPurchRedmpDate(p_Type){
	try{
		var dateFmt=GConObj.dtFmtStr1;
		var totRows = GRInvObj.rowId;
		for(var i=0;i<totRows;i++){
			if(	getDateObject(p_Type+'_divdt'+(i+1),dateFmt) <GRInvObj.v_main_dtof_purch 
													||  
				getDateObject(p_Type+'_divdt'+(i+1),dateFmt) >GRInvObj.v_main_dtof_redemp
			){
				alert('Date Entered Should be Greater than Date Of Purchase and less than Date Of Redemption !');						
				$('dob_But_'+p_Type+(i+1)).focus();
				return false;
			}				
		}
		return true;
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.checkPurchRedmpDate() "+err.description)
	}
}

//********************xtra common functions[END]****************************************/

function validateBeforeAddNewRow(p_Type){
	try{
		if(GRInvObj.rowId >= 1){	
			if($$(p_Type+'_divdt'+GRInvObj.rowId) == ''){														
				alert('Please Enter Date of the above row First !')
				$('dob_But_'+p_Type+GRInvObj.rowId).focus();	
				return	false;
			}else{
				if(transReturnInvestment(p_Type,'trans')){
					addNewRow(p_Type);				
				}
			}
		}else{
					addNewRow(p_Type);				
		}
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.addNewRow() "+err.description)
	}
}

function addNewRow(p_type){
	try{
		if(p_type == 'eq_reinv_it'){
			var tabObj=$('eq_reinv_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="eq_reinv_it_divdt'+temp_rowid+'"  name="eq_reinv_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"    readonly  onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_reinv_it'+temp_rowid+'" onclick="show_calendar(\'eq_reinv_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_reinv_it_divamt'+temp_rowid+'" id="eq_reinv_it_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			var td3 = document.createElement("TD");
		    td3.innerHTML=	'<input type="text" name="eq_reinv_it_divnav'+temp_rowid+'" id="eq_reinv_it_divnav'+temp_rowid+'"  value="0" class="textBox"   onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td3.setAttribute('align','center')
			var td4 = document.createElement("TD");
			 td4.className=GConObj.tableResultsDetCss 
			 td4.setAttribute("id",'eq_reinv_it_unitrec'+temp_rowid)
			 td4.innerHTML='0';
			 td4.setAttribute('align','center')
			 var td5 = document.createElement("TD");
			 td5.className=GConObj.tableResultsDetCss 
			 td5.setAttribute("id",'eq_reinv_it_nofunitrec'+temp_rowid)
			 td5.innerHTML='0';
			 td5.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'eq_reinv_it_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'eq_reinv_it_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'eq_reinv_it_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td3);
	  		row.appendChild(td4);
	  		row.appendChild(td5);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		}else  if(p_type == 'eq_reinv_st'){
			var tabObj=$('eq_reinv_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="eq_reinv_st_divdt'+temp_rowid+'"  name="eq_reinv_st_divdt'+temp_rowid+'" value=""  maxlength="30"     readonly  class="textBox"    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_reinv_st'+temp_rowid+'" onclick="show_calendar(\'eq_reinv_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_reinv_st_divamt'+temp_rowid+'" id="eq_reinv_st_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			var td3 = document.createElement("TD");
		    td3.innerHTML=	'<input type="text" name="eq_reinv_st_divnav'+temp_rowid+'" id="eq_reinv_st_divnav'+temp_rowid+'"  value="0" class="textBox"   onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td3.setAttribute('align','center')
			var td4 = document.createElement("TD");
			 td4.className=GConObj.tableResultsDetCss 
			 td4.setAttribute("id",'eq_reinv_st_unitrec'+temp_rowid)
			 td4.innerHTML='0';
			 td4.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'eq_reinv_st_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'eq_reinv_st_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'eq_reinv_st_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td3);
	  		row.appendChild(td4);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		} else  if(p_type == 'eq_bonus_it'){
			var tabObj=$('eq_bonus_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="eq_bonus_it_divdt'+temp_rowid+'"  name="eq_bonus_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"       readonly   onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_bonus_it'+temp_rowid+'" onclick="show_calendar(\'eq_bonus_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_bonus_it_bon_unit_rec'+temp_rowid+'" id="eq_bonus_it_bon_unit_rec'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center');
			 var td5 = document.createElement("TD");
			 td5.className=GConObj.tableResultsDetCss 
			 td5.setAttribute("id",'eq_bonus_it_nofunitrec'+temp_rowid)
			 td5.innerHTML='0';
			 td5.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'eq_bonus_it_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'eq_bonus_it_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'eq_bonus_it_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td5);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		}else  if(p_type == 'eq_bonus_st'){
			var tabObj=$('eq_bonus_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="eq_bonus_st_divdt'+temp_rowid+'"  name="eq_bonus_st_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"      readonly    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_bonus_st'+temp_rowid+'" onclick="show_calendar(\'eq_bonus_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_bonus_st_bon_unit_rec'+temp_rowid+'" id="eq_bonus_st_bon_unit_rec'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			 var td5 = document.createElement("TD");
			 td5.className=GConObj.tableResultsDetCss 
			 td5.setAttribute("id",'eq_bonus_st_nofunitrec'+temp_rowid)
			 td5.innerHTML='0';
			 td5.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'eq_bonus_st_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'eq_bonus_st_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'eq_bonus_st_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td5);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		}else  if(p_type == 'eq_divpo_it'){
			var tabObj=$('eq_divpo_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');//
		    td1.innerHTML=	'<input type="text"  id="eq_divpo_it_divdt'+temp_rowid+'"  name="eq_divpo_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"      readonly    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_divpo_it'+temp_rowid+'" onclick="show_calendar(\'eq_divpo_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_divpo_it_divamt'+temp_rowid+'" id="eq_divpo_it_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
			tbody.appendChild(row);
		}else  if(p_type == 'eq_divpo_st'){
			var tabObj=$('eq_divpo_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="eq_divpo_st_divdt'+temp_rowid+'"  name="eq_divpo_st_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"     readonly     onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_eq_divpo_st'+temp_rowid+'" onclick="show_calendar(\'eq_divpo_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="eq_divpo_st_divamt'+temp_rowid+'" id="eq_divpo_st_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
			tbody.appendChild(row);
		}else  if(p_type == 'debt_divpo_it'){
			var tabObj=$('debt_divpo_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_divpo_it_divdt'+temp_rowid+'"  name="debt_divpo_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"      readonly    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_divpo_it'+temp_rowid+'" onclick="show_calendar(\'debt_divpo_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_divpo_it_divamt'+temp_rowid+'" id="debt_divpo_it_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
			tbody.appendChild(row);
		}else  if(p_type == 'debt_divpo_st'){
			var tabObj=$('debt_divpo_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_divpo_st_divdt'+temp_rowid+'"  name="debt_divpo_st_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"      readonly    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_divpo_st'+temp_rowid+'" onclick="show_calendar(\'debt_divpo_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_divpo_st_divamt'+temp_rowid+'" id="debt_divpo_st_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
			tbody.appendChild(row);
		}else  if(p_type == 'debt_reinv_it'){
			var tabObj=$('debt_reinv_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_reinv_it_divdt'+temp_rowid+'"  name="debt_reinv_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"       readonly   onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_reinv_it'+temp_rowid+'" onclick="show_calendar(\'debt_reinv_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_reinv_it_divamt'+temp_rowid+'" id="debt_reinv_it_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			var td3 = document.createElement("TD");
		    td3.innerHTML=	'<input type="text" name="debt_reinv_it_divnav'+temp_rowid+'" id="debt_reinv_it_divnav'+temp_rowid+'"  value="0" class="textBox"   onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td3.setAttribute('align','center')
			var td4 = document.createElement("TD");
			 td4.className=GConObj.tableResultsDetCss 
			 td4.setAttribute("id",'debt_reinv_it_unitrec'+temp_rowid)
			 td4.innerHTML='0';
			 td4.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'debt_reinv_it_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			 row.appendChild(td1);
			 row.appendChild(td2);
	  		 row.appendChild(td3);
	  		 row.appendChild(td4);
	  		 row.appendChild(td7);
			 tbody.appendChild(row);
		} else  if(p_type == 'debt_reinv_st'){
			var tabObj=$('debt_reinv_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_reinv_st_divdt'+temp_rowid+'"  name="debt_reinv_st_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"      readonly    onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_reinv_st'+temp_rowid+'" onclick="show_calendar(\'debt_reinv_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_reinv_st_divamt'+temp_rowid+'" id="debt_reinv_st_divamt'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			var td3 = document.createElement("TD");
		    td3.innerHTML=	'<input type="text" name="debt_reinv_st_divnav'+temp_rowid+'" id="debt_reinv_st_divnav'+temp_rowid+'"  value="0" class="textBox"   onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td3.setAttribute('align','center')
			var td4 = document.createElement("TD");
			 td4.className=GConObj.tableResultsDetCss 
			 td4.setAttribute("id",'debt_reinv_st_unitrec'+temp_rowid)
			 td4.innerHTML='0';
			 td4.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'debt_reinv_st_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'debt_reinv_st_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'debt_reinv_st_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td3);
	  		row.appendChild(td4);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		} 
		else  if(p_type == 'debt_bonus_it'){
			var tabObj=$('debt_bonus_it_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_bonus_it_divdt'+temp_rowid+'"  name="debt_bonus_it_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"     readonly     onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_bonus_it'+temp_rowid+'" onclick="show_calendar(\'debt_bonus_it_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_bonus_it_unitrec'+temp_rowid+'" id="debt_bonus_it_unitrec'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			 var td3 = document.createElement("TD");
			 td3.className=GConObj.tableResultsDetCss 
			 td3.setAttribute("id",'debt_bonus_it_nofunitrec'+temp_rowid)
			 td3.innerHTML='0';
			 td3.setAttribute('align','center')
			var td4 = document.createElement("TD");
			 td4.className=GConObj.tableResultsDetCss 
			 td4.setAttribute("id",'debt_bonus_it_capgain'+temp_rowid)
			 td4.innerHTML='0';
			 td4.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td3);
	  		row.appendChild(td4);
			tbody.appendChild(row);
		}else  if(p_type == 'debt_bonus_st'){
			var tabObj=$('debt_bonus_st_div_tab');
			GRInvObj.rowId=(GRInvObj.rowId+1)
			var temp_rowid=GRInvObj.rowId;			
			var tbody = tabObj.getElementsByTagName("TBODY")[0];
	  		var row = document.createElement("TR");
			var td1 = document.createElement("TD");
			td1.setAttribute('nowrap','nowrap');
		    td1.innerHTML=	'<input type="text"  id="debt_bonus_st_divdt'+temp_rowid+'"  name="debt_bonus_st_divdt'+temp_rowid+'" value=""  maxlength="30" class="textBox"     readonly     onfocus="startBlinking()"/>'+
											'<input type="button" class="buttonSmallWid"  id="dob_But_debt_bonus_st'+temp_rowid+'" onclick="show_calendar(\'debt_bonus_st_divdt'+temp_rowid+'\', null,null,\'DD/MM/YYYY\');"  value="..."  title="Select Date" onfocus="startBlinking()">&nbsp;';
			td1.setAttribute('align','center')
			var td2 = document.createElement("TD");
		    td2.innerHTML=	'<input type="text" name="debt_bonus_st_bon_unit_rec'+temp_rowid+'" id="debt_bonus_st_bon_unit_rec'+temp_rowid+'"  value="0" class="textBox"    onblur="javascript:if(this.value == \'\')this.value=0;" onfocus="startBlinking()">';
			td2.setAttribute('align','center')
			var td6 = document.createElement("TD");
			 td6.className=GConObj.tableResultsDetCss 
			 td6.setAttribute("id",'debt_bonus_st_taxrate'+temp_rowid)
			 td6.innerHTML='0';
			 td6.setAttribute('align','center')
			var td7 = document.createElement("TD");
			 td7.className=GConObj.tableResultsDetCss 
			 td7.setAttribute("id",'debt_bonus_st_capgain'+temp_rowid)
			 td7.innerHTML='0';
			 td7.setAttribute('align','center')
			var td8 = document.createElement("TD");
			 td8.className=GConObj.tableResultsDetCss 
			 td8.setAttribute("id",'debt_bonus_st_tax'+temp_rowid)
			 td8.innerHTML='0';
			 td8.setAttribute('align','center')
			row.appendChild(td1);
			row.appendChild(td2);
	  		row.appendChild(td6);
	  		row.appendChild(td7);
	  		row.appendChild(td8);
			tbody.appendChild(row);
		} 
	}catch(err){
		alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.addNewRow() "+err.description)
	}
}

//XIRR calculation [ START ]
	function getXIRRPre(cashFlowsArr,dateArray, estimatedResult) {
		try{
			var temp_XirrResult=0.0;

			temp_XirrResult=getXIRR(cashFlowsArr,dateArray, estimatedResult)
			if(temp_XirrResult < 0){
				temp_XirrResult=getXIRR(cashFlowsArr,dateArray, 0.0)
			}
			else if(temp_XirrResult==""){
					
					 alert("Using This Input We can not perform XIIR Calculation, So We use IIR Calculation")	
				 	 temp_XirrResult=getIRR(cashFlowsArr,dateArray, estimatedResult)
				
			}
				
			
			return ( roundNumber( (temp_XirrResult * 100),2 ) ) ;
		}catch(err){
			alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.getXIRRPre() "+err.description)
		}
	}
	function getXIRR(cashFlowsArr,dateArray, estimatedResult) {
		 try {
/*			 alert(cashFlowsArr.length)
			 alert(dateArray.length)
			alert(dateArray[0])
			alert(dateArray[1])
*/			 var result ="";
				
			 if (cashFlowsArr != null && cashFlowsArr.length > 0) { 
				//check if business startup costs is not zero:
				if (cashFlowsArr[0] != 0.0) {
					var noOfcashFlowsArr = cashFlowsArr.length;
					var irrGuess = 0.1; //default: 10%
					if (isNaN(estimatedResult)) {
						irrGuess = estimatedResult;
						if (irrGuess <= 0.0) irrGuess = 0.5;
					}
					var sumcashFlowsArr = 0.0;
					//check if at least 1 positive and 1 negative cash flow exists:
					var noOfNegativecashFlowsArr = 0;
					var noOfPositivecashFlowsArr = 0;
					for (var i = 0; i < noOfcashFlowsArr; i++) {
						sumcashFlowsArr += (cashFlowsArr[i]/( Math.pow( ( 1+irrGuess )  ,(  days_between( dateArray[i], dateArray[0] )  ) / 365  )  ) );
						if (cashFlowsArr[i] > 0) {
							noOfPositivecashFlowsArr++;
						} else if (cashFlowsArr[i] < 0) {
							noOfNegativecashFlowsArr++;
						}
					}
					
					if (noOfNegativecashFlowsArr > 0 && noOfPositivecashFlowsArr > 0) { //at least 1 negative and 1 positive cash flow available?
						//set estimated result:
						
						//initialize first IRR with estimated result:
						var irr = 0.0;
						if (sumcashFlowsArr < 0) { //sum of cash flows negative?
							irr = -irrGuess;
							
						} else { //sum of cash flows not negative
							
							irr = irrGuess;
						}

						//iteration:
						var minDistance = .0000001; //the smaller the distance, the smaller the interpolation error
						var cashFlowsArrtart = cashFlowsArr[0]; //business startup costs
						var maxIteration = 50;
						var wasHi = false;
						var cashValue = 0.0; //cash value (Kapitalwert)
						for (var i = 0; i <= maxIteration; i++) { //for each iteration
							//calculate cash value with current irr:
							cashValue = cashFlowsArrtart; //init with startup costs
							for (var  j = 1; j < noOfcashFlowsArr; j++) { //for each cash floe
								cashValue += cashFlowsArr[j] / Math.pow( ( 1+irr)  ,(days_between( dateArray[j] , dateArray[0] ) ) / 365  )   ;
	//							cashValue += cashFlowsArr[j] / Math.pow(1.0 + irr, j);
							}//next cash flow
							
							if (Math.abs(cashValue) < 0.01) { //cash value is nearly zero
								result = irr;
								break;
							}
							
							//adjust irr for next iteration:
							if (cashValue > 0.0) { //cash value > 0 => next irr > current irr
								if (wasHi) {
									irrGuess /= 2;
								}
								
								irr += irrGuess;
								
								if (wasHi) {
									irrGuess -= minDistance;
									wasHi = false;
								}
								
							} else { //cash value < 0 => next irr < current irr
								irrGuess /= 2;
								irr -= irrGuess;
								
								wasHi = true;
								
							}
							
							if (irrGuess <= minDistance) { //estimated result too small to continue => end calculation
									
								if( irr>=3){
								result = 3;
	  							}
								else{
									result = irr;
								
								}
								break;
							}
							
						}//next iteration
					}//else: noOfNegativecashFlowsArr == 0 || noOfPositivecashFlowsArr == 0
				}//else: first cash flow is 0
			}//else: cashFlowsArr unavailable
			
			if(result==""){
				 return result;
	  	    }
			else{
				return result;
			}
		}catch(err){
			alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.getXIRR() "+err.description)
		}
	}//
//XIRR calculation [ END ]

function getIRR(cashFlowsArr,dateArray, estimatedResult) {
		 try {
			 if (cashFlowsArr != null && cashFlowsArr.length > 0) { 
				//check if business startup costs is not zero:
				if (cashFlowsArr[0] != 0.0) {
					var noOfcashFlowsArr = cashFlowsArr.length;
					var irrGuess = 0.1; //default: 10%
					if (isNaN(estimatedResult)) {
						irrGuess = estimatedResult;
						if (irrGuess <= 0.0) irrGuess = 0.5;
					}
					var sumcashFlowsArr = 0.0;
					//check if at least 1 positive and 1 negative cash flow exists:
					var noOfNegativecashFlowsArr = 0;
					var noOfPositivecashFlowsArr = 0;
					for (var i = 0; i < noOfcashFlowsArr; i++) {
					sumcashFlowsArr += (cashFlowsArr[i]/( Math.pow( ( 1+irrGuess )  ,i  )  ) );
						if (cashFlowsArr[i] > 0) {
							noOfPositivecashFlowsArr++;
						} else if (cashFlowsArr[i] < 0) {
							noOfNegativecashFlowsArr++;
						}
					}
					
					if (noOfNegativecashFlowsArr > 0 && noOfPositivecashFlowsArr > 0) { //at least 1 negative and 1 positive cash flow available?
						//set estimated result:
						
						//initialize first IRR with estimated result:
						var irr = 0.0;
						if (sumcashFlowsArr < 0) { //sum of cash flows negative?
							irr = -irrGuess;
						} else { //sum of cash flows not negative
							irr = irrGuess;
						}

						//iteration:
						var minDistance = .0000001; //the smaller the distance, the smaller the interpolation error
						var cashFlowsArrtart = cashFlowsArr[0]; //business startup costs
						var maxIteration = 50;
						var wasHi = false;
						var cashValue = 0.0; //cash value (Kapitalwert)
						for (var i = 0; i <= maxIteration; i++) { //for each iteration

							//calculate cash value with current irr:
							cashValue = cashFlowsArrtart; //init with startup costs
							for (var  j = 1; j < noOfcashFlowsArr; j++) { //for each cash floe

								cashValue += cashFlowsArr[j] / Math.pow( ( 1+irr)  ,j )   ;
	//							cashValue += cashFlowsArr[j] / Math.pow(1.0 + irr, j);
							}//next cash flow
							
							if (Math.abs(cashValue) < 0.01) { //cash value is nearly zero
								result = irr;
								break;
							}
							
							//adjust irr for next iteration:
							if (cashValue > 0.0) { //cash value > 0 => next irr > current irr
								if (wasHi) {
									irrGuess /= 2;
								}
								
								irr += irrGuess;
								
								if (wasHi) {
									irrGuess -= minDistance;
									wasHi = false;
								}
							} else { //cash value < 0 => next irr < current irr
								irrGuess /= 2;
								irr -= irrGuess;
								wasHi = true;
							}
							
							if (irrGuess <= minDistance) { //estimated result too small to continue => end calculation
								result = irr;
								break;
							}
						}//next iteration
					}//else: noOfNegativecashFlowsArr == 0 || noOfPositivecashFlowsArr == 0
				}//else: first cash flow is 0
			}//else: cashFlowsArr unavailable
			
			if(result==""){
				
	  	    }
			else{
				
				return result;
			}
		}catch(err){
			result=3;
			return result;
			//alert("err in KStreetCalcMutFnd.html.ReturnInvestment.js.getXIRR() 111111111"+err.description)
		}
	}//
//IRR calculation [ END ]

