// 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 qqlogout()
{
   // writeCookie("uin", "");
   // writeCookie("skey", "");
	delCookie("uin");
	delCookie("skey");
    document.location.reload(true);
}

function showLogined()
{
	var CurrUser = readCookie("uin");
	var uin = CurrUser.substr(1);
	uin++; uin--;
  var sWelcome = "欢迎您！ QQ[" + uin + "] 的用户！";
  var odiv =  document.getElementById("t_uin");
  odiv.innerHTML = sWelcome;
	
	
  //alert(sWelcome);
	//document.writeln("<input type='hidden' name='logined' value='1'>");
	//document.writeln("<input type='hidden' name='uin' size=12 value='" + uin + "'>");
  //document.writeln(sWelcome);
	//document.writeln("<a href='http://comment.qq.com/cgi-bin/qqlogout?url=" +document.URL+"' target='_top' style='color:red;text-decoration:underline'>登出</a>&nbsp;&nbsp;");
}

function showNotLogined()
{
  //var uin = readCookie("UINLOGIN");
	//document.writeln("<input type='hidden' name='logined' value='0'>");
	//document.writeln("QQ号码：<input type='text' name='uin' size=9 value='" + uin + "' >");
	//document.writeln("QQ密码：<input type='password' name='pwd' size=9 >");
	//document.writeln("验证码：<input type='text' name='verifycode' size=4 > <img src='http://verify.qq.com/getimage?",Math.random(),"'>");
	
	var sWelcome = "您还没有登录";
  var odiv =  document.getElementById("t_uin");
  odiv.innerHTML = sWelcome;
}

function showLoginForm()
{
    // check uin & skey
    var uin, skey;
    uin  = readCookie("uin");
    skey = readCookie("skey");
    
    if (uin.length>10 && uin.charAt(0)=="o" && skey.length>0)
    {
        showLogined();
    }
    else
    {
        showNotLogined();
    }
}

//功能：
//广告系统5.0通用js函数
//历史：
//	created by stone.Lv 2005-01-28 15:30 
/********************************************************* 
### 函数名  : checkqqload() 
### 功能    : 检查qq是否登陆过
### 入参    : 无
### 出参    : 
### 作者    : stonelv 
### 修改日期: 2005.01.27
*********************************************************/
function checkqqload()
{
    // check uin & skey
    var uin, skey;
    uin  = readCookie("uin");
    skey = readCookie("skey");
    
    if (uin.length>5 && uin.length < 15  && skey.length>0)
    {
     		return true;
    }
    else
    {
       return false;
    }
}	


function touploadstory()
{
	/*
	if(checkqqload() == false)
	{
		openLogin(4006301)
	}
	else
	{
		top.location.href = "http://mycheetos.qq.com/upload_story.htm";
	} 
	*/

	top.location.href = "http://mycheetos.qq.com/upload_story.htm";
}

function touploadphoto()
{
	/*
	if(checkqqload() == false)
	{
		openLogin(4006301)
	}
	else
	{
		top.location.href = "http://mycheetos.qq.com/upload_photo.htm";
	} 
	*/
	top.location.href = "http://mycheetos.qq.com/upload_photo.htm";
}

function touploadmusic()
{
	/*
	if(checkqqload() == false)
	{
		openLogin(4006301)
	}
	else
	{
		top.location.href = "http://mycheetos.qq.com/upload_music.htm";
	} 
	*/
	top.location.href = "http://mycheetos.qq.com/upload_music.htm";
}

function getCode()
{
	if(checkqqload() == false)
	{
		openLogin(4006301, "http://mycheetos.qq.com/cgi-bin/mycheetos_showcode");
	}
	else
	{
		top.location.href = "http://mycheetos.qq.com/cgi-bin/mycheetos_showcode";
	} 
}

function checklogin()
{
	if(checkqqload() == false)
	{
		openLogin(4006301)
	}
}

function tovote(id, surl)
{
	if(checkqqload() == false)
	{
		openLogin(4006301)
	}
	else
	{
		qq_form(4006301, "", "", "", "", 2, "投票", "http://mycheetos.qq.com/cgi-bin/mycheetos_vote", id, surl);
	}	
}