var Epub = {

   DOMAIN_RE: new RegExp('^(https?://)([^/]+)(.*)'),
   FRAME_HEIGHT_COOKIE_NAME: '__neighborhoodinformation_frameHeight',

   checkDomain: function(allowedDomains) {
      var d = ('' + window.location).match(this.DOMAIN_RE);
      for (var i = 0; i < allowedDomains.length; i++) {
         if (d[2] == allowedDomains[i]) return true;
      }
      return false;
   },

   updateFrameHeight: function(frameId) {
      try {
         var h = this.getCookie(this.FRAME_HEIGHT_COOKIE_NAME);
         if (h) {
            if (h > 400) {
               document.getElementById(frameId).height = h;
            }
         }
      } catch (err) { }
      setTimeout('Epub.updateFrameHeight(\'' + frameId + '\')', 1000);
   },

   storeFrameHeight: function() {
      try {
         this.setCookie(this.FRAME_HEIGHT_COOKIE_NAME, window.location.search.substring(1));
      } catch (err) { }
   },

   clearFrameHeight: function() {
      try {
         this.setCookie(this.FRAME_HEIGHT_COOKIE_NAME, null);
      } catch (err) { }
   },

   getCookieVal: function(offset) {
      var endstr = document.cookie.indexOf(";", offset);
      if (endstr == -1) endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
   },

   getCookie: function(name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
         var j = i + alen;
         if (document.cookie.substring(i, j) == arg) return this.getCookieVal(j);
         i = document.cookie.indexOf(" ", i) + 1;
         if (i == 0) break;
      }
      return null;
   },

   setCookie : function(name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape (value) +
         ((expires) ? "; expires=" + expires.toGMTString() : "") +
         "; path=" + ((path) ? path : "/") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "");
   }

};
