var CidadeBusca = "";

// Alertas (mensagens) /////////////////////////////
function alerta(msg, obj, foco, topo)
{
	alert(msg);
	if (!foco)
		obj.focus();
	if (topo)
		document.location = '#' + topo;
	return false;
}
////////////////////////////////////////////////////

// Pop-Up em DIV ///////////////////////////////////
function showPopUp(linkpagina, mensagem)
{
	document.getElementById('divPopUp').style.display = '';
	
	if (mensagem == "")
	{
		mensagem = "Carregando..."; 	
	}
	
	jah(linkpagina,'c_div_popup','',mensagem);	
}

function hidePopUp()
{
	document.getElementById('divPopUp').style.display = 'none';
}
////////////////////////////////////////////////////

// Comentários dos Posts no Blog ///////////////////
function enviarComentarioPost()
{
	with (document.frmcomentblog)
	{
		if (nomecomentario.value == "" || nomecomentario.value == "nome")
		{
			return alerta("Informe o seu nome.", nomecomentario);
		}
		else
		if (emailcomentario.value == "" || emailcomentario.value == "e-mail")
		{
			return alerta("Informe o seu e-mail.", emailcomentario);
		}
		else
		if (emailcomentario.value.indexOf('@') < 1 || emailcomentario.value.indexOf('.') < 1)
		{
			return alerta("Informe um e-mail válido.", emailcomentario);
		}
		else
		if (comentario.value == "" || comentario.value == "comentário")
		{
			return alerta("Preencha o comentário.", comentario);
		}
		else
		{
			return true;
		}
	}
}

function confValorCampo(campo, valorpadrao)
{
	if (document.getElementById(campo).value == valorpadrao)
	{
		document.getElementById(campo).value = '';
	}
	else
	if (document.getElementById(campo).value == '')
	{
		document.getElementById(campo).value = valorpadrao;
	}
}
////////////////////////////////////////////////////

// onde Comprar ////////////////////////////////////
function setaEstadoComprar(sigla)
{
	lista = document.getElementById('sel_estados');
	opcoeslista = lista.options.length;
	
	for (o = 0; o < opcoeslista; o++)
	{
		if (lista.options[o].value == sigla)
		{
			lista.selectedIndex = o;	
		}
	}
	
	jah('comprar_cidades.php?uf='+sigla,'div_cidades','','carregando cidades...');	
}

function setaEstadoComprarCombo(sigla)
{
	jah('comprar_cidades.php?uf='+sigla,'div_cidades','','carregando cidades...');	
}

function buscarLojas()
{
	estado = document.getElementById('sel_estados').value;
	cidade = document.getElementById('sel_cidades').value;
	
	if (estado != "" && cidade != "")
	{
		jah('comprar_lista.php?uf='+estado+'&cidade='+cidade,'localize-resultados','','carregando resultados da busca...');
	}
}
////////////////////////////////////////////////////

// Dicas Ramarim ///////////////////////////////////
function buscarDicas()
{
	strBusca = document.getElementById('strBusca').value;
	idCategoriaDica = document.getElementById('idCategoriaDica').value;
	idOcasiaoDica = document.getElementById('idOcasiaoDica').value;
	idEstilo = document.getElementById('idEstilo').value;
	idTipo = document.getElementById('idTipo').value;
	
	if (strBusca == "" && idCategoriaDica == "" && idOcasiaoDica == "" && idEstilo == "" && idTipo == "")
	{
		alert('Informe pelo menos um item\npara efetuar a busca.');
	}
	else
	{
		document.frmdicas.submit();
	}
}
////////////////////////////////////////////////////

// Dica ////////////////////////////////////////
function enviarDica()
{
	with(document.dica)
	{
		if (strTitulo.value == "")
		{
			return alerta("Digite o titulo da dica.", strTitulo);
		}
		else
		if (strDescricao.value == "")
		{
			return alerta("Digite a descrição da dica.", strDescricao);
		}
		else
		{
			return true;
		}
	}
}

// Pergunta ////////////////////////////////////////
function enviarPergunta()
{
	with(document.pergunta)
	{
		if (strNome.value == "" || strNome.value == "nome")
		{
			return alerta("Digite o seu nome.", strNome);
		}
		else
		if (strEmail.value == "" || strEmail.value == "e-mail")
		{
			return alerta("Digite o seu e-mail.", strEmail);
		}
		else
		if (strEmail.value.indexOf('@') < 1 || strEmail.value.indexOf('.') < 1)
		{
			return alerta("Digite um e-mail válido.", strEmail);
		}
		else
		if (strPergunta.value == "" || strPergunta.value == "pergunta")
		{
			return alerta("Digite a pergunta.", strPergunta);
		}
		else
		{
			return true;
		}
	}
}

