﻿/// <reference path="javascripts.js" />

function Right(str, n) {
    if (n <= 0)
        return '';
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}

function getCookie(cname) {
    if (document.cookie.length > 0) {
        cstart = document.cookie.indexOf(cname + '=');
        if (cstart != -1) {
            cstart = cstart + cname.length + 1;
            cend = document.cookie.indexOf(';', cstart);
            if (cend == -1) cend = document.cookie.length;
            return unescape(document.cookie.substring(cstart, cend));
        }
    }
    return '';
}

function checkCookie(cname) {
    c = getCookie(cname);
    alert(cname + '= ' + c );

}

function setCookie(cname, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = cname + '=' + escape(value) +
		((expiredays == null) ? '' : ';expires=' + exdate.toUTCString());
}

function deleteCookie(cname) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate());
    document.cookie = cname + '=;expires=' + exdate.toUTCString();
}

function deleteCookiesAll(url) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate());
    document.cookie = 'fiveprime=;expires=' + exdate.toUTCString();
    document.cookie = 'threeprime=;expires=' + exdate.toUTCString();
    document.cookie = 'Sequence=;expires=' + exdate.toUTCString();
    document.location = url;
}

function updateorderform(fiveprime, threeprime, internalmod) {
    var updatediv = document.getElementsByClassName('updatediv');
    //updatediv.style.display = 'block';
    $('updatediv').style.display = 'block';
    if (fiveprime != '') {
        $('fiveprime').style.backgroundColor = '#d3e1d0';
        $('fiveprime').value = fiveprime;
        $('updatediv').innerHTML = fiveprime + ' Added to 5 Prime Modification!';
        setCookie('fiveprime', fiveprime, '30');
    }
    if (threeprime != '') {
        $('threeprime').style.backgroundColor = '#d3e1d0';
        $('threeprime').value = threeprime;
        $('updatediv').innerHTML = threeprime + ' Added to 3 Prime Modification!';
        setCookie('threeprime', threeprime, '30');
    }
    if (internalmod != '') {
        var newseq = $('Sequence').value + '[' + internalmod + ']';
        //alert(newseq);
        $('Sequence').value = newseq;
        $('Sequence').style.backgroundColor = '#d3e1d0';
        $('updatediv').innerHTML = internalmod + ' Internal Modification Added to Sequence!';
        setCookie('Sequence', newseq, '30');
    }

    Effect.Fade('updatediv', { duration: 3.0 });
}

// Exception Arrays - These are use in various functions below. One day they maybe should be generated dynamically from the database

//select distinct p.shortname from products p 
//inner join prodtocat pc on p.prodid = pc.prodid
//where pc.catid = 42 and  p.active = 1
//order by p.shortname;

//d-Uridine
//I
//MeOA
//MeOC
//MeOG
//MeOU
//Methylene Blue
//rA
//rC
//rG
//rU
//T(Methylene Blue)


function e1() {
    //var e = new Array('*', '[rA]', '[rG]', '[rU]', '[rC]', '[I-SH]');
    var e = new Array('[rA]', '[rG]', '[rU]', '[rC]', '[I-SH]');
    return e
}

function e45() {
    var e = new Array('[d-Uridine]', '[I]', '[MeOA]', '[MeOC]', '[MeOG]', '[MeOU]', '[Methylene Blue]', '[rA]', '[rC]', '[rG]', '[rU]', '[T(Methylene Blue)]');
    return e;
}

function e43() {
    var e = new Array('[BHQ-0]', '[BHQ-1]', '[BHQ-2]', '[BHQ-3]', '[DABCYL]', '[T(BHQ-1)]', '[T(BHQ-2)]', '[T(Dabsyl)]');
    return e;
}

function e42() {
    var e = new Array('[Biosearch Blue]', '[C3-Fluorescein]', '[CAL Fluor Gold 540]', '[CAL Fluor Orange 560]', '[CAL Fluor Red 590]', '[CAL Fluor Red 610]', '[CAL Fluor Red 635]', '[FAM]', '[HEX]', '[mdC(ROX)]', '[Pulsar 650]', '[Quasar 570]', '[Quasar 670]', '[Quasar 705]', '[T(CAL Fluor Gold 540)]', '[T(CAL Fluor Orange 560)]', '[T(CAL Fluor Red 590)]', '[T(CAL Fluor Red 610)]', '[T(CAL Fluor Red 635)]', '[T(FAM)]', '[T(JOE)]', '[T(Quasar 570)]', '[T(Quasar 670)]', '[T(ROX)]', '[T(TAMRA)]', '[TAMRA]', '[TET]');
    return e;
}

