/*
funções em Ajax para controle do Admin
*/

function getAjax()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}else if(window.ActiveXObject){
	      	try {
			var ajax=new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			var ajax=new ActiveXObject("Msxml2.XMLHTTP");
			}
		}else{
		  alert('Seu browser n&atilde;o tem suporte ao XMLHttpRequest');
		}
		return ajax;
}

function mudaPagina(caminho, parametros)
{
	if(!div)
	{
		var div='conteudo';

	}

	// se existe a div msg
	if(document.getElementById('msg'))
	{
		// limpa o conteudo dela
		limpaErros();
	}

	//
	var ajax=getAjax();
	ajax.open('POST', caminho, true);
	ajax.onreadystatechange = function(){
		if (ajax.readyState == 4)
		{
			document.getElementById(div).innerHTML=ajax.responseText;
		}else{
			document.getElementById(div).innerHTML= "<div class='titulo'>Aguarde, processando informa&ccedil;&otilde;es...</div>";
		}
	}

	parametros=setaParametros(parametros);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.send(parametros);
	return;

}

function mudaPaginaDiv(caminho, parametros, div)
{
	var ajax=getAjax();
	ajax.open('GET', caminho, true);
	ajax.onreadystatechange = function(){
		if (ajax.readyState == 4)
		{
			document.getElementById(div).innerHTML=ajax.responseText;
		}else{
			document.getElementById(div).innerHTML= "<div class='titulo'>Aguarde, processando informa&ccedil;&otilde;es...</div>";
		}
	}

	parametros=setaParametros(parametros);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.send(parametros);
	return;

}

function mudaPaginaDiv2(caminho, parametros, div)
{
	var ajax=getAjax();
	ajax.open('POST', caminho, true);
	ajax.onreadystatechange = function(){
		if (ajax.readyState == 4)
		{
			document.getElementById(div).innerHTML=ajax.responseText;
		}else{
			document.getElementById(div).innerHTML= "<div class='titulo'>Aguarde, processando informa&ccedil;&otilde;es...</div>";
		}
	}

	parametros=setaParametros(parametros);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.send(parametros);
	return;

}


function ativarDesativar(caminho, alvo, cod, ativa_desativa)
{

	var div=cod;

	//
	var ajax=getAjax();
	ajax.open('POST', caminho, true);
	ajax.onreadystatechange = function(){
		if (ajax.readyState == 4)
		{
			if(ativa_desativa=='ativa')
			{
				document.getElementById(div).innerHTML='<a href="javascript:;" class="menu2" onclick="ativarDesativar(\'AtivarDesativar.php\', \'medico\',\''+cod+'\', \'desativa\')">Ativo</a>';

			}else if(ativa_desativa=='desativa'){

				document.getElementById(div).innerHTML='<a href="javascript:;" class="menu2" onclick="ativarDesativar(\'AtivarDesativar.php\', \'medico\',\''+cod+'\', \'ativa\')">Inativo</a>';

			}
		}
	}

	parametros = 'alvo='+alvo+'&ativa_desativa='+ativa_desativa+'&cod_'+alvo+'='+cod;
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.send(parametros);
	return;

}


function resetaCont()
{

	document.getElementById('cont').value = 1;

}

function mudaCor(id, cor)
{
	//alert(id);
	document.getElementById(id).setAttribute('bgcolor',cor);


}

//n&atilde;o usada
function addEvent(object, evType, func, useCapture)
{
    if(object.addEventListener)
    {
        object.addEventListener(evType, func, useCapture);
    } else
    if(object.attachEvent)
    {
        object.attachEvent("on" + evType, func);
    }
}

// n&atilde;o usada
function destacaLinha(objeto)
{
	if(window.addEventListener)
    {
        objeto.addEventListener("mouseover", function() { alert("Página carregada."); }, false);
    } else{
        objeto.attachEvent("onmouseover", function() { alert("Página carregada."); });
    }

	objeto.addEventListener('mouseover')

}

