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 ValidaNumber(thisField,strPlus,tamminimo,tammax,tam,StrFieldLabel,Obr,valormin,valormax)
{

	var tamamim = tamminimo;
	var checkOK = "0123456789" + strPlus;
 	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)
	{
		//return ('O campo ' + StrFieldLabel + ' possui caracteres inválidos - Não use caracteres especiais.');
		////thisField.focus()
		return ('O campo ' + StrFieldLabel + ' possui caracteres inválidos - Não use caracteres especiais.');
	}
	if (Obr=='NO')
	{
	  if (thisField.value.length>0)
	  {
		  if (parseFloat(CNumeric(thisField.value,"")) < parseFloat(valormin))
		  {
			return ('O campo ' + StrFieldLabel + ' tem o valor mínimo de ' + valormin + '');
			//thisField.focus()
			//return (false);
		  }
		  if (parseFloat(CNumeric(thisField.value,"")) > parseFloat(valormax))
		  {
			return ('O campo ' + StrFieldLabel + ' tem o valor máximo de ' + valormax + '');
			//thisField.focus()
			//return (false);
		  }		  
	  	  if (tamminimo!=99)
		  {
		    if (thisField.value.length < tamminimo)
		    {
			  return ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamamim + ' caracteres.');
			  //thisField.focus()
			  //return (false);
		    }
		  }  
		  if (tammax!=99)
		  {
		    if (thisField.value.length > tammax)
		    {
			  return ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
			  //thisField.focus()
			  //return (false);
		    }
		  }  			
		  if (tam!=99)
		  {
		    if (thisField.value.length != tam)
		    {
			  return ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
			  //thisField.focus()
			  //return (false);
		    }
		  }	

	  }
	}
	else
	{	
	  if (thisField.value.length==0)
	  {
	  	  return ('O campo ' + StrFieldLabel + ' deve ser preenchido.');
		  //thisField.focus()
		  //return (false);
	  }
	  if (parseFloat(CNumeric(thisField.value,"")) < parseFloat(valormin))
	  {
	    return ('O campo ' + StrFieldLabel + ' tem o valor mínimo de ' + valormin + '');
	  	//thisField.focus()
	  	//return (false);
	  }
	  if (parseFloat(CNumeric(thisField.value,"")) > parseFloat(valormax))
	  {
	    return ('O campo ' + StrFieldLabel + ' tem o valor máximo de ' + valormax + '');
	  	//thisField.focus()
	  	//return (false);
	  }		  	  
	  if (tamminimo!=99)
	  {
	    if (thisField.value.length < tamminimo)
	    {
		  return ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamamim + ' caracteres.');
		  //thisField.focus()
		  //return (false);
	    }
	  }  
	  if (tammax!=99)
	  {
	    if (thisField.value.length > tammax)
	    {
		  return ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
		  //thisField.focus()
		  //return (false);
	    }
	  }  			
	  if (tam!=99)
	  {
	    if (thisField.value.length != tam)
	    {
		  return ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
		  //thisField.focus()
		  //return (false);
	    }
	  }	
	
	}


	return ('');
}

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.');
		//thisField.focus()
		return ('O campo ' + StrFieldLabel + ' possui caracteres inválidos - Não use caracteres especiais.');
	}
	
	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.');
				//thisField.focus()
				return ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamminimo + ' caracteres.');
			  }
			}  
			if (tammax!=99)
			{
				if (thisField.value.length > tammax)
				{
					//alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
					//thisField.focus()
					return ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
				}
			}  			
			if (tam!=99)
			{
				if (thisField.value.length != tam)
				{
					//alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
					//thisField.focus()
					return ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
				}
			}					
		}	
	}
	else
	{
	
		if (thisField.value.length==0)
		{
			//alert ('O campo ' + StrFieldLabel + ' deve ser preenchido.');
			//thisField.focus()
			return ('O campo ' + StrFieldLabel + ' deve ser preenchido.');
		}	
		if (tamminimo!=99)
		{
			if (thisField.value.length < tamminimo)
			{
				//alert ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamminimo + ' caracteres.');
				//thisField.focus()
				return ('O campo ' + StrFieldLabel + ' tem o tamanho mínimo de ' + tamminimo + ' caracteres.');
			}
		}  
		if (tammax!=99)
		{
			if (thisField.value.length > tammax)
			{
				//alert ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
				//thisField.focus()
				return ('O campo ' + StrFieldLabel + ' tem o tamanho maximo de ' + tammax + ' caracteres.');
			}
		}  			
		if (tam!=99)
		{
			if (thisField.value.length != tam)
			{
				//alert ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
				//thisField.focus()
				return ('O campo ' + StrFieldLabel + ' tem o tamanho definido de ' + tam + ' caracteres.');
			}
		}		
		
	}

	

	
	return ('');
}

