function validate_personal_info(){
  var first = eval("document.getElementById('first_name')");
  var last = eval("document.getElementById('last_name')");
  var address = eval("document.getElementById('address1')");
  var city = eval("document.getElementById('city')");
  var state = eval("document.getElementById('state')");
  var zipcode = eval("document.getElementById('survey_zipcode')");
  var email = eval("document.getElementById('email')");
  var verify_email = eval("document.getElementById('verify_email')");
  var phone = eval("document.getElementById('phone')");
  //var store = eval("document.getElementById('store')");
  var receipt_code = eval("document.getElementById('receipt_code')");
  var unit = eval("document.getElementById('unit')");
  if(!first.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your First Name.";
    first.style.backgroundColor = "#FFFFCC";
  }else if(!last.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your Last Name.";
    last.style.backgroundColor = "#FFFFCC";
  }else if(!address.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your Address";
    address.style.backgroundColor = "#FFFFCC";
  }else if(!city.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your City.";
    city.style.backgroundColor = "#FFFFCC";
  }else if(!state.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your State.";
    state.style.backgroundColor = "#FFFFCC";
  }else if(!zipcode.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your Zip Code.";
    zipcode.style.backgroundColor = "#FFFFCC";
  }else if(!email.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your E-mail.";
    email.style.backgroundColor = "#FFFFCC";
  }else if(!verify_email.value){
    document.getElementById('personal-info-error').innerHTML = "Please verify your E-mail.";
    verify_email.style.backgroundColor = "#FFFFCC";
  }else if(verify_email.value != email.value){
    document.getElementById('personal-info-error').innerHTML = "The E-mail and the Verify E-mail fields do not match. Please make sure you have entered the correct E-mail.";
  }else if(!phone.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your Phone Number.";
    phone.style.backgroundColor = "#FFFFCC";
  }/*else if(!store.value){
    alert("Please choose a Store.");
  }*/else if(!receipt_code.value){
    document.getElementById('personal-info-error').innerHTML = "Please enter your Receipt Code.";
    receipt_code.style.backgroundColor = "#FFFFCC";
  }
  else if($('#frequencyOfVisit').val() == 'choose') {
    document.getElementById('personal-info-error').innerHTML = "Please choose how often you visit.";
    //frequencyOfVisit.style.backgroundColor = "#FFFFCC";
  }
  else if(!Date.parse($('#dateVisit').val())) {
    document.getElementById('personal-info-error').innerHTML = "Please use YYYY/MM/DD";
    dateVisit.style.backgroundColor = "#FFFFCC";
  }
  else if($('#shiftVisit').val() == 'choose') {
    document.getElementById('personal-info-error').innerHTML = "Please choose what time of day you visited.";
    //frequencyOfVisit.style.backgroundColor = "#FFFFCC";
  }
else{
    var querystring = "action=check_receipt&receipt_code="+receipt_code.value+"&email="+email.value;
    if(unit){
      var unit_id = eval("document.getElementById('unit').options[document.getElementById('unit').selectedIndex].value");
      querystring = querystring + '&unit_id='+unit_id;
    }
    var randomnumber=Math.floor(Math.random()*11);
    $.ajax({
      type:'POST',
      url: 'test_survey.cgi',
      data: querystring+'&'+randomnumber,
      complete: function(data,statusText){
        if(data.responseText == "OK"){
          document.getElementById('personal_info').style.display = "none";
          document.getElementById('survey_info').style.display = "block";
        }else{
          document.getElementById('personal-info-error').innerHTML = data.responseText;
          receipt_code.style.backgroundColor = "#FFFFCC";
        }
      }
    });
  }
}
function validate_survey(mc_question){
  var radio1 = document.survey_form.radio1;
  var radio2 = document.survey_form.radio2;
  var radio3 = document.survey_form.radio3;
  var check_radio1;
  var check_radio2;
  var check_radio3;
  var check_mc = new Array;
  var require_comments;
  var check_mc_question;
  
  //check multiple choice has at least one selected
  //if there is more than one in the list, split it into an array, if not add it to the array
  if(mc_question.match(',')){
    check_mc = mc_question.split(',');
  }else{
    check_mc.push(mc_question);
  }
  for(var i = 0; i < check_mc.length; i++){
    var input = eval("document.getElementById('"+check_mc[i]+"').value");
    if(!input){
      check_mc_question = 1;
    }
  }
  
  //check radio buttons for values
  for(var i = 0; i < radio1.length; i++){
    if(document.survey_form.radio1[i].checked == true){
      var input = document.survey_form.radio1[i].value;
      check_radio1 = 1;
      if(input <= 6 && !document.getElementById('comment5').value){ 
        //if the user answers with a 6 or lower on any of the questions, require them to fill out comments
        require_comments = 1;
      }
    }
  }
  
  for(var i = 0; i < radio2.length; i++){
    if(document.survey_form.radio2[i].checked == true){
      var input = document.survey_form.radio2[i].value;
      check_radio2 = 1;
      if(input <= 6 && !document.getElementById('comment5').value){ 
        //if the user answers with a 6 or lower on any of the questions, require them to fill out comments
        require_comments = 1;
      }
    }
  }
  
  for(var i = 0; i < radio3.length; i++){
    if(document.survey_form.radio3[i].checked == true){
      var input = document.survey_form.radio3[i].value;
      check_radio3 = 1;
      if(input <= 6 && !document.getElementById('comment5').value){ 
        //if the user answers with a 6 or lower on any of the questions, require them to fill out comments
        require_comments = 1;
      }
    }
  }
  
  if(check_radio1 != 1){
    document.getElementById('pick-one1').style.display = 'block';
  }else if(check_radio2 != 1){
    document.getElementById('pick-one2').style.display = 'block';
  }else if(check_radio3 != 1){
    document.getElementById('pick-one3').style.display = 'block';
  }else if(check_mc_question == 1){
    //alert("Please answer the multiple choice question.");
    document.getElementById('mc-error').style.display = 'block';
  }else if(require_comments == 1){
    document.getElementById('comments-required').style.display = 'block';
  }else{
    document.survey_form.submit();
    //alert('WENT THROUGH AND ABLE TO SUBMIT (turned off submit for testing.)');
  }
}
function add_remove_id(checkbox_id,question_id,option_id){
  var hidden_input = eval("document.getElementById('hidden"+question_id+"')");
  var checkbox = eval("document.getElementById('"+checkbox_id+"')");
  if(checkbox.checked == true){
    if(hidden_input.value){
      hidden_input.value = hidden_input.value + "," + option_id;
    }else{
      hidden_input.value = option_id;
    }
  }else{
    var ids = new Array; // existing array of values
    var new_ids = new Array; // newly created array of values without the unchecked value in it
    if(hidden_input.value.match(',')){
      ids = hidden_input.value.split(',');
      for(var i = 0; i < ids.length; i++){
        if(ids[i] != option_id){
          new_ids.push(ids[i]);  
        }
      }
      hidden_input.value = new_ids;
    }else if(hidden_input.value == option_id){
      hidden_input.value = "";
    }
  }
}

