// FAQ
$(function() {
	$(".faqlist dd").hide();
	
	$(".faqlist dt").toggle(
		function() {
			$(this).next("dd").slideDown(300);
			$(this).addClass("open");
		},
		function() {
			$(this).next("dd").slideUp(300);
			$(this).removeClass("open");
		}
	);
});

// Beräkna stämpelskatt
$(function() {
	// Only if #FormStampelskatt
	if ($("#FormStampelskatt")) {
		$("#typeChoser").hide();
		$("#inputPrice").hide();
		
		// If the user f5, show appropriate elements
		showStuff();
		
		// .focus for IE, .change for ff (need to check other browsers)
		$("#lagfart").change(function(){ showStuff(); hideResults(); });
		$("#inteckning").change(function(){ showStuff(); hideResults(); });
		$("#lagfart").focus(function(){ showStuff(); hideResults(); });
		$("#inteckning").focus(function(){ showStuff(); hideResults(); });
		$("#lagfart").click(function(){ showStuff(); hideResults(); });
		$("#inteckning").click(function(){ showStuff(); hideResults(); });
	}
});

function showStuff() {
	if ($("#lagfart").attr("checked") == true) {
		$("#price-label-inteckning").hide();
		$("#price-label-lagfart").show();
		$("#typeChoser").show();
		$("#inputPrice").show();
	} else if ($("#inteckning").attr("checked") == true) {
		$("#price-label-inteckning").show();
		$("#price-label-lagfart").hide();
		$("#typeChoser").hide();
		$("#inputPrice").show();
	}
}

function hideResults() {
	if ($("#lagfart").attr("checked") == true) {
		if ($("#taxResult").css("display" == "block")) {
			$("#taxResult").hide();
			$("#purchase-price").attr("value","");
		}
	} else if ($("#inteckning").attr("checked") == true) {
		if ($("#taxResult").css("display" == "block")) {
			$("#taxResult").hide();
			$("#purchase-price").attr("value","");
		}
	}
}

// Spontanansokan
$(function() {
	// Only if .spontan
	if ($(".spontan")) {
		$("#otherEducation-wrap").hide();
		
		var origVal = "Ange ort";
		
		if ($("#arbetsort").val() == "" || $("#arbetsort").val() == origVal) {
			$("#arbetsort").addClass("instructions").attr("value",origVal);
		}
		
		$("#arbetsort").focus(function() {
			if ($(this).val() == origVal) {
				$(this).val("").removeClass("instructions");
			}
		});
		
		$("#arbetsort").blur(function() {
			if ($(this).val() == origVal || $(this).val() == "") {
				$(this).val(origVal).addClass("instructions");
			}
		});
		
		$("#dropHighEducation").change(function() {
			otherCheck();
		});
		
		$("#no-pref").click(function(){
			prefCheck();
		});
		
		otherCheck();
		prefCheck();
	}
});

function prefCheck() {
	if ($("#no-pref").attr("checked") == true) {
		$("#arbetsort").attr("disabled","disabled");
		$("#arbetsort").css("background-color","ddd");
	} else {
		$("#arbetsort").attr("disabled","");
		$("#arbetsort").css("background-color","fff");
	}
}

function otherCheck() {
	//if ($("#dropHighEducation option:selected").attr("value") == "Annat...") {
	if ($("#dropHighEducation option:selected").attr("value") == "Annat..." || $("#dropHighEducation option:selected").attr("value") == "Other...") {
		$("#otherEducation-wrap").show(300);
	} else {
		$("#otherEducation-wrap").hide();
	}
}

function clickButton(e, buttonid)
{
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);

      if (bt)
      {
          if (evt.keyCode == 13)
          {
               bt.click();
               return false;
          }
     }
}

