function InicializarIndices()
{if(document.CargaInicial==null)
{document.CargaInicial=false;var ctrlAnterior=null;var IndAnt=0;for(var i=0;i<formcadastro.elements.length;i++)
{var e=formcadastro.elements[i];if(e.type!="hidden"&&e.type!="image")
{if(ctrlAnterior!=null)
ctrlAnterior.IndicePosterior=i;ctrlAnterior=e;e.Indice=i;e.IndiceAnterior=IndAnt;}}}}
function SetarFoco(ind){InicializarIndices();if(isNaN(ind)&&formcadastro.elements[ind].type!="hidden")
formcadastro.elements[ind].focus();else
for(;ind<formcadastro.elements.length;ind++)
if(formcadastro.elements[ind].type!="hidden")
break;if(ind<=formcadastro.elements.length)
formcadastro.elements[ind].focus();}
function LimparCampo(ind)
{if(isNaN(ind))
formcadastro.elements[ind].value="";else if(ind!=-1)
for(var i=ind;i<formcadastro.elements.length;i++)
if(formcadastro.elements[i].type=="text"||formcadastro.elements[i].type=="password")
{formcadastro.elements[i].value="";break;}
else
for(var i=0;i<formcadastro.elements.length;i++)
if(formcadastro.elements[i].type=="text"||formcadastro.elements[i].type=="password")
formcadastro.elements[i].value="";}
function QualNavegador()
{var s=navigator.appName;if(s=="Microsoft Internet Explorer")
return"IE";else if(s=="Netscape")
return"NE";else
return"";}
function QualVersao()
{var s=navigator.appVersion;if(QualNavegador()=="IE")
{var i=s.search("MSIE");s=s.substring(i+5);i=s.search(".");return parseInt(s.substring(0,i+1));}
else if(QualNavegador()=="NE")
return parseInt(s.substring(0,1));else
return 0;}
function SetarEvento(ctrl,Tam,Tipo,AutoSkip)
{var s=QualNavegador();if(s.length==0)
return;if(s=="IE"&&QualVersao()>6)
return;if(s=="NE"&&QualVersao()>4)
return;if(ctrl.onkeypress==null)
{if(AutoSkip==null)
AutoSkip=true;if(Tipo!=null)
Tipo.toUpperCase();ctrl.Tam=Tam;ctrl.Tipo=Tipo;ctrl.AutoSkip=true;ctrl.Saltar=false;InicializarIndices();ctrl.onkeypress=ValidarTecla;if(QualNavegador()=="IE"&&QualVersao()>=5)
ctrl.onkeyup=SaltarCampo;}}
function SaltarCampo(ctrl)
{if(ctrl==null)
ctrl=this;if(ctrl.AutoSkip&&ctrl.Saltar)
if(ctrl.Saltar)
{ctrl.Saltar=false;if(ctrl.IndicePosterior!=null)
SetarFoco(ctrl.IndicePosterior);}}
function ValidarTecla(evnt)
{var tk;var c;var tkce;var ce;tk=((QualNavegador()=="IE")?event.keyCode:evnt.which);c=String.fromCharCode(tk);c=c.toUpperCase();tkce=((QualNavegador()=="IE")?event.keyCode:evnt.which);ce=String.fromCharCode(tkce);ce=ce.toUpperCase();if(tk<32)
return true;if(tk>127)
return false;switch(this.Tipo)
{case"D":if(c<"0"||c>"9")
return false;break;case"N":if((c<"0"||c>"9")&&(c!="."&&c!=","))
return false;if((c==",")&&((this.value.search(",")>-1)||(this.value.length==0)))
return false;if((c==".")&&(this.value.length==0))
return false;break;case"C":if(c<"A"||c>"Z")
return false;break;case"CE":if(tkce<33)
return true;if(tkce>127)
return false;if(ce<"A"||ce>"Z")
return false;break;default:break;}
this.Saltar=(this.value.length==this.Tam-1);if(((QualNavegador()=="IE")&&QualVersao()<5)||(QualNavegador()!="IE"))
SaltarCampo(this);return true;}
function formcadastroataData(ctrl,formcadastron,campo,teclapres){var tecla=teclapres.keyCode;vr=document.formcadastro[formcadastron][campo].value;vr=vr.replace(/\./gi,"");vr=vr.replace(/\//gi,"");vr=vr.replace(/\-/gi,"");tam=vr.length;if(tecla!=9&&tecla!=8){if(tam<=1){if(tecla==109||tecla==111||tecla==189||tecla==191){document.formcadastro[formcadastron][campo].value=vr;}}
else if(tam>=2&&tam<=3)
document.formcadastro[formcadastron][campo].value=vr.substr(0,2)+'/'+vr.substr(2,tam);else if(tam==4)
document.formcadastro[formcadastron][campo].value=vr.substr(0,2)+'/'+vr.substr(2,2)+'/';else if(tam>4)
document.formcadastro[formcadastron][campo].value=vr.substr(0,2)+'/'+vr.substr(2,2)+'/'+vr.substr(4,tam);}
if(tam==8){ctrl.Saltar=false;if(ctrl.IndicePosterior!=null)
SetarFoco(ctrl.IndicePosterior);}}
