// JavaScript Document


function CarregaCombo(Combo,Str)
{
//alert(Combo)
//return
    var comb=""
    eval("comb="+Combo+";")
	comb.selectedIndex = 0;
    do
    {
      comb.options[comb.selectedIndex]=null;
    }
    while (comb.selectedIndex >= 0)
    eval(Str);
}

function CarregaListBox(Combo,Str)
{

    var comb="";
    eval("comb="+Combo+";")
	comb.selectedIndex = 0;
	

  while (comb.options.length > 0)
    {
     comb.options[0]=null;	
    }   

    eval(Str);
}




function SelecionaComboDefault(Combo,strValor)
{
  //alert(strValor)
        var comb=""
        eval("comb="+Combo+";")  	
		//comb.selectedIndex = 0;	  
        for (var i=0;i<comb.options.length;i++)
        {
		
          if (comb.options[i].value==strValor)
          {
            comb.options[i].selected=true;
          }  
        }  
}	

function ApagarItemListBox(fbox) {  
     var arrFbox = new Array();
     var arrLookup = new Array();
     var i;

     
	 var fLength = 0;

     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {

          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();

     fbox.length = 0;

     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }

}



function ApagarListBox(fbox, tbox) {  
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
	 
	 if (tbox.options[i].value==fbox.options.value){

		//alert('texto');
		ApagarItemListBox(fbox);
		return
	 }
      
	      arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     
	 var fLength = 0;

     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}

function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     box[i].selected = true;
     }
}


function MoverListBox(fbox, tbox) {  
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
	 
	 if (tbox.options[i].value==fbox.options.value){

		alert(' Item já Inserido !! ');
		return
	 }
      
	      arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     
	 var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {

               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}

function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     box[i].selected = true;
     }
}



