jQuery.fn.extend({
    // Based off of the plugin by Clint Helfers, with permission.
    // http://blindsignals.com/index.php/2009/07/jquery-delay/
    delay: function( time, type ) {
        time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
        type = type || "fx";
 
        return this.queue( type, function() {
            var elem = this;
            setTimeout(function() {
                jQuery.dequeue( elem, type );
            }, time );
        });
    }
});

$(document).ready(function() {
  $('input.loginformfieldpassword').keypress(function(e) {
        if(e.which == 13) {
            jQuery(this).blur();
            jQuery('a.loginformsubmit').focus().click();
        }
  });
  $(".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();
  }
}
