//注册第一步检查邮箱
function CheckRegister(objEmal, objWarn){
	var strEmail = gid(objEmal).value;
	var strUrl = gid("theUrl").value;
	strUrl = escape(strUrl);
	
	HideObj("warn_3");
	
	if(strEmail == null || strEmail == ""){
	    gid(objEmal).className="Warning";
		showmsg(objWarn, "请输入您常用的电子邮件地址");
	}
	else if(isEmail(strEmail) == false){
	    gid(objEmal).className="Error";
		showmsg(objWarn, "电子邮件地址格式错误！");
	}
	else{
		window.location.href = "register.aspx?email="+escape(strEmail)+"&TheUrl="+strUrl;
		//parent.location.replace("register.aspx");
	}
}

//login.aspx页回车登录
function KeyLogin(frm, objInputUser, objInputPassword, objWarn, event)
{
  	if(event.keyCode == 13)   
  	{
  		checkLogin(frm, objInputUser, objInputPassword, objWarn);
	}	
}
//登录检查
function checkLogin(frm, objInputEmail,objInputPassword,objWarn)
{
	var strEmail = gid(objInputEmail).value;
	var strPass = gid(objInputPassword).value;

	if(strEmail == null || strEmail == "")
	{
		alert("如果您已注册成为TT中国的会员\n请输入注册时使用的电子邮件地址");
		gid(objInputEmail).focus();
		gid(objInputEmail).className="Warning";
		return false;
	}
	else if(isEmail(strEmail) == false)
	{
		alert("电子邮件地址格式错误！");
		gid(objInputEmail).focus();
		gid(objInputEmail).className="Error";
		return false;
	}
	else if(strPass == null || strPass == "")
	{
	    gid(objInputEmail).className="Ok";
		alert("请您输入密码");
		gid(objInputPassword).focus();
		gid(objInputPassword).className="Warning";
		return false;
	}
	else
	{
        document.getElementById("form1").target = "_parent";
		gid(frm).submit();
		return true;
	}
}

//登录(下载页弹出使用)
function CheckLogin(frm, objInputEmail,objInputPassword)
{
    CheckLogin(frm, objInputEmail,objInputPassword, 'view')
}
//回车登录方式(文章页使用)
function KeyDownLogin(frm, objInputUser, objInputPassword, event)
{
    KeyDownLogin(frm, objInputUser, objInputPassword, 'view',event)
}
function KeyDownLogin(frm, objInputUser, objInputPassword, stype, event)
{
  	if(event.keyCode == 13)   
  	{
        CheckLogin(frm, objInputUser, objInputPassword, stype);
	}	
}
function CheckLogin(frm, objInputEmail,objInputPassword, stype)
{
	var strEmail = gid(objInputEmail).value;
	var strPass = gid(objInputPassword).value;
    var strtarget = "_parent";
	if(strEmail == null || strEmail == "")
	{
		SetObjContent("warn_"+objInputEmail, "请输入您的电子邮件地址。");
        gid("warn_"+objInputEmail).className = "msg_Warning";
        
		gid(objInputEmail).focus();
		gid(objInputEmail).className = "WarningShort";
		
		return false;
	}
	else if(isEmail(strEmail) == false)
	{
		SetObjContent("warn_"+objInputEmail,"电子邮件地址格式错误。");
		gid("warn_"+objInputEmail).className = "msg_Error";
		
		gid(objInputEmail).focus();
		gid(objInputEmail).className="ErrorShort";
		
		return false;
	}
	else if(strPass == null || strPass == "")
	{
	    gid(objInputEmail).className = "OkShort";
	    gid("warn_"+objInputEmail).className = "msg_NormalShort";
	    SetObjContent("warn_"+objInputEmail, "电子邮件地址输入正确。");
		
		SetObjContent("warn_"+objInputPassword,"请输入登录密码");
		gid("warn_"+objInputPassword).className="msg_Error";
		
		gid(objInputPassword).focus();
		gid(objInputPassword).className="WarningShort";
		
		return false;
	}
	else
	{
	    if(stype == "download")
	    {
	        strtarget = "_blank";
	        document.location.reload();
	    }
	    document.getElementById("form1").target = strtarget; 
		gid(frm).submit();
		return true;
	}
}

