//Abrir PopUP
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//MENU DROP DOWN
var cssdropdown = {
	disappeardelay: 250,

	dropmenuobj: null, ie: document.all, firefox: document.getElementById && !document.all,

	getposOffset: function(what, offsettype) {
		var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
		var parentEl = what.offsetParent;
		while (parentEl != null) {
			totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
			parentEl = parentEl.offsetParent;
		}
		return totaloffset;
	},

	showhide: function(obj, e, visible, hidden) {
		if (this.ie || this.firefox)
			this.dropmenuobj.style.left = this.dropmenuobj.style.top = "-500px"
		if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover")
			obj.visibility = visible
		else if (e.type == "click")
			obj.visibility = hidden
	},

	iecompattest: function() {
		return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
	},

	clearbrowseredge: function(obj, whichedge) {
		var edgeoffset = 0
		if (whichedge == "rightedge") {
			var windowedge = this.ie && !window.opera ? this.iecompattest().scrollLeft + this.iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
			this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetWidth
			if (windowedge - this.dropmenuobj.x < this.dropmenuobj.contentmeasure)  //move menu to the left?
				edgeoffset = this.dropmenuobj.contentmeasure - obj.offsetWidth
		}
		else {
			var topedge = this.ie && !window.opera ? this.iecompattest().scrollTop : window.pageYOffset
			var windowedge = this.ie && !window.opera ? this.iecompattest().scrollTop + this.iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
			this.dropmenuobj.contentmeasure = this.dropmenuobj.offsetHeight
			if (windowedge - this.dropmenuobj.y < this.dropmenuobj.contentmeasure) { //move up?
				edgeoffset = this.dropmenuobj.contentmeasure + obj.offsetHeight
				if ((this.dropmenuobj.y - topedge) < this.dropmenuobj.contentmeasure) //up no good either?
					edgeoffset = this.dropmenuobj.y + obj.offsetHeight - topedge
			}
		}
		return edgeoffset
	},

	dropit: function(obj, e, dropmenuID) {
		if (this.dropmenuobj != null) //hide previous menu
			this.dropmenuobj.style.visibility = "hidden"
		this.clearhidemenu()
		if (this.ie || this.firefox) {
			obj.onmouseout = function() { cssdropdown.delayhidemenu() }
			this.dropmenuobj = document.getElementById(dropmenuID)
			this.dropmenuobj.onmouseover = function() { cssdropdown.clearhidemenu() }
			this.dropmenuobj.onmouseout = function() { cssdropdown.dynamichide(e) }
			this.dropmenuobj.onclick = function() { cssdropdown.delayhidemenu() }
			this.showhide(this.dropmenuobj.style, e, "visible", "hidden")
			this.dropmenuobj.x = this.getposOffset(obj, "left")
			this.dropmenuobj.y = this.getposOffset(obj, "top")
			this.dropmenuobj.style.left = this.dropmenuobj.x - this.clearbrowseredge(obj, "rightedge") + "px"
			this.dropmenuobj.style.top = this.dropmenuobj.y - this.clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + 1 + "px"
		}
	},

	contains_firefox: function(a, b) {
		while (b.parentNode)
			if ((b = b.parentNode) == a)
			return true;
		return false;
	},

	dynamichide: function(e) {
		var evtobj = window.event ? window.event : e
		if (this.ie && !this.dropmenuobj.contains(evtobj.toElement))
			this.delayhidemenu()
		else if (this.firefox && e.currentTarget != evtobj.relatedTarget && !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
			this.delayhidemenu()
	},

	delayhidemenu: function() {
		this.delayhide = setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'", this.disappeardelay)
	},

	clearhidemenu: function() {
		if (this.delayhide != "undefined")
			clearTimeout(this.delayhide)
	}
}

function flash(arquivo, largura, altura) {
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + largura + "' height='" + altura + "' id='index' align='middle'>")
	document.write("<param name='allowScriptAccess' value='sameDomain' />")
	document.write("<param name='movie' value='" + arquivo + "' />")
	document.write("<param name='quality' value='high' />")
	document.write("<param name='wmode' value='transparent' />")
	document.write("<param name='bgcolor' value='#F0FFF3' />")
	document.write("<embed src='" + arquivo + "' quality='high' wmode='transparent' bgcolor='#F0FFF3' width='" + largura + "' height='" + altura + "' name='index' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />")
	document.write("</object>")
}

