$(document).ready(function(){
	//去除超级链接外围虚线框
	$("a").bind("focus",function(){
		if(this.blur){ //如果支持 this.blur
			this.blur(); 
		}
	});
	if(document.getElementById("username") != null && document.getElementById("username") != '' && document.getElementById("username") != 'undefined')
		isBox(document.getElementById("username"));


	if ( $("#username").val()=="" )
	{
		$("#username").focus();
	}else{
		$("#password").focus();
	}
	$(document).keydown(function(){if(event.keyCode==13){
		//event.keyCode='9';
		login(document.loginform);
	}});
	resetSizes();
    window.onresize=resetSizes
});

function login(from) {

	if ( isBox(from.name)) {
		alert('请填写用户名!');
		from.name.focus();
		return false;
	}
	if ( isBox(from.pwd)) {
		alert('请填写密码!');
		from.pwd.focus();
		return false;
	}
	
	if ( from.is_code.value>=1 )
	{
		if ( isBox(from.valid2)) {
			alert('请填写验证码!');
			from.valid2.focus();
			return false;
		}
	}
	from.action="index.php?module=login&action=checkLogin";
	from.submit();
}

function isBox(obj){
	
	if (obj.value.length==0) { return true;}
	if (/\s+/g.test(obj.value)) {
		obj.value = obj.value.replace(/\s+/g,"");
		return true;
	}else{
		return false;
	}
}

function checkCorpabbr(abbr){
	$.post("index.php?module=login&action=checklogins&ajax=abbr",
       { name: abbr },
       function(data){
          if (data == 1)
          {
			  $("#s_info").html("&radic;");
			  $("#tab_user").css('display','block');
          }
		  else if(data == 0){
			   $("#s_info").html("&times;");
			   $("#tab_user").css('display','none');
		  }
		   else if(data == 2){
			   $("#s_info").html("该用户已到期!");
			   $("#tab_user").css('display','none');
		  }
       } 
	); 
}

function resetSizes()
{
    var theBody=document.getElementById("main_body");
    var theBg=document.getElementById("showBG");
    if(theBg && theBody)
    {
        var minus = theBody.scrollHeight > theBody.clientHeight ? 15 : 0;
        theBg.style.width=document.body.clientWidth-minus;
        minus = theBody.scrollWidth > theBody.clientWidth ? 15 : 0;
        theBg.style.height=document.body.clientHeight-minus;
    }
    var scrHelp=document.getElementById("ScrollHelpDiv");
    if(scrHelp)
    {
        with(scrHelp.style)
        {
            width=theBody.scrollWidth;
            height=theBody.scrollHeight;
        }
    }
}

//获取客户端MAC地址，写入SESSION
function getClientMac(){
	document.writeln('<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>');
	document.writeln('<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>');
	document.writeln('<SCRIPT   language=JScript>');
	document.writeln('var   service   =   locator.ConnectServer();');
	document.writeln('var   MACAddr   ;');
	document.writeln('var   IPAddr   ;');
	document.writeln('var   DomainAddr;');
	document.writeln('var   sDNSName;');
	document.writeln('var	  count = 1;');
	document.writeln('service.Security_.ImpersonationLevel=3;');   
	document.writeln('service.InstancesOfAsync(foo, \'Win32_NetworkAdapterConfiguration\');');  
	document.writeln('</SCRIPT>');
	document.writeln('<SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>'); 
	document.writeln('if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true && count == 1){');
	document.writeln('if(objObject.MACAddress != null && objObject.MACAddress != "undefined")'); 
	document.writeln('MACAddr = objObject.MACAddress;');
	document.writeln('if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")');
	document.writeln('IPAddr = objObject.IPAddress(0);');
	document.writeln('if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")');
	document.writeln('sDNSName = objObject.DNSHostName;');
	document.writeln('count++;');
	document.writeln('}');
	document.writeln('</SCRIPT>');
	document.writeln('<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">');
	document.writeln('var client_macaddr =unescape(MACAddr);');
	document.writeln('var client_ipaddr =unescape(IPAddr);');
	document.writeln('var client_dnsname =unescape(sDNSName);');
	document.writeln('$.ajax({');
	document.writeln('	  async: false,');
	document.writeln('	  type: "POST",');
	document.writeln('	  url: "index.php?module=login&action=showlogin",');
	document.writeln('	  data: "loadJs=yes&act=getmac&ipaddr=" + client_ipaddr + "&macaddr=" + client_macaddr + "&dnsname=" + client_dnsname,');
	document.writeln('	  success: function( info_data ){');
	document.writeln('		//alert(info_data);');
	document.writeln('	  }');
	document.writeln('	});');
	document.writeln('</script> ');
}
