function getGreeting() {
    var display
    var datetoday = new Date();
    var timenow=datetoday.getTime();
    datetoday.setTime(timenow);
    var thehour = datetoday.getHours();

    if (thehour >= 2 && thehour < 12) display = qsTr("morning");
    else if (thehour >= 12 && thehour <=17) display = qsTr("afternoon");
    else display = qsTr("evening")



    var greeting = (qsTr("Good")+" " + display + "!");
    return greeting//document.write(greeting);
}


function getAll(hls,codec,bitrate) {
    var h =false
    var retVal = ""
    if (hls === "1") h = true
    if (h) retVal = "[HLS] "
    if (codec && codec !== "UNKNOWN") retVal = retVal + "[" + codec
    if (bitrate && bitrate > 0) retVal = retVal + " : " + bitrate
    if (retVal !== "") retVal = retVal + "]"; else retVal = "[UNKNOWN]"

    return retVal
}

function getHLS(hls,codec,bitrate) {
    var h =false
    var retVal = ""
    if (hls === "1") h = true
    if (h) retVal = "HLS"

    return retVal
}

function getCodec(codec) {
    var retVal = ""
    if (codec && codec !== "UNKNOWN") retVal = codec
    return retVal
}

function getBitrate(bitrate) {
    var retVal = ""
    if (bitrate && bitrate > 0) retVal = bitrate
    return retVal
}

function getTimeStamp () {
  var now = new Date();
  var year = "" + now.getFullYear();
  var month = "" + (now.getMonth() + 1); if (month.length === 1) { month = "0" + month; }
  var day = "" + now.getDate(); if (day.length === 1) { day = "0" + day; }
  var hour = "" + now.getHours(); if (hour.length === 1) { hour = "0" + hour; }
  var minute = "" + now.getMinutes(); if (minute.length === 1) { minute = "0" + minute; }
  var second = "" + now.getSeconds(); if (second.length === 1) { second = "0" + second; }
  return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
// Random color generator
function getRandomColor() {
  var letters = '0123456789ABCDEF';
  var color = '#FF';
  for (var i = 0; i < 4; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

// future experiment to set dark or light background in favicons
function getImageLightness(imageSrc,callback) {
    var img = document.createElement("img");
    img.src = imageSrc;
    img.style.display = "none";
    document.body.appendChild(img);

    var colorSum = 0;

    img.onload = function() {
        // create canvas
        var canvas = document.createElement("canvas");
        canvas.width = this.width;
        canvas.height = this.height;

        var ctx = canvas.getContext("2d");
        ctx.drawImage(this,0,0);

        var imageData = ctx.getImageData(0,0,canvas.width,canvas.height);
        var data = imageData.data;
        var r,g,b,avg;

        for(var x = 0, len = data.length; x < len; x+=4) {
            r = data[x];
            g = data[x+1];
            b = data[x+2];

            avg = Math.floor((r+g+b)/3);
            colorSum += avg;
        }

        var brightness = Math.floor(colorSum / (this.width*this.height));
        callback(brightness);
    }
}
