﻿window.onload = function() { AjaxRequest('Calculators.xml', showCalculators); }
function showCalculators(req) {
    var xmlDoc = req.responseXML;
    var models = xmlDoc.getElementsByTagName("model");

    var poorPrices = xmlDoc.getElementsByTagName("poorPrice");
    var fairPrices = xmlDoc.getElementsByTagName("fairPrice");
    var goodPrices = xmlDoc.getElementsByTagName("goodPrice");
    var likeNewPrices = xmlDoc.getElementsByTagName("likeNewPrice");
    var prices = xmlDoc.getElementsByTagName("newInBox");    
    var images = xmlDoc.getElementsByTagName("imagename");
    var editions = xmlDoc.getElementsByTagName("edition");
    for (i = 0; i < models.length; i++) {
        var model = models[i];
        var poorPrice = poorPrices[i];
        var fairPrice = fairPrices[i];
        var goodPrice = goodPrices[i];
        var likeNewPrice = likeNewPrices[i];
        var price = prices[i];        
        var image = images[i];
        var edition = editions[i];
        var modelName = model.firstChild.nodeValue;
        var poorPriceValue = poorPrice.firstChild.nodeValue;
        var fairPriceValue = fairPrice.firstChild.nodeValue;
        var goodPriceValue = goodPrice.firstChild.nodeValue;
        var likeNewPriceValue = likeNewPrice.firstChild.nodeValue;
        var priceValue = price.firstChild.nodeValue;

        var imageName = image.firstChild.nodeValue;

        var editionName = '';

        if (edition.firstChild) {
            editionName = edition.firstChild.nodeValue;
        }
        createCalculator(modelName, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, priceValue, imageName, editionName);
    }
}