function ValidaFullData (DataField,strFriendlyName,fNull,isBirthDay)
{
	var DtDia;
	var DtMes;
	var DtAno;

	var DtDia = DataField.value.substr(0,2);
	var DtMes = DataField.value.substr(3,2);
	var DtAno = DataField.value.substr(6,4);	
	
	var DiaMes = new Array (31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var DtAnoAux;
	var DtDiaMax;
	
	// Valida a data completa considerando os dias pelo mês

	



//	 Se os campos preenchidos estão ok
	if (ValidaData (DtDia,"dia",false,strFriendlyName) &&
		ValidaData (DtMes,"mes", false,strFriendlyName) &&
		ValidaData (DtAno,"ano", false,strFriendlyName))
	{			
		if (isBirthDay)
		{
		 hoje = new Date()
         var ano = hoje.getYear()
         if ((DtAno>ano) )
           {
             alert ("Preecha o campo " + strFriendlyName + " corretamente\n A Data deve ser menor que o dia de hoje");
             DataField.value='';
			 DataField.focus();
             DataField.select();
             return false
           }
		}
		
		// Checa se eh uma data valida
		if ((isNaN(parseInt(DtDia)) || isNaN(parseInt(DtMes)) || isNaN(parseInt(DtAno))) ||(DtAno < 1900 || DtAno > 9999) ||(DtMes < 1 || DtMes > 12) ||(DtDia < 1 || DtDia > 31) ||(DtMes == 2 && DtDia > 28 && (DtAno % 4 != 0)) ||(DtMes == 2 && DtDia > 29 && (DtAno % 4 == 0)) ||(DtDia > 30 && (DtMes == 4 || DtMes == 6 || DtMes == 9 || DtMes== 11))){
			alert ('Preencha uma Data Valída !!');
			 DataField.focus();
			 DataField.select();
			 return false;
		} else {
			return true;
		}	
       
	}
	else
	{
      DataField.focus();
      DataField.select();
	  return false;	
	}
	
	
}



function ValidaAno (iString, fNull)
{
	if (fNull && iString == "")
		return (true);
	else
	{
		if (ValidaInt (iString) && iString.length == 4 && iString>0)
			return (true);
		else
			return (false);
	}
}


function ValidaMes (iString, fNull)
{
	if (fNull && iString == "")
		return (true);
	else
	{
		if (ValidaInt (iString, 1, 12))
			return (true);
		else
			return (false);
	}
}


function ValidaDia (iString, fNull)
{
	if (fNull && iString == "")
		return (true);

	else
	{
		if (ValidaInt (iString, 1, 31))
			return (true);
		else
			return (false);
	}
}



function ValidaData (thisFieldvalue, strTipoData, fNull, NomeCampo)
{
	var thisFieldValue = thisFieldvalue;

	switch (strTipoData)
	{
		case "dia":
			// Se o valor estiver OK (Inteiro válido)
			if (!ValidaDia (thisFieldValue, fNull))
			{
				alert ('Preencha um dia válido (de 1 a 31) para o campo '+NomeCampo);
				//thisField.focus();
				//thisField.select();
				return (false);
			}
			break;
		
		case "mes":
			if (!ValidaMes (thisFieldValue, fNull))
			{
				alert ('Preencha um mês válido (de 1 a 12) para o campo '+NomeCampo);
				//thisField.focus();
				//thisField.select();
				return (false);
			}
			break;
		
		case "ano":
			// Se o valor estiver OK (data válida)
			if (!ValidaAno (thisFieldValue, fNull))
			{
				alert ('Preencha o ano com 4 dígitos (ex. 2000) para o campo '+NomeCampo);
				//thisField.focus();
				//thisField.select();
				return (false);
			}
			break;
	}
	
	return (true);
}

function ValidaInt (strField, NmInicial, NmFinal)
{
	var iField = strField;
	//var prsVal = parseInt(iField, 10);
    var prsVal = iField;	
	
	// Se for um número
	if (!isNaN (prsVal))
	{
		// Se NmInicial e NmFinal não foram informados
		if (!NmInicial && !NmFinal)
		{
			// É um int válido
			return (true);
		}
		else
		{
			// Se não estiver dentro dos limites passados
			if (!(prsVal >= NmInicial && prsVal <= NmFinal))
			{
				// Não é um Int válido
				return (false);
			}
			else
				return (true);
		}
	}
	else
	{
		return (false);
	}	
}


function ValidaNumber(thisField,strPlus,strMinus,tamminimo,tammax,tam,StrFieldLabel,Obr,valormin,valormax)
{

	var tamamim = tamminimo;
	var checkOK = "0123456789" + strPlus;
	for (i = 0;  i < strMinus.length;  i++)
	{
           checkOK = checkOK.replace(strMinus.charAt(i),"");
	}	
 	var checkStr = thisField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
	        break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		
		allNum += ch;
	}
	if (!allValid)
	{
		alert ('O campo ' + StrFieldLabel + ' possui caracteres inválidos - Não use caracteres especiais.');
		thisField.value='';
		thisField.focus()
		return (false);
	}
	if (Obr=='NO')
	{
	  if (thisField.value.length>0)
	  {
		  if (parseFloat(CNumeric(thisField.value,"")) < parseFloat(valormin))
		  {
			alert ('O campo ' + StrFieldLabel + ' tem o valor mínimo de ' + valormin + '');
			thisField.focus()
			return (false);
		  }
		  if (parseFloat(CNumeric(thisField.value,"")) > parseFloat(valormax))
		  {
			alert ('O campo ' + StrFieldLabel + ' tem o valor máximo de ' + valormax + '');
			thisField.focus()
			return (false);
		  }		  
	  	  if (tamminimo!=99)
		  {
		    if (thisField.value.length < tamminimo)
		    {
			  alert ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamamim + ' caracteres.');
			  thisField.focus()
			  return (false);
		    }
		  }  
		  if (tammax!=99)
		  {
		    if (thisField.value.length > tammax)
		    {
			  alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
			  thisField.focus()
			  return (false);
		    }
		  }  			
		  if (tam!=99)
		  {
		    if (thisField.value.length != tam)
		    {
			  alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
			  thisField.focus()
			  return (false);
		    }
		  }	

	  }
	}
	else
	{	
	  if (thisField.value.length==0)
	  {
	  	  alert ('O campo ' + StrFieldLabel + ' deve ser preenchido.');
		  thisField.focus()
		  return (false);
	  }
	  if (parseFloat(CNumeric(thisField.value,"")) < parseFloat(valormin))
	  {
	    alert ('O campo ' + StrFieldLabel + ' tem o valor mínimo de ' + valormin + '');
	  	thisField.focus()
	  	return (false);
	  }
	  if (parseFloat(CNumeric(thisField.value,"")) > parseFloat(valormax))
	  {
	    alert ('O campo ' + StrFieldLabel + ' tem o valor máximo de ' + valormax + '');
	  	thisField.focus()
	  	return (false);
	  }		  	  
	  if (tamminimo!=99)
	  {
	    if (thisField.value.length < tamminimo)
	    {
		  alert ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamamim + ' caracteres.');
		  thisField.focus()
		  return (false);
	    }
	  }  
	  if (tammax!=99)
	  {
	    if (thisField.value.length > tammax)
	    {
		  alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
		  thisField.focus()
		  return (false);
	    }
	  }  			
	  if (tam!=99)
	  {
	    if (thisField.value.length != tam)
	    {
		  alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
		  thisField.focus()
		  return (false);
	    }
	  }	
	
	}


	return (true);
}


