// JavaScript Document
function login(){
if($('username').value==''){
	alert("帐号必须！");
	$('username').focus(); 
	return;  
		}
if($('pwd').value==''){
	alert("密码必须！");
	$('pwd').focus();   
	return false;
	}

var data="username="+ encodeURIComponent(encodeURIComponent($('username').value))+"&pwd="+ encodeURIComponent(encodeURIComponent($('pwd').value))+"&user_type="+ getValue('user_type');
//alert(data);
login_2(data);
}


function login_2(data)
{	
//alert(data+str);
var xmlhttp = newXMLHttpRequest();
	if (!xmlhttp){
		dialogShow('Err', '创建XMLHTTP对象失败');
	}
	try {	
		xmlhttp.open('POST', 'login.asp', true);
	}catch(e){
		document.getElementById(Tid).innerHTML ='错误!';
	}	
	xmlhttp.onreadystatechange = login3(xmlhttp);
	//xmlhttp.setrequestheader("content-length",data.length); 
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded;")
	if (xmlhttp.overrideMimeType) {
		xmlhttp.overrideMimeType('text/xml');
	}
	xmlhttp.send(data);	
}
function login3(req) {
		return function () { 
			if (req.readyState == 4 && req.status == 200) {
					var tt= req.responseXML;
					//alert(req.responseText);
					var result =tt.getElementsByTagName("result")[0].firstChild.nodeValue;
					var msg =tt.getElementsByTagName("msg")[0].firstChild.nodeValue;
					if (result=='succ'){
						
						if (getValue('user_type')=='1')
						window.location.href='/company/company_center.asp';
						//window.location.reload();
						else
						window.location.href='/person/person_center.asp';
				        //$('yes_login').innerHTML=msg;
						 //$('yes_login').style.display='';
						// $('loading').style.display='none';
						// $('no_login').style.display='none';
					}
					else{
						alert(msg);
						$('loading').style.display='none';
					}
				} 
			else 
				{ 
					 $('loading').style.display='';
				} 
		
	} 
}
