/*
#############################################
## Desenvolvimento do Script: IlhaWeb Host ##
## http://www.ilhawebhost.com.br           ##
## MSN: atendimento@ilhawebhost.com.br     ##
## Skype: atendimento.ilhaweb              ##  
#############################################
*/

/* FUNÇÕES PARA FORMATAÇÃO DE CAMPOS */

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); }
      else { // qualquer caracter...
        return true;
      }
    }
    else {
      return true;
    }
  }
  
/* SOMENTE NÚMEROS  */
function sonum(nro){
		
		var valid    = "0123456789";
		var numerook = "";
		var temp;
		for(var i = 0; i < nro.length; i++)
		{
			temp = nro.substr(i, 1);
			if (valid.indexOf(temp) != -1)
				numerook = numerook + temp;
		}
		return(numerook);
	}
	
/* FORMATANDO O CAMPO VALOR  */
function formatavalor(objeto, e, tammax, decimais){
		
		var tecla  = (window.Event) ? e.which : e.keyCode;
		var tamObj = objeto.value.length;
	
		if ((tecla == 8) && (tamObj == tammax))
			tamObj = tamObj - 1;
	
		vr = sonum(objeto.value);
		tam = vr.length;
	
		if (((tecla == 8) || (tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)) && (parseInt(tamObj) + 1 <= parseInt(tammax)))
		{
			if ((tam < tammax) && (tecla != 8))
				tam = vr.length + 1;
			if ((tecla == 8) && (tam > 1))
				tam = tam - 1;
	
			/*if (tam <= decimais)
				objeto.value = ("0," + vr);*/
			if ((tam == (decimais + 1)) && (tecla == 8))
				objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr((tam - decimais), tam);
			if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) == "0"))
				objeto.value = vr.substr(1, (tam - (decimais+1))) + "," + vr.substr(tam - (decimais), tam);
			if ((tam > (decimais + 1)) && (tam <= (decimais + 3)) && (vr.substr(0,1) != "0"))
				objeto.value = vr.substr(0, (tam - decimais)) + "," + vr.substr(tam - decimais, tam);
			if ((tam >= (decimais + 4)) && (tam <= (decimais + 6)))
				objeto.value = vr.substr(0, tam - (decimais + 3)) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
			if ((tam >= (decimais + 7)) && (tam <= (decimais + 9)))
				objeto.value = vr.substr(0, tam - (decimais + 6)) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
			if ((tam >= (decimais + 10)) && (tam <= (decimais + 12)))
				objeto.value = vr.substr(0, tam - (decimais + 9)) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
			if ((tam >= (decimais + 13)) && (tam <= (decimais + 15)))
				objeto.value = vr.substr(0, tam - (decimais + 12)) + "." + vr.substr(tam - (decimais + 12), 3) + "." + vr.substr(tam - (decimais + 9), 3) + "." + vr.substr(tam - (decimais + 6), 3) + "." + vr.substr(tam - (decimais + 3), 3) + "," + vr.substr(tam - decimais, tam);
		}
		else if((tecla != 8) && (tecla != 9) && (tecla != 13) && (tecla != 18) && (tecla != 35) && (tecla != 36) && (tecla != 37) && (tecla != 39))
		{
			return false;
		}
	}
	
/* FORMULÁRIO DE INFORMAÇÕES */
function validar_info(forminfo) {

	if (forminfo.nome.value == "" || forminfo.nome.value == null)
	{
		window.alert("Por favor informe seu nome\n\nObrigado!");
		forminfo.nome.focus();
		return false;
	}
	if (forminfo.email.value=='' || forminfo.email.value.match(/(\w+)@(.+)\.(\w+)$/)==null)
	{
		window.alert("Por favor informe seu email\n\nObrigado!");
		forminfo.email.focus();
		return false;
	}
	if (forminfo.tel.value == "" || forminfo.tel.value == null)
	{
		window.alert("Por favor informe seu telefone\n\nObrigado!");
		forminfo.tel.focus();
		return false;
	}
	if (forminfo.msg.value == "" || forminfo.msg.value == null)
	{
		window.alert("Por favor insira um comentário\n\nObrigado!");
		forminfo.msg.focus();
		return false;
	}
}