function setEditableFieldValue(element, newVal){
    if(element.oldvalue!=newVal){
    	element.value = newVal;
    	element.oldvalue = newVal;
    }
}

////////////////////////////// CG Calculation Starts /////////////////////////////////

function addCGDeductions(tableId){
	console.log('addCGDeductionsaddCGDeductionstableIdtableId '+tableId);
	var tab = document.getElementById(tableId);
	var inputs = tab.getElementsByTagName("INPUT");
	var sum = 0;
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].name.match('amount$')){
			sum = parseInt(sum) + parseInt(coalesce(inputs[i].value));
		}
	}
	return sum;
}

function calcBulidingSellSTCG(){
	try{

		var table = document.getElementById('scheduleCGstcg1');
		var noOfRows = table.rows.length;


		var temp=parseInt('0',10);
		var temp1=parseInt('0',10);
		var capgainonAssetsTemp=parseInt('0',10);


		for (var i = 0; i <noOfRows/14; i++) {
			//calculate deduction
			var totalDedn = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].deductSec48totalDedn')[0];
			if(eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].fullConsideration50C'))>0)
			{

			totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].deductSec48aquisitCost') +
	                coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].deductSec48improveCost') +
	                coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].deductSec48expOnTrans'));
			}
			
			else
			{
				totalDedn.value=parseInt('0', 10);
			}


			//calcBalance
			   var balanceCG = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].balanceCG')[0];
			   balanceCG.value = eval(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].fullConsideration50C')[0].value) -
			                    coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].deductSec48totalDedn'));

			   //gain on asset
			   var capgainonAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].capgainonAssets')[0];

			   var exemptionOrDednUs54 = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDednUs54')[0];
			   var j = i+1;
			   var tableId = 'stcgDeduction_ded'+j;

				var table2 = document.getElementById(tableId);
				var noOfRows2 = table2.rows.length;

				var temp=parseInt('0',10);

					for(var j = 0; j <noOfRows2-3; j++){
						temp = parseInt(temp) + eval(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDedn['+j+'].amount')[0].value),10));
					}

			   exemptionOrDednUs54.value = temp;

			   if(parseInt(balanceCG.value) > parseInt(0,10)){
			   capgainonAssets.value = zeroOrMore(eval(parseInt(balanceCG.value) -
			                    			parseInt(exemptionOrDednUs54.value)));
				} else {
				capgainonAssets.value = parseInt(balanceCG.value);
				}

			   capgainonAssetsTemp = parseInt(capgainonAssets.value) + parseInt(capgainonAssetsTemp);
		}

		var capgainonAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild.capgainonAssets')[0];
		 capgainonAssets.value = eval(parseInt(capgainonAssetsTemp,10));


	}catch(e){
	   alert('error in calcBulidingSellSTCG=' + e.stack);
   }
}
function addCGDeductionsStcg1(tableId){
	var table = document.getElementById('scheduleCGstcg1');
	var noOfRows = table.rows.length;
	console.log("tableId"+tableId);
	var table2 = document.getElementById(tableId);
	var noOfRows2 = table2.rows.length;

	var temp=parseInt('0',10);

	var exemptionOrDednUs54=parseInt('0',10);

	for (var i = 0; i <noOfRows/14; i++) {

		for(var j = 0; j <noOfRows2-3; j++){
			temp = parseInt(temp) + eval(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDedn['+j+'].amount')[0].value),10));
		}
		return temp;
	}

}

function calcSlumpSaleSTCG(){
	   var netWorthOfUTDivn = document.getElementsByName('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSale')[0];
	   netWorthOfUTDivn.value = coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.fullConsideration')
	   							- coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.netWorthOfUTDivn');;

}
function calcPTISTCG(){
	   var stcgUnderptiTotal = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.totAmtStcgUnderPTI')[0];
	   stcgUnderptiTotal.value = coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcg15')
	   							+ coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcg30')
	   							+ coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcgAr');

}


function calcEquitySellSTCG(cgosIncome){

	var tab = document.getElementById('scheduleCGstcg2');
	var len = tab.tBodies.length;
	var sum = 0;
	for(var i=0;i<len;i++){
		//Calc deduction
	    var totalDedn = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].deductSec48totalDedn')[0];
	    if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+i+'].fullConsideration')[0].value),10)>0)
		{

	    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].deductSec48aquisitCost') +
	                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].deductSec48improveCost') +
	                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].deductSec48expOnTrans'));

		}
		else
		{
			totalDedn.value=parseInt('0', 10);
		}

	    //calcBalance
	    var balanceCG = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].balanceCG')[0];
	    balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].fullConsideration') -
	    					   totalDedn.value);

	    //gain on equity share
	    var capgainonAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].capgainonAssets')[0];
	    capgainonAssets.value = eval(parseInt(balanceCG.value, 10) +
	                     coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT['+ i +'].lossSec94of7Or94of8'));

	    var section = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT[' + i +  '].section')[0].value;
	    if(section=='1A'){
	    	sum = parseInt(sum) + parseInt(capgainonAssets.value);
	    }else if(section=='5AD1biip'){
	    	cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = capgainonAssets.value;
	    }

	}
	return sum;
}

function calcSecuritiesSellSTCG(){
	//Calc deduction
	
    var totalDedn = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.deductSec48totalDedn')[0];
    if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.fullConsideration')[0].value),10)>0)
	{
    
    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.deductSec48aquisitCost') +
                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.deductSec48improveCost') +
                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.deductSec48expOnTrans'));
	}
    else
	{
    	totalDedn.value=parseInt('0', 10);
	}

    //calcBalance
    var balanceCG = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.balanceCG')[0];
     balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.fullConsideration') -
    					   totalDedn.value);

    //gain on Securities
    var capgainonAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.capgainonAssets')[0];
    capgainonAssets.value = eval(parseInt(balanceCG.value, 10) +
                     coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.lossSec94of7Or94of8'));


}

function calcOtherAssetSellSTCG(){
	//Calc deduction
    var totalDedn = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.deductSec48.totalDedn')[0];
    if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.fullConsideration')[0].value),10)>0)
	{

    
    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.deductSec48.aquisitCost') +
                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.deductSec48.improveCost') +
                           coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.deductSec48.expOnTrans'));
	}
    else
	{
    	totalDedn.value=parseInt('0', 10);
	}

    //calcBalance
    var balanceCG = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.balanceCG')[0];
    balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.fullConsideration') - (totalDedn.value));

    var exemptionOrDednUs54 = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.exemptionOrDednUs54')[0];
    exemptionOrDednUs54.value = addCGDeductions('stcgDeduction2');
    //gain on Securities
    var capgainonAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.capgainonAssets')[0];
    capgainonAssets.value = eval(parseInt(balanceCG.value, 10) +
                     coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.lossSec94of7Or94of8') + coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.amtDeemedCGDepAssets'));

    if(parseInt(coalesce(capgainonAssets.value),10) > 0){
    	capgainonAssets.value = zeroOrMore(parseInt(capgainonAssets.value) - coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.exemptionOrDednUs54'));
    }
}


function calculateSTCG(cgosIncome){

	calcBulidingSellSTCG();
	calcSlumpSaleSTCG();
	calcPTISTCG();

    var sum = calcEquitySellSTCG(cgosIncome);
    calcSecuritiesSellSTCG();

    var amtDeemedCGDepAssets = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.amtDeemedCGDepAssets')[0];
    amtDeemedCGDepAssets.value =coalesceSetRet('scheduleDCG.summaryFromDeprSchCG.totalDepreciation');

    calcOtherAssetSellSTCG();



    var totalSTCG = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.totalSTCG')[0];
    totalSTCG.value = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild.capgainonAssets') +
    						coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSale') +
            				parseInt(sum) +
            				parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii) +
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRITransacSec48Dtl.nRItaxSTTPaid') +
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRITransacSec48Dtl.nRItaxSTTNotPaid') +
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.totAmtStcgUnderPTI') +
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.capgainonAssets') +
            			    coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.capgainonAssets') +
            				//coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.amtDeemedCGDepAssets') +
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.unUtilizedCapGain54.totAmtStcgUnderDtaa') -
            				coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.totAmtStcgUnderDtaa'));

	cgosIncome.cgInc.stcg.prctg30.sec115AD  = coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRISecur115AD.capgainonAssets');
    cgosIncome.cgInc.stcg.prctg30.secPti = coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcg30');

	cgosIncome.cgInc.stcg.prctgAr.stcgApp = eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleofLandBuild.capgainonAssets') +
										coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSale') +
										coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRITransacSec48Dtl.nRItaxSTTNotPaid') +
										coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.saleOnOtherAssets.capgainonAssets') +
										coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.unUtilizedCapGain54.totAmtStcgUnderDtaa'));

	cgosIncome.cgInc.stcg.prctgAr.secPti=coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcgAr');
	cgosIncome.cgInc.stcg.prctg15.sec111a = eval(parseInt(sum) +
										 coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.nRITransacSec48Dtl.nRItaxSTTPaid'));
	cgosIncome.cgInc.stcg.prctg15.secPti = coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.ptiStcg15');

	document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.AmtStcgUnderDtaa8b'));
	document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa.AmtLtcgUnderDtaa10b'));
	document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncome')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.AmtStcgUnderDtaa8b'));
	document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncome')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa.AmtLtcgUnderDtaa10b'));

	document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.AmtStcgUnderDtaa8b'));
	document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden')[0].value=
		eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa.AmtLtcgUnderDtaa10b'));


}



function calcBulidingSellLTCG(){
	try{

		var table = document.getElementById('scheduleCGltcg1');
		var noOfRows = table.rows.length;


		var temp=parseInt('0',10);
		var temp1=parseInt('0',10);
		var capgainonAssetsTemp=parseInt('0',10);


		for (var i = 0; i <noOfRows/14; i++) {
			//calculate deduction
			var totalDedn = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].deductSec48totalDedn')[0];
			 if(eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].fullConsideration50C'))>0)
				{
					
			totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].deductSec48aquisitCost') +
	                coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].deductSec48improveCost') +
	                coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].deductSec48expOnTrans'));
				}
			    else
				{
			    	totalDedn.value=parseInt('0', 10);
				}

			//calcBalance
			   var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].balanceCG')[0];
			   balanceCG.value = eval(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].fullConsideration50C')[0].value) -
			                    coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].deductSec48totalDedn'));

			   //gain on asset
			   var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].capgainonAssets')[0];

			   var exemptionOrDednUs54 = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDednUs54')[0];
			   var j = i+1;
			   var tableId = 'ltcgDeduction1_ded'+j;



				var table2 = document.getElementById(tableId);

				var noOfRows2 = table2.rows.length;



				var temp=parseInt('0',10);

					for(var j = 0; j <noOfRows2-3; j++){
						temp = parseInt(temp) + eval(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDedn['+j+'].amount')[0].value),10));
					}

			   exemptionOrDednUs54.value = temp;

			   if(parseInt(balanceCG.value) > parseInt(0,10)){
			   capgainonAssets.value = zeroOrMore(eval(parseInt(balanceCG.value) -
			                    			parseInt(exemptionOrDednUs54.value)));
				} else {
				capgainonAssets.value = parseInt(balanceCG.value);
				}

			   capgainonAssetsTemp = parseInt(capgainonAssets.value) + parseInt(capgainonAssetsTemp);
		}

		var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild.capgainonAssets')[0];
		 capgainonAssets.value = eval(parseInt(capgainonAssetsTemp,10));


	}catch(e){
	   alert('error in calcBulidingSellLTCG=' + e);
   }
}

function addCGDeductionsLtcg1(tableId){
	var table = document.getElementById('scheduleCGltcg1');
	var noOfRows = table.rows.length;
	console.log("tableId"+tableId);
	var table2 = document.getElementById(tableId);
	var noOfRows2 = table2.rows.length;

	var temp=parseInt('0',10);

	var exemptionOrDednUs54=parseInt('0',10);

	for (var i = 0; i <noOfRows/14; i++) {

		for(var j = 0; j <noOfRows2-3/10; j++){
			temp = parseInt(temp) + eval(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild['+i+'].exemptionOrDedn['+j+'].amount')[0].value),10));
		}

return temp;
	}
}
function calcSlumpSaleLTCG(){
	   var netWorthOfUTDivn = document.getElementsByName('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSaleB')[0];
	   netWorthOfUTDivn.value = coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.fullConsiderationB')
	   							- coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.netWorthOfUTDivnB');

	   var exemptionOrDednUs54 =document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.exemptionOrDednUs54')[0];
	   exemptionOrDednUs54.value = coalesce(exemptionOrDednUs54.value);
	   
/*	   exemptionOrDednUs54.value = addCGDeductions('ltcgDeduction54ec54ee1');
*/
	   var longTCgains = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.capgainonAssets')[0];
	    if(parseInt(netWorthOfUTDivn.value) < 0){
	    	longTCgains.value = netWorthOfUTDivn.value;
	    }else{
	    	longTCgains.value = zeroOrMore(netWorthOfUTDivn.value - exemptionOrDednUs54.value);
	    }
}
/*function calcSlumpSaleLTCG(){
	//2c
	   var netWorthOfUTDivn = document.getElementsByName('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSaleB')[0];
	  //2a - 2b
	   netWorthOfUTDivn.value = coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.fullConsiderationB')
	   							- coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.netWorthOfUTDivnB');
//2e (2c-2d)

	   var exemptionOrDednUs54 =document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.capgainonAssets')[0];
		var exemptionOrDedn2d =document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.exemptionOrDednUs54')[0];



	    if(parseInt(netWorthOfUTDivn.value) < 0){
	    	exemptionOrDednUs54.value = netWorthOfUTDivn.value;
	    }else if (   parseInt(netWorthOfUTDivn.value) > 0  && parseInt(exemptionOrDedn2d.value) > parseInt(netWorthOfUTDivn.value) ){
	    	exemptionOrDednUs54.value = 0 ;
	    		    }
	    	    else{
	    	exemptionOrDednUs54.value = coalesceSetRet('scheduleCGFor4.shortTermCapGainFor4.capGainSlumpSale.cgSlumpSaleB')
 			- coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.exemptionOrDednUs54');
	    }

}*/



function calcPTILTCG(){
	   var ltcgUnderptiTotal = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.totAmtLtcgUnderPTI')[0];
	   ltcgUnderptiTotal.value = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg10') + coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg10OthrUs112A')+ coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg20');
	   
}