function criaCampoEventoNoticia(evento_noticia, titulos, codigos)
{

	document.getElementById('cont_'+evento_noticia).value++;
	var numero = Number(document.getElementById('cont_'+evento_noticia).value);
	var linha = document.getElementById('tabela_'+evento_noticia).insertRow(document.getElementById('tabela_'+evento_noticia).rows.length);
	linha.id = 'l'+evento_noticia+numero;
	var linha2 = document.getElementById('tabela_'+evento_noticia).insertRow(document.getElementById('tabela_'+evento_noticia).rows.length);
	linha2.id = 'le'+evento_noticia+numero;
	linha2.setAttribute('height','8');
	var coluna0 = linha.insertCell(0);
	coluna0.setAttribute('align','left');
	coluna0.setAttribute('width','300');
	coluna0.className = 'menu2';
	//coluna0.innerHTML = evento_noticia+' '+numero+': ';
	var coluna1 = linha.insertCell(1);
	coluna1.setAttribute('width','10');
	coluna1.innerHTML = ' ';
	var coluna2 = linha.insertCell(2);
	//coluna2.setAttribute('width','10');

	var excluir = document.createElement('a');
	excluir.className = 'menu2';
	excluir.id = evento_noticia+numero;
	excluir.innerHTML = 'Excluir';
	excluir.style.cursor="pointer";

	excluir.onclick = function(){
		if(evento_noticia=='eventos')
		{
			document.getElementById('tabela_eventos').deleteRow(document.getElementById('l'+this.id).rowIndex);
			document.getElementById('tabela_eventos').deleteRow(document.getElementById('le'+this.id).rowIndex);
			//document.getElementById('cont_eventos').value--;numero--;
		}else{
			document.getElementById('tabela_noticias').deleteRow(document.getElementById('l'+this.id).rowIndex);
			document.getElementById('tabela_noticias').deleteRow(document.getElementById('le'+this.id).rowIndex);
			}
		}
	coluna2.appendChild(excluir);

	var lista = document.createElement('select');
	lista.id = (evento_noticia+numero);
	lista.className = 'input_lista';

	var i = 0;

	var opcao=document.createElement('option');
	opcao.text = 'Escolha uma opção';

	opcao.value = '0';
	try
	{
		lista.add(opcao,null); // standards compliant
	}
 	catch(ex)
	{
		lista.add(opcao); // IE only
	}
	coluna1.appendChild(lista);

	for(i=0;i<=titulos.length-1;i++)
	{
		var opcao=document.createElement('option');
		opcao.value = codigos[i];
		opcao.text = titulos[i];
		//alert(opcao.value);
		//opcao.setAttribute('id',codigos[i]);
		opcao.value = codigos[i];
		try
		{
			lista.add(opcao,null); // standards compliant
		}
	 	catch(ex)
		{
			lista.add(opcao); // IE only
		}
		coluna0.appendChild(lista);
	}
	return numero;
}


