$(document).ready(function() {
			$('.googlemaps').hide();
			$('a.gm').click(function(){
			$('.googlemaps').show('slow');
	});
			$('a#fechar').click(function(){
   			$('.googlemaps').hide('slow');
	})
			
			$('.pics').cycle({
			fx: 'fade',
			speed: 3500
 });
			$(".ds").qtip({
			       style: { 
					  width: 200,
					  padding: 5,
					  background: '#000000',
					  color: '#84D1E3',
					  textAlign: 'center',
					  border: {
						 width: 7,
						 radius: 5,
						 color: '#000'
					  },
					  tip: 'topLeft',
					  name: 'dark' 
   }
 });
 
			$('a[href=#top]').click(function(){
	        $('html, body').animate({scrollTop:0}, 'slow');
    	    return false;
});

});

function uiGo(url){
	window.location=url;
}

function uiGID(id){
	return document.getElementById(id);
}

function uiHTMLEncode(txt){
	var r='';
	if (txt!=null && typeof(txt)!='undefined')
		for(var i=0;i<txt.length;i++){
			var c=txt.charCodeAt(i);
			if (c==32 || (c>=48 && c<=57) || (c>=65 && c<=90) || (c>=97 && c<=122))
				r+=String.fromCharCode(c);
			else
				r+='&#'+c+';';
		}
	return r;
}
function submeter_pesquisa(ddlregiao, txtalerta)
{	
	var txtpesq;
	var oParceiro = document.getElementById("pesquisa_parceiro");
	var oPalavraChave = document.getElementById("palavra_chave");
	var oValor = document.getElementById("ddlvalor");
	var oRegiao = document.getElementById(ddlregiao);
	
	var parceiro = uiHTMLEncode(oParceiro.value);
	var palavraChave = uiHTMLEncode(oPalavraChave.value);
	var valor = oValor.value;
	var regiao = oRegiao.value;
	
	if((parceiro == '' || parceiro == uiHTMLEncode('Parceiro / Nome') ) && (palavraChave == '' || palavraChave == uiHTMLEncode('Palavra chave') ) && valor == '' && regiao == '')
	{
		alert(txtalerta);
	}
	else
	{	
		if(parceiro == uiHTMLEncode('Parceiro / Nome'))
			parceiro = '';
			
		if(palavraChave == uiHTMLEncode('Palavra chave'))
			palavraChave = '';
			
		txtpesq='pesquisa.aspx?p=' + parceiro + '&v=' + valor + '&r=' + regiao + '&pc=' + palavraChave
		oParceiro.value='';
		oPalavraChave.value='';
		uiGo(txtpesq);	
	}
}
function AlterarQuantidadeProduto(idObj,quantidade)
{
	var textbox = document.getElementById(idObj);
	var total = 0;
	if(textbox != null)
	{
		total = parseInt(textbox.value);
		total = total + quantidade;
		if(total < 1)
			total = 1;
		
		textbox.value = total;
	}
}
function ChamarOutroBotao(idbotao,hfpacoteremover,idpacote)
{
	var botao = document.getElementById(idbotao);
	var hidden = document.getElementById(hfpacoteremover);
	if(hidden != null)
	{
		hidden.value = idpacote;
	}
	if(botao != null)
	{
		botao.click();
	}
}
function toogleMoradaEntrega()
{
	var ent1 = document.getElementById("Ent1");
	var ent2 = document.getElementById("Ent2");
	var ent3 = document.getElementById("Ent3");
	var ent4 = document.getElementById("Ent4");
	var ent5 = document.getElementById("Ent5");
	
	if(ent1 != null && ent2 != null && ent3 != null && ent4 != null && ent5 != null)
	{
		if(ent1.style.display == 'none')
		{
			ent1.style.display = 'inline';
			ent2.style.display = 'inline';
			ent3.style.display = 'inline';
			ent4.style.display = 'inline';
			ent5.style.display = 'inline';
		}
		else
		{
			ent1.style.display = 'none';
			ent2.style.display = 'none';
			ent3.style.display = 'none';
			ent4.style.display = 'none';
			ent5.style.display = 'none';
		}
	}
}

function IsEmailAddress(email) {
	var s = "", re;
	s = "" + email + "";
	if (s.length == 0) {return true;}
	s = s.replace(/^\s*|\s*$/g, "");
	if (s == "undefined" || s.length < 6) {return false;}
	re = /\s+/g
	if (re.test(s)) {return false;}
	re = /^(\w|[^_]\.|[\-])+((\@){1}([^_]))(([a-z]|[\d]|[\-]|\.)+|([^_]\.[^_])*)+\.[a-z]{2,6}$/i
	if (!re.test(s)) {return false;}
	re = /\.(a[c-gil-oq-uwz]|b[a-bd-jm-or-tvwyz]|c[acdf-ik-orsuvx-z]|d[ejkmoz]|e[ceghr-u]|f[i-kmorx]|g[abd-ilmnp-uwy]|h[kmnrtu]|i[delm-oq-t]|j[emop]|k[eg-imnprwyz]|l[a-cikr-vy]|m[acdghk-z]|n[ace-giloprtuz]|om|p[ae-hk-nrtwy]|qa|r[eouw]|s[a-eg-ort-vyz]|t[cdf-hjkm-prtvwz]|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[admrw]|com|edu|net|org|mil|gov|biz|pro|aero|coop|info|name|museum)$/i
	if (!re.test(s)) {return false;}
	re = /\.\./
	if (re.test(s)) {return false;}
	re = /\@\@/
	return(!re.test(s));
}

function submitenterNews(e, txtalerta)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;

	if(keycode == 13)
	{
		inscreverNewsletter(txtalerta);
		return false;
	}
	return true;	
}
function inscreverNewsletter(txtalerta)
{
	var vEmail;
	var link;
	
	vEmail = document.getElementById('tbInscNewsletter');	
	var emailTxt=vEmail.value;
	
	if(emailTxt == '' || !IsEmailAddress(emailTxt))
	{
		alert(txtalerta);
		vEmail.value='';
		vEmail.focus();
	}
	else
	{
		link='inscricaonewsletter.aspx?e=' + emailTxt;
		//uiGo(link);
		window.open(link,'','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=421,height=250,left=200,top=200');
		vEmail.value='';		
	}
}