function calcBondSellLTCG(){
	//Calc deduction
    var totalDedn = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.deductSec48.totalDedn')[0];
   
	if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.fullConsideration')[0].value),10)>0)
	{
    
    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.deductSec48.aquisitCost') +
                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.deductSec48.improveCost') +
                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.deductSec48.expOnTrans'));
	}
    else
	{
    	totalDedn.value=parseInt('0', 10);
	}
    //calcBalance
    var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.fullConsideration')[0];
    balanceCG.value = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.fullConsideration');


    //gain on Assets
    var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.balanceCG')[0];
   
    /*exemptionOrDednUs54.value = addCGDeductions('ltcgDeduction54ec54ee2');
*/
	
    capgainonAssets.value = (eval(balanceCG.value -
                     			 parseInt(totalDedn.value)));
}

function calcListedSecuritiesSellLTCG(cgosIncome){

	var tab = document.getElementById('scheduleCGltcg3');
	var len = tab.tBodies.length;
	var sum = 0;
	for(var i=0;i<len;i++){

		//Calc deduction
	    var totalDedn = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].deductSec48.totalDedn')[0];
	 
		if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+i+'].fullConsideration')[0].value),10)>0)
		{
    
	    
	    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].deductSec48.aquisitCost') +
	                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].deductSec48.improveCost') +
	                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].deductSec48.expOnTrans'));

		}
	    else
		{
	    	totalDedn.value=parseInt('0', 10);
		}

	    //calcBalance
	   
	    var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].fullConsideration')[0];
	    balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].fullConsideration'));
	    //gain on Assets
	    var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable['+ i +'].balanceCG')[0];
	   
	  /*  exemptionOrDednUs54S.value = addCGDeductions('scheduleCGltcg3_ded1');
*/
	    capgainonAssets.value = eval(balanceCG.value - parseInt(totalDedn.value));
	   

	   var section = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable[' + i +  '].sectionCode')[0].value;
	    if(section=='22'){
	    	sum = parseInt(sum) + parseInt(capgainonAssets.value);
	    }
	}

	return sum;
}

/*function calcNRIProvisoSec48LTCG(){
	var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.BalanceCG')[0];
	var ltcgWithoutBenefit = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.ltcgWithoutBenefit');
	var exemptionOrDednUs54 = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.exemptionOrDednUs54')[0];
	exemptionOrDednUs54.value = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.exemptionOrDednUs54');

	exemptionOrDednUs54.value = addCGDeductions('ltcgDeduction54ec54ee4');

	if(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.ltcgWithoutBenefit') > parseInt(0, 10)){
		balanceCG.value = zeroOrMore(eval( ltcgWithoutBenefit - exemptionOrDednUs54.value));
	}else{
		balanceCG.value = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.ltcgWithoutBenefit');
	}
}
*/
function calcUnlistedSecuritiesSellLTCG(cgosIncome){
	//Calc deduction

	var tab = document.getElementById('stcg10pctTab');
	var len = tab.tBodies.length;
	var sum = 0;
	for(var i=0;i<len;i++){
	    var totalDedn = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].deductSec48.totalDedn')[0];
		if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115['+i+'].fullConsideration')[0].value),10)>0)
		{

	    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].deductSec48.aquisitCost') +
	                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].deductSec48.improveCost') +
	                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].deductSec48.expOnTrans'));
		}
	    else
		{
	    	totalDedn.value=parseInt('0', 10);
		}

	  //calcBalance
	    var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].balanceCG')[0];
	    balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].fullConsideration') -(totalDedn.value));

	    //gain on Assets
/*	   var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].capgainonAssets')[0];
*/		/*var exemptionOrDednUs54S = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].exemptionOrDednUs54S')[0];
		exemptionOrDednUs54S.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].exemptionOrDednUs54S'));*/
		//coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].exemptionOrDednUs54S');

		/*if(balanceCG.value > parseInt(0,10)){
	    capgainonAssets.value = zeroOrMore(eval(balanceCG.value -
	    							 parseInt(exemptionOrDednUs54S.value)));
		} else {
		capgainonAssets.value = balanceCG.value;
		}*/
	    sum = parseInt(sum, 10) + parseInt(balanceCG.value, 10);
	 var section = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115[' + i +  '].sectionCode')[0].value;
	    if(section=='21ciii'){
	    	cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = parseInt(balanceCG.value, 10);
	    }else if(section=='5AC1c'){
	    	cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = parseInt(balanceCG.value, 10);
	    }else if(section=='5AB1b'){
	    	cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = parseInt(balanceCG.value, 10);
	    }else if(section=='5ADiii'){
	    	cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = parseInt(balanceCG.value, 10);
	    }
	   }
	return sum;
}

function calcForexAssetLTCG(){

	if(parseInt(saleonSpecAsset) > parseInt(0, 10)){
		balonSpeciAsset.value = zeroOrMore(eval(parseInt(saleonSpecAsset) -
							   		 parseInt(dednSpecAssetus115)));
	}else{
		balonSpeciAsset.value = saleonSpecAsset;
	}

	var saleOtherSpecAsset = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRISaleofForeignAsset.saleOtherSpecAsset');

	if(parseInt(saleOtherSpecAsset) > parseInt(0, 10)){
		balOtherthanSpecAsset.value = zeroOrMore(eval(parseInt(saleOtherSpecAsset) -
							  		parseInt(coalesce(dednOtherSpecAssetus115),10)));
	}else{
		balOtherthanSpecAsset.value = saleOtherSpecAsset;
	}
}

function calcOthAssetLTCG(){
	//Calc deduction
	try
	{
    var totalDedn = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.totalDedn')[0];
    if(parseInt(coalesce(document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.fullConsideration')[0].value),10)>0)
	{

    totalDedn.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.aquisitCost') +
                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.improveCost') +
                           coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.expOnTrans'));
    
	}
    else
	{
    	var aquisitCost = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.aquisitCost')[0]; aquisitCost.value = coalesce(aquisitCost.value);
    	var improveCost = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.improveCost')[0]; improveCost.value = coalesce(improveCost.value);
    	var expOnTrans = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.expOnTrans')[0]; expOnTrans.value = coalesce(expOnTrans.value);

    	totalDedn.value=parseInt('0', 10);
	}


  //calcBalance
    var balanceCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.balanceCG')[0];
    balanceCG.value = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.deductSec48.fullConsideration') -
    					   totalDedn.value);

    //gain on Assets
    var capgainonAssets = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.capgainonAssets')[0];
    var exemptionOrDednUs54S = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.exemptionOrDednUs54S')[0];
    coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.exemptionOrDednUs54S');
    exemptionOrDednUs54S.value = addCGDeductions('scheduleCGltcg7');

    if(parseInt(balanceCG.value) > 0){
    capgainonAssets.value = zeroOrMore(eval(balanceCG.value -
    							 parseInt(coalesce(exemptionOrDednUs54S.value))));
    }else{
    	capgainonAssets.value = balanceCG.value;
    }
    }catch(e){
    	alert('error in calcForexAssetLTCG=' + e);
    }
}


function calculateLTCG(cgosIncome){

	calcBulidingSellLTCG();
	calcSlumpSaleLTCG();
	calcBondSellLTCG();
	var secSell = calcListedSecuritiesSellLTCG(cgosIncome);
	/*calcNRIProvisoSec48LTCG();*/
	var sum = calcUnlistedSecuritiesSellLTCG(cgosIncome);
	calcOthAssetLTCG();
	calcPTILTCG();

    var totalLTCG = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.totalLTCG')[0];
    document.getElementsByName('scheduleCGFor8.shortTermCapGainFor8.saleofEquityLtcg.ltcgCapGain')[0].value=coalesce(document.getElementsByName('scheduleCGFor8.shortTermCapGainFor8.saleofEquityLtcg.ltcgCapGain')[0].value);
    document.getElementsByName('scheduleCGFor5.shortTermCapGainFor5.saleofEquityLtcg.ltcgCapGain')[0].value=coalesce(document.getElementsByName('scheduleCGFor5.shortTermCapGainFor5.saleofEquityLtcg.ltcgCapGain')[0].value);
    /*  Total long term capital gain [B1e + B2e + B3c + B4c + B5d + B6 + B7c + B8 + B9e + B10 + B11-B12a] */

    totalLTCG.value = eval( coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild.capgainonAssets') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.capgainonAssets') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.balanceCG') +
			parseInt(secSell) +
			coalesceSetRet('scheduleCGFor5.shortTermCapGainFor5.saleofEquityLtcg.ltcgCapGain') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.BalanceCG') +
			parseInt(sum, 10) +
			coalesceSetRet('scheduleCGFor8.shortTermCapGainFor8.saleofEquityLtcg.ltcgCapGain') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.capgainonAssets') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.totAmtStcgUnderDtaa') +
			coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.totAmtLtcgUnderPTI') -
            coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa.totAmtLtcgUnderDtaa'));


	cgosIncome.cgInc.ltcg.prctg20.sec112 = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofLandBuild.capgainonAssets') +
												coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.capGainSlumpSale.capgainonAssets') +
												coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofBondsDebntr.balanceCG') +
												coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.nRIProvisoSec48.BalanceCG') +
												coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.totAmtStcgUnderDtaa') +
												coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.saleofAssetNA.capgainonAssets') - setOffWithDtaa('sec112'));



	cgosIncome.cgInc.ltcg.prctg10.secPti = eval(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg10'));

	console.log('cgosIncome.cgInc.ltcg.prctg10.sec112A '+cgosIncome.cgInc.ltcg.prctg10.sec112A);

	cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP =
		coalesceSetRet('scheduleCGFor8.shortTermCapGainFor8.saleofEquityLtcg.ltcgCapGain') - setOffWithDtaa('5ADiiiP');


	cgosIncome.cgInc.ltcg.prctg10.secProviso = eval(parseInt(secSell) - setOffWithDtaa('secProviso'));
	cgosIncome.cgInc.ltcg.prctg10.sec112A =
		coalesceSetRet('scheduleCGFor5.shortTermCapGainFor5.saleofEquityLtcg.ltcgCapGain') - setOffWithDtaa('112A');
	
	cgosIncome.cgInc.ltcg.prctg10.secPti112A = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg10OthrUs112A');
	
	cgosIncome.cgInc.ltcg.prctg20.secPti = coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.stcgUnderDtaa.ptiLtcg20') - setOffWithDtaa('PTI_LTCG20P');

	cgosIncome.cgInc.ltcg.prctg10.sec115E_b = 0;
}

function doCGSetOff(cgosIncome){
	populateCGTab(cgosIncome);
	setOffPctg30Loss(cgosIncome);
	setOffPctgArLoss(cgosIncome);
	  setOffPctgSDTAALoss(cgosIncome);
	setOffPctg20Loss(cgosIncome);
	setOffPctg15Loss(cgosIncome);
	setOffPctg10Loss(cgosIncome);
	  setOffPctgLDTAALoss(cgosIncome);

}

//To setOfff STCG With A9
function setOffSTCGWithA9(cgosIncome) {

	var sec111a= parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a,10);
	var sec115ad_1_b_ii = parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii,10);
	var secPti = parseInt(cgosIncome.cgInc.stcg.prctg15.secPti,10);

	var tab = document.getElementById('scheduleStcgDtaa');
	var noOfRows = tab.rows.length - 2;

	var sectionValue;
	var amount;
	var residentialSatus = document.getElementsByName('partAGEN1.filingStatus.residentialStatus')[0].value;

	for(var i=0; i<noOfRows; i++){
		sectionValue = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa['+i+'].itemIncluded')[0].value;
		amount = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa['+i+'].amount')[0].value;
		var taxResidCertFlag=document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa['+i+'].taxResidCertFlag')[0].value;
		if(residentialSatus=='NRI')
		{ 
			if(taxResidCertFlag=='Y')
			{

		if(sectionValue=='A3e_111A' || sectionValue=='A4a' ){
			sec111a -= amount;
		}
		else if(sectionValue=='A3e_115AD'){
			sec115ad_1_b_ii -= amount;
		}
		else if(sectionValue=='A8a'){
			secPti -= amount;
		}
		else if(sectionValue=='A5e'){

			cgosIncome.cgInc.stcg.prctg30.sec115AD  -= amount;
		}

		else if(sectionValue=='A8b'){
			cgosIncome.cgInc.stcg.prctg30.secPti  -= amount;
		}
		else if(sectionValue=='A1e'||sectionValue=='A4b'||sectionValue=='A6g'||sectionValue=='A7' || sectionValue=='A2c'){

			cgosIncome.cgInc.stcg.prctgAr.stcgApp  -= amount;
		}
		else if(sectionValue == 'A8c'){

		cgosIncome.cgInc.stcg.prctgAr.secPti -= amount;
		}

	}
		}
		else if(residentialSatus!='NRI')
		{
			if(sectionValue=='A3e_111A' || sectionValue=='A4a' ){
				sec111a -= amount;
			}
			else if(sectionValue=='A3e_115AD'){
				sec115ad_1_b_ii -= amount;
			}
			else if(sectionValue=='A8a'){
				secPti -= amount;
			}
			else if(sectionValue=='A5e'){

				cgosIncome.cgInc.stcg.prctg30.sec115AD  -= amount;
			}

			else if(sectionValue=='A8b'){
				cgosIncome.cgInc.stcg.prctg30.secPti  -= amount;
			}
			else if(sectionValue=='A1e'||sectionValue=='A4b'||sectionValue=='A6g'||sectionValue=='A7' || sectionValue=='A2c'){

				cgosIncome.cgInc.stcg.prctgAr.stcgApp  -= amount;
			}
			else if(sectionValue == 'A8c'){

			cgosIncome.cgInc.stcg.prctgAr.secPti -= amount;
			}

		}
			}

	cgosIncome.cgInc.stcg.prctg15.sec111a = sec111a;
	cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii=sec115ad_1_b_ii;
	cgosIncome.cgInc.stcg.prctg15.secPti = secPti;

}

