function DatetimeBetween(today, startOfYear) {
    var msecPerMinute = 1000 * 60;
    var msecPerHour = msecPerMinute * 60;
    var msecPerDay = msecPerHour * 24;

    // Determine the current date and time.
    //var today = new Date();

    // Determine January 1, at midnight, of the current year.
    var january = 0;
    //var startOfYear = new Date();
    startOfYear.setMonth(january);
    startOfYear.setDate(1);
    startOfYear.setHours(0, 0, 0, 0);

    // Determine the difference in milliseconds.
    var interval = today.getTime() - startOfYear.getTime();

    // Calculate how many days the interval contains. Subtract that
    // many days from the interval to determine the remainder.
    var days = Math.floor(interval / msecPerDay);
    interval = interval - (days * msecPerDay);

    // Calculate the hours, minutes, and seconds.
    var hours = Math.floor(interval / msecPerHour);
    interval = interval - (hours * msecPerHour);

    var minutes = Math.floor(interval / msecPerMinute);
    interval = interval - (minutes * msecPerMinute);

    var seconds = Math.floor(interval / 1000);

    // Display the result.
    //var msg = days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.";
    var msg = hours + " : " + minutes + " : " + seconds;
    return msg;
}

function date_time(id) {
    date = new Date;
    year = date.getFullYear();
    month = date.getMonth();
    months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'Jully', 'August', 'September', 'October', 'November', 'December');
    d = date.getDate();
    day = date.getDay();
    days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    h = date.getHours();
    if (h < 10) {
        h = "0" + h;
    }
    m = date.getMinutes();
    if (m < 10) {
        m = "0" + m;
    }
    s = date.getSeconds();
    if (s < 10) {
        s = "0" + s;
    }
    result = '' + days[day] + ' ' + months[month] + ' ' + d + ' ' + year + ' ' + h + ':' + m + ':' + s;
    document.getElementById(id).innerHTML = result;

    return true;
}

