// JavaScript Document

var lug = {
		
	init : function() 
	{
		
		/* ---------------------------------------- */
		/*    Link blur						 		*/
		/* ---------------------------------------- */
		$("a").focus(function() {
		  $(this).blur();
		});


		/* ---------------------------------------- */
		/*    Hide or show the optional amount 		*/
		/* ---------------------------------------- */
		$("select.dropdown").change(function() {
			
			if($(this).val() == '0')
			{
				$('.otherAmountContainer').slideDown('medium');
			};
			
			if($(this).val() != '0')
			{
				$('input[name="otheramount"]').attr({ value: '' });
				$('.otherAmountContainer').slideUp('medium');
			};
			
		});

		
		/* ---------------------------------------- */
		/*    Form field							*/
		/* ---------------------------------------- */
		// This changes the style of the input field, if the user clicks on it
		$('form.standard input[type="text"]').focus(function() 
		{
			$(this).removeClass("txt").addClass("focusField");
			if (this.value == this.defaultValue)
			{
			this.value = '';
			}
			if(this.value != this.defaultValue)
			{
			this.select();
			}
		});
		// This deletes the prefield content
		$('form.standard input[type="text"]').blur(function() 
		{
			$(this).removeClass("focusField").addClass("txt");
			/*
			if ($.trim(this.value == ''))
			{
			this.value = (this.defaultValue ? this.defaultValue : '');
			} */
		});
		
		
		/* ---------------------------------------- */
		/*    Form field							*/
		/* ---------------------------------------- */
		// $("#donationFormID").validate();
		$("#donationFormID").validate({
		   rules: {
			 fornamn: "required",
			 efternamn: "required",
			 gatuadress: "required",
			 postnummer: "required", 
			 personnummer: {
				  required: true,
				  minlength: 10,
				  maxlength: 11
			 },
			 epost: {
			   required: true,
			   email: true
			 }
		   },
		   messages: {
			 fornamn: "Ditt förnamn saknas.",
			 efternamn: "Ditt efternamn saknas.",
			 gatuadress: "Din gatuadress saknas",
			 postnummer: "Postnummer saknas", 
			 personnummer: {
			   required: "Personnummer saknas",
			   minlength: "ååmmdd-xxxx",
			   maxlength: "ååmmdd-xxxx"
			 },
			 epost: {
			   required: "Din e-post saknas.",
			   email: "Ogiltig e-postadress."
			 }
		   }
		})

	}
};

$(document).ready(function() 
{
	lug.init();
});

