﻿// JScript 文件
var isIe=(document.all)?true:false; 
//设置select的可见状态 
function setSelectState(state) 
{ 
var objl=document.getElementsByTagName('select'); 
for(var i=0;i<objl.length;i++) 
{ 
objl[i].style.visibility=state; 
} 
} 
function mousePosition(ev) 
{ 
if(ev.pageX || ev.pageY) 
{ 
return {x:ev.pageX, y:ev.pageY}; 
} 
return { 
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop 
}; 
} 
//弹出方法 
function showMessageBox(wTitle,content,pos,wWidth) 
{ 
closeWindow(); 
var bWidth=parseInt(document.documentElement.scrollWidth); 
var bHeight=parseInt(document.documentElement.scrollHeight); 
if(isIe){ 
setSelectState('hidden');} 
var back=document.createElement("div"); 
back.id="back"; 
var styleStr="top:0px;left:0px;position:absolute;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;"; 
styleStr+=(isIe)?"filter:alpha(opacity=0);":"opacity:0;"; 
back.style.cssText=styleStr; 
document.body.appendChild(back); 
showBackground(back,50); 
var mesW=document.createElement("div"); 
mesW.id="mesWindow"; 
mesW.className="mesWindow"; 
mesW.innerHTML="<div class='mesWindowTop'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:1px;'><input type='button' onclick='closeWindow();' title='关闭窗口' class='close2' value='关闭' /></td></tr></table></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>"; 

var left = (screen.width/2) - 350/2;
var top = (screen.height/2) - 235;
  
styleStr="left:"+left+"px;top:"+top+"px;position:absolute;width:"+wWidth+"px;"; 
mesW.style.cssText=styleStr; 
document.body.appendChild(mesW); 
} 
//让背景渐渐变暗 
function showBackground(obj,endInt) 
{ 
if(isIe) 
{ 
//obj.filters.alpha.opacity+=1; 
//if(obj.filters.alpha.opacity<endInt) 
//{ 
setTimeout(function(){showBackground(obj,endInt)},5); 
//} 
}else{ 
var al=parseFloat(obj.style.opacity);al+=0.01; 
obj.style.opacity=al; 
if(al<(endInt/100)) 
{setTimeout(function(){showBackground(obj,endInt)},5);} 
} 
} 
//关闭窗口 
function closeWindow() 
{ 
if(document.getElementById('back')!=null) 
{ 
document.getElementById('back').parentNode.removeChild(document.getElementById('back')); 
} 
if(document.getElementById('mesWindow')!=null) 
{ 
document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow')); 
} 

if(isIe){ 
setSelectState('');} 
} 
//测试弹出 
function testMessageBox(ev) 
{ 
var objPos = mousePosition(ev); 
messContent="<form method='post'  id='api_login' class='api_ajax_window'><div class='tophead'>登录 Searchina 通行证</div><img class='crossway_icon' src='/inc/imgs/lock.gif' height='60' width='53'><div class='login_tip'>登录 Searchina 通行证，继续下面的操作。</div><table border='0' cellpadding='0' cellspacing='0'>  <tbody><tr>    <td class='col_1'>用户名</td>    <td class='col_2'><input name='txtUserName' id='txtUserName' value='' class='input' type='text'></td>  </tr>  <tr>    <td class='col_1'>密码</td>    <td class='col_2'><input name='txtPassWord' id='txtPassWord' value='' class='input' type='password'></td>  </tr></tbody></table><div class='login_tip'><span style='color: rgb(137, 37, 253);'>没有 Searchina 通行证？</span><a href='http://www.searchina.net.cn/reg/UserReg.aspx' ><span style='color: rgb(255, 0, 0);'>立即注册！</span></a></div><div class='form_foot'><input value='登 录' class='button submit' type='button' style='cursor:pointer' onclick='validatelogon();'> <input value='重置' class='button reset' type='reset'></div></form>"; 
showMessageBox('用户登录',messContent,objPos,350); 
document.getElementById("txtUserName").focus();
} 
var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function validatelogon()
{
    var loginname=filter(escape(document.getElementById("txtUserName").value));
    var password=filter(escape(document.getElementById("txtPassWord").value));
    
    if(loginname=="")
    {
        alert("请输入用户名！");
		document.getElementById("txtUserName").focus();
        return false;
    }
    if(password=="")
    {
        alert("请输入密码！");
		document.getElementById("txtPassWord").focus();
        return false;
    }

    
    var url = "/myboom/loginin.asp?a="+loginname+"&b="+password;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.onreadystatechange = getdata;
	xmlHttp.send(null);
}
function filter(str)
{
    str = str.replace(/\+/g,"%2B");
    str = str.replace(/\&/g,"%26");
    return str;
}

function getdata()
{
    //alert(xmlHttp.readyState);
	if(xmlHttp.readyState==4)
    {
		if(xmlHttp.status==200)
        {
	        var text=xmlHttp.responseText;
			var aaaa=text.split("|&|");	
			//alert(aaaa[1]);
			if(aaaa[1].toLowerCase().indexOf('yes')>=0)
			{
				alert("登陆成功");
				window.location.reload();
			}
			else
			{
				alert("登录失败，请重新登录！");
				document.getElementById("txtUserName").value='';
				document.getElementById("txtPassWord").value='';
				document.getElementById("txtUserName").focus();
				return false;				

			}	         
        }
    }
}
function getOs()  
{  
   var OsObject = "";  
   if(navigator.userAgent.indexOf("MSIE")>0) {  
        return "MSIE";       //IE浏览器
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
        return "Firefox";     //Firefox浏览器
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {  
        return "Safari";      //Safan浏览器
   }
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){  
        return "Camino";   //Camino浏览器
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){  
        return "Gecko";    //Gecko浏览器
   }  
} 