function validaSelect(Field,strFieldLabel,InvalidValue)
{
 if (Field.options[Field.selectedIndex].value==InvalidValue)
  {
    return("Escolha um valor válido para o campo " + strFieldLabel);
    //Field.focus();
    //return false;
  }
 return (''); 
}


function validacgc(InString,strFieldLabel,Obr) {
    if (Obr=='NO')
    {
        Field = InString;
        InString = InString.value;
        LenStr = InString.length;        
        if (LenStr==0)
            return true;
		if ((LenStr < 8)||(LenStr > 14)) {
			alert("O campo " + strFieldLabel + " está inválido");
			Field.focus();
			return false};
        TempString="";
		if (LenStr < 14) {
	        for (Count=1; Count<=(14-LenStr); Count++) {
	                TempString = TempString + "0";
        	}
		}
		InString = TempString + InString;
		CgcFrente = "" + InString.substring(0,12);
		CgcDigito = "" + InString.substring(12,14);
		TempString = CgcFrente;
		Fator=5;
		DigitoFinal = "";
		for (loop=0; loop<=1; loop++) {
			SomaDig=0;
			for (Count=0; Count<=TempString.length; Count++) {
					StrChar = TempString.substring(Count, Count+1);
					SomaDig = SomaDig + (StrChar * Fator);
					Fator--;
					if (Fator==1) {Fator=9}
			}
			Resto = SomaDig % 11;
			if (Resto<=1)
				Digito = 0;
			else
				Digito = 11 - Resto;
			DigitoFinal = "" + DigitoFinal + Digito;
			TempString = CgcFrente + "" + Digito;
			Fator=6;
			if (SomaDig==0) {
				DigitoFinal=01;
				CicDigito=02;
				}
		}
		if (DigitoFinal!=CgcDigito) {
			alert("Informe um CGC válido para o campo " + strFieldLabel);
			Field.focus();
        	return (false);
		}
		
		
	}
	else
	{
        
        Field = InString;
        InString = InString.value;
        LenStr = InString.length;        
		if ((LenStr < 8)||(LenStr > 14)) {
			alert("O campo " + strFieldLabel + " está inválido");
			Field.focus();
			return false};
        TempString="";
		if (LenStr < 14) {
	        for (Count=1; Count<=(14-LenStr); Count++) {
	                TempString = TempString + "0";
        	}
		}
		InString = TempString + InString;
		CgcFrente = "" + InString.substring(0,12);
		CgcDigito = "" + InString.substring(12,14);
		TempString = CgcFrente;
		Fator=5;
		DigitoFinal = "";
		for (loop=0; loop<=1; loop++) {
			SomaDig=0;
			for (Count=0; Count<=TempString.length; Count++) {
					StrChar = TempString.substring(Count, Count+1);
					SomaDig = SomaDig + (StrChar * Fator);
					Fator--;
					if (Fator==1) {Fator=9}
			}
			Resto = SomaDig % 11;
			if (Resto<=1)
				Digito = 0;
			else
				Digito = 11 - Resto;
			DigitoFinal = "" + DigitoFinal + Digito;
			TempString = CgcFrente + "" + Digito;
			Fator=6;
			if (SomaDig==0) {
				DigitoFinal=01;
				CicDigito=02;
				}
		}
		if (DigitoFinal!=CgcDigito) {
			alert("Informe um CGC válido para o campo " + strFieldLabel);
			Field.focus();
        	return (false);
		}	  
	  
	}  	
		
  return true;
}


