// ***************************
// ******** Variables ********
// ***************************
//
// Warn about reading the Scriptures
var warnScript = true;
// Ask before submiting if incomplete
var askfirst = true;

function checkForm(frm) 
{
  for (i = 0; i < frm.length; i++) {
    
    a=frm[i];
    if (a.type == "checkbox") {
      if (!a.checked && a.name=="A1" && askfirst && warnScript) {
        warnScript = false;
        a.focus();
        alert("Please read each passage of Scripture that is mentioned in this chapter before moving on.")
        return false; 
      }
    }
    if (a.name=="name" && a.value == "") {
      a.focus();
      alert("Please enter your name so that we can get to know you.")
      return false;  
    }
  
    if (a.name=="email" && a.value == "") {
      a.focus();
      alert("Please enter your email address so that we can contact you. Don't worry, you email address is save with us.")
      return false;  
    }
      
    if (a.name=="email") { 
      if( a.value.indexOf("@") < 1 || a.value.indexOf(".") <= a.value.indexOf("@") || a.value.indexOf(".")-a.value.indexOf("@") == 1 || a.value.indexOf(".")+1 == parseInt(a.value.length)) {
        alert(a.value + " is not a valid email address.")
        a.focus();
        return false;
      }
    }
    
    if (a.value == "" && a.name != "QaC") {
      a.focus();
      if (askfirst) {
        if (confirm("Are you sure you want to submit your answers incompleted?")) {
          askfirst = false;
        } else {
          return false;
        }
      }    
      
    }
  }
  
}


function validateBack() {
  if (confirm("Do you really want to go back to the contents without submitting your answers?"))
    window.location.replace("index.htm")
}


function getCookie(name)
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return false;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
    end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
}



function checkCookies() 
{
  var bbdName = getCookie("bbdName");
  var bbdEmail = getCookie("bbdEmail");
  var bbdType = getCookie("bbdType");
  
  if (bbdName != false) document.Qfrm.bbdName.value=bbdName.replace("+", " ");
  if (bbdEmail != false) document.Qfrm.bbdEmail.value=bbdEmail;
  if (bbdType != false) {
    //alert(bbdType);
  }
}



