/* 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


function showAddressQRCode() {
    var fromqrstring = $("#addresscodeform #from_name").val() + "\t"
            + $("#addresscodeform #from_company").val() + "\t"
            + $("#addresscodeform #from_street1").val() + "\t"
            + $("#addresscodeform #from_street2").val() + "\t"
            + "\t"
            + "\t"
            + $("#addresscodeform #from_zip").val();

    var toqrstring = $("#addresscodeform #to_name").val() + "\t"
            + $("#addresscodeform #to_company").val() + "\t"
            + $("#addresscodeform #to_street1").val() + "\t"
            + $("#addresscodeform #to_street2").val() + "\t"
            + $("#addresscodeform #to_city").val() + "\t"
            + $("#addresscodeform #to_state").val() + "\t"
            + $("#addresscodeform #to_zip").val() + "\t"
            + $("#addresscodeform #to_country").val();

    var canvas = document.createElement('canvas');

    bwipjs.toCanvas(canvas, {
        bcid: 'qrcode', // Barcode type
        text: fromqrstring, // Text to encode
        scale: 5,
        includetext: false, // Show human-readable text
        textxalign: 'center', // Always good to set this
        eclevel: 'M'
    });
    document.getElementById("addresscode-barcode-from").src = canvas.toDataURL('image/png');
    
    canvas = document.createElement('canvas');
    bwipjs.toCanvas(canvas, {
        bcid: 'qrcode', // Barcode type
        text: toqrstring, // Text to encode
        scale: 5,
        includetext: false, // Show human-readable text
        textxalign: 'center', // Always good to set this
        eclevel: 'M'
    });
    document.getElementById("addresscode-barcode-to").src = canvas.toDataURL('image/png');

    app.popup.create({el: document.getElementById("qrCodePopup")}).open();
}