﻿window.onerror = function() { 
  return true; 
}
//全局变量
var IntervalTime = 1000;
var MaxTry = 0;
var TryCount = 0;
var IsLogined = false;
var KugooID = 0;
var NickName = "";
var IntervalID = -1;
function sdnClick(num) {
	(new Image()).src = "http://sdn.kugou.com/link.aspx?id="+num+"&url=&t="+ Math.random();
}
function GetUserCookie(){
    var MyCookie = document.cookie.toLowerCase();
    re = /kugooid=(\d+)&/g;
    if (re.test(MyCookie)) {
        IsLogined = true;
        KugooID = RegExp.$1;
        re2 = /nickname=([^&]+)/g;
        re2.test(MyCookie);
        NickName = unescape(RegExp.$1).replace("+", " ").replace("+", " ");
        return KugooID;
    }
}
function ShowAllDiv() {
    var str = "";
    str += "<span id='LoginedDiv' style='display:none;'><div style='margin: 5px 5px 0; color: #585858;'><a style='font-weight: bold; color: #009900;' target='_blank' title='" + NickName + "'>" + ((NickName.length > 12) ? NickName.substring(0, 12) : NickName) + "</a></div><div style='margin: 0 5px; color: #585858; text-align: right;'>[<a style='color:#585858;text-decoration: none;' href='http://www.kugou.com/user/logout.aspx'>退出</a>]</div></span>";
    str += "<span id='UnLoginedDiv' style='display:none;'><div style='color: #585858; text-align: center; margin-top:8px;'><form action='' method='post' id='loginform' onSubmit='return LoginCheck(this);'><input id='UserName' name='UserName'  type='text' value='输入帐号' class='utext' style='color:#DADADA;' onfocus='IStatus(this)' onblur='LStatus(this)'>&nbsp;&nbsp;&nbsp;&nbsp; <input  id='UserPwd' name='UserPwd' type='password'  class='utext' style='background:url(http://www.kugou.com/images/pwd_bg.gif);' onfocus='IPwdStatus(this)' onblur='LPwdStatus(this)' />&nbsp;&nbsp;<input  id='subLogin' name='subLogin' type='submit' value='' class='ulogin' />&nbsp;&nbsp;&nbsp;<a href='http://www.kugou.com/user' onclick='sdnClick(1508)' target='_blank' style='color:#CF0008;'>注册</a></form></div></span>";
    document.write(str);
}
function ShowLogined() {
    var span_UnLogined = document.getElementById("span_UnLogined");
    var span_login=document.getElementById("span_login");
    if (IsLogined) {
        //LoginedDiv.innerHTML = LoginedDiv.innerHTML.replace("{KugooID}",KugooID).replace("{NickName}",NickName);
        span_UnLogined.style.display = "none";
        span_login.style.display = "block";
        var url="http://www.kugou.com/user/logout.aspx";
        if(typeof(urlRef)!='undefined'){
           url+="?url="+ urlRef;
        }
        span_login.innerHTML="<a style='font-weight: bold; color: #009900;' href='http://www.kugou.com/uc/' target='_blank'>" + NickName + "</a><span class='textSpan'>|</span>[<a style='color:#585858;text-decoration: none;' href='"+url+"'>退出</a>]<span class='textSpan'>|</span><a href='http://www.kugou.com/service/' onclick='sdnClick(1519)' target='_blank' class='linkBlue2'>客服</a>";
        
    } else {
        span_UnLogined.style.display = "block";
        span_login.style.display = "none";
    }
}
GetUserCookie();
//ShowAllDiv();
ShowLogined();

function TryReadCookie() {
    TryCount++;
    if (TryCount < MaxTry) {
        GetUserCookie();
        if (IsLogined) {
            window.clearInterval(IntervalID);
            ShowLogined();
        }
    }
    else {
        window.clearInterval(IntervalID);
    }
}
if(!IsLogined) {
    IntervalID = window.setInterval(TryReadCookie, IntervalTime);
}
function LoginCheck(form) {
  if(form.UserName.value.length==0 || form.UserName.value=="输入帐号") {
    form.UserName.focus();
    alert('请先填用户名！');
    return false;
  }
  if(form.UserPwd.value.length==0) {
    form.UserPwd.focus();
    alert('请先填密码！');
    return false;
  }
  form.action="http://www.kugou.com/user/LoginCheck2.aspx?url="+location.href;
  sdnClick(1524);
  return true;
}
function IStatus(obj)
{
	if(obj.value=="输入帐号")
	{
		obj.value="";
		obj.style.color="#6D6D6D";
	}
}
function LStatus(obj)
{
	if(obj.value=="")
	{
		obj.value="输入帐号";
		obj.style.color="#DADADA";
	}
}
function IPwdStatus(obj)
{
	if(obj.style.background=="url(http://www.kugou.com/images/pwd_bg.gif)")
	{
		obj.style.background="#fff";
	}
}
function LPwdStatus(obj)
{
	if(obj.value=="")
	{
		obj.style.background="url(http://www.kugou.com/images/pwd_bg.gif)";
	}
}