﻿// 匹配帐号是否合法(字母开头，允许5-20字节，允许字母数字下划线)
function validateAccount(account)
{
    var reg = /^[a-zA-Z][a-zA-Z0-9_]{4,19}$/;
    var ret = account.match(reg);
    return null == ret ? false : true;
}


// 匹配电子邮箱
function validateEmail(email)
{
    var reg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var ret = email.match(reg);
    return null == ret ? false : true;
}

// 在各种浏览器下创建XMLHTTPRequest对象
function createXmlHttpRequest()
{
	/* Create a new XMLHttpRequest object to talk to the Web server */
	var xmlHttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try 
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e2)
		{
			xmlHttp = false;
		}
	}
	@end @*/
 
	if(!xmlHttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlHttp = new XMLHttpRequest();
	}
	
	return xmlHttp;	
}

function closeMe()
{
    window.close();
    if(window.opener) 
        window.opener.focus();
}

// 发送忘记密码的邮件
function sendPasswordEmail(receiver,loginAccount,loginPwd)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/SendPasswordEmail.asp?receiver=" + encodeURI(receiver) + "&LoginAccount=" + encodeURI(loginAccount) + "&LoginPwd=" + encodeURI(loginPwd);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        alert("密码已发送到您的邮箱，请注意查收。");
        return true;
    }
    else
    {
        alert(ret);
        return false;
    }
    
}

// 发送注册成功的邮件
function sendRegisterOKEmail(receiver,loginAccount,loginPwd,memberType)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/RegisterOKEmail.asp?receiver=" + encodeURI(receiver) + "&LoginAccount=" + encodeURI(loginAccount) + "&LoginPwd=" + encodeURI(loginPwd) + "&MemberType=" + encodeURI(memberType);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        return true;
    }
    else
    {
        //alert(ret);
        return false;
    }
    
}

// 发送毕业生简历的邮件
function sendGraduateEmail(receiver,graduateID,graduateName)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/SendGraduateEmail.asp?receiver=" + encodeURI(receiver) + "&GraduateID=" + graduateID.toString() + "&GraduateName=" + encodeURI(graduateName);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        return true;
    }
    else
    {
        //alert(ret);
        return false;
    }
}

// 发送简历的邮件
function sendResumeEmail(receiver,resumeID,yourName)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/SendResumeEmail.asp?receiver=" + encodeURI(receiver) + "&ResumeID=" + resumeID.toString() + "&YourName=" + encodeURI(yourName);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        return true;
    }
    else
    {
        //alert(ret);
        return false;
    }
}

// 发送职位的邮件
function sendJobEmail(receiver,jobID,jobTitle)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/SendJobDetail.asp?receiver=" + encodeURI(receiver) + "&JobID=" + jobID.toString() + "&JobTitle=" + encodeURI(jobTitle);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        return true;
    }
    else
    {
        //alert(ret);
        return false;
    }
}

// 发送其它通用的邮件
function sendCommonEmail(receiver,subject,body)
{
    var xmlHttp = createXmlHttpRequest();
    if(!xmlHttp)
    {
        alert("浏览器不支持该功能，发送邮件失败，请使用IE或网景浏览器。");
        return false;
    }
    
    var url = "/tools/SendJobEmail.asp?receiver=" + encodeURI(receiver) + "&Subject=" + encodeURI(subject) + "&Body=" + encodeURI(body);
    xmlHttp.open("get",url,false);
    xmlHttp.send();
    var ret = xmlHttp.responseText;
    xmlhttp = null;
    
    if(ret == "0")
    {
        return true;
    }
    else
    {
        //alert(ret);
        return false;
    }
}

// 弹出窗口会话结束的处理
function sessionEndOnPopWin()
{
    alert("对不起，会话已过期或您还没有登录，请重新登录系统。");
    window.close();
    if(window.opener)window.opener.focus();
}

// 弹出窗口无权限时的提示信息
function showNoAuthorityMsgOnPopWin()
{
    alert("对不起，您没有访问该页面的权限！");
    window.close();
    if(window.opener)window.opener.focus();
}

// 会话结束的处理
function onSessionEnd(goUrl)
{
    alert("对不起，会话已过期或您还没有登录，请重新登录系统。");
    window.location.href = goUrl;
}

// iFrame检测到会员结束的处理
function onIFrameSessionEnd(goUrl)
{
    alert("对不起，会话已过期或您还没有登录，请重新登录系统。");
    window.parent.location.href = goUrl;
}

// 无权限时的提示信息
function showNoAuthorityMsg(goUrl)
{
    alert("对不起，您没有访问该页面的权限！");
    if(window.parent)
        parent.window.location.href = goUrl;
    else
        window.location.href = goUrl;
}

// 显示日历
function showCalendar(objTarget)
{
    var ff = "dialogWidth:150px; dialogHeight:240px; scroll:no; status:no; help:no; center:yes;";
    var url = "/tools/Calendar.htm";
    window.showModalDialog(url,objTarget,ff);
}

// 验证日期是否有效
function validateDate(sDate)
{
    var objXmlHttp = createXmlHttpRequest();
    if(!objXmlHttp)
    {
        alert("浏览器不支持XMLHTTP。");
        return false;
    }
    
    var url = "/Tools/ValidateDate.aspx?CheckDate=" + escape(sDate);
    objXmlHttp.open("post",url,false);
    objXmlHttp.send();
    var ret = objXmlHttp.responseText;
    objXmlHttp = null;
    
    return ret == "0" ? true : false;
}