function criaCampoTratamentos()
{

	var numero = Number(document.getElementById('cont').value);
	//alert('numero: '+numero);
	document.getElementById('cont').value = Number(numero+1);
	//alert('cont recebe: '+document.getElementById('cont').value);

	var linha = document.getElementById('tabela').insertRow(0);
	//var espaco = linha.insertCell(0);
	var coluna = linha.insertCell(0);

	// CAMPO SELECT
	var campo=document.createElement('select');

	//var nome = "tratamento"+numero;
	campo.name = 'tratamentos'+numero;
	campo.id = 'tratamentos'+numero;
	campo.className = 'input_padrao';
	//alert(campo.id);
	//OPÇÃO 1 - SELECIONE UMA OPÇÃO
	var opcao1 = document.createElement('option');
	opcao1.value = '';
	opcao1.text = '';
	try
	{
  		campo.add(opcao1,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao1); // IE only
  	}


	//OPÇÃO 2 - CÂNCER DE PELE
	var opcao2 = document.createElement('option');
	opcao2.value = '1';
	opcao2.text = 'Câncer de Pele';
	try
	{
  		campo.add(opcao2,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao2); // IE only
  	}


	//OPÇÃO 3 - CELULITE
	var opcao3 = document.createElement('option');
	opcao3.value = '2';
	opcao3.text = 'Celulite';
	try
	{
  		campo.add(opcao3,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao3); // IE only
  	}


	//OPÇÃO 4 - CICATRIZ DE ACNE
	var opcao4 = document.createElement('option');
	opcao4.value = '3';
	opcao4.text = 'Cicatriz de Acne';
	try
	{
  		campo.add(opcao4,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao4); // IE only
  	}


	//OPÇÃO 5 - CONTORNO CORPORAL
	var opcao5 = document.createElement('option');
	opcao5.value = '4';
	opcao5.text = 'Contorno Corporal';
	try
	{
  		campo.add(opcao5,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao5); // IE only
  	}


	//OPÇÃO 6 - ESTRIAS
	var opcao6 = document.createElement('option');
	opcao6.value = '5';
	opcao6.text = 'Estrias';
	try
	{
  		campo.add(opcao6,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao6); // IE only
  	}


	//OPÇÃO 7 - FLACIDEZ CORPORAL
	var opcao7 = document.createElement('option');
	opcao7.value = '6';
	opcao7.text = 'Flacidez Corporal';
	try
	{
  		campo.add(opcao7,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao7); // IE only
  	}


	//OPÇÃO 8 - FLACIDEZ FACIAL
	var opcao8 = document.createElement('option');
	opcao8.value = '7';
	opcao8.text = 'Flacidez Facial';
	try
	{
  		campo.add(opcao8,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao8); // IE only
  	}


	//OPÇÃO 9 - GORDURA LOCALIZADA
	var opcao9 = document.createElement('option');
	opcao9.value = '8';
	opcao9.text = 'Gordura Localizada';
	try
	{
  		campo.add(opcao9,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao9); // IE only
  	}


	//OPÇÃO 10 - LESÕES VASCULARES
	var opcao10 = document.createElement('option');
	opcao10.value = '9';
	opcao10.text = 'Lesões Vasculares';
	try
	{
  		campo.add(opcao10,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao10); // IE only
  	}


	//OPÇÃO 11 - OLHEIRAS
	var opcao11 = document.createElement('option');
	opcao11.value = '10';
	opcao11.text = 'Olheiras';
	try
	{
  		campo.add(opcao11,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao11); // IE only
  	}


	//OPÇÃO 12 - PSORÍASE E VITILIGO
	var opcao12 = document.createElement('option');
	opcao12.value = '11';
	opcao12.text = 'Psoríase e Vitiligo';
	try
	{
  		campo.add(opcao12,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao12); // IE only
  	}


	//OPÇÃO 13 - REJUVENECIMENTO
	var opcao13 = document.createElement('option');
	opcao13.value = '12';
	opcao13.text = 'Rejuvenescimento';
	try
	{
  		campo.add(opcao13,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao13); // IE only
  	}


	//OPÇÃO 14 - REMOÇÃO DE MANCHAS
	var opcao14 = document.createElement('option');
	opcao14.value = '13';
	opcao14.text = 'Remoção de Manchas';
	try
	{
  		campo.add(opcao14,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao14); // IE only
  	}


	//OPÇÃO 15 - REMOÇÃO DE PÊLOS
	var opcao15 = document.createElement('option');
	opcao15.value = '14';
	opcao15.text = 'Remoção de Pêlos';
	try
	{
  		campo.add(opcao15,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao15); // IE only
  	}


	//OPÇÃO 16 - REMOÇÃO DE TATUAGENS
	var opcao16 = document.createElement('option');
	opcao16.value = '15';
	opcao16.text = 'Remoção de Tatuagens';
	try
	{
  		campo.add(opcao16,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao16); // IE only
  	}


	//OPÇÃO 17 - ROSÁCEA
	var opcao17 = document.createElement('option');
	opcao17.value = '16';
	opcao17.text = 'Rosácea';
	try
	{
  		campo.add(opcao17,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao17); // IE only
  	}


	//OPÇÃO 18 - RUGAS
	var opcao18 = document.createElement('option');
	opcao18.value = '17';
	opcao18.text = 'Rugas';
	try
	{
  		campo.add(opcao18,null); // standards compliant
  	}
	catch(ex)
  	{
  		campo.add(opcao18); // IE only
  	}

	coluna.appendChild(campo);

	return numero;

}


