// 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", "");
    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>4 && skey.length>0)
    {
    				
     		return true;
    }
    else
    {
       return false;
    }
}	

//功能：
//广告系统5.0通用js函数
//历史：
//	created by karlwu  2008-08-15
/********************************************************* 
### 函数名  : baoming() 
### 功能    : 参加活动报名
### 入参    : 无
### 出参    : 
### 作者    : karlwu
### 修改日期: 2008.08.15
*********************************************************/
function Isbaoming()
{
	return false;
}
//功能：
//广告系统5.0通用js函数
//历史：
//	created by karlwu  2008-08-15
/********************************************************* 
### 函数名  : baoming() 
### 功能    : 参加活动报名
### 入参    : 无
### 出参    : 
### 作者    : karlwu
### 修改日期: 2008.08.15
*********************************************************/
function baoming()
{
	if(!checkqqload()){ //qq没有登录，先登录
		openLogin(4002501,
				  "http://show.qq.com/qiandaohu/wybm.htm"
				  );
		
	}
	else if(!Isbaoming()){//没有报名，先报名
	
		top.location.href="http://show.qq.com/qiandaohu/wybm.htm";
		}
	else {
		alert("you have already baoming!");
	}
}



//功能：
//广告系统5.0通用js函数
//历史：
//	created by stone.Lv 2005-01-28 15:30 
/********************************************************* 
### 函数名  : checkqqload() 
### 功能    : 检查qq是否登陆过
### 入参    : 无
### 出参    : 
### 作者    : stonelv 
### 修改日期: 2005.01.27
*********************************************************/
function checkEmailload()
{
    // check uin & skey
    var emailnic;
    emailnic  = readCookie("MyEmailNic");
    
    if (emailnic.length>0)
    {
     		return true;
    }
    else
    {
       return false;
    }
}	

//功能：
//广告系统5.0通用js函数
//历史：
//	created by stone.Lv 2005-01-28 15:30 
/********************************************************* 
### 函数名  : checkload() 
### 功能    : 检查是否登陆过
### 入参    : 无
### 出参    : 
### 作者    : stonelv 
### 修改日期: 2005.01.27
*********************************************************/
function checkload()
{
	if(checkqqload() == true)
	{
		top.location.href="http://mcd.qq.com/wycjbs_choose.html";
		return;
	}
	if(checkEmailload() == true)
	{
		top.location.href="http://mcd.qq.com/wycjbs_choose.html";
		return;
	}
	
	top.location.href="http://mcd.qq.com/wycjbs.html";
	return;
}

/********************************************************* 
### 函数名  : giftexchange() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function giftexchange(){
	if(checkqqload() == false)
	{	
		window.alert("请先登录QQ!");
		return;
	}	
	
	var a=giftexchange.arguments;		
	exchange_form(4003201,'http://ctt.qq.com/cgi-bin/ctt_exchange',a[0],a[1],"",a[2]);	
}

/********************************************************* 
### 函数名  : codeexchange() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function codeexchange(){
	
	var a=codeexchange.arguments;		

}

/********************************************************* 
### 函数名  : entercode() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function entercode()
{
	if(checkLogin() == false)
	{	
		window.alert("请先登录!");
		return;
	}	
	var ctrl = document.getElementById('FExchangeCode');
	if(ctrl != null)
	{
		if(ctrl.value == "")
		{
			alert('请输入随机代码!');
			return;
		}		
	
		codeexchange(ctrl.value);
	}
}

/********************************************************* 
### 函数名  : entercode() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function enter_comment_verify(commentform)
{
	var ctrl = commentform.Nick;
	if(ctrl != null)
	{
		if(ctrl.value == "")
		{
			alert('请输入昵称!');
			return;
		}		
	}
	ctrl = commentform.Comment;
	if(ctrl != null)
	{
		if(ctrl.value == "")
		{
			alert('请输入评论内容!');
			return;
		}		
	}
	//alert(commentform.Nick.value);
	//alert(commentform.Comment.value);
 	comment_code_form(APPID,'http://ad.qq.com/cgi-bin/qiandaohu/emk_comment',0,0,commentform.Nick.value, commentform.Comment.value, commentform.DesId.value);	
}

/********************************************************* 
### 函数名  : showdetail() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function showdetail(){
	if(checkqqload() == false)
	{	
		window.alert("请先登录QQ!");
		return;
	}	
	
	top.location.href="http://ctt.qq.com/cgi-bin/ctt_showexdetail";
}

/********************************************************* 
### 函数名  : showdetail() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function leavemsg(){
	if(checkqqload() == false)
	{	
		window.alert("请先登录QQ!");
		return;
	}	
	
	top.location.href="http://ctt.qq.com/cornetto_speak_fabiao.html";
}


/********************************************************* 
### 函数名  : checksearch() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function checksearch(s,n) {
	if (n == 0 && s.value == "-请输入盖子背面12位编码-"){s.value="";}
	if (n == 1){
		if(s.value == "-请输入盖子背面12位编码-"){s.value="";}
	}
	if (n == 2 && s.value == ""){s.value = "-请输入盖子背面12位编码-";}
}


/********************************************************* 
### 函数名  : checkload() 
### 功能    : 检查是否登陆过
### 入参    : 无
### 出参    : 
### 作者    : stonelv 
### 修改日期: 2005.01.27
*********************************************************/
function vote(id)
{
	if(checkqqload() == false)
	{
		qq_form(APPID, location.href);
	}
	else
	{
		qq_form(APPID, "", "", "", "", 2, "投票", "http://show.qq.com/cgi-bin/qiandaohu/qdh_vote", id);
	}	
}