$(document).ready(function() {
	$('#contactFrm').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.send.email.php",
			type: "POST",
			data: $(this).serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					$('.medium-button').attr('disabled', '');

				}else{
					alert(data.msgSuccess);
//					window.location.href = '/campaigns?details=' + data.returnId;
				}
				$.unblockUI();
			}
		});
	});
	$('#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.account.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();
			}
		});
	});
	$('#step1').click( function(e){
		$.blockUI({ theme: true, title: $('div#loadMsg p#loadTitle').html(), message: $('div#loadMsg p#loadBody') });
		$('.large-button').attr('disabled', 'disabled');
		$.ajax({
			url: ABSPATH + "ajax/validation.school.notify.step1.php",
			type: "POST",
			data: $('#sNotifyS1').serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					$('.large-button').attr('disabled', '');
				}else{
					$('#sNotifyS1').submit();
				}
				$.unblockUI();
			}
		});
	});
	$('#step2').click( 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');
		$.ajax({
			url: ABSPATH + "ajax/validation.school.notify.step2.php",
			type: "POST",
			data: $('#sNotifyS2').serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
					$('.large-button').attr('disabled', '');
				}else{
					$('#sNotifyS2').submit();
				}
				$.unblockUI();
			}
		});
	});
	$('#step3').click( 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');
		$.ajax({
			url: ABSPATH + "ajax/validation.school.notify.step3.php",
			type: "POST",
			data: $('#sNotifyS3').serialize(),
			dataType: "json",
			success: function(data){
				if(data.hasError){
					throwError(data);
				}else{
					if(confirm(data.returnMsg)){
						document.forms['sNotifyS3'].submit();
					}
				}
				$('.large-button').attr('disabled', '');
				$.unblockUI();
			}
		});
	});
	$('#tac_link').click( function(e){
		$("#tac_text").dialog("destroy");
		$("#tac_text").dialog({
			width: 500,
			height: 450,
			modal: true,
			closeOnEscape: true,
			closeText: 'Stäng',
			buttons: {
				Stäng: function() {
					$(this).dialog('close');
				}
			}
		});
	});
	$('#sp_link').click( function(e){
		$("#sp_text").dialog("destroy");
		$("#sp_text").dialog({
			width: 500,
			height: 450,
			modal: true,
			closeOnEscape: true,
			closeText: 'Stäng',
			buttons: {
				Stäng: function() {
					$(this).dialog('close');
				}
			}
		});
	});


});