/**  
 * VisãoI Sistemas
 * visaoi@visaoi.com.br
 * 
 * Rua Marcílio Dias, 26
 * Bairro Americano - Lajeado - RS
 * (51)3011-7001 | (51)8424-4494
 * 
 * DESCRIÇÃO
 * Javascripts do módulo site
 *
 * @author		Flávio Johann
 * @copyright   Copyright (c) 2005-2008 VisãoI Sistemas. (http://www.visaoi.com)
 * 
 */
 
 

/*
 * função que atualiza os bairros de acordo com a cidade escolhida
 * para o campo de busca
 */
 
$(function () {

	$('#topo').media({ 
	    width: 950,
    	height: 135,
	    autoplay:  true,
	    bgColor: '', 
	    src: baseurl+'/flash/site/topo.swf',
	    attrs:     { wmode:  'transparent' }, // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text
	});
	
	$('#topoEspanhol').media({ 
	    width: 950,
    	height: 135,
	    autoplay:  true,
	    bgColor: '', 
	    src: baseurl+'/flash/site/topoEspanhol.swf',
	    attrs:     { wmode:  'transparent' }, // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text
	});
	
	$('#visaoi').media({ 
	    width: 68,
    	height: 35,
	    autoplay:  true,
	    src: baseurl+'/flash/site/visaoi.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	$('#propaganda').media({ 
	    width: 750,
    	height: 220,
	    autoplay:  true,
	    src: baseurl+'/flash/site/propaganda.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	$('#propagandaEspanhol').media({ 
	    width: 750,
    	height: 220,
	    autoplay:  true,
	    src: baseurl+'/flash/site/propagandaEspanhol.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	$('#flash_representantes').media({ 
	    width: 500,
    	height: 370,
	    autoplay:  true,
	    bgColor: '', 
	    src: baseurl+'/flash/site/representantes.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
	
	$('#flash_representantesAmerica').media({ 
	    width: 500,
    	height: 470,
	    autoplay:  true,
	    bgColor: '', 
	    src: baseurl+'/flash/site/representantesAmerica.swf',
	    attrs:     { wmode:  'transparent' },  // object/embed attrs 
	    params:    { wmode:  'transparent' }, // object params/embed attrs 
	    caption:   false // supress caption text 
	});
	
});

//Para abrir submenus verticais em menu horizontal	
$(document).ready(function(){
	
	//Menu Colapsado
	$('UL[id^=menu_] ul').hide();
	$('UL[id^=menu_] li').click(
	  function() {
		  $(this).find('a').next().slideToggle('normal');		  
	  });
	
	 $("ul.sf-menu").superfish({ 
	        animation: {height:'show'},   // slide-down effect without fade-in 
	        delay:     400               // 1.2 second delay on mouseout 
	 	  }); 
   
	
	//Manipulação do formulario de newsletter
	$("#form_newsletter").each(function(){
		$(this).find('fieldset').css({'border':'0px','padding':'0px'});
	});
	
	var bt_salvar = $("#form_newsletter").find('#salvar');	
	
	bt_salvar.click(function(){		
		var form_news = $("#form_newsletter");
		var nome = $('FORM[id=form_newsletter] input[id = nome]').val();
		var email = $('FORM[id=form_newsletter] input[id = email]').val();
		var fone =  $('FORM[id=form_newsletter] input[id = telefone]').val();
		
		$.post(baseurl+"/site/home/news-letter/",
			{nome: nome, email:email, telefone:fone},
			function(data){
				if(data === "success"){
					mensagemBlockUI(data, msg_sucesso[3], 2000,'index');
				}else{
					mensagemBlockUI(data, msg_erro[2], 2000,'javascript:void(0);');		
				}
		});
	});
	
	
	/*Muda o idioma*/
	var idioma = $("[id^=language_]");
	idioma.click(function(){
		var locale = $(this).find('img').attr('id');
		$.post(
				baseurl+"/site/index/locale-json/",
				{locale: locale}, 
				function(data){				
					if(data){
						var sURL = unescape(window.location.pathname);
						window.location.href = sURL;
					}
				}
			);
		
	});
	
	
	   
});



/* JS dos pedidos de Orçamento */

//adiciona um item ao carrinho
function adicionaItem(id_produto) {

	var quantidade = $("#quantidade").val();
	
	/*msg_sucesso e msg_error
	 * está no script_elements => site_js_head.phtml
	 */
		
	if(quantidade != 0 && quantidade != '') {
		
		$.post(
			baseurl+"/site/pedido/adiciona-item/",
			{id_produto: id_produto, quantidade: quantidade}, 
			function(response){				
				if(response == '') {
					mensagemBlockUI('success', msg_sucesso[0], 2000, baseurl+"/site/pedido/lista-itens/");
				} else {
					mensagemBlockUI('error', msg_erro[0], 2000, '');
				}
			}
		);
		

	} else {
		mensagemBlockUI('error', msg_erro[1], 2000, '');
	}

}


// retira um item ao carrinho
function atualizaPedido(id_produto, quantidade) {
	//alert(quantidade);
	$.post(
		baseurl+"/site/pedido/atualiza-itens/",
		{id_produto: id_produto, quantidade: quantidade}, 
		function(response){				
			if(response == '') {
				if(quantidade == 0) {
					mensagemBlockUI('success', msg_sucesso[1], 2000, baseurl+"/site/pedido/lista-itens/");
				} else {
					mensagemBlockUI('success', msg_sucesso[2], 2000, baseurl+"/site/pedido/lista-itens/");
				}
				
				
			} else {
				alert(response);
				mensagemBlockUI('error', msg_erro[0], 2000, '');
			}
		}
	);
}



//Mostra o Campo CPF caso seja pessoa Física ou CNPJ caso seja Pessoa Jurídica
function mostraTipoPessoa(){	
	//Abre a div dos anexos dos editais 
	$("#form_orcamento").each(
			function() {
				var tipo = $(this).find('#tipo').val();	
				//Se foi selecionado um tipo mostro somente o campo daquele tipo
				if(tipo){
					switch(tipo){
						case 'pf':
							$(this).find('#cpf, label[for="cpf"]').show();
							$(this).find('#cnpj, label[for="cnpj"]').hide();
							$(this).find('#cnpj, label[for="cnpj"]').val('')
							break;
							
						case 'pj':
							$(this).find('#cnpj, label[for="cnpj"]').show();
							$(this).find('#cpf, label[for="cpf"]').hide();
							$(this).find('#cpf, label[for="cpf"]').val('');
							break;		
					}
				}else{
					//senão escondo as opções
					$(this).find('#cpf, label[for="cpf"]').hide();
					$(this).find('#cnpj, label[for="cnpj"]').hide();
					$(this).find('#cnpj, label[for="cnpj"]').val('');
					$(this).find('#cpf, label[for="cpf"]').val('');
				}			  
			}			
	);	
}








