﻿function checkusername()
{
	theform=document.login;

	if (theform.txtLoginName.value==""){
		alert("请输入用户名!");
		theform.txtLoginName.focus();
		return false;
	}
	else if (theform.txtLoginPassword.value==""){
		alert("请输入登录密码!");
		theform.txtLoginPassword.focus();
		return false;
	}else {
		return true;
	}
}
function loginok(username){
	var temp1=""
	temp1=temp1+"	&nbsp;<font color=#000000>欢迎您："+username+"</font>";
	temp1=temp1+"&nbsp;&nbsp;<a href='http://box.666ccc.com/MusicFav.asp' target=_blank><font color=blue><b>我的音乐盒</b></font></a>";
	temp1=temp1+"&nbsp;&nbsp;<a href='http://box.666ccc.com/SpecialFav.asp' target=_blank><font color=blue><b>专辑收藏</b></font></a>";
	temp1=temp1+"&nbsp;&nbsp;<a href='http://box.666ccc.com/UserModify.asp' target=_blank><font color=blue><b>修改资料</b></font></a>";
	temp1=temp1+"&nbsp;&nbsp;<a href='#' onclick='javascript:logout();'><font color=red>退出</font></a>";
	getObject("login_zu").innerHTML=temp1;
}
function loginerror(st){
	var temp1=""
	if (st!="2"){
		temp1=temp1+'<form name="userlogin">';
		temp1=temp1+'用户名：<input name="txtLoginName" id="txtLoginName" size="20" class="input" onKeyPress="if(event.keyCode==13) login();" />&nbsp;密码：<input name="txtLoginPassword" id="txtLoginPassword" type="password" class="input" maxlength="50" onKeyPress="if(event.keyCode==13) login();" />&nbsp;<input type="button" name="submit" value="登录" class="index_play" onclick="javascript:login();">&nbsp;<input type="button" name="reg1" value="免费注册" class="lb2" onclick="javascript:window.open(\'http://box.666ccc.com/Reg.asp\',\'_blank\',\'\');">';
		temp1=temp1+'</form>';
		getObject("login_zu").innerHTML=temp1;
	}else{
		temp1=temp1+'<font color="#006699">错误提示：用户名或密码不正确。</font>&nbsp;<a href="javascript:void(0)" onclick="loginerror()"><font color="#FF0000">点击返回</font></a>';
		getObject("login_zu").innerHTML=temp1;
		setTimeout("loginerror()",3000);
	}
}
function checkLogin(){
	var username=GetCookie("username");
	if(username && username!=""){
		loginok(DecodeCookie(username));
	}else{
		loginerror();
	}
}

function login(){

	//id="" 方式获取值
	//var usernameValue = getObject("txtLoginName").value;
	//var passwordValue = getObject("txtLoginPassword").value;
	
	theform=document.userlogin;

	if (theform.txtLoginName.value==""){
		alert("请输入用户名!");
		theform.txtLoginName.focus();
		return false;
	}
	else if (theform.txtLoginPassword.value==""){
		alert("请输入登录密码!");
		theform.txtLoginPassword.focus();
		return false;
	}else{


	var usernameValue = theform.txtLoginName.value;
	var passwordValue = theform.txtLoginPassword.value;

	var s = document.createElement("script");
	s.type="text/javascript";
	s.src="http://box.666ccc.com/UserLoginChk.asp?txtLoginName="+escape(usernameValue)+"&txtLoginPassword="+ escape(passwordValue) + "&_="+(new Date()).getTime();
	document.getElementsByTagName("head")[0].appendChild(s);


	s.onreadystatechange=function(){
		if(this.readyState && (this.readyState == "complete" || this.readyState == "loaded") ){
			if(typeof(username) != 'undefined'){
				if(username != null){
					loginok(usernameValue);
				}else{
					loginerror(2);
				}
			}else{
				alert("抱歉，可能由于网络问题没有连接到服务器。");
			}
		}
	}

	s.onload = function () {
		if(typeof(username) != 'undefined'){
			if(username != null){
				loginok(usernameValue);
			}else{
				loginerror(2);
			}
		}else{
				alert("抱歉，可能由于网络问题没有连接到服务器。");
		}
	}

	}
}

function logout(){
	var s = document.createElement("script");
	s.type="text/javascript";
	s.src="http://box.666ccc.com/UserLogout.asp?_=" + (new Date()).getTime();
	document.getElementsByTagName("head")[0].appendChild(s);
	s.onreadystatechange=function(){
		if(this.readyState && (this.readyState == "complete" || this.readyState == "loaded") ){
			if(typeof(isLogout)   ==   'undefined'){
				setTimeout("logout()",1000);
			}else{
				loginerror();
			}
		}
	}

	s.onload = function () {
		if(typeof(isLogout) == 'undefined'){
			setTimeout("logout()",1000);
		}else{
			loginerror();
		}
	}
}

window.onload = checkLogin;

/*

function window.onload(){
	alert("11");
	checkLogin();
}
*/