function criaCampoImagem()
{

	var limite = 5;
	var numero = Number(document.getElementById('cont').value);

	if(numero  < 5)
	{
		if(navigator.appVersion.indexOf('MSIE 7.0')!==-1)
		{

			var numero = Number(document.getElementById('cont').value);
			document.getElementById('tabela').innerHTML += "<table height='100%' width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td height='8'></td></tr><tr><td width='14'></td><td><input type='file' name='imagem"+numero+"' id='imagem"+numero+"' class='bt_arquivo' /></td><td></td></tr></table>";

		}else{
			//alert('n&atilde;o é ie7 - '+navigator.appVersion.indexOf('MSIE 7.0'));
			var espaco = document.createElement('tr');
			var coluna_espaco = document.createElement('td');
			var linha = document.createElement('tr');
			var coluna1 = document.createElement('td');
			var coluna_meio = document.createElement('td');
			var coluna2 = document.createElement('td');
			var campo=document.createElement('input');
			var numero = Number(document.getElementById('cont').value);
			var nome = "imagem"+numero;

			//alert(nome);

			campo.setAttribute('type','file');
			campo.setAttribute('name','imagem'+numero);
			campo.setAttribute('id','imagem'+numero);
			campo.setAttribute('class','bt_arquivo');
			coluna_espaco.setAttribute('height', '8');

			document.getElementById('tabela').appendChild(espaco);
			document.getElementById('tabela').appendChild(linha);

			espaco.appendChild(coluna_espaco);
			linha.appendChild(coluna1);
			linha.appendChild(coluna_meio);
			linha.appendChild(coluna2);
			coluna_meio.appendChild(campo);


		}
		document.getElementById('cont').value = numero+1;
		return numero;
	}else{
		return erro('Voc&ecirc; n&atilde;o pode inserir mais do que 5 imagens.','Imagem');
	}
}


function valorRadio(radio_group)
{

	var valor_opcao = "";
	if(radio_group != null)
	{
		var len = radio_group.length;

	}else{
		return 0;

	}
	var i;

	for (i = 0; i <len; i++)
	{
		if (radio_group[i].checked)
		{
			valor_opcao = radio_group[i].value;
		}
	}

	return valor_opcao;

}

function setaParametros(parametros)
{
	if(parametros!==null)
	{
		var i;
		var caracter = null;

		for(chave in parametros)
		{
			if(caracter!==null)
			{
				retorno += caracter+chave+'='+parametros[chave];
			}else{
				var retorno;
				retorno = chave+'='+parametros[chave];
			}
			caracter = '&';
		}
	}else{
		return null;
	}
	return retorno;
}

function Trim(strTexto)
{
    return strTexto.replace(/^\s+|\s+$/g, '');
}

function limpaErros()
{
	document.getElementById('msg').innerHTML = "";
	return;
}

function validaNoticia()
{
	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('titulo_noticia').value, 'Por favor, digite o título da notícia.', 'Título');
	erros[1] = preenchido(document.getElementById('autor_noticia').value, 'Por favor, digite o autor da notícia', 'Autor');
	erros[2] = preenchido(document.getElementById('texto_noticia').value, 'Por favor, digite o corpo da notícia', 'Texto');

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}
}


function setaListaEventosNoticias(eventos_noticias)
{
	var i = 0;
	var resultado;
	for (i=0;i<=document.getElementById('cont_'+eventos_noticias).value;i++)
	{
		if(document.getElementById(eventos_noticias+i))
		{
			if(document.getElementById(eventos_noticias+i).value!=='')
			{
				if(i==1)
				{
					resultado = document.getElementById(eventos_noticias+i).value;

				}else{
					resultado += '-'+document.getElementById(eventos_noticias+i).value;
				}
			}
		}
	}
	//alert('total de '+eventos_noticias+': '+document.getElementById('cont_'+eventos_noticias).value);
	//alert('Resultado: '+resultado);
	return resultado;

}