//To setOff LTCG With B10
/*function setOffLTCGWithB10(cgosIncome) {

	var tab = document.getElementById('scheduleStcgDtaa');
	var rowCount = tab.rows.length - 2;
	var sectionValue;
	var amount;
	for(var i=0; i<rowCount; i++){
		sectionValue = document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa['+i+'].itemIncluded')[0].value;
		amount = parseInt(document.getElementsByName('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa['+i+'].amount')[0].value,10);
		if(sectionValue == 'B4e'){
			cgosIncome.cgInc.ltcg.prctg10.secProviso -= amount;
		}else if(sectionValue == 'B5'){
			cgosIncome.cgInc.ltcg.prctg10.sec112A -= amount;
		}

		 else if(sectionValue == 'B7c112(1)(c)'){
			cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 -= amount;
		} else if(sectionValue == 'B7c115AC'){
			cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 -= amount;
		} else if(sectionValue == 'B7c115AD'){
			cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 -= amount;
		} else if(sectionValue == 'B7c115AB1b'){
			cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B-= amount;

		} else if(sectionValue == 'B8'){
			cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP -= amount;
		}
		else if(sectionValue == 'B11b'){
			cgosIncome.cgInc.ltcg.prctg20.secPti -= amount;
		}
		else if(sectionValue == 'B1e' || sectionValue == 'B2e' || sectionValue == 'B3c' || sectionValue == 'B6' || sectionValue == 'B9e' || sectionValue == 'B10'){
			cgosIncome.cgInc.ltcg.prctg20.sec112 -= amount;
		}else if(sectionValue == 'B11a'){
			cgosIncome.cgInc.ltcg.prctg10.secPti -= amount;
		}

	}

}*/
//To populate CG Tab values
function populateCGTab(cgosIncome){

	setOffSTCGWithA9(cgosIncome);
	//setOffLTCGWithB10(cgosIncome);
	var stcg = cgosIncome.cgInc.stcg;
	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
							 parseInt(prctg15.sec115ad_1_b_ii,10)+
							 parseInt(prctg15.secPti,10));

	var neg15 = 0;
	if(zeroOrLess(prctg15.sec111a) < 0){
		neg15 = parseInt(neg15) + parseInt(prctg15.sec111a);
		prctg15.sec111a = 0;
	}
	if(zeroOrLess(prctg15.sec115ad_1_b_ii) < 0){
		neg15 = parseInt(neg15) + parseInt(prctg15.sec115ad_1_b_ii);
		prctg15.sec115ad_1_b_ii = 0;
	}
	if(zeroOrLess(prctg15.secPti) < 0){
		neg15 = parseInt(neg15) + parseInt(prctg15.secPti);
		prctg15.secPti = 0;
	}

	if(neg15 < 0){
		var setOff = setOffAgainst115ad_1_b_ii(neg15, cgosIncome);
		neg15 = parseInt(neg15) + parseInt(setOff);
		setOff = setOffAgainst15Pti(neg15, cgosIncome);
		neg15 = parseInt(neg15) + parseInt(setOff);
		setOff = setOffAgainst111a(neg15, cgosIncome);
		neg15 = parseInt(neg15) + parseInt(setOff);
		prctg15.secPti = parseInt(neg15) + parseInt(prctg15.secPti);
	}


	var prctg30 = cgosIncome.cgInc.stcg.prctg30;
	var prctgAr = cgosIncome.cgInc.stcg.prctgAr;

	var prctg30Sum = eval( parseInt(prctg30.sec115AD,10) +
			 parseInt(prctg30.secPti,10));
	var prctgArSum = eval( parseInt(prctgAr.stcgApp,10) +
			 parseInt(prctgAr.secPti,10));

	setProfitLoss(prctg15Sum, 'scheduleCGPost45.currYrLosses.inLossSetOff.stclSetoff15Per', 'scheduleCGPost45.currYrLosses.inStcg15Per.currYearIncome');
	setProfitLoss(prctg30Sum, 'scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoff30Per', 'scheduleCGPost45.currYrLosses.inStcg30Per.currYearIncome');
	setProfitLoss(prctgArSum, 'scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoffAppRate', 'scheduleCGPost45.currYrLosses.inStcgAppRate.currYearIncome');



	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	prctg10.sec112_1_c_2 = prctg10.sec112_1_c_2 - setOffWithDtaa('sec112_1_c_2');
	prctg10.sec115AC_1 = prctg10.sec115AC_1 -  setOffWithDtaa('sec115AC_1');
	prctg10.sec115AD_3 = prctg10.sec115AD_3 - setOffWithDtaa('sec115AD_3');
	prctg10.sec115ADiiiP = prctg10.sec115ADiiiP - setOffWithDtaa('sec115ADiiiP');
	prctg10.sec115_AB_1_B = prctg10.sec115_AB_1_B - setOffWithDtaa('sec115_AB_1_B');
	prctg10.secPti = prctg10.secPti - setOffWithDtaa('PTI_LTCG10P');
	prctg10.secPti112A = prctg10.secPti112A - setOffWithDtaa('PTI_LTCG10P112A');
 	prctg10.sec112A = prctg10.sec112A - setOffWithDtaa('sec112A');


	var prctg10Sum = eval( parseInt(prctg10.secProviso,10) +
							 parseInt(prctg10.sec112_1_c_2,10) +
							 parseInt(prctg10.sec115AC_1,10) +
							 parseInt(prctg10.sec115_AB_1_B,10) +
							 parseInt(prctg10.sec115AD_3,10) +
							 parseInt(prctg10.sec115ADiiiP,10) +
                             parseInt(prctg10.sec112A,10) +
							 parseInt(prctg10.secPti112A,10)+
							 parseInt(prctg10.secPti,10));


	var neg10 = 0;

	if(zeroOrLess(prctg10.sec112_1_c_2) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec112_1_c_2);
		prctg10.sec112_1_c_2 = 0;
	}
	if(zeroOrLess(prctg10.sec115_AB_1_B) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec115_AB_1_B);
		prctg10.sec115_AB_1_B = 0;
	}
	if(zeroOrLess(prctg10.sec115AC_1) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec115AC_1);
		prctg10.sec115AC_1 = 0;
	}
	if(zeroOrLess(prctg10.sec115AD_3) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec115AD_3);
		prctg10.sec115AD_3 = 0;
	}
	if(zeroOrLess(prctg10.secProviso) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.secProviso);
		prctg10.secProviso = 0;
	}
	if(zeroOrLess(prctg10.sec115ADiiiP) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec115ADiiiP);
		prctg10.sec115ADiiiP = 0;
	}
	if(zeroOrLess(prctg10.sec112A) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.sec112A);
		prctg10.sec112A = 0;
	}
	if(zeroOrLess(prctg10.secPti112A) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.secPti112A);
		prctg10.secPti112A = 0;
	}

	if(zeroOrLess(prctg10.secPti) < 0){
		neg10 = parseInt(neg10) + parseInt(prctg10.secPti);
		prctg10.secPti = 0;
	}






	if(neg10 < 0){
		var setOff = setOffAgainst112_1_c_2(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);



		setOff = setOffAgainst115_AB_1_B(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);



		setOff = setOffAgainst115AC_1(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);



		setOff = setOffAgainst115AD_3(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);

		setOff = setOffAgainstsec115ADiiiP(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);

		setOff = setOffAgainst10Pti(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);

		setOff = setOffAgainstsecProviso(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);

		setOff = setOffAgainst10Pti112A(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);

		
		setOff = setOffAgainstsec112A(neg10, cgosIncome);
		neg10 = parseInt(neg10) + parseInt(setOff);




		prctg10.sec112_1_c_2 = parseInt(neg10) + parseInt(prctg10.sec112_1_c_2);


	}


	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = eval( parseInt(prctg20.sec112,10)+parseInt(prctg20.secPti,10));



	var neg20 = 0;
	if(zeroOrLess(prctg20.sec112) < 0){
		neg20 = parseInt(neg20) + parseInt(prctg20.sec112);
		prctg20.sec112 = 0;
	}


	if(zeroOrLess(prctg20.secPti) < 0){
		neg20 = parseInt(neg20) + parseInt(prctg20.secPti);
		prctg20.secPti = 0;
	}

	if(neg20 < 0){
		var setOff = setOffAgainst112(neg20, cgosIncome);
		neg20 = parseInt(neg20) + parseInt(setOff);
		setOff = setOffAgainst20Pti(neg20, cgosIncome);
		neg20 = parseInt(neg20) + parseInt(setOff);
		prctg20.sec112 = parseInt(neg20) + parseInt(prctg20.sec112 );
	}



	setProfitLoss(prctg10Sum, 'scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOff10Per', 'scheduleCGPost45.currYrLosses.inLtcg10Per.currYearIncome');
	setProfitLoss(prctg20Sum, 'scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOff20Per', 'scheduleCGPost45.currYrLosses.inLtcg20Per.currYearIncome');
	setProfitLoss(coalesceSetRet('scheduleCGPost45.shortTermCapGainPost45.stcgUnderDtaa.AmtStcgUnderDtaa8b'), 'scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoffDtaaRate', 'scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncome');
	setProfitLoss(coalesceSetRet('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa.AmtLtcgUnderDtaa10b'), 'scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOffDtaaRate', 'scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncome');



}



function setOffPctg30Loss(cgosIncome){
	var inStcgAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoff30Per')[0];
	var inStcg15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg15Per.stclSetoff30Per')[0];
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoff30Per')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoff30Per')[0];
	var inStcgDTAARate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoff30Per')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoff30Per')[0];

	var prctg30 = cgosIncome.cgInc.stcg.prctg30;
	var prctg30Sum = eval( parseInt(prctg30.sec115AD,10) +
							 parseInt(prctg30.secPti,10));


	var amtSetOff = 0;

	amtSetOff = setOffAgainstAr(parseInt(prctg30Sum, 10), cgosIncome);
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
			parseInt(prctg30Sum, 10));
	inStcgAppRate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst20(parseInt(prctg30Sum, 10), cgosIncome);
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
			  parseInt(prctg30Sum, 10));
	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst15(parseInt(prctg30Sum, 10), cgosIncome);
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
			  parseInt(prctg30Sum, 10));
	inStcg15Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst10(parseInt(prctg30Sum, 10), cgosIncome);
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
			  parseInt(prctg30Sum, 10));
	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));
	/*2019Changes*/


	amtSetOff = setOffAgainstStcgDr(parseInt(prctg30Sum, 10));
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
			  parseInt(prctg30Sum, 10));
	inStcgDTAARate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstLtcgDr(parseInt(prctg30Sum, 10));
	prctg30Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg30Sum, 10));
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));


}

