//获取屏幕坐标，by Yipeng
// document.domain = "tom.com";
 var sb = {x: 0, y: 0, w: 0, h: 0};
 var cw = 0, ch = 0;
 function getScreen(){
  if (window.scrollWidth) {
	sb = {x: window.scrollLeft, y: window.scrollTop, w: window.scrollWidth, h: window.scrollHeight};
  } else if (document.documentElement.scrollWidth) {
	sb = {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop, w: document.documentElement.scrollWidth, h: document.documentElement.scrollHeight};
  } else if (document.body.scrollWidth) {
	sb = {x: document.body.scrollLeft, y: document.body.scrollTop, w: document.body.scrollWidth, h: document.body.scrollHeight};
  }

  if (window.innerHeight) {
    cw = window.innerWidth;
    ch = window.innerHeight;
  } else if (document.documentElement.clientHeight) {
    cw = document.documentElement.clientWidth;
    ch = document.documentElement.clientHeight;
  } else if (document.body.clientHeight) {
    cw = document.body.clientWidth;
    ch = document.body.clientHeight;
  } else {
    cw = ch = 0;
  }
}

function nba_expert_login_send(url, config) {
	try {
		var xmlObj = null;
		if(window.XMLHttpRequest) {
			xmlObj = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			return;
		}
		xmlObj.onreadystatechange = function() {
			if(xmlObj.readyState == 4) {
				if(xmlObj.status == 200) {
					call_back(xmlObj.responseText);
				}
				else {
					alert("您所请求的页面有异常！");
				}
			}
		}
		xmlObj.open(config.method, url, true);
		xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
		xmlObj.send(config.params);
	}
	catch (e) {
	}
}

function nba_expert_login_get () {
	var username = document.getElementsByName("username")[0].value;
	username = encodeURIComponent(username);
	
	var Password = document.getElementsByName("password")[0].value;
	Password = encodeURIComponent(Password);
	
	var returnType = document.getElementsByName("returnType")[0].value;
	returnType = encodeURIComponent(returnType);
	
	var config = {method: 'POST'};
	var tUrl = "/User_Login.php"
	config.params = "username="+username+"&password="+Password+"&returnType="+returnType;
	nba_expert_login_send(tUrl, config);
}

function call_back(info) {
	if (info && (info = eval('('+info+')'))) {
		parent.calledByIframe(info);
	} else {
		alert('用户名或密码不正确！');
	}
}

function login_validator(form) {
	if (form.username.value == "" || form.password.value == "") {
	showWindow('/User_LoginByLayer.php', 'refresh');
	return false;
	}
}
function calledByIframe(pInfo) {
	if (typeof window.callType == 'string') {
		switch(window.callType) {
			case 'refresh' : window.location.href = window.location.href+"?"+new Date().getTime();
											break;
			case 'gotoUserCenter' :
										window.location.href = '/User_UserCenter.php';
										break;
			case 'gotoIndex':   window.location.href = '/User_Index.php';
										break;
			case 'gotoQuestion':   window.location.href = '/User_Question.php';
										break;							
		}
	} else if(window.callType.href) {
		window.location.href = window.callType.href;
	} else if(typeof window.callType == 'function') {
		window.callType.call(this, window.targetEle);
	}
}

function getById(id) {
	return document.getElementById(id);
}

function  locking(pCallType, pTarget){  
	getById('Layer2').src || (getById('Layer2').src = '/User_LoginByLayer.php');
	window.callType  = pCallType || 'refresh';
	window.targetEle = pTarget || '';
  getById('ly').style.display  = "block";  
  getById('ly').style.width    = document.body.clientWidth + 'px';  
  getById('ly').style.height   = document.body.clientHeight + 'px';  
	/*if(window.innerHeight){
	  h = window.innerHeight;//Mozilla
	 }else if(document.documentElement.clientHeight){
	  h = document.documentElement.clientHeight;//IE6
	 }else{
	  h = document.body.clientHeight;//IE5.x
	 }
	tTop = h/2-84+document.documentElement.scrollTop;
  getById('Layer2').style.left = (document.body.clientWidth-267)/2 + 'px';
 getById('Layer2').style.top  = tTop + 'px';*/
	 getScreen();
	getById('Layer2').style.top =((ch - getById('Layer2').offsetHeight) / 2 + sb.y-100) + "px";
	getById('Layer2').style.left = ((cw - getById('Layer2').offsetWidth) / 2 + sb.x-100) + "px"; // 屏幕居中 by Yipeng
  getById('Layer2').style.display='block'; 
}

function showWindow(pUrl, pCallType, pTarget,pJudgelogin) {
	if(1 == pJudgelogin)
	{
		if(readcookie('TOM_QU')){
			//window.location.href=pTarget.href;
			return true;
		}
	}
	getById('Layer2').src=pUrl;
	locking(pCallType, pTarget);
	return false;
}
function  Lock_CheckForm(){
  getById('ly').style.display='none';
  getById('Layer2').style.display='none'; 
  try {
  	getById('Layer2').Document.body.innerHTML ='';
  } catch(e) {
  	getById('Layer2').contentDocument.body.innerHTML ='';
  }
  return  false;
}

function navdirect(pEle, pType) {
		window.location.href = '/UserCenter.php?gourl='+encodeURIComponent(window.location.href);
	}

function readcookie(name) {
		var cookieValue = "";
		var search = name + "=";
		if(document.cookie.length > 0) { 
			offset = document.cookie.indexOf(search);
			if (offset != -1) { 
				offset += search.length;
				end = document.cookie.indexOf(";", offset);
				if (end == -1) end = document.cookie.length;
				cookieValue = decodeURIComponent(document.cookie.substring(offset, end))
			}
	}
		return cookieValue;
	}

