
    
function weekendAreas(axes) {
        var markings = [];
        var d = new Date(axes.xaxis.min);
        // go to the first Saturday
        d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
        d.setUTCSeconds(0);
        d.setUTCMinutes(0);
        d.setUTCHours(0);
        var i = d.getTime();
        do {
            // when we don't set yaxis the rectangle automatically
            // extends to infinity upwards and downwards
            markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
            i += 7 * 24 * 60 * 60 * 1000;
        } while (i < axes.xaxis.max);

        return markings;
    }
function dateConvert(ms) {
	var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	var d = new Date();
	d.setTime(ms);
	return monthNames[d.getUTCMonth()] + ' ' + d.getDate() + 'th';
}



function timeConvert(ms)
{
	var secs = ms/1000;
	var t = new Date(1970,0,1);
	t.setSeconds(secs);
	var s = t.toTimeString().substr(0,5);
	if(secs > 86399) s="24:00";
	//s = Math.floor((t - Date.parse("1/1/70")) / 3600000) + s.substr(2);


	var time = s.split(':');
	var timeTip = '';

	if (time[0].substring(0,1) == '0') {
		time[0] = time[0].substring(1);
	}
	if (time[1].substring(0,1) == '0') {
		time[1] = time[1].substring(1);
	}
	
	if (time[0] != '0') {
		if (time[0] == '1') {
			timeTip += '1 hour';
		} else {
			timeTip += time[0] + ' hours';
		}
	}
	
	if (time[1] != '0') {
		if (time[0] != '0') {
			timeTip += ' and ';
		}
		if (time[1] == '1') {
			timeTip += '1 minute'; 
		} else if (time[1] == '5') {
			timeTip += '5 minutes'; 
		} else {
			timeTip += time[1] + ' minutes'; 
		}
	} else if (time[0] == '0') {
		timeTip += '0 minutes';
	}

	return timeTip;
}

function showTooltip(x, y, contents,bgcolor,bordercolor) {
	 if (bgcolor == null){
	   bgcolor='#aaaaff';
	 }
	 if (bordercolor == null){
	   bordercolor='#5555ff';
	 }
	
        $('<div id="tooltip">' + contents + '</div>').css( {
            position: 'absolute',
            display: 'none',
            top: y - 20,
            left: x + 11,
            border: '1px solid ' + bordercolor,
            padding: '4px',
            'background-color': bgcolor,
            opacity: 0.90
        }).appendTo("body").fadeIn(200);
    }
    
    var options = {
        xaxis: { mode: "time" },
	yaxis: { mode: "time", timeformat: "%h:%M" }, 
        selection: { mode: "x" },
        grid: { markings: weekendAreas,hoverable: true, clickable: true  },
	lines: { show: true },
	points: { show: true },
	bars: {show:false,align:"center",barWidth:20}

    };

 var optionsBar = {
        xaxis: { mode: "time", ticks: 5 },
	yaxis: { mode: "time", timeformat: "%h:%M" },
    colors: [ "#aa0000"],    
        selection: { mode: "x" },
        grid: { markings: weekendAreas,hoverable: true, clickable: true  },
	lines: { show: false },
	points: { show: false },
	bars: {show:true,align:"center",barWidth:86400000}

    };