//取回密码检查邮箱格式(register.asp)
function checkGetPass(objTxt, objWarn)
{
	var strEmail = gid(objTxt).value;
	
	HideObj("warn_1");
	
	if(strEmail == null || strEmail == "")
	{
		gid(objTxt).focus();
		gid(objTxt).className="Warning";
		showmsg(objWarn, "请输入您注册时填写的电子邮件地址");
	}
	else if(isEmail(strEmail) == false)
	{
		gid(objTxt).focus();
		gid(objTxt).className="Error";
		showmsg(objWarn, "电子邮件地址格式错误！");
	}
	else
	{
	    window.open("http://www.techtarget.com.cn/common/GetPassword.aspx?UserName="+escape(strEmail));
		//window.location.href = "http://www.techtarget.com.cn/common/GetPassword.asp?UserName="+strEmail;
		//gid("getPassForm").action = "getPass.asp?email="+strEmail
		//gid("getPassForm").submit();
	}
}


//(新版)取回密码检查邮箱格式(login.aspx)
function CheckPassword(objTxt, objWarn)
{
	var strEmail = gid(objTxt).value;
	HideObj("warn_1");
	if(strEmail == null || strEmail == "")
	{
		gid(objTxt).focus();
		gid(objTxt).className="Warning";
		showmsg(objWarn, "请输入您注册TechTarget中国时填写的电子邮件地址");
	}
	else if(isEmail(strEmail) == false)
	{
		gid(objTxt).focus();
		gid(objTxt).className="Error";
		showmsg(objWarn, "电子邮件地址格式错误！");
	}
	else
	{
	    window.open("/common/getpassword.aspx?username="+escape(strEmail));
	}
}

//重设密码检查
function checkSetPass(frm, objWarn)
{
	var newPass1 = gid("newPass1").value;
	var newPass2 = gid("newPass2").value;
	if(newPass1 == null || newPass1 == "")
	{
		gid("newpass1").focus();
		return showmsg(objWarn, "请输入您要重设的新密码");
	}
	else if(newPass1.length < 6)
	{
		gid("newpass1").focus();
		return showmsg(objWarn, "请输入6-15位字符的密码");
	}
	else if(newPass1 != newPass2)
	{
		return showmsg(objWarn, "两次输入的密码不相同");
	}
	else
	{
		gid(frm).submit();
		return true;
	}
}

//注册回车提交
function KeyDownReg(objInputUser, objWarn, event)
{
  	if(event.keyCode == 13)   
  	{
  		CheckRegister(objInputUser, objWarn);
	}
}
//取回密码回车
function KeyDownGetPassword(objInput, objWarn, event)
{
  	if(event.keyCode == 13)   
  	{
  		checkGetPass(objInput,objWarn);
	}	
}
function OpenRSS()
{
    window.open("CreateRSS.ashx?" + para);
}
///登录
function login(objName)
{
    //显示登录层
    ShowObj(objName);
    //灰化背景
    SetObjStyleName("over","over");
}
function HideLoginWindow(objName)
{
    //隐藏登录窗口
    HideObj(objName); 
    //取消灰化
    SetObjStyleName("over","overo");
}