function setOffPctgArLoss(cgosIncome){
	var inStcg30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg30Per.stclSetoffAppRate')[0];
	var inStcg15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg15Per.StclSetoffAppRate')[0];
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoffAppRate')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoffAppRate')[0];
	var inStcgDTAARate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoffAppRate')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoffAppRate')[0];
	var prctgAr = cgosIncome.cgInc.stcg.prctgAr;
	var prctgArSum = eval( parseInt(prctgAr.stcgApp,10) +
							 parseInt(prctgAr.secPti,10));


	var amtSetOff = 0;

	amtSetOff = setOffAgainst30(parseInt(prctgArSum, 10), cgosIncome);
	prctgArSum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inStcg30Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst20(parseInt(prctgArSum, 10), cgosIncome);
	prctgArSum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst15(parseInt(prctgArSum, 10), cgosIncome);
	prctgArSum= eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inStcg15Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst10(parseInt(prctgArSum, 10), cgosIncome);
	prctgArSum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));
	amtSetOff = setOffAgainstStcgDr(parseInt(prctgArSum, 10));
	prctgArSum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inStcgDTAARate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstLtcgDr(parseInt(prctgArSum, 10));
	prctgArSum= eval( parseInt(amtSetOff, 10) +
										  parseInt(prctgArSum, 10));
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));

}
//To setOff Percentage STCG DTAA rates Loss
function setOffPctgSDTAALoss(cgosIncome){
	var inStcg15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg15Per.StclSetoffDtaaRate')[0];
	var inStcg30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg30Per.StclSetoffDtaaRate')[0];
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.stclSetoffDtaaRate')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoffDtaaRate')[0];
	var inStcgAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoffDtaaRate')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoffDtaaRate')[0];
	var inStcgDTAARatesVal = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden')[0];

	var amtSetOff = 0;

	amtSetOff = setOffAgainst30(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) + parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inStcg30Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstAr(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) + parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inStcgAppRate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst20(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value= eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst15(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inStcg15Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst10(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstLtcgDr(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden'), 10));
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));
}


//To setOff Percentage LTCG DTAA rates Loss
function setOffPctgLDTAALoss(cgosIncome){
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.ltclSetOffDtaaRate')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOffDtaaRate')[0];
	var inStcgDTAARatesVal = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden')[0];

	var amtSetOff = 0;

	amtSetOff = setOffAgainst20(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden'), 10));
	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst10(parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden'), 10), cgosIncome);
	inStcgDTAARatesVal.value = eval( parseInt(amtSetOff, 10) +
										  parseInt(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden'), 10));
	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));
}


function setOffPctg15Loss(cgosIncome){
	var inStcg30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg30Per.stclSetoff15Per')[0];
	var inStcgAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoff15Per')[0];
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoff15Per')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoff15Per')[0];
	var inStcgDTAARate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoff15Per')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoff15Per')[0];

	var amtSetOff = 0;
	var totalSetOff = 0;

	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
			 parseInt(prctg15.sec115ad_1_b_ii,10)+ parseInt(prctg15.secPti,10));



	amtSetOff = setOffAgainst30(parseInt(prctg15Sum, 10), cgosIncome);
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
					   parseInt(prctg15Sum, 10));
	totalSetOff = amtSetOff;
	inStcg30Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstAr(parseInt(prctg15Sum, 10), cgosIncome);
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg15Sum, 10));
	totalSetOff = parseInt(totalSetOff) + parseInt(amtSetOff);
	inStcgAppRate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst20(parseInt(prctg15Sum, 10), cgosIncome);
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg15Sum, 10));
	totalSetOff = parseInt(totalSetOff) + parseInt(amtSetOff);
	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainst10(parseInt(prctg15Sum, 10), cgosIncome);
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg15Sum, 10));
	totalSetOff = parseInt(totalSetOff) + parseInt(amtSetOff);
	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));


	if(parseInt(totalSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10)) > parseInt(totalSetOff, 10)){
		cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) +
												parseInt(totalSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(totalSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) < 0){
		amtSetOff = parseInt(totalSetOff, 10) +
					parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) ;
		cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = 0;
	}
	if(parseInt(totalSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10)) > parseInt(totalSetOff, 10)){
		cgosIncome.cgInc.stcg.prctg15.secPti = parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) +
												parseInt(totalSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(totalSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) < 0){
		amtSetOff = parseInt(totalSetOff, 10) +
			parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) ;
		cgosIncome.cgInc.stcg.prctg15.secPti = 0;
	}

	if(parseInt(totalSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10)) > parseInt(totalSetOff, 10)){
		cgosIncome.cgInc.stcg.prctg15.sec111a = parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) +
												parseInt(totalSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(totalSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) < 0){
		amtSetOff = parseInt(totalSetOff, 10) +
			parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) ;
		cgosIncome.cgInc.stcg.prctg15.sec111a = 0;
	}


	amtSetOff = setOffAgainstStcgDr(parseInt(prctg15Sum, 10));
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg15Sum, 10));
	totalSetOff = parseInt(totalSetOff) + parseInt(amtSetOff);
	inStcgDTAARate.value = Math.abs(parseInt(amtSetOff, 10));

	amtSetOff = setOffAgainstLtcgDr(prctg15Sum, 10);
	prctg15Sum = eval( parseInt(amtSetOff, 10) +
										  parseInt(prctg15Sum, 10));
	totalSetOff = parseInt(totalSetOff) + parseInt(amtSetOff);
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));

}

function setOffPctg20Loss(cgosIncome){
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOff20Per')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.LtclSetOff20Per')[0];

	var amtSetOff = 0;

	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = eval( parseInt(prctg20.sec112,10) +
			parseInt(prctg20.secPti,10));

	amtSetOff = setOffAgainst10(parseInt(prctg20Sum, 10), cgosIncome);

	inLtcg10Per.value = Math.abs(parseInt(amtSetOff, 10));

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg20.secPti = parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) ;
		cgosIncome.cgInc.ltcg.prctg20.secPti = 0;
	}

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg20.sec112 = parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
			parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) ;
		cgosIncome.cgInc.ltcg.prctg20.sec112 = 0;
	}


	prctg20Sum = eval( parseInt(prctg20.sec112,10) +
			 			 parseInt(prctg20.secPti,10));
	amtSetOff = setOffAgainstLtcgDr(parseInt(prctg20Sum, 10));
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));


}

function setOffPctg10Loss(cgosIncome){
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.LtclSetOff10Per')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.LtclSetOff10Per')[0];

	var amtSetOff = 0;


	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = eval( parseInt(prctg10.secProviso,10) +
							 parseInt(prctg10.sec112_1_c_2,10) +
							 parseInt(prctg10.sec115AC_1,10) +
							 parseInt(prctg10.sec115_AB_1_B,10) +
							 parseInt(prctg10.sec115AD_3,10) +
							 parseInt(prctg10.sec115ADiiiP,10) +
							 parseInt(prctg10.sec112A,10)+
							 parseInt(prctg10.secPti112A,10) +
							 parseInt(prctg10.secPti,10));


	amtSetOff = setOffAgainst20(parseInt(prctg10Sum, 10), cgosIncome);

	inLtcg20Per.value = Math.abs(parseInt(amtSetOff, 10));



	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = 0;
	}

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = 0;
	}

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = 0;
	}


	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = 0;
	}

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP = 0;
	}
	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.secPti = parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.secPti = 0;
	}

	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.secProviso = parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.secProviso = 0;
	}


	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.sec112A = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.sec112A = 0;
	}


	if(parseInt(amtSetOff, 10) >= 0 && Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10)) > parseInt(amtSetOff, 10)){
		cgosIncome.cgInc.ltcg.prctg10.secPti112A = parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) +
												parseInt(amtSetOff, 10);
		amtSetOff = 0;
	}else if(parseInt(amtSetOff, 10) >= 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) < 0){
		amtSetOff = parseInt(amtSetOff, 10) +
					parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) ;
		cgosIncome.cgInc.ltcg.prctg10.secPti112A = 0;
	}

	prctg10Sum = eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10));

	amtSetOff = setOffAgainstLtcgDr(parseInt(prctg10Sum, 10));
	inLtcgDTAARates.value = Math.abs(parseInt(amtSetOff, 10));

	console.log("parseInt(prctg10.secProviso,10) ::: "+parseInt(prctg10.secProviso,10));
	console.log("prctg10Sumsssssssssssssssss1 ::: "+ parseInt(prctg10.sec112_1_c_2,10));
	console.log("prctg10Sumsssssssssssssssss2 ::: "+parseInt(prctg10.sec115AC_1,10));
	console.log("prctg10Sumsssssssssssssssss3 ::: "+parseInt(prctg10.sec115_AB_1_B,10));
	console.log("prctg10Sumsssssssssssssssss4 ::: "+ parseInt(prctg10.sec115AD_3,10));
	console.log("prctg10Sumsssssssssssssssss5 ::: "+parseInt(prctg10.sec115ADiiiP,10));
	console.log("prctg10Sumsssssssssssssssss7 ::: "+ parseInt(prctg10.sec112A,10));
	console.log("prctg10Sumsssssssssssssssss6 ::: "+ parseInt(prctg10.secPti112A,10));
	console.log("prctg10Sumsssssssssssssssss8 ::: "+parseInt(prctg10.secPti,10));

	console.log('prctg10Sumprctg10Sumprctg10Sum '+prctg10Sum);

	calcCYCgRemaining(cgosIncome);
	calcTotalSetOffs();
	calcLossRemaining(cgosIncome);

}
/*	2019Changes */
/*Current year? capital gains remaining after set off (7= 1-2-3-4-5-6)*/