function Synth2(synthscale, purification, cb, checker) {
    //CheckSequenceLengthCustom();
    var sequence = $('Sequence').value;
    var fiveprime = $('fiveprime').value;
    var threeprime = $('threeprime').value;
    var rna = $('rna').checked;
    var allgood = true
    var exceptions = e1();

    //loop through exceptions
    for (x in exceptions) {
        if (sequence.indexOf(exceptions[x]) != -1) {
            allgood = false
        }
    }

    if (rna == true) {
        allgood = false
    }

    if (fiveprime == 'none' && threeprime == 'none' && allgood == true) {
//        if (synthscale = 'none') {
//            CustomPure(synthscale);
//        }

        //RPC
        if (purification == 'RPC') {
            switch (synthscale) {
                case '1 µmol':
                    $('catalogid').value = 'P1C-1';
                    $('item_itemid').value = '5014';
                    $('item_qty').value = '1';
                    $('basecost').value = '2.00';
                    break;
                case '200 nmol':
                    $('catalogid').value = 'P1C-2';
                    $('item_itemid').value = '5013';
                    $('item_qty').value = '1';
                    $('basecost').value = '.75';
                    break;
                case '50 nmol':
                    $('catalogid').value = 'P1C-5';
                    $('item_itemid').value = '5012';
                    $('item_qty').value = '1';
                    $('basecost').value = '.40';
                    break;
                default:
                    $('catalogid').value = '';
                    $('item_itemid').value = '';
                    $('item_qty').value = '';
                    $('basecost').value = '';
            }
        }
        //RP HPLC
        if (purification == 'RPH') {
            switch (synthscale) {
                case '1 µmol':
                    $('catalogid').value = 'P1R-1';
                    $('item_itemid').value = '5017';
                    $('item_qty').value = '1';
                    $('basecost').value = '2.00';
                    break;
                case '200 nmol':
                    $('catalogid').value = 'P1R-2';
                    $('item_itemid').value = '5016';
                    $('item_qty').value = '1';
                    $('basecost').value = '.75';
                    break;
                case '50 nmol':
                    $('catalogid').value = 'P1R-5'
                    $('item_itemid').value = '5015';
                    $('item_qty').value = '1';
                    $('basecost').value = '.40';
                    break;
                default:
                    $('catalogid').value = '';
                    $('item_itemid').value = '';
                    $('item_qty').value = '';
                    $('basecost').value = '';
            }
        }
        //AX-HPLC
        if (purification == 'AXH') {
            switch (synthscale) {
                case '1 µmol':
                    $('catalogid').value = 'P1A-1';
                    $('item_itemid').value = '5020';
                    $('item_qty').value = '1';
                    $('basecost').value = '2.00';
                    break;
                case '200 nmol':
                    $('catalogid').value = 'P1A-2';
                    $('item_itemid').value = '5019';
                    $('item_qty').value = '1';
                    $('basecost').value = '.75';
                    break;
                case '50 nmol':
                    $('catalogid').value = 'P1A-5';
                    $('item_itemid').value = '5018';
                    $('item_qty').value = '1';
                    $('basecost').value = '.40';
                    break;
                default:
                    $('catalogid').value = '';
                    $('item_itemid').value = '';
                    $('item_qty').value = '';
                    $('basecost').value = '';
            }
        }
        //Dual HPLC - RAH
        if (purification == 'RAH') {
            switch (synthscale) {
                case '1 µmol':
                    $('catalogid').value = 'RAH-1';
                    $('item_itemid').value = '1079';
                    $('item_qty').value = '1';
                    $('basecost').value = '2.00';
                    break;
                case '200 nmol':
                    $('catalogid').value = 'RAH-2';
                    $('item_itemid').value = '1080';
                    $('item_qty').value = '1';
                    $('basecost').value = '.75';
                    break;
                case '50 nmol':
                    $('catalogid').value = 'RAH-5';
                    $('item_itemid').value = '1081';
                    $('item_qty').value = '1';
                    $('basecost').value = '.40';
                    break;
                    break;
                default:
                    $('catalogid').value = '';
                    $('item_itemid').value = '';
                    $('item_qty').value = '';
                    $('basecost').value = '';
            }
        }
        if (purification == 'Salt-Free') {
            switch (synthscale) {
                case '1 µmol':
                    $('catalogid').value = 'COS-1';
                    $('item_itemid').value = '636';
                    $('item_qty').value = '1';
                    $('basecost').value = '2.00';
                    break;
                case '200 nmol':
                    $('catalogid').value = 'COS-2';
                    $('item_itemid').value = '637';
                    $('item_qty').value = '1';
                    $('basecost').value = '.75';
                    break;
                case '50 nmol':
                    $('catalogid').value = 'COS-5';
                    $('item_itemid').value = '638';
                    $('item_qty').value = '1';
                    $('basecost').value = '.40';
                    break;
                    break;
                default:
                    $('catalogid').value = '';
                    $('item_itemid').value = '';
                    $('item_qty').value = '';
                    $('basecost').value = '';
            }
        }
    } else if (purification != 'none') {

        switch (synthscale) {
            case '1 µmol':
                $('catalogid').value = 'DNA';
                $('item_itemid').value = '4892';
                $('item_qty').value = '1';
                $('basecost').value = '2.00';
                break;
            case '200 nmol':
                $('catalogid').value = 'DNA';
                $('item_itemid').value = '4892';
                $('item_qty').value = '1';
                $('basecost').value = '.75';
                break;
            case '50 nmol':
                $('catalogid').value = 'DNA';
                $('item_itemid').value = '4892';
                $('item_qty').value = '1';
                $('basecost').value = '.40';
                break;
            default:
                $('catalogid').value = '';
                $('item_itemid').value = '';
                $('item_qty').value = '';
                $('basecost').value = '';
                break;
        }
    }

    if ($('item_itemid').value != '') {
        GetCustomTotal(cb, checker);
        }
    }

