var blnCheckUnload = true;
var exitwithConfirm = true;
window.onbeforeunload = function() {
	if (is1001mSite() == false) return; //如果不是1001m网页则不需要此流程
	if(blnCheckUnload) {
		var favorited = readCookie("favoriteCookie");
		if (favorited == "havaAddfavorited")
		{
			if (exitwithConfirm){
				return "梦境家园虚拟社区 | 1001m.com";
			}
		}else{
			if (confirm("感谢您光临梦境家园 | 1001m.com\n\n现在要把梦境加入收藏吗？"))
			{
				writeCookie("favoriteCookie", "havaAddfavorited", 365*24);
				addfavorite();
			}
		}
	}
}

function is1001mSite(){
	var ignore = new Array("ownskin", "56cn", "duowan", "xiaoyouxi", "i8610", "51wan");
	var strUrl = window.location.href;
	for (var i=0; i<ignore.length; i++){
		if (strUrl.indexOf(ignore[i]) != -1){
			return false;
		}
	}
	return true;
}

function exitWithoutConfirm(){
	exitwithConfirm = false;
}

function addfavorite()
{
	if (document.all)
	{ 
	window.external.addFavorite('http://www.1001m.com','梦境家园');
	}
	else if (window.sidebar)
	{ 
	window.sidebar.addPanel('梦境家园', 'http://www.1001m.com', ""); 
	}
} 

function  readCookie(name)   
  {   
      var   cookieValue   =   "";   
      var   search   =   name   +   "=";   
      if(document.cookie.length   >   0)   
      {     
          offset   =   document.cookie.indexOf(search);   
          if   (offset   !=   -1)   
          {     
              offset   +=   search.length;   
              end   =   document.cookie.indexOf(";",   offset);   
              if   (end   ==   -1)   end   =   document.cookie.length;   
              cookieValue   =   unescape(document.cookie.substring(offset,   end))   
          }   
      }   
      return   cookieValue;
  }
    
  function   writeCookie(name,   value, hours)   
  {   
      var   expire   =   Date.MaxValue;  
      if(hours   !=   null)   
      { 
          expire   =   new   Date((new   Date()).getTime()   +   hours   *   3600000);   
          expire   =   ";   expires="   +   expire.toGMTString();   
      }
      document.cookie   =   name   +   "="   +   escape(value)   +   expire;   
  }