function createCalculator(calculatorID, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, price, image, edition) {

    var calcTemplate = new Template('<td class="calcselect">' + '<a href="javascript:void(0);" id="#{calcID}_link" onclick="addCalculatorDetails(\'#{calcID}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\',\'#{imageName}\',\'#{calcEdition}\');">' + '<img src="images/#{imageName}" alt="#{calcID}" style="border:none;" align="top" />' + '<div class="calcModelLabel">#{calcID}</div>' + '<div style="height: 25px">#{calcEdition}</div>' + '</a>' + '<table style="width: 80%; text-align: center; margin-top: 5px;" cellpadding="0" cellspacing="0" align="center">' + '<tr>' + '<td style="width: 23px"><a id="#{calcID}_add" href="javascript:void(0);" onclick="addCalculatorDetails(\'#{calcID}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\',\'#{imageName}\',\'#{calcEdition}\');"><img src="images/addCalc.gif" alt="+" width="23" height="23" style="border:none" /></a></td>' + '<td style="border-top: 1px solid #cccccc; border-bottom: 1px solid #cccccc; font-weight: bold" id="#{calcID}_cnt">0</td>' + '<td style="width: 23px"><a id="#{calcID}_remove" href="javascript:void(0);" onclick="removeCalculatorDetails(\'#{calcID}\');"><img src="images/subCalc.gif" alt="+"  width="23" height="23" style="border:none" /></a></td>' + '</tr>' + '</table>' + '</td>');
    var vars = { calcID: calculatorID, poorPriceValue: poorPriceValue, fairPriceValue: fairPriceValue, goodPriceValue: goodPriceValue, likeNewPriceValue: likeNewPriceValue, calcPrice: price, imageName: image, calcEdition: edition };
    Element.insert($('calculatorContainer'), calcTemplate.evaluate(vars));
}
function removeCalculatorDetails(calculatorID) {
    var el = $(calculatorID + '_list');
    if (el !== null) {
        el.lastChild.remove();
        refreshModelList(calculatorID); updateTotalPrice();
    }
    handleHelpInfo();
}
function refreshModelList(calculatorID) {
    var listName = calculatorID + '_list';
    if ($(listName) != null) {
        var childEl = $(listName).descendants();
        if (childEl.length < 2) {
            $(listName).remove();
        }
        getModelListCount(calculatorID);
    }
}
function addCalculatorDetails(calculatorID, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, calculatorPrice, calculatorImage, calculatorEdition) {
    var listName = calculatorID + '_list';
    if ($(listName) == null) {
        createModelContainer(calculatorID, calculatorEdition);
        createCalculatorDetails(calculatorID, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, calculatorPrice, 0, calculatorImage, calculatorEdition);
        getModelListCount(calculatorID);
    }
    else {
        createCalculatorDetails(calculatorID, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, calculatorPrice, Math.floor(Math.random() * 100001), calculatorImage, calculatorEdition);
        getModelListCount(calculatorID);
    }
    if (validateCalcList() == true) {
        $('calcListErrorMsg').hide();
    }
    updateTotalPrice(); handleHelpInfo();
}
function handleHelpInfo() {
    if ($A($('selectedContainer').descendants()).length > 0) {
        $('totalPriceContainer').show();
        $('buybackHelp').hide();
        $('submitBar').show();
    }
    else {
        $('totalPriceContainer').hide();
        $('buybackHelp').show();
        $('submitBar').hide();
    }
}
function getModelListCount(calculatorID) {
    var listName = calculatorID + '_list';
    if ($(listName) != null) {
        var listChildren = $(listName).childElements();
        var modelCount = listChildren.length - 1;
        $(calculatorID + '_cnt').innerHTML = modelCount;
        $(calculatorID + '_cnt').style.backgroundColor = '#ffffcc';
    }
    else {
        $(calculatorID + '_cnt').innerHTML = '0';
        $(calculatorID + '_cnt').style.backgroundColor = '#ffffff';
    }
}
function createCalculatorDetails(calculatorID, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, calculatorPrice, calculatorCount, calculatorImage, calculatorEdition) {
    var calcTemplate = new Template('<table id="#{calcID}_#{calcCount}" title="#{calcID}" class="calculatorDetailsSelected" cellpadding="10" cellspacing="0">' + '<tr>' + '<td style="width: 80px; text-align: center;">' + '<img id="image#{calcID}_#{calcCount}" src="images/#{calcImage}" alt="#{calcID}" style="border:none;" align="top" />' + '<input type="hidden" id="edition#{calcID}_#{calcCount}" value="#{calcEdition}" />' + '</td>' + '<td valign="top">' + '<strong>Accessories</strong><br />' + '<input type="checkbox" onclick="updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="chkCover#{calcID}_#{calcCount}" name="chkCover#{calcID}_#{calcCount}" id="chkCover" value="Cover" /> Cover' + '<input type="checkbox" onclick="updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');"  id="chkLinkCable#{calcID}_#{calcCount}" name="chkLinkCable#{calcID}_#{calcCount}" id="chkLinkCable" value="Link Cable" /> Link Cable' + '<br /><br />' + '<strong>Condition</strong><br />' + '<span class="hotspot" onmouseover="tooltip.show(\'<b>Poor</b><br>Any of the following means poor condition:<br>+ Cracked Housing<br>+ Deep Scratches<br>+ Missing Screws<br>+ Broken or Missing Battery Cover<br>+ Scratched Display<br>+ Stickers, Marker, White-out, etc.<br>+ Dents\');" onmouseout="tooltip.hide();"><input type="radio" onclick="enableAccessories(\'#{calcID}\',\'#{calcCount}\');updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="radCond#{calcID}_#{calcCount}" name="radCond#{calcID}_#{calcCount}" value="Poor" /> Poor' + '</span><span class="hotspot" onmouseover="tooltip.show(\'<b>Fair</b><br>Any of the following means fair condition:<br>+ Heavy Use<br>+ Dents or Scratches<br>+ Permanent Marks<br>+ One or More Missing Rubber Feet\');" onmouseout="tooltip.hide();"> <input type="radio" onclick="enableAccessories(\'#{calcID}\',\'#{calcCount}\');updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="radCond#{calcID}_#{calcCount}" name="radCond#{calcID}_#{calcCount}" value="Fair" /> Fair' + '</span><span class="hotspot" onmouseover="tooltip.show(\'<b>Good</b><br>Any of the following means good condition:<br>+ Normal Use<br>+ Light Scratches or Scuff Marks\');" onmouseout="tooltip.hide();"><input type="radio" onclick="enableAccessories(\'#{calcID}\',\'#{calcCount}\');updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="radCond#{calcID}_#{calcCount}" name="radCond#{calcID}_#{calcCount}" value="Good" checked="checked" /> Good' + '</span><span class="hotspot" onmouseover="tooltip.show(\'<b>Like New</b><br>Like New means:<br>+ No Cosmetic Flaws<br>+ No Signs of Use<br>+ Looks Shiny and Brand New\');" onmouseout="tooltip.hide();"> <input type="radio" onclick="enableAccessories(\'#{calcID}\',\'#{calcCount}\');updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="radCond#{calcID}_#{calcCount}" name="radCond#{calcID}_#{calcCount}" value="Like New" />Like New' + '</span><span class="hotspot" onmouseover="tooltip.show(\'<b>New-In-Box</b><br>New-In-Box means:<br>+ Brand New Retail Packaging<br>+ Never Opened (100% Sealed)\');" onmouseout="tooltip.hide();"><input type="radio" onclick="disableAccessories(\'#{calcID}\',\'#{calcCount}\');updateUnitPrice(\'#{calcID}\',\'#{calcCount}\',\'#{poorPriceValue}\',\'#{fairPriceValue}\',\'#{goodPriceValue}\',\'#{likeNewPriceValue}\',\'#{calcPrice}\');" id="radCond#{calcID}_#{calcCount}" name="radCond#{calcID}_#{calcCount}" value="New-In-Box" /> New-In-Box' + '</span></td>' + '<td valign="top" style="text-align: right">' + '<a href="javascript:void(0);" class="detailsRemove" onclick="$(\'#{calcID}_#{calcCount}\').remove();refreshModelList(\'#{calcID}\');updateTotalPrice(); handleHelpInfo();"><img src="images/removeCalc.gif" alt="Remove"  width="80" height="14" style="border: none" /></a><br />' + '<div style="margin-top: 50px;">' + '<strong>We Pay:</strong><br />' + '<span class="unitPriceLabel">$<span id="spanPrice#{calcID}_#{calcCount}" title="#{calcPrice}" class="calcPrice">#{calcPrice}</span></span>' + '</div>' + '</td>' + '</tr>' + '</table>');
    var vars = { calcID: calculatorID, poorPriceValue: poorPriceValue, fairPriceValue: fairPriceValue, goodPriceValue: goodPriceValue, likeNewPriceValue: likeNewPriceValue, calcPrice: calculatorPrice, calcCount: calculatorCount, calcImage: calculatorImage, calcEdition: calculatorEdition };
    Element.insert($(calculatorID + '_list'), calcTemplate.evaluate(vars));
    updateUnitPrice(calculatorID, calculatorCount, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, calculatorPrice);
}
function enableAccessories(calcID, calcCount) {
    var chkCover = $('chkCover' + calcID + '_' + calcCount);
    var chkLinkCable = $('chkLinkCable' + calcID + '_' + calcCount);
    chkCover.disabled = false;
    chkLinkCable.disabled = false;
}
function disableAccessories(calcID, calcCount) {
    var chkCover = $('chkCover' + calcID + '_' + calcCount);
    var chkLinkCable = $('chkLinkCable' + calcID + '_' + calcCount);
    chkCover.disabled = true;
    chkLinkCable.disabled = true;
    chkCover.checked = true;
    chkLinkCable.checked = true;
}
function updateUnitPrice(calcID, calcCount, poorPriceValue, fairPriceValue, goodPriceValue, likeNewPriceValue, originalPrice) {
    var spanPrice = $('spanPrice' + calcID + '_' + calcCount);
    var chkCover = $('chkCover' + calcID + '_' + calcCount);
    var chkLinkCable = $('chkLinkCable' + calcID + '_' + calcCount);
    var currPrice = originalPrice;
    //    var coverAmount = -1;
    var coverAmount = 0;
    //    var linkCableAmount = -1;
    var linkCableAmount = 0;
    var payPrice = parseFloat(originalPrice);
    if (chkCover.checked) {
        //        coverAmount = 0;
        coverAmount = 1;
    }
    if (chkLinkCable.checked) {
        //       linkCableAmount = 0;
        linkCableAmount = 1;
    }
    switch (getRadioButtonValue('radCond' + calcID + '_' + calcCount)) {
        case 'Poor':
            //payPrice = parseFloat(originalPrice) * .30;
            payPrice = parseFloat(poorPriceValue);
            break;
        case 'Fair':
            payPrice = parseFloat(fairPriceValue);
            break;
        case 'Good':
            payPrice = parseFloat(goodPriceValue);
            break;
        case 'Like New':
            payPrice = parseFloat(likeNewPriceValue);
            break;
        default:
            coverAmount = 0;
            linkCableAmount = 0;
            payPrice = parseFloat(originalPrice);
    }

    var totalUnitPrice = Math.round(payPrice + coverAmount + linkCableAmount);
    spanPrice.title = formatCurrency(totalUnitPrice);
    spanPrice.update(formatCurrency(totalUnitPrice));
    updateTotalPrice();
}
function updateTotalPrice() {
    var prices = $$('span.calcPrice');
    var totalPrice = 0;

    for (i = 0; i < prices.length; i++) {
        var discount = 0;
        if ($('couponOrderType').value == "C") {
            var unitPrice = parseFloat(prices[i].title)
            discount = parseFloat($('couponValue').value)
            if ($('couponvalueType').value == "P")
                discount = (unitPrice * discount) / 100;
            prices[i].update(formatCurrency(unitPrice + discount));
        }
        else {
            prices[i].update(prices[i].title);
        }

        var price = parseFloat(prices[i].innerHTML);
        totalPrice += price;
    }
    var discount = 0;
    if ($('couponOrderType').value == "O") {
        discount = parseFloat($('couponValue').value)
        if ($('couponvalueType').value == "P")
            discount = (totalPrice * discount) / 100;
    }

    $('totalPrice').update(formatCurrency(totalPrice + discount));
    $('totalPrice').show();
}
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g, ''); if (isNaN(num))
        num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num * 100 + 0.50000000001); cents = num % 100; num = Math.floor(num / 100).toString(); if (cents < 10)
        cents = "0" + cents; for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + ',' +
    num.substring(num.length - (4 * i + 3)); return (((sign) ? '' : '-') + '' + num + '.' + cents);
}
function createModelContainer(calculatorID, calculatorEdition) {
    var calcTemplate = new Template('<div id="#{calcID}_list"><div style="font-size: 18px; font-weight: bold; color: #002398; border-bottom: 1px solid #3159DE">#{calcID} #{calcEdition}</div></div>');
    var vars = { calcID: calculatorID, calcEdition: calculatorEdition };
    Element.insert($('selectedContainer'), calcTemplate.evaluate(vars));
}

