﻿var isMetric = getCookie("weight");
if (isMetric == null || isMetric == "" || isMetric == 1 || isMetric == "1") {
    isMetric = 1;
} else {
    isMetric = 0;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + unescape(value) + "; path=/" + 
((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function changeWeight(isMetricClicked) {
    metricImg = document.getElementById("metric");
    impImg = document.getElementById("imperial");
    if (isMetric == 1 && isMetricClicked == 0) {
        setCookie("weight", "0", 7);
   //     isMetric = 0;
   //     impImg.src = "images/imgLayout/imperialOn.png";
  //      metricImg.src = "images/imgLayout/metric" + imgSuff + ".png";

 //       updateWeights();
        
    } else if (isMetricClicked == 1) {
    setCookie("weight", "1", 7);
  //  isMetric = 1;
  //  impImg.src = "images/imgLayout/imperial" + imgSuff + ".png";
  //  metricImg.src = "images/imgLayout/metricOn.png";

   //     updateWeights();
    }

    location.reload(true);

    
}

// Adds commas to number
function nicePrice(nStr) {

    nStr = roundNumber(nStr, 2);

    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    if (x2.length == 2) {
        x2 += "0";
    }
    return x1 + x2;
}
function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}
