// JavaScript Document
function aumentafonte(tag) {
   var p = document.getElementsByTagName(tag);
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function diminuifonte(tag) {
   var p = document.getElementsByTagName(tag);
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function validaForm(f) {
	required = $('.required'); // seleciona campos com class required
	// inicia verificacao de campos requeridos
	i=0;
	while (i < required.length) {
		
		if (required[i].value == '' || required[i].value == '0' || required[i].value == null) {
		 	var title = $(required[i]).attr('title'); 
			
			alert(title);
			
			$(required[i]).addClass('error');
			$('.loading-submit').hide();
			required[i].focus();
			return (false);
			break;
		}
		i++;
	}	
	// fim de verificacao de campos requeridos
	
	// testa email
	if ($('.email').length > 0) {

		email = $('.email').attr('value');
		if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
			alert("Você precisa inserir um e-mail válido");
			$('.email').addClass('error');
			$('.loading-submit').hide();
			$('.email').focus();
			return false;
		}
		//alert('tudo ok');
		return true;
	}

	//tudo ok
	return true;
}

//retorna a cor original dos campos do formulário
function OriColor(ObjCampo){
	ObjCampo.style.background="#ffffff";
	ObjCampo.style.borderColor = "#999999";
	return(false);
}

//Somente numeros
function isNumber(field) {
	var re = /^[0-9-'.'-',']*$/;
	if (!re.test(field.value)) {
		//alert('Value must be all numberic charcters. Non numerics will be removed from field!');
		field.value = field.value.replace(/[^0-9-'.'-',']/g,"");
	}
}

function isNumberKey(evt)
  {
	 var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	 return true;
  }

//Somente Alfanumericos
function noNumbers(which) {
	if (/[^a-z\s&]/gi.test(which.value)) {
		//alert ("Only alpha characters are valid in this field");  // no spaces, full stops or anything but A-Z
		which.value = "";
		which.focus();
		return false;
	}
}

$( function(){
	
	//limpa formulario
	$.fn.clearForm = function() {
		return this.each(function() {
		  var type = this.type, tag = this.tagName.toLowerCase();
		  if (tag == 'form')
			return $(':input',this).clearForm();
		  if (type == 'text' || type == 'password' || tag == 'textarea' || type == 'file')
			this.value = '';
		  else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		  else if (tag == 'select')
			this.selectedIndex = 0;
		});
	};


});

