// JavaScript Document

// Início do código de Aumentar/ Diminuir a letra
 
// Para usar coloque o comando: "javascript:mudaTamanho('tag_ou_id_alvo', -1);" para diminuir
// e o comando "javascript:mudaTamanho('tag_ou_id_alvo', +1);" para aumentar
 
var tagAlvo = new Array('p','li', 'td', 'div'); //pega todas as tags p//
 
// Especificando os possíveis tamanhos de fontes, poderia ser: x-small, small...
var tamanhos = new Array( '9px','10px','11px','12px','13px','14px','15px' );
var tamanhoInicial = 2;
 
function mudaTamanho( idAlvo,acao ){
  if (!document.getElementById) return
  var selecionados = null,tamanho = tamanhoInicial,i,j,tagsAlvo;
  tamanho += acao;
  if ( tamanho < 0 ) tamanho = 0;
  if ( tamanho > 6 ) tamanho = 6;
  tamanhoInicial = tamanho;
  if ( !( selecionados = document.getElementById( idAlvo ) ) ) selecionados = document.getElementsByTagName( idAlvo )[ 0 ];
  
  selecionados.style.fontSize = tamanhos[ tamanho ];
  
  for ( i = 0; i < tagAlvo.length; i++ ){
    tagsAlvo = selecionados.getElementsByTagName( tagAlvo[ i ] );
    for ( j = 0; j < tagsAlvo.length; j++ ) tagsAlvo[ j ].style.fontSize = tamanhos[ tamanho ];
  }
}


function mostraCaixa() {
	document.getElementById('mascara').style.display='block';
	document.getElementById('carrega_foto_amigo').style.display='block';
}
function escondeCaixa() {
	document.getElementById('mascara').style.display='none';
	document.getElementById('carrega_foto_amigo').style.display='none';
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- email inválido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é um campo de preenchimento obrigatório.\n'; }
  } if (errors) alert('Erro(s):\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function abre_print_e_email(url,janela,medidas) {
	window.open(url,janela,medidas);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function frmValidaAmigo(){
// variáveis
	var erro = '';
	nome = document.getElementById('nome')
	email = document.getElementById('email')
	amigoNome = document.getElementById('amigoNome')
	amigoEmail = document.getElementById('amigoEmail')
	mensagem = document.getElementById('mensagem')
	
	if((nome.value == '' || nome.value == ' ') && erro == 0){
		alert("Preencha o campo " + nome.title);
		nome.focus();
		erro = 1;
	}
		if((email.value == '' || email.value == ' ') && erro == 0){
		alert("Preencha o campo " + email.title);
		email.focus();
		erro = 1;
	}
	if((amigoNome.value == '' || amigoNome.value == ' ') && erro == 0){
		alert("Preencha o campo " + amigoNome.title);
		amigoNome.focus();
		erro = 1;
	}
	if((amigoEmail.value == '' || amigoEmail.value == ' ') && erro == 0){
		alert("Preencha o campo " + amigoEmail.title);
		amigoEmail.focus();
		erro = 1;
	}
		if((mensagem.value == '' || mensagem.value == ' ') && erro == 0){
		alert("Preencha o campo " + mensagem.title);
		mensagem.focus();
		erro = 1;
	}
	
	
	if(erro == 0){
		return true;
	} else {
		return false;
	}
}
function formataString(campo, mask, event) {
       key = event.keyCode;
       if(key=='0')
       key = event.which;


       if(key==8 || key==39 || key==37 || key==46 || key==9)
               return true;
       string = campo.value;
       i = string.length;

       var maskAux = '';
       k=0;
       for(a=0;a<mask.length;a++) {
               if(mask.charAt(a) == '§' || mask.charAt(a) == '!') {
                       if(campo.value.charAt(a)) {
                               maskAux += campo.value.charAt(k);
                       }
               }
               else if(mask.charAt(a) == '#') {
                       if(campo.value.charAt(a) && verificaNumero(campo.value.charAt(a))) {
                               maskAux += campo.value.charAt(k);
                       }
               }
               else {

                       if(campo.value.charAt(a) && campo.value.charAt(a) == mask.charAt(a)) {
                               maskAux += mask.charAt(a);
                       }
                       else if(campo.value.charAt(a)) {
                               maskAux += mask.charAt(a);
                               k--;
                       }
               }
               k++;
       }
       if (i < mask.length) {
               if (mask.charAt(i) == '#') {
                       if(!verificaNumeroPress(campo,event))
                       {
                               return false;
                       }
                       maskAux += String.fromCharCode(key);
                       /*if(mask.charAt(i+1) != '!' && mask.charAt(i+1) != '§' && mask.charAt(i+1) != '#') {
                         maskAux += mask.charAt(i+1);
                       } */
                       var a = i+1;
                       while(a<mask.length && mask.charAt(a) != '!' && mask.charAt(a) != '§' && mask.charAt(a) != '#') {
                               maskAux += mask.charAt(a);
                               a++
                       }
               }
               else if(mask.charAt(i) == '!' || mask.charAt(i) == '§') {

                       maskAux += String.fromCharCode(key);
                       var a = i+1;
                       while(a<mask.length && mask.charAt(a) != '!' && mask.charAt(a) != '§' && mask.charAt(a) != '#') {
                               maskAux += mask.charAt(a);
                               a++
                       }
                       
               }
               else {
										if(mask.charAt(i)==String.fromCharCode(key)) {
										maskAux += String.fromCharCode(key);
										var a = i+1;
										while(a<mask.length && mask.charAt(a) != '!' && mask.charAt(a) != '§' && mask.charAt(a) != '#') {
											maskAux += mask.charAt(a);
											a++
											}
										}
                       else if((i+1)<mask.length && mask.charAt(i+1) == "#") {
                               if(verificaNumeroPress(campo,event)) {
                                       maskAux += mask.charAt(i) + String.fromCharCode(key);
                               }
                       }
                       else if((i+1)<mask.length && (mask.charAt(i+1) == "§" ||mask.charAt(i+1) == "!" )) {
                               maskAux += mask.charAt(i) + String.fromCharCode(key);
                       }
               }
               campo.value=maskAux;
               try {
///event.keyCode = 0;
			event.preventDefault();
		}
		catch (e) {
//event.charCode = 0;
			event.returnValue = false;
		}

	}
	else return false;
}

function verificaNumeroPress(campo,event) {
code = event.keyCode;
if(code=='0') {
code = event.charCode;
}

codeAux = 0;
if(arguments[2]) {
codeAux = arguments[2].charCodeAt(0);
}

if ( (code < 48 && code != codeAux && code != 8 && code!=39 && code!=37 && code != 9 && code != 46) || (code > 57 ) ) {
try {
///event.keyCode = 0;
event.preventDefault();
}
catch (e) {
//event.charCode = 0;
event.returnValue = false;
}
return false;

}
else {
return true;
}
}
function verificaNumero(valor) {
code = valor.charCodeAt(0);
if ( (code < 48 ) || (code > 57 ) ) {
return false;
}
return true;
}

//-->
