/*
These functions require cookiefunc.js
*/

var _countConversion = true; // whether or not to consider as a conversion

function rememberUser() {
  // remembers the fact that this user has already submitted a form
  var submittedForm = new Object();
  submittedForm.set = true; // dummy property and value.  later on only check for existance of cookie
  writeCookie("submittedForm", submittedForm); // write submittedForm into the super cookie
}

function rememberUser_firstTime() {
  // remembers the fact that this user has already submitted a form
  var submittedForm = new Object();
  submittedForm.set = true; // dummy property and value.  later on only check for existance of cookie
  submittedForm.countConversion = true;
  writeCookie("submittedForm", submittedForm); // write submittedForm into the super cookie
}

function rememberUser_noConversion() {
  // remembers the fact that this user has already submitted a form
  // but do not count the conversion for google analytics
  var submittedForm = new Object();
  submittedForm.set = true; // dummy property and value.  later on only check for existance of cookie
  submittedForm.countConversion = false; // do not count as conversion since user didn't fill out form
  writeCookie("submittedForm", submittedForm); // write submittedForm into the super cookie
}

function returningUser() {
  // checks if the user has already submitted a form previously
  // cookie gets written by rememberUser()
  // returns true/false.
  var alreadySubmittedForm = false;
  var allCookies = getCookies();
  // test if the user has already submitted the form previously
  for (var i in allCookies) {
    if (i == "submittedForm") {
      alreadySubmittedForm = true;
      break;
    }
  }
  return alreadySubmittedForm;
}

function countConversion() {
  // checks if the user whether or not to count the conversion
  // returns true/false.
  var undefined;
  var countTheConversion = true;
  var allCookies = getCookies();
  // test if the user has already submitted the form previously
  for (var i in allCookies) {
    if (i == "submittedForm") {
      if (allCookies.submittedForm.countConversion != undefined) {
        countTheConversion = allCookies.submittedForm.countConversion;
      }
      break;
    }
  }
  return countTheConversion;
}

function forgetUser() {
  // delete the cookie that stores fact that user already submitted form
  cutCookie("submittedForm"); // delete the cookie
}