function validaNewsletter()
{

	var retorno = new Array();
	retorno[0] = setaListaEventosNoticias('eventos');
	retorno[1] = setaListaEventosNoticias('noticias');

	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('titulo_newsletter').value, 'Por favor, digite o título da newsletter.', 'Título');
	erros[1] = preenchido(document.getElementById('texto_newsletter').value, 'Por favor, digite o texto da newsletter.', 'Texto');

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return retorno;
	}
}


function validaVisitante()
{
	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('nome_visitante').value, 'Por favor, digite o seu nome.', 'Nome');
	erros[1] = isEmail(document.getElementById('email_visitante').value, "Por favor, digite um endereço de e-mail válido.", "E-Mail");

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}

}

function validaMedico()
{
	var i;
	var tratamentos = new String();
	for (i=0;i<document.getElementById('cont').value;i++)
	{
		//alert(document.getElementById('cont').value);
		//alert(document.getElementById('tratamentos'+i).value);
		if(document.getElementById('tratamentos'+i).value!=='')
		{
			if(i==0)
			{
				//alert(document.getElementById('tratamentos'+i).value);
				tratamentos = document.getElementById('tratamentos'+i).value;
			}else{

				tratamentos += '-'+document.getElementById('tratamentos'+i).value;

			}
		}
	}

	limpaErros();
	var erros = new Array();

	erros[0] = preenchido(document.getElementById('nome_medico').value, 'Por favor, digite o nome.', 'Nome');
	erros[1] = isNum(document.getElementById('crm').value, 'Por favor, digite um n&uacute;mero v&aacute;lido de CRM.', 'CRM');
	erros[2] = preenchido(document.getElementById('especialidade').value, 'Por favor, digite qual a especialidade.', 'Especialidade');
//	erros[3] = verificaRadio(valorRadio(document.getElementsByName('area_interesse')), '&Aacute;rea de Interesse.');
//	erros[3] = isNum(document.getElementById('sexo').value, 'Por favor, selecione o sexo.');
	erros[4] = true; // validar tratamentos??
	erros[5] = preenchido(document.getElementById('endereco').value, 'Por favor, digite o endere&ccedil;o.', 'Endere&ccedil;o');
	erros[6] = preenchido(document.getElementById('cidade').value, 'Por favor, digite o bairro.', 'Bairro');
	erros[7] = preenchido(document.getElementById('cidade').value, 'Por favor, digite a cidade.', 'Cidade');
	erros[8] = preenchido(document.getElementById('estado').value, 'Por favor, indique o estado.', 'Estado');
	erros[9] = isTelefone(document.getElementById('tel_comercial').value, 'O n&uacute;mero do telefone comercial n&atilde;o parece válido.', 'Telefone Comercial');
//	erros[10] = isTelefone(document.getElementById('tel_celular').value, 'O n&uacute;mero do telefone celular n&atilde;o parece válido.', 'Telefone Celular');
	erros[11] = isTelefone(document.getElementById('cep').value, 'O n&uacute;mero do CEP n&atilde;o parece v&aacute;lido.', 'CEP');
//	erros[12] = isEmail(document.getElementById('email').value, 'O endere&ccedil;o de email n�o parece v&aacute;lido.', 'E-Mail');

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		//alert(tratamentos);
		return tratamentos;
	}

	return tratamentos;
}

function validaEvento()
{
	limpaErros();
	var erros = new Array();

	erros[0] = preenchido(document.getElementById('titulo_evento').value, 'Por favor, digite o nome do evento.', 'Nome do Evento');
	erros[1] = isData(document.getElementById('data_evento').value);
	erros[2] = preenchido(document.getElementById('hora_evento').value, 'Por favor, digite o horário do evento.', 'Hora');
	erros[3] = preenchido(document.getElementById('descricao_evento').value, 'Por favor, digite a descri��o do evento.', 'Descri��o');


	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}
}
function isNum(str, msg, nome)
{
	if(str.length > 5)
	{
		erro('O n�mero do CRM deve ter exatamente 5 d�gitos.', nome);
		return false;

	}
	var VBlnIsNum;
	VIntTam = str.length;
	VBlnIsNum = true;
	if (VIntTam == 0)
	{
		erro(msg,nome);
		return false;
	}
	else
	{
		for (i=0; i < VIntTam; i++)
		{
			if (str.substring(i,i+1) < '0' || str.substring(i,i+1) >'9')
			{
				VBlnIsNum = false;
			}
		}
		return VBlnIsNum;
	}
}

