  function init() {
    authorized = readCookie("state_auth");
    if(authorized == 'false') {
      window.location.href="http://cpsnotes.com/closed.php";
    }
    if( !authorized && window.location.href.indexOf("landing.php") == -1) {
      window.location.href="http://cpsnotes.com/landing.php";
    }
  }

  //Check state from dropdown and either allow entry or alert the user that they won't be able to access the site and redirect to... ''.
  function check_state() {
    var block_states = {'AL':'', 'AK':'','AZ':'', 'DE':'', 'KY':'', 'MD':'', 'KY':'', 'MA':'', 'MT':'', 'NE':'', 'NV':'', 'NH':'', 'NJ':'', 'ND':'', 'OR':'', 'RI':'', 'UT':'', 'VA':'', 'WA':'', 'WV':'', 'WY':''};
    var selected = document.getElementById("consumer_state").value;
    var blocked = selected in block_states;
    if(blocked) {
      //createCookie('state_auth', !blocked, 14);
      window.location.href = "http://cpsnotes.com/closed.php";
    } else {
      createCookie('state_auth', !blocked, 14);
      window.location.href = "http://cpsnotes.com/index.php";
    }
  }

  /* Helpers for Cookies */
  function createCookie(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
  }

  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
  }

  function eraseCookie(name) {
    createCookie(name,"",-1);
  }

  //Lets go!
  init();

