// 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 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]);	
}

function getLogin()
{
    return readCookie("XDJ_USER");

}
function checkLogin()
{
    var login = getLogin();
    if(login == null || login == "")
    {
        return false;
    }
    return true;
}
/********************************************************* 
### 函数名  : codeexchange() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function codeexchange(){
	
	var a=codeexchange.arguments;	
	
	var strPostUrl;
	if(a[1] == "1")	
	{
	    strPostUrl = '/cgi-bin/emk_exchange_code_score';
	}
	else
	{
	    strPostUrl = '/cgi-bin/emk_exchange_code_score2';
	}
	exchange_form(4003201,strPostUrl,a[1],a[2],a[0]);	
}

/********************************************************* 
### 函数名  : entercode() 
### 功能    : 
### 入参    : 无
### 出参    : 
### 作者    : stonelv
### 修改日期: 2008.01.20
*********************************************************/
function entercode()
{
  //alert('活动还没有开始,敬请关注最新动态!');
  //return;
	if(checkqqload() == false)
	{	
		window.alert("请先登录!");
		window.location.replace("login.html?FUrl=" + document.location.href);
		return;
	}	
	var ctrl = document.getElementById('FExchangeCode');
	if(ctrl != null)
	{
		if(ctrl.value == "")
		{
			alert('请输入随机代码!');
			return;
		}		
	
	
	  var BType = document.getElementById('BType');
	  
	  var strBType='0';
	  var strLType='0';
	  if(BType != null)
	  {
	    strBType = BType.value;
	  }
	    
	  
	  var LType = document.getElementById('LType');
	  if(LType != null)
	  {
	    strLType=LType.value;
	  }
	  
	  
		codeexchange(ctrl.value, strBType, strLType);
	}
}

/********************************************************* 
### 函数名  : 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位编码-";}
}