﻿// JScript 文件
HTTPRequest = function () 
{
　var xmlhttp=null;
　try 
　{
　　xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
　}
　 catch (_e) 
　 {
　　try 
　　{
　　　xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
　　} 
　　catch (_E) 
　　{ }
　}
　if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
　{
　　try 
　　{
　　　xmlhttp = new XMLHttpRequest();
　　} 
　　catch (e) 
　　{
　　　xmlhttp = false;
　　}
　}
　return xmlhttp;
}

//login
function submitLog(url, state)
{
    var xhttp = new HTTPRequest();
    xhttp.onreadystatechange = function()
	{
		if(xhttp.readyState!=4)
		{
			//document.all.msg.innerHTML = "登录中...";
		}
		else if(xhttp.readyState==4)
		{
			if(xhttp.status==200)
			{
			    if(xhttp.responseText == "" || xhttp.responseText == "0")
			    {
			        if(state == "1")
			        {
			            alert("用户名或密码无效");
			            //document.all.msg.innerHTML = "用户名或密码无效";
			        }
			        else
			        if(state == "0")
			        {
			            //document.all.msg.innerHTML = "";
			        }
			    }
			    else
			    if(xhttp.responseText != "" && xhttp.responseText != "0")
			    {
			        if(xhttp.responseText == "disableip")
			        {
			            alert('您的IP已被禁用，请与管理员联系！');
			        }
			        else
			        {
			            getLoginInfo(xhttp.responseText)
			        }
			        //document.all.msg.innerHTML = xhttp.responseText;
				}				
			}
			else
			{
				//document.all.msg.innerHTML = "登录失败，请您重新刷新页面";
			}
		}
		else
		{
			//document.all.msg.innerHTML = "正在登录，请稍后...";
		}
	}
	xhttp.open("GET", url ,true);
	xhttp.send(null);
}

//login
function getLoginBar(user,pass,state)
{
    submitLog("../tools/ajax.aspx?username="+user+"&password="+pass+"&oper=login&state="+state, state);
}

//最近来访公司
function LatestVisitCompany(num)
{
    submitLatestVisitCompany("../tools/LatestVisitCompany.aspx?num="+num);
}

//Submit LatestVisitCompany
function submitLatestVisitCompany(url)
{
    var xhttp = new HTTPRequest();
	xhttp.open("GET", url ,false);
	xhttp.send(null);
	document.write(xhttp.responseText);
}

//论坛最新帖子
function LatestBBS(num)
{
    submitLastBBS("../tools/LatestBBS.aspx?num="+num);
}

//Submit LatestBBS
function submitLastBBS(url)
{
    var xhttp = new HTTPRequest();
	xhttp.open("GET", url ,false);
	xhttp.send(null);
	document.write(xhttp.responseText);
}

//登录次数排行
function GetLoginCount()
{
    submitLoginCount("../tools/LoginCount.aspx");
}

//Submit LoginCount
function submitLoginCount(url)
{
    var xhttp = new HTTPRequest();
	xhttp.open("GET", url ,false);
	xhttp.send(null);
	document.write(xhttp.responseText);
}

//求购Login
//login
function QiugouLogin(user,pass,state)
{
    submitQiugouLogin("../tools/ajax.aspx?username="+user+"&password="+pass+"&oper=login&state="+state, state);
}

//Submit QiugouLogin
function submitQiugouLogin(url, state)
{
var xhttp = new HTTPRequest();
    xhttp.onreadystatechange = function()
	{
		if(xhttp.readyState!=4)
		{
			//document.all.msg.innerHTML = "登录中...";
		}
		else if(xhttp.readyState==4)
		{
			if(xhttp.status==200)
			{
			    if(xhttp.responseText == "" || xhttp.responseText == "0")
			    {
			        if(state == "1")
			        {
			            alert("用户名或密码无效");
			            //document.all.msg.innerHTML = "用户名或密码无效";
			        }
			        else
			        if(state == "0")
			        {
			            //document.all.msg.innerHTML = "";
			        }
			    }
			    else
			    if(xhttp.responseText != "" && xhttp.responseText != "0")
			    {
			        if(xhttp.responseText == "disableip")
			        {
			            alert('您的IP已被禁用，请与管理员联系！');
			        }
			        else
			        {
			            window.location = window.location;
			        }
			        //document.all.msg.innerHTML = xhttp.responseText;
				}				
			}
			else
			{
				//document.all.msg.innerHTML = "登录失败，请您重新刷新页面";
			}
		}
		else
		{
			//document.all.msg.innerHTML = "正在登录，请稍后...";
		}
	}
	xhttp.open("GET", url ,true);
	xhttp.send(null);
//    var xhttp = new HTTPRequest();
//	xhttp.open("GET", url ,false);
//	xhttp.send(null);
	//document.write(xhttp.responseText);
//	window.location = window.location;
}
//Check login
function chkLogin(state)
{
    var username = document.getElementById("_yonghumingshurukuang_id").value;
	var password = document.getElementById("_mimashurukuang_id").value;
	if(state == "1")
	{
        if (username == "")
	    {
		    alert("【用户名】不能为空！\n");
		    document.getElementById("_yonghumingshurukuang_id").focus();
		    return false;
	    }
        
	    if (password == "")
	    {
		    alert("【密码】不能为空！\n");
		    document.getElementById("_mimashurukuang_id").focus();
		    return false;
	    }
	}
	getLoginBar(username,password,state);
}

//Login Info
function getLoginInfo(info)
{
    document.getElementById("_mylogindiv").innerHTML = info;
}

//KeyDown Login
function SubmitLogin(state)
{
    if (event.keyCode == 13)
    {
        chkLogin(state);
    }
}
function SubmitKeyClick(button) 
{ 
 if (event.keyCode == 13 && document.all["_sousuoneirong"].value.trim().length != 0)
 { 
    document.all[button].focus();   
 }
}

    //Check login
function chkLogin1(state)
{
    var username1 = document.getElementById("_yonghumingshurukuang_id1").value;
	var password1 = document.getElementById("_mimashurukuang_id1").value;
	if(state == "1")
	{
        if (username1 == "")
	    {
		    alert("【用户名】不能为空！\n");
		    document.getElementById("_yonghumingshurukuang_id1").focus();
		    return false;
	    }
        
	    if (password1 == "")
	    {
		    alert("【密码】不能为空！\n");
		    document.getElementById("_mimashurukuang_id1").focus();
		    return false;
	    }
	}
	QiugouLogin(username1,password1,state);
}
//Check login
function chkLogin2(state)
{
    var username2 = document.getElementById("_yonghumingshurukuang_id2").value;
	var password2 = document.getElementById("_mimashurukuang_id2").value;
	if(state == "1")
	{
        if (username2 == "")
	    {
		    alert("【用户名】不能为空！\n");
		    document.getElementById("_yonghumingshurukuang_id2").focus();
		    return false;
	    }
        
	    if (password2 == "")
	    {
		    alert("【密码】不能为空！\n");
		    document.getElementById("_mimashurukuang_id2").focus();
		    return false;
	    }
	}
	QiugouLogin(username2,password2,state);
}
//KeyDown Login1
function SubmitLogin1(state)
{
    if (event.keyCode == 13)
    {
        chkLogin1(state);
    }
}
//KeyDown Login2
function SubmitLogin2(state)
{
    if (event.keyCode == 13)
    {
        chkLogin2(state);
    }
}
