﻿// JScript File

function SetBSp(Sel)
{
	BSpSel=Sel;
	return false;
}

function HdlKey(Evt)
{
  var Ret=true;
  var Cod=0;
  var Ctl=null;
  var Fnd=false;
  var Pre;
  var Nam;
  var CIx;
  var Idx;
  var Nxt;
  if (!Evt) Evt=window.event;
	if (Evt.keyCode) 
	{
		Cod=Evt.keyCode; 
	}
	else
	{
		if (Evt.which) 
		{
			Cod=Evt.which;
		}
	}
	if (Evt.target) 
	{
		Ctl=Evt.target;
	}
	else 
	{
		if (Evt.srcElement) Ctl=Evt.srcElement;
		if (Ctl.nodeType==3) // defeat Safari bug
		{
			Ctl=Ctl.parentNode;
		}
	}
	if (Ctl!=null)
	{
	  for (CIx=0; CIx<4; CIx++)
	  {
	    if (CIx==0) Pre="txtCerNm";
	    if (CIx==1) Pre="txtCCrNm";
	    if (CIx==2) Pre="txtRCrNm";
	    if (CIx==3) Pre="txtROrCr";
			for (Idx=0; Idx<9; Idx++)
			{
				Nam=Pre + (Idx+1);
				if (Ctl.id==Nam) 
				{
					Fnd=true; 
					switch (Cod)
					{
					case 8:  // Backspace
		    		if (document.getElementById(Nam).value=="")
						{
							if (Idx>0)
							{
								Nxt=Pre + Idx;
								document.getElementById(Nxt).value="";
								document.getElementById(Nxt).focus();
							}
						}
						else document.getElementById(Nam).value="";
						break;
					case 13:
					  if (!document.getElementById("cmdCerNum").disabled) OpnCer();
					  break;
					case 46: // Delete
						document.getElementById(Nam).value="";				
						break;
					case 37: // Left Arrow
						if (Idx>0)
						{
							Nxt=Pre + Idx;
							document.getElementById(Nxt).focus();
						}
						break;
					case 39: // Right Arrow
						if (Idx<8)
						{
							Nxt=Pre + (Idx+2);
							document.getElementById(Nxt).focus();
						}
						break;
					default:
						if ((Cod>=48 && Cod<=59) || (Cod>=96 && Cod<=105))
						{
							if (Cod>59) Cod-=48;
							document.getElementById(Nam).value=String.fromCharCode(Cod);
							if (Idx<8) 
							{
								Nxt=Pre + (Idx+2);
								document.getElementById(Nxt).focus();
							}
							ChkCer(CIx);
						}
					}
					Ret=false;
				}
			}
		}
		if (!Fnd)
		{
		  if (Cod==8)
		  {
				Ret=false;
		    if (BSpSel==1)					 Ret=true;
				if (Ctl.id=="txtTxtLn1") Ret=true;
				if (Ctl.id=="txtTxtLn2") Ret=true;
				if (Ctl.id=="txtBrdLns") Ret=true;
				if (Ctl.id=="txtGftCrd") Ret=true;
				if (Ctl.id=="txtThwQty") Ret=true;
				if (Ctl.id=="txtTBgQty") Ret=true;
				if (Ctl.id=="txtPurQty") Ret=true;
				if (Ctl.id=="txtSPlQty") Ret=true;
				if (Ctl.id=="txtLPlQty") Ret=true;
				if (Ctl.id=="txtSWHQty") Ret=true;
				if (Ctl.id=="txtLWHQty") Ret=true;
				if (Ctl.id=="txtGWHQty") Ret=true;
				if (Ctl.id=="txtUsrNam") Ret=true;
				if (Ctl.id=="txtUsrPwd") Ret=true;
				if (Ctl.id=="txtBrdMgm") Ret=true;
				if (Ctl.id=="txtBbyNam") Ret=true;
				if (Ctl.id=="txtBbyLbs") Ret=true;
				if (Ctl.id=="txtBbyOzs") Ret=true;
				if (Ctl.id=="txtBbyBDt") Ret=true;
				if (Ctl.id=="txtBbyBTm") Ret=true;
				if (Ctl.id=="txtConFst") Ret=true;
				if (Ctl.id=="txtConLst") Ret=true;
				if (Ctl.id=="txtConPho") Ret=true;
				if (Ctl.id=="txtConEMl") Ret=true;
				if (Ctl.id=="txtConCEm") Ret=true;
				if (Ctl.id=="txtReqDte") Ret=true;
				if (Ctl.id=="txtROrCNm") Ret=true;
				if (Ctl.id=="txtROrCer") Ret=true;
				if (Ctl.id=="txtDisCod") Ret=true;
				if (Ctl.id=="txtOrdIDN") Ret=true;
				if (Ctl.id=="txtOrdQty") Ret=true;
				if (Ctl.id=="txtConUsr") Ret=true;
				if (Ctl.id=="txtEntQty") Ret=true;
		  }
		  if (Cod==13)
		  {
				if (Ctl.id=="txtUsrNam") { Ret=false; }
				if (Ctl.id=="txtUsrPwd") { PrcSgn();			Ret=false; }
				if (Ctl.id=="txtFmtNam") { SelFNm();			Ret=false; }
				if (Ctl.id=="txtDupNam") { SelDNm();			Ret=false; }
				if (Ctl.id=="txtItmTxt") { SelTxt();			Ret=false; }
				if (Ctl.id=="txtOrdQty") { CalTot();      Ret=false; }
				if (Ctl.id=="txtAdjQty") { UpdQty();			Ret=false; }
				if (Ctl.id=="txtReqDte") { SelRDt(true);  Ret=false; }
				if (Ctl.id=="txtDisCod") { EvlDis();			Ret=false; }
				if (Ctl.id=="txtEntQty") { UpdQty();			Ret=false; }
				if (Ret) 
				{	
					if (Ctl.id.substring(0,9)=="adrConAdr") Ret=false;
					if (Ctl.id.substring(0,9)=="adrShpAdr") Ret=false;
					if (Ctl.id.substring(0,9)=="adrCstAdr") Ret=false;
				}
			}
		}
	}
	else
  {
		if (Cod==8 || Cod==13) Ret=false;
	}
	return Ret;
}