function CNumeric(str,AddStrPlus)    
{
var strPlus="R$. " + AddStrPlus;   
var strNew = str;
for (i=0;i<str.length;i++)
{
   for (j=0;j<strPlus.length;j++)
   {
     if (strPlus.charAt(j)==str.charAt(i))
       strNew = strNew.replace(strPlus.charAt(j),"") 
   }
}  
strNew = strNew.replace(",",".")
return strNew;  
}   


function validaSelect(Field,strFieldLabel,InvalidValue)
{
 if (Field.options[Field.selectedIndex].value==InvalidValue)
  {
    alert("Escolha um valor válido para o campo " + strFieldLabel);
    Field.focus();
    return false;
  }
 return true; 
}

function validaSelect2(Field,strFieldLabel,InvalidValue)
{
 if (Field.options.value==InvalidValue)
  {
    alert("Escolha um valor válido para o campo " + strFieldLabel);
    Field.focus();
    return false;
  }
 return true; 
}
function VerificaPeriodoData(DataFieldIni,DataFieldIniDes,DataFieldFim,DataFieldFimDes)
{
var DtDia = DataFieldIni.value.substr(0,2);
var DtMes = DataFieldIni.value.substr(3,2);
var DtAno = DataFieldIni.value.substr(6,4);
dtini = new Date(DtAno,DtMes,DtDia);
DtDia = DataFieldFim.value.substr(0,2);
DtMes = DataFieldFim.value.substr(3,2);
DtAno = DataFieldFim.value.substr(6,4);
dtfim = new Date(DtAno,DtMes,DtDia);
if (dtini > dtfim)
  {
    alert("O campo "+DataFieldIniDes+" não pode ser maior que o campo "+DataFieldFimDes);
    return false;
  }
return true;  
}

function VerificaPeriodoData1(DataFieldIni,DataFieldIniDes,DataFieldFim,DataFieldFimDes)
{
var DtDia = DataFieldIni.value.substr(0,2);
var DtMes = DataFieldIni.value.substr(3,2);
var DtAno = DataFieldIni.value.substr(6,4);
dtini = new Date(DtAno,DtMes,DtDia);
DtDia = DataFieldFim.value.substr(0,2);
DtMes = DataFieldFim.value.substr(3,2);
DtAno = DataFieldFim.value.substr(6,4);
dtfim = new Date(DtAno,DtMes,DtDia);
if (dtfim < dtini)
  {   
    alert("O campo "+DataFieldFimDes+" tem que ser Maior que a Data de Hoje");
    return false;
  } 
  
 
return true;  
} 
function ValidaString (thisField,StrFieldLabel,StrPlus,StrMinus,Obr,tamminimo,tammax,tam)
{	
	var checkOK = ' <\/>&;.-_,=!#",.<>?:;()*&%$#@!-+/\|=_abcdefghijklmnopqrstuvxywzABCDEFGHIJKLMNOPQRSTUVXYWçÇáÁàÀéÉíÍóÓúÚãõÃÕêÊÔôZ0123456789ºª'+unescape("%0A") + unescape("%0D") + StrPlus;
	for (i = 0;  i < StrMinus.length;  i++)
	{
           checkOK = checkOK.replace(StrMinus.charAt(i),"");
	}
	var checkStr = thisField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
	        break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		
		allNum += ch;
	}
	
	if (!allValid)
	{
		alert ('O campo ' + StrFieldLabel + ' possui caracteres inválidos - Não use caracteres especiais.');
		if(thisField.type!='hidden')
		  thisField.focus()
		return (false);
	}
	
	if (Obr=='NO')
	{
		if (thisField.value.length>0)
		{	
			if (tamminimo!=99)
			{
			  if (thisField.value.length < tamminimo)
			  {
				alert ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamminimo + ' caracteres.');
				if(thisField.type!='hidden')
				  thisField.focus()
				return (false);
			  }
			}  
			if (tammax!=99)
			{
				if (thisField.value.length > tammax)
				{
					alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
					if(thisField.type!='hidden')
					  thisField.focus()
					return (false);
				}
			}  			
			if (tam!=99)
			{
				if (thisField.value.length != tam)
				{
					alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
					if(thisField.type!='hidden')
					  thisField.focus()
					return (false);
				}
			}					
		}	
	}
	else
	{
	
		if (thisField.value.length==0)
		{
			alert ('O campo ' + StrFieldLabel + ' deve ser preenchido.');
			if(thisField.type!='hidden')
			  thisField.focus()
			return (false);
		}	
		if (tamminimo!=99)
		{
			if (thisField.value.length < tamminimo)
			{
				alert ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamminimo + ' caracteres.');
				if(thisField.type!='hidden')
				  thisField.focus()
				return (false);
			}
		}  
		if (tammax!=99)
		{
			if (thisField.value.length > tammax)
			{
				alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
				if(thisField.type!='hidden')
				  thisField.focus()
				return (false);
			}
		}  			
		if (tam!=99)
		{
			if (thisField.value.length != tam)
			{
				alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
				if(thisField.type!='hidden')
				  thisField.focus()
				return (false);
			}
		}		
		
	}

	

	
	return (true);
}