/*****************************************************图片以弹出层形式显示***********************************************/
//获取ID值
function $(a){return document.getElementById(a);}
//关闭层
function hidden_div(obj){$(obj).style.display='none';}
//显示层
function show_div(obj){$(obj).style.display='block';}
//显示关闭层
function display_div(obj){var s=$(obj).style;if(s.display=="none"){s.display="block";}else{s.display="none";}}
//自定义层
function showdiv(obj,content,width,height,mode)
{
	//检测ID是否存在
	if($(obj))
	{
		//存在直接调用
		var oDiv=$(obj);
	}
	else 
	{
		//不存在生成一个并设置默认属性
		var oDiv=document.createElement("DIV");
			oDiv.id=obj;
			oDiv.className=obj;
		document.body.appendChild(oDiv);
	}
		//填充内容
		oDiv.innerHTML=content;
		//定义默认样式
		oDiv.style.width=width+"px";
		oDiv.style.display="block";
		//该模式完全自定义方式
		if(mode==1){
			//设置高度
			oDiv.style.height=height+"px";
		}else{
			//获取高度
			if (height==0){height=$(obj).offsetHeight;}
			//获取可视宽高
			var bt = document.documentElement.clientHeight-height;
			var bl = document.documentElement.clientWidth-width;
			//初始化
			var top,left;
			//非IE6及以下
			if (window.XMLHttpRequest){
				//计算位置
				top=(bt/2)-10;
				left=(bl/2);
				//使用决对定位
				oDiv.style.position='fixed';
			}else{
			
				//获取浏览器上卷和左卷
				var st = window.pageYOffset || document.documentElement.scrollTop;
				var sl = window.pageXOffset || document.documentElement.scrollLeft;

					//计算位置
					top=(bt/2)+st-10;
					left=(bl/2)+sl;
					//使用相对定位
					oDiv.style.position='absolute';
			}
			//设置位置
			oDiv.style.top=top+"px";
			oDiv.style.left=left+"px";
		}
}
function showbgdiv(obj,content,width,height,mode)
{
	//检测ID是否存在
	if($(obj))
	{
		//存在直接调用
		var oDiv=$(obj);
		oDiv.className="over";
	}
	else 
	{
		//不存在生成一个并设置默认属性
		var oDiv=document.createElement("DIV");
			oDiv.id=obj;
			oDiv.className=obj;
		document.body.appendChild(oDiv);
	}
		//填充内容
		//oDiv.innerHTML=content;
		//定义默认样式
		oDiv.style.width=width+"px";
		oDiv.style.display="block";
		//该模式完全自定义方式
		if(mode==1){
			//设置高度
			oDiv.style.height=height+"px";
		}else{
			//获取高度
			if (height==0){height=$(obj).offsetHeight;}

			//获取可视宽高
			var bt = document.documentElement.clientHeight-height;
			var bl = document.documentElement.clientWidth-width;
			//初始化
			var top,left;
			//非IE6及以下
			if (window.XMLHttpRequest){
				//计算位置
				top=(bt/2)-10;
				left=(bl/2);
				//使用决对定位
				oDiv.style.position='fixed';
			}else{
			
				//获取浏览器上卷和左卷
				var st = window.pageYOffset || document.documentElement.scrollTop;
				var sl = window.pageXOffset || document.documentElement.scrollLeft;

					//计算位置
					top=(bt/2)+st-10;
					left=(bl/2)+sl;
					//使用相对定位
					oDiv.style.position='absolute';
			}
			//设置位置
			oDiv.style.top=top+"px";
			oDiv.style.left=left+"px";
		}
}
//透明层
function showmask(){
	showbgdiv("over","",document.documentElement.scrollWidth,document.documentElement.scrollHeight,1)
}
/*********************************************************
简单图片显示，兼容所有浏览器
*********************************************************/
function showimg(url) {
	//显示进度
	showdiv("imgline","图片加载中……",200,30);
	//替换为原图网址
var wx=document.documentElement.clientWidth-40
var hx=document.documentElement.clientHeight-40
var width,height,openw,openstr;openw=false;openstr=""
//初始化
var img = new Image();
	img.src = url;
	//检测是否存在缓存
	img.complete?ImgOK():img.onload=ImgOK;
	function ImgOK(){
		//透明层
		width=img.width;
		height=img.height;
		//检测宽高度
		if(width>wx){height=(wx/width)*height;width=wx;openw=true;}
		if(height>hx){width=(hx/height)*width;height=hx;openw=true;}
		//隐藏进度
		hidden_div("imgline");
		showmask()
		//是否显示原图连接
		openstr="<div id=\"imgshow\" class=\"imgshow_box\"><div class=\"imgshow_prompt\"><span class=\"img_close\"><img src=\"http://club.techtarget.com.cn/images/common/newwindow.gif\" alt=\"在新窗口中打开\" onclick=\"ShowTruePic();\" style=\" cursor:pointer;\">&nbsp;&nbsp;<img src=\"http://club.techtarget.com.cn/images/common/close.gif\" alt=\"关闭\" onclick=\"HideShowPicWindow();\" style=\" cursor:pointer;\"/></span>";
		outdivstr="</div>";
		//显示图片
		showdiv("imgshow",openstr+"<img id=\"img_showpic\" src="+url+" class=\"img_showpic\" onclick=\"HideShowPicWindow();\" style=\"cursor:pointer;width:"+width+"px;height:"+height+"px;\" title=\"点击关闭\">"+outdivstr,width,height);return false;}
}
function ShowTruePic()
{
    var url=document.getElementById("img_showpic").src;
    window.open(url);
}
function HideShowPicWindow()
{
    //隐藏登录窗口
    hidden_div('imgshow');
    
    //取消灰化
    $("over").className="overo";
}
/****************************************结束*************************************************************/