/* group list
-------------------------------------------------------------*/
function open_complist(f){
	var f = f;
	var c = f.comp.options[f.comp.selectedIndex].value;
	var t = f.type.options[f.type.selectedIndex].value;

	if(!(c == "") && !(t == "")){
		window.open(ABSPATH + "ledare/tavling/" + c + "/" + (t == 1 ? "gren" : "medlem") + "/");
	}
}
$(document).ready(function(){
	$('#loginFrm').submit( function(e){
		$('.form-field input:text,input:password,textarea').each(function(){
			$(this).removeClass('error');
			var $img = $(this).parent().parent().find('img:first');
			$img.attr("src", ABSPATH + "pics/spacer.gif");
		});
		$.blockUI({ theme: true, title: $('div#loadMsg p#loadTitle').html(), message: $('div#loadMsg p#loadBody') });
		$('.medium-button').attr('disabled', 'disabled');
		e.preventDefault();
		$.ajax({
			url: ABSPATH + "ajax/ajax.user.login.php",
			type: "POST",
			data: $(this).serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					$('.medium-button').attr('disabled', '');
				}else{
					window.location.href = data.returnUrl;
				}
				$.unblockUI();
			}
		});
	});
	$('#updateFrm').submit( function(e){
		$('.form-field input:text,input:password,input:radio,textarea').each(function(){
			$(this).removeClass('error');
			var $img = $(this).parent().parent().find('img:first');
			$img.attr("src", ABSPATH + "pics/spacer.gif");
		});
		$.blockUI({ theme: true, title: $('div#loadMsg p#loadTitle').html(), message: $('div#loadMsg p#loadBody') });

		$('.large-button').attr('disabled', 'disabled');
		e.preventDefault();
		$.ajax({
			url: ABSPATH + "ajax/ajax.user.settings.php",
			type: "POST",
			data: $(this).serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					
				}else{
					alert(data.returnMsg);
					window.location.reload();
				}
				$('.large-button').attr('disabled', '');
				$.unblockUI();
			}
		});
	});
	$('#imgremove').click( function(e){
		if(!confirm("Vill du ta bort den nuvarande bilden?\n")) return false;
		$.blockUI({ theme: true, title: $('div#loadMsg p#loadTitle').html(), message: $('div#loadMsg p#loadBody') });
		$.ajax({
			url: ABSPATH + "ajax/ajax.avatar.php",
			type: "POST",
			data: "removeImg=true&table=system_user&userid=" + $('input[name=user_id]').val(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);

				}else{
					$('#imgbrowse').show();
					$('#imgremove').hide();
				}
				$('#user_avatar').attr("src", data.fileName);
				$('#imgbrowse').html("<strong>Ladda upp bild</strong>");
				$.unblockUI();
			}
		});
	});
	$('#newPasswdFrm').submit( function(e){
		$('.form-field input:text,input:password,textarea').each(function(){
			$(this).removeClass('error');
			var $img = $(this).parent().parent().find('img:first');
			$img.attr("src", ABSPATH + "pics/spacer.gif");
		});
		$.blockUI({ theme: true, title: $('div#loadMsg p#loadTitle').html(), message: $('div#loadMsg p#loadBody') });
		$('.large-button').attr('disabled', 'disabled');
		e.preventDefault();
		$.ajax({
			url: ABSPATH + "ajax/ajax.user.change.passwd.php",
			type: "POST",
			data: $(this).serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					$('.large-button').attr('disabled', '');
				}else{
					alert(data.returnMsg);
					window.location.href = data.returnUrl;
				}
				$.unblockUI();
			}
		});
	});
});