function ValidaContato() {
	var form = document.contato
	if (form.nome.value == "") {
		window.alert("Preencha o Nome");
		form.nome.focus();
		return false
	}
	if (form.email.value == "") {
		window.alert("Preencha o Email");
		form.email.focus();
		return false
	}
	if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1) {
		alert("E-mail inválido!")
		form.email.focus()
		return false
	}
	if (form.telefone.value == "" || form.telefone.value == "99 9999-9999") {
		window.alert("Preencha o Telefone");
		form.telefone.focus();
		return false
	}
	if (form.telefone.value.length < 12) {
		window.alert("Preencha o Telefone corretamente. Número de caracteres inválido");
		form.telefone.focus();
		return false
	}

	if (form.assunto.value == "") {
		window.alert("Preencha o Assunto");
		form.assunto.focus();
		return false
	}
	if (form.mensagem.value == "") {
		window.alert("Preencha a Mensagem");
		form.mensagem.focus();
		return false
	}

}

function validaBuscaPagina() {
	var form = document.buscaPagina;
	if (form.categoria.value == "") {
		window.alert("Selecione a Categoria");
		form.categoria.focus();
		return false
	}
	if (form.subCategoria.value == "") {
		window.alert("Selecione a Sub Categoria");
		form.subCategoria.focus();
		return false
	}
	if (form.evento.value == "") {
		window.alert("Selecione o Evento");
		form.evento.focus();
		return false
	}
}

function validaDoacao() {
	var form = document.doacao;
	if (form.categoria.value == "") {
		window.alert("Selecione a Categoria");
		form.categoria.focus();
		return false
	}
	if (form.subCategoria.value == "") {
		window.alert("Selecione a Sub Categoria");
		form.subCategoria.focus();
		return false
	}
	if (form.evento.value == "") {
		window.alert("Selecione o Evento");
		form.evento.focus();
		return false
	}
	if (form.pagina.value == "") {
		window.alert("Selecione a Página");
		form.pagina.focus();
		return false
	}
	if (form.valor.value == "") {
		window.alert("Preencha o valor que você deseja doar");
		form.valor.focus();
		return false
	}
}

function validaBuscaRapida() {
	var form = document.busca

	if (form.categoria.value == "" && form.categoria.selectedIndex == 0) {
		window.alert("Preencha a palavra-chave ou selecione a categoria");
		return false
	} 

}

function Mascara(tipo, campo, teclaPress) {
	if (window.event) {
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}

	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g, '');

	tam = s.length + 1;

	if (tecla != 9 && tecla != 8) {
		switch (tipo) {
			case 'CPF':
				if (tam > 3 && tam < 7)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, tam);
				if (tam >= 7 && tam < 10)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, tam - 6);
				if (tam >= 10 && tam < 12)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '-' + s.substr(9, tam - 9);
				break;

			case 'CNPJ':

				if (tam > 2 && tam < 6)
					campo.value = s.substr(0, 2) + '.' + s.substr(2, tam);
				if (tam >= 6 && tam < 9)
					campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, tam - 5);
				if (tam >= 9 && tam < 13)
					campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, tam - 8);
				if (tam >= 13 && tam < 15)
					campo.value = s.substr(0, 2) + '.' + s.substr(2, 3) + '.' + s.substr(5, 3) + '/' + s.substr(8, 4) + '-' + s.substr(12, tam - 12);
				break;

			case 'IE':

				if (tam > 3 && tam < 7)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, tam);
				if (tam >= 7 && tam < 10)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, tam - 6);
				if (tam >= 10 && tam < 12)
					campo.value = s.substr(0, 3) + '.' + s.substr(3, 3) + '.' + s.substr(6, 3) + '.' + s.substr(9, tam - 9);
				break;

			case 'TEL':

				if (!(tecla >= 48 && tecla <= 57)) {
					if (tecla != 0) {
						return false
					}
				} else {
					if (tam > 2 && tam < 4)
						campo.value = s.substr(0, 2) + ' ' + s.substr(2, tam);
					if (tam >= 7 && tam < 11)
						campo.value = s.substr(0, 2) + ' ' + s.substr(2, 4) + '-' + s.substr(6, tam - 6);
				}

				break;

			case 'CEP':

				if (!(tecla >= 48 && tecla <= 57)) {
					if (tecla != 0) {
						return false
					}
				} else {
					if (tam >= 6 && tam < 8)
						campo.value = s.substr(0, 5) + '-' + s.substr(5, tam - 5);
				}

				break;

			case 'DATA':
				if (!(tecla >= 48 && tecla <= 57)) {
					if (tecla != 0) {
						return false
					}
				} else {
					if (tam > 2 && tam < 4)
						campo.value = s.substr(0, 2) + '/' + s.substr(2, tam);
					if (tam > 4 && tam < 11)
						campo.value = s.substr(0, 2) + '/' + s.substr(2, 2) + '/' + s.substr(4, tam - 4);
				}
				break;
		}
	}
}

