function TrocaTexto (texto,elemento) {
	document.getElementById(elemento).innerHTML = texto;
}

function Excluir(tipo,identificador) {
	if(confirm("Deseja realmente excluir este registro?"))
	{
		location = tipo+"_excluir.php?id="+identificador;
	}
}

function listar()
{
	location = "muralderecados_listar.php";
}

function Visualizar(url,page,w,h,sc) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
if(sc=="")
sc = "Yes";
win = window.open(url,page, 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+sc+',resizable=no')
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function radio(url) {
	var w=330;
	var h=170;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	win = window.open('modulos/radio/sis_radio.php?m='+url, 'radio', 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no')
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function validarOpniao()
{
	with(document.formOpiniao)
	{
		if(nome.value=="" || nome.value=="nome")
		{
			alert("O campo NOME deve ser preenchido!");
			nome.focus();
			return false;
		}
		if(telefone.value=="" || telefone.value=="telefone")
		{
			alert("O campo TELEFONE deve ser preenchido!");
			telefone.focus();
			return false;
		}
		if (email.value=="")
		{
			alert ("O campo E-MAIL deve ser preenchido!");
		  	email.focus();
		   	return false;
		}
		if (email.value.indexOf ("@",0) == -1 || email.value.indexOf (".",0) == -1)
	    {
	    	alert("Por favor, preencha o campo E-MAIL corretamente!")
	        email.focus();
	        return false;
	    }
		if(opiniao.value=="" || opiniao.value=="opinião")
		{
			alert("O campo OPINIÃO deve ser preenchido!");
			opiniao.focus();
			return false;
		}
		return true;
	}
}

function esqueceu()
{
	with(document.esquecer)
	{
		if (email.value=="")
		{
			alert ("O campo E-MAIL deve ser preenchido!");
			email.focus();
		 	return false;
		}
		if (email.value.indexOf ("@",0) == -1 || email.value.indexOf (".",0) == -1)
		{
		    alert("Por favor, preencha o campo E-MAIL corretamente!")
		    email.focus();
		    return false;
		 }
	}
		
}

function RedimensionaIframe() {
	try{
		var frame = document.getElementById('conteudo');
		if(navigator.appName.indexOf("Internet Explorer")>-1) {
			var altura = frame.contentWindow.document.body.scrollHeight;
			if(altura > 120) {
				frame.style.height = altura;
			} else {
				frame.style.height = 120;
			}
		}
		else {
			var val = frame.contentWindow.document.body.parentNode.offsetHeight;
			frame.style.height= val + "px";	
		}
	}
	catch(erro){
		alert("Mensagem de Erro:\n\n"+erro.message);
	}
}

function validaEmail(email)
{
	if(email.length < 6)
	{
		return false;
	}
	var x=0;
	for(var c=0;c<email.length;c++)
	{
		if(email.substring(c,c+1)=='@')
		{
			x=c;
		}
	}
	var y=0;
	if(x > 0)
	{
		for(c=x;c<email.length;c++)
		{
			if(email.substring(c,c+1)=='.')
			{
				y=c;
				var valida=1;
			}
		}					
	}
	else
		{
			return false;
		}

	if(y<=x+2)
	{
		return false;
	}

	if(valida==1)
	{
		return true;
	}
	return true;
}

function validaForm( NomeForm )
{
	if (NomeForm == 'frmContato')
	{
		if (document.forms[NomeForm].elements['para'].value == "")
		{
			alert("Selecione o campo Para!");
			document.forms[NomeForm].elements['para'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['nome'].value == "")
		{
			alert("O campo NOME deve ser preenchido!");
			document.forms[NomeForm].elements['nome'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['telefone'].value == "")
		{
			alert("O campo TELEFONE deve ser preenchido!");
			document.forms[NomeForm].elements['telefone'].focus();
			return false;
		}

		if(document.forms[NomeForm].elements['email'].value == ""){
			alert("O campo E-MAIL deve ser preenchido!");
			document.forms[NomeForm].elements['email'].focus();
			return false;
		}else{
				if(!(validaEmail(document.forms[NomeForm].elements['email'].value))){
					alert("O campo E-MAIL não está com um e-mail válido!");
					document.forms[NomeForm].elements['email'].focus();
					return false;
				}
		}
		
		if (document.forms[NomeForm].elements['assunto'].value == "")
		{
			alert("Selecione um ASSUNTO!");
			document.forms[NomeForm].elements['assunto'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['mensagem'].value == "")
		{
			alert("Selecione um MENSAGEM!");
			document.forms[NomeForm].elements['mensagem'].focus();
			return false;
		}
		return true;
	} //Fim frmContato

	if (NomeForm == 'frmPeca')
	{
		if (document.forms[NomeForm].elements['nome'].value == "")
		{
			alert("O campo NOME deve ser preenchido!");
			document.forms[NomeForm].elements['nome'].focus();
			return false;
		}

		if(document.forms[NomeForm].elements['email'].value == ""){
			alert("O campo E-MAIL deve ser preenchido!");
			document.forms[NomeForm].elements['email'].focus();
			return false;
		}else{
				if(!(validaEmail(document.forms[NomeForm].elements['email'].value))){
					alert("O campo E-MAIL não está com um e-mail válido!");
					document.forms[NomeForm].elements['email'].focus();
					return false;
				}
		}
		
		if (document.forms[NomeForm].elements['msn'].value == "")
		{
			alert("O campo MSN deve ser preenchido!");
			document.forms[NomeForm].elements['msn'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['cidadeuf'].value == "")
		{
			alert("O campo CIDADE/UF deve ser preenchido!");
			document.forms[NomeForm].elements['cidadeuf'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['banda'].value == "")
		{
			alert("O campo BANDA deve ser preenchido!");
			document.forms[NomeForm].elements['banda'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['musica'].value == "")
		{
			alert("O campo MÚSICA deve ser preenchido!");
			document.forms[NomeForm].elements['musica'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['programa'].value == "0")
		{
			alert("O campo PROGRAMA deve ser preenchido!");
			document.forms[NomeForm].elements['programa'].focus();
			return false;
		}
		
		if (document.forms[NomeForm].elements['opiniao'].value == "")
		{
			alert("O campo ESCREVA deve ser preenchido!");
			document.forms[NomeForm].elements['opiniao'].focus();
			return false;
		}
		return true;
	} //Fim frmContato
	
}

function validaFormCad() {
	if (document.frmCadastro.nome.value=="") {
		alert("Informe seu nome!");	
		document.frmCadastro.nome.focus();
		return false;
	}
	
	var email = document.frmCadastro.email.value;
	
	if (email=="") {
		alert("Informe seu e-mail!");	
		document.frmCadastro.email.focus();
		return false;
	}
	
	if (!checkMail(email)) {
		alert("E-mail inválido!");	
		document.frmCadastro.email.focus();
		return false;
	}

	var cpf = document.frmCadastro.cpf.value
	
	if (cpf == "") {
		alert("Informe seu CPF!");	
		document.frmCadastro.cpf.focus();
		return false;
	}

	if (!validaCPF(cpf)) {
		alert("CPF inválido!");	
		document.frmCadastro.cpf.focus();
		return false;
	}	

	if (document.frmCadastro.endereco.value=="") {
		alert("Informe seu endereço!");	
		document.frmCadastro.endereco.focus();
		return false;
	}

	if (document.frmCadastro.cidade.value=="") {
		alert("Informe sua cidade!");	
		document.frmCadastro.cidade.focus();
		return false;
	}

	if (document.frmCadastro.uf.value=="") {
		alert("Informe seu estado!");	
		document.frmCadastro.uf.focus();
		return false;
	}
	
	var senha  = document.frmCadastro.senha.value;
	var senha2 = document.frmCadastro.senha2.value;

	if (senha=="") {
		alert("Informe sua senha!");	
		document.frmCadastro.senha.focus();
		return false;
	}
	
	if (senha!=senha2) {
		alert("Senhas nao coincidem!");	
		document.frmCadastro.senha.focus();
		return false;
	}

}

function validaFormCadArtista() {
	if (document.frmCadastro.nome.value=="") {
		alert("Informe o nome do artista!");	
		document.frmCadastro.nome.focus();
		return false;
	}
	
	if (document.frmCadastro.mensagem.value=="") {
		alert("Informe a release!");	
		document.frmCadastro.mensagem.focus();
		return false;
	}
	
	/*
	var email = document.frmCadastro.email.value;
	
	if (email=="") {
		alert("Informe o e-mail do artista!");	
		document.frmCadastro.email.focus();
		return false;
	}
	
	if (!checkMail(email)) {
		alert("E-mail inválido!");	
		document.frmCadastro.email.focus();
		return false;
	}
	*/

}

function validaFormCadPromocao() {
	if (document.frmCadastro.nome.value=="") {
		alert("Informe o nome do artista!");	
		document.frmCadastro.nome.focus();
		return false;
	}
	
	if (document.frmCadastro.mensagem.value=="") {
		alert("Informe a release!");	
		document.frmCadastro.mensagem.focus();
		return false;
	}
	
	/*
	var email = document.frmCadastro.email.value;
	
	if (email=="") {
		alert("Informe o e-mail do artista!");	
		document.frmCadastro.email.focus();
		return false;
	}
	
	if (!checkMail(email)) {
		alert("E-mail inválido!");	
		document.frmCadastro.email.focus();
		return false;
	}
	*/

}

function validaFormContato() {
	if (document.frmContato.nome.value=="") {
		alert("Informe seu nome!");	
		document.frmContato.nome.focus();
		return false;
	}
	
	
	var email = document.frmContato.email.value;
	
	if (email=="") {
		alert("Informe seu e-mail!");	
		document.frmContato.email.focus();
		return false;
	}
	
	if (!checkMail(email)) {
		alert("E-mail inválido!");	
		document.frmContato.email.focus();
		return false;
	}
	
	if (document.frmContato.mensagem.value=="") {
		alert("Informe sua mensagem!");	
		document.frmContato.mensagem.focus();
		return false;
	}
}

function validaFormNewsletter() {

	var email = document.frmNewsletter.email.value;
	
	if (!checkMail(email)) {
		alert("E-mail inválido!");	
		document.frmNewsletter.email.focus();
		return false;
	}
}

function validaCPF(cpf){ // Verifica a validade do CPF informado
	var msg = "CPF válido";
	var sch;
	var nRecebeCPF, nSoma, nresultado1, nresultado2, ns, nx;
	var arrNumero = Array(11);

	nRecebeCPF = cpf;
	ns = "";
	for(nx=0;nx<nRecebeCPF.length;nx++){
		sch = nRecebeCPF.substring(nx,nx+1);
		sch = parseInt(sch);
		sch = new String(sch);
		if(sch != "NaN"){
			ns += sch;
		}
	}

	nRecebeCPF = ns

	tudoIgual = 1; // Verifica se todos os números são iguais
	for (i = 1; i < nRecebeCPF.length; i++) {
		if (nRecebeCPF.substring(i-1, i) != nRecebeCPF.substring(i, i+1)){
			tudoIgual = 0;
		}
	}

	if(nRecebeCPF.length != 11){
		msg = "Quantidade de dígitos inferior a quantidade de dígitos de CPF";
		resultado = false;
	}
	else if(tudoIgual == 1){
		msg = "Todos us números são iguais";
		resultado = false;
	}
	else if(nRecebeCPF == "12345678909"){
		msg = "Número de CPF inexistente";
		resultado = false;
	}
	else{
		arrNumero[0] = nRecebeCPF.substring(0,1);
		arrNumero[1] = nRecebeCPF.substring(1,2);
		arrNumero[2] = nRecebeCPF.substring(2,3);
		arrNumero[3] = nRecebeCPF.substring(3,4);
		arrNumero[4] = nRecebeCPF.substring(4,5);
		arrNumero[5] = nRecebeCPF.substring(5,6);
		arrNumero[6] = nRecebeCPF.substring(6,7);
		arrNumero[7] = nRecebeCPF.substring(7,8);
		arrNumero[8] = nRecebeCPF.substring(8,9);
		arrNumero[9] = nRecebeCPF.substring(9,10);
		arrNumero[10] = nRecebeCPF.substring(10,11);

		nSoma = 10 * arrNumero[0] + 9 * arrNumero[1] + 8 * arrNumero[2] + 7 * arrNumero[3] + 6 * arrNumero[4] + 5 * arrNumero[5] + 4 * arrNumero[6] + 3 * arrNumero[7] + 2 * arrNumero[8]
		nSoma = nSoma-(11*parseInt(nSoma/11));

		if(nSoma == 0 || nSoma == 1){
			nresultado1 = 0;
		}
		else{
			nresultado1 = 11-nSoma;
		}

		if(nresultado1 == arrNumero[9]){
			nSoma = arrNumero[0] * 11 + arrNumero[1] * 10 + arrNumero[2] * 9 + arrNumero[3] * 8 + arrNumero[4] * 7 + arrNumero[5] * 6 + arrNumero[6] * 5 + arrNumero[7] * 4 + arrNumero[8] * 3 + arrNumero[9] * 2
			nSoma = nSoma-(11*parseInt(nSoma/11));
			if(nSoma == 0 || nSoma == 1){
				nresultado2 = 0;
			}
			else{
				nresultado2 = 11 - nSoma;
			}

			if(nresultado2 == arrNumero[10]){
				resultado = true;
			}
			else{
				msg = "CPF inválido";
				resultado = false;
			}
		}
		else{
			msg = "CPF inválido";
			resultado = false;
		}
	}
	//resultado = msg;
	return resultado;
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){ 
					return true; 
				}
	}else{
		return false;
		}
}


function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function f_telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function f_cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function f_data(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    return v
}


function f_cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function f_cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function f_romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function f_site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}

function f_texto(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^ABCDEFGHIJLKMNOPQRSTUVWXZ1234567890 ./]/g,"")

    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    //while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
    //    v=v.replace(/.$/,"")
    return v
}

function twVerificaTamanho(target)
{
	var StrLen;
	var nome = 0;
	var adicional;
	var maximo;
	maximo = 400;
	adicional = 0;
	StrLen = adicional;

	if (document.all.mensagem.value.length != "" )
	{
		StrLen = StrLen + document.all.mensagem.value.length;
	}
	if (StrLen == 1 && document.all.mensagem.value.substring(0,1) == " ")
	{
		document.all.mensagem.value = "";
		StrLen = StrLen - 1;
	}
	if (StrLen > maximo)
	{
		document.all.mensagem.value = document.all.mensagem.value.substring(0,maximo-1);
		StrLen = StrLen - 1;
	}
   document.all.caract.value = maximo - StrLen;
}

function twlimpa_msg(valor) {
	//document.all.mensagem.value = "";
}
var pagina = 1;
function setPagina(newPag){
	pagina = newPag;
}
function MostraUsuario(idEstado, idTipoRegiao){
	try{
		setId("representates");
		setCampoRetorno("div");
		setTagXml("representates");

		if ( typeof idTipoRegiao == 'undefined' ) {
			setTipoRegiao(1);
		}
		else{
			setTipoRegiao(idTipoRegiao);	
		}
		document.getElementById("representates").innerHTML = "<img src='imagens/icon_loading.gif' border='0'>";
		//alert("admin/pessoas/ctrlPessoas.php?acao=xml&idEstado="+idEstado+"pagina="+pagina);
		loadReq("admin/pessoas/ctrlPessoas.php?acao=xml&idEstado="+idEstado+"&pagina="+pagina);
	}
	catch(erro){
		alert("Mensagem de erro:\n\n"+erro.message);
	}
}
function goTo(url){
	document.location.href = url;
}