function validaNews(){
		if(nomecampo('Nome').value=='' || nomecampo('Nome').value=='seu nome'){
			alert('Preencha o campo Nome');
			nomecampo('Nome').focus();
			return false;
			
		}
		if(nomecampo('Email').value=='' || nomecampo('Email').value=='seu e-mail'){
			alert('Preencha o campo Email');
			nomecampo('Email').focus();
			return false;
			
		}
		if(!validaFormatos(nomecampo('Email').value,'email')){
			alert('Preencha o campo Email corretamente');
			nomecampo('Email').focus();
			return false;
			
		}
		return true;
	}
function validaAmigo() {	
  if (nomecampo('seunome').value == '' || nomecampo('seunome').value == '› seu nome:' ) {
	alert('Por favor informe seu Nome.');
	nomecampo('seunome').focus();
	return false;
 }
  if (nomecampo('seuemail').value == '' || nomecampo('seuemail').value.indexOf("@") == -1 || nomecampo('seuemail').value.indexOf(".") == -1) {
	alert('Por favor informe um Email válido.');
	nomecampo('seuemail').focus();
	return false;
 }
  if (nomecampo('nomeamigo').value == '' || nomecampo('nomeamigo').value == '› nome do amigo:' ) {
	alert('Por favor informe o Nome de seu Amigo.');
	nomecampo('nomeamigo').focus();
	return false;
 }
  if (nomecampo('emailamigo').value == '' || nomecampo('emailamigo').value.indexOf("@") == -1 || nomecampo('emailamigo').value.indexOf(".") == -1) {
	alert('Por favor informe um Email válido.');
	nomecampo('emailamigo').focus();
	return false;
 }

 }