function isValorLista(valor, nome)
{
	if(valor=='')
	{
		erro('Selecione uma das opções', nome);
		return false;
	}else{
		return true;
	}
}

function verificaRadio(valor, nome)
{

	if (valor == false || valor =="" || valor ==0)
	{
		erro('Por favor, selecione uma opção.', nome);
		return false;

	}
	else {
		return true;

	}
}


function validaUsuario()
{
	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('nome').value, "Por favor, digite o nome do usuario.", "Nome");
	erros[1] = isEmail(document.getElementById('email').value, "Por favor, digite um endereço de e-mail válido.", "E-Mail");
	erros[2] = preenchido(document.getElementById('login').value, "Por favor, digite o login do usuário", "Login");
	erros[3] = validaSenhas(document.getElementById('senha_1'), document.getElementById('senha_2'));
	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}
}

function validaContato()
{
	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('nome').value, 'Por favor, digite o seu nome.', 'Nome');
	erros[1] = isEmail(document.getElementById('email').value, 'Por favor, digite um endereço de e-mail válido.', 'E-Mail');
	erros[2] = isValorLista(document.getElementById('area').value, 'Área');

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}
}

function validaEdicaoUsuario(cod)
{
	limpaErros();
	var erros = new Array();
	erros[0] = preenchido(document.getElementById('nome').value, 'Por favor, digite o nome do usuário.', 'Nome');
	erros[1] = isEmail(document.getElementById('email').value, 'Por favor, digite um endereço de e-mail válido.', 'E-Mail');
	erros[2] = preenchido(document.getElementById('login').value, 'Por favor, digite o login do usuário', 'Login');

	var procura = array_search(erros, false);
	if(procura!==false)
	{
		return false;
	}else{
		return true;
	}
}

function array_search (array,val)
{
	for (var i = 0; i < array.length; i++)
	{
		if (array[i] == val)
		{
			return i;
		}
	}
	return false;
}

function validaSenhas(senha_1, senha_2)
{
	if(senha_1.value == '' || senha_2.value == '')
	{
		erro('Por favor, digite a senha e confirme-a.', 'Senha');
		senha_1.value='';
		senha_2.value='';
		return false;
	}else{
		if(senha_1.value == senha_2.value)
		{
			return true;
		}else{
			erro('Os campos de senha informadas n&atilde;o coincidem. Por favor, digite novamente.', 'Senha');
			senha_1.value='';
			senha_2.value='';
			return false;
		}
	}
}

