  
function not_defined(obj){
	return typeof(obj)=='undefined';
}



Data = {
  set: function (key, value, session) {
    if (not_defined(key) || not_defined(value)) { return; }

    if (typeof value === "object") {
      value = JSON.stringify(value);
    } else {
    }

    if (session) {
      sessionStorage.setItem(key, value);
      //console.log('immediately after saving', sessionStorage.getItem(key));
    } else {

      if (localStorage) {
        localStorage.setItem(key, value);
      }
    }
  },
  get: function (key, session) {
    if (not_defined(key)) { return; }
    if (!localStorage) return;
    if (!key) return;
    if (session) {
      var value = sessionStorage.getItem(key);
    } else {
      var value = localStorage.getItem(key);
    }

    if (!value) { return; }

    // assume it is an object that has been stringified
    if (value[0] === "{" || value[0] === "[") {
      value = JSON.parse(value);
    }

    return value;
  }
}
