//Força o campo a ter um determinado formato e tamanho
function montar(formato, campo) {
	//# = numeros
	//! = letras
	//Um exemplo para CEP: montar('#####-###',this)
	valor = campo.value;
	for (i=0;i<valor.length;i++) { // Verifica caractere por caractere e é valido ou não
		//i = valor.length-1;
		
		/*-----------------------------------------------------------------
		Verifica nos campos telefone residêncial e comercial não podendo 
		colocoar 7,8 ou 9, que são início de celular que não é válido 
		para estes campos
		Por 	: Robson Mello
		Data	: 29/08/2008
		-----------------------------------------------------------------*/
		if (campo.id == 'tel_residencial' || campo.id == 'tel_comercial')
		{
			if (i == 0)
			{
				if (campo.value.substr(0,1) > 6 && campo.value.substr(0,1) < 10)// !! (campo.value.substr(0,1) == 0))
				{
					valor = ""		
				}
				if (campo.value.substr(0,1) == 0)
				{
					valor = ""		
				}				
			}
		}
		/*---------------------------------------------------------------*/


		/*-----------------------------------------------------------------
		Verifica o campo telefone celular não podendo colocoar número menor 
		que 7, pois abaixo de 7 são iniciais de tel fixo.
		Por 	: Robson Mello
		Data	: 29/08/2008
		-----------------------------------------------------------------*/
		if (campo.id == 'celular')
		{
			if (i == 0)
			{
				if (campo.value.substr(0,1) < 6)
				{
					valor = ""		
				}
			}
		}
		/*---------------------------------------------------------------*/
		
		caractere=valor.substr(i,1);
		if ((formato.substr(i,1)=="#" && (isNaN(caractere) || caractere == " ")) || (formato.substr(i,1)=="!" && !isNaN(caractere))) {
			valor = valor.substr(0,valor.length-1);
		} else if (formato.substr(i,1)!="#" && formato.substr(i,1)!="!" && caractere!=formato.substr(i,1)) {
			if ((formato.substr(i+1,1)=="#" && isNaN(caractere)) || (formato.substr(i,1)=="!" && !isNaN(caractere))) {
				valor = valor.substr(0,valor.length-1)+formato.substr(i,1);
			} else {
				valor = valor.substr(0,valor.length-1)+formato.substr(i,1)+valor.substr(valor.length-1,1);
			}
		}
		valor = valor.substr(0,formato.length);
	} //fim do loop
	campo.value = valor;
}

function somenteAlpha(w_campoID, w_maximo)
{
	w_valor = w_campoID.value
	if ((event.keyCode > 95 && event.keyCode < 106) || (event.keyCode > 47 && event.keyCode < 58))
	{
		w_campoID.value = w_valor.substr(0,w_valor.length-1)
	}

}
function limitar(maximo, campo) 
{ //Limita o campo
	//alert(event.keyCode)
	if (campo.value.length>maximo) { //Verifica se o campo é maior que o maximo permitido
		campo.value = campo.value.substr(0,maximo); //corta o campo
	}
}