function isData(data)
{

	var objER = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/?(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

	if(data.length>0){

		if(objER.test(data))
		{
			return true;
		}else{
			erro('Essa n&atilde;o é uma data v&aacute;lida.', 'Data do Evento');
			return false;
		}

	}else{
		erro('Por favor, digite a data do evento.', 'Data do Evento');
		return false;
	}
}




function isHora(hora)
{

	var objER = /^([0-1]\d|2[0-3]):[0-5]\d$/;

	if(hora.length>0){

		if(objER.test(hora))
		{
			return true;
		}else{
			erro('Essa n&atilde;o é uma hora v&aacute;lida.', 'Hora');
			return false;
		}

	}else{
		erro('Por favor, digite a hora do evento.', 'Hora');
		return false;
	}
}
//teste
/*
	function mascara(o,f)
	{
		v_obj=o
		v_fun=f
		setTimeout("execmascara()",1)
	}

	function execmascara()
	{
		v_obj.value=v_fun(v_obj.value)
	}

	//valida formato de hora 00:00 at� 23:59 com mascara
	//criada em 2008-04-15 15:57
	//er=/^(([01][\d])|([2][0-3]))([0-5][\d])/ //ereg que valida a hora(nao usada aqui)

	function mascaraHora(v)
	{
		v=v.replace(/\D/g,"") //Remove tudo o que n�o � d�gito
		v=v.replace(/^[^012]/,"") //valida o primeiro d�gito #
		v=v.replace(/^([2])([^0-3])/,"$1") //valida o segundo d�gito ##
		v=v.replace(/^([\d]{2})([^0-5])/,"$1")//valida o terceiro d�gito ###
		v=v.replace(/(\d{2})(\d)/,"$1:$2") //Coloca dois ponto entre o segundo e o terceiro d�gitos ##:##
.		v=v.substr(0,5) //Remove digitos extras (aceita no max 5 caracteres(contando o ':' no meio) )
		return v
	}

	function mascaraData(v)
	{
		v=v.replace(/\D/g,"") //Remove tudo o que n�o � d�gito
		v=v.replace(/^[^0123]/,"") //valida o primeiro d�gito #
		v=v.replace(/^([^0-9])/,"$1") //valida o segundo d�gito ##
		v=v.replace(/^([\d]{2})([^0-1])/,"$1")//valida o terceiro d�gito ###
		v=v.replace(/(\d{2})(\d)/,"$1:$2") //Coloca dois ponto entre o segundo e o terceiro d�gitos ##:##
.		v=v.substr(0,5) //Remove digitos extras (aceita no max 5 caracteres(contando o ':' no meio) )
		return v

	}
*/
//fim teste

function isEmail(Email, msg)
{
	var objEm = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    Email = Trim(Email);
	var teste = preenchido(Email, 'Por favor, digite o endereço de e-mail.', 'E-Mail');
    if(teste!==false)
    {
    	if(objEm.test(Email))
		{
        	return true;
		}
        else
		{
			erro(msg, 'E-Mail');
			return false;
		}
	}
	else
	{
		return false;

	}
}
function isTelefone(Tel, msg, nome)
{
	var objTl = /^[0-9]?[0-9]?\s?[0-9]{4}\s?[0-9]{4}$/;
    Tel = Trim(Tel);

    if(Tel.length > 0)
    {
    	if(objTl.test(Tel))
		{
			//alert("é valido");
        	return true;
		}
        else
		{
			//alert("n&atilde;o é valido");
        	erro(msg, nome);
			return false;
		}
	}else{
		erro('O campo n&atilde;o foi preenchido.', nome);
		return false;
	}
}

function preenchido(Campo, msg, nome)
{

	if(Campo.length == 0)
    {
		erro(msg, nome);
		return false;
	}
}

function umMinuto(pagina, parametros)
{

	// mostra um 'alert' de ok ou cancelar
	if(confirm("Tem certeza de que deseja prosseguir? Esta operação não tem volta."))
	{
	   mudaPagina(pagina, parametros);
	   limpaErros();
	   return true;

	}else{
		return false;

	}
}

function erro(mensagem, campo)
{
	if(document.getElementById('msg').innerHTML == "")
	{
		document.getElementById('msg').innerHTML += "<div class='erro'>Os seguintes erros foram encontrados:</div>";
	}else{
		var quebra = document.createElement('br');
		document.getElementById('msg').appendChild(quebra);
	}

	document.getElementById('msg').innerHTML += "<span class='erro'>*&nbsp;</span><span class='menu2'> "+campo+" - "+mensagem+"</span>";
	return;
}


function isCEP(CEP)
{

    var objER = /^[0-9]{5}-[0-9]{3}$/;
	//var objER = /^[0-9]{2}\.[0-9]{3}-[0-9]{3}$/

    CEP = Trim(CEP)
    if(CEP.length > 0)
    {
    	if(objER.test(CEP))
		{
        	return true;
		}
        else
		{
        	erro('O n&uacute;mero do CEP informado n&atilde;o é válido.', 'CEP');
			return false;
		}
	}


}

function ok(mensagem)
{
	document.getElementById('msg').innerHTML += "<div align='center' class='positivo'>"+mensagem+"</div>";
	return;
}

function setaFocus(id)
{
	document.getElementById(id).focus();
}
