/*Require a name to be entered on index page*/
function checkName() {

	var enterNameForm = document.forms["enterName"];
	
	/*Name is a Required Field*/
	var name = enterNameForm["name"].value;
	if(name == false || name == "") {
			alert("Please enter your name");
			return false;
		} else { 
			return true;
		}
}	



/*Check Radio Buttons*/
/*Display a confirmation dialog box if answer is not selected.*/
function checkAnswer(num) {
	var answers = false;
	var responseGroup = document.forms["question"]["q" + num];
	for(var i=0; i <responseGroup.length; i++) {	
			if(responseGroup[i].checked == true)
				{ answers = true; }
		}
	if(answers == '') { var r = confirm("Are you sure you want to move on without answering the question?  Remember, your best guess is okay, and will help us assign you a more accurate score.\nPress \"Cancel\" to continue without answering or \"OK\" to go back and fill in the details."); 
		if(r==true) { return false; } else { return true; }
	}
}

/*Check Question 5*/
/*Display a confirmation dialog box if no textfields are entered.*/
function checkDebt(num) {
	var answers = false;
	var answers = document.getElementById('q5').value;
	if(answers == '') { var r = confirm("Are you sure you want to move on without answering the question?  Remember, your best guess is okay, and will help us assign you a more accurate score.\nPress \"OK\" to continue without answering or \"Cancel\" to go back and fill in the details."); 
		if(r==true) { return true; } else { return false; }
	}
}


/* Script for Question 5 */
function calculate() {
 
  var total = document.getElementsByName("expense");
  /*alert(total.length);*/
  var t =0;
  var e =0;
  for (var i=1;i<=total.length;i++) {
  	  /*Get the Value of each text field*/
	  e = document.getElementById("expense" + i).value;

	  //Check if the value is null
	  if (!(e.length==0) || (e==null)) { 
		  /*Check if Non Digit Characters Were Entered, if so Remove*/
		  e = e.replace(/^(\D)*/,''); /*Remove Non Digit Characters from the begining of the string*/
		  e = e.replace(/(\D)*$/,''); /*Remove Non Digit Characters from the end of the string*/
		  t += parseInt(e);
		}
   }
   /*If no expenditures were entered then display alert message requiring atleast 1 expense*/
   if(t =="" || income == false) { alert('Please enter at least one expenditure.'); exit; }
  
  /*Get Income*/
  var income =0;
  income = document.getElementById("income").value;
  /*If no value was entered display alert box, required field*/
  if(income =="" || income == false) { alert('Please enter your estimated income.'); exit; }
  income = income.replace(/^(\D)*/,''); /*Remove Non Digit Characters from the begining of the string*/
  income = income.replace(/(\D)*$/,''); /*Remove Non Digit Characters from the end of the string*/ 
  
  /*Divide Total Debit by Income, Round and Convert to a Percent*/
  var total = t / parseInt(income);
  total = Math.round(total * 100) / 100;
  total_num = (Math.round(total * 100));
  total = (Math.round(total * 100)) + '%';
  var text_total = document.getElementById("totaltext");
  text_total.innerHTML = 'Your Percentage Going to Debt is:';
  var text_total = document.getElementById("total");
  text_total.innerHTML = total;
  
  /*Set value in hidden field -- 1-10=8, 11-20=5, 21-30=2, 31 or higher = 0 */
  var tn =0;
  if(total_num == 0) { tn = 10 } else if
    (total_num >=1 && total_num <=10) { tn = 8 } else if
	(total_num >=11 && total_num <= 20) { tn = 5 } else if
    (total_num >=21 && total_num <= 30) { tn = 2 } else if
    (total_num >31) { tn = 0 } else { }
  var a = document.getElementById("q5");
  a.setAttribute("value",tn);
  

