function lTrim(str){
  if (str.charAt(0) == " "){
  str = str.slice(1);
  str = lTrim(str);
  }
  return str;
}

function rTrim(str){
  var iLength;
  iLength = str.length;
  if (str.charAt(iLength - 1) == " ") {
    str = str.slice(0, iLength - 1);
    str = rTrim(str);
  }
  return str;
}

function trim(str){
  return lTrim(rTrim(str));
}



function password_onkeydown(){
  if (event.keyCode==13){
    if (trim(document.form1.username.value)=="") {
      alert("用户名不能为空!");
      document.form1.username.focus() ;
    } else document.form1.rand.focus();
  }
}

function okBtn_onclick(){
  if (trim(document.form1.username.value)=="") {
    alert("用户名不能为空!");
    document.form1.username.focus();
  } else document.form1.submit();;
}

function window_onload(){
  document.form1.username.focus();
}


function username_onkeydown(){
  if (event.keyCode==13) {
    if (trim(document.form1.username.value)=="") {
      alert("用户名不能为空!");
      document.form1.username.focus();
    } else document.form1.password.focus();
  }
}
function rand_onkeydown(){
  if (event.keyCode==13) {
    if (trim(document.form1.rand.value)=="") {
      alert("验证码为空!");
      document.form1.rand.focus();
    } else 
	document.form1.submit();
  }
}
