
function addGenoTubeCustom() {
	var title = "Custom TaqMan<sup>&reg;</sup>&nbsp;SNP Genotyping Assays";
	var format = "";
	var subtype = "Custom";
	var noofreactions = getExperimentInfo('noofreplicates')
			* getExperimentInfo('noofsamples');
	
	var equipment = getExperimentInfo('equipment');
	
//	if(equipment == "96-well") {
//		if (noofreactions <= 300) {
//			format = 'Small';
//		} else if (noofreactions <= 1000) {
//			format = 'Medium';
//		} else {
//			format = 'Large';
//		}
//	} else {
//		if (noofreactions <= 1500) {
//			format = 'Small';
//		} else if (noofreactions <= 5000) {
//			format = 'Medium';
//		} else {
//			format = 'Large';
//		}
//	}
//	
	
	
	var species = "";
	if(getExperimentInfo('species') == "Human") {
		species = "Human";
	} else {
		species = "Non-Human";
	}
	var isOtherFormat = getExperimentInfo('isOtherFormat');
	var spno = 2;
	if( isOtherFormat === "YES" ){
		spno = getExperimentInfo('otherFmPano');
		var selOtherForVal = getExperimentInfo('selOtherFormatValue');
		var tubeObj = findAppTapRecForOtherFormat(genoTypeTubes, 'productname', selOtherForVal);
	}else{
		updateExperimentInfo("currFmPno", spno);
		var tubeObj = findOptimumGenoTubeRecord(subtype, species, noofreactions);
	}
	var productName = tubeObj.get('productname');
	var partNumber = tubeObj.get('partnumber');
	var tubenoofreactions = "";
	var wellNum = 96;
	if(equipment == "96-well") {
		tubenoofreactions = tubeObj.get('no of reactions in 96-well tube');
	} else {
		wellNum = 384;
		tubenoofreactions = tubeObj.get('no of reactions in 384-well tube');
	}
	
	var noofunits = Math.ceil((noofreactions / tubenoofreactions)) * getExperimentInfo('nooftargets');
	
	var mvolume = 0;
	if (equipment == '96-well') {
		mvolume = tubeObj.get('mastermix volume perreaction for 96-well')
				* getExperimentInfo('nooftargets')
				* getExperimentInfo('noofreplicates')
				* getExperimentInfo('noofsamples');
	} else if (equipment == '384-well') {
		mvolume = tubeObj.get('mastermix volume perreaction for 384-well')
				* getExperimentInfo('nooftargets')
				* getExperimentInfo('noofreplicates')
				* getExperimentInfo('noofsamples');
	}
	var isOtherMMFormat = getExperimentInfo('isOtherMMFormat');
	if( isOtherMMFormat === "YES" ){
		spno = getExperimentInfo('otherFmPano');
		var selOtherForVal = getExperimentInfo('selOtherFormatMMValue');
		var selOtherForPd = getExperimentInfo('selOtherFormatMMProd');
		var mastermixObj = findAppTapRecForOtherMMFormat(genoMasterMix, 'productname', selOtherForPd);
		var mastermix = mastermixObj.get('productname');
		var mnoofunits = (Math.ceil(mvolume / mastermixObj.get('volume')));
		var mmxPartNumber = mastermixObj.get('partnumber');
		var masterMixCostPerUnit = pricelist.findRecord('partnumber',mmxPartNumber).regions().findRecord('region',region + "-" + currency).get('price');
		var masterperc = (Ext.get('masterperc').dom.value).split('%')[0];
		var totalMasterMixCost = masterMixCostPerUnit * mnoofunits * (1 - (masterperc / 100));
		var masterMixCostPerReaction = totalMasterMixCost / (getExperimentInfo('nooftargets') * 
										getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
		var mmixCostPerSample = totalMasterMixCost	/ getExperimentInfo('noofsamples');
		var masterMixCostPerReaction1 = 0;
		var masterMixCostPerReaction2 = 0;
		var masterMixCostPerReaction3 = 0;
		var mmixCostPerSample1 = 0;
		var mmixCostPerSample2 = 0;
		var mmixCostPerSample3 = 0;
		var totalMasterMixCost1 = 0;
		var totalMasterMixCost2 = 0;
		var totalMasterMixCost3 = 0;
	} else{
		// Master Mix Combination starts here
		//console.log("mvolume : "+mvolume);
		totalQty = [];
		allCombination = [];
		var totQty = Math.ceil( mvolume / 1000 );
		var toGetCombinationVal = pbRatio(0, totQty, mvolume, genoTypingMasterMix);
		var selMM = toGetOptimumPrice(toGetCombinationVal, genoMasterMix);
		//var mmxObj = findGenoMMXRecordCombination(mvolume);
		var mmxObj = selMM;
		
		var mastermix = mmxObj['Product Name1'];
		var mastermix1 = mmxObj['Product Name2'];
		var mastermix2 = mmxObj['Product Name3'];
		var mastermix3 = mmxObj['Product Name4'];
		
		
		var mnoofunits = mmxObj['qty1'];
		var mnoofunits1 = mmxObj['qty2'];
		if(mnoofunits1 != undefined){
			mnoofunits1 = mnoofunits1;
		} else {
			mnoofunits1 = 0;
		}
		var mnoofunits2 = mmxObj['qty3'];
		if(mnoofunits2 != undefined){
			mnoofunits2 = mnoofunits2;
		} else {
			mnoofunits2 = 0;
		}
		var mnoofunits3 = mmxObj['qty4'];
		if(mnoofunits3 != undefined){
			mnoofunits3 = mnoofunits3;
		} else {
			mnoofunits3 = 0;
		}
		
		var mmxPartNumber = mmxObj["Part Number1"];
		var mmxPartNumber1 = mmxObj["Part Number2"];
		if(mmxPartNumber1 != undefined){
			mmxPartNumber1 = mmxPartNumber1;
		} else {
			mmxPartNumber1 = 0;
		}
		var mmxPartNumber2 = mmxObj["Part Number3"];
		if(mmxPartNumber2 != undefined){
			mmxPartNumber2 = mmxPartNumber2;
		} else {
			mmxPartNumber2 = 0;
		}
		var mmxPartNumber3 = mmxObj["Part Number4"];
		if(mmxPartNumber3 != undefined){
			mmxPartNumber3 = mmxPartNumber3;
		} else {
			mmxPartNumber3 = 0;
		}
		
		
		var masterMixCostPerUnit = pricelist.findRecord('partnumber', mmxPartNumber).regions().findRecord('region', region + "-" + currency).get('price');
		
		if(mmxPartNumber1 != 0){
			var masterMixCostPerUnit1 = pricelist.findRecord('partnumber', mmxPartNumber1).regions().findRecord('region', region + "-" + currency).get('price');
		} else {
			var masterMixCostPerUnit1 = 0;
		}
		if(mmxPartNumber2 != 0){
			var masterMixCostPerUnit2 = pricelist.findRecord('partnumber', mmxPartNumber2).regions().findRecord('region', region + "-" + currency).get('price');
		} else {
			var masterMixCostPerUnit2 = 0;
		}
		if(mmxPartNumber3 != 0){
			var masterMixCostPerUnit3 = pricelist.findRecord('partnumber', mmxPartNumber3).regions().findRecord('region', region + "-" + currency).get('price');
		} else {
			var masterMixCostPerUnit3 = 0;
		}
		
		var masterperc = (Ext.get('masterperc').dom.value).split('%')[0];
		var totalMasterMixCost = masterMixCostPerUnit * mnoofunits * (1 - (masterperc / 100));
		var totalMasterMixCost1 = masterMixCostPerUnit1 * mnoofunits1 * (1 - (masterperc / 100));
		var totalMasterMixCost2 = masterMixCostPerUnit2 * mnoofunits2 * (1 - (masterperc / 100));
		var totalMasterMixCost3 = masterMixCostPerUnit3 * mnoofunits3 * (1 - (masterperc / 100));
		
		var masterMixCostPerReaction = (totalMasterMixCost) / (getExperimentInfo('nooftargets')	* getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
		var masterMixCostPerReaction1 = (totalMasterMixCost1) / (getExperimentInfo('nooftargets')	* getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
		var masterMixCostPerReaction2 = (totalMasterMixCost2) / (getExperimentInfo('nooftargets')	* getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
		var masterMixCostPerReaction3 = (totalMasterMixCost3) / (getExperimentInfo('nooftargets')	* getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
		
		var mmixCostPerSample = totalMasterMixCost / getExperimentInfo('noofsamples');
		var mmixCostPerSample1 = totalMasterMixCost1 / getExperimentInfo('noofsamples');
		var mmixCostPerSample2 = totalMasterMixCost2 / getExperimentInfo('noofsamples');
		var mmixCostPerSample3 = totalMasterMixCost3 / getExperimentInfo('noofsamples');
		
		// Master Mix Combination ends here
	}
	
	var assayCostPerUnit = pricelist.findRecord('partnumber', partNumber).regions().findRecord('region', region + "-" + currency).get('price');

	var volumeDiscount = 0;
	var costWithVolDisc = noofunits * assayCostPerUnit * (1 - (volumeDiscount / 100));
	var assayperc = (Ext.get('assayperc').dom.value).split('%')[0];
	var totalAssayCost = costWithVolDisc * (1 - (assayperc / 100));
	
	

	var numPlates = Math.ceil(getExperimentInfo('nooftargets') * getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples')/wellNum);
	//console.log("Number of plates: " + numPlates);
	var hours = Math.ceil(67/60 * 1.2 * numPlates);
	
//	var hours = Math.ceil((45 / 60 / wellNum) * getExperimentInfo('nooftargets')
//			* getExperimentInfo('noofreplicates')
//			* getExperimentInfo('noofsamples'));
	var totalCost = totalAssayCost + totalMasterMixCost + totalMasterMixCost1 + totalMasterMixCost2;

	var assayCostPerReaction = totalAssayCost / (getExperimentInfo('nooftargets') * getExperimentInfo('noofreplicates') * getExperimentInfo('noofsamples'));
	
    var optimizationCostPerReaction = 0;
    var totalCostPerReaction = assayCostPerReaction + masterMixCostPerReaction + masterMixCostPerReaction1 + masterMixCostPerReaction2 + optimizationCostPerReaction;
	
    var productUrl = "";
    productUrl = "https://www.invitrogen.com/site/us/en/home/Products-and-Services/Applications/PCR/real-time-pcr/real-time-pcr-assays/snp-genotyping-taqman-assays/custom-snp-assays.html";
    
	var assayCostPerSample = totalAssayCost / getExperimentInfo('noofsamples');
	var totalCostPerSample = assayCostPerSample + mmixCostPerSample + mmixCostPerSample1 + mmixCostPerSample2;
	
	var totalCostPreDisc = costWithVolDisc + (masterMixCostPerUnit * mnoofunits);
	var totalDiscount = 100 - (totalCost*100/totalCostPreDisc);

	var formats = productName;
	var formatqnt = formats.replace("TaqMan","TaqMan®");
	var format = formatqnt.replace("QuantStudio TM","QuantStudio™");
	outputList.add({
		pno : spno,
		title : title,
		partnumber : partNumber,
		mastermixpartnumber : mmxPartNumber,
		mastermixpartnumber1 : mmxPartNumber1,
		mastermixpartnumber2 : mmxPartNumber2,
		mastermixpartnumber3 : mmxPartNumber3,
		format : format,
		noofunits : noofunits,
		noofreactions : noofreactions * getExperimentInfo('nooftargets'),
		mastermix : mastermix.replace(/�/gi, '<sup>&reg;</sup>&nbsp;'),
		mastermix1 : mastermix1,//.replace(/�/gi, '<sup>&reg;</sup>&nbsp;'),
		mastermix2 : mastermix2,//.replace(/�/gi, '<sup>&reg;</sup>&nbsp;'),
		mastermix3 : mastermix3,//.replace(/�/gi, '<sup>&reg;</sup>&nbsp;'),
		mnoofunits : mnoofunits,
		mnoofunits1 : mnoofunits1,
		mnoofunits2 : mnoofunits2,
		mnoofunits3 : mnoofunits3,
		totalcost : roundNumber(totalCost, 2),
		volumediscount : volumeDiscount,
		mvolumediscount : masterperc,
		assayscost : roundNumber(costWithVolDisc, 2),
		assayscostperunit : roundNumber(assayCostPerUnit, 2),
		assayscostwithvoldisc : roundNumber(totalAssayCost, 2),
		mastermixvol : roundNumber(mvolume, 2),
		mastermixcostperunit : roundNumber(masterMixCostPerUnit, 2),
		mastermixcostperunit1 : roundNumber(masterMixCostPerUnit1, 2),
		mastermixcostperunit2 : roundNumber(masterMixCostPerUnit2, 2),
		mastermixcostperunit3 : roundNumber(masterMixCostPerUnit3, 2),
		mastermixdisc : masterperc,
		mastermixcostwithdisc: roundNumber(totalMasterMixCost, 2),
		mastermixcostwithdisc1: roundNumber(totalMasterMixCost1, 2),
		mastermixcostwithdisc2: roundNumber(totalMasterMixCost2, 2),
		mastermixcostwithdisc3: roundNumber(totalMasterMixCost3, 2),
		mastermixcostpredisc : roundNumber((masterMixCostPerUnit * mnoofunits), 2),
		mastermixcostpredisc1 : roundNumber((masterMixCostPerUnit1 * mnoofunits1), 2),
		mastermixcostpredisc2 : roundNumber((masterMixCostPerUnit2 * mnoofunits2), 2),
		mastermixcostpredisc3 : roundNumber((masterMixCostPerUnit3 * mnoofunits3), 2),
		mastermixcost : roundNumber(masterMixCostPerUnit * mnoofunits, 2),
		mastermixcost1 : roundNumber(masterMixCostPerUnit1 * mnoofunits1, 2),
		mastermixcost2 : roundNumber(masterMixCostPerUnit2 * mnoofunits2, 2),
		mastermixcost3 : roundNumber(masterMixCostPerUnit3 * mnoofunits3, 2),
		mmxcostpersample : roundNumber(mmixCostPerSample,2),
		mmxcostpersample1 : roundNumber(mmixCostPerSample1,2),
		mmxcostpersample2 : roundNumber(mmixCostPerSample2,2),
		mmxcostpersample3 : roundNumber(mmixCostPerSample3,2),
		assaycostpersample : roundNumber(assayCostPerSample,2),
		totalcostpersample : roundNumber(totalCostPerSample,2),
		totalcostpredisc : roundNumber(totalCostPreDisc,2),
		totaldiscount : roundNumber(totalDiscount,2),
		noofhours : hours,
		assaycostperreaction : roundNumber(assayCostPerReaction, 2),
		mastermixcostperreaction : roundNumber(masterMixCostPerReaction, 2),
		mastermixcostperreaction1 : roundNumber(masterMixCostPerReaction1, 2),
		mastermixcostperreaction2 : roundNumber(masterMixCostPerReaction2, 2),
		mastermixcostperreaction3 : roundNumber(masterMixCostPerReaction3, 2),
		optimizationcostperreaction : roundNumber(optimizationCostPerReaction,
				2),
		totalcostperreaction : roundNumber(totalCostPerReaction, 2),
		totalcostpersample: roundNumber(totalCostPerSample, 2),
		producturl : productUrl,
		reqnoofunits : noofunits,
		fnName:'addGenoTubeCustom',
		type: 'tube'
	});

}

// Master Mix Combination calculation
function findGenoMMXRecordCombination(mvolume){	
	var total = Math.ceil(mvolume / 1000);
	var genoMaster = [1,10,20,50,100];
	var totalQty = [];
	for(var gi = 0; gi < genoMaster.length; gi++){
		var qty = total / genoMaster[gi]; 
		var temp1 =  parseInt(qty) * genoMaster[gi];
		var temp2 = total - parseInt(qty) * genoMaster[gi]; 
		var mius = qty - parseInt(qty);
		var subTotal = [];
		var subsubTotal = [];
		for(var sgi = 0; sgi < genoMaster.length; sgi++){
			subsubTotal = [];
			var temp3 = temp2 / genoMaster[sgi];
			if(temp3 >= 1){
				var temp4 =  temp2 - ( parseInt(temp3) * genoMaster[sgi] );
				if(temp4 > 0){
					subsubTotal.push({"qtyType":1,"aQty":parseInt(temp4)});
					subsubTotal.push({"qtyType":10,"aQty":1});
					subTotal.push({"suQtyType":genoMaster[sgi],"sQty":parseInt(temp3),"XQty":subsubTotal});
				}else{
					subTotal.push({"suQtyType":genoMaster[sgi],"sQty":parseInt(temp3),"XQty":subsubTotal});
				}
			}else if( temp3 >= 0.5 && temp3 <= 1 ){
				var temp4 = 1;
				subTotal.push({"suQtyType":genoMaster[sgi],"sQty":temp4,"XQty":subsubTotal});
			}
		}
		totalQty.push({"aQtyType":genoMaster[gi],"mQty":parseInt(qty),"sub":subTotal});
	}

	var combination = [];
	var allCombination = [];
	for(var vi = 0; vi < totalQty.length; vi++){
		combination = [];
		var rec1 = genoMasterMix.findRecord('volume', (totalQty[vi]['aQtyType'] * 1000) );
		if(totalQty[vi]['mQty'] > 0){
			var qty1Price = totalQty[vi]['mQty'] * rec1.get('price');
			var subi = totalQty[vi]['sub'];
			if( subi.length > 0 ){
				for(var su = 0 ; su <  subi.length; su++){
					var rec2 = genoMasterMix.findRecord('volume', ( subi[su]['suQtyType'] * 1000) );
					var qty2Price = subi[su]['sQty'] * rec2.get('price');
					if( subi[su]['XQty'].length > 0){
						var subi1 = subi[su]['XQty'];
						if(subi1.length > 0){
							for(var su1 = 0 ; su1 <  subi1.length; su1++){
								var rec3 = genoMasterMix.findRecord('volume', ( subi1[su1]['qtyType'] * 1000) );
								var qty3Price = subi1[su1]['aQty'] * rec3.get('price'); 
								var totalPrice = qty1Price + qty2Price +qty3Price;
								combination.push({"Product Name1" : rec1.get('productname'), "Part Number1" : rec1.get('partnumber'), "volume1": rec1.get('volume'), "qty1":totalQty[vi]['mQty'], "qty1Rate1" : qty1Price, "Product Name2" : rec2.get('productname'), "Part Number2" : rec2.get('partnumber'), "volume2": rec2.get('volume'), "qty2":subi[su]['sQty'], "qty1Rate2" : qty2Price, "Product Name3" : rec3.get('productname'), "Part Number3" : rec3.get('partnumber'), "volume3": rec3.get('volume'), "qty3":subi1[su1]['aQty'], "qty1Rate3" : qty3Price, "total Price":totalPrice});
							}
						}
					}else{
						var totalPrice = qty1Price + qty2Price;
						combination.push({"Product Name1" : rec1.get('productname'), "Part Number1" : rec1.get('partnumber'), "volume1": rec1.get('volume'), "qty1":totalQty[vi]['mQty'], "qty1Rate1" : qty1Price, "Product Name2" : rec2.get('productname'), "Part Number2" : rec2.get('partnumber'), "volume2": rec2.get('volume'), "qty2":subi[su]['sQty'], "qty1Rate2" : qty2Price, "Product Name3" : 0, "Part Number3" : 0, "volume3": 0, "qty3":0, "qty1Rate3" : 0, "total Price":totalPrice});
					}
				}
		}else {
			var totalPrice = qty1Price;
		   combination.push({"Product Name1" : rec1.get('productname'), "Part Number1" : rec1.get('partnumber'), "volume1": rec1.get('volume'), "qty1":totalQty[vi]['mQty'], "qty1Rate1" : qty1Price, "Product Name2" : 0,  "Part Number2" :0, "volume2": 0, "qty2":0, "qty1Rate2" : 0, "Product Name3" : 0, "Part Number3" : 0, "volume3": 0, "qty3":0, "qty1Rate3" : 0, "total Price":totalPrice});
		}
			allCombination.push(combination);
		}
	}

	var price =0;
	var recordIndex = 0;
	var mprice = 0;
	var finalArray = [];
	for(var ai = 0; ai < allCombination.length; ai++){
		var pdtArray = allCombination[ai];
		for(var pdi = 0; pdi < pdtArray.length; pdi++){
			mprice = pdtArray[pdi]['total Price'];
			if (price == 0) {
				price = mprice;
			}
			if (mprice < price) {
				price = mprice;
				finalArray = [];
				finalArray = pdtArray[pdi];
			
			}
		}
	}
	return finalArray;
}