function sub1_abre(tabela) {
	tabela = document.getElementById(tabela);
	if (tabela.style.display == "none") {
		tabela.style.display = "block";
	} else {
		tabela.style.display = "none";
	}
}

function encerrarPagina() {
	if (window.confirm('Tem certeza que deseja Encerrar?')) {
		return true;
	} else {
		return false;
	}
}

function formataMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	// 13=enter, 8=backspace as demais retornam 0(zero)
	// whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
	if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
		return true;

	key = String.fromCharCode(whichCode); // Valor para o código da Chave

	if (strCheck.indexOf(key) == -1)
		return false; // Chave inválida
	len = objTextBox.value.length;
	for (i = 0; i < len; i++)
		if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal))
		break;
	aux = '';
	for (; i < len; i++)
		if (strCheck.indexOf(objTextBox.value.charAt(i)) != -1)
		aux += objTextBox.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0)
		objTextBox.value = '';
	if (len == 1)
		objTextBox.value = '0' + SeparadorDecimal + '0' + aux;
	if (len == 2)
		objTextBox.value = '0' + SeparadorDecimal + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += SeparadorMilesimo;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		objTextBox.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			objTextBox.value += aux2.charAt(i);
		objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
	}
	return false;
}

function adicionarFavorito(titulo) {
	var url   = document.location;
	var title = titulo;
	
	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if (window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel', 'sidebar');
		mbm.setAttribute('href', url);
		mbm.setAttribute('title', title);
		mbm.click();
	} else if (document.all) {
		window.external.AddFavorite(url, title);
	} else {
		alert('Adicione está página ao seus favoritos apertando em seu teclado \'CTRL + D\'.')
	}
} 

/*
* Função obterCidades
* Param: cbo_r, cbo_d
* função que utiliza requisições assincronas para obter uma lista de cidades
* e popular um combobox.
* Para funcionar a função dependo do framework prototype
* Recebe como parametros a referencia ao do combo remetente e o id do combo destino
*/

function obterCidades(cbo_r, id_cbo_d) {
	var uf = cbo_r.options[cbo_r.selectedIndex].value; //obtém o valor selecionado
	var sel = new Select(id_cbo_d);

	new Ajax.Request('includes/hibrido.asp', { method: 'get',
		parameters: { estado: uf, acao: "getCidades" },
		encoding: 'ISO-8859-1',
		requestHeaders: { Accept: 'application/json' },
		onCreate: function() {
			//desabilita o select											  	
			sel.select.disabled = 1;
			//remove os opttions existentes
			sel.removeAllOptions();
			//adiciona a mensagem de carregando
			sel.addOption('Carregando...', '0', true)
		},
		onSuccess: function(transport) {
			var json = transport.responseText.evalJSON();
			var cboCidades = $('cidades');
			//remove a mensagem de carregando
			sel.removeAllOptions();
			sel.addOption('Selecione', '0', true)
			//monta o combo com os dados recebidos
			for (var i = 0; i < json.cidades.length; i++) {
				v = json.cidades[i].cidade;
				sel.addOption(v, v, false);
			}
			sel.select.disabled = 0;
		}
	});
}

function obterSubCategoria(cbo_r, id_cbo_d) {
	var cbo_value = cbo_r.options[cbo_r.selectedIndex].value; //obtém o valor selecionado
	var sel = new Select(id_cbo_d);

	new Ajax.Request('includes/hibrido.asp?anticache=' + Math.random(),
		{ method: 'get',
			parameters: { categoria: cbo_value, acao: "obterSubCategoria" },
			encoding: 'ISO-8859-1',
			requestHeaders: { Accept: 'application/json' },
			onCreate: function() {
				//desabilita o select											  	
				sel.select.disabled = 1;
				//remove os opttions existentes
				sel.removeAllOptions();
				//adiciona a mensagem de carregando
				sel.addOption('Carregando...', '0', true)
			},
			onSuccess: function(transport) {
				var json = transport.responseText.evalJSON();
				//remove a mensagem de carregando
				sel.removeAllOptions();
				sel.addOption('Selecione', '0', true)
				//monta o combo com os dados recebidos
				for (var i = 0; i < json.resposta.length; i++) {
					v = json.resposta[i].cd_subcategoria;
					text = json.resposta[i].subcategoria;
					sel.addOption(text, v, false);
				}
				sel.select.disabled = 0;
			}
		});
}