function enviaNewsletter(nome,email){
	
	httpRequest('newsletterAcao.php?email='+email+'&nome='+nome, 'escreveNewsletter');
}
function escreveNewsletter(resposta){
	if(resposta=="true"){
			alert('Cadastro realizado com sucesso!');
			nomecampo('Nome').value='seu nome';
			nomecampo('Email').value='seu e-mail';
			
	}else{
			alert('Houve um erro no cadastro, tente novamente mais tarde.');
	}
}
function trim(str){
	return str.replace(/^\s+|\s+$/g, '');
}
function validaFormatos(str,formato){
            var objER;
			switch (formato){
				case 'cep':
					objER = /^[0-9]{5}-[0-9]{3}$/;
					break;
				case 'telefone':
					objER = /[(]\d{2}[)]\s{1}\d{4}[-]\d{4}/;
					break;
				case 'cpf':
					objER = /^[0-9]{3}.[0-9]{3}.[0-9]{3}-[0-9]{2}$/;
					break;
				case 'cnpj':
					objER = /^[0-9]{2}.[0-9]{3}.[0-9]{3}[\/][0-9]{4}.[0-9]{2}$/;				
					break;
				case 'email':
					objER = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$/ ;
					break;				
			}
			str = str.replace(/^\s+|\s+$/g, '')
            if(str.length > 0) {
                    if(objER.test(str)){
                        return true;
					}else{
                        return false;
					}
             }else{
                return false;
       		 }
}
function nomecampo(id)
{
	return document.getElementById(id)
}
function httpRequest(strUrl, strFnc)
{

	if (window.XMLHttpRequest) {
		objReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		objReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	objReq.open("GET", strUrl, true);
	objReq.send(null);
	if (strFnc != "") {
		objReq.onreadystatechange = function() 
		{
			if (objReq.readyState == 4)
			{
				eval(strFnc + '(objReq.responseText)');
			}
		};
	}
}

function validaForm(frm, excecoes, validados)
{
	printConfig(frm)
	
	Array.prototype.busca = function busca(txt)
	{
		var i
		for(i = 0; i < this.length; i++)
		{
			if(this[i] == txt)
				return true
		}
		return false
	}
	
	if(excecoes)
		excecoes = excecoes.split(',')
	else
		excecoes = new Array()
		
	if(validados)
		validados = validados.split(',')
	else
		validados = new Array()
	
	for(i = 0; i < frm.length; i++)
	{
		obj = frm.elements[i]
		
		if(excecoes.length > 0)
		{
			if(!excecoes.busca(obj.name))
			{
				if(!tagName(obj))
					return false
			}
		}
		else if(validados.length > 0)
		{
			if(validados.busca(obj.name))
			{
				if(!tagName(obj))
					return false
			}
		}
		else
		{
			if(!tagName(obj))
				return false
		}
	}
	return true
}

function tagName(obj)
{
	if(obj.name.substr(0,5).toLowerCase() == 'email')
	{
		if(!validaEmail(obj))
		{
			return false
		}
	}
	else if(obj.name.substr(0,8).toLowerCase() == 'telefone')
	{
		if(!validaTelefone(obj))
		{
			return false
		}
	}
	else if(obj.name.substr(0,4).toLowerCase() == 'data')
	{
		if(!validaData(obj))
		{
			alert('O campo ' + obj.name + ' está incorreto.')
			obj.focus()
			return false
		}
	}
	
	switch(obj.tagName)
	{
		case 'SELECT':
			if(obj.value == '')
			{
				obj.focus()
				alert('Selecione o campo ' + obj.name)
				return false
			}
			return true
			break
		case 'TEXTAREA':
			if(obj.value == '')
			{
				obj.focus()
				alert('Preencha o campo ' + obj.name)
				return false
			}
			return true
			break
		case 'INPUT':
			return Input(obj)
			break
	}
}

function Input(obj)
{
	switch(obj.type)
	{
		case "hidden":
		case "image":
		case "button":
			return true
			break
		case "file":
			if(obj.value == '')
			{
				obj.focus()
				alert('Selecione um Arquivo' )
				return false
			}
			return true
			break
		case "text":
			if(obj.value == '')
			{
				obj.focus()
				alert('Preencha o campo ' + obj.name)
				return false
			}
			return true
			break
		case "checkbox":
			var checkbox = document.getElementsByName(obj.name)
			var i, checked = 0
			for(i = 0; i < checkbox.length; i++)
			{
				if(checkbox[i].checked)
					checked = 1
			}
			if(checked == 0)
			{
				obj.focus()
				alert('Selecione o campo ' + obj.name)
				return false
			}
			else
				return true
			break
		case "radio":
			var radio = document.getElementsByName(obj.name)
			var i, checked = 0
			for(i = 0; i < radio.length; i++)
			{
				if(radio[i].checked)
					checked = 1
			}
			if(checked == 0)
			{
				obj.focus()
				alert('Selecione o campo ' + obj.name)
				return false
			}
			else
				return true
			break
		default:
			return true
			break
	}
}

function printConfig(frm)
{
	Array.prototype.busca = function busca(txt)
	{
		var i
		for(i = 0; i < this.length; i++)
		{
			if(this[i] == txt)
				return true
		}
		return false
	}
	var printConfig = Array()
	if(frm.print_config)
	{
		for(i = 0; i < frm.length; i++)
		{
			if(frm.elements[i].tagName == 'INPUT')
			{
				if(frm.elements[i].type != 'hidden')
				{
					if(!printConfig.busca(frm.elements[i].name))
					{
						printConfig.push(frm.elements[i].name)
					}
				}
			}
			else
			{
				if(!printConfig.busca(frm.elements[i].name))
				{
					printConfig.push(frm.elements[i].name)
				}
			}
		}
		frm.print_config.value = printConfig.toString()
	}
}


function validaEmail(campo)
{   
	if (!ConsisteEmail(campo.value)  && campo.value != '')
	{
		alert("Favor Digitar o Email Corretamente.");
		campo.focus();
		return false
	}
	return true
}

function ConsisteEmail(valor) 
{
	var reg = /\w{1,}[@]\w{1,}[.]\w{1,}/
	return reg.test(valor);
}

function validaTelefone(campo)
{
	var reg = /[(]\d{2}[)]\s{1}\d{4}[-]\d{4}/
	
	if (!reg.test(campo.value)  && campo.value != '')
	{
		alert("O campo " + campo.name + " está em um formato incorreto.");
		campo.focus();
		return false
	}
	return true
}

function validaData(campo)
{
	
	var reg = /\d{2}[\/]\d{2}[\/]\d{4}/
	
	if(!reg.test(campo.value) && campo.value != '')
		return false
	
	
	dia = parseInt(campo.value.substr(0,2))
	mes = parseInt(campo.value.substr(3,2))
	ano = parseInt(campo.value.substr(6,4))
	
	data = new Date()
	dias = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
	if(data.getFullYear() % 4 == 0)
		dias[1] = 29
				
	if(mes < 1 || mes > 12)
		return false
		
	if(dia < 1 || dia > dias[mes - 1])
		return false
		
	return true
}


function formatar(src,mask,validador,somenteNumero,e)
{
	var tecla = (e.keyCode) ? e.keyCode : e.charCode
	if(tecla != 8)
	{
		string = src.value
		aux = ''
		
		if(string == '') return
		
		if(somenteNumero == 's')
		{
			string = string.replace(/\D/gi,'')
		}
		
		val = mask.replace(validador,'')
		for(i = 0; i < val.length; i++)
		{
			string = string.replace(val.charAt(i),'')
		}
		
		mask = mask.split('')
		string = string.split('')
		
		v = Array(mask.length)
		pV = 0
		pString = 0
		
		for (pMask = 0; pMask < mask.length; pMask++)
		{
			if(mask[pMask] != validador)
			{
				v[pV] = mask[pMask]
				pV++
			}
			else
			{
				v[pV] = string[pString]
				pV++
				pString++
			}
			
			if(pString > string.length)
				break
		}
	
		src.value = v.join('')
	}
}





