function toggleSlide(qid, cid) {
	if ($("#no_" + qid + "_" + cid).attr('checked') || ($("#ta_" + qid).val() != "" || $("#da_" + qid).val() != "")) {
		$("#op_" + qid).show();
	} else {
		$("#op_" + qid).hide();
	}
}

function toggleSlide2(qid) {
	if (($("#ta_" + qid).val() != "") || ($("#op_" + qid).is(':hidden'))  ) {
		$("#op_" + qid).show();
	}
	else {
		$("#op_" + qid).hide();
	}
}

function aijosdfjaoisd() {
$.extend(DateInput.DEFAULT_OPTS, {
	month_names: ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"],
	short_month_names: ["jan", "feb", "mar", "apr", "maj", "jun", "jul", "aug", "sep", "okt", "nov", "dec"],
	short_day_names: ["s&ouml;n", "m&aring;n", "tis", "ons", "tor", "fre", "l&ouml;r"]
});

$.extend(DateInput.DEFAULT_OPTS, {
  stringToDate: function(string) {
    var matches;
    if (matches = string.match(/^(\d{4,4})-(\d{2,2})-(\d{2,2})$/)) {
      return new Date(matches[1], matches[2] - 1, matches[3]);
    } else {
      return null;
    };
  },
  dateToString: function(date) {
    var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    return date.getFullYear() + "-" + month + "-" + dom;
  }
});
}

function ajaxSaveComment(id) {
	var splitted = id.split("_");
	var uid = $('#current_user_id').val();
	var qid = splitted[1];
	var cmt = $('#ta_'+splitted[1]).val();
	var dat = $('#da_'+splitted[1]).val();
	$.post("/answer/make_comment", { question_id: qid, user_id: uid, comment: cmt, attended: dat });	
}

function ajaxDoAnswer(id) {
	var splitted = id.split("_");
	var uid = $('#current_user_id').val();
	var cid = splitted[2];
	var qid = splitted[1];
	var resp = splitted[0];

	$.post("/answer/make_answer", { question_id: qid, user_id: uid, checklist_id: cid, qresponse: resp });	
/*	$.post("/answer/make_answer", { question_id: qid, user_id: uid, qresponse: resp },
	  function(data){
	    alert("Data Loaded: " + data);
	  });	*/
	toggleSlide(qid, cid);
	
	//check if all questions have been answered for the part that this question belongs to
	toggleAllAnsweredImage(id);
}

function toggleAllAnsweredImage(id) {
	var table = $('#' + id).parent().parent().parent().parent();
	
	// find the id of the image
	var imageid = '';
	var classes = table.attr('className').split(' ');
	var aClass;
	for (var i = 0; i < classes.length; i++) {
		aClass = classes[i].split('_');
		if (aClass[0] == 'quests') {
			imageid = 'image_' + aClass[2];
			break;
		}
	}
	
	var questions = 0;
	var answered = 0;
	$(':radio', table).each(function () {
		questions++;
		if ($(this).is(':checked')) {
			answered++;
		}
	});
	questions = questions / 3; // each question has 3 radio buttons
	
	if (answered == questions) {
		$('#' + imageid).show();
	} else {
		$('#' + imageid).hide();
	}
}

