jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
// string trim
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

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, mins)
{
  var expire = "";
  if(mins != null)
  {
    expire = new Date((new Date()).getTime() + mins * 60000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

/**
 *	function:
 *		get value from cookie
 *	# in :	sKey
 *	# out:	null on error|value on success
 *	history:
 *		<author>	<time>		<version >	<desc>
 *		moky mo		2004/12/29	0.1			create
 *		moky mo		2005/06/07	0.2			modify
 */
function getCookie(sKey)
{
	var sCookie = document.cookie;
	var sTag = sKey + "=";
	
	var iBegin = sCookie.indexOf(sTag);
	if (iBegin < 0)	return null;
	
	iBegin += sTag.length;
	
	var iEnd = sCookie.indexOf(";", iBegin);
	if (iEnd < 0)	iEnd = sCookie.length;
	
	return sCookie.substring(iBegin, iEnd);
}

/**
 *	function:
 *		set value to cookie with domain(current domain as default)
 *	# in :	sKey, sValue, sDomain, sPath, sExpires, blSecure
 *	# out:	none
 *	history:
 *		<author>	<time>		<version >	<desc>
 *		moky mo		2005/05/16	0.1			create
 *		moky mo		2005/06/07	1.1			add domain
 */
function setCookie(sKey, sValue, sDomain, sPath, sExpires, blSecure)
{
	var sCookieStr = sKey + "=" + sValue + ";";
	if (sDomain)	sCookieStr += " DOMAIN=" + sDomain + ";";
	if (sPath)		sCookieStr += " PATH=" + sPath + ";";
	if (sExpires)	sCookieStr += " EXPIRES=" + sExpires + ";";
	if (blSecure)	sCookieStr += " SECURE";
	
	document.cookie = sCookieStr;
}



function logout_()
{
	setCookie('uin',"","qq.com","/");
	setCookie('skey',"","qq.com","/");
	window.location.href="http://lays.qq.com/";
}

function checkQQLoad()
{
    // check uin & skey
    var uin, skey;
		uin  = getCookie("uin");
    skey = getCookie("skey");
    if (uin&&uin.length>4 && skey&&skey.length>0)
    {
     	return true;
    }
    else
    {
       return false;
    }
}

function LoginQQ(appid)
{
	if(checkQQLoad())
	{
		alert("温馨提示：您已经登录QQ");	
	}
	else
	{
		openLogin(appid);	
	}
}

function getQQ(){
	var CurrUser = $.cookie("uin");
	var uin = CurrUser.substr(1);
	uin++; uin--;
	return uin;
}

//显示用户登录信息
//分别显示登录成功和未登录时的情况
function showLoginStatus()
{
	var sWelcome ="";
  if (checkQQLoad())
	{
		sWelcome = getQQ();
		$("#myqq").text(sWelcome);
	}
	else
	{
		sWelcome = "<input id=\"btn_login\"  type=\"button\" value=\"\" onclick=\"LoginQQ(4000901);\" />";	
		$("#myqq").parent().css({"background-image":"none"}).text("").html(sWelcome);
	}
}

function showAwardList()
{
	alert("温馨提示：敬请期待！");
	return;
}

function vote(id)
{
	
	var APPID=4006502;
	if(checkQQLoad() == false)
	{
		openLogin(APPID);
	}
	else
	{
		qq_form(APPID, "", "", "", "", 2, "投票", "/con/vote/act/saveajax", id);
	}	
}