function obterEvento(cbo_r, id_cbo_d, cbo_categoria) {
	var cbo_value = cbo_r.options[cbo_r.selectedIndex].value; //obtém o valor selecionado
	var cbo_categoria = $(cbo_categoria);
	var cbo_v_categoria = cbo_categoria.options[cbo_categoria.selectedIndex].value;  //obtém o valor da categoria
	var sel = new Select(id_cbo_d);

	new Ajax.Request('includes/hibrido.asp?anticache=' + Math.random(),
		{ method: 'get',
			parameters: { c: cbo_v_categoria, sc: cbo_value, acao: "obterEvento" },
			encoding: 'ISO-8859-1',
			requestHeaders: { Accept: 'application/json' },
			onCreate: function() {
				//desabilita o select											  	
				sel.select.disabled = 1;
				//remove os opttions existentes
				sel.removeAllOptions();
				//adiciona a mensagem de carregando
				sel.addOption('Carregando...', '0', true)
			},
			onSuccess: function(transport) {
				var json = transport.responseText.evalJSON();
				//remove a mensagem de carregando
				sel.removeAllOptions();
				sel.addOption('Selecione', '0', true)
				//monta o combo com os dados recebidos
				for (var i = 0; i < json.resposta.length; i++) {
					v = json.resposta[i].cd_evento;
					text = json.resposta[i].nome;
					sel.addOption(text, v, false);
				}
				sel.select.disabled = 0;
			}
		});
}

function obterPaginas(cbo_r, id_cbo_d, cbo_categoria, cbo_subcategoria) {	
	var cbo_categoria    = $(cbo_categoria);
	var cbo_subcategoria = $(cbo_subcategoria);
	var cbo_value = cbo_r.options[cbo_r.selectedIndex].value; //obtém o valor do evento
	var cbo_v_categoria = cbo_categoria.options[cbo_categoria.selectedIndex].value;  //obtém o valor da categoria
	var cbo_v_subcategoria = cbo_subcategoria.options[cbo_subcategoria.selectedIndex].value;  //obtém o valor da subcategoria
	
	var sel = new Select(id_cbo_d);

	new Ajax.Request('includes/hibrido.asp?anticache=' + Math.random(),
		{ method: 'get',
			parameters: { c: cbo_v_categoria, sc: cbo_v_subcategoria, e:cbo_value, acao: "obterPagina" },
			encoding: 'ISO-8859-1',
			requestHeaders: { Accept: 'application/json' },
			onCreate: function() {
				//desabilita o select											  	
				sel.select.disabled = 1;
				//remove os opttions existentes
				sel.removeAllOptions();
				//adiciona a mensagem de carregando
				sel.addOption('Carregando...', '0', true)
			},
			onSuccess: function(transport) {
				var json = transport.responseText.evalJSON();
				//remove a mensagem de carregando
				sel.removeAllOptions();
				sel.addOption('Selecione', '0', true)
				//monta o combo com os dados recebidos
				for (var i = 0; i < json.resposta.length; i++) {
					v = json.resposta[i].cd_pagina;
					text = json.resposta[i].titulo;
					sel.addOption(text, v, false);
				}
				sel.select.disabled = 0;
			}
		});
}

function verificarDominio(value, id) {
	if (value == '' || value.length < 1) {
		alert('Informe um nome para o dominio.');
	} else {
		new Ajax.Request(
			'includes/hibrido.asp?anticache=' + Math.random(),
			{
				method: 'get', parameters: { dominio: value, acao: "verificaDominio" },
				requestHeaders: { Accept: 'application/json' },
				onCreate: function() {
					$(id).show();
					$(id).update('Aguarde...');
				},
				onSuccess: function(transport) {
					var json = transport.responseText.evalJSON();

					$(id).update(json.resposta[0])

					if (json.resposta[1] == 1) {
						$('btnProximo').show();
					} else {
						$('btnProximo').hide();
					}
				}
			}
		);
	}
}

//funções de confirmação de exclução do banco de dados!
function denuncie()
{
if (window.confirm('O recurso Denuncie Já, tem com função alertar à\n administração sobre paginas que contenham conteúdo inapropriado.\n\n Caso a denuncia seja confirmada, o o site tomará \n as devidas providencias condizente com os termos de uso do Mootiva.com \n\n Tem certeza que deseja confirmar a denuncia?'))
{
	return true;
} else {
    return false;
}
}







