//|||||| LIMITA CARACTERES ||||||||||||||||||
/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

//||||||| FIM LIMITA CARACTERES ||||||||||||||||||

//||||||||||||| FUNÇÃO CHECKA EMAIL ||||||||||||||||||
function emailCheck (emailStr,nome_campo) {

var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var firstChars=validChars
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom="(" + firstChars + validChars + "*" + ")"
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)
if (matchArray==null && document.getElementById(nome_campo).value!="") {
	   alert("Endereço incorreto (verifique @ e .'s)")
	   document.getElementById(nome_campo).value="";
	   document.getElementById(nome_campo).focus();		
	   return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null ) {
    // user is not valid
    alert("E-mail não válido.")
	 document.getElementById(nome_campo).value="";
	 document.getElementById(nome_campo).focus();
    return false
}

var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
			  document.getElementById(nome_campo).value="";
			  document.getElementById(nome_campo).focus();
		     return false
	    }
    }

    //document.form.submit()
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("O domínio do e-mail não é válido!")
	document.getElementById(nome_campo).value="";
	document.getElementById(nome_campo).focus();
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   alert("O final do endereço está incorreto")
	document.getElementById(nome_campo).value="";
	document.getElementById(nome_campo).focus();
   return false
}


if (domArr[domArr.length-1].length==3 && len<2) {
   var errStr="Endereço Inválido!"
   alert(errStr)
	document.getElementById(nome_campo).value="";
	document.getElementById(nome_campo).focus();
   return false
}
    //document.form.submit();

}
//||||||||||||| FIM FUNÇÃO CHECKA EMAIL |||||||||||||||||

//|||||||||||| FUNÇÃO DETECTA CAMPOS VAZIOS CADASTRO CLIENTE ADMIN |||||||||||
function verifica(v){
	
   if(navigator.appName =="Microsoft Internet Explorer"){   
		if(v!="x"){
	      if(navigator.appName =="Microsoft Internet Explorer"){
			   // Se a chamada vier dos próprios campos
		      for (i=0;i<18;i++){		            
	            if(document.form1.elements[v-1].value==""){
			         if(navigator.appName !="Microsoft Internet Explorer"){
	                  alert('preencha o campo '+	document.form1.elements[v+1].name);	
				      }else{					
				          alert('preencha o campo '+	document.forms[0].getElementsByTagName('B')[v].innerHTML);					
				      }	
					   if(document.form1.elements[v].value==""){			
				         document.form1.elements[v].value="";
					   }
					   d=1
				      document.form1.elements[v-1].focus();					   
				      return false										
		         }else{
			         if(d!=1){
		               document.form1.submit()	    
				      } 
		         }		  
	         }			      
	      }
			
		}else{
			// Se a chamada vier do submit	   
		   for (i=0;i<18;i++){		
            if(i==13 || i==15){
			      continue;
			   }
	         if(document.form1.elements[i].value==""){
			      if(navigator.appName !="Microsoft Internet Explorer"){
	               alert('preencha o campo '+	document.form1.elements[i].name);	
			      }else{					
				      alert('preencha o campo '+	document.forms[0].getElementsByTagName('B')[i+1].innerHTML);					
				   }	
				   d=1				
				   document.form1.elements[i].focus();					   
				   return false																
		      }else{
			      if(d!=1){
		            document.form1.submit()	    
				   } 
		      }		  
	      }						
		}	
	}

}
//|||||||||| FIM FUNÇÃO DETECTA CAMPOS VAZIOS CADASTRO CLIENTE ADMIN ||||||||||||||

//||||||FUNÇAO CAMPOS VAZIOS ATIVIDADE SERVIÇO ||||||||||||||
function verifica2(){

   if(document.form1.elements[0].value=="" || document.form1.elements[1].value==""){
	   alert('preencha todos o campo acima')
	   return false;
	}
}

//||||| FIM FUNÇAO CAMPOS VAZIOS ATIVIDADE SERVIÇO ||||||||||||||

//||||||||||| VALIDA TELEFONE ||||||||||||||||||||||||||
function valida_fone(campo_fone){
	s= document.getElementById(campo_fone).value;
	if( !s.match(/[0-9][0-9][0-9]\-[0-9][0-9][0-9][0-9]$/)&&            
	 document.getElementById(campo_fone).value !=""  )
                {
			  alert('Por Favor Use Apenas Números Para O Telefone\n'+
			  'E Separe o Prefixo do Número com "-"\n'+
			  'Exemplo (xx)443-1250 ou 433-1250\n'+
			  'ou aínda (xx)4432-1250 ou 4332-1250' )
			  document.getElementById(campo_fone).value = "";
			  document.getElementById(campo_fone).focus();
			  return false;
			    }
				
    return true;
}
//||||||||||||||| FIM VALIDA TELEFONE ||||||||||||||||||