function calcCYCgRemaining(cgosIncome){
	var inStcg15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg15Per.CurrYrLosSetOff')[0];
	var inStcg30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcg30Per.currYrLosSetOff')[0];
	var inStcgAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgAppRate.currYrLosSetOff')[0];
	var inLtcg10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg10Per.currYrLosSetOff')[0];
	var inLtcg20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcg20Per.CurrYrLosSetOff')[0];
	var inStcgDTAARate = document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYrLosSetOff')[0];
	var inLtcgDTAARates = document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.CurrYrLosSetOff')[0];

	if(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden')>0){
		inStcgDTAARate.value=coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden');
	}else{
		inStcgDTAARate.value=parseInt('0');
	}
	if(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden')>0){
		inLtcgDTAARates.value=coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden');
	}else{
		inLtcgDTAARates.value=parseInt('0');
	}


	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
							parseInt(prctg15.sec115ad_1_b_ii,10)+
								parseInt(prctg15.secPti,10));

	inStcg15Per.value = zeroOrMore(prctg15Sum);
	var prctg30 = cgosIncome.cgInc.stcg.prctg30;
	var prctg30Sum = eval( parseInt(prctg30.sec115AD,10) +
							 parseInt(prctg30.secPti,10));

	inStcg30Per.value = zeroOrMore(prctg30Sum);

	var prctgAr = cgosIncome.cgInc.stcg.prctgAr;
	var prctgArSum = eval( parseInt(prctgAr.stcgApp,10) +
							 parseInt(prctgAr.secPti,10));

	inStcgAppRate.value = zeroOrMore(prctgArSum);



	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;

	var prctg10Sum = eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
            parseInt(prctg10.sec112A,10) +
            parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10));

	console.log("prctg10Sumsssssssssssssssss ::: "+prctg10Sum);
	console.log("parseInt(prctg10.secProviso,10) ::: "+parseInt(prctg10.secProviso,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+ parseInt(prctg10.sec112_1_c_2,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+parseInt(prctg10.sec115AC_1,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+parseInt(prctg10.sec115_AB_1_B,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+ parseInt(prctg10.sec115AD_3,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+parseInt(prctg10.sec115ADiiiP,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+ parseInt(prctg10.sec115E_b,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+ parseInt(prctg10.sec112A,10));
	console.log("prctg10Sumsssssssssssssssss ::: "+parseInt(prctg10.secPti,10));


	console.log("asdsadsssssssssssss ::: "+coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOffDtaaRate'));

	inLtcg10Per.value = zeroOrMore(prctg10Sum-coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOffDtaaRate'));

	console.log("inLtcg10Per.valuessssssssssss ::: "+inLtcg10Per.value);

	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = eval( parseInt(prctg20.sec112,10) +
							parseInt(prctg20.secPti,10));

	inLtcg20Per.value = zeroOrMore(prctg20Sum-coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.ltclSetOffDtaaRate'));

}
/*	2019Changes */
/*Total loss set off (ii + iii + iv + v + vi + vii + viii)*/

function calcTotalSetOffs(){
	var stclSetoff15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoff15Per')[0];
	var stclSetoff30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoff30Per')[0];
	var stclSetoffAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoffAppRate')[0];
	var ltclSetOff10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOff10Per')[0];
	var ltclSetOff20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOff20Per')[0];
	var stclSetoffDtaaRate = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoffDtaaRate')[0];
	var ltclSetoffDtaaRate = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOffDtaaRate')[0];

	ltclSetOff20Per.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOff20Per') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.LtclSetOff20Per'));

	ltclSetOff10Per.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.LtclSetOff10Per') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.LtclSetOff10Per'));


	stclSetoffAppRate.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg15Per.StclSetoffAppRate') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg30Per.stclSetoffAppRate') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoffAppRate') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoffAppRate') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoffAppRate') +
			 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoffAppRate'));


	stclSetoff30Per.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg15Per.stclSetoff30Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoff30Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoff30Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoff30Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoff30Per')+
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoff30Per'));




	stclSetoff15Per.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg30Per.stclSetoff15Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoff15Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoff15Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.StclSetoff15Per') +
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgDTAARate.stclSetoff15Per')+
				 coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoff15Per'));

	stclSetoffDtaaRate.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg15Per.StclSetoffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.stclSetoffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.stclSetoffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inStcg30Per.StclSetoffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inStcgAppRate.stclSetoffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcgDTAARates.StclSetoffDtaaRate'));

	ltclSetoffDtaaRate.value = eval(coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg10Per.ltclSetOffDtaaRate') +
			coalesceSetRet('scheduleCGPost45.currYrLosses.inLtcg20Per.ltclSetOffDtaaRate'));


}

/*	2019Changes */

/*calculating for the field Loss remaining after set off (i â€“ vii)*/
/* i is Loss to be set off (Fill this row if figure computed is negative)
 vii is Total loss set off (ii + iii + iv + v + vi)*/


function calcLossRemaining(cgosIncome){
	var stclSetoff15Per = document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.stclSetoff15Per')[0];
	var stclSetoff30Per = document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.stclSetoff30Per')[0];
	var stclSetoffAppRate = document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.stclSetoffAppRate')[0];
	var ltclSetOff10Per = document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.ltclSetOff10Per')[0];
	var ltclSetOff20Per = document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.ltclSetOff20Per')[0];
	var stclSetoffDtaaRate= document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.stclSetoffDtaaRate')[0];
	var ltclSetOffDtaaRate= document.getElementsByName('scheduleCGPost45.currYrLosses.lossRemainSetOff.ltclSetOffDtaaRate')[0];

	var stclSetoff15PerLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.stclSetoff15Per')[0];
	var stclSetoff30PerLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoff30Per')[0];
	var stclSetoffAppRateLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoffAppRate')[0];
	var ltclSetoff10PerLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOff10Per')[0];
	var ltclSetoff20PerLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOff20Per')[0];
	var stclSetoffDtaaRateLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.StclSetoffDtaaRate')[0];
	var ltclSetoffDtaaRateLoss = document.getElementsByName('scheduleCGPost45.currYrLosses.inLossSetOff.LtclSetOffDtaaRate')[0];


	var stclSetoff15PerTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoff15Per')[0];
	var stclSetoff30PerTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoff30Per')[0];
	var stclSetoffAppRateTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoffAppRate')[0];
	var ltclSetOff10PerTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOff10Per')[0];
	var ltclSetOff20PerTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOff20Per')[0];
	var stclSetoffDtaaRateTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.stclSetoffDtaaRate')[0];
	var ltclSetoffDtaaRateTot = document.getElementsByName('scheduleCGPost45.currYrLosses.totLossSetOff.ltclSetOffDtaaRate')[0];



	stclSetoff15Per.value = zeroOrMore(parseInt(stclSetoff15PerLoss.value,10)-parseInt(stclSetoff15PerTot.value,10));

	stclSetoff30Per.value = zeroOrMore(parseInt(stclSetoff30PerLoss.value,10)-parseInt(stclSetoff30PerTot.value,10));

	stclSetoffAppRate.value = zeroOrMore(parseInt(stclSetoffAppRateLoss.value,10)-parseInt(stclSetoffAppRateTot.value,10));


	ltclSetOff10Per.value = zeroOrMore(parseInt(ltclSetoff10PerLoss.value,10)-parseInt(ltclSetOff10PerTot.value,10));

	ltclSetOff20Per.value = zeroOrMore(parseInt(ltclSetoff20PerLoss.value,10)-parseInt(ltclSetOff20PerTot.value,10));
	stclSetoffDtaaRate.value = zeroOrMore(parseInt(stclSetoffDtaaRateLoss.value,10)-parseInt(stclSetoffDtaaRateTot.value,10));

	ltclSetOffDtaaRate.value = zeroOrMore(parseInt(ltclSetoffDtaaRateLoss.value,10)-parseInt(ltclSetoffDtaaRateTot.value,10));

}
//To setOff Against applicable rate

function setOffAgainstAr(value, cgosIncome){
	var amtSetOffstcgApp = 0;
	var amtSetOffArPti = 0;
	if(value<0){

		amtSetOffstcgApp = setOffAgainststcgApp(value, cgosIncome);
		amtSetOffArPti = setOffAgainstArPti(value + amtSetOffstcgApp, cgosIncome);

	}

	return parseInt(amtSetOffstcgApp, 10) + parseInt(amtSetOffArPti, 10);

}

//To setOff Against percent 30

function setOffAgainst30(value, cgosIncome){
	try{
		var amtSetOff115AD = 0;
		var amtSetOffPti = 0;
		if(value<0){

			amtSetOff115AD = setOffAgainst115AD(value, cgosIncome);
			amtSetOffPti = setOffAgainst30PTI(value + amtSetOff115AD, cgosIncome);

		}
		return parseInt(amtSetOff115AD, 10) + parseInt(amtSetOffPti, 10);
		}catch(e){
			alert(e.stack);
		}

}

//To setOff Against percent 15

function setOffAgainst15(value, cgosIncome){

	var amtSetOff115ad_1_b_ii = 0;
	var amtSetOff15Pti = 0;
	var amtSetOff111a = 0;
	var amtSetOff = 0;

	if(value<0){


		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst115ad_1_b_ii(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst15Pti(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst111a(value + amtSetOff, cgosIncome), 10));



	}
	return parseInt(amtSetOff, 10);



}

//To setOff Against percent 20

function setOffAgainst20(value, cgosIncome){
	var amtSetOff112 = 0;
	var amtSetOff115ea = 0;
	var amtSetOff20Pti = 0;
	var amtSetOff = 0;

	if(value<0){

		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst115Ea(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst20Pti(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst112(value + amtSetOff, cgosIncome), 10));


	}
	return parseInt(amtSetOff, 10);


}

//To setOff Against percent 10

function setOffAgainst10(value, cgosIncome){
	var amtSetOff = 0;
	if(value < 0){
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst112_1_c_2(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst115_AB_1_B(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst115AC_1(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst115AD_3(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainstsec115ADiiiP(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst10Pti(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainstsecProviso(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainst10Pti112A(value + amtSetOff, cgosIncome), 10));
		amtSetOff = eval(parseInt(amtSetOff, 10) + parseInt(setOffAgainstsec112A(value + amtSetOff, cgosIncome), 10));

	}
	return amtSetOff;
}

//To setOff Against section 115AD
function setOffAgainst115AD(value, cgosIncome){


	var prctg30 = cgosIncome.cgInc.stcg.prctg30;
	var prctg30Sum = eval( parseInt(prctg30.sec115AD,10) +
							 parseInt(prctg30.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctg30.sec115AD, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctg30.sec115AD, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctg30.sec115AD = eval( parseInt(cgosIncome.cgInc.stcg.prctg30.sec115AD, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg30.sec115AD, 10));
			cgosIncome.cgInc.stcg.prctg30.sec115AD = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg30Sum)){
			cgosIncome.cgInc.stcg.prctg30.sec115AD = parseInt(cgosIncome.cgInc.stcg.prctg30.sec115AD) + parseInt(amtSetOff) - parseInt(prctg30Sum);
			amtSetOff = zeroOrMore(parseInt(prctg30Sum));
		}
	}

	return amtSetOff;
}

//To setOff Against section Pti112A
function setOffAgainst10Pti112A(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115ACA_1,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));
	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.secPti112A = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A, 10));
			cgosIncome.cgInc.ltcg.prctg10.secPti112A = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.secPti112A = parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti112A) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}
	return amtSetOff;
}



//To setOff Against section PTI
function setOffAgainst30PTI(value, cgosIncome){

	try{


	var prctg30 = cgosIncome.cgInc.stcg.prctg30;
	var prctg30Sum = eval( parseInt(prctg30.sec115AD,10) +
							 parseInt(prctg30.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctg30.secPti, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctg30.secPti, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctg30.secPti = eval( parseInt(cgosIncome.cgInc.stcg.prctg30.secPti, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg30.secPti, 10));
			cgosIncome.cgInc.stcg.prctg30.secPti = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg30Sum)){
			cgosIncome.cgInc.stcg.prctg30.secPti = parseInt(cgosIncome.cgInc.stcg.prctg30.secPti) + parseInt(amtSetOff) - parseInt(prctg30Sum);
			amtSetOff = parseInt(prctg30Sum);
		}
	}

	return amtSetOff;
	}catch(e){
		alert(e.stack);
	}
}


//To setOff Against section stcgApp
function setOffAgainststcgApp(value, cgosIncome){


	var prctgAr = cgosIncome.cgInc.stcg.prctgAr;
	var prctgArSum = eval( parseInt(prctgAr.stcgApp,10) +
							 parseInt(prctgAr.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctgAr.stcgApp, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctgAr.stcgApp, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctgAr.stcgApp = eval( parseInt(cgosIncome.cgInc.stcg.prctgAr.stcgApp, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctgAr.stcgApp, 10));
			cgosIncome.cgInc.stcg.prctgAr.stcgApp = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctgArSum)){
			cgosIncome.cgInc.stcg.prctgAr.stcgApp = parseInt(cgosIncome.cgInc.stcg.prctgAr.stcgApp) + parseInt(amtSetOff) - parseInt(prctgArSum);
			amtSetOff = zeroOrMore(parseInt(prctgArSum));
		}
	}

	return amtSetOff;
}


//To setOff Against section Applicable PTI
function setOffAgainstArPti(value, cgosIncome){


	var prctgAr = cgosIncome.cgInc.stcg.prctgAr;
	var prctgArSum = eval( parseInt(prctgAr.stcgApp,10) +
							 parseInt(prctgAr.secPti,10));



	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctgAr.secPti, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctgAr.secPti, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctgAr.secPti = eval( parseInt(cgosIncome.cgInc.stcg.prctgAr.secPti, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctgAr.secPti, 10));
			cgosIncome.cgInc.stcg.prctgAr.secPti = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctgArSum)){
			cgosIncome.cgInc.stcg.prctgAr.secPti = parseInt(cgosIncome.cgInc.stcg.prctgAr.secPti) + parseInt(amtSetOff) - parseInt(prctgArSum);
			amtSetOff = zeroOrMore(parseInt(prctgArSum));
		}
	}

	return amtSetOff;
}




//To setOff Against STCG DTAA rate
function setOffAgainstStcgDr(value){
	var stcgDtaa=document.getElementsByName('scheduleCGPost45.currYrLosses.inStcgDTAARate.currYearIncomeHidden')[0];
	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(stcgDtaa.value, 10) > 0){
		if(parseInt(stcgDtaa.value, 10) >= Math.abs(parseInt(value, 10))){
			stcgDtaa.value = eval( parseInt(stcgDtaa.value, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(stcgDtaa.value, 10));
			stcgDtaa.value = 0;
		}
	}
	return amtSetOff;
}

//To setOff Against LTCG DTAA rate
function setOffAgainstLtcgDr(value){
	var stcgDtaa=document.getElementsByName('scheduleCGPost45.currYrLosses.inLtcgDTAARates.currYearIncomeHidden')[0];
	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(stcgDtaa.value, 10) > 0){
		if(parseInt(stcgDtaa.value, 10) >= Math.abs(parseInt(value, 10))){
			stcgDtaa.value = eval( parseInt(stcgDtaa.value, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(stcgDtaa.value, 10));
			stcgDtaa.value = 0;
		}
	}

	return amtSetOff;
}




//To setOff Against section 111a


function setOffAgainst111a(value, cgosIncome){


	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
			 parseInt(prctg15.sec115ad_1_b_ii,10)+
			 parseInt(prctg15.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctg15.sec111a = eval( parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a, 10));
			cgosIncome.cgInc.stcg.prctg15.sec111a = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg15Sum)){
			cgosIncome.cgInc.stcg.prctg15.sec111a = parseInt(cgosIncome.cgInc.stcg.prctg15.sec111a) + parseInt(amtSetOff) - parseInt(prctg15Sum);
			amtSetOff =  zeroOrMore(parseInt(prctg15Sum));
		}
	}

	return amtSetOff;
}
//To setOff Against section 115ad_1_b_ii

function setOffAgainst115ad_1_b_ii(value, cgosIncome){


	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
			 parseInt(prctg15.sec115ad_1_b_ii,10) +
			 parseInt(prctg15.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = eval( parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii, 10));
			cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg15Sum)){
			cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii = parseInt(cgosIncome.cgInc.stcg.prctg15.sec115ad_1_b_ii) + parseInt(amtSetOff) - parseInt(prctg15Sum);
			amtSetOff =  zeroOrMore(parseInt(prctg15Sum));
		}
	}

	return amtSetOff;
}

//To setOff Against section 15 Pti
function setOffAgainst15Pti(value, cgosIncome){


	var prctg15 = cgosIncome.cgInc.stcg.prctg15;
	var prctg15Sum = eval( parseInt(prctg15.sec111a,10) +
							 parseInt(prctg15.sec115ad_1_b_ii,10)+
							 parseInt(prctg15.secPti,10));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) > 0){
		if(parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.stcg.prctg15.secPti = eval( parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.stcg.prctg15.secPti, 10));
			cgosIncome.cgInc.stcg.prctg15.secPti = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg15Sum)){
			cgosIncome.cgInc.stcg.prctg15.secPti = parseInt(cgosIncome.cgInc.stcg.prctg15.secPti) + parseInt(amtSetOff) - parseInt(prctg15Sum);
			amtSetOff =  zeroOrMore(parseInt(prctg15Sum));
		}
	}

	return amtSetOff;
}

//To setOff Against section 112

function setOffAgainst112(value, cgosIncome){


	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = zeroOrMore(eval( parseInt(prctg20.sec112,10) +
			 parseInt(prctg20.sec11EA,10) +
			 parseInt(prctg20.secPti,10)));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg20.sec112 = eval( parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112, 10));
			cgosIncome.cgInc.ltcg.prctg20.sec112 = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg20Sum)){
			cgosIncome.cgInc.ltcg.prctg20.sec112 = parseInt(cgosIncome.cgInc.ltcg.prctg20.sec112) + parseInt(amtSetOff) - parseInt(prctg20Sum);
			amtSetOff = zeroOrMore(parseInt(prctg20Sum));
		}
	}

	return amtSetOff;
}

//To setOff Against section 115EA

function setOffAgainst115Ea(value, cgosIncome){
	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = zeroOrMore(eval( parseInt(prctg20.sec112,10) +
			 parseInt(prctg20.sec11EA,10)+
			 parseInt(prctg20.secPti,10)));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg20.sec11EA, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg20.sec11EA, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg20.sec11EA = eval( parseInt(cgosIncome.cgInc.ltcg.prctg20.sec11EA, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg20.sec11EA, 10));
			cgosIncome.cgInc.ltcg.prctg20.sec11EA = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg20Sum)){
			cgosIncome.cgInc.ltcg.prctg20.sec11EA = parseInt(cgosIncome.cgInc.ltcg.prctg20.sec11EA) + parseInt(amtSetOff) - parseInt(prctg20Sum);
			amtSetOff =zeroOrMore(parseInt(prctg20Sum));
		}
	}


	return amtSetOff;
}

