$('body').on('click', 'ul.dropdown-menu [data-toggle=dropdown]', function(event) {
	event.preventDefault(); 
	event.stopPropagation(); 
	$(this).parent().siblings().removeClass('open');
	$(this).parent().toggleClass('open');
});

var isVisible = false;
var clickedAway = false;
var pcontent = "<table class='table table-bordered selection pointer'><tbody><tr><td class='td-primary'>Admin</td></tr><tr><td class='td-primary'>Judge</td></tr><tr><td class='td-primary'>Student</td></tr></tbody></table>";

$('.judgePopover').on('click', function() {
	$(this).popover({html: true, show: 'toggle', content: pcontent, placement: 'auto bottom'});
});
$('body').on('click', function (e) {
	$('[data-toggle="popover"]').each(function () {
		//the 'is' for buttons that trigger popups
		//the 'has' for icons within a button that triggers a popup
		if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
			$(this).popover('hide');
		}
	});
});


function incrementStudents(myInput) {
	var max = 10;
	var value = myInput.value;
	if (value < max) {
		myInput.value = (+myInput.value + 1) || 0;
		value++;
	}
}
function decrementStudents(myInput) {
	var min = 1;
	var value = myInput.value;
	if (value > min){
		myInput.value = (myInput.value - 1) || 0;
		value--;
	}
}

function incrementFrames(myInput) {
	var max = 80;
	var value = myInput.value;
	if (value < max) {
		myInput.value = (+myInput.value + 1) || 0;
		value++;
	}
}
function decrementFrames(myInput) {
	var min = 0;
	var value = myInput.value;
	if (value > min){
		myInput.value = (myInput.value - 1) || 0;
		value--;
	}
}

function incrementWeight(myInput) {
	var max = 10;
	var value = myInput.value;
	if (value < max) {
		myInput.value = (+myInput.value + 1) || 0;
		value++;
	}
}
function decrementWeight(myInput) {
	var min = 1;
	var value = myInput.value;
	if (value > min){
		myInput.value = (myInput.value - 1) || 0;
		value--;
	}
}
function getSelectIndex(selectId) {
	var e = document.getElementById(selectId);
	var selection = e.options[e.selectedIndex].text;
	return selection;
}
function setSelectedIndex(selectId, selectedId) {
	console.log('This is the passed in Template Title: ', selectedId);
	var e = document.getElementById(selectId);
	console.log('This is the obtained Element Name: ', e);
	/*$(function() {
	 $(selectId).val(selectedId);
	 });*/
	$(document).ready(function () {
		$("selectId option[value=selectedId]").prop('selected', true);
		// you need to specify id of combo to set right combo, if more than one combo
	});
}
function insertText(textToInput){
	CKEDITOR.instances.templateEditor.insertHtml(textToInput);
}

function getText() {
	var data = CKEDITOR.instances.templateEditor.getData();
	return data;
}

/*
$(document).ready(function(){
	change();
});

function change()
{
	getStudentCount();
	getPendingCount();
}

function getStudentCount()
{
	$.ajax({
		url: "http://localhost/api/count/students",
		dataType: 'json',
		type: 'GET',
		success: function(data) {
			$(".table tr td").eq(1).html(data);
		}.bind(this),

	});
}
function getPendingCount()
{
	$.ajax({
		url: "http://localhost/api/pendingGrade",
		dataType: 'json',
		type: 'GET',
		success: function(data) {
			$(".table tr td").eq(3).html(data);
		}.bind(this),

	});
}
	*/

Chart.defaults.global.responsive = true;
// Get context with jQuery - using jQuery's .get() method.
//var ctx = $("#myChart").get(0).getContext("2d");
// This will get the first returned node in the jQuery collection.
//var myNewChart = new Chart(ctx);

var data = {
    labels: ["BOLO", "Col. Platform", "Drugs Database", "Cloud Computing", "iBLESS", "Mission-Critical", "Mobile Judge"],
    datasets: [
        {
            label: "My Second dataset",
            fillColor: "rgba(151,187,205,0.5)",
            strokeColor: "rgba(151,187,205,0.8)",
            highlightFill: "rgba(151,187,205,0.75)",
            highlightStroke: "rgba(151,187,205,1)",
            data: [28, 40, 40, 19, 46, 27, 50]
        }
    ]
};

//new Chart(ctx).PolarArea(data);

//var myLineChart = new Chart(ctx).Line(data);

//var myBarChart = new Chart(ctx).Bar(data);
