//js获取cookie
var acookie=document.cookie.split("; ");
function getck(sname)
{//获取单个cookies
for(var i=0;i<acookie.length;i++){
var arr=acookie[i].split("=");
if(sname==arr[0]){
if(arr.length>1)
return unescape(arr[1]);
else
return "";
}}
return "";
}
//给相应的ID赋值
function LoginCk(){
if (getck("JSusername")==''){

document.getElementById("Login").innerHTML='<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td width="37%" height="35"><strong>用户名：</strong></td><td width="63%"><input name="username" type="text" id="username"></td></tr><tr><td height="35"><strong>密&nbsp;&nbsp;码：</strong></td><td><input name="password" type="password" id="password"></td></tr><tr><td height="50" colspan="2" align="center"><input type="image" src="images/login.jpg" width="75" height="25" style="width:75px; height:25px; border:0px;"   onClick="Login();"/> <a href="reg.asp"><img src="images/reg.gif"  border="0"  style="padding-top:8px;"/></a></td></tr></table>'
}//还未登陆的信息
else{
document.getElementById("Login").innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="100%" height="35" align="left">'+unescape(getck("JSusername"))+'你好！<br/><br/>欢迎登陆温州海洋环境监测中心！</td></tr><tr><td height="115" align="center">&nbsp;&nbsp;<a href="member.asp">会员中心</a> &nbsp;&nbsp;<a href="memberAllFile.asp">下载区</a> &nbsp;&nbsp;<a onClick="over()" style="cursor:hand;">退出</a></td></tr></table>'       //登陆成功后信息
}


}


function rest()
{
			   document.getElementById("username").value=""
			   document.getElementById("password").value=""
}




function createAjax() {			//该函数将返回XMLHTTP对象实例
	var _xmlhttp;
	try {	
		_xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");	//IE的创建方式
	}
	catch (e) {
		try {
			_xmlhttp=new XMLHttpRequest();	//FF等浏览器的创建方式
		}
		catch (e) {
			_xmlhttp=false;		//如果创建失败，将返回false
		}
	}
	return _xmlhttp;	//返回xmlhttp对象实例
}




function Login() {	// 登陆判断登陆判断登陆判断

	if(document.getElementById("username").value=='' )
	{
		alert("用户名不能为空");
		 document.getElementById("username").focus();

	}
	else if(document.getElementById("password").value=='' )
	{
		alert("密码不能为空");
		document.getElementById("password").focus();
		
	}

else{
	var xmlhttp=createAjax();	//创建变量xmlhttp，并将createAjax()函数创建的对象实例赋于它
	if (xmlhttp) {		//如果xmlhttp对象创建成功，则执行条件语句中的程序
	var loginuser=document.getElementById("username").value;
	var loginpass=document.getElementById("password").value;
	//alert('login.asp?action=login&loginname='+loginuser+'&loginpwd='+loginpass+'&n='+Math.random());
			//获取页面中id为content的对象
		xmlhttp.open('get','login.asp?action=login&loginname='+loginuser+'&loginpwd='+loginpass+'&n='+Math.random(),true);
		
	

		
		//打开与服务器的连接，其中get为连接方式，server.asp为要连接的页面，有两个参数，其中第一个参数page为需要返回数据的页数,第二个参数n为一个随机数，这样每次发送的URL都会不一样，相当于都向服务器发出一个新的请求，避免浏览器缓存数据。
		xmlhttp.onreadystatechange=function() {		//为xmlhttp对象的readyState属性指定事件，改属性值改变时，则会执行其中的程序
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {	//如果xmlhttp.readyState==4并且xmlhttp.status==200时，执行条件中的程序，其中readyState有五个值，4为请求完成，是客户端向服务器提交的数据成功到达，status有N多值-_-!!，其中200为OK，是指服务器向客户端完成发送数据。
				var response=xmlhttp.responseText;	//将服务器返回的数据解码并写入指定的ID中。
				if(response==1){
				alert("用户名或密码错误");
			   document.getElementById("username").value="";
			   document.getElementById("password").value="";
			    document.getElementById("username").focus();
				}
				else if(response==2)//会员尚未通过认证
				{
				alert("对不起，你尚未通过认证，不能登录！");
				document.getElementById("username").value="";
			    document.getElementById("password").value="";
			    document.getElementById("username").focus();

				}
				else 
				{
					location='member.asp';
				//document.getElementById("Login").innerHTML=unescape(response);
				//alert("登录成功");
				
				}

			
			}
			else {
					//如果服务器没有完成传送，则向用户提示正在传输。
			}
		}
		xmlhttp.send(null);	//向服务器发送请求，因为是get请求，会直接附在URL后面，所以这里括号中的数据为null，IE中也可以不写，但FF就必须加上null，否则会发送失败。
	}
	
}	
}






function over() //退出登陆
{

	
	var xmlhttp=createAjax();	//创建变量xmlhttp，并将createAjax()函数创建的对象实例赋于它
	if (xmlhttp) {		//如果xmlhttp对象创建成功，则执行条件语句中的程序

			//获取页面中id为content的对象
		xmlhttp.open('get','login.asp?login=out'+'&n='+Math.random(),true);
		

		
		//打开与服务器的连接，其中get为连接方式，server.asp为要连接的页面，有两个参数，其中第一个参数page为需要返回数据的页数,第二个参数n为一个随机数，这样每次发送的URL都会不一样，相当于都向服务器发出一个新的请求，避免浏览器缓存数据。
		xmlhttp.onreadystatechange=function() {		//为xmlhttp对象的readyState属性指定事件，改属性值改变时，则会执行其中的程序
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {	//如果xmlhttp.readyState==4并且xmlhttp.status==200时，执行条件中的程序，其中readyState有五个值，4为请求完成，是客户端向服务器提交的数据成功到达，status有N多值-_-!!，其中200为OK，是指服务器向客户端完成发送数据。
			    //alert("退出成功");
				location='index.asp';
				document.getElementById("Login").innerHTML=unescape(xmlhttp.responseText);	//将服务器返回的数据解码并写入指定的ID中。
			  

			  
			  
			
			}
			else {
					//如果服务器没有完成传送，则向用户提示正在传输。
			}
		}
		xmlhttp.send(null);	//向服务器发送请求，因为是get请求，会直接附在URL后面，所以这里括号中的数据为null，IE中也可以不写，但FF就必须加上null，否则会发送失败。
	}

}