function validacic(InString,strFieldLabel) {
        Field = InString;
        InString = InString.value;
        LenStr = InString.length;

		if ((LenStr < 8)||(LenStr > 11)) {
			alert("O campo CPF está inválido");
			Field.focus();
			return false};
        TempString="";
		if (LenStr < 11) {
	        for (Count=1; Count<=(11-LenStr); Count++) {
	                TempString = TempString + "0";
        	}
		}
		InString = TempString + InString;
		CicFrente = "" + InString.substring(0,9);
		CicDigito = "" + InString.substring(9,11);
		TempString = CicFrente;
		Fator=10;
		DigitoFinal = "";
		for (loop=0; loop<=1; loop++) {
			SomaDig=0;
			for (Count=0; Count<=TempString.length; Count++) {
					StrChar = TempString.substring(Count, Count+1);
					SomaDig = SomaDig + (StrChar * Fator);
					Fator--;
			}
			Resto = SomaDig % 11;
			if (Resto<=1)
				Digito = 0;
			else
				Digito = 11 - Resto;
			DigitoFinal = "" + DigitoFinal + Digito;
			TempString = CicFrente + "" + Digito;
			Fator=11;
			if (SomaDig==0) {
				DigitoFinal=01;
				CicDigito=02;
				}
		}
		if ((DigitoFinal!=CicDigito)||(InString=="11111111111")||(InString=="22222222222")||
		   (InString=="33333333333")||(InString=="44444444444")||(InString=="55555555555")||
		   (InString=="66666666666")||(InString=="77777777777")||(InString=="88888888888")||
		   (InString=="99999999999")||(InString=="01234567890")||(InString=="1234567890"))
			{
			alert("Informe um CPF válido para o campo " + strFieldLabel);
			Field.focus();
        	return (false);
		}
		return true;
}

function ValidaFullData (DataField,strFriendlyName,fNull,isBirthDay)
{
	var DtDia;
	var DtMes;
	var DtAno;
//  alert(fNull)
	if ((DataField.value.length==0)&&(fNull==true))
	  return("");
	  
	if ((DataField.value.length!=10))
	{
	  return("O tamanho do campo " + strFriendlyName +" está incorreto!\n EX:'01/02/1998'")
      //DataField.focus();
      //DataField.select();	  
	  //return false;
	}
	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
	var vErroDia,vErroMes,vErroAno
		vErroDia = ValidaData (DtDia,"dia",false)
        vErroMes = ValidaData (DtMes,"mes", false)
        vErroAno = ValidaData (DtAno,"ano", false)

	if ((vErroDia=='') &&
		(vErroMes=='') &&
		(vErroAno===''))
	{	
		
		if (isBirthDay)
		{
		 hoje = new Date()
         var ano = hoje.getYear()
         if (DtAno>=ano)
           {
             return ("Preecha o campo " + strFriendlyName + " corretamente\n EX:'01/02/1998'");
             //DataField.focus();
             //DataField.select();
             return false
           }
		}
		// Valida dia pelo mes
		if (DtMes == 2)
		{
			DtAnoAux = DtAno % 4;
			//return ('DtAnoAux = ' + DtAnoAux);
			if (DtAnoAux == 0)
				DtDiaMax = 29;
			else
				DtDiaMax = 28;
			//return ('DtDiaMax = ' + DtDiaMax);
			//return ('ValidaInt = ' + ValidaInt (DtDia, 1, DtDiaMax));
			if (ValidaInt (DtDia, 1, DtDiaMax))
			{
				return ('');
			}
			else
			{
				return ("Preecha o campo " + strFriendlyName + " corretamente\n EX:'01/02/1998'");
                //DataField.focus();
                //DataField.select();
				//return false;
			}
		}
		else
		{
			if (ValidaInt (DtDia, 1, DiaMes[DtMes - 1]))
			{
				return ('');
			}
			else
			{
				return ("Preecha o campo " + strFriendlyName + " corretamente\n EX:'01/02/1998'");
                //DataField.focus();
                //DataField.select();
				//return false;
			}
		}
	}
	else
	{
		return vErroDia+vErroMes+vErroAno;
	}
}


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)
{
	var thisFieldValue = thisFieldvalue;

	switch (strTipoData)
	{
		case "dia":
			// Se o valor estiver OK (Inteiro válido)
			if (!ValidaDia (thisFieldValue, fNull))
			{
				return ('Preencha um dia válido (de 1 a 31)');
				//thisField.focus();
				//thisField.select();
				//return (false);
			}
			break;
		
		case "mes":
			if (!ValidaMes (thisFieldValue, fNull))
			{
				return ('Preencha um mês válido (de 1 a 12)');
				//thisField.focus();
				//thisField.select();
				//return (false);
			}
			break;
		
		case "ano":
			// Se o valor estiver OK (data válida)
			if (!ValidaAno (thisFieldValue, fNull))
			{
				return ('Preencha o ano com 4 dígitos (ex. 2000)');
				//thisField.focus();
				//thisField.select();
				//return (false);
			}
			break;
	}
	
	return ('');
}

function ValidaInt (strField, NmInicial, NmFinal)
{
	var iField = strField;
	var prsVal = parseInt(iField, 10);

	// 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 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 ('');  
}