//To setOff Against section 20Pti
function setOffAgainst20Pti(value, cgosIncome){
	var prctg20 = cgosIncome.cgInc.ltcg.prctg20;
	var prctg20Sum = zeroOrMore(eval( parseInt(prctg20.sec112,10) +
							 parseInt(prctg20.sec11EA,10)+
							 parseInt(prctg20.secPti,10)));
	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg20.secPti = eval( parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti, 10));
			cgosIncome.cgInc.ltcg.prctg20.secPti = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg20Sum)){
			cgosIncome.cgInc.ltcg.prctg20.secPti = parseInt(cgosIncome.cgInc.ltcg.prctg20.secPti) + parseInt(amtSetOff) - parseInt(prctg20Sum);
			amtSetOff = zeroOrMore(parseInt(prctg20Sum));
		}
	}


	return amtSetOff;
}

//To setOff Against section 10 Pti
function setOffAgainst10Pti(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115ACA_1,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));
	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.secPti = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti, 10));
			cgosIncome.cgInc.ltcg.prctg10.secPti = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.secPti = parseInt(cgosIncome.cgInc.ltcg.prctg10.secPti) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}


	return amtSetOff;
}



//To setOff Against section Proviso

function setOffAgainstsecProviso(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10)+
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));


	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.secProviso = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso, 10));
			cgosIncome.cgInc.ltcg.prctg10.secProviso = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.secProviso = parseInt(cgosIncome.cgInc.ltcg.prctg10.secProviso) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff =zeroOrMore(parseInt(prctg10Sum));
		}
	}



	return amtSetOff;
}
//To setOff Against section 115ADiiip
function setOffAgainstsec115ADiiiP(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115ACA_1,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));

	console.log("prctg10Sumaaaaaaaaa " +prctg10Sum);

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115ADiiiP) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}



	return amtSetOff;
}
//To setOff Against section 112A
function setOffAgainstsec112A(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115ACA_1,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10) ));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec112A = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec112A = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec112A = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112A) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}



	return amtSetOff;
}

//To setOff Against section 112_1_c_2

function setOffAgainst112_1_c_2(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10)+
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));


	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec112_1_c_2) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff =zeroOrMore(parseInt(prctg10Sum));
		}
	}

	return amtSetOff;
}
//To setOff Against section 115AC_1

function setOffAgainst115AC_1(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));

	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec115AC_1 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AC_1) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}

	}



	return amtSetOff;
}
function setOffAgainst115_AB_1_B(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
            parseInt(prctg10.sec112A,10) +
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10));

	var amtSetOff = 0;

	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = 0;
		}

		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115_AB_1_B) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}

	return amtSetOff;
}
//To setOff Against section 115AD_3

function setOffAgainst115AD_3(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
			 parseInt(prctg10.sec112_1_c_2,10) +
			 parseInt(prctg10.sec115AC_1,10) +
			 parseInt(prctg10.sec115_AB_1_B,10) +
			 parseInt(prctg10.sec115AD_3,10) +
			 parseInt(prctg10.sec115ADiiiP,10) +
			 parseInt(prctg10.sec115E_b,10) +
			 parseInt(prctg10.sec112A,10)+
			 parseInt(prctg10.secPti112A,10)+
			 parseInt(prctg10.secPti,10)));


	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec115AD_3 = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115AD_3) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff =zeroOrMore(parseInt(prctg10Sum));
		}
	}

	return amtSetOff;
}
//To setOff Against section 115E_b

function setOffAgainst115E_b(value, cgosIncome){
	var prctg10 = cgosIncome.cgInc.ltcg.prctg10;
	var prctg10Sum = zeroOrMore(eval( parseInt(prctg10.secProviso,10) +
							 parseInt(prctg10.sec112_1_c_2,10) +
							 parseInt(prctg10.sec115AC_1,10) +
							 parseInt(prctg10.sec115_AB_1_B,10) +
							 parseInt(prctg10.sec115AD_3,10) +
							 parseInt(prctg10.sec115ADiiiP,10) +
							 parseInt(prctg10.sec112A,10)+
							 parseInt(prctg10.secPti112A,10)+
							 parseInt(prctg10.secPti,10)));


	var amtSetOff = 0;
	if(parseInt(value, 10) < 0 && parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115E_b, 10) > 0){
		if(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115E_b, 10) >= Math.abs(parseInt(value, 10))){
			cgosIncome.cgInc.ltcg.prctg10.sec115E_b = eval( parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115E_b, 10) +
												  parseInt(value, 10));
			amtSetOff = Math.abs(parseInt(value, 10));
		}else{
			amtSetOff = Math.abs(parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115E_b, 10));
			cgosIncome.cgInc.ltcg.prctg10.sec115E_b = 0;
		}
		if(parseInt(amtSetOff) > parseInt(prctg10Sum)){
			cgosIncome.cgInc.ltcg.prctg10.sec115E_b = parseInt(cgosIncome.cgInc.ltcg.prctg10.sec115E_b) + parseInt(amtSetOff) - parseInt(prctg10Sum);
			amtSetOff = zeroOrMore(parseInt(prctg10Sum));
		}
	}

	return amtSetOff;
}

//To set Profit Loss

function setProfitLoss(value, lossFld, profitFld){


	if(parseInt(value, 10) < 0){
		document.getElementsByName(lossFld)[0].value = Math.abs(value);
		document.getElementsByName(profitFld)[0].value = 0;
	}else if(parseInt(value, 10) > 0){
		document.getElementsByName(lossFld)[0].value = 0;
		document.getElementsByName(profitFld)[0].value = Math.abs(value);
	}else{
		document.getElementsByName(lossFld)[0].value = 0;
		document.getElementsByName(profitFld)[0].value = 0;
	}
}

//////////////////////////////CG Calculation Ends/////////////////////////////////

function calcCFL_sumAll(){
	try{
		//HP Loss :: total of earlier year losses
		
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.hpLossCFTotal');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.hpLossCFTotal')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.hpLossCFTotal')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.hpLossCFTotal');

		// Loss from business other than loss from speculative business and specified business :: total of earlier year losses
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.busLossOthThanSpecLossCF');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.busLossOthThanSpecLossCF')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev9ThYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev8ThYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.busLossOthThanSpecLossCF')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.busLossOthThanSpecLossCF');

		//  Loss from speculative business :: total of earlier year losses
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmSpecBusCF');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmSpecBusCF')[0].value =
		    coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.lossFrmSpecBusCF')+
		    coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.lossFrmSpecBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.lossFrmSpecBusCF')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.lossFrmSpecBusCF');

		//Loss from specified business :: total of earlier year losses
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmSpecifiedBusCF');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmSpecifiedBusCF')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev9ThYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev8ThYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.lossFrmSpecifiedBusCF')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.lossFrmSpecifiedBusCF');

		//Short-term capital loss
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.stcgLossCFTotal');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.stcgLossCFTotal')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev9ThYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev8ThYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.stcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.stcgLossCFTotal');

		//Long-term Capital loss
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.ltcgLossCFTotal');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.ltcgLossCFTotal')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev9ThYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev8ThYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.ltcgLossCFTotal')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.ltcgLossCFTotal');


		//Other sources loss (from owning race horses)
		coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.othSrcLossRaceHorseCF');
		document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.othSrcLossRaceHorseCF')[0].value =
			coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.othSrcLossRaceHorseCF')+
			coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.othSrcLossRaceHorseCF')+
			coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.othSrcLossRaceHorseCF')+
			coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.othSrcLossRaceHorseCF');

		//Insurance Business new change 
				coalescePath('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmInsuCF');
				  document.getElementsByName('scheduleCFL.totalOfBFLossesEarlierYrs.lossSummaryDetail.lossFrmInsuCF')[0].value =
					coalescePath('scheduleCFL.lossCFFromPrev7ThYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrev6ThYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrev5ThYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrev4thYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrev3rdYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrev2ndYearFromAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFFromPrevYrToAY.carryFwdLossDetail.lossFrmInsuCF')+
					coalescePath('scheduleCFL.lossCFCurrentAssmntYear.carryFwdLossDetail.lossFrmInsuCF');

		
		
	}catch(e){
		alert('error in calcCFL_sumALL=' + e.stack);
	}
}

function getLTCG20ExmpFrmSI(){
	var inc = {"10":0, "20":0};
	var afterExmp = {"10":0, "20":0};
	var tab = document.getElementById('scheduleSI');
	var allInput = tab.getElementsByTagName("INPUT");
	for(var i=0;i<allInput.length;i++){
		if(allInput[i].name.match('secCode$')){
			index = allInput[i].name.substring(allInput[i].name.indexOf('[')+1,allInput[i].name.indexOf(']'));
			if(allInput[i].value=='22'||allInput[i].value=='2A'){
				inc["10"] = eval(parseInt(inc["10"]) + coalesceSetRet('scheduleSI.splCodeRateTax[' + index + '].splRateInc'));
				afterExmp["10"] = eval(parseInt(afterExmp["10"]) + coalesceSetRet('scheduleSI.splCodeRateTax[' + index + '].taxableInc'));

			}else if(allInput[i].value=='21'){
				inc["20"] = eval(parseInt(inc["20"]) + coalesceSetRet('scheduleSI.splCodeRateTax[' + index + '].splRateInc'));
				afterExmp["20"] = eval(parseInt(afterExmp["20"]) + coalesceSetRet('scheduleSI.splCodeRateTax[' + index + '].taxableInc'));

			}
		}
	}
	return {"10":(inc["10"]-afterExmp["10"]), "20":(inc["20"]-afterExmp["20"])};

}

function deleteRowFSI(tableId , noOfHeader , noOfFooter){
	try{
		var mytable = document.getElementById(tableId);
		var rowCount = mytable.rows.length;
		var itemCount = (rowCount - 4 )/ 5;
		noOfHeader = parseInt(noOfHeader , 10);
		var isChecked=false;
		var listOfCheckBox = mytable.getElementsByTagName('input');
		var totalChecked = 0;
		for(var z=0; z<listOfCheckBox.length; z++){
			if(listOfCheckBox[z].name.match(".chosenCheckBox$")){
				if(listOfCheckBox[z].checked==true){
					totalChecked = eval( parseInt(totalChecked,10) +1);
					isChecked=true;
				}
			}
		}
		if(!isChecked){
			addErrorXHTML('','Please select a checkbox for deleting row');
		}

		for(var j=1; j<=totalChecked ; j++){      // iterate for total number of checkboxes
			var totalNoOfInput = mytable.getElementsByTagName('input');

			for(var z=0; z<totalNoOfInput.length; z++){
				if(totalNoOfInput[z].name.match(".chosenCheckBox$")){		// if its a chosenCheckBox element

					var akhilIndex1 = eval(parseInt(totalNoOfInput[z].name.lastIndexOf('[') ,10)+1);
					var akhilIndex2 = eval(parseInt(totalNoOfInput[z].name.lastIndexOf(']') ,10));
					var rowNumber = totalNoOfInput[z].name.substring(akhilIndex1, akhilIndex2);
					rowNumber = parseInt(rowNumber ,10);

					var myCurrtable = document.getElementById(tableId);
					var rowCurrCount = myCurrtable.rows.length;


					if(totalNoOfInput[z].checked==true){
						if((rowNumber!=0) || (rowNumber==0 &&  parseInt(eval(rowCurrCount-noOfHeader-noOfFooter)/5)>1) ){
							rowNumber = eval(parseInt(rowNumber,10) * 5 + noOfHeader);
							for(var i=0;i<5;i++){
								mytable.deleteRow(rowNumber);
							}
							//To Do - reset the name of row for all input , textarea, select
							var newTrList = mytable.getElementsByTagName('tr');
							var newTrListLength = eval(parseInt(newTrList.length ,10)-noOfFooter);
							for( var q=rowNumber; q < newTrListLength ; q++ ){	//iterate over all rows from delete point to second last row
								var p = parseInt((q-noOfHeader) /5) + noOfHeader;
								//set the serial number;
								if((q-noOfHeader)%5==0){
									if(noOfHeader==2){
										newTrList[q].getElementsByTagName('td')[0].innerHTML = parseInt(p-1,10);
									}else if(noOfHeader==1){
										newTrList[q].getElementsByTagName('td')[0].innerHTML = parseInt(p,10);
									}else if(noOfHeader==3){
										newTrList[q].getElementsByTagName('td')[0].innerHTML = parseInt(p-2,10);
									}
								}
								var allInputTags = newTrList[q].getElementsByTagName('input');

								for(var zz=0; zz<allInputTags.length ; zz++ ){
									var index1= allInputTags[zz].name.lastIndexOf('[');
									var index2= allInputTags[zz].name.lastIndexOf(']');

									var str1 = allInputTags[zz].name.substring(0, index1);
									var str3 = allInputTags[zz].name.substring(index2 + 1, allInputTags[zz].name.length);

									allInputTags[zz].name = str1+'[' +eval(parseInt(p,10)-noOfHeader) +']'+str3;
								}

								var allSelectTags = newTrList[q].getElementsByTagName('select');

								for(var zz=0; zz<allSelectTags.length ; zz++ ){
									var index1= allSelectTags[zz].name.lastIndexOf('[');
									var index2= allSelectTags[zz].name.lastIndexOf(']');

									var str1 = allSelectTags[zz].name.substring(0, index1);
									var str3 = allSelectTags[zz].name.substring(index2 + 1, allSelectTags[zz].name.length);

									allSelectTags[zz].name = str1+'[' +eval(parseInt(p,10)-noOfHeader) +']'+str3;
								}

								var allTextAreaTags = newTrList[q].getElementsByTagName('textarea');

								for(var zz=0; zz<allTextAreaTags.length ; zz++ ){
									var index1= allTextAreaTags[zz].name.lastIndexOf('[');
									var index2= allTextAreaTags[zz].name.lastIndexOf(']');

									var str1 = allTextAreaTags[zz].name.substring(0, index1);
									var str3 = allTextAreaTags[zz].name.substring(index2 + 1, allTextAreaTags[zz].name.length);

									allTextAreaTags[zz].name = str1+'[' +eval(parseInt(p,10)-noOfHeader) +']'+str3;
								}
							}
							break;
						}else if((rowNumber==0)  && (parseInt(eval(rowCurrCount-noOfHeader-noOfFooter)/5)==1)){
							//Vacate the content if its first row

							for(var m=0; m<5; m++){
								var firstRow = mytable.getElementsByTagName('tr')[parseInt(noOfHeader) + m];

								var firstInputBox = firstRow.getElementsByTagName('input')[0];
								firstInputBox.checked = false;

								var allInputTags = firstRow.getElementsByTagName('input');
								for ( var i = 0; i < allInputTags.length; i++) {
									allInputTags[i].value = "";
								}
								var allSelectTags = firstRow.getElementsByTagName('select');
								for ( var i = 0; i < allSelectTags.length; i++) {
									var elem = allSelectTags[i];
									elem[0].selected = true;
								}
								var allTextAreaTags = firstRow.getElementsByTagName('textarea');
								for ( var i = 0; i < allTextAreaTags.length; i++) {
									allTextAreaTags[i].value = "";
								}
							}
						}
					}
				}
			}
		}
		//modifyRow(mytable);
	}catch(e){
		alert('exception caught in =' +e.stack );
	}
}