function ValidaSenha (thisField)
{
	var checkOK = "abcdefghijklmnopqrstuvxywzABCDEFGHIJKLMNOPQRSTUVXYWZ0123456789-_";
	var checkStr = thisField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
	        break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		
		allNum += ch;
	}
	
	if (!allValid)
	{
		alert ('Você não inseriu caracteres válidos - Não use acentos ou caracteres especiais.');
		thisField.focus()
		return (false);
	}
	
	return (true);
}

function emailCheck (emailField,strFieldLabel) 
{
if (emailField.value.search("'")!=-1)
{
 alert("O campo " + strFieldLabel + " possui caracteres especiais inválidos")
 emailField.focus();
 return false;
}
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var emailStr = emailField.value; 

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert(" O campo " + strFieldLabel + " parece estar incorreto (cheque @ e .'s)");
val= false;
emailField.focus();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("O nome de usuario do campo " + strFieldLabel + " contém caracteres inválidos.");
val= false;
emailField.focus();
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("O nome do dominio do campo " + strFieldLabel + " contém caracteres inválidos.");
val= false;
emailField.focus();
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("O nome de usuario do campo " + strFieldLabel + " parece estar inválido.");
val= false;
emailField.focus();
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("O Endereçamento IP do campo " + strFieldLabel + " está incorreto!");
val= false;
emailField.focus();
return false;
   }
}
val= true;
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("O dominio de usuario do campo " + strFieldLabel + " parece estar inválido.");
val= false;
emailField.focus();
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("O fim do endereço do campo " + strFieldLabel + ", deve ter mais de duas letras" + "país.");
val= false;
emailField.focus();
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("O endereço do campo " + strFieldLabel + " não tem um hostname!");
val= false;
emailField.focus();
return false;
}

// If we've gotten this far, everything's valid!
return true;
emailField.focus();
return false;
}


function Mascara (formato, keypress, objeto){
campo = eval(objeto);
// CEP
if (formato=='CEP'){
	separador = '-'; 
	conjunto1 = 5;	
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}	
}

// DATA
if (formato=='DATA'){
	separador = '/'; 
	conjunto1 = 2;
	conjunto2 = 5;
	//ano = '20';
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}
	if (campo.value.length == conjunto2){
		campo.value = campo.value + separador;
	}
}

// TELEFONE
if (formato=='TELEFONE'){
	separador = '-'; 
	conjunto1 = 4;
	if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;
	}
}


}


function FormataCpf(campo,tammax,teclapres) {
 var tecla = teclapres.keyCode;
  
 vr = event.srcElement.value;
 vr = vr.replace( "/", "" );
 vr = vr.replace( "/", "" );
 vr = vr.replace( ",", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( ".", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 vr = vr.replace( "-", "" );
 tam = vr.length;

 if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

 if (tecla == 8 ){ tam = tam - 1 ; }
  
 if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
  if ( tam <= 2 ){ 
    event.srcElement.value = vr ; }
   if ( (tam > 2) && (tam <= 5) ){
    event.srcElement.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ){
    event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ){
    event.srcElement.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 12) && (tam <= 14) ){
    event.srcElement.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 15) && (tam <= 17) ){
    event.srcElement.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
 }  
}

function FormataMoeda(campo,tammax,teclapres) {
 var tecla = teclapres.keyCode;  
 
vr = Limpar(event.srcElement.value,"0123456789");
tam = vr.length;

 if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

 if (tecla == 8 ){ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
  if ( tam <= 2 ){ 
    event.srcElement.value = vr ; }
   if ( (tam > 2) && (tam <= 5) ){
    event.srcElement.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ){
    event.srcElement.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ){
    event.srcElement.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
   	
  }  
}

function SoNumber(e)
{
if(document.all) // Internet Explorer
var tecla = event.keyCode;

else if(document.layers) // Nestcape
var tecla = e.which;

if(tecla > 47 && tecla < 58) // numeros de 0 a 9
return true;
else
{
if (tecla != 8) // backspace
return false;
else
return true;
}

}


function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

function Mascara_Chapa (keypress, objeto){
campo = eval (objeto);
separador = '-'; 
conjunto1 = 6;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador;
}

}

