<!-- Begin
//
var khIE,khNS;
var khHotKey,khPopupMenu,khUrlDisplay=true;
var khCurObj,khCurKeyChar,khCurObjVal="",khCurEvent;
var khWhenKeyIn,khFinishKeyIn,khCurChkObjIdx=0,khCurChkFunLst,khObjAtt;
var khIsComm,khIsDebugComm,khCommDefTimerOut=50000,khCommCallBack,khCommCurObj,khCommTimerOut,khCommStatus,khCommTimerID,khCommWin;
var khIsDebug,khDebugMsg="";
var khAppStat="khCurObj=this;\nkhCurEvent=(e)?e:window.event;\n";
var khImgArray,khImgSrc;
var khSTxt,khToolTips,khFloating;
//
function khShowWarning(message,isUseWindow){
 window.alert("message:"+message);
}
//
function khIsIE(){
 if(!khIE){
  if(document.all) khIE=true;
  else khIE=false;
 }
 if (khIE==true) return(khIE);
 else return (null);
}
function khIsNS(){
 if(!khNS){
   if(document.all) khNS=false;
   else khNS=true;
 }
 if (khNS==true) return(khNS);
 else return (null);
}
function khToLowerCase(kc){
 return (kc.khToLowerCase());
}
function kcToUpperCase(kc){
  return (kc.kcToUpperCase());
}
function khGetKeyCode(e){
 var kc;
 if(khIsIE()==true) kc=event.keyCode;
 else kc=(e)?e.which:null;
 return (kc);
}
function khKeyToChar(kc){
 return (String.fromCharCode(kc));
}
function khGetKeyChar(e){
 return (khKeyToChar(khGetKeyCode(e)));
}
function khIsVisualChar(kc){
 if(31<kc && kc<127) return (true);
 else return (false);
}
function khGetValidChar(e){
 var kc=khGetKeyCode(e);
 if(khIsVisualChar(kc)==true) return (khKeyToChar(kc));
 else return (null);
}
function khGetIfInputObj(obj){
 var rs=null;
 if(obj){
  var tn=obj.tagName;
  if((tn=='INPUT')||(tn=='TEXTAREA')||(tn=='BUTTON')||(tn=='SELECT'))
   rs=obj;
 }
 return (rs);
}
function khSetHandler(nm,en,hl){
 if(nm&&nm!=""){
  var o=khGetElementsByName(nm,'all');
  if(!o) return;
  var oL=o.length;
  for (var i=0;i<oL;i++)
   if(o[i]){
    if(khIsDebug==true) khDebugMsg+="event "+en+" is set to "+nm+"\n";
    if(en=="onkeypress") o[i].onkeypress=hl;
    else if(en=="onblur") o[i].onblur=hl;
    else if(en=="onchange") o[i].onchange=hl;
    else if(en=="onclick") o[i].onclick=hl;
    else if(en=="onfocus") o[i].onfocus=hl;
    else if(en=="onmouseover") o[i].onmouseover=hl;
    else if(en=="onmouseout") o[i].onmouseout=hl;
    else if(en=="onmousedown") o[i].onmousedown=hl;
    else if(en=="onmouseup") o[i].onmouseup=hl;
    else if(en=="onsubmit") o[i].onsubmit=hl;
  }
 }
}
function khGetCurObj(){
 return(khCurObj);
}
function khGetCurEvent(){
 return(khCurEvent);
}
function khGetCurKey(){
 return(khGetValidChar(khGetCurEvent()));
}
function khGetEventTargetForInput(e){
 var obj=(khIsIE()==true)?event.srcElement:e.target;
 return(khGetIfInputObj(obj));
}
function khGetElementsByName(nm,idx){
 var objs=document.getElementsByName(nm);
 if(idx!='all'&&objs){
  var oLen=(objs)?objs.length:0;
  if (!idx) idx=0;
  if(oLen>0&&idx<=oLen){
   if (idx>0) objs=objs[idx-1];
   else if (objs[0].type=='radio'){
    var i;
    for (i=0;i<oLen;i++)
     if (objs[i].checked){
      objs=objs[i];
      break;
     }
     if (i>=oLen) objs=null;
    }
  }
  else objs=null;
 }
 return (objs);
}
function khGetSelectValue(obj,idx){
 return (obj.options[idx].value);
}
function khGetObjValBasedType(obj,flag){
 if(!obj) return(null);
 var oT=obj.type;
 if(oT=='select' || oT=='select-one'){
  var value=obj.selectedIndex;
  if(flag!='index') value=obj.options[value].value;
  return (value);
 }
 else if((oT=='checkbox' || oT=='radio') && flag == 'check') return (obj.checked);
 else return (obj.value);
}
function khGetElementsValueByName(nm,idx, flag){
 var objs=khGetElementsByName(nm,idx),rs=null;
 if(objs){
  if(idx!='all') rs=khGetObjValBasedType(objs, flag);
  else {
   var oL=objs.length;
   rs=new Array(oL);
   for (var i=0;i<oL;i++)
    rs[i]=khGetObjValBasedType(objs[i], flag);
  }
 }
 return (rs);
}
function khGetIndexInGroup(obj){
 var idx=0;
 if(obj){
  var objs=khGetElementsByName(obj.name,'all');
  if(objs){
   var oL=objs.length;
   for (var i=0;i<oL;i++)
   if(objs[i]==obj){
    idx=i+1;
    break;
   }
  }
 }
 return (idx);
}
function khSetObjVal(o,v,flag){
 if(!o) return;
 if(o.type=='checkbox' && flag== 'check') o.checked=v;
 else if((o.type=='select' || o.type=='select-one')) {
  if (flag=='index'){
   o.selectedIndex=(v<0)?0:((v>=o.length)?o.length-1:v);
   o.options[o.selectedIndex].selected=true;
  }
  else
   o.options[o.selectedIndex].value=v;
 }
 else o.value=v;
}
function khSetObjValsByName(nm,idx,vs,flag){
 var objs=khGetElementsByName(nm,idx);
 if(objs){
  if(idx!='all') khSetObjVal(objs,vs,flag);
  else {
   var oL=objs.length;
   for (var i=0;i<oL;i++)
   khSetObjVal(objs[i],vs[i],flag);
  }
 }
}
function khSetOpt(obj, disp, vs, idx) {
 if (obj) {
  if (!vs) vs=disp;
  var optLen=obj.length,rsLen=disp.length,i;
  for (var i = 0; i < rsLen; i++) obj.options[i] = new Option(disp[i], vs[i]);
  for (var i = optLen-1; i >= rsLen; i--) obj.options[i] = null;
  if (!idx) idx=0;
   obj.selectedIndex = idx;
 }
}
function khGetElementsCountByName(nm){
 var objs=khGetElementsByName(nm,'all'),oL=(objs)?objs.length:0;
 return (oL);
}
//
function khGetArrayIdx(nm,ia){
 var idx=0;
 if(ia){
  var i,aL=ia.length;
  for (i=0;i<aL;i++)
   if(ia[i][0]==nm) break;
  if(i<aL)
   idx=i+1;
 }
 return (idx);
}
function khGetKeyArrayIdx(nm,ia){
 var idx=khGetArrayIdx(nm,ia), lst;
 if (idx>0)
  lst=ia[idx-1][1];
 else
  lst=null;
 khCurChkObjIdx=idx;
 khCurChkFunLst=lst;
 return (idx);
}
function khCheckWhenKeyIn(e){
 obj=khGetIfInputObj(this);
 if(!obj) return(true);

 var key=khGetValidChar(e);
 if(!key) return(true);
 khCurKeyChar=key;

 var pObj=khCurObj;
 khCurObj=obj;
 khCurEvent=(e)? e: window.event;
 var idx=khCurChkObjIdx;
 if(idx==0 || pObj!=obj) // use blur to clear will be better
  idx=khGetKeyArrayIdx(obj.name,khWhenKeyIn);
 if(idx!=0){
  var i,fun=khWhenKeyIn[idx-1][1],fLen=fun.length;
  for (i=0;i<fLen;i++){
   if(khIsDebug==true) alert("call controller :\n  "+khWhenKeyIn[idx-1][0]+"\nuser function :\n  "+fun[i][0]+"\non event :\n  onkeypress");
   if(eval(fun[i][0])<0){
    if(khIsNS()==true) khSetObjVal(khCurObj,khCurObjVal); //bug, should reload it when focus
    khShowWarning(fun[i][1],fun[i][2]);
    obj.focus();
    return (false);
   }
  }
 }
 khCurObjVal=khGetObjValBasedType(obj);
 return(true);
}
function khCheckFinishKeyIn(e){
 obj=khGetIfInputObj(this);
 if(!obj) return(true);
 khCurObj=obj;
 khCurEvent=(e)? e: window.event;
 khCurObjVal=khGetObjValBasedType(obj);

 var idx=khGetKeyArrayIdx(obj.name,khFinishKeyIn);
 if(idx!=0){
  var i,fun=khFinishKeyIn[idx-1][1],fLen=fun.length;
  for (i=0;i<fLen;i++){
   if(khIsDebug==true) alert("call controller :\n  "+khFinishKeyIn[idx-1][0]+"\nuser function : \n  "+fun[i][0]+"\non event :\n  onchange");
   if(eval(fun[i][0])<0){
    khShowWarning(fun[i][1],fun[i][2]);
    obj.focus();
    obj.select();
    return (false);
    }
  }
 }
// clean when move to next target
 khCurObj=null;
 khCurObjVal="";
 khCurEvent=null;
 khCurChkObjIdx=0;
 khCurChkFunLst=null;
 return(true);
}
function khSubmit(obj) {
  var fm = (obj) ? obj.form: null;
  if (fm)
    fm.submit();
}
function khReloadToIframe(where,url){
 var mid=document.getElementById(where);
 if (mid) mid.src=url;
}
function khCallServer(obj,url,cb,tout){
 if(khIsDebug==true)
  khDebugMsg="khCallServer(this,"+url+",'"+cb+"',"+tout+") is called\n";
 if(url&&url!=""){
  if(!tout) tout=khCommDefTimerOut;
  khCommCallBack=cb;
  khCommCurObj=obj;
  khCommTimerOut=tout;
  khCommStatus=1;
  khReloadToIframe('khCommIfr',url);
  if(tout > 0&&cb&&cb!=""){
   khCommTimerID=window.setTimeout(khCommTimerOutFun,tout);
   if(khIsDebug==true) khDebugMsg+="timer is set,timerout ="+tout+"\n";
   }
 }
 if(khIsDebug==true&&khDebugMsg!=""){
  alert(khDebugMsg);
  khDebugMsg="";
 }
}
function khCommReceived(status,result){
 if(khCommStatus > 0){
// clean timer ,status and notify the user function.
  if(khCommTimerID){
  window.clearTimeout(khCommTimerID);
  khCommTimerID=null;
  }
  if(khIsDebugComm==true){
   var rsLen=(result)?result.length:0,msg="";
   for (var i=0;i<rsLen;i++) msg+=(i+1)+":"+result[i]+"\n";
   alert(msg);
  }  
  khCommWin=khCommCurObj;
  khCommStatus=0;
  if(khIsDebug==true) alert("received comm and call user callback : \n  "+khCommCallBack);
  eval(khCommCallBack);
 }
}
function khCommTimerOutFun(){
 if(khCommTimerID){
  khCommTimerID=null;
  if(khCommStatus > 0){
   var status=-1,result=null;
   khCommStatus=-1;
   khCommWin=null;
  if(khIsDebug==true) alert("timer out of comm and call user callback : \n  "+khCommCallBack);
   eval(khCommCallBack);
  }
 }
}
function khCommInit(){
 if(khIsComm==true){
  document.write("<div id='commDiv'><iframe id='khCommIfr'></iframe></div>");
 if(khIsDebug==true) khDebugMsg+="khIsComm is defined\n";
 }
}
function khCheckInit(){
 if(khWhenKeyIn){
  if(khIsDebug==true) khDebugMsg+="khWhenKeyIn is defined\n";
  var i,aLen=khWhenKeyIn.length;
  for (i=0;i<aLen;i++) khSetHandler(khWhenKeyIn[i][0],"onkeypress",khCheckWhenKeyIn);
 }
 if(khFinishKeyIn){
  if(khIsDebug==true) khDebugMsg+="khFinishKeyIn is defined\n";
  aLen=khFinishKeyIn.length;
  for (i=0;i<aLen;i++) khSetHandler(khFinishKeyIn[i][0],"onchange",khCheckFinishKeyIn);
 }
 if(khObjAtt){
  if(khIsDebug==true) khDebugMsg+="khObjAtt is defined\n";
  aLen=khObjAtt.length;
  for (i=0;i<aLen;i++){
   var eLen=khObjAtt[i][1].length;
   for (var j=0;j<eLen;j++) {
    var debugSt="";
    if(khIsDebug==true)
     debugSt="alert(\"call user function :\\n  "+khObjAtt[i][1][j][1]+"\\nof controller :\\n  "+khObjAtt[i][0]+"\\non event :\\n  "+khObjAtt[i][1][j][0]+"\");";
    var fun=new Function("e",khAppStat+debugSt+khObjAtt[i][1][j][1]);
    khSetHandler(khObjAtt[i][0],khObjAtt[i][1][j][0],fun);
   }
  }
 }

 

}
//
function khStringToNumber(num){
 num=''+num;
 var nL=num.length,out='';
 for (var i=0;i<nL;i++){
  var c=num.charAt(i);
  if('0'<=c&&c<='9' || c=='.') out+=c;
 }
 var rs=parseFloat(out);
 if(isNaN(rs)) rs=0;
 return (rs);
}
function khRepeatChar(c,t){
 var out='';
 for (var i=0;i<t;i++) out+=c;
 return (out);
}
function khProcSuffix(num,mt,suf){
 num=parseFloat(''+num);
 var out=num;
 if(mt > 0){
  var dm=parseInt('1'+khRepeatChar('0',mt));
  out=''+Math.round(num*dm) / dm;
  var pt=out.indexOf('.');
  if(pt<0){
   out=out+'.';
   pt=out.length-1;
  }
  if(suf&&suf!=''){
   var rm=mt-(out.length-pt -1);
   if(rm > 0) out=out+ khRepeatChar(suf,rm);
  }
 }
 return (out);
}
function khProcPrefix(num,mDigs,pref,sep){
 num=''+num;
 var nL,dPt=num.indexOf('.');
 if(dPt >= 0) nL=dPt;
 else nL=num.length;
 var out=num;
 if(sep&&sep!=''){
  if(nL > 3){
   var mod=nL % 3;
   out=(mod > 0?(num.substring(0,mod)):'');
   for (var i=0 ;i<Math.floor(nL / 3);i++){
    if((mod==0)&&(i==0)) out+=num.substring(mod+ 3 * i,mod+3 * i+3);
    else out+= ','+num.substring(mod+3 * i,mod+3 * i+3);
   }
  }
 }
 if(mDigs > 0&&pref&&pref!=''){
  var ndp=out.indexOf('.'),iDif;
  if(ndp<0) iDif=mDigs-out.length;
  else iDif=mDigs-ndp;
  if(iDif > 0) out=khRepeatChar(pref,iDif)+out;
 }
 if(dPt >= 0&&sep&&sep!=''&&nL > 3) out=out+num.substring(dPt);
 return (out);
}
function khStringToDecimal(num,mids,mfds,sym,sep,pref,suf){
 if(num){
  num=khProcSuffix(num,mfds,suf);
  num=khProcPrefix(num,mids,pref,sep);
  if(sym) num=sym+num;
 }
 return (num);
}
//
function khChgImg(obj, iam) {
 var idx=khGetArrayIdx(iam,khImgArray);
 if (idx>0){
  var iI=khImgSrc[idx-1];
  var iL=iI.length;
  var i=0;
  for ( i=0;i<iL;i++)
   if (obj.src.lastIndexOf(iI[i].src)>=0)
    break;
  i++;
  if (i>=iL)
   i=0;
  obj.src = iI[i].src;
 }
}
function khImgInit() {
 if (khImgArray) {
  var iL=khImgArray.length;
  khImgSrc=new Array(iL);
  for (var i=0;i<iL;i++) {
   var fL=khImgArray[i][1].length;
   khImgSrc[i]=new Array(fL);
   for (var j=0;j<fL;j++) {
     khImgSrc[i][j]=new Image();
     khImgSrc[i][j].src=khImgArray[i][1][j];
   }
  }
 }
}
//
function khGenericInit(){
 khCheckInit();
 if(khSTxt)khSTxtInit();
 if(khToolTips)khToolTipsInit();
 if(khFloating)khFloatingInit();

 if(khIsDebug==true&&khDebugMsg!=""){
  alert(khDebugMsg);
  khDebugMsg="";
 }
}
function khInitAtTop(){
 khCommInit();
 khImgInit();
 if(khSTxt)khSTxtInit(1);
 if(khToolTips)khToolTipsInit(1);
}
khInitAtTop();
window.onload=khGenericInit;
//  End -->
