$(document).ready(function() {
  $(".cluetip").cluetip({showTitle: false});
});
function disableButton(theButton)
{
 theButton.value="Processing...";
 theButton.disabled = true;
 theButton.form.submit();
}

function show_error_message(message){
  $.ajax({
	url: "icares_message_error",
  	data: "message=" + message,
  	cache: false,
  	success: function(html){
  		$("#error_message").html(html).show()
 	}
  });
}
function show_alert_message(message){
  $.ajax({
	url: "icares_message_alert",
  	data: "message=" + message,
  	cache: false,
  	success: function(html){
  		$("#alert_message").html(html).show()
 	}
  });
}

function check_searchtext(){
  if (document.forms.icares_filter_form.searchtext.value.length < 3 && document.forms.icares_filter_form.search_org.value.length == 0 ) {
    $("#error_minimal_3_characters").show();
    return false;
  } else {
    $("#error_minimal_3_characters").hide();
    return true;
  }  
}

function check_smartsearch(form){
  checked = false;
  count = 0
  for (x=0;x<form.code.length;x++)
  {  
    if (form.code[x].checked) {
      count +=1
    }
  }
  if ( count < 3) {
    $("#error_minimal_3").show();
    $("#error_maximal_15").hide();
    return false;
  } else {
    if ( count > 15) {
      $("#error_minimal_3").hide();
      $("#error_maximal_15").show();
      return false;
    } else {
      return true;
    }
  }
}


function make_test(active_test) {
  if (active_test == 2 && confirm("Do you wish to make the choice of study test again? Your old test results will be overwritten.")) {
    document.make_test_form.overwrite.value = 'yes';
    document.make_test_form.submit();
  } else if (active_test == 1 && confirm("Do you wish to continue the choice of study test?")) {
    document.make_test_form.overwrite.value = 'yes';
    document.make_test_form.submit();
  } else if (active_test == 0) {
    document.make_test_form.overwrite.value = 'yes';
    document.make_test_form.submit();
  }
}