// 读取cookie
function getCookie(key) {
   if (document.cookie.length > 0) {
      var start = document.cookie.indexOf(key + "=")
      if (start !== -1) {
         start = start + key.length + 1
         var end = document.cookie.indexOf(";", start)
         if (end === -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(start, end))
      }
   }
}

// 设置cookie
function setCookie(key, value, second) {
   var cookie = key + "=" + escape(value) + ";";
   if (second !== undefined && second !== '') {
      cookie += "Max-Age=" + second + ";";
   }
   document.cookie = cookie
}