//|||||| LIMITA CARACTERES ||||||||||||||||||
/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
	// text width//
	var fieldWidth =  parseInt(field.offsetWidth);
	var charcnt = field.value.length;        

	// trim the extra text
	if (charcnt > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}

	else { 
	// progress bar percentage
	var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
	document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
	document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
	// color correction on style from CCFFF -> CC0000
	setcolor(document.getElementById(counter),percentage,"background-color");
	}
}

function setcolor(obj,percentage,prop){
	obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}

//||||||| FIM LIMITA CARACTERES ||||||||||||||||||


//||||||| FUNÇÃO TRAVA BOTÃO DIREITO ||||||||||||||||||||
function verfonte()
{
if (event.button==2)
{
window.alert('Desculpe-me mas ó código não pode ser exibido!')
}
}
//document.onmousedown=verfonte
//||||||| FIM FUNÇÃO TRAVA BOTÃO DIREITO ||||||||||||||||||||

//||||||||||| AUMENTA E DIMINUE TEXTO |||||||||||||||||
var contar=0; 
function resize_text(idtexto,opcao){          
   if(opcao=="aumenta"){
	   ft=document.getElementById(idtexto).style.fontSize
		ft=parseInt(ft) 		  
		document.getElementById(idtexto).style.fontSize=ft+1;
		contar++;
		spy=1;
	}else if(opcao=="diminue"){
	   ft=document.getElementById(idtexto).style.fontSize
	   ft=parseInt(ft) 		  
		document.getElementById(idtexto).style.fontSize=ft-1;
		contar++
		spy=0
	}else{				
	   ft=document.getElementById(idtexto).style.fontSize
		ft=parseInt(ft) 	
		if(spy==1){	  
		   document.getElementById(idtexto).style.fontSize=ft-contar;
		  	contar=0;
		}else if(spy==0){	  
		   document.getElementById(idtexto).style.fontSize=ft+contar;
		   contar=0;
		}
   }
}
//|||||||| FIM AUMENTA E DIMINUE TEXTO ||||||||||||||||||


//||||||||||||||| MÁSCARA PARA VALORES EM GERAL ||||||||||||||||||||||||

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 if (sMask.charAt(i-1) == "a"){
		    return ((nTecla > 96) && (nTecla < 123));
       }else { // qualquer caracter...
          return true;
       }
    }
    else {
      return true;
    }
  }
  // EXEMPLO: onkeypress="return txtBoxFormat(this, 'AAA-9999', event);"
  
 //||||||||||||| FIM MÁSCARA PARA VALORES EM GERAL ||||||||||||||||||||||
  
 //|||||||||||||| MÁSCARA PARA VALORES MONETÁRIOS |||||||||||||||||||||||
 /**
 *
 * function currencyFormat(fld, milSep, decSep, e)
 *
 * fld    = Objeto a ser verficado.
 * milSep = Separador para milhar.
 * decSep = Separador para decimal.
 * e      = Evento.
 *
 * Formata um valor decimal conforme for digitado no box (Ex:1.234.566,00).
 * Criação: Anonima (coletada em http://http://www.scriptbrasil.com/?class=2&secao=javascript&categoria=Formulários&menu=javascript&ini=1
 * Revisao: pedro.leao@ig.com.br	2003/08/16
 * Exemplos:
 * <input type="text" name="test" length=15 onKeyPress="return(currencyFormat(this,'.',',',event))">
 * <input type="text" name="test2" length=15 onKeyPress="return(currencyFormat(this,'','.123',event))"> 
 *
 */
function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if (whichCode == 13) {
		return true;  // Enter
	}
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	len = fld.value.length;
	for(i = 0; i < len; i++) {
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)){
			 break;
		}
	}
	
	aux = '';
	for(; i < len; i++) {
		if (strCheck.indexOf(fld.value.charAt(i))!=-1){
			aux += fld.value.charAt(i);
		}
	}
	aux += key;
			
	len = aux.length;
	if (len == 0) {
		fld.value = '';
	} else if (len == 1) {
		fld.value = '0'+ decSep + '0' + aux;
	} else if (len == 2) {
		fld.value = '0'+ decSep + aux;
	} else if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--) {
			fld.value += aux2.charAt(i);
		}
		
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}
 //||||||||||||||||| FIM MÁSCARA PARA VALORES |||||||||||||||||||||||||||
 
 
/// ||||||||||||| PROIBE HOTMAIL ||||||||||||||||||||||||
var proibe= new Array();
var avisa= new Array();
proibe[0]="@hotmail.com"
avisa[0]="sim"
proibe[1]="--"
avisa[1]="sim"

//Obs: o array avisa,decide se um alerta será aberto "sim" ou "nao" avisando
// que o termo não pode ser usado, esse recurso é individual para cada termo
//Ex onkeyup="detecta_email('email_cli')"
function detecta_email(valor){    
   var anyString=document.getElementById(valor).value	   
	for(contar=0;contar<=proibe.length;contar++){
	   if(anyString.indexOf(proibe[contar])>-1){
		   if(avisa[contar]=="sim"){
	         alert('Desculpe! Não é aceito: '+ proibe[contar])
			}
		   document.getElementById(valor).value=""
	   }
	}
}

