var HTML = "";
function replaceSpecialCharactersForSendMail(string){
	string = string.trim();
	string = string.replace(/#trademark#/g, '');
	string = string.replace(/&#174;/gi, '');
	string = string.replace(/&#8482;/gi, '');
	string = string.replace(/&#8482;&nbsp;/gi, '');
	string = string.replace(/&reg;/gi, '');
	string = string.replace(/®/gi, '');
	string = string.replace(/&nbsp;/, ' ');
	string = string.replace(/™/, '');
	string = string.replace(/#/, '%23');
	string = string.replace(/&/, '%26');
	string = string.replace(/;/, '');
	
	return string;
}
function prepareMailDiscHTML() {
    HTML = "";
    HTML += "<table border='1' rules='cols' cellpadding='5'>";
    HTML += "<thead>";
    HTML += "<tr style='background:rgb(42,128,213)'>";
    HTML += "<th style='color:white'>Product</th>";
    HTML += "<th style='color:white'>Type</th>";
    HTML += "<th style='color:white'>Number rxns</th>";	
	HTML += "<th style='color:white'>Part number</th>";
    HTML += "<th style='color:white'>Quantity</th>";
    HTML += "<th style='color:white'>Unit Price</th>";
    HTML += "<th style='color:white'>Volume Discount</th>";
    HTML += "<th style='color:white'>Total Discount</th>";	
	HTML += "<th style='color:white'>Price per rxn</th>";
	HTML += "<th style='color:white'>Price per sample</th>";
    HTML += "<th style='color:white'>Net Price</th>";
    HTML += "</tr>";
    HTML += "</thead>";
    HTML += "<tbody>";
    var totalPrice = 0;
    var reaction = new Array();
	
	var currencyArr = ["EUR", "CZK", "GBP", "PLN", "KRW", "CNY", "JPY"];
	var curSymbol ='';
	if(currency == "EUR"){
		curSymbol = '&#8364;';
	} else if(currency == "CZK"){
		curSymbol = 'K&#269;';
	} else if(currency == "GBP"){
		curSymbol = '&#163;';
	} else if(currency == "PLN"){
		curSymbol = '&#122;&#322;'; //&#122; &#322;
	} else if(currency == "KRW"){
		curSymbol = '&#8361;';
	} else if(currency == "CNY"){
		curSymbol = '&#165;';
	} else if(currency == "JPY"){
		curSymbol = '&#165;';
	}
	
    for (var i = 0; i < detailspageinfo.getCount(); i++) {
        var e = detailspageinfo.getAt(i);
        //console.log(e)
        if (e.get('quantity') > 0) {
            var count = 0;
            var cellValues = new Array(10);
			var pricePerReaction = (e.get('netprice') / (e.get('noofreactions')));
			var pricePerSample = (e.get('netprice') / (getExperimentInfo('noofsamples')));
			
			var EmailVolumeDiscount = e.get('volumediscount2');
			EmailVolumeDiscount = EmailVolumeDiscount > 0 ? EmailVolumeDiscount + "%" : EmailVolumeDiscount;
			var EmailTotalDiscount = e.get('discount');
			EmailTotalDiscount = EmailTotalDiscount > 0 ? EmailTotalDiscount + "%" : EmailTotalDiscount;
				
            HTML += "<tr>";
            HTML += "<td><span>" + replaceSpecialCharactersForSendMail(e.get('product')) + "</span></td>";
            HTML += "<td><span>" + e.get('type') + "</span></td>";
            HTML += "<td><span>" + e.get('noofreactions') + "</span></td>";
			HTML += "<td><span>" + e.get('partnumber') + "</span></td>";
            HTML += "<td><span>" + e.get('quantity') + "</span></td>";
            if(jQuery.inArray(currency, currencyArr) !== -1){
				HTML +=  "<td><span>"+ curSymbol +" "+ roundNumber(e.get('unitprice'), 2)+"</span></td>";
			} else {
				HTML += "<td><span>" + convertCurrency(roundNumber(e.get('unitprice'), 2), region + "-" + currency) + "</span></td>";
			}	
            HTML += "<td><span>" + EmailVolumeDiscount  + "</span></td>";
            HTML += "<td><span>" + EmailTotalDiscount + "</span></td>";						
			if(jQuery.inArray(currency, currencyArr) !== -1){
				HTML +=  "<td><span>"+curSymbol +" "+ roundNumber(pricePerReaction, 2)+"</span></td>";
				HTML +=  "<td><span>"+curSymbol +" "+ roundNumber(pricePerSample, 2)+"</span></td>";
				HTML +=  "<td><span>"+curSymbol +" "+ roundNumber(e.get('netprice'), 2)+"</span></td>";
			} else {
				HTML += "<td><span>" + convertCurrency((pricePerReaction), region + "-" + currency) + "</span></td>";
				HTML += "<td><span>" + convertCurrency((pricePerSample), region + "-" + currency) + "</span></td>";            
				HTML += "<td><span>" + convertCurrency(roundNumber(e.get('netprice'), 2), region + "-" + currency) + "</span></td>";
			}
            HTML += "</tr>";
            totalPrice = totalPrice + e.get('netprice');
        }
    }
    HTML += "</tbody></table><table cellpadding='5'>";
   if(jQuery.inArray(currency, currencyArr) !== -1){
		var totcost = document.getElementById('productlisttotalcost').innerHTML;
		totcost = totcost.split(".")[0];
		totcost = totcost.replace(/[^\d]/g, "");
		HTML += "<tr><td>Total Cost</td><td>" + curSymbol +" "+ totcost + "</td></tr>";
	} else {
		HTML += "<tr><td>Total Cost</td><td>" + convertCurrency(roundNumber(totalPrice, 2), region + "-" + currency) + "</td></tr>";
	}
    HTML += "</table>";	
	//console.log('prepareMailDiscHTML()');
	if(Development){
		Ext.get('MailHTMLData').update(HTML);	
	}
}

function mailHandler() {
    Ext.get('emailstatus').update('Mail sent successfully');
    Ext.get('mailpopup').addCls('hidden');
    Ext.get('mailpopup').removeCls('visible');
    Ext.get('mailsuccespopup').addCls('visible');
    Ext.get('mailsuccespopup').removeCls('hidden');
    var interval = setInterval(function () {
        clearInterval(interval);
        Ext.get('mailsuccespopup').addCls('hidden');
        Ext.get('mailsuccespopup').removeCls('visible');
    }, 5000);
}

function sendMailNew(){
	var emails = Ext.get('emails').dom.value.split(',');
    var from = Ext.get('from').dom.value;
    var msg = "<div style='margin-bottom:15px'>" + Ext.get('msg').dom.value + "</div>";
    var subject = Ext.get('subject').dom.value;
    emails = trimEmails(emails);
    if (!(validateEmails(emails))) {
        Ext.get('emailstatus').update('Invalid email entered');
        return;
    }
	var from = "pricingtool@lifetech.com";
	var to = [];
	var content = msg + HTML;
	 for (var i = 0; i < emails.length; i++) {
        to.push(emails[i]);
    }
	to = to.join(",");
	var type = "html";
	var data = {from : from, to : to, subject : subject ,  content : content, type : type};
	var jsonData = JSON.stringify(data);	
	$.support.cors = true;
	$.ajax({
		type: "POST",
		url: 'http://ec2-54-243-60-203.compute-1.amazonaws.com:8080/sendemail/api/v1/send',
		data: jsonData,
		headers: {
		 "app-id":"appid",
		 "app-key":"appkey"
		},
		contentType: "application/json",
		success :function(Resdata){
			console.log(Resdata);
			if(Resdata == "Success"){
				mailHandler();
			} else {
				Ext.get('emailstatus').update('Mail sending failed.');
			}
		},
		error: function (errmsg, status) {
			alert('error');
		}
	}); 
	HTML = "";	
}

// Send referel email
function sendReferelEmail(){
	var type = "";
	if(getExperimentInfo("IsPGX") == "PGx"){
		type = "Pharmacogenomics";
		var PGxreturnval = isValidIstrumrntsforPGX();		
		if(PGxreturnval == true){				
			calcforPGXInputs();
		} else {
			alert(PGxreturnval);
			return false;
		}
	} else{
		type = getExperimentInfo("type");
	}
	
	if($("#customerFirstName").val() == ""){
		$("#customerFirstNameErr").html("First Name is required.");
		return false;
	} else {
		$("#customerFirstNameErr").html("");
	}
	if($("#customerLastName").val() == ""){
		$("#customerLastNameErr").html("Last Name is required.");
		return false;
	} else {
		$("#customerLastNameErr").html("");
	}
	if($("#customerEmail").val() == ""){
		$("#customerEmailErr").html("Email is required.");
		return false;
	} else if( !validateEmail($("#customerEmail").val())) {
		$("#customerEmailErr").html("Enter valid email.");
		return false;
	} else {
		$("#customerEmailErr").html("");
	}
	if($("#institutionName").val() == ""){
		$("#institutionNameErr").html("Institution Name is required.");
		return false;
	} else {
		$("#institutionNameErr").html("");
	}
	if($("#refererName").val() == ""){
		$("#refererNameErr").html("Name is required.");
		return false;
	} else {
		$("#refererNameErr").html("");
	}
	if($("#refererComments").val() == ""){
		$("#refererCommentsErr").html("Comments is required.");
		return false;
	} else {
		$("#refererCommentsErr").html("");
	}
	if($("#refererEmail").val() == ""){
		$("#refererEmailErr").html("Email is required.");
		return false;
	} else if( !validateEmail($("#refererEmail").val())) {
		$("#refererEmailErr").html("Enter valid email.");
		return false;
	} else {
		$("#refererEmailErr").html("");
	}
	
	// other app values
	
	var targets = getExperimentInfo("nooftargets");
	var samples = getExperimentInfo("noofsamples");
	/*var species = getExperimentInfo("species");
	var replicates = getExperimentInfo("noofreplicates");
	var instrument = Ext.get('referInstrument').dom.value;*/
	
	// pgx values
	var param1 = Ext.get('no_of_pgxsamples').dom.value;
	var param2 = Ext.get('pgxsamplecombobox').dom.value;
	var param3 = Ext.get('no_of_reagentsmonths').dom.value;
	var param4 = getExperimentInfo("generateQuoteFor");
	var param5 = Ext.get('pgxsnpopenarrayformat').dom.value;
	var param6 = Ext.get('pgxsnpformatneed').dom.value;
	var param7 = Ext.get('pgxsnpreplicates').dom.value;
	var param8 = Ext.get('pgxcnasample').dom.value;
	var param9 = Ext.get('pgxcnainstruments').dom.value;
	var param10 = Ext.get('pgxcnainstrumentsneedtouse').dom.value;
	var param11 = Ext.get('pgxcnvassaytype').dom.value;
	var param12 = Ext.get('pgxsnpassaytype').dom.value;
	var param13 = Ext.get('pgxsnpsample').dom.value;
	var param14 = Ext.get('pgxdnavalues').dom.value;
	var param15 = Ext.get('pgxsnpqsoavalue').dom.value;
	var param16 = Ext.get('pgxsnpaccufillvalue').dom.value;
	var param17 = Ext.get('pgxcnanoofinstruments').dom.value;
	
	// link url
	if(getExperimentInfo("IsPGX") == "PGx"){
		var ispgx = true;
		var linkUrl = 'http://test.ceino.com/PriceCalculator/v6/Config/price-calculator.html?param1='+param1+'&param2='+param2+'&param3='+param3+'&param4='+param4+'&param5='+param5+'&param6='+param6+'&param7='+param7+'&param8='+param8+'&param9='+param9+'&param10='+param10+'&param11='+param11+'&param12='+param12+'&param13='+param13+'&param14='+param14+'&param15='+param15+'&param16='+param16+'&param17='+param17+'&ispgx='+ispgx;
	} else {
		var ispgx = false;
		var linkUrl = 'http://test.ceino.com/PriceCalculator/v6/Config/price-calculator.html?type='+type+'&targets='+targets+'&samples='+samples+'&ispgx='+ispgx;
	}
	
	var to = '';
	var cc = '';
	var toName = '';
	if(getExperimentInfo("repEmail") == null){
		to = getExperimentInfo("ccrepEmail");
		cc = $("#refererEmail").val();
		toName = getExperimentInfo("ccrepName");
	} else {
		to = getExperimentInfo("repEmail");
		toName = getExperimentInfo("repName");
		cc = $("#refererEmail").val()+','+getExperimentInfo("ccrepEmail");
	}
	
	//var to = 'sankar@ceino.com';
    //var cc = $("#refererEmail").val()+','+getExperimentInfo("ccrepEmail");
	
	
	var referMailHtml = '';
	referMailHtml = referMailHtml + '<div>Hi '+toName+',</div><br><br>';
	referMailHtml = referMailHtml + '<div>A referral has been made for a potential TaqMan Assay Opportunity.  Details are included below.</div><br>';	
	referMailHtml = referMailHtml + '<div>Referred by: '+Ext.get('refererName').dom.value+'</div><br>';
	referMailHtml = referMailHtml + '<div>Account: '+Ext.get('institutionName').dom.value+'</div><br>';
	referMailHtml = referMailHtml + '<div>Customer Name: '+Ext.get('customerFirstName').dom.value+' '+Ext.get('customerLastName').dom.value+'</div><br>';
	referMailHtml = referMailHtml + '<div>Email: '+Ext.get('customerEmail').dom.value+'</div><br>';
	referMailHtml = referMailHtml + '<div>Application: '+type+'</div><br>';
	if(getExperimentInfo("IsPGX") != "PGx"){
		referMailHtml = referMailHtml + '<div># Targets: '+targets+'</div><br>';
		referMailHtml = referMailHtml + '<div># Samples: '+samples+'</div><br>';
	}
	referMailHtml = referMailHtml + '<div>Notes: '+Ext.get('refererComments').dom.value+'</div><br>';
	referMailHtml = referMailHtml + '<div style="margin-top:10px;">';
	referMailHtml = referMailHtml + 'Cost Calculator Referral <a href="'+linkUrl+'">Link</a></div>';
	referMailHtml = referMailHtml + '<div style="margin-top:10px;">Thank you,</div>';
	referMailHtml = referMailHtml + '<div>'+Ext.get('refererName').dom.value+'</div>';
	
	
	
	var fromEmail = 'referral@thermofisher.com';
    var subject = "Customer referral";
    $("#overlay").show();
	$("#referrelSuccessMsg").show();
	var type = "html";
	var data = {from : fromEmail, fromName : 'qPCR Referral', to : to, cc:cc, subject : subject ,  content : referMailHtml, type : type};
	var jsonData = JSON.stringify(data);	
	$.support.cors = true;
	$.ajax({
		type: "POST",
		url: 'http://ec2-54-243-60-203.compute-1.amazonaws.com:8080/sendemail/api/v1/send',
		data: jsonData,
		headers: {
		 "app-id":"appid",
		 "app-key":"appkey"
		},
		contentType: "application/json",
		success :function(Resdata){			
			if(Resdata == "Success"){				
				saveReferelDetails();								
			} else {
				alert("Failed");
			}
		},
		error: function (errmsg, status) {
			alert('error');
		}
	}); 
	referMailHtml = "";	
}

// Save referal details in db
function saveReferelDetails(){
	var appType = getExperimentInfo("type");
	//var species = getExperimentInfo("species");
	var targets = getExperimentInfo("nooftargets");
	var samples = getExperimentInfo("noofsamples");
	//var replicates = getExperimentInfo("noofreplicates");
	//var instrument = Ext.get('referInstrument').dom.value;
	var repName = getExperimentInfo("repName");
	var repEmail = getExperimentInfo("repEmail");
	var referedByName = Ext.get('refererName').dom.value
	var referedByEmail = Ext.get('refererEmail').dom.value; 
	var customerName = Ext.get('customerFirstName').dom.value+' '+Ext.get('customerLastName').dom.value;
	var customerEmail = Ext.get('customerEmail').dom.value;
	var institutionName = Ext.get('institutionName').dom.value;
	var refererComments = Ext.get('refererComments').dom.value;
	
	var data = {"appType":appType, "targets":targets, "samples": samples, "repName": repName, "repEmail":repEmail, "referedByName":referedByName, "referedByEmail":referedByEmail, "customerName":customerName, "customerEmail":customerEmail, "institutionName":institutionName};
	var jsonData = JSON.stringify(data);	
	$.support.cors = true;
	$.ajax({
		method: "POST",
		url: 'http://dev.ceino.com:8080/PriceCalculator/SALESREP/SENDREFERRALDETAILS',
		//url: 'http://prod.ceino.com:8080/PriceCalculator/SALESREP/SENDREFERRALDETAILS',
		data: jsonData,		
		dataType:'JSON',
		headers : { 'Content-Type': 'application/x-www-form-urlencoded;'},
		success : function(resp) {
			var respData = resp.data
			if(resp.success == true){
				//$("#overlay").hide();
				//$("#referrelSuccessMsg").hide();
				/*$( '#referralSectionDiv input, textarea' ).each(function(){
					$(this).val('');
				});*/
				//$("#repNameSpn").html("");
			}			
		},
		error : function(request,error)
		{
			alert("Request: "+JSON.stringify(request));
		}
	}); 
}

function sendMail() {
    var emails = Ext.get('emails').dom.value.split(',');
    var from = Ext.get('from').dom.value;
    var msg = "<div style='margin-bottom:15px'>" + Ext.get('msg').dom.value + "</div>";
    var subject = Ext.get('subject').dom.value;
    emails = trimEmails(emails);
    if (!(validateEmails(emails))) {
        Ext.get('emailstatus').update('Invalid email entered');
        return;
    }
	
    var url = "https://sendgrid.com/api/mail.send.xml?";
    url += "api_user=lifetech";
    url += "&api_key=life$123";
    url += "&subject=" + subject;
    url += "&from=" + "pricingtool@lifetech.com";
    url += "&fromname=" + from;
    for (var i = 0; i < emails.length; i++) {
        url += "&to[]=" + emails[i];
    }
    url += "&html=" + msg + HTML;
	if(Development){
		Ext.get('MailHTMLData').update(HTML);	
	}
	
    
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.onreadystatechange = function () {
        if (this.readyState == 'loaded' || this.readyState == 'complete') mailHandler();
    };
	script.onload = mailHandler();
	script.src = url;
    if(!Development){
		head.appendChild(script);
	}else{
		head.appendChild(script);
	}
}

function clearMailFields() {
    Ext.get('emails').dom.value = '';
    Ext.get('from').dom.value = '';
    Ext.get('msg').dom.value = '';
    Ext.get('subject').dom.value = '';
    Ext.get('emailstatus').update('');
}

function validateEmails(emails) {
    for (var i = 0; i < emails.length; i++) {
        if (!validateEmail(emails[i])) return false;
    }
    return true;
}

function trimEmails(emails) {
    var trimmedEmails = new Array(emails.length);
    for (var i = 0; i < emails.length; i++) {
        trimmedEmails[i] = trim(emails[i]);
    }
    return trimmedEmails;
}

function validateEmail(elementValue) {
    var emailPattern = /^[a-zA-Z0-9_\+-]+(\.[a-zA-Z0-9_\+-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.([a-zA-Z]{2,4})$/;
    return emailPattern.test(elementValue);
}

/*function prepareMailHTML(rec) {
	//console.log('prepareMailHTML()');
    HTML = "";
    HTML += "<table border='1' rules='cols' cellpadding='5'>";
    HTML += "<thead>";
    HTML += "<tr style='background:rgb(42,128,213)'>";
    HTML += "<th style='color:white'>Product</th>";
    HTML += "<th style='color:white'>Type</th>";
    HTML += "<th style='color:white'>Part number</th>";
    HTML += "<th style='color:white'>Quantity</th>";
    HTML += "<th style='color:white'>Price</th>";
    HTML += "<th style='color:white'>Volume Discount</th>";
    HTML += "<th style='color:white'>Total Discount</th>";
    HTML += "<th style='color:white'>Net Price</th>";
    HTML += "</tr>";
    HTML += "</thead>";
    HTML += "<tbody>";
    HTML += "<tr>";
    HTML += "<td><span>" + rec.get('format').replace("<sup>&reg;</sup>&nbsp;", "??????").replace("&nbsp;", " ").replace("<a href='#'>Product Page</a>", "") + "</span></td>";
    HTML += "<td><span>" + (rec.get('type').indexOf('tube') != -1 ? 'Assay' : 'Array') + "</span></td>";
    HTML += "<td><span>" + rec.get('partnumber') + "</span></td>";
    HTML += "<td><span>" + rec.get('noofunits') + "</span></td>";
    HTML += "<td><span>" + convertCurrency(rec.get('assayscost'), region + "-" + currency) + "</span></td>";
    HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
	HTML += "<td><span>" + rec.get('volumediscount') + "</span></td>";
    HTML += "<td><span>" + convertCurrency(rec.get('assayscostwithvoldisc'), region + "-" + currency) + "</span></td>";
    HTML += "</tr>";
    
    if (isNumber(rec.get('refassayqty')) && rec.get('refassayqty') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + rec.get('refassayname') + "</span></td>";
        HTML += "<td><span>" + (rec.get('type').indexOf('tube') != -1 ? 'Assay' : 'Array') + "</span></td>";
        HTML += "<td><span>" + rec.get('refassaypartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('refassayqty') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('refassaycostpersample'), region + "-" + currency) + "</span></td>";
        HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('refassaycost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('openarray384wellsampleplatesunits') && rec.get('openarray384wellsampleplatesunits') > 0) {
       // console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>OpenArray?? 384-well Sample Plates</span></td>";
        HTML += "<td><span>Accessories </span></td>";
        HTML += "<td><span>" + rec.get('accessory1partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('openarray384wellsampleplatesunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('openarray384wellsampleplatescost'), region + "-" + currency) + "</span></td>";
        HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('openarray384wellsampleplatescost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('openarrayaccufillsystemtips10packunits') && rec.get('openarrayaccufillsystemtips10packunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>OpenArray?? AccuFill?? System Tips, 10 Pack</span></td>";
        HTML += "<td><span>Accessories </span></td>";
        HTML += "<td><span>" + rec.get('accessory3partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('openarrayaccufillsystemtips10packunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('openarrayaccufillsystemtips10packcost'), region + "-" + currency) + "</span></td>";
        HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('openarrayaccufillsystemtips10packcost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('megaplexprimerpoolshumanunits') && rec.get('megaplexprimerpoolshumanunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (getExperimentInfo('species') == "Human" ? 'Megaplex?? Primer Pools, Human' : 'Megaplex?? Primer Pools, Rodent') + "</span></td>";
        HTML += "<td><span>Accessories </span></td>";
        HTML += "<td><span>" + rec.get('accessory5partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('megaplexprimerpoolshumanunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('megaplexprimerpoolshumanunits'), region + "-" + currency) + "</span></td>";
        HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('megaplexprimerpoolshumancost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('mnoofunits1') && rec.get('mnoofunits1') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('mastermix1')) + "</span></td>";
        HTML += "<td><span>Master Mix</span></td>";
        HTML += "<td><span>" + rec.get('mastermixpartnumber1') + "</span></td>";
        HTML += "<td><span>" + rec.get('mnoofunits1') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('mnoofunits1'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('mastermixdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('mastermixcost1') * (1 - (rec.get('mastermixdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('rtprimerpoolsnoofunits') && rec.get('rtprimerpoolsnoofunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('rtprimerpools')) + "</span></td>";
        HTML += "<td><span>Primer Pools </span></td>";
        HTML += "<td><span>" + rec.get('rtprimerpoolpartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('rtprimerpoolsnoofunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('totalrtprimerpoolspricecost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('totalrtprimerpoolspricecost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('preampprimerpoolsnoofunits') && rec.get('preampprimerpoolsnoofunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('preampprimerpools')) + "</span></td>";
        HTML += "<td><span>Primer pools</span></td>";
        HTML += "<td><span>" + rec.get('accessory3partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('preampprimerpoolsnoofunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('totalpreampprimerpoolspricecost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('totalpreampprimerpoolspricecost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('preampnoofunits') && rec.get('preampnoofunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('preampproduct')) + "</span></td>";
        HTML += "<td><span>Pre-Amp</span></td>";
        HTML += "<td><span>" + rec.get('preamppartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('preampnoofunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('totalpreampcost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + ((Ext.get('preamprtperc').dom.value).split('%')[0]) + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('totalpreampcost') * (1 - (((Ext.get('preamprtperc').dom.value).split('%')[0]) / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('openarrayaccufillsystemtipsunits') && rec.get('openarrayaccufillsystemtipsunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>OpenArray?? AccuFill?? System Tips</span></td>";
        HTML += "<td><span>Accessories</span></td>";
        HTML += "<td><span>" + rec.get('accessory2partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('openarrayaccufillsystemtipsunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('openarrayaccufillsystemtipscost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('openarrayaccufillsystemtipscost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    /*if (rec.get('openarrayaccufillsystemtips10packunits')
			&& rec.get('openarrayaccufillsystemtips10packunits') > 0) {
		HTML += "<tr>";
		HTML += "<td><span>OpenArray AccuFill System Tips, 10 pack</span></td>";
		HTML += "<td><span>Accessories</span></td>";
		HTML += "<td><span>" + rec.get('accessory3partnumber') + "</span></td>";
		HTML += "<td><span>"
				+ rec.get('openarrayaccufillsystemtips10packunits')
				+ "</span></td>";
		HTML += "<td><span>"
				+ convertCurrency(rec
						.get('openarrayaccufillsystemtips10packcost'), region
						+ "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
		HTML += "<td><span>"
				+ convertCurrency(roundNumber(rec
						.get('openarrayaccufillsystemtips10packcost')
						* (1 - (rec.get('accessoriesdisc') / 100)), 2), region
						+ "-" + currency) + "</span></td>";
		HTML += "</tr>";
	}*/
   /* if (rec.get('openarrayrealtimepcraccessorieskitunits') && rec.get('openarrayrealtimepcraccessorieskitunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + rec.get('realtimePCRname') + "</span></td>";
        HTML += "<td><span>Accessories</span></td>";
        HTML += "<td><span>" + rec.get('accessory4partnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('openarrayrealtimepcraccessorieskitunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('openarrayrealtimepcraccessorieskitcost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('accessoriesdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('openarrayrealtimepcraccessorieskitcost') * (1 - (rec.get('accessoriesdisc') / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (isNumber(rec.get('ipcunits')) && rec.get('ipcunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + rec.get('ipcname') + "</span></td>";
        HTML += "<td><span>IPC Kit</span></td>";
        HTML += "<td><span>" + rec.get('ipcpartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('ipcqty') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('ipcprice'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + ((Ext.get('preamprtperc').dom.value).split('%')[0]) + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('ipcnetprice') * (1 - (((Ext.get('preamprtperc').dom.value).split('%')[0]) / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('rtnoofunits') && rec.get('rtnoofunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('rtproduct')) + "</span></td>";
        HTML += "<td><span>RT</span></td>";
        HTML += "<td><span>" + rec.get('rtpartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('rtnoofunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('totalrtcost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + ((Ext.get('preamprtperc').dom.value).split('%')[0]) + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('totalrtcost') * (1 - (((Ext.get('preamprtperc').dom.value).split('%')[0]) / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('rtnoofunits1') && rec.get('rtnoofunits1') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + (rec.get('rtproduct1')) + "</span></td>";
        HTML += "<td><span>RT</span></td>";
        HTML += "<td><span>" + rec.get('rtpartnumber1') + "</span></td>";
        HTML += "<td><span>" + rec.get('rtnoofunits1') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('totalrtcost1'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + ((Ext.get('preamprtperc').dom.value).split('%')[0]) + "</span></td>";
        HTML += "<td><span>" + convertCurrency(roundNumber(rec.get('totalrtcost1') * (1 - (((Ext.get('preamprtperc').dom.value).split('%')[0]) / 100)), 2), region + "-" + currency) + 
		"</span></td>";
        HTML += "</tr>";
    }
    if (rec.get('mnoofunits') && rec.get('mnoofunits') > 0) {
        //console.log('prepareMailHTML');
		HTML += "<tr>";
        HTML += "<td><span>" + rec.get('mastermix').replace("<sup>&reg;</sup>&nbsp;", "??????") + "</span></td>";
        HTML += "<td><span>Master Mix</span></td>";
        HTML += "<td><span>" + rec.get('mastermixpartnumber') + "</span></td>";
        HTML += "<td><span>" + rec.get('mnoofunits') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('mastermixcost'), region + "-" + currency) + "</span></td>";
		HTML += "<td><span>" + rec.get('volumediscount2') + "</span></td>";
        HTML += "<td><span>" + rec.get('mastermixdisc') + "</span></td>";
        HTML += "<td><span>" + convertCurrency(rec.get('mastermixcostwithdisc'), region + "-" + currency) + "</span></td>";
        HTML += "</tr>";
        HTML += "</tbody>";
        HTML += "</table>";
        HTML += "<table cellpadding='5'>";
        HTML += "<tr><td>Total Cost</td><td>" + convertCurrency(rec.get('totalcost'), region + "-" + currency) + "</td></tr>";
    }
    HTML += "</table>";
	
	if(Development){
		Ext.get('MailHTMLData').update(HTML);	
	}
}*/