jQuery(function($){
	/** Remove the school-selection from the template **/
	
	$(".tx-srfeuserregister-pi1 .teacher.usertype input#tx-srfeuserregister-pi1-tx_columbus_usertype-1")
		.next().remove().end().remove();
	
	/** Add condition for changing account from private to teacher **/
	if($(".tx-srfeuserregister-pi1 .teacher.usertype input[name='FE[fe_users][tx_columbus_usertype]']").val() == 0) {
		$(".tx-srfeuserregister-pi1 .teacher:gt(1)").css("display", "none");
	}
	
	$(".tx-srfeuserregister-pi1 .teacher.usertype input[name='FE[fe_users][tx_columbus_usertype]']").change(function(){

	});
	
	/** Toggle usertype **/
	var usertype = $(".tx-srfeuserregister-pi1 .teacher.usertype input[name='FE[fe_users][tx_columbus_usertype]']:checked").val();
	$(".tx-srfeuserregister-pi1 .teacher.usertype input[name='FE[fe_users][tx_columbus_usertype]']").click(function(){
		if($(this).val() == 0) {
			$(".tx-srfeuserregister-pi1 .teacher:gt(1)").css("display", "none");
			usertype = 0;
		}
		else if($(this).val() == 2) {
			$(".tx-srfeuserregister-pi1 .teacher:gt(1)").css("display", "block");
			usertype = 2;
		}
	});
	$(".tx-srfeuserregister-pi1 .teacher.usertype input[name='FE[fe_users][tx_columbus_usertype]'][value=" + usertype +"]").click();
	
	
	
	/** validate form **/
	$(".tx-srfeuserregister-pi1  #tx-srfeuserregister-pi1-fe_users_form .tx-srfeuserregister-pi1-submit").click(function(){
		validate = true;
		if(usertype == 2) {
			$(this).parent().siblings(".teacher").children("input").each(function(){
				$(this).css("border-color","#B7BBBE");
				if($(this).val() == "") {
					validate = false;
					$(this).css("border-color","#FF0000");
				}
			});
		}
		else if (usertype == 0) {
			$(this).parent().siblings(".teacher").children("input:gt(1)").val("");
		}
		
		return validate;
	});
	
	/** Set usertype to 2 when user is created as teacher **/
	$(".tx-srfeuserregister-pi1 dd:not('.teacher') input[name='FE[fe_users][tx_columbus_usertype]']").val(2);
});