function validaciccgc(ObjString,FieldName,flObr) {
        var InString = ObjString.value;        
        LenStr = InString.length;
		if ((!flObr)&&(LenStr==0))
		{
			 return('')
		}
		if ((LenStr < 8)||(LenStr > 14)) {
			return("O campo "+FieldName+" está inválido\nEste Campo não pode conter caracteres especiais, somente números!");
			//return false;
			//return 99;
		}
        TempString="";
		if (LenStr < 11) {
			for (Count=1; Count<=(11-LenStr); Count++) {
				TempString = TempString + "0";
        		}
		}
		InString = TempString + InString;
		CicFrente = "" + InString.substring(0,9);
		CicDigito = "" + InString.substring(9,11);
		TempString = CicFrente;
		Fator=10;
		DigitoFinal = "";
		for (loop=0; loop<=1; loop++) {
			SomaDig=0;
			for (Count=0; Count<=TempString.length; Count++) {
					StrChar = TempString.substring(Count, Count+1);
					SomaDig = SomaDig + (StrChar * Fator);
					Fator--;
			}
			Resto = SomaDig % 11;
			if (Resto<=1)
				Digito = 0;
			else
				Digito = 11 - Resto;

			DigitoFinal = "" + DigitoFinal + Digito;
			TempString = CicFrente + "" + Digito;
			Fator=11;
			if (SomaDig==0) {
				DigitoFinal=01;
				CicDigito=02;
			}
		}
		
		if ((DigitoFinal==CicDigito)&&(InString!="11111111111")&&(InString!="22222222222")&&
		   (InString!="33333333333")&&(InString!="44444444444")&&(InString!="55555555555")&&
		   (InString!="66666666666")&&(InString!="77777777777")&&(InString!="88888888888")&&
		   (InString!="99999999999")&&(InString!="01234567890")&&(InString!="1234567890"))
		{
		        //return (1)
	        	return ('');
		}
		else
		{
		        TempString="";
				if (LenStr < 14) {
				        for (Count=1; Count<=(14-LenStr); Count++) {
				                TempString = TempString + "0";
			        	}
				}
			InString = TempString + InString;
			CgcFrente = "" + InString.substring(0,12);
			CgcDigito = "" + InString.substring(12,14);
			TempString = CgcFrente;
			Fator=5;
			DigitoFinal = "";
			for (loop=0; loop<=1; loop++) {
				SomaDig=0;
				for (Count=0; Count<=TempString.length; Count++) {
						StrChar = TempString.substring(Count, Count+1);
						SomaDig = SomaDig + (StrChar * Fator);
						Fator--;
						if (Fator==1) {Fator=9}
				}
				Resto = SomaDig % 11;
				if (Resto<=1)
					Digito = 0;
				else
					Digito = 11 - Resto;
				DigitoFinal = "" + DigitoFinal + Digito;
				TempString = CgcFrente + "" + Digito;
				Fator=6;
				if (SomaDig==0) {
					DigitoFinal=01;
					CicDigito=02;
					}
			}
			if (DigitoFinal!=CgcDigito) {
				return("O campo "+FieldName+" está inválido\nEste Campo não pode conter caracteres especiais, somente números!");
			}
			return ('');
		}
}


function ProcuraCaracter(re, str)
{
  if (str.search(re) == -1)
    return ('');
  else
    return ('');
}

function ValidaTextArea(Field,Desc,Obr,InvalidValue)
{
  var ch;
  var str = Field.value;
  var err = false;
  if ((Obr) && (str.length==0))
    return ('O campo '+Desc+' não pode estar vazio!');
	
  for (var i = 0;  i < InvalidValue.length;  i++) {
    ch = InvalidValue.charAt(i);
    if (str.search(ch) != -1)
	  err=true;	
  }
		
  if (err)
    return ('O campo '+Desc+' possui caracteres invalidos')
  else
    return ('');			

}