function selectPayment(el) {
    var payElements = $('paymentOptions').immediateDescendants();
    for (i = 0; i < payElements.length; i++) {
        var payElement = payElements[i];
        payElement.className = 'pay';
        (el.id == 'PayPal') ? $('paypalNotifier').show() : $('paypalNotifier').hide();
    }
    el.parentNode.className = 'paySelected';
}

function submitCalcBuyback() {
    if (validateCalcList() == false) {
        showError($('calcListErrorMsg'), 'You must add at least one calculator to your list.');
        $('calcListErrorMsg').show();
    }
    else {
        $('calcListErrorMsg').hide();
        Modalbox.show($('paymentForm'), { title: 'Send My Payment Here', width: 600, overlayClose: false, overlayDuration: 0, slideUpDuration: 0, resizeDuration: 0, inactiveFade: true, autoFocusing: true }); fillUserInfo();
    }
}

function fillUserInfo() { var jsonObject = readCookie('CalculatorCustomer'); if (jsonObject != null) { var jsonText = jsonObject.substr(0, jsonObject.length - 1); jsonText = jsonObject.substr(1, jsonText.length - 1); var userInfo = jsonText.evalJSON(); $('txtPayFirstName').value = userInfo.FirstName; $('txtPayLastName').value = userInfo.LastName; $('txtPayAddress1').value = userInfo.Address1; $('txtPayAddress2').value = userInfo.Address2; $('txtPayCity').value = userInfo.City; $('txtPayZip').value = userInfo.Zip; $('txtPayEmail').value = userInfo.Email; $('txtPayPalEmail').value = userInfo.PayPalEmail; selectValueFromDropDown($('ddPayState'), userInfo.State); selectValueFromRadio('paymentType', userInfo.PaymentType); selectPayment($(userInfo.PaymentType)); } }

