// JavaScript Document

function mostraFlash(src, larg, alt, wmode)
{
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
	flash += '<param name="movie" value="'+ src +'" />';
	flash += '<param name="allowScriptAccess" value="sameDomain" />';
	flash += '<param name="menu" value="false" />';	
	flash += '<param name="wmode" value="'+ wmode +'" />';	
	flash += '<embed src="'+ src +'" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'" menu = "false" wmode = "'+ wmode +'"></embed>';
	flash += '</object>';	
	
	document.write(flash);
}

function confereCep(cep)
{
	if(cep.value.length == 5)
	{
		$('#cep2').focus();
	}
}

/* sIFR */
var swf = {src: '_swfs/sifr.swf'};
		
sIFR.activate(swf);

sIFR.replace(swf, {
	selector: '.title',
	wmode: 'transparent',
	css: '.sIFR-root {color: #7a7a7a; font-weight: bold; }'
} );

sIFR.replace(swf, {
	selector: '.title2',
	wmode: 'transparent',
	css: '.sIFR-root {color: #FFFFFF; }'
} );

sIFR.replace(swf, {
	selector: '.title3',
	wmode: 'transparent',
	css: '.sIFR-root {color:#2c5c8c; font-weight:bold;font-size:20px; }'
} );

sIFR.replace(swf, {
	selector: '.title4',
	wmode: 'transparent',
	css: '.sIFR-root {color: #7a7a7a;font-size:14px; }'
} );

sIFR.replace(swf, {
	selector: '.title5',
	wmode: 'transparent',
	css: '.sIFR-root {color: #578cc2;font-size:17px; }'
} );

sIFR.replace(swf, {
	selector: '.title6',
	wmode: 'transparent',
	css: '.sIFR-root {color: #FFFFFF;font-size:26px; }'
} );


/* jQuery */

function atualiza(id)
{
	$('#alvo').hide();
	
	$('#loading').ajaxStart(function(){			
		//$('#alvo').hide();			
		$('#loading').show();			
	});		
	$('#loading').ajaxStop(function(){			
		$('#loading').hide();			
	});		
	$.post('../_includes/inc_produtos_detalhes.php',		
	{busca: id},		
	function(data){			
		$('#alvo').show();				
		$('#alvo').empty().html(data);			
	}		
	);
}

function buscaProduto(busca)
{
	$('#alvo').hide();
	
	$('#loading').ajaxStart(function(){						
		$('#loading').show();			
	});		
	$('#loading').ajaxStop(function(){			
		$('#loading').hide();			
	});		
	$.post('../_includes/inc_produtos_detalhes.php',		
	{pesquisa: busca},		
	function(data){			
		$('#alvo').show();				
		$('#alvo').empty().html(data);	
		$('html, body').animate({scrollTop: $('#alvo').offset().top}, 2000);
	}		
	);
}

function verificaCPF(cpf)
{
	$('#alvo').hide();
	
	$('#loading').ajaxStart(function(){						
		$('#loading').show();			
	});		
	$('#loading').ajaxStop(function(){			
		$('#loading').hide();			
	});		
	$.post('../_includes/inc_verificacpf.php',		
	{cpf: cpf},		
	function(data){			
		$('#alvo').show();				
		$('#alvo').empty().html(data);	
	}		
	);
}

function recuperarSenha(cpf)
{
	$('#alvo').hide();
	
	$('#loading').ajaxStart(function(){						
		$('#loading').show();			
	});		
	$('#loading').ajaxStop(function(){			
		$('#loading').hide();			
	});		
	$.post('../_includes/inc_recuperapassword.php',		
	{cpf: cpf},		
	function(data){			
		$('#alvo').show();				
		$('#alvo').empty().html(data);	
	}		
	);
}

