$(document).ready(function () {
	var pos = 0;
	
	$(".neste_slide").click(function(){
		pos = pos + 498;
		$("#slideboks").animate({left: "-"+pos+"px"}, 800 );
	});
	/*
	$("#til_slide_2").click(function(){
      	$("#slideboks").animate({left: "-498px"}, 800 );
    });
	*/
    
    $("#til_slide_3").click(function(){
    	var error = 0;
    	var total = 0;
      	$("input.rangering").each(function() {
      		if($(this).val() > 3 || $(this).val() == 0 || $(this).val() == "") {
      			error++;
      		}
      		if($(this).val() != "") {
	      		total = total + parseInt($(this).val());
      		}
      	});
      	if(error == 0 && total == 6) {
	    	pos = pos + 498;
			$("#slideboks").animate({left: "-"+pos+"px"}, 800 );
      	}
      	else {
      		alert("Fyll inn alle felt med en verdi mellom 1 og 3. Hver verdi kan kun forekomme en gang");
      	}
    });
    
    $(".en_til_fem a").click(function() {
    	if(!$(this).hasClass("valgt")) {
			var s = $(this).attr("class");
    		$(".en_til_fem a."+s).each(function() {
    			$(this).removeClass("valgt");
    		});
    		$("#val_"+s).val($(this).text());
    		$(this).addClass("valgt");
    	}
    });
    
    /*
    $("#til_slide_4").click(function(){
      $("#slideboks").animate({left: "-1494px"}, 800 );
    });
    */
    $("table#nb a").click(function(){
      if($(this).hasClass("valgt")) {
      	$(this).removeClass("valgt");
      	$("#vil_ha_nb").val("Nei");
      }
      else {
      	$(this).addClass("valgt");
      	$("#vil_ha_nb").val("Ja");
      }
    });
    
    $("#til_slide_5").click(function(){
      $("#slideboks").animate({left: "-1992px"}, 800 );
    });
    
    $("#send_skjema").click(function(){
    	if($("#vil_ha_nb").val() == "Ja") {
    		if($("#mail").val() == "") {
    			alert("Vennligst fyll inn en epostadresse for nyhetsbrevet");
    		}
    		else {
    		$("#undersokelse_skjema").submit();
    	}
    	}
    	else {
    		$("#undersokelse_skjema").submit();
    	}
    });
});