// NOTE: For Build Your Own
function Synth(sinput) {
    switch (sinput) {
        case '1 µmol':
            $('catalogid').value = 'COS-1';
            $('item_itemid').value = '636';
            $('item_qty').value = '1';
            break;
        case '200 nmol':
            $('catalogid').value = 'COS-2';
            $('item_itemid').value = '637';
            $('item_qty').value = '1';
            break;
        case '50 nmol':
            $('catalogid').value = 'COS-5';
            $('item_itemid').value = '638';
            $('item_qty').value = '1';
            break;
            break;
        default:
            $('catalogid').value = '';
            $('item_itemid').value = '';
            $('item_qty').value = '';
    }
}

function CustomPure(sinput) {
    if (($('threeprime').value == 'none') && ($('fiveprime').value == 'none') && ($('SynthScale').value != 'none')) {
        switch (sinput) {
            case '1 µmol':
                $('Purification').options.length = 1;
                $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
                $('Purification').options[2] = new Option("RPC", "RPC");
                $('Purification').options[3] = new Option("RP HPLC", "RPH");
                $('Purification').options[4] = new Option("AX HPLC", "AXH");
                break;
            case '200 nmol':
                $('Purification').options.length = 1;
                $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
                $('Purification').options[2] = new Option("RPC", "RPC");
                $('Purification').options[3] = new Option("RP HPLC", "RPH");
                $('Purification').options[4] = new Option("AX HPLC", "AXH");
                break;
            case '50 nmol':
                $('Purification').options.length = 1;
                $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
                $('Purification').options[2] = new Option("RPC", "RPC");
                break;
            default:
                $('Purification').options.length = 1;
                $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
                $('Purification').options[2] = new Option("RPC", "RPC");
                $('Purification').options[3] = new Option("RP HPLC", "RPH");
                $('Purification').options[4] = new Option("AX HPLC", "AXH");
                $('Purification').options[5] = new Option("Dual HPLC", "RAH");
            }  
        }
        else {
            $('Purification').options.length = 1;
            $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
            $('Purification').options[2] = new Option("RPC", "RPC");
            $('Purification').options[3] = new Option("RP HPLC", "RPH");
            $('Purification').options[4] = new Option("AX HPLC", "AXH");
            $('Purification').options[5] = new Option("Dual HPLC", "RAH");
            
            var fiveprime = $('fiveprime').value;
            if (fiveprime == 'Phos') {
                $('Purification').options.length = 0;
                $('Purification').options[0] = new Option('choose', 'none');
                $('Purification').options[1] = new Option('Salt-Free', 'Salt-Free');
                $('Purification').options[2] = new Option('AX HPLC', 'AXH');
                $('Purification').style.backgroundColor = 'yellow';
            }
    }
}

