var the_score = 0



$(function(){

	//Hide the second part of the form
	//$("#form_page_2").hide()
	
	
	//Continue
	/*
$("#continue_trigger").bind('click', function(){
		$("#form_page_1").hide()
		$("#form_page_2").show()
	})
*/
	
	
	//calculate the scores
	$("#risk_form").bind("submit", function(){
	
		valid = true
		
		if($("#postcode").val().length < 4){
			valid = false
		}

		if($(".valid_rb:checked").length < 12){
			valid = false
		}
		
		if(valid){
			//If all the fields are filled in
			the_score = 0
			$('input:checked').each(function(i){
				
				//Check if its a number
				//If it is add it to the score
				if(IsNumeric($(this).val())){
					the_score += Number($(this).val())
				}
			})
			$("#score").val(the_score)
			return true
		
		}
		else{
			alert("Please complete all questions")
			/*
$("#form_page_1").show()
			$("#form_page_2").hide()
*/
			return false
		}
		
		
		
	})

})


function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }




