// File Name: scrips.js
// Author Name: In-young Choung
// Date: March 1, 2017
// Description: This Javascript file redirects users' input values asynchronously
//              to the end points in python file.


/**
 * handling form data passed from html and relaying it to python
 *
 * @param itemtype
 * @param brandN1
 * @param brandN2
 * @param price1
 * @param price2
 * @param weight1
 * @param weightT1
 * @param weight2
 * @param weightT2
 * @param discount1
 * @param discountT1
 * @param discount2
 * @param discountT2
 */
function calc_handle(itemtype, brandN1, brandN2, price1, price2,
                     weight1, weightT1, weight2, weightT2,
                     discount1, discountT1, discount2, discountT2) {

    // create an object of XMLHttpRequest
    x = new XMLHttpRequest();

    // send an http request to /calculate which is mapped in python
    x.open("GET", '/calculate?param1=' + itemtype + '&param2=' + brandN1 + '&param3=' + brandN2 +
                    '&param4=' + price1 + '&param5=' + price2 + '&param6=' + weight1 + '&param7=' + weightT1 +
                    '&param8=' + weight2 + '&param9=' + weightT2 + '&param10=' + discount1 + '&param11=' + discountT1 +
                    '&param12=' + discount2 + '&param13=' + discountT2 + true);

    // fire the request
    x.send();
}