function submitPaymentInfo() {
    if (validatePaymentInfo() == true) { AjaxRequest('Scripts/getNewBuybackID.aspx', insertData); }
}

function getCouponInfo() {
    if ($('txtCouponCode').value != "") {
        AjaxRequest('Scripts/getCouponInfo.aspx?couponCode=' + $('txtCouponCode').value, validateCoupon);
    }
    else {
        clearCoupon();
        updateTotalPrice();
    }
}

function validateCoupon(req) {
    var couponInfo = req.responseText;
    switch (couponInfo) {
        case '0':
            showError($('couponValMsg'), 'Coupon Is Already Used. Try another one');
            $('couponValMsg').show();
            $('couponAppliedMg').hide()
            clearCoupon();
            break;
        case '1':
            showError($('couponValMsg'), 'Invalid CouponCode or Coupon has Expired');
            $('couponValMsg').show();
            $('couponAppliedMg').hide()
            clearCoupon()
            break;
        case '2':
            showError($('couponValMsg'), 'Invalid CouponCode or Coupon has Expired');
            $('couponValMsg').show();
            $('couponAppliedMg').hide()
            clearCoupon()
            break;
        default:
            $('couponValMsg').hide();
            showError($('couponAppliedMg'), '(Coupon Applied : ' + $('txtCouponCode').value + ')');
            $('couponAppliedMg').show();
            var coupons = couponInfo.split(",");
            $('couponValue').value = coupons[0];
            $('couponvalueType').value = coupons[1];
            $('couponOrderType').value = coupons[2];
    }
    updateTotalPrice();

}
function clearCoupon() {
    $('txtCouponCode').value = ""
    $('couponValue').value = ""
    $('couponvalueType').value = ""
    $('couponOrderType').value = ""
}