function ValidaMail (thisField,Desc,Obr)
{

	var checkOK = ".abcdefghijklmnopqrstuvxywzABCDEFGHIJKLMNOPQRSTUVXYWZ0123456789-@_";
	var PrimeiroNao = "@.-_"
	var checkStr = thisField.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	var ExisteArroba;
    if ((Obr) && (checkStr.length==0))
      return ('O campo '+Desc+' não pode estar vazio!');
	  
    if ((!Obr) && (checkStr.length==0))
      return ('');	  
		
	for (i = 0;  i < checkStr.length;  i++)
	{
		//Percorrendo a String
		ch = checkStr.charAt(i);
	
		//Testando para ver se existe o simbolo de @
		if (ch == "@")	
		{	
			ExisteArroba = "sim";
		}
		
		//Validando para o Primeiro Caracter não ser "@.-_"
		if (i == 0)
		{
			for (j = 0;  j < PrimeiroNao.length;  j++)
			{
			//alert(ch);
			//alert(PrimeiroNao.charAt(j));
			if (ch == PrimeiroNao.charAt(j))
				{
				//alert("entrou");
				allValid = false;
				break;
				}			
			}
		}	
		
				
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
	        break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		
		allNum += ch;
	}
	
	if (!allValid)
	{
		return ('O campo '+Desc+' não é um email válido');
		//thisField.focus();
		//return (false);
	}

	if (ExisteArroba != "sim")
	{
		return ('O campo '+Desc+' digitado não esta no formato correto.');
		//thisField.focus();
		//return (false);
	}
	
	return ('');
}



function Campo(Nome,Tipo,Descricao,StrPlus,StrMinus,Obr,tamminimo,tammax,tam,valormin,valormax,isBirthDay,InvalidValue) {
  this.Nome=Nome
  this.Tipo=Tipo
  this.Descricao=Descricao
  this.StrPlus=StrPlus
  this.StrMinus=StrMinus
  this.Obr=Obr
  this.tamminimo=tamminimo
  this.tammax=tammax
  this.tam=tam
  this.valormin=valormin
  this.valormax=valormax
  this.isBirthDay=isBirthDay
  this.InvalidValue=InvalidValue
}




function InsereCampo(vCampo,Nome,Tipo,Descricao,StrPlus,StrMinus,Obr,tamminimo,tammax,tam,valormin,valormax,isBirthDay,InvalidValue) {
  var objCampo = new Campo(Nome,Tipo,Descricao,StrPlus,StrMinus,Obr,tamminimo,tammax,tam,valormin,valormax,isBirthDay,InvalidValue)
  if ((vCampo.length==0)||(vCampo[vCampo.length]==null)) {
    vCampo[vCampo.length]=objCampo;
  }
  else {
    vCampo[vCampo.length+1]=objCampo;  
  }
}

function RetornaCampo(vCampo,Nome){
  for (var i = 0; i < vCampo.length; i++) {
    if (vCampo[i].Nome==Nome)
	  return vCampo[i];
  }
  return new Campo("");
  
}


function ValidaForm(Form,VetorCampo){
  var objCampo;
  var vErro="";
  var pErro="";  
  for (var i = 0; i < Form.elements.length; i++) {
     objCampo = RetornaCampo(VetorCampo,Form.elements[i].name)
	 if(objCampo.Nome!="") {
	   if (objCampo.Tipo=="T")
	     pErro = ValidaString (Form.elements[i],objCampo.Descricao,objCampo.StrPlus,objCampo.StrMinus,objCampo.Obr,objCampo.tamminimo,objCampo.tammax,objCampo.tam) 
	   if (objCampo.Tipo=="N")
	     pErro = ValidaNumber(Form.elements[i],objCampo.strPlus,objCampo.tamminimo,objCampo.tammax,objCampo.tam,objCampo.Descricao,objCampo.Obr,objCampo.valormin,objCampo.valormax)
	   if (objCampo.Tipo=="D")
	     pErro = ValidaFullData (Form.elements[i],objCampo.Descricao,objCampo.Obr,objCampo.isBirthDay)
	   if (objCampo.Tipo=="C")
	     pErro = validaciccgc(Form.elements[i],objCampo.Descricao,objCampo.Obr)	     
	   if (objCampo.Tipo=="S")
	     pErro = validaSelect(Form.elements[i],objCampo.Descricao,objCampo.InvalidValue)
	   if (objCampo.Tipo=="M")
	     pErro = ValidaTextArea(Form.elements[i],objCampo.Descricao,objCampo.Obr,objCampo.InvalidValue)
	   if (objCampo.Tipo=="E")
	     pErro = ValidaMail (Form.elements[i],objCampo.Descricao,objCampo.Obr)		 
		 		 
		 
		 		 
		      		 		 		 	     		  		 
	   
	 }
	 if (pErro!=""){
        vErro = vErro +"\n * "+pErro	 
	 }
	 pErro="";
  }
  if (vErro!="") {
    vErro =  "O seu formulário não pode ser enviado devido aos problemas abaixo. Por favor corrija-os e tente novamente.\n\n" + vErro
    alert(vErro);
	return false  
  }
  return true
}