function setSIDesc(){
	var tab = document.getElementById('scheduleSI');
	var inputs = tab.getElementsByTagName("INPUT");
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].name.match('secCode$')){
			var row = inputs[i].parentNode.parentNode;
			row.cells[1].innerHTML = getSectionTextMap(inputs[i].value);
		}
	}
}

function getSlabbedIncome(totalIncome){

	var taxPayer = document.getElementsByName('partAGEN1.personalInfo.status')[0];
	var resStatus = document.getElementsByName('partAGEN1.filingStatus.residentialStatus')[0];
	var sharePercentage = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].sharePercentage')[0].value;//RES , NRI
	var executorStatusCount=false;
	var statusCode = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].status')[0].value;
		if(statusCode=='EXECUTOR')
		{
			executorStatusCount=true;
		}
	var netTxblIncome = totalIncome;

	var inc = {"5":0,"10":0,"20":0,"30":0,"40":0};

	rateCase = -1;
	var taxPayer = document.getElementsByName('partAGEN1.orgFirmInfo.statusOrCompanyType')[0];
	var subtaxPayer = document.getElementsByName('partAGEN1.orgFirmInfo.subStatus')[0];



	if( (taxPayer.value=='14' && subtaxPayer.value=='11')||(taxPayer.value=='9' && subtaxPayer.value=='19') ){



		if(parseInt(netTxblIncome,10) >= parseInt('0',10) && parseInt(netTxblIncome,10) <= parseInt('250000',10)){
			inc = {"5":0,"10":0, "20":0, "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('250001',10) && parseInt(netTxblIncome,10) <= parseInt('500000',10)){
			inc = {"5":(parseInt(netTxblIncome,10) - 250000),"10":0, "20":0, "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('500001',10) && parseInt(netTxblIncome,10) <= parseInt('1000000',10)){
			inc = {"5":250000, "10":0,"20":(parseInt(netTxblIncome,10) - 500000), "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('1000001',10)){
			inc = {"5":250000, "10":0,"20":500000, "30":(parseInt(netTxblIncome,10) - 1000000),"40":0};
		}

	}else if((taxPayer.value=='14' &&  subtaxPayer.value=='8') || (taxPayer.value=='14' && subtaxPayer.value=='20') ||(taxPayer.value=='14' && subtaxPayer.value=='21')){



		var isSharedForeign = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].partnerForeignCompFlg')[0].value;
		var totIncFrmMemberOfAop = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].totIncFrmMemberOfAop')[0].value;
		var shares = getPercentOfShare();
		var total = parseInt(shares.foreignPerc,10)+parseInt(shares.otherPerc,10);
		if(isSharedForeign=='NO' && shares.otherPerc==100){
			if(totIncFrmMemberOfAop=='Y'){
				rateCase = 1;
				inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};

			}else{
				rateCase = 2;
				if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('0',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('250000',10)){

					inc = {"5":0,"10":0, "20":0, "30":0,"40":0};
				}else if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('250001',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('500000',10)){

					inc = {"5":(parseInt(netTxblIncome,10) - 250000),"10":0, "20":0, "30":0,"40":0};
				}else if(parseInt(netTxblIncome,10) >= parseInt('500001',10) && parseInt(netTxblIncome,10) <= parseInt('1000000',10)){
					inc = {"5":250000,"10":0, "20":(parseInt(netTxblIncome,10) - 500000), "30":0,"40":0};
				}else if(parseInt(netTxblIncome,10) >= parseInt('1000001',10)){
					inc = {"5":250000,"10":0, "20":500000, "30":(parseInt(netTxblIncome,10) - 1000000),"40":0};
				}
			}
		}else if(isSharedForeign=='NO'){
			rateCase = 3;

			inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};
		}else if(isSharedForeign=='YES' && total==100){

			rateCase = 4;

			inc = {"5":0,"10":0, "20":0, "30":parseInt(parseInt(rndOffNrsTen(netTxblIncome),10) * parseFloat(shares.otherPerc==0?0:shares.otherPerc/100)),"40":parseInt(parseInt(rndOffNrsTen(netTxblIncome),10) * parseFloat(shares.foreignPerc==0?0:shares.foreignPerc/100))};
		}else{
			rateCase = 5;
			inc = {"5":0,"10":0, "20":0, "30":0,"40":parseInt(netTxblIncome)};
		}

	}else if(taxPayer.value=='14' && (subtaxPayer.value=='7' || subtaxPayer.value=='13')){
		var isSharedForeign = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].partnerForeignCompFlg')[0].value;
		var totIncFrmMemberOfAop = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].totIncFrmMemberOfAop')[0].value;
		var shares = getPercentOfShare();
		var sharePercentage = document.getElementsByName('partAGEN2.partnerOrMemberInfo[0].sharePercentage')[0].value;
		
		var total = parseInt(shares.foreignPerc,10)+parseInt(shares.otherPerc,10);

		var firstFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustShare')[0].value;
		var secondFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustBusInc')[0].value;
		var thirdFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustWill')[0].value;
		var fourthFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustBasic')[0].value;
		var fifthFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustReceivable')[0].value;
		var sixthFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustRelatives')[0].value;
		var seventhFlag = document.getElementsByName('partAGEN2.partnerOrMemberInfo.pvtDiscretioneryTrustBusProf')[0].value;

		if( (firstFlag=='Y' && secondFlag=='Y' && thirdFlag=='Y' ) || (firstFlag=='N' && secondFlag=='Y' && thirdFlag=='Y') || (firstFlag=='N' && secondFlag=='N' && (fourthFlag=='Y' || fifthFlag=='Y' || sixthFlag=='Y' || seventhFlag=='Y'))||(firstFlag=='Y' && secondFlag=='N' ) ){
		 if(isSharedForeign=='NO' && shares.otherPerc==100){
			if(totIncFrmMemberOfAop=='Y'){
				rateCase = 1;
				inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};

			}else{
				rateCase = 2;
				if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('0',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('250000',10)){

					inc = {"5":0,"10":0, "20":0, "30":0,"40":0};
				}else if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('250001',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('500000',10)){

					inc = {"5":(parseInt(netTxblIncome,10) - 250000),"10":0, "20":0, "30":0,"40":0};
				}else if(parseInt(netTxblIncome,10) >= parseInt('500001',10) && parseInt(netTxblIncome,10) <= parseInt('1000000',10)){
					inc = {"5":250000,"10":0, "20":(parseInt(netTxblIncome,10) - 500000), "30":0,"40":0};
				}else if(parseInt(netTxblIncome,10) >= parseInt('1000001',10)){
					inc = {"5":250000,"10":0, "20":500000, "30":(parseInt(netTxblIncome,10) - 1000000),"40":0};
				}
			}
		}else if(isSharedForeign=='NO'){
			rateCase = 3;

			inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};
		}else if(isSharedForeign=='YES' && total==100){

			rateCase = 4;

			inc = {"5":0,"10":0, "20":0, "30":parseInt(parseInt(rndOffNrsTen(netTxblIncome),10) * parseFloat(shares.otherPerc==0?0:shares.otherPerc/100)),"40":parseInt(parseInt(rndOffNrsTen(netTxblIncome),10) * parseFloat(shares.foreignPerc==0?0:shares.foreignPerc/100))};
		}else{
			rateCase = 5;
			inc = {"5":0,"10":0, "20":0, "30":0,"40":parseInt(netTxblIncome)};
		}
	}else if( (firstFlag=='Y' && secondFlag=='Y' && thirdFlag=='N' ) || (firstFlag=='N' && secondFlag=='Y' && thirdFlag=='N') || (firstFlag=='N' && secondFlag=='N' && fourthFlag=='N' && fifthFlag=='N' && sixthFlag=='N' && seventhFlag=='N')){

			inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};

		}

	}
	else if(taxPayer.value=='2' || (taxPayer.value=='1' &&( subtaxPayer.value=='5' || subtaxPayer.value=='10')) || (taxPayer.value=='14' && subtaxPayer.value=='12') || (taxPayer.value=='9' && subtaxPayer.value=='18') ){

		inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};

	}else if(taxPayer.value=='14' && (subtaxPayer.value=='17' ||  subtaxPayer.value=='15' || subtaxPayer.value=='16' || subtaxPayer.value=='4')){


		if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('0',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('10000',10)){

			inc = {"5":0,"10":parseInt(netTxblIncome), "20":0, "30":0,"40":0};
		}else if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('10001',10) && parseInt(rndOffNrsTen(netTxblIncome),10) <= parseInt('20000',10)){

			inc = {"5":0,"10":10000, "20":parseInt(netTxblIncome)-10000, "30":0,"40":0};
		}else if(parseInt(rndOffNrsTen(netTxblIncome),10) >= parseInt('20001',10)){

			inc = {"5":0,"10":10000, "20":10000, "30":parseInt(netTxblIncome)-20000,"40":0};
		}
	}else if((taxPayer.value=='9'&&subtaxPayer.value=='12')&& sharePercentage==100 && executorStatusCount){

		if(parseInt(netTxblIncome,10) >= parseInt('0',10) && parseInt(netTxblIncome,10) <= parseInt('250000',10)){
			inc = {"5":0,"10":0, "20":0, "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('250001',10) && parseInt(netTxblIncome,10) <= parseInt('500000',10)){
			inc = {"5":(parseInt(netTxblIncome,10) - 250000),"10":0, "20":0, "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('500001',10) && parseInt(netTxblIncome,10) <= parseInt('1000000',10)){
			inc = {"5":250000, "10":0,"20":(parseInt(netTxblIncome,10) - 500000), "30":0,"40":0};
		}else if(parseInt(netTxblIncome,10) >= parseInt('1000001',10)){
			inc = {"5":250000, "10":0,"20":500000, "30":(parseInt(netTxblIncome,10) - 1000000),"40":0};
		}
	}else if((taxPayer.value=='9'&&subtaxPayer.value=='12')){
	
		inc = {"5":0,"10":0, "20":0, "30":parseInt(netTxblIncome),"40":0};
	}


	return inc;
}

function customImport(fieldId,rowCount,type){
	if(((fieldId.indexOf('scheduleCGPost45.longTermCapGainPost45.nRIOnSec112and115')!=-1 &&
		fieldId.indexOf('.exemptionOrDedn[')==-1) ||
		fieldId.indexOf('scheduleCGPost45.shortTermCapGainPost45.equityMFonSTT')!=-1 ||
		(fieldId.indexOf('scheduleCGPost45.longTermCapGainPost45.proviso112Applicable')!=-1 &&
		fieldId.indexOf('.exemptionOrDedn[')==-1))){
			addRowToCG(getTableId(fieldId));
			return true;
	}
	return false;
    }

function checkUniqueOSSec(){

	checkUniqueTableCol('schduleOsinc', 'sourceDescription$');
	checkUniqueTableCol('scheduleCGstcg2', 'section$',' A particular drop down cannot be selected twice in Point A3 of schedule CG');
	var table = document.getElementById('scheduleCGltcg1');
	var noOfRows = table.rows.length;

	var valueB1d = parseInt('0',10);
	for (var i = 0; i <noOfRows/14; i++) {
		var r = i+1;
		var tableId = 'ltcgDeduction1_ded'+r;
		checkUniqueTableCol(tableId, 'section$',' A particular drop down cannot be selected twice in Point B1(d) of schedule CG');
	}

	var table = document.getElementById('scheduleCGstcg1');
	var noOfRows = table.rows.length;

	var valueB1d = parseInt('0',10);
	for (var i = 0; i <noOfRows/14; i++) {
		var r = i+1;
		var tableId = 'stcgDeduction_ded'+r;
		checkUniqueTableCol(tableId, 'section$' ,' A particular drop down cannot be selected twice in Point A1(d) of schedule CG');
	}

	checkUniqueTableCol('stcgDeduction2', 'section$','A particular drop down cannot be selected twice in A6 in schedule CG');
	

	checkUniqueTableCol('scheduleCGltcg7', 'section$' ,'A particular drop down cannot be selected twice in B9 in schedule CG');

}
function checkUniqueTableCol(tableId, colname,errorMesg){

	var tab = document.getElementById(tableId);
	var selects = tab.getElementsByTagName('SELECT');
	var arr = new Array();
	for(var i=0;i<selects.length;i++){
		if(selects[i].name.match(colname) && selects[i].value!=''){
			if(arr.indexOf(selects[i].value)==-1){
				arr.push(selects[i].value);
			}else if(selects[i].value!='Others'){
				var msg = errorMesg || 'A particular drop down cannot be selected twice';
				j.setFieldError(selects[i].name, msg);
				addErrorXHTML(selects[i], msg ,true);
			}
		}
	}
}

function ltcgPoint8Sum(){

var exemptionOrDednUs54 = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.amtDeemedCGSec54')[0];
exemptionOrDednUs54.value = addCGDeductions('ltcgDeduction8');
checkUniqueTableCol('ltcgDeduction8', 'section$');
}

function addBPExmptInc(tableId){
	console.log('bppppppppppppppp');
	var tab = document.getElementById(tableId);
	var inputs = tab.getElementsByTagName("INPUT");
	var sum = 0;
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].name.match('totalAmount$')){
			sum = parseInt(sum) + parseInt(coalesce(inputs[i].value));
		}
	}
	return sum;
}