$(function() {	 
	
	if($('#slider') != null){
		$("#slider").easySlider();
	}

	if($('ul#menu li.parent > a') != null){
		$('ul#menu li.parent > a').click(function() {
			$('ul.sub-menu', $(this).parent()).slideToggle('fast', function() {
			});
			return false;
		});
	}
	
	if($('#loading') != null){
		$('#loading').hide();
	}
	
	//Carousel
	if($(".anyClass") != null){
		$(".anyClass").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			circular: true
		});
	}
	
	// MENU  
	if($('#flat') != null){
		$('#flat').menu({ 
			content: $('#flat').next().html(), // grab content from this page
			showSpeed: 400 
		});
	}
	
	// valida o formulário
	if($('#form-passo1') != null){
		$('#form-passo1').validate({
			// define regras para os campos
			rules: {
				// passo 1
				cpf: {
					required: true,
					minlength: 10
				},
				nome: {
					required: true,
					minlength: 2
				},
				email: {
					email: true,
					required: true
				},
				endereco: {
					required: true
				},
				uf: {
					required: true
				},
				bairro: {
					required: true
				},
				datanascimento: {
					required: true
				},
				sexo: {
					required: true
				},
				fone: {
					required: true
				}
	
			},
			// define messages para cada campo
			messages: {
				//passo1
				cpf: "<div style='color:Red'>Preencha o CPF</div>",
				nome: "<div style='color:Red'>Preencha o seu nome</div>",
				email: "<div style='color:Red'>Endere&ccedil;o de e-mail inv&aacute;lido</div>",
				endereco: "<div style='color:Red'>Informe seu endere&ccedil;o</div>",
				uf: "<div style='color:Red'>Informe seu estado</div>",
				bairro: "<div style='color:Red'>Informe seu bairro</div>",
				datanascimento: "<div style='color:Red'>Informe sua data de nascimento</div>",
				numfilhos: "<div style='color:Red'>Informe o n&uacute;mero de filhos</div>",
				sexo: "<div style='color:Red'>Informe seu sexo</div>",
				fone: "<div style='color:Red'>Informe ao menos um telefone</div>"
			}
		});
		
		$('#form-passo2').validate({
			// define regras para os campos
			rules: {
				cargo1: {
					required: true
				}
	
			},
			// define messages para cada campo
			messages: {
				cargo1: "<div style='color:Red'>Informe ao menos um cargo</div>"
			}
		});
		
		$('#form-faleconosco').validate({
			// define regras para os campos
			rules: {
				// passo 1
				unidade: {
					required: true
				},
				nome: {
					required: true,
					minlength: 2
				},
				email: {
					email: true,
					required: true
				},
				telefone: {
					required: true
				},
				cidade: {
					required: true
				},
				estado: {
					required: true
				},
				assunto: {
					required: true
				},
				mensagem: {
					required: true
				}
	
			},
			// define messages para cada campo
			messages: {
				//passo1
				unidade: "<span style='color:Red'> * Selecione uma unidade</span>",
				nome: "<div style='color:Red;margin-top:-2px'> * Preencha o seu nome</div>",
				email: "<div style='color:Red;margin-top:-2px'> * Endere&ccedil;o de e-mail inv&aacute;lido</div>",
				telefone: "<div style='color:Red;margin-top:-2px'> * Informe seu telefone</div>",
				empresa: "<div style='color:Red;margin-top:-2px'> * Informe a empresa</div>",
				cidade: "<div style='color:Red;margin-top:-2px'> * Informe a cidade</div>",
				pais: "<div style='color:Red;margin-top:-2px'> * Informe o pais</div>",
				estado: "<div style='color:Red;margin-top:-2px'> * Informe o estado</div>",
				assunto: "<div style='color:Red;margin-top:-2px'> * Informe o assunto</div>",
				mensagem: "<div style='color:Red;margin-top:-2px'> * Digite a mensagem</div>"
			}
		});
	}
	//validação
	if($("#datanascimento") != null)
		$("#datanascimento").mask("99/99/9999");
	if($("#cep") != null)
		$("#cep").mask("99999-999");
	if($("#fone") != null)
		$("#fone").mask("(99)9999-9999");
	if($("#foneresidencial") != null)
		$("#foneresidencial").mask("(99)9999-9999");
	if($("#celular") != null)
		$("#celular").mask("(99)9999-9999");
	if($("#telefone") != null)
		$("#telefone").mask("(99)9999-9999");
	if($("#dataentrada") != null)
		$("#dataentrada").mask("99/9999");
	if($("#datasaida") != null)
		$("#datasaida").mask("99/9999");
		
	//Galeria
	//these are the default settings for the component 
	// you can redefine this defaults or change each parameter on the component call 
	$.fn.mbGallery.defaults={ 
		galleryWidth: 300, 
		galleryHeight: 300, 
		galleryMaxWidth: 0, 
		galleryColor: "#333", 
		galleryFrameBorder: 12, 
		galleryFrameColor: "#fff", 
		maskOpacity:.5, 
		maskBgnd:"#000", 
	
		startFrom: "random", 
		headerOpacity: 0.8, 
		thumbsBorder: 4, 
		thumbHeight: 50, 
		thumbStripWidth:250, 
		thumbStripColor: "#333333", 
		thumbStripPos: "right", 
		thumbSelectColor: "black", 
		thumbOverColor: "#cccccc", 
		imageSelector: ".imgFull", 
		thumbnailSelector: ".imgThumb", 
		descSelector: ".imgDesc", 
		descriptionWidth:300, 
	
		labelColor: "#333", 
		labelColorDisactive: "#333", 
		labelTextColor: "#fff", 
		labelTextSize: "11px", 
		labelHeight: 20, 
	
		iconFolder: "_images/elements/white", 
		fadeTime: 500, 
		autoSlide: true, 
		slideTimer: 6000, 
		autoSize: true, 
		startTimer:0 
	}; 
});

//this is a direct call on document load 
$('#g1').mbGallery({maskBgnd:'#f0f0f0', maskOpacity:.8}); 

// this is a call attached to an event 
$('#galleryOpener') 
  .bind("click", function(){ 
		$('#g1').mbGallery({maskBgnd:'#f0f0f0', maskOpacity:.8}); 
});
  
//JMonthCalendar


function chkFaq(){
	d = document.formpergunta;

	if (d.nome.value == ""){
		alert("Para enviar uma pergunta o campo " + d.nome.name + " deve ser preenchido!");
		d.nome.focus();
		return false;
	}
	if (d.email.value == ""){
		alert("Para enviar uma pergunta o campo " + d.email.name + " deve ser preenchido!");
		d.email.focus();
		return false;
	}
	if (d.pergunta.value == ""){
		alert("Para enviar uma pergunta o campo " + d.pergunta.name + " deve ser preenchido!");
		d.pergunta.focus();
		return false;
	}
	d.submit();
	return true;
}


function chkMaterial(){
	d = document.formmateriais;

	if (d.nome.value == ""){
		alert("Para solicitar um material o campo " + d.nome.name + " deve ser preenchido!");
		d.nome.focus();
		return false;
	}
	if (d.email.value == ""){
		alert("PPara solicitar um material o campo " + d.email.name + " deve ser preenchido!");
		d.email.focus();
		return false;
	}
	if (d.pergunta.value == ""){
		alert("PPara solicitar um material o campo " + d.pergunta.name + " deve ser preenchido!");
		d.pergunta.focus();
		return false;
	}
	d.submit();
	return true;
}

function buscar()
{
	location="?section=pesquisa&query="+$('#busca').val()+"";
}

function submitMe(tecla)
{
	if(tecla == 13)
		location="?section=pesquisa&query="+$('#busca').val()+"";
}