
	function combo(uf_id, cidade_id) {
		url_padrao = $('#path_www').text(); 
		$.ajax({
            type: "POST",
            url:  url_padrao + "/include/cidades.php",
            data: "id=" + uf_id + "&cidade_id=" + cidade_id,
            beforeSend: function() {
            	// enquanto a função esta sendo processada, você pode exibir na tela uma ...
        		$('#comboCidades').html('Processando...'); // ...mensagem de espera
        	},
        	success: function(txt) { // executa quando o servidor responde
        		//alert (txt);
	            // Pego a div com id = combo2 que está dentro de um select 
	            //e substituo seu conteudo com o texto enviado pelo php
	            $('#comboCidades').html(txt);
        		//$('#comboCores' + linha).append('<option value=1>Jef</option>');
        		//$('#comboCores' + linha).addOption(myOptions, false); // use true if you want to select the added options » Run
	            //alert(txt);
        	},
        	error: function(txt) { // executa quando não responde ou envia um erro
	            // em caso de erro você pode dar um alert('msg erro');
	            alert('Desculpe, houve um erro interno, tente mais tarde.');
            }
        });
    }
	
	
	jQuery(function(){
		$(".cep").mask("99999-999");
		$(".fone").mask("(99) 9999.9999");
		$(".cnpj").mask("99.999.999/9999-99");
		$(".cpf").mask("999.999.999-99");
		
		$('.confirm').live('click', function() {
			if (!confirm('Tem certeza que deseja excluir?')) {
				return false;
			}
		});
		
		$("#form_cadastro").submit(function() {
			$("#msgbox-newaccount").removeClass().addClass('messagebox').text('Validando...').fadeIn(1000);
			var dados = { 'subcategorias' : []};
			$("input[name='subcategorias[]']:checked").each(function() { 
				dados['subcategorias'].push($(this).val());
			});
			$("input[name='termos']:checked").each(function() { 
				dados['termos'] = '1';
			});
			$("input[type='radio']:checked").each(function() { 
				dados['subcategorias'].push($(this).val());
			});
			$("select[name='cidade_id']").each(function() {
				dados['cidade_id'] = $('option:selected').val();
			});
			$(this).find("input").each(function(){
				if ($(this).attr('type') != 'checkbox' && $(this).attr('type') != 'radio') {
					var a = $(this).attr('name');
				    var b = $(this).val();
				    dados[a] = b;
				}
			});
	    	//check the username exists or not from ajax
		    $.post($('#path_www').text() + "/cadastro/concluir", dados, function(data) {
		    	if (data == 1) {
	    			$('#form_cadastro').slideUp('slow');
	    			$('#msgbox-newaccount').html('Cadastro concluído. Redirecionando...').fadeTo(1100,1, function() {
    					document.location = $('#path_www').text() + '/restrito/painel-de-controle';
    				});
	    		} else {
	    			$("#msgbox-newaccount").fadeTo(200,0.1,function() {
	    				$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		}
		    });
	    	return false;
	    });
		
		/**
		 * RESTRITO - ALTERAR MEUS DADOS
		 */
		$("#form_cadastro_update").submit(function() {
			$("#msgBoxCadastroUpdate").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			var dados = { };
			$("select[name='cidade_id']").each(function() {
				dados['cidade_id'] = $('option:selected').val();
			});
			$("input[name='termos']:checked").each(function() { 
				dados['termos'] = 1;
			});
			$(this).find("input").each(function(){
				if ($(this).attr('type') != 'checkbox' && $(this).attr('type') != 'radio') {
					var a = $(this).attr('name');
				    var b = $(this).val();
				    dados[a] = b;
				}
			});
		    $.post($('#path_www').text() + "/ajax/atualizarCadastro.php", dados, function(data) {
		    	if (data == '1') {
		    		$('#form_cadastro').slideUp('slow');
	    			$('#msgBoxCadastroUpdate').removeClass('notice error').addClass('success').html('Cadastro atualizado.').fadeTo(1100,1, function() {
	    				$("#mc" + dados['bloco']).slideUp('slow');
	    				$("#completeCadastro").hide();
	    				$("#menuRestrito").show();
	    				$("#titulo" + dados['bloco']).removeClass("mctop-open");
	                    $("#titulo" + dados['bloco']).addClass("mctop-closed");
	                    $('#msgBoxCadastroUpdate').hide();
    				});
	    		} else {
	    			$("#msgBoxCadastroUpdate").fadeTo(200,0.1,function() {
	    				$(this).removeClass('notice sucess').addClass('error').html(data).fadeTo(900,1);
	    			});
	    		}
		    });
	    	return false;
	    });
		
		/**
		 * RESTRITO - ALTERAR SENHA
		 */
		$("#form_cadastro_update_senha").submit(function() {
			$("#msgBoxCadastroUpdateSenha").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			var dados = {};
			$(this).find("input").each(function(){
				if ($(this).attr('type') != 'checkbox' && $(this).attr('type') != 'radio') {
					var a = $(this).attr('name');
				    var b = $(this).val();
				    dados[a] = b;
				}
			});
		    $.post($('#path_www').text() + "/ajax/atualizarSenha.php", dados, function(data) {
		    	if (data == '1') {
		    		$('#form_cadastro').slideUp('slow');
	    			$('#msgBoxCadastroUpdateSenha').removeClass('notice error').addClass('success').html('Senha atualizada.').fadeTo(1100,1, function() {
	    				$("#mc" + dados['bloco']).slideUp('slow');
	    				$("#titulo" + dados['bloco']).removeClass("mctop-open");
	                    $("#titulo" + dados['bloco']).addClass("mctop-closed");
	                    $('#msgBoxCadastroUpdateSenha').hide();
	                    $('#novaSenha').val('');
	                    $('#novaSenha2').val('');
    				});
	    		} else {
	    			$("#msgBoxCadastroUpdateSenha").fadeTo(200,0.1,function() {
	    				$(this).removeClass('notice sucess').addClass('error').html(data).fadeTo(900,1);
	    			});
	    		}
		    });
	    	return false;
	    });
		
		
		/**
		 * RESTRITO - ALTERAR SUBCATEGORIAS
		 */
		$("#form_cadastro_update_subcategorias").submit(function() {
			$("#msgBoxCadastroUpdateSubcat").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			var dados = $(this).serialize();
			var bloco = $(this).find('input[name=bloco]').val();
		    $.post($('#path_www').text() + "/ajax/atualizarSubcategorias.php", dados, function(data) {
		    	if (data == '1') {
		    		$('#form_cadastro').slideUp('slow');
	    			$('#msgBoxCadastroUpdateSubcat').removeClass('notice error').addClass('success').html('Cadastro atualizado.').fadeTo(1100,1, function() {
	    				$("#mc" + bloco).slideUp('slow');
	    				$("#titulo" + bloco).removeClass("mctop-open").addClass("mctop-closed");
	                    $('#msgBoxCadastroUpdateSubcat').hide();
    				});
	    		} else {
	    			$("#msgBoxCadastroUpdateSubcat").fadeTo(200,0.1,function() {
	    				$(this).removeClass('notice sucess').addClass('error').html(data).fadeTo(900,1);
	    			});
	    		}
		    });
	    	return false;
	    });
		
		/**
		 * RESTRITO - ALTERAR MARCAS
		 */
		$("#form_cadastro_marcas").submit(function() {
			$("#msgBoxAddMarcas").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			var dados = {};
			$(this).find("input").each(function(){
				if ($(this).attr('type') != 'checkbox' && $(this).attr('type') != 'radio') {
					var a = $(this).attr('name');
				    var b = $(this).val();
				    dados[a] = b;
				}
			});
		    $.post($('#path_www').text() + "/ajax/atualizarMarcas.php", dados, function(data) {
		    	if (data == '1') {
		    		$('#form_cadastro').slideUp('slow');
	    			$('#msgBoxAddMarcas').removeClass('notice error').addClass('success').html('Marca(s) atualizada(s).').fadeTo(1100,1, function() {
	    				$("#mc" + dados['bloco']).slideUp('slow');
	    				$("#titulo" + dados['bloco']).removeClass("mctop-open").addClass("mctop-closed");
	                    $('#msgBoxAddMarcas').hide();
    				});
	    		} else {
	    			$("#msgBoxAddMarcas").fadeTo(200,0.1,function() {
	    				$(this).removeClass('notice sucess').addClass('error').html(data).fadeTo(900,1);
	    			});
	    		}
		    });
	    	return false;
	    });
		
		/**
		 * RESTRITO - ADICIONAR GALERIA
		 */
		$("#form_cadastrar_galeria").submit(function() {
			var dados = $(this).serialize();
			$("#msgBox").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			$.ajax({
				type: 'POST',
				url: $('#path_www').text() + "/ajax/galerias.php?action=add",
				data: dados,
				success: function(msg) {
					if (msg.substr(0,2) == 'id') {
						// redireciona
						$('#msgBox').removeClass('notice error').addClass('success').html('Galeria cadastrada. Redirecionando...').fadeTo(1100,1, function() {
							window.location = $('#path_www').text() + '/restrito/produtos/adicionar-imagem/' + msg.substr(3);
						});
					} else {
						$("#msgBox").fadeTo(200,0.1,function() {
							$(this).removeClass('notice sucess').addClass('error').html(msg).fadeTo(900,1);
						});
	    			}
	    		}
			});
	    	return false;
	    });
		
		$("#form_cadastrar_galeria_admin").submit(function() {
			var dados = $(this).serialize();
			$("#msgBox").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			$.ajax({
				type: 'POST',
				url: $('#path_www').text() + "/ajax/galerias.php?action=add",
				data: dados,
				success: function(msg) {
					if (msg.substr(0,2) == 'id') {
						// redireciona
						$('#msgBox').removeClass('notice error').addClass('success').html('Galeria cadastrada. Redirecionando...').fadeTo(1100,1, function() {
							window.location = $('#path_www').text() + '/admin/produtos.php?action=adicionar-imagem&id=' + msg.substr(3);
						});
					} else {
						$("#msgBox").fadeTo(200,0.1,function() {
							$(this).removeClass('notice sucess').addClass('error').html(msg).fadeTo(900,1);
						});
	    			}
	    		}
			});
	    	return false;
	    });
		
		/**
		 * RESTRITO - EDITAR GALERIA
		 */
		$("#form_atualizar_galeria").submit(function() {
			var dados = $(this).serialize();
			$("#msgBox").removeClass('error sucess').addClass('notice').show().text('Validando...').fadeIn(1000);
			$.ajax({
				type: 'POST',
				url: $('#path_www').text() + "/ajax/galerias.php?action=edit",
				data: dados,
				success: function(msg) {
					if (msg.substr(0,2) == 'id') {
						// redireciona
						$('#msgBox').removeClass('notice error').addClass('success').html('Galeria atualizada. Redirecionando...').fadeTo(1100,1, function() {
							window.location.href = $('#path_www').text() + '/restrito/produtos/';
						});
					} else {
						$("#msgBox").fadeTo(200,0.1,function() {
							$(this).removeClass('notice sucess').addClass('error').html(msg).fadeTo(900,1);
						});
	    			}
	    		}
			});
	    	return false;
	    });
		
		/**
		 * RESTRITO - EXCLUIR IMAGEM
		 */
		$(".btnExcluirImagem").live('click', function() {
			
			if (confirm('Deseja remover esta imagem?')) {
				var id = $(this).val();
				$('#btn' + id).attr('src', $('#path_www').text() + '/css/loading.gif');
				$.ajax({
					type: 'POST',
					url: $('#path_www').text() + "/ajax/imagens.php?action=excluir",
					data: 'imagem_id='+id,
					success: function(msg) {
						$('#imagem' + id).fadeOut();
		    		}
				});
		    	return false;
			} else {
				return false;
			}
	    });
		
		/**
		 * ADMIN - REPROVAR IMAGEM
		 */
		$(".btnReprovarImagem").live('click', function() {
			
			if (confirm('Deseja reprovar esta imagem?')) {
				var id = $(this).val();
				$('#btnReprovar' + id).attr('src', $('#path_www').text() + '/css/loading.gif');
				$.ajax({
					type: 'POST',
					url: $('#path_www').text() + "/ajax/imagens.php?action=reprovar",
					data: 'imagem_id='+id,
					success: function(retorno) {
						var obj = jQuery.parseJSON(retorno);
						$('#imagem' + id).fadeOut();
						atualizaGaleria(obj.cadastro_id, obj.galeria_id, 'reprovadas', 0);
		    		}
				});
		    	return false;
			} else {
				return false;
			}
	    });
		
		/**
		 * ADMIN - REPROVAR IMAGEM
		 */
		$(".btnAprovarImagem").live('click', function() {
			var id = $(this).val();
			$('#btnAprovar' + id).attr('src', $('#path_www').text() + '/css/loading.gif');
			$.ajax({
				type: 'POST',
				url: $('#path_www').text() + "/ajax/imagens.php?action=aprovar",
				data: 'imagem_id='+id,
				success: function(retorno) {
					var obj = jQuery.parseJSON(retorno);
					$('#imagem' + id).fadeOut();
					atualizaGaleria(obj.cadastro_id, obj.galeria_id, 'aprovado', 0);
	    		}
			});
	    	return false;
	    });
		
		
		jQuery('#formularioContato').submit(function() {
			var url = $('#path_www').text();
			var dados = $(this).serialize();
			$("#resposta").html('E-mail sendo enviada, por favor aguarde... <img src="' + url + '/css/loading.gif">');
			$.ajax({
				type: 'POST',
				url: $('#path_www').text() + "/empresa.php?action=contato",
				data: dados,
				success: function(msg) {
					if (msg == '1') {
						// redireciona
						$('#resposta').removeClass('notice error').addClass('success').html('E-mail enviado');
						$('.form').attr('value','');
					} else {
						$("#resposta").fadeTo(200,0.1,function() {
							$(this).removeClass('notice sucess').addClass('error').html(msg).fadeTo(900,1);
						});
	    			}
	    		},
	    		error: function(xhr, er) {
					jQuery('#resposta').html(xhr.status + ' ' + xhr.statusText + ' ' + er);
				}
			});
			return false;
		});
		
		
	});

	/*
	jQuery(function(){
		$("#formularioContatoSite").validate({
			rules: {
				nome: {
					required: true
				},
				email: {
					required: true,
					email: true
				},
				assunto: {
					required: true
				},
	            cidade:{
	                required: true
	            },
	            mensagem: {
	            	required: true
	            }
			},
			messages: {
				nome: {
					required: "Campo obrigatório."
				},
				email: {
					required: "Campo obrigatório.",
					email: "E-mail inválido"
				},
				assunto: {
					required: "Campo obrigatório."
				},
				cidade:{
	            	required: "Campo obrigatório."
	            },
	            mensagem: {
	            	required: "Campo obrigatório."
	            }
				
			}
		});
	});
	*/
	
	/*
	jQuery(document).ready(function() {
		$('table#list tr:odd').addClass('impar');
		$('table#list tr:even').addClass('par');
		$('table#list tr').hover(
	        function() {
	        	$(this).addClass('destacar');
	        },
	        function() {
	        	$(this).removeClass('destacar');
	        }
	    );
	});
	*/
	
	function setDominio(dominio) {
		document.getElementById('dominio').value = dominio;
	}
	
	/**
	 * RESTRITO - ATUALIZA GALERIA FOTOS
	 */
	function atualizaGaleria(cadastro_id, galeria_id, status, admin) {
		$.ajax({
			type: 'POST',
			url: $('#path_www').text() + "/ajax/galerias.php?action=view",
			data: 'cadastro_id=' + cadastro_id + '&galeria_id=' + galeria_id + '&admin=' + admin + '&status=' + status,
			success: function(msg) {
				//alert(msg);
				$('#' + status).removeClass('notice').html(msg);
				
    		}
		});
    	return false;
	}
	
	/**
	 * RESTRITO - ATUALIZA GALERIA FOTOS
	 */
	function alteraFavoritos(cadastro_id, adicionado_id) {
		$('#favoritos').html('<img src="'+ $('#path_www').text() + '/css/loading.gif" />');
		$.ajax({
			type: 'POST',
			url: $('#path_www').text() + "/ajax/cadastro.php?action=favoritos",
			data: 'cadastro_id=' + cadastro_id + '&adicionado_id=' + adicionado_id,
			success: function(msg) {
				if (msg == 'adicionou') {
					$('#favoritos').html('favoritos (desfazer)');
				} else {
					$('#favoritos').html('favoritos (adicionar)');
				}
    		}
		});
    	return false;
	}
	
	function atualizaLogo(cadastro_id, diretorio) {
		$.ajax({
			type: 'POST',
			url: $('#path_www').text() + "/ajax/cadastros.php?action=view",
			data: 'cadastro_id=' + cadastro_id + '&diretorio=' + diretorio,
			success: function(msg) {
				//alert(msg);
				$('#cadastro-logo').html(msg);
    		}
		});
    	return false;
	}

