function setLocation(Url){
	window.location.href = Url;
}

function setStatusBar(texto){
	window.status=texto;
}

function statusBarIn(obj){
	var texto = "";
	if (obj.title!=""){
		texto = obj.title;
	}
	setStatusBar(texto);
	return true;
}

function statusBarOut(){
	setStatusBar("");
	return true;
}

function voltar(){
	window.history.back();
}

function AbreJanela(Url, Nome, Opcoes){
	var Janela = window.open(Url,Nome,Opcoes);
	return Janela;
}

function AbreConto(Url){
	var winEmail = AbreJanela(Url,"popConto","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=520");
	winEmail.focus();
	return true;
}

function ShowDivConto(div){
	if (div.style.display == "none"){div.style.display = "inline";}
	else{div.style.display = "none"};
	return true;
}

function SomenteNumero(e){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else 
		if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else{
			if (tecla != 8) // backspace
				return false;
			else
				return true;
			}
}

function Confirma(strTexto, strURL){
	if (confirm(strTexto)){
		setLocation (strURL);
		return true;
	}
	else{
		return false;
	}
}

function CheckAll(objForm, acao){
	var cont = 0;
	for (cont = 0; cont < objForm.elements.length; cont++){
		var obj = objForm.elements(cont);
		if (obj.type == "checkbox"){
			obj.checked = acao;
		}
	}
}

function Selecionar(objForm, objRetorno){
	var cont = 0;
	var aux = "";
	objRetorno.value = "";
	for (cont = 0; cont < objForm.elements.length; cont++){
		var obj = objForm.elements(cont);
		if (obj.type == "checkbox"){
			if (obj.checked && obj.name!="all"){
				objRetorno.value += aux + obj.email;
				aux = ";";
			}
		}
	}
}

function changePagina(e, objForm){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else
		if(document.layers) // Nestcape
			var tecla = e.which;
	objForm.submit();
}

function getElementPosition(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

function ValidacaoEmail(emailad){
    var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
        return false;
    }
    else {
        return true;
    }
}

function doAreaMensagemErro(tipo, msg){
	var icone= "";
	var html = "";
	icone = "../imagens/icones/ico_" + tipo + ".gif";
	html = html + "<div class='area_" + tipo + "'><table width='100%'>";
	html = html + "		<tr>";
	html = html + "		<td width='30' valign='top' align='center'><img src='" + icone + "'></td>";
	html = html + "		<td valign='top' class='texto_" + tipo + "'>";
	html = html + "		<ul class='" + tipo + "'>" + msg + "</ul>";
	html = html + "		</tr>";
	html= html + "</table></div>";
	return html;
}

function ValidaContato(form, span){
	var msgRetorno = "";
	if (form.contato_nome.value.length < 3){
		msgRetorno = msgRetorno + "<li>Nome não preenchido ou inválido.</li>";
	}
	if (!ValidacaoEmail(form.contato_email.value)){
		msgRetorno = msgRetorno + "<li>E-mail não preenchido ou inválido.</li>";
	}
	if (form.contato_mensagem.value.length < 3){
		msgRetorno = msgRetorno + "<li>Mensagem não preenchida ou inválida.</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}

function ValidaVisitante(form, span){
	var msgRetorno = "";
	if (form.visitante_apelido.value.length < 3){
		msgRetorno = msgRetorno + "<li>Apelido não preenchido (mínimo 3 caracteres).</li>";
	}
	if (form.visitante_senha.value.length < 5){
		msgRetorno = msgRetorno + "<li>Senha não preenchida (mínimo 5 caracteres).</li>";
	}
	if (form.visitante_senha_confirmacao.value != form.visitante_senha.value){
		msgRetorno = msgRetorno + "<li>Confirmação está diferente da senha digitada.</li>";
	}
	if (!ValidacaoEmail(form.visitante_email.value)){
		msgRetorno = msgRetorno + "<li>E-mail não preenchido ou inválido.</li>";
	}
	if (!form.visitante_email_visivel[0].checked && !form.visitante_email_visivel[1].checked){
		msgRetorno = msgRetorno + "<li>Visibilidade do e-mail inválida.</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}

function ValidaLogin(form, span){
	var msgRetorno = "";
	if (form.visitante_apelido.value.length < 3){
		msgRetorno = msgRetorno + "<li>Apelido não preenchido (mínimo 3 caracteres).</li>";
	}
	if (form.visitante_senha.value.length < 5){
		msgRetorno = msgRetorno + "<li>Senha não preenchida (mínimo 5 caracteres).</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}

function ValidaLoginAdm(form, span){
	var msgRetorno = "";
	if (form.usuario_login.value.length < 3){
		msgRetorno = msgRetorno + "<li>Login não preenchido (mínimo 3 caracteres).</li>";
	}
	if (form.usuario_senha.value.length < 5){
		msgRetorno = msgRetorno + "<li>Senha não preenchida (mínimo 5 caracteres).</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}

function ValidaLembreteSenha(form, span){
	var msgRetorno = "";
	if (form.visitante_apelido.value.length < 3){
		msgRetorno = msgRetorno + "<li>Apelido não preenchido (mínimo 3 caracteres).</li>";
	}
	if (!ValidacaoEmail(form.visitante_email.value)){
		msgRetorno = msgRetorno + "<li>E-mail não preenchido ou inválido.</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}

function ValidaConto(form, span){
	var msgRetorno = "";
	if (form.categoria_codigo.value.length < 1){
		msgRetorno = msgRetorno + "<li>Categoria não preenchida.</li>";
	}
	if (form.conto_titulo.value.length < 5){
		msgRetorno = msgRetorno + "<li>Título não preenchido (mínimo 5 caracteres).</li>";
	}
	if (form.conto_texto.value.length < 50 || form.conto_texto.value.length > 80000){
		msgRetorno = msgRetorno + "<li>Conto inválido (mínimo 50 caracteres).</li>";
	}
	if (msgRetorno == ""){
		return true;
	}
	else{
		obj = document.getElementById(span);
		obj.innerHTML = doAreaMensagemErro("erro", msgRetorno);
		return false;
	}
}
function validaBoletim(form, span){
	var msgRetorno = "";
	var nome = form.nome.value;
	var email = form.email.value;
	var ajax = new AJAX();
	ajax.callPage("../site/conto_info.asp?info=boletim_add&nome=" + nome + "&email=" + email, writeBoletim);
	return false;
}
function writeBoletim(response){
	obj = document.getElementById("mensagemBoletim");
	obj.innerHTML = response;
}
function doVitrineLoja(limite){
	//var ajax = new AJAX();
	//ajax.callPage("URL", writeVitrineLoja);
}
function writeVitrineLoja(response){
	obj = document.getElementById("vitrine_loja");
	obj.innerHTML = response;
}
function doVitrineLoja2(limite){
	var ajax = new AJAX();
	//ajax.callPage("URL", writeVitrineLoja2);
}
function writeVitrineLoja2(response){
	obj = document.getElementById("vitrine_loja2");
	obj.innerHTML = response;
}