function deleteRowRowToTableSchPartnerInfo(tableId, noOfRow, last) {

	if (numberOfPartnerInfoCheck(tableId,7) ) {

		deleteRowTable(tableId,noOfRow,last);
		//setSerialNumber(elem,2);
	}
}


function numberOfPartnerInfoCheck(tableId,noRows){
	var tab = document.getElementById(tableId);
	var rowCount = tab.rows.length;
	var status = document.getElementsByName('partAGEN1.orgFirmInfo.statusOrCompanyType')[0].value;
	var subStatus = document.getElementsByName('partAGEN1.orgFirmInfo.subStatus')[0].value;
	//setting new values for case where one row is mandatory
	var rowCountNew =6;


if(rowCount < noRows && status == 14 && (subStatus == 3 ||  subStatus == 11 ||  subStatus == 4  || subStatus == 8)   ){

		addErrorXHTML('','Atleast two members are required',true);
		return false;

	}else if(rowCount < rowCountNew && status == 14 && ( subStatus == 13|| subStatus == 20 || subStatus == 21 ) ){

		addErrorXHTML('','Atleast one members are required',true);
		return false;
	}
	else if(rowCount < rowCountNew && status == 9 && (subStatus == 12) ){

		addErrorXHTML('','Atleast one members are required',true);
		return false;
	}

	return true;

}

function natureOfBusChck(tableId){
	var noRows=18;
	var tab = document.getElementById(tableId);
	var rowCount = tab.rows.length;//5
	var status = document.getElementsByName('partAGEN1.orgFirmInfo.statusOrCompanyType')[0].value;
	var subStatus = document.getElementsByName('partAGEN1.orgFirmInfo.subStatus')[0].value;
	
	if((status == 14 && (subStatus == 15 || subStatus == 16 || subStatus == 4))){
		if(rowCount > noRows){
			j.setFieldError('partAGEN2.natOfBus.natureOfBusiness[0].code','Cannot insert more than 17 rows');
			addErrorXHTML('','Cannot insert more than 17 rows',true);
			return false;
		}	
	}else {
	if( !(status == 14 && (subStatus == 15 || subStatus == 16 || subStatus == 4)) && eval(parseInt(rowCount,10)-parseInt('2',10)) > 3){
	j.setFieldError('partAGEN2.natOfBus.natureOfBusiness[0].code','Cannot insert more than 3 rows');
	addErrorXHTML('','Cannot insert more than 3 rows',true);
		return false;
	}
	}
	return true;
}


function isDSCMandatory(){
		var count = 0;

		var i=0;
		var limit = 5000000;
		var msg50l = 'Liable for audit u/s 44AB as turnover exceeds  Rs. 50 lakh. Please check 44AB selection.';
		var code06Count =0;
		var codeOther06Count =0 ;
		var transpoterCodeCount = 0;

		var grossRcpt = parseInt(coalesce(document.getElementsByName('partapl.noBooksOfAccPL.grossReceipt')[0].value));
		var totRevenueFrmOperations = parseInt(coalesce(document.getElementsByName('partapl.creditsToPL.totRevenueFrmOperations')[0].value));

		var grossRcptFrmSales = parseInt(coalesce(document.getElementsByName('partapl.creditsToPL.businessReceipts')[0].value));
		var grossRcptFrmProf = parseInt(coalesce(document.getElementsByName('partapl.creditsToPL.plGrossReceipts')[0].value));
		var grossRcptFrmVat = parseInt(coalesce(document.getElementsByName('partapl.creditsToPL.exciseCustomsVAT.totExciseCustomsVAT')[0].value));
		var grossRcptFrmCringProf = parseInt(coalesce(document.getElementsByName('partapl.noBooksOfAccPL.grossReceiptProf')[0].value));
		var sec44AD = parseInt(coalesce(document.getElementsByName('itr5ScheduleBP.businessIncOthThanSpec.deemedProfitBusUs.section44AD')[0].value));
		var auditFlag = document.getElementsByName('partAGEN2.liableSec44ABflg')[0];


		while(document.getElementsByName('partAGEN2.natOfBus.natureOfBusiness['+i+'].code')[0] &&
				document.getElementsByName('partAGEN2.natOfBus.natureOfBusiness['+i+'].code')[0].value){

			if(document.getElementsByName('partAGEN2.natOfBus.natureOfBusiness['+i+'].code')[0].value.match('0712')){

				transpoterCodeCount++;
			}

			if(document.getElementsByName('partAGEN2.natOfBus.natureOfBusiness['+i+'].code')[0].value.match('060[1-7]')){

				code06Count++;
			}

			if(!document.getElementsByName('partAGEN2.natOfBus.natureOfBusiness['+i+'].code')[0].value.match('060[1-7]')){

				codeOther06Count++;
			}

			i++;
		}

		if ( transpoterCodeCount > 0){

			return;
		}

		var msg;

		if( sec44AD > 0){
			limit=20000000;
			msg = 'Liable for audit u/s 44AB as turnover exceeds  Rs. 2 crore . Please check 44AB selection.';
		}else{

			limit=10000000;
			msg = 'Liable for audit u/s 44AB as turnover exceeds  Rs. 1 crore . Please check 44AB selection.';
		}

		if(!(parseInt(grossRcptFrmSales) > 0 && parseInt(grossRcptFrmCringProf) >0)){
		if(parseInt(grossRcptFrmSales) > 0 || parseInt(grossRcptFrmVat) >0){
			if(parseInt(grossRcpt) + parseInt(grossRcptFrmSales) + parseInt(grossRcptFrmVat) > limit){

				if(auditFlag.value!='Y'){
					j.setFieldError(auditFlag.name, msg);
					addErrorXHTML(auditFlag, msg ,true);
				}
			}

		}

		if(parseInt(grossRcptFrmCringProf) > 0 || parseInt(grossRcptFrmVat) >0){

		if(parseInt(grossRcptFrmProf) + parseInt(grossRcptFrmCringProf) + parseInt(grossRcptFrmVat)  > 5000000){

			if(auditFlag.value!='Y'){
				j.setFieldError(auditFlag.name, msg50l);
				addErrorXHTML(auditFlag, msg50l ,true);
			}
		}
		}
		}

}

function setOffWithDtaa(sectionCode) {

	var arr = {
			'B1e' : 0,
			'B2e' : 0,
			'B3c' : 0,
			'B4c' : 0,
			'B5' : 0,
			'B6' : 0,
			'B7c112(1)(c)' : 0,
			'B7c115AB1b' : 0,
			'B7c115AC' : 0,
			'B7c115AD' : 0,
			'B8' : 0,
			'B9e' : 0,
			'B10' : 0,
			'B11a1' : 0,
			'B11a2' : 0,
			'B11b' : 0
		};
	var tab = document.getElementById('scheduleLtcgDtaa');
	var rowCount = tab.rows.length - 2;
	var total = 0;
	var residentialStatus = document.getElementsByName('partAGEN1.filingStatus.residentialStatus')[0].value;

	for ( var i = 0; i < rowCount; i++) {
		var itemIncluded = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa['+ i + '].itemIncluded')[0].value;
		var amount = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa['	+ i + '].amount')[0].value;
	    var taxResidCertFlag = document.getElementsByName('scheduleCGPost45.longTermCapGainPost45.ltcgUnderDtaa['+i+'].taxResidCertFlag')[0].value;
	    
	    if(residentialStatus == 'NRI')
		{
	    	if(taxResidCertFlag == 'Y')
	    	{

		
		
		if(itemIncluded == 'B1e') {
		       arr['B1e'] = parseInt(arr['B1e'],10) +  parseInt(coalesce(amount),10);
		    } else if(itemIncluded == 'B2e') {
			       arr['B2e'] = parseInt(arr['B2e'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B3c') {
			       arr['B3c'] = parseInt(arr['B3c'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B4c') {
			       arr['B4c'] = parseInt(arr['B4c'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B5') {
			       arr['B5'] = parseInt(arr['B5'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B6') {
			       arr['B6'] = parseInt(arr['B6'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B7c112(1)(c)') {
			       arr['B7c112(1)(c)'] = parseInt(arr['B7c112(1)(c)'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B7c115AB1b') {
			       arr['B7c115AB1b'] = parseInt(arr['B7c115AB1b'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B7c115AC') {
				   arr['B7c115AC'] = parseInt(arr['B7c115AC'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B7c115AD') {
			       arr['B7c115AD'] = parseInt(arr['B7c115AD'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B8') {
			       arr['B8'] = parseInt(arr['B8'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B9e') {
			       arr['B9e'] = parseInt(arr['B9e'],10) +  parseInt(coalesce(amount),10);
			} else if(itemIncluded == 'B10') {
			       arr['B10'] = parseInt(arr['B10'],10) +  parseInt(coalesce(amount),10);
			}else if (itemIncluded == 'B11a1') {
				arr['B11a1'] = parseInt(arr['B11a1'], 10)	+ parseInt(coalesce(amount), 10);
			}else if (itemIncluded == 'B11a2') {
				arr['B11a2'] = parseInt(arr['B11a2'], 10)	+ parseInt(coalesce(amount), 10);
			}else if (itemIncluded == 'B11b') {
				arr['B11b'] = parseInt(arr['B11b'], 10)	+ parseInt(coalesce(amount), 10);
			}
		}
		}
	    else if(residentialStatus != 'NRI')
	    {
	    	
			if(itemIncluded == 'B1e') {
			       arr['B1e'] = parseInt(arr['B1e'],10) +  parseInt(coalesce(amount),10);
			    } else if(itemIncluded == 'B2e') {
				       arr['B2e'] = parseInt(arr['B2e'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B3c') {
				       arr['B3c'] = parseInt(arr['B3c'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B4c') {
				       arr['B4c'] = parseInt(arr['B4c'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B5') {
				       arr['B5'] = parseInt(arr['B5'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B6') {
				       arr['B6'] = parseInt(arr['B6'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B7c112(1)(c)') {
				       arr['B7c112(1)(c)'] = parseInt(arr['B7c112(1)(c)'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B7c115AB1b') {
				       arr['B7c115AB1b'] = parseInt(arr['B7c115AB1b'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B7c115AC') {
					   arr['B7c115AC'] = parseInt(arr['B7c115AC'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B7c115AD') {
				       arr['B7c115AD'] = parseInt(arr['B7c115AD'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B8') {
				       arr['B8'] = parseInt(arr['B8'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B9e') {
				       arr['B9e'] = parseInt(arr['B9e'],10) +  parseInt(coalesce(amount),10);
				} else if(itemIncluded == 'B10') {
				       arr['B10'] = parseInt(arr['B10'],10) +  parseInt(coalesce(amount),10);
				}else if (itemIncluded == 'B11a1') {
					arr['B11a1'] = parseInt(arr['B11a1'], 10)	+ parseInt(coalesce(amount), 10);
				}else if (itemIncluded == 'B11a2') {
					arr['B11a2'] = parseInt(arr['B11a2'], 10)	+ parseInt(coalesce(amount), 10);
				}else if (itemIncluded == 'B11b') {
					arr['B11b'] = parseInt(arr['B11b'], 10)	+ parseInt(coalesce(amount), 10);
				}
			
	    }
	}


	if (sectionCode == 'sec112') {
		total = arr['B1e'] + arr['B2e'] + arr['B3c'] + arr['B9e'] + arr['B6'] + arr['B10'];
	} else if(sectionCode == '112A') {
		  total = arr['B5'];
	}else if(sectionCode == '5ADiiiP') {
		  total = arr['B8'];
	}
		else if (sectionCode == 'secProviso') {
		total = arr['B4c'] ;
	} else if(sectionCode == 'sec112_1_c_2') {
	    total = arr['B7c112(1)(c)'];
    } else if(sectionCode == 'sec115_AB_1_B') {
	    total = arr['B7c115AB1b'];
    } else if(sectionCode == 'sec115AC_1') {
	    total = arr['B7c115AC'];
    } else if(sectionCode == 'sec115AD_3') {
	    total = arr['B7c115AD'];
    } else if(sectionCode == 'PTI_LTCG10P112A') {
		  total = arr['B11a1'];
    } else if(sectionCode == 'PTI_LTCG10P') {
    	total = arr['B11a2'];
    } else if(sectionCode == 'PTI_LTCG20P') {
    	total = arr['B11b'];
    }
	return total;

}