function StarFieldSaver(settings) {
    // default values
    this.speed = 50;
    this.nStars = 100;
    this.zIndex = 1000;

    // override with settings values
    if (settings.speed) this.speed = settings.speed;
    if (settings.nStars) this.nStars = settings.nStars;
    if (settings.zIndex) this.zIndex = settings.zIndex;
}
StarFieldSaver.prototype.init = function() {

    self.parent.location = "../LogOut.aspx";

//    this.oCanvas = document.createElement("div");
//    document.body.appendChild(this.oCanvas);

//    this.oCanvas.id = "scrsvrCanvas";
//    this.oCanvas.style.zIndex = this.zIndex;
//    this.oCanvas.style.position = "absolute";
//    this.oCanvas.style.marginBottom = "0";
//    this.oCanvas.style.marginLeft = "0";
//    this.oCanvas.style.marginTop = "0";
//    this.oCanvas.style.marginRight = "0";
//    this.oCanvas.style.border = "0px none black";

//    this.oCanvas.style.backgroundColor =  "Transparent";
//    this.oCanvas.style.backgroundRepeat = "no-repeat";
//    this.oCanvas.style.backgroundPosition = "center center";

//    this.oCanvas.style.left = document.body.scrollLeft + "px";
//    this.oCanvas.style.top = document.body.scrollTop + "px";
//    this.oCanvas.style.width = document.body.parentElement.clientWidth + "px";
//    this.oCanvas.style.height = document.body.parentElement.clientHeight + "px";
//    this.width = document.body.parentElement.clientWidth;
//    this.height = document.body.parentElement.clientHeight;

//    var pathname1 = document.location.pathname.split('/')
//    var filename1 = pathname1[pathname1.length - 1];
//    if (nScreenSaver == 0) {
//        this.oCanvas.style.backgroundColor = "Black";
//        this.oCanvas.style.backgroundImage = "url(../Images/HiggsBoson.jpg)";
//        //        if (filename1.toUpperCase() != "APPDETAIL.ASPX") {
//        //            if (FileExists("../Images/HiggsBoson.jpg") == false)
//        //                this.oCanvas.style.backgroundImage = "url(Images/HiggsBoson.jpg)";
//        //        }
//        if ((filename1.toUpperCase() == "BRANCHSELECT.ASPX") ||
//            (filename1.toUpperCase() == "BOOKSELECT.ASPX") ||
//            (filename1.toUpperCase() == "DASHBOARD.ASPX") ||
//            (filename1.toUpperCase() == "REPORTVIEWER.ASPX")) {
//            this.oCanvas.style.backgroundImage = "url(../Images/HiggsBoson.jpg)";
//        }
//    }
//    else {
//        this.oCanvas.style.backgroundImage = "url(../Images/" + nScreenSaver + ".png)";
//      
//        if ((filename1.toUpperCase() == "BRANCHSELECT.ASPX") ||
//            (filename1.toUpperCase() == "BOOKSELECT.ASPX") ||
//            (filename1.toUpperCase() == "DASHBOARD.ASPX") ||
//            (filename1.toUpperCase() == "REPORTVIEWER.ASPX")) {
//            this.oCanvas.style.backgroundImage = "url(Images/" + nScreenSaver + ".png)";
//        }
//        this.oCanvas.style.backgroundSize = getBrowserWindowSize().width + 'px ' + getBrowserWindowSize().height + 'px';
//    }

//    var spanTag1 = document.createElement("span");
//    spanTag1.id = "scrsvrspan1";
//    spanTag1.style.color = "white";
//    this.oCanvas.appendChild(spanTag1);

//    var spanTag2 = document.createElement("span");
//    spanTag2.id = "scrsvrspan2";
//    spanTag2.style.color = "red";
//    this.oCanvas.appendChild(spanTag2);

//    date_time(document.getElementById('scrsvrspan1').id);

//    this.g = new Graphics(this.oCanvas);
//    this.g.penColor = "white";  //getColor();

//    this.aPoints = new Array();

    ticker = setInterval("tick( )", 1000);
    tick();
}
StarFieldSaver.prototype.start = function() {
    if (this.bActive) return;
    this.bActive = true;
    elapsed = -1;

    if (!this.oCanvas) this.init();
    this.oCanvas.style.visibility = "visible";
    this.tick();
}
StarFieldSaver.prototype.stop = function() {
    if (!this.bActive) return;
    elapsed = -1;

    window.clearTimeout(this.timerID);
    
    this.oCanvas.style.visibility = "hidden";

    for (var i in this.aPoints) {
        this.aPoints[i].undraw();
    }
    this.aPoints = new Array();

    this.bActive = false;
}
StarFieldSaver.prototype.tick = function() {
    this.oCanvas.style.left = document.body.scrollLeft + "px";
    this.oCanvas.style.top = document.body.scrollTop + "px";
 
    this.oCanvas.style.width = document.body.parentElement.clientWidth + "px";
    this.oCanvas.style.height = document.body.parentElement.clientHeight + "px";
    this.width = document.body.parentElement.clientWidth;
    this.height = document.body.parentElement.clientHeight;


    if (nScreenSaver == 0) {
        //drawRibbon();
            
            var cx = this.width / 2;
            var cy = this.height / 2;
            for (var i in this.aPoints) {
                var p = this.aPoints[i];
                var dx = p.x - cx;
                var dy = p.y - cy;

                // move point outwards
                p.x += dx / 50;
                p.y += dy / 50;
                if ((p.x < 0) || (p.x > this.width - Math.ceil(p.n / 50)) || (p.y < 0) || (p.y > this.height - Math.ceil(p.n / 50))) {
                    p.x = Math.random() * this.width;
                    p.y = Math.random() * this.height;
                    p.n = 0;
                }
                p.move(Math.floor(p.x), Math.floor(p.y));

                // resize as they get closer
                p.setSize(Math.ceil(p.n++ / 50))
            }

            while (this.aPoints.length < this.nStars) {
                var x = Math.random() * this.width;
                var y = Math.random() * this.height;
                var p = this.g.drawPoint(Math.floor(x), Math.floor(y));
                p.setSize(1);
                p.x = x;
                p.y = y;
                p.n = 0;
                this.g.penColor = getColor();
                this.aPoints.push(p);
            }
    }

    //var x = new Date()
    //document.getElementById('scrsvrspan1').innerHTML = x;
    date_time(document.getElementById('scrsvrspan1').id);

    var pThis = this;
    var f = function() { pThis.tick(); }
    this.timerID = window.setTimeout(f, this.speed);
}

function ScreenSaver(settings) {
    this.settings = settings;

    this.nTimeout = this.settings.timeout;

    document.body.screenSaver = this;

    // link in to body events
    document.body.onmousemove = ScreenSaver.prototype.onevent;
    document.body.onmousedown = ScreenSaver.prototype.onevent;
    document.body.onkeydown = ScreenSaver.prototype.onevent;
    document.body.onkeypress = ScreenSaver.prototype.onevent;

    var pThis = this;
    var f = function() { pThis.timeout(); }
    this.timerID = window.setTimeout(f, this.nTimeout);
}
ScreenSaver.prototype.timeout = function() {
    if (!this.saver) {
        this.saver = this.settings.create();
    }
    this.saver.start();
}
ScreenSaver.prototype.signal = function() {
    if (this.saver) {
        this.saver.stop();
    }

    window.clearTimeout(this.timerID);

    var pThis = this;
    var f = function() { pThis.timeout(); }
    this.timerID = window.setTimeout(f, this.nTimeout);
}

ScreenSaver.prototype.onevent = function(e) {
    this.screenSaver.signal();
}

function getColor() {
    cnt = cnt + 1;
    if (cnt >= 11)
        cnt = 1;
    if (cnt == 1)
        return "white";
    if (cnt == 2)
        return "red";
    if (cnt == 3)
        return "yellow";
    if (cnt == 4)
        return "green";
    if (cnt == 5)
        return "lime";
    if (cnt == 6)
        return "blue";
    if (cnt == 7)
        return "silver";
    if (cnt == 8)
        return "cyan";
    if (cnt == 9)
        return "lightskyblue";
    if (cnt == 10)
        return "violet";

}
var nScreenSaver = 0
var seconds = null;
var ticker = null;
var stdate;
var cnt = 0;
var saver;
var elapsed = null;
//Lets make some particles
var particles = [];
function initScreenSaver(ScrSvr,AutoLogOutTime) {
    
    if (ScrSvr == null)
        ScrSvr = -1;
    if (ScrSvr == undefined)
        ScrSvr = -1;
    nScreenSaver = ScrSvr;
    
    AutoLogOutTime = AutoLogOutTime * 1000 * 60

    if (nScreenSaver == -1)
        return;

    for (var i = 0; i < 25; i++) {
        particles.push(new particleRibbon());
    }

    cnt = 0;
    stdate = new Date();
    seconds = -1;
    elapsed = -1;
    saver = new ScreenSaver({ timeout: AutoLogOutTime, speed: 50, nStars: 500, zIndex: 100, create: function() { return new StarFieldSaver(this); } });
}

function tick() {
    ++seconds;
    ++elapsed;
    var secs = elapsed;
    var hrs = Math.floor(secs / 3600);
    secs %= 3600;
    var mns = Math.floor(secs / 60);
    secs %= 60;
    var elapsedtime = (hrs < 10 ? "0" : "") + hrs
                   + ":" + (mns < 10 ? "0" : "") + mns
                   + ":" + (secs < 10 ? "0" : "") + secs;
    if (document.getElementById("scrsvrspan2") != null)
        document.getElementById("scrsvrspan2").innerHTML = "  Elapsed - " + elapsedtime;
}

function FileExists(filename) {
    var imgtmp = new Image;
    imgtmp.src = filename;
    var nh = imgtmp.naturalHeight;
    var nw = imgtmp.naturalWidth;

    if (nw > 0) //(tmp.complete)
        return true;
    else
        return false;
}


function particleRibbon() {
    //location on the canvas
    this.location = { x: Math.random() * this.width, y: Math.random() * this.height };
    //radius - lets make this 0
    this.radius = 0;

    //speed
    this.speed = 3;
    //steering angle in degrees range = 0 to 360
    this.angle = Math.random() * 360;
    //colors

    var r = Math.round(Math.random() * 255);
    var g = Math.round(Math.random() * 255);
    var b = Math.round(Math.random() * 255);
    var a = Math.random();

    this.rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
}

//Lets draw the particles

function drawRibbon() {
    //re-paint the BG
    //Lets fill the canvas black
    //reduce opacity of bg fill.
    //blending time
    var ctx = document.getElementById('scrsvrCanvas').getContext('2d');

    //var ctx = rCanvas.getContext('2d');

    ctx.globalCompositeOperation = "source-over";
    ctx.fillStyle = "rgba(0, 0, 0, 0.01)";
    ctx.fillRect(0, 0, this.width, this.height);
    ctx.globalCompositeOperation = "lighter";

    for (var i = 0; i < particles.length; i++) {

        var p = particles[i];
        ctx.fillStyle = "white";
        ctx.fillRect(p.location.x, p.location.y, p.radius, p.radius);

        //Lets move the particles
        //So we basically created a set of particles moving in random direction
        //at the same speed
        //Time to add ribbon effect
        for (var n = 0; n < particles.length; n++) {
            var p2 = particles[n];
            //calculating distance of particle with all other particles
            var yd = p2.location.y - p.location.y;
            var xd = p2.location.x - p.location.x;
            var distance = Math.sqrt(xd * xd + yd * yd);
            //draw a line between both particles if they are in 200px range
            if (distance < 200) {
                ctx.beginPath();
                ctx.lineWidth = 1;
                ctx.moveTo(p.location.x, p.location.y);
                ctx.lineTo(p2.location.x, p2.location.y);
                ctx.strokeStyle = p.rgba;
                ctx.stroke();
                //The ribbons appear now.
            }
        }

        //We are using simple vectors here
        //New x = old x + speed * cos(angle)
        p.location.x = p.location.x + p.speed * Math.cos(p.angle * Math.PI / 180);
        //New y = old y + speed * sin(angle)
        p.location.y = p.location.y + p.speed * Math.sin(p.angle * Math.PI / 180);
        //You can read about vectors here:
        //http://physics.about.com/od/mathematics/a/VectorMath.htm

        if (p.location.x < 0) p.location.x = this.width;
        if (p.location.x > this.width) p.location.x = 0;
        if (p.location.y < 0) p.location.y = this.height;
        if (p.location.y > this.height) p.location.y = 0;
    }
}

//http: //jdstiles.com/colorchart.html 

