// JavaScript Document by Jorge Gonzaga Jr.

<!-- mensagem de confirmação
function confirmation(text,URL) {
	var answer = confirm(text);
	if (answer){
		parent.document.location = URL;
	}
}

function campoInteger(objeto){
	$(objeto).val($(objeto).val().replace(/\D/g, ""));
}

function campoBoolean(objeto){
	$(objeto).val($(objeto).val().replace(/([^0-9\,])/i,''));
}

//-->
<!-- inicia o menu principal
$.fn.nav_one_li = function(){
	$(this).hover(
		function(){$("ul", this).fadeIn("fast");}, 
		function() { } 
	);
  	if (document.all) {
		$(this).hoverClass ("sfHover");
	}
};
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() {$(this).addClass(c);},
			function() {$(this).removeClass(c);}
		);
	});
};
//-->
<!-- ajax lista valores cidades
function jqueryListValues(origem,destino,text){
    /*$(function(){
		if(origem == 'cidade'){
			$(("#bairro_div")).hide();
			$(("#loja_div")).hide();
			$(("#resultado_div")).hide();
                        $('#error_endereco').hide();
		}
		if(origem == 'loja'){
			$.getJSON('Scripts/search.php',{id: $(('#'+origem)).val(), ajax: 'true', tipo: destino}, function(t){
				$(("#"+destino+"_div")).html('<table width="600" border="0" cellspacing="0" cellpadding="0" class="txt"><tr><td width="16"><img src="img/seta.gif" width="8" height="10" /></td><td width="584">'+
							      t[0].texto+'<br>'+t[0].telefone+'</td></tr></table><input type="hidden" value="'+t[0].texto+' '+t[0].telefone+'" name="calculo[endere_loja]" />');
				$(("#"+destino+"_div")).show();
                                $('#error_endereco').hide();
			});
		}else{
			var options = $(("#"+destino)).attr('options');
			$.getJSON('Scripts/search.php',{id: $(('#'+origem)).val(), ajax: 'true', tipo: destino, id_cidade: $('#cidade').val()}, function(j){
			  options = '<option selected="selected">'+text+'</option>';
			  if(j != null){
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].id + '">' + j[i].nome + '</option>';
				}
				$(("#"+destino)).html(options);
				$(("#"+destino+"_div")).show();
                                $('#error_endereco').hide();
			  }
			});
		}
    })*/
	 $(function(){
		if(origem == 'cidade'){
			$(("#bairro_div")).hide();
			$(("#loja_div")).hide();
			$(("#resultado_div")).hide();
            $('#error_endereco').hide();
		}
		if(origem == 'loja'){
			/*$.getJSON('Scripts/search.php',{id: $(('#'+origem)).val(), ajax: 'true', tipo: destino}, function(t){
				$(("#"+destino+"_div")).html('<table width="600" border="0" cellspacing="0" cellpadding="0" class="txt"><tr><td width="16"><img src="img/seta.gif" width="8" height="10" /></td><td width="584">'+
							      t[0].texto+'<br>'+t[0].telefone+'</td></tr></table><input type="hidden" value="'+t[0].texto+' '+t[0].telefone+'" name="calculo[endere_loja]" />');
				$(("#"+destino+"_div")).show();
                                $('#error_endereco').hide();
			});*/
			
			$.ajax({ 
				url: "Scripts/search.php", 
				data: {id: $(('#'+origem)).val(), ajax: 'true', tipo: destino},
				success: function(data){
					$("#"+destino).empty();
					$("#"+destino).append('<option value="" selected="selected">' + text + '</option>');
					var texto;
					var telefone;
					$(data).find("item").each(function(){
						texto = $(this).find("texto").text();
						telefone = $(this).find("telefone").text();
					});

					$(("#"+destino+"_div")).html('<table width="600" border="0" cellspacing="0" cellpadding="0" class="txt"><tr><td width="16"><img src="img/seta.gif" width="8" height="10" /></td><td width="584">'+
							      texto+'<br>'+telefone+'</td></tr></table><input type="hidden" value="'+texto+' '+telefone+'" name="calculo[endere_loja]" />');
					
					$(("#"+destino+"_div")).show();
					$('#error_endereco').hide();
				}
				
			});

		}else{
			/*var options = $(("#"+destino)).attr('options');
			$.getJSON('Scripts/search.php',{id: $(('#'+origem)).val(), ajax: 'true', tipo: destino, id_cidade: $('#cidade').val()}, function(j){
			  options = '<option selected="selected">'+text+'</option>';
			  if(j != null){
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].id + '">' + j[i].nome + '</option>';
				}
				$(("#"+destino)).html(options);
				$(("#"+destino+"_div")).show();
                $('#error_endereco').hide();
			  }
			});*/
			
			$.ajax({ 
				url: "Scripts/search.php", 
				data: {id: $(('#'+origem)).val(), ajax: 'true', tipo: destino, id_cidade: $('#cidade').val()},
				success: function(data){
					$("#"+destino).empty();
					$("#"+destino).append('<option value="" selected="selected">' + text + '</option>');
					$(data).find("item").each(function(){
						var id = $(this).find("id").text();
						var desc = $(this).find("nome").text();
						$("#"+destino).append('<option value="' + id + '">' + desc + '</option>');	
					});
					if ($(data).find("item").length > 0) {
						$(("#"+destino+"_div")).show();
					}
					$('#error_endereco').hide();
				}
				
			});
		}
    })
}
//-->
<!-- lista valores cidades
$(function(){
	$('#seguinte').click(function(){
		var total = $('input').length;
        var z = 0; var saida = false;
		for(var k = 0; k < total; k++){
			var campo = $($('input')[k]);
			if(campo.attr('type') == 'radio'){
				if(!campo.attr('checked')){ z++; }
				if(z > 1){
					$('#error_sexo').show();
					saida = true;
				}else{  $('#error_sexo').hide(); }
			}else{
				if(campo.val() == '' && 'image' != campo.attr('type') && "telefone_cel" != campo.attr('id')){
					if($(('#error_'+campo.attr("id"))).html() != null){
						$(('#error_'+campo.attr("id"))).show();
						saida = true;
					}
				}else if(campo.val() != '' && 'image' != campo.attr('type') && "telefone_cel" != campo.attr('id')){
					$(('#error_'+campo.attr("id"))).hide();
				}			
			}
		}
		if(total <= 12 && 'simula4.php' == $("form").attr('action')){
			$('#error_endereco').show();
			saida = true;
		}else if('contato.php' == $("form").attr('action') && $('#mensagem').val() == ''){
			$('#error_mensagem').show();
			saida = true;
		}
		if('contato.php' != $("form").attr('action') && $('#estado').val() == ''){
			$('#error_estado').show();
			saida = true;
		}
		
		if(saida) return false;
	});
});
//-->
