var xmlHttp; //定义一个XMLHttpRequest全局变量
//用于创建XMLHttpRequest对象
function createXmlHttp() {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
//获取页面信息的调用函数
function switchPage(srcTab, pageName) {
resetTabs();
srcTab.className = "person_menu";
createXmlHttp(); //创建XmlHttpRequest对象
xmlHttp.onreadystatechange = writePageInfo;
xmlHttp.open("GET", pageName, true);
xmlHttp.send(null);
}
//获取页面信息的回调函数
function writePageInfo() {
if(xmlHttp.readyState == 4){
var pageInfo = xmlHttp.responseText;
document.getElementById("pageInfo").innerHTML = pageInfo;
}
}
//恢复所有标签的class属性
function resetTabs() {
//获取tabdiv下的所有a节点
var tabs = document.getElementById("tabdiv").getElementsByTagName("a");
//遍历td节点,将class属性恢复为person_menu1
for (var i = 0; i < tabs.length; i++) {
tabs[i].className = "person_menu1";
}
}
//用户个性设置个性签名更新操作
var gxqm_1="";
var grjj_1="";
var gxqm ="";
var grjj ="";
function init(){
gxqm_1 = document.getElementById("gxqm").innerHTML;
grjj_1 = document.getElementById("grjj").innerHTML;
}
function update_person(){
gxqm = document.getElementById("gxqm").innerHTML;
grjj = document.getElementById("grjj").innerHTML;
if(gxqm==gxqm_1 && grjj==grjj_1){
alert("未修改数据");
return ;
}else{
update();
}
}
function update(){
createXmlHttp(); //创建xmlHttp对象
if(xmlHttp){
xmlHttp.onreadystatechange = submitPostCallBack;
xmlHttp.open("POST","update",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("action=person"+"&usergxqq="+encodeURI(gxqm)+"&usergrjj="+encodeURI(grjj));
}
}
function submitPostCallBack(){
if(xmlHttp.readyState==4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
//更新用户头像
var imagePathLoad;
function imageLoading(){
imagePathLoad = document.getElementById("headImage").src;
}
function update_image(){
var imagePath = document.getElementById("headImage").src;
if(imagePath == imagePathLoad){
alert("未上传要更新的头像");
return false;
}
alert("imagePath===="+imagePath);
createXmlHttp();
if(xmlHttp){
xmlHttp.onreadystatechange = submitHead;
xmlHttp.open("POST","update",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("action=head"+"&imagePath="+encodeURI(imagePath));
}
}
function submitHead(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
//用户关于信息更新操作
function update_about(){
var address = document.getElementById("address").value;
var department = document.getElementById("department").value;
var selfweb = document.getElementById("selfweb").value;
var sex = document.getElementById("sex").value;
var agent = document.getElementById("agent").value;
var city = document.getElementById("city").value;
//个人网址格式验证正则表达式
var regex=/^(http:)?([/w-]+/.)+[/w-]+(//[/w- /.//?%&=]*)?$/i;
var result = regex.test(selfweb);
if(result==false){
alert("网址格式不正确!");
document.getElementById("selfweb").value="";
document.getElementById("selfweb").focus();
return false;
}
createXmlHttp();
if(xmlHttp){
xmlHttp.onreadystatechange = submitAbout;
xmlHttp.open("POST","update",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("action=about"+"&sex="+encodeURI(sex)+"&agent="+encodeURI(agent)+"&city="+encodeURI(city)+"&department="
+encodeURI(department)+"&address="+encodeURI(address)+"&selfweb="+encodeURI(selfweb));
}
}
function submitAbout(){
if(xmlHttp.readyState==4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
//用户联系方式信息更改操作
function update_cantact(){
var pbmail = document.getElementById("pbmail").value;
var msn = document.getElementById("msn").value;
var rcmailarray = document.cantactForm.rcmail;
var mailarray = document.cantactForm.mail ;
var rcmail = "";
var mail = "";
for(var i=0; i<rcmailarray.length;i++){
if(rcmailarray[i].checked == true){
rcmail = rcmailarray[i].value;
}
}
for(var i=0;i<mailarray.length;i++){
if(mailarray[i].checked == true){
mail = mailarray[i].value;
}
}
//Email格式判断正则表达式
var regex = /^([a-zA-Z0-9]+[_|/-|/.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|/-|/.]?)*[a-zA-Z0-9]+/.[a-zA-Z]{2,3}$/gi;
var result = regex.test(pbmail);
if(result == false){
alert("不合法的Email格式");
document.getElementById("pbmail").value = "";
document.getElementById("pbmail").focus();
return false;
}
var regexmsn = /^([a-zA-Z0-9]+[-|/-|/.]?)*[a-zA-Z0-9]+@hotmail+/.com$/gi;
var resultmsn = regexmsn.test(msn);
//alert("resultmsn"+resultmsn);
if(resultmsn == false){
alert("不合法的MSN格式");
document.getElementById("msn").value="";
document.getElementById("msn").focus();
return false;
}
createXmlHttp();
if(xmlHttp){
xmlHttp.onreadystatechange = submitCantact;
xmlHttp.open("POST","update",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("action=cantact"+"&rcmail="+encodeURI(rcmail)+"&mail="+encodeURI(mail)+"&pbmail="+pbmail+"&msn="+msn);
}
}
function submitCantact(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert(xmlHttp.responseText);
}
}
}
//用户密码更改
function update_pwd(){
var oldPassw = document.getElementById("oldPassw").value;
var passw = document.getElementById("passw").value;
if(oldPassw != passw){
alert("原始密码不正确!");
document.getElementById("oldPassw").value="";
document.getElementById("oldPassw").focus();
return false;
}
var newPassw = document.getElementById("newPassw").value;
if(newPassw == ""){
alert("新密码不能够为空!");
document.getElementById("newPassw").focus();
return false;
}
//密码格式验证正则表达式
var exp = /[^/w]/gi;
if(newPassw.search(exp)!=-1){
alert("新密码输入格式不正确!");
document.getElementById("newPassw").value ="";
document.getElementById("newPassw").focus();
return false;
}
var newRePassw = document.getElementById("newRePassw").value;
if(newPassw != newRePassw){
alert("两次输入的密码不一致");
document.getElementById("newRePassw").value="";
document.getElementById("newRePassw").focus();
return false;
}
createXmlHttp();
if(xmlHttp){
xmlHttp.onreadystatechange = submitModify;
xmlHttp.open("POST","update",true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("action=modify"+"&passw="+encodeURI(newPassw));
}
}
function submitModify(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert(xmlHttp.responseText);
}
}
}