// JavaScript Document
function checkMessage(emptyUserName, emptyTel, correctEmailFormat, emptyContent, operateFail, tryOperate)
{
  var message = '';
  if('' == document.myform.username.value)
  {
    message += emptyUserName;
  }
  if('' == document.myform.telephone.value)
  {
    message += emptyTel;
  }
  /*多邮箱验证*/
  var patternEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
   var email =  document.myform.email.value;
  if('' == email || !patternEmail.test(email))
  {
    message += correctEmailFormat;
  }
  if('' == document.myform.messagecontent.value)
  {
    message += emptyContent;
  }
  if('' != message)
  {
    alert(operateFail+message+tryOperate);
    return false
  }
  return true;
}

function checkSearch()
{
  if('' == document.searchForm.searchkeyword.value)
  {
    return false;
  }
  return true;
}


function checkResume(emptyUserName, emptyTel, correctEmailFormat, operateFail, tryOperate)
{
  var message = '';
  if('' == document.myform.resumename.value)
  {
    message += emptyUserName;
  }
  if('' == document.myform.resumetel.value)
  {
    message += emptyTel;
  }
  var patternEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
   var email =  document.myform.resumeemail.value;
  if('' == email || !patternEmail.test(email))
  {
    message += correctEmailFormat;
  }
  if('' != message)
  {
    alert(operateFail+message+tryOperate);
    return false
  }
  return true;
}

function checkRegister(emptyUserName, emptyPassword, isPasswordNotSame, emptySex, emptyTel, correctEmailFormat, operateFail, tryOperate)
{
  
  var message = '';
  if('' == document.myform.username.value || 5 > document.myform.username.value.length || 15 < document.myform.username.value.length)
  {
    message += emptyUserName;
  }
  if('' == document.myform.userpassword.value || 5 > document.myform.userpassword.value.length ||  15 < document.myform.userpassword.value.length)
  {
    message += emptyPassword;
  }
  if('' == document.myform.checkuserpassword.value || document.myform.userpassword.value != document.myform.checkuserpassword.value)
  {
    message += isPasswordNotSame;
  }
  if('' == document.myform.usersex.value)
  {
    message += emptySex;
  }
  if('' == document.myform.usertel.value)
  {
    message += emptyTel;
  }
  var patternEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
   var email =  document.myform.useremail.value;
  if('' == email || !patternEmail.test(email))
  {
    message += correctEmailFormat;
  }
  if('' != message)
  {
    alert(operateFail+message+tryOperate);
    return false
  }
  return true;
}

function checkLogin(emptyUserName, emptyPassword, emptyCheckCode, operateFail, tryOperate)
{
  var message = '';
  if('' == document.myform.username.value)
  {
    message += emptyUserName;
  }
  if('' == document.myform.userpassword.value)
  {
    message += emptyPassword;
  }
  if('' == document.myform.checkcode.value)
  {
    message += emptyCheckCode;
  }
  if('' != message)
  {
    alert(operateFail+message+tryOperate);
    return false
  }
  return true;
}

function checkUserInfoModify(emptyTel, correctEmailFormat, operateFail, tryOperate)
{
  var message = '';
  if('' == document.myform.usertel.value)
  {
    message += emptyTel;
  }
  var patternEmail = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
   var email =  document.myform.useremail.value;
  if('' == email || !patternEmail.test(email))
  {
    message += correctEmailFormat;
  }
  if('' != message)
  {
    alert(operateFail+message+tryOperate);
    return false
  }
  return true;
}




/******************************************************************************************/
function createXHR() 
{
  var request;
  var browser = navigator.appName;
  //使用IE，则使用XMLHttp对象
  if(browser == "Microsoft Internet Explorer") 
  {
    var arrVersions = ["Microsoft.XMLHttp", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","MSXML2.XMLHttp.5.0"];
    for (var i=0; i < arrVersions.length; i++) 
    {
      try 
      {
        //从中找到一个支持的版本并建立XMLHttp对象
        request = new ActiveXObject(arrVersions[i]); 
        return request;
      } 
      catch(exception)
      {
         //忽略，继续
      }
    }
  }
  else
  {
    //否则返回一个XMLHttpRequest对象
    request = new XMLHttpRequest(); 
    if(request.overrideMimeType)
    {
  　　  request.overrideMimeType('text/xml;charset=utf-8');
  　}
    return request;
  }   
}

var Request = createXHR();//实例化

function checkLogin(flag, username, userpassword, kuHttpPath, action, lang, loginEmptyFail)
{
  //alert('登录处理');
  if('flag1' == flag)
  {
    var username = document.getElementById('userNameId').value;
    var userpassword = document.getElementById('userPasswordId').value;
  }
  else if('flag2' == flag)
  {
    document.getElementById('loginTable').style.display = 'none';
    var username = username;
    var userpassword = userpassword;
  }
  if('' == username || '' == userpassword)
  {
    alert(loginEmptyFail);
    exit;
  }
  var url = kuHttpPath+"login_ajax.php?username="+username+"&userpassword="+userpassword+"&kuhttppath="+kuHttpPath+"&action="+action+"&lang="+lang;     
  //alert(url);
  Request.open("get", url, true);
  Request.onreadystatechange = loginDealWith;
  Request.send(null);
}

function loginDealWith()
{
   if(Request.readyState == 4 && Request.status == 200) 
   {  
       if('对不起，登录失败，请重新登录' == Request.responseText || 'Sorry, login fail, please login again.' == Request.responseText)
      {
        alert(Request.responseText);
        document.getElementById("loginTable").style.display = 'block';
      }
      else
      {
        document.getElementById("loginTable").style.display = 'none';
        document.getElementById('loginDiv').innerHTML = Request.responseText;
      }
   }
}
