// JavaScript Document

//Validate ranking questions: each value used exactly once.
function rankem(question, q_size) {

 var aLert1 = "";
 var aLert2 = "";

 // supports up to 26 items to be ranked -- extend this array to increase
 var cal = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z";
 cal = cal.split('.');
 var a = 0;
 var irate = "rank" + question;
 eval(irate + " = new Object();");
 var myrate = "";

 for (var x = 0; x < q_size; ++x) {
  myrate = "q"+question+cal[x];
  eval(irate + "[" + x + "] = document.form1." + myrate + ".selectedIndex");
  if (eval(irate + "[" + x + "]")) {
   ++a;
   for (var y = 0; y < x; ++y) {
    if (eval(irate + "[" + y + "]") == eval(irate + "[" + x + "]")) {
     aLert1 = "Question "+ question +": please use each ranking only once.\n";
    }
   }
  }
 }
 if (a != q_size) {
  aLert2 = "Question " + question +":please rank all items.\n";
 }
 var aLert = aLert1 + aLert2;
 if (aLert) {
  alert(aLert);
  return true;
 }
 return false;
}
//  End -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  David Blackledge -->
<!-- Web Site:  http://David.Blackledge.com -->

<!-- Begin
function checkRadios() {
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
    alert("Please choose an answer for all questions.");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
 }
 return true;
} 

//  End -->
function checkSurvey() {
 var el = document.forms[0].elements;
 for(var i = 0 ; i < el.length ; ++i) {
  if(el[i].type == "radio") {
   var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
   var itemchecked = false;
   for(var j = 0 ; j < radiogroup.length ; ++j) {
    if(radiogroup[j].checked) {
	 itemchecked = true;
	 break;
	}
   }
   if(!itemchecked) { 
    alert("Please choose an answer for all questions.");
    if(el[i].focus)
     el[i].focus();
	return false;
   }
  }
  if(el[i].name == "consent"){ // get the informed consent check box.
	if(!el[i].checked){
	  alert("You must check the Informed Consent box to submit this survey.");
	  if(el[i].focus)
	    el[i].focus();
	  return false;
	}
  }
 }
 if(rankem(21,6) || rankem(23,9)){
	el[392].focus();
	return false;
 }
 return true;
} 