function insertData(req) {
    var buybackID = req.responseText;
    var customerID = '';
    var customerReferralID = '';
    var referral = $('ddReferral').value;
    if ($('hidCustomerID').value != '') {
        customerID = $('hidCustomerID').value;
    }
    if ($('hidReferralCustID').value != '') {
        customerReferralID = $('hidReferralCustID').value;
    }
    AjaxRequest('Scripts/InsertBuyback.aspx?id=' + buybackID + '&custid=' + customerID + '&payType=' + getRadioButtonValue('paymentType') + '&totalPrice=' + $('totalPrice').innerHTML + '&referral=' + referral + '&rid=' + customerReferralID + '&couponCode=' + $('txtCouponCode').value,
            function(req2) {
                customerID = req2.responseText;
                var customerURL;
                ($('hidCustomerID').value == '') ? customerURL = 'Scripts/InsertCustomer.aspx?id=' + customerID + '&fn=' + $('txtPayFirstName').value + '&ln=' + $('txtPayLastName').value + '&addr1=' + $('txtPayAddress1').value + '&addr2=' + $('txtPayAddress2').value + '&city=' + $('txtPayCity').value + '&state=' + $('ddPayState').value + '&zip=' + $('txtPayZip').value + '&email=' + $('txtPayEmail').value : customerURL = 'Scripts/Proxy.aspx';
                // +'&paypal='+$('txtPayPalEmail').value
                AjaxRequest(customerURL,
                function(req3) { });
                var calcLists = $("selectedContainer").immediateDescendants();
                for (i = 0; i < calcLists.length; i++) {
                    var list = calcLists[i];
                    var calculators = list.immediateDescendants();
                    for (j = 1; j < calculators.length; j++) {
                        var calculator = calculators[j];
                        var selectedID = calculator.id;
                        var modelName = calculator.title;
                        var modelPrice = $('spanPrice' + selectedID).innerHTML;
                        var price = $('spanPrice' + selectedID).title;
                        var calculatorCover = $('chkCover' + selectedID).checked;
                        var calculatorLinkCable = $('chkLinkCable' + selectedID).checked;
                        var radCondition = getRadioButtonValue('radCond' + selectedID);
                        var imageURL = $('image' + selectedID).src;
                        var calculatorEdition = $('edition' + selectedID).value;
                        AjaxRequest('Scripts/InsertBuybackDetails.aspx?buybackID=' + buybackID + '&model=' + modelName + '&cover=' + calculatorCover + '&linkCable=' + calculatorLinkCable + '&condition=' + radCondition + '&price=' + modelPrice + '&imageURL=' + imageURL + '&actualPrice=' + price,
                        function(req4) { });
                    }
                }
            });
    var nextPage = '';
    ($('chkCreateAccount').checked) ? nextPage = 'CreateAccount.aspx?custid=' + customerID + "&id=" + buybackID : nextPage = 'Process.aspx?id=' + buybackID;
    window.location = nextPage;
}

function getSelectedCalculatorsJSON() {
    var strJSON = '['; var calcLists = $("selectedContainer").immediateDescendants();
    for (i = 0; i < calcLists.length; i++) {
        var list = calcLists[i];
        var calculators = list.immediateDescendants();
        for (j = 1; j < calculators.length; j++) {
            var calculator = calculators[j];
            var selectedID = calculator.id;
            var modelName = calculator.title;
            var modelPrice = $('spanPrice' + selectedID).innerHTML;
            var calculatorCover = $('chkCover' + selectedID).checked;
            var calculatorLinkCable = $('chkLinkCable' + selectedID).checked;
            var radCondition = getRadioButtonValue('radCond' + selectedID);
            var imageURL = $('image' + selectedID).src;
            var calculatorEdition = $('edition' + selectedID).value;
            var objCalculator = { Model: modelName, Cover: calculatorCover, LinkCable: calculatorLinkCable, Condition: radCondition, Price: modelPrice, Image: imageURL, Edition: calculatorEdition }
            strJSON += Object.toJSON(objCalculator) + ","
        }
    }
    return strJSON.substr(0, strJSON.length - 1) + "]";
}
function getCustomerJSON() {
    var strJSON = '[';
    var objCustomer = { FirstName: $('txtPayFirstName').value,
        LastName: $('txtPayLastName').value,
        Address1: $('txtPayAddress1').value,
        Address2: $('txtPayAddress2').value,
        City: $('txtPayCity').value,
        State: $('ddPayState').value,
        Zip: $('txtPayZip').value,
        Email: $('txtPayEmail').value,
        PayPalEmail: $('txtPayPalEmail').value,
        PaymentType: getRadioButtonValue('paymentType')
    }
    strJSON += Object.toJSON(objCustomer) + ","
    return strJSON.substr(0, strJSON.length - 1) + "]";
}


function getRadioButtonValue(id) {
    var radio = document.getElementsByName(id);
    for (var ii = 0; ii < radio.length; ii++) {
        if (radio[ii].checked)
            return radio[ii].value;
    }
}
function selectValueFromDropDown(el, ivalue) {
    for (i = 0; i < el.options.length; i++) {
        if (el.options[i].value == ivalue) {
            el.options[i].selected = true; break;
        }
    }
}
function selectValueFromRadio(id, value) {
    var radio = document.getElementsByName(id);
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].value == value)
            radio[i].checked = 'checked';
    }
}
function showError(el, msg) {
    el.innerHTML = msg; el.className = 'error';
}
function clearDefaultText(el, defaultText) {
    if (el.value == defaultText) {
        el.value = '';
    }
}
function restoreDefaultText(el, defaultText) {
    if (el.value == '') {
        el.value = defaultText;
    }
}
