/* yxg namespace */
var yxg = {};
yxg.alphaBg = null;

/* 错误信息映射 */
yxg.errorsMapping = {
	"1":"用户名不能为空！",
	"2":"密码不能为空！",
	"3":"验证码输入有误！",
	"4":"查询类型错误！",
	"1000":"谷豆不足，不能进行该操，不能进行该操，不能进行该操纵！"
}
/* 显示错误消息 */
yxg.createPopupWin = function ( width, height, id, title, errorStr ){
	if(location.href != parent.location.href){
		parent.eval("yxg.createPopupWin('"+ width +"' , '"+ height +"' , '"+ id +"' , '"+ title +"' , '"+ errorStr +"' );");
		return;
	}
	var popupWin = document.getElementById(id);
	var t = yxg.getElementsByClassName("t", "div", id);
	if( typeof errorStr == "string" && errorStr != "" ){  //用于显示错误
		var errorsHTML="";
		var errors = errorStr.split("|");
		for(var i=0;i<errors.length;i++){
			errorsHTML += yxg.errorsMapping[errors[i]] + "<br/>";
		}
		document.getElementById("errorsAlertCont").innerHTML = errorsHTML;
	}
	if(title != ""){ //设置标题
		var popupWinTitle = yxg.getElementsByClassName("popupWinTitle", "span", id);
		//popupWinTitle[0].innerHTML = title + "：";
	}
	
	if(width != ""){ //设置宽度
		popupWin.style.width = width + "px";
		var popupWinMidWrap = yxg.getElementsByClassName("popupWinMidWrap", "div", id);
		popupWinMidWrap[0].style.width = width - 6 + "px";
		var popupWinMid = yxg.getElementsByClassName("popupWinMid", "div", id);
		popupWinMid[0].style.width = width - 8 + "px";
		//t[0].style.width = width - 28 + "px";
		var c = yxg.getElementsByClassName("c", "div", id);
		c[0].style.width = width - 41 + "px";
	}
	if(height != ""){//设置高度
		var c = yxg.getElementsByClassName("c", "div", id);
		c[0].style.height = height + "px";
	}
	function posWin(){
		var browserWidth = parseInt(document.documentElement.clientWidth);
		var browserHeight = parseInt(document.documentElement.clientHeight);
		var browserScrollLeft = parseInt(document.documentElement.scrollLeft);
		var browserScrollTop = parseInt(document.documentElement.scrollTop);
		
		var popupWinWidth = parseInt(popupWin.clientWidth);
		var popupWinHeight = parseInt(popupWin.clientHeight);
		popupWin.style.left = (browserWidth / 2 - popupWinWidth / 2 + browserScrollLeft)+"px";
		popupWin.style.top = (browserHeight / 2 - popupWinHeight / 2 + browserScrollTop)+"px";
		yxg.showAlphaBg();
	}
	popupWin.style.display = "block";
	var closePopupWinPic = yxg.getElementsByClassName("closePopupWinPic", "div", id);
	//closePopupWinPic[0].onclick = function(){ yxg.closePopupWinHandle(id) };
	posWin();
	
	function followCursor(event){
	
	}
	
	function unFollowCursor(event){
		
	}
	
	if(window.attachEvent){
	   window.attachEvent("onresize",posWin);
	  //t[0].attachEvent("onmousedown",followCursor);
	  //t[0].attachEvent("onmouseup",unFollowCursor);
	}else{
	    window.addEventListener("resize",posWin,true);
	  //t[0].addEventListener("mousedown",followCursor,true);
	  //t[0].addEventListener("mouseup",unfollowCursor,true);
	}
}

/* 关闭提示框时触发 */
yxg.closePopupWinHandle = function(id){
	document.getElementById(id).style.display = "none";
	yxg.closeAlphaBg();
}

//隐藏透明背景
yxg.closeAlphaBg = function(){
	yxg.alphaBg.style.display = "none";
}

//显示透明背景
yxg.showAlphaBg = function(){
	if(yxg.alphaBg == null){
		yxg.alphaBg = document.createElement("DIV");
		yxg.alphaBg.setAttribute("id","alphaBg");
		document.body.appendChild(yxg.alphaBg);
	}
	yxg.alphaBg.style.width = document.documentElement.scrollWidth+"px";
	yxg.alphaBg.style.height = document.documentElement.scrollHeight+"px";
	yxg.alphaBg.style.display = "block";
}

yxg.getElementsByClassName = function(classname, el, root){
	var _root = document.getElementById(root);
	var els = _root.getElementsByTagName(el);
	var nodes = [];
	for(var i=0 ; i<els.length; i++){
		if(els[i].className == classname){
			nodes.push(els[i]);
		}
	}
	return nodes;
}