

//if(pageTracker) pageTracker._trackEvent(_ele.getAttribute('gCat'),_ele.getAttribute('gAction'),_ele.getAttribute('gLabel'),_ele.getAttribute('gValue'));
	
function sendWindowForm( divForm, _form ){
	
	_form = $('#'+_form);
	
	if($(_form).validate().form()){
		divResp = 'emailResponse'+divForm;
		
			if($('#'+divResp).length < 1){
				$(_form).append('<div id="'+divResp+'" class="emailResponse"><div id="emailResponseMsg">Enviando...</div></div>');
			}
			$.ajax({
					  url: 'http://www.mesacor.com.br/_Request/',
					  data: _form.serialize(),
					  dataType: 'json',
					  cache: false,
					  type: 'POST',
					  complete: function(resposta) {
						  try
							{
								res = jQuery.parseJSON( resposta.responseText );
								
								if(res.status == 'ok'){
									
									if(res.mensagem){
										$("body").append('<div id="dialog">'+res.mensagem+'</div>');
										$("#dialog").dialog({
													modal: true,
													buttons: {
														Ok: function() {
															$(this).dialog('destroy');
															$("#dialog").remove();
														}
													}
												});
									}else{
										$("body").append('<div id="dialog">'+res.erro+'</div>');
										$("#dialog").dialog({
													modal: true,
													buttons: {
														Ok: function() {
															$(this).dialog('destroy');
															$("#dialog").remove();
														}
													}
												});
									}
									if(res.script)
										eval(res.script);
								}else{
										$("body").append('<div id="dialog">'+res.mensagem+'</div>');
										$("#dialog").dialog({
													modal: true,
													buttons: {
														Ok: function() {
															$(this).dialog('destroy');
															$("#dialog").remove();
														}
													}
												});
								}
							}
							catch(e)
							{
							  $("body").append('<div id="dialog">'+resposta.responseText+'</div>');
							  $("#dialog").dialog({
										  modal: true,
										  buttons: {
											  Ok: function() {
												  $(this).dialog('destroy');
												  $("#dialog").remove();
											  }
										  }
									  });
							}
					  }
			});
	}
		
	return false;
}
$(document).ready(function() {
			$("a.imgZoom").fancybox({
				'type'				: 'image',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Imagem: ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
			$("a.ajaxZoom").fancybox({
				'type'				: 'ajax'
			});
			$('input:text').setMask();
			
			$(".catPlus").click(function(){
										 $(this).next('ul').slideToggle(300);
										 });
			
			$("a[href="+window.location+"]").parent().parent().show()
			$("a[href="+window.location+"]").addClass('current');
			$("a[href="+window.location+"]").next().next().toggle();
			
			$("#cadastreseForm").validate();
			$("#formularioForm").validate({
				rules: { 
						senha: { 
							required: false, 
							minlength: 5 
						}, 
						confirmacao: { 
							required: false, 
							minlength: 5, 
							equalTo: "#senha" 
						}, 
//						email: { 
//							required: true, 
//							email: true, 
//							remote: "emails.php" 
//						},
						nome: {
						  required: "#pessoaFisica:checked"
						},
						cpf: {
						  required: "#pessoaFisica:checked"
						},
						rg: {
						  required: "#pessoaFisica:checked"
						},
						razao_social: {
						  required: "#pessoaJuridica:checked"
						},
						cnpj: {
						  required: "#pessoaJuridica:checked"
						},
						cep: {
							minlength: 9
						}
					}, 
				messages: {
					cpf: "Este campo &eacute; obrigat&oacute;rio.",
					telefone: "Este campo &eacute; obrigat&oacute;rio.",
					endereco: "Este campo &eacute; obrigat&oacute;rio.",
					numero: "Este campo &eacute; obrigat&oacute;rio.",
					remote: "Please fix this field.",
					email: "Este e-mail n&atilde;o &eacute; v&aacute;lido.",
					url: "Please enter a valid URL.",
					date: "Please enter a valid date.",
					dateISO: "Please enter a valid date (ISO).",
					number: "Please enter a valid number.",
					digits: "Please enter only digits",
					creditcard: "Please enter a valid credit card number.",
					equalTo: "Digite igual ao campo Senha.",
					accept: "Please enter a value with a valid extension.",
					cep: {
						required: "Por favor, informe o seu CEP",
						minlength: "Preencha todos os 8 dígitos do seu CEP"
					},
				}
			});
			
			
			
			$('#listadeProdutos').masonry({
				// 
				columnWidth: 194, 
				animate: true,
				animationOptions: {
					duration: 300,
					easing: 'linear',
					queue: false
				  }
			  });
			
			
			
								/*
								* Author:      Marco Kuiper (http://www.marcofolio.net/)
								*/
								
								// Speed of the automatic slideshow
								var slideshowSpeed = 6000;
								
								// Variable to store the images we need to set as background
								// which also includes some text and url's.
								
								
										
									// Backwards navigation
									$("#back").click(function() {
										stopAnimation();
										navigate("back");
									});
									
									// Forward navigation
									$("#next").click(function() {
										stopAnimation();
										navigate("next");
									});
									
									var interval;
									$("#control").toggle(function(){
										stopAnimation();
									}, function() {
										// Change the background image to "pause"
										$(this).css({ "background-image" : "url(http://www.mesacor.com.br/_imagens/btn_pause.png)" });
										
										// Show the next image
										navigate("next");
										
										// Start playing the animation
										interval = setInterval(function() {
											navigate("next");
										}, slideshowSpeed);
									});
									
									
									var activeContainer = 1;	
									var currentImg = 0;
									var animating = false;
									var navigate = function(direction) {
										// Check if no animation is running. If it is, prevent the action
										if(animating) {
											return;
										}
										
										// Check which current image we need to show
										if(direction == "next") {
											currentImg++;
											if(currentImg == photos.length + 1) {
												currentImg = 1;
											}
										} else {
											currentImg--;
											if(currentImg == 0) {
												currentImg = photos.length;
											}
										}
										
										// Check which container we need to use
										var currentContainer = activeContainer;
										if(activeContainer == 1) {
											activeContainer = 2;
										} else {
											activeContainer = 1;
										}
										
										showImage(photos[currentImg - 1], currentContainer, activeContainer);
										
									};
									
									var currentZindex = -1;
									var showImage = function(photoObject, currentContainer, activeContainer) {
										animating = true;
										
										// Make sure the new container is always on the background
										currentZindex--;
										
										// Set the background image of the new active container
										$("#bannerimg" + activeContainer).css({
											"background-image" : "url(" + photoObject.image + ")",
											"display" : "block",
											"z-index" : currentZindex
										}).attr("href", photoObject.url).click(function() {
											_gaq.push(['_trackEvent', 'Banner', 'Click', photoObject.title]);
										});
										
										$("#bannerimg" + currentContainer).fadeOut(function() {
											setTimeout(function() {
												$("#headertxt").css({"display" : "block"});
												animating = false;
											}, 500);
										});
										
									};
									
									var stopAnimation = function() {
										// Change the background image to "play"
										$("#control").css({ "background-image" : "url(http://www.mesacor.com.br/_imagens/btn_play.png)" });
										
										// Clear the interval
										clearInterval(interval);
									};
									
									// We should statically set the first image
									navigate("next");
									
									// Start playing the animation
									interval = setInterval(function() {
										navigate("next");
									}, slideshowSpeed);
									
	}
)
function enviaBusca(){
	window.location = 'http://www.mesacor.com.br/Produtos/Busca/'+$('#campobusca').val();
	return false;
}



	function carregaCep( _cep ){
		$('#carregandoCEP').html("Consultando CEP " + _cep).fadeIn();
		$.ajax({
			url: 'http://www.mesacor.com.br/_Request' + '/carregaCEP/'+_cep, 
			complete: function(resposta){
					var res = $.parseJSON( resposta.responseText );
					if(res){
						if(res.logradouro){
							$('#endereco').val(res.logradouro);
						}
						$('#carregandoCEP').html('Selecionando estado');
						if(res.estado){
							//$('#idestados').selectedIndex = res.estado;
							$('#estado').val(res.estado);
						}
						$('#carregandoCEP').html('Selecionando cidade');
						if(res.cidade){
							$('#carregandoCEP').html('Buscando lista de cidades');
							$('#cidade').load('http://www.mesacor.com.br/_Request' + '/carregaCidades/'+res.estado+"/"+res.cidade,
								function() {
									if(res.bairro){
										$('#carregandoCEP').html('Buscando lista de bairros');
										$('#bairro').load('http://www.mesacor.com.br/_Request' + '/carregaBairros/'+res.cidade+"/"+res.bairro);
									}else{
										$('#bairro').html("<option value=''>Outro:</option>").disable();
										$('#bairro').append('<input type="text" id="bairro" name="bairro" class="input inputTextoPequeno" value="">');
									}
								});
						}
					}else{
						alert('O CEP digitado não é válido')
					}
					$('#carregandoCEP').html('Carregando...').fadeOut();
			}
		});
		
	}
	function carregaCidades( _estado , _preSeleciona ){
		$('#carregandoCEP').html("Carregando lista de cidades").show();
		$('#cidade').html("<option value=''>Carregando</option>");
		$('#cidade').load('http://www.mesacor.com.br/_Request' + '/carregaCidades/'+_estado+"/"+_preSeleciona,
			function() {
				$('#carregandoCEP').html('Carregando...').hide();
			});
		$('#bairro').html("<option value=''>Selecione uma cidade</option>");
		
	}
	
	function carregaBairros( _cidade , _preSeleciona){
		$('#carregandoCEP').html("Carregando lista de bairros").show();
		$('#bairro').html("<option value=''>Carregando</option>");
		$('#bairro').load('http://www.mesacor.com.br/_Request' + '/carregaBairros/'+_cidade+"/"+_preSeleciona,
			function() {
				$('#carregandoCEP').html('Carregando...').hide();
			});
		
	}



