var ch,len,time_id;
function checkEvent() //设置键盘运行操作对象函数
{
  if(window.event.keyCode==13) document.middle.sch_code.focus();
  else{
   ch=String.fromCharCode(window.event.keyCode)
   if((ch<='9')&&(ch>='0')){
	   len=document.middle.sch_code.value.length;
	   if(len==3) CodeToName(ch,'1');//需要增加最后输入的CH值
	}//if((ch<='9')&&(ch>='0'))
	else{
	  alert('对不起,学校代码中不能包含字母');
	  ch=document.middle.sch_code.value;
	  setTimeout("resetValue('"+ch+"')",0);
	}
 }//else if(window.event.keyCode!=13) 
}

function resetValue(val)
{
   if(val.length==0) document.middle.sch_code.value='';
   else  document.middle.sch_code.value=val;
}

function check()
{       

  if(document.middle.school.selectedIndex!=0&&document.middle.sch_code.value.length<4)
	 document.middle.school.selectedIndex=0;
}

function main(val)
{
  if(val=='0'){ //文本框失去焦点
 	  len=document.middle.sch_code.value.length;
      if(time_id!=null) clearInterval(time_id);
	  if(len!=4&&len!=0){ 
		alert('学校代码必须为4位!');

		document.middle.sch_code.focus();
	  }  
	}//
  if(val=='1') time_id=setInterval("check()",100);//文本框得到焦点
}

function CodeToName(ch,mark)
{
  var temp,j;

  j=document.middle.school.options.length;
  temp=document.middle.sch_code.value;
  if(mark=='1'){ 
	  temp=temp+ch;
	  document.middle.sch_code.value=temp;
  }//if(mark=='1')
  
  for(var i=1;i<j;i++){
    if(document.middle.school.options[i].value==temp) document.middle.school.selectedIndex=i;
  }//for
		 
}

function NameToCode()
{     
  if(document.middle.school.options[document.middle.school.selectedIndex].value==0)
	 document.middle.sch_code.value="";
  else
	 document.middle.sch_code.value=document.middle.school.options[document.middle.school.selectedIndex].value; 
 
}//end function NameToCode()

function subForm()
{
  //document.middle.sch_name.value=document.middle.school.options[document.middle.school.selectedIndex].text;
  //document.middle.submit();

}