function RequestQuote() {
    Effect.toggle('rcontent', 'blind');
    if ($('rcontent').style.display = 'block') {
        $('company').className = 'formborder4 required';
        $('email').className = 'formborder4 required';
    } else {
        $('company').className = 'formborder4';
        $('email').className = 'formborder4';
    }
}

function MakeSelected(selectid, sinput) {
    //$(selectid).value = sinput;
    $('Purification').options.length = 1;
    $('Purification').options[1] = new Option("Salt-Free", "Salt-Free");
    $('Purification').options[2] = new Option("RPC", "RPC");
    $('Purification').options[3] = new Option("RP HPLC", "RPH");
    $('Purification').options[4] = new Option("AX HPLC", "AXH");
    $('Purification').options[5] = new Option("Dual HPLC", "Dual HPLC");
}

//Check Exceptions
function CheckExceptions() {
    CheckPrimeExceptions();
    SynthIntException();
}

function CheckPrimeExceptions() {
    var fiveprime = $('fiveprime').value;
    var threeprime = $('threeprime').value;
    if (fiveprime == 'T(ROX)') {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
        return;
    } else {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
        $('SynthScale').options[3] = new Option('50 nmol', '50 nmol');
    }
    if (threeprime == 'mdC(ROX)') {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
        return;
    } else {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
        $('SynthScale').options[3] = new Option('50 nmol', '50 nmol');
    }
}

// For Synth Scale Limiting
function SynthIntException() {

    GetCustomTotal('onthefly');

    var allgood = true
    var sequence = $('Sequence').value;
    
    // catid 43
    var exceptions43 = e43();

    // catid 42
    var exceptions42 = e42();

    //loop through exception43
    for (x in exceptions43) {
        if (sequence.indexOf(exceptions43[x]) != -1) {
            allgood = false
        }
    }
    //loop through exception42
    for (x in exceptions42) {
        if (sequence.indexOf(exceptions42[x]) != -1) {
            allgood = false
        }
    }
        
    if (allgood != true) {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
    }

    // exceptions
    if (sequence.indexOf('T(Methylene Blue)') != -1) {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
    }

    if (sequence.indexOf('dSpacer') != -1) {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
    }

    if (sequence.indexOf('*') != -1) {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
    }
}


function CheckSequenceLengthCustom() {
    var synthscale = $('SynthScale').value;
    var purification = $('Purification').value;
    var sequence = $('Sequence').value;
    var regex = /(\[([^\]]+)\])/ig; //strip out internal modifications
    var sequenceWithoutMods = sequence.replace(regex, "");
    var sequencelength = sequenceWithoutMods.length;
    var synthscalelength = $('SynthScale').getElementsByTagName("option").length;

    if (synthscale == '50 nmol' && sequencelength > 60) {
        $('SynthScale').options.length = 0;
        $('SynthScale').options[0] = new Option('choose', 'none');
        $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
        $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
        $('SynthScale').style.backgroundColor = 'yellow';
        alert('Please choose a Synthesis Scale of either 1 µmol or 200 nmol for sequences longer than 60+ bases. You have ' + sequencelength + ' bases.');
    } else {
    //resets SynthScale option list
        if ((synthscalelength == 3) && (purification == 'none')) {
            $('SynthScale').options.length = 0;
            $('SynthScale').options[0] = new Option('choose', 'none');
            $('SynthScale').options[1] = new Option('1 µmol', '1 µmol');
            $('SynthScale').options[2] = new Option('200 nmol', '200 nmol');
            $('SynthScale').options[3] = new Option('50 nmol', '50 nmol');
            }
    }
}

// Here is the big functions that calculates total ///////////////////////////////////////
function GetCustomTotal(ReturnType, Checker) {

    //fields
    var sequence = $('Sequence').value;
    var sequencelength = sequence.length;
    var synthscale = $('SynthScale').value;
    var purification = $('Purification').value;
    var rna = $('rna').checked;
    var qty = $('item_qty').value;
    var fiveprime = $('fiveprime').value;
    var threeprime = $('threeprime').value;
    var fiveprimetemp = '[' + fiveprime + ']';
    var threeprimetemp = '[' + threeprime + ']';
    if (Checker == 'SynthScale' && fiveprime == 'none' && threeprime == 'none') {
        purification = 'none';
    }

    //CheckSequenceLengthCustom();
     
    //calculations
    var allgood = true
    var popup = false
    var countInternal = 0;
    var countExternal = 0;
    var basecost = 0;
    var total = 0;
    var righttemp = 0;
    var exceptionlength = 0;

    //alert message
    var alertmessage = '';
    var pricetbd = '';

    $('buyoptions').style.display = 'block';

    // Calling this ajax was done at the end. Perhaps it needs to be rolled into sc_custompricecalculation.ashx 
    // but there is an order issue problem.

    if (fiveprime != '' && threeprime != '') {
        var url = '/sc_customcheckdlp.ashx?synthscale=' + synthscale + '&fiveprime=' + fiveprime + '&threeprime=' + threeprime + '&purification=' + purification +  '&sequence=' + sequence + '&basecost=' + basecost + '&rna=' + rna + '&qty=' + qty;
        
        //AJAX POST
        new Ajax.Request(url, {
            method: "get",
            onSuccess: function(transport) {

                if (transport.responseText == 'True') {
                    allgood = false;
                    $('buyoptions').style.display = 'none';

                    var alertdlp;
                    alertdlp = "<div style=\"width:300px; text-align:left; border: 1px solid #f00; background-color: #fff; padding:5px;\">"
                    alertdlp = alertdlp + "<b>ALERT!</b><br />"
                    alertdlp = alertdlp + "It looks like you are trying to build a fluorogenic probe.  If so, please use the appropriate order form for any of the following products:"
                    alertdlp = alertdlp + "<ul>"
                    alertdlp = alertdlp + "<li><a href=\"http://www.biosearchtech.com/store/product.aspx?catid=224,171,40\">Dual-Labeled BHQ&reg; Probes</a></li>"
                    alertdlp = alertdlp + "<li><a href=\"http://www.biosearchtech.com/store/product.aspx?catid=224,171,218\">BHQplus&trade; Probes</a></li>	"
                    alertdlp = alertdlp + "<li><a href=\"http://www.biosearchtech.com/store/product.aspx?catid=224,171,41\">Molecular Beacons</a></li>"
                    alertdlp = alertdlp + "</ul>"
                    alertdlp = alertdlp + "</div>"
                    $('pricecalculation').innerHTML = alertdlp;

                } 
            } //-onSuccess
            }//-request arguments
	    );     // new ajax request

    }
    
    // basic exceptions
    var exceptions = e1();

    // catid 45
    var exceptions45 = e45();

    // catid 43
    var exceptions43 = e43();

    // catid 42
    var exceptions42 = e42();

    //loop through exceptions
    for (x in exceptions) {
        if (sequence.indexOf(exceptions[x]) != -1) {
            allgood = false
        }
    }

    //loop through exception45
    for (x in exceptions45) {
        if (sequence.indexOf(exceptions45[x]) != -1) {
            allgood = false
        }
    }

    for (x in exceptions45) {
        if (fiveprimetemp.indexOf(exceptions45[x]) != -1) {
            allgood = false
        }
    }

    for (x in exceptions45) {
        if (threeprimetemp.indexOf(exceptions45[x]) != -1) {
            allgood = false
        }
    }

//alert(allgood + ' ' + fiveprimetemp);

    //loop through exception43
    for (x in exceptions43) {
        if (sequence.indexOf(exceptions43[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;
            
            //check for duplicates
            exceptionlength = (exceptions43[x].length);
            righttemp = Right(sequence, sequence.length - sequence.indexOf(exceptions43[x]) - exceptionlength);
            if (righttemp.indexOf(exceptions43[x]) != -1) {
                countInternal = countInternal + 1;
                countExternal = countExternal + 1;
            }
            
            if (countInternal > 1) {
                allgood = false
            }
        }
        if (fiveprimetemp.indexOf(exceptions43[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;
            if (countInternal > 1) {
                allgood = false
            }
        }
        if (threeprimetemp.indexOf(exceptions43[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;
            if (countInternal > 1) {
                allgood = false
            }
        }
    }

    //alert (countInternal);


    countInternal = 0; //reset internal count

    //loop through exception42
    for (x in exceptions42) {
        if (sequence.indexOf(exceptions42[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;

            //check for duplicates
            exceptionlength = (exceptions42[x].length);
            righttemp = Right(sequence, sequence.length - sequence.indexOf(exceptions42[x]) - exceptionlength);
            if (righttemp.indexOf(exceptions42[x]) != -1) {
                countInternal = countInternal + 1;
                countExternal = countExternal + 1;
            }
            
            if (countInternal > 1) {
                allgood = false
            }
        }
        if (fiveprimetemp.indexOf(exceptions42[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;
            if (countInternal > 1) {
                allgood = false
            }
        }
        if (threeprimetemp.indexOf(exceptions42[x]) != -1) {
            countInternal = countInternal + 1;
            countExternal = countExternal + 1;
            if (countInternal > 1) {
                allgood = false
            }
        }
  
    }

    //last check
    if (rna == true || countExternal > 1 || synthscale == 'none' || qty.length == 0) {
        allgood = false
    }

    // check illegal characters
    var regex = /(\[([^\]]+)\])/ig; //strip out internal modifications
    var sequenceWithoutMods = sequence.replace(regex, "");
    var illegalchars = /[^ACGTRYMKSWHBVDNUI*acgtrymkswhbvdnui*]/g; //legal character
    var test = sequenceWithoutMods.replace(illegalchars, '');
    if (sequenceWithoutMods.length != test.length) {
        allgood = false;
    }


    //base cost
    switch (synthscale) {
        case '1 µmol':
            basecost = '2.00';
            break;
        case '200 nmol':
            basecost = '.75';
            break;
        case '50 nmol':
            basecost = '.40';
            break;
        default:
            basecost = '0';
    }

    $('basecost').value = basecost;


    if (allgood != true && popup != true) {
        if (synthscale == 'none') {
            alertmessage = 'The price could not determined. Please choose a Synthesis Scale.';
            $('pricecalculation').innerHTML = '';
            $('pricetbd').value = 'true';
            if (ReturnType == 'calculation' ) {
                alert(alertmessage);
            }
            if (ReturnType == 'onthefly') {
                $('pricecalculation').innerHTML = alertmessage;
            }        
        } else if (qty.length == 0) {
            alertmessage = 'The price could not determined. Please choose a Quantity.';
            $('pricecalculation').innerHTML = '';
            $('pricetbd').value = 'true';  
            alert(alertmessage);
        } else {
            alertmessage = 'The price could not determined.';
            $('pricecalculation').innerHTML = '';
            $('pricetbd').value = 'true';
            if (ReturnType == 'calculation') {
                alert(alertmessage);
            }
            if (ReturnType == 'onthefly' || ReturnType == 'rna') {
                $('pricecalculation').innerHTML = 'Estimated Total: Price to be determined. Item will add to cart with TBD pricing.';
            }   
        }
    }

    if (allgood == true) {
        $('pricetbd').value = '';  
    }

    if ((allgood == true) && (ReturnType == 'calculation' || ReturnType == 'onthefly' || ReturnType == 'rna')) {
    //if ((ReturnType == 'onthefly')) {

        //alert('Pricing Total: $' + ((sequencelength * basecost) * qty).toFixed(2));

        var url = '/sc_custompricecalculation.ashx?synthscale=' + synthscale + '&fiveprime=' + fiveprime + '&threeprime=' + threeprime + '&purification=' + purification +  '&sequence=' + sequence + '&basecost=' + basecost + '&rna=' + rna + '&qty=' + qty;
        
        //AJAX POST
        new Ajax.Request(url, {
            method: "get",
            onSuccess: function(transport) {
            $('pricecalculation').innerHTML = transport.responseText; 

                } //-onSuccess
            }//-request arguments
		    ); // new ajax request
        }
        if ((ReturnType == 'addtocart') && (alertmessage == 'The price could not determinded.')) {
            alertmessage = 'The price could not determinded so it will go into your cart as TBD.';
            alert(alertmessage);
            return true
        }


    }