// Cadastro ////////////////////////////////////////
function enviarCadastro()
{
	var erro = 0;
	with(document.cad)
	{
		if ((strNome.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu nome.");
			erro = 1;
			strNome.focus();
		}
		else
		if ((intDia.value == "" || intMes.value == "" || intAno.value == "") && erro == 0)
		{
			window.alert("Selecione sua data de nascimento corretamente.");
			erro = 1;
		}
		else
		if ((strEmail.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu email.");
			erro = 1;
			strEmail.focus();
		}
		else
		if (((strEmail.value.indexOf("@") == "-1") || (strEmail.value.indexOf(".") == "-1")) && erro == 0)
		{
			window.alert("Digite um e-mail válido.");
			erro = 1;
			strEmail.focus();
		}
		else
		if ((strSenha.value == "" && strSenha2.value == "") && erro == 0)
		{
			window.alert("Informe uma senha para seu cadastro.");
			erro = 1;
			strSenha.focus();
		}
		else
		if ((strSenha.value != "" && strSenha2.value == "") && erro == 0)
		{
			window.alert("Repita a sua senha para o cadastro.");
			erro = 1;
			strSenha2.focus();
		}
		else
		if ((strSenha.value != strSenha2.value) && erro == 0)
		{
			window.alert("As senhas digitadas não conferem. Verifique.");
			erro = 1;
			strSenha2.value = "";
			strSenha2.focus();
		}
		else
		if ((strPais.value == "" ) && erro == 0)
		{
			window.alert("Selecione o seu país.");
			erro = 1;
			strPais.focus();
		}
		else
		if (strPais.value == "1" && strEstado.value == "" && erro == 0)
		{
			window.alert("Selecione o seu estado.");
			erro = 1;
			strEstado.focus();
		}
		else
		if ((strCidade.value == "" ) && erro == 0)
		{
			window.alert("Digite a sua cidade.");
			erro = 1;
			cidade.focus();
		}
		else
		if ((strEndereco.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu endereço.");
			erro = 1;
			strEndereco.focus();
		}
		else
		if ((strNumero.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu número do endereço.");
			erro = 1;
			strNumero.focus();
		}
		else
		if ((strBairro.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu bairro.");
			erro = 1;
			strBairro.focus();
		}
		else
		if ((intCep.value == "" ) && erro == 0)
		{
			window.alert("Digite seu CEP.");
			erro = 1;
			intCep.focus();
		}
		else
		if ((strTelefone.value == "" ) && erro == 0)
		{
			window.alert("Digite o seu telefone.");
			erro = 1;
			strTelefone.focus();
		}
		else
		if	((strProfissao.value == "" ) && erro == 0)
		{
			window.alert("Digite sua profissão.");
			erro = 1;
			strProfissao.focus();
		}
		else
		if ((strEstadoCivil.value == "" ) && erro == 0)
		{
			window.alert("Selecione o seu estado civil.");
			erro = 1;
			strEstadoCivil.focus();
		}

		/*
		if (codcad == "")
		{
			if ((opiniao.value == "0" ) && erro == 0)
			{
				window.alert("Selecione a sua opinião sobre a Coleção Primavera-Verão 2006/07.");
				erro = 1;
				opiniao.focus();
			}
			else
			if ((possui.value == "0" ) && erro == 0)
			{
				window.alert("Selecione se você possui calçados Ramarim.");
				erro = 1;
				possui.focus();
			}
			else
			if	((importante.value == "0") && erro == 0)
			{
				window.alert("Selecione o que é importante na hora da compra.");
				erro = 1;
				importante.focus();
			}
			else
			if ((frequencia.value == "0") && erro == 0)
			{
				window.alert("Selecione com que freqüência você acessa a internet.");
				erro = 1;
				frequencia.focus();
			}
		}
		*/

		if (erro == 0)
			return true;
		else
			return false;
	}
}

function enviarCadastroLogin()
{
	document.frmlogin.action = '_forms_enviar.php?secao=cadastro&act=fazerlogin';

	with(document.frmlogin)
	{
		if (strEmailLogin.value == '')
			return alerta("Informe o seu e-mail.", strEmailLogin);
		else
		if (strEmailLogin.value.indexOf('@') < 1 || strEmailLogin.value.indexOf('.') < 1)
			return alerta('Informe um e-mail válido.', strEmailLogin);
		else
		if (strSenhaLogin.value == '')
			return alerta("Informe sua senha.", strSenhaLogin);
		else
			return true;

	}
}

function enviarSenhaCadastro()
{
	document.frmlogin.action = '_forms_enviar.php?secao=cadastro&act=esquecisenha';

	with(document.frmlogin)
	{
		if (strEmailLogin.value == '')
			alerta("Informe o seu e-mail.", strEmailLogin);
		else
		if (strEmailLogin.value.indexOf('@') < 1 || strEmailLogin.value.indexOf('.') < 1)
			alerta('Informe um e-mail válido.', strEmailLogin);
		else
		    submit();
	}
}

function enviarConfMail()
{
	with(document.frmemail)
	{
		if (strEmail.value == '')
			return alerta("Informe o seu e-mail.", strEmail);
		else
		if (strEmail.value.indexOf('@') < 1 || strEmail.value.indexOf('.') < 1)
			return alerta('Informe um e-mail válido.', strEmail);
		else
			return true;

	}
}

function editarCadastro()
{
	document.location = 'cadastro_form.php';
}

function logOff()
{
    if (confirm('Confirmar logoff do Site?'))
	{
		document.location = '_logoff_site.php';
	}
}
////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function setaNoticia( idNoticia )
{
	if( idNoticia == '' )
	{
		alert('Selecione uma notícia.');
		return false;
	}
	else
	{
		return true;
	}
}

function submetePesquisa( id )
{
	if( document.getElementById(id).value == '')
	{
		alert('Selecione uma notícia');
		return false;
	}
	else
	{
		return true;
	}
}

function carregaFoto(str){
	var carrosel = document.getElementById('html-carousel');
	var imgs = carrosel.getElementsByTagName('img');
	for(var i=0; i < imgs.length; i++) 
	{
		imgs[i].onclick=function() 
		{
			legenda = document.getElementById(this.id).getAttribute('texto');
			
			carrega(this.src, legenda);
			limpaBordas();
			this.className = "thumbativo";
		}
		imgs[i].onmouseover=function() 
		{
			if(this.className != "thumbativo")
			{
				this.className += " opacidade";
			}
		}
		imgs[i].onmouseout=function() 
		{
			if(this.className != "thumbativo")
			{
				this.className = "thumb";
			}
		}
	}
}
function limpaBordas() {
	var carrosel = document.getElementById('html-carousel');
	var imgs = carrosel.getElementsByTagName('img');
	for(var i=0; i < imgs.length; i++) 
	{
		imgs[i].className = 'thumb';
	}
}
function carrega(str, legenda){
	var img = document.getElementById('imggrande');
	var parte=str.split("thumb_");
	var src = parte[0]+parte[1];
	img.src = src;
	document.getElementById('desc_imagem').innerHTML = legenda;
}

function buttonStateHandler(button, enabled) {
 	if (button == "prev-arrow") 
   		$('prev-arrow').src = enabled ? "images/left3-enabled.gif" : "images/left3-disabled.gif"
 	else 
   		$('next-arrow').src = enabled ? "images/right3-enabled.gif" : "images/right3-disabled.gif"
}
function animHandler(carouselID, status, direction) {
  	var region = $(carouselID).down(".carousel-clip-region")
  	if (status == "before") 
  	{
    	Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  	}
  	if (status == "after") 
  	{
    	Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  	}
}

// Pergunta ////////////////////////////////////////
function enviarContato()
{
	with(document.contato)
	{
		if (strNome.value == "" || strNome.value == "nome")
		{
			return alerta("Digite o seu nome.", strNome);
		}
		else
		if (strEmail.value == "" || strEmail.value == "e-mail")
		{
			return alerta("Digite o seu e-mail.", strEmail);
		}
		else
		if (strEmail.value.indexOf('@') < 1 || strEmail.value.indexOf('.') < 1)
		{
			return alerta("Digite um e-mail válido.", strEmail);
		}
		else
		if (strMensagem.value == "" || strMensagem.value == "pergunta")
		{
			return alerta("Digite a mensagem.", strMensagem);
		}
		else
		{
			return true;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
