/*####################################################################*/
/*# Funções auxiliares criadas por: Irroba Multimedia			     			 #*/
/*####################################################################*/


/**********************************************************************/
/* Função para manipular AJAX									      									*/
/**********************************************************************/
function ajax() {
	obj_ajax = null;
	try {
		obj_ajax = new XMLHttpRequest(); //Firefox, Opera 8.0+, Safari
	} catch (e) {
		try { //Internet Explorer
			obj_ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			obj_ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return obj_ajax;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/


/**********************************************************************/
/* Atualizar endereço do cliente								      								*/
/**********************************************************************/
function enderecoCadastroCliente(form) {
	// Inicia o Objeto Ajax 
	var obj_ajax;
	obj_ajax = ajax();
	
	// Verifica se o navegador da suporte a Ajax 
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	// Cria um identificador para o link, para evitar cache 
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	var params = "?id_link="+id_link;
	params += "&busca=endereco";
	params += "&cep="+form.postcode.value;
	obj_ajax.open("GET", "catalog/controller/account/correios.php"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readystate == 1) {
			document.getElementById("carregando_endereco").innerHTML = "Carregando...";
		} 
		
		if (obj_ajax.readyState == 4) {
			if (obj_ajax.responseText != "0") {
				var endereco = obj_ajax.responseText.split("#");
				
				if (endereco[0] == "sim") { //Se é apenas 1 CEP por cidade
					form.address_1.value	= '';
					form.neighborhood.value = endereco[5];
					form.city.value 		= endereco[1];
					selecionarEstado(endereco[2], form.zone_id);
					form.number_home.focus();
					
				} else if (endereco[0] == "nao") { //Se é + de 1 CEP por cidade
					form.address_1.value	= endereco[3]+" "+endereco[4];
					form.neighborhood.value = endereco[5];
					form.city.value 		= endereco[1];
					selecionarEstado(endereco[2], form.zone_id);
					form.number_home.focus();
					
				} else {
					form.address_1.value	= '';
					form.address_2.value	= '';
					form.neighborhood.value = '';
					form.city.value 		= '';
					selecionarEstado('', form.zone_id);
					
				}
			} else {
				form.address_1.value	= '';
				form.address_2.value	= '';
				form.neighborhood.value = '';
				form.city.value 		= '';
				selecionarEstado('', form.zone_id);
			}
		}
	}	
	
	obj_ajax.send(null);
	
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Selecionar estado											      											*/
/**********************************************************************/
function selecionarEstado(uf, combo) {
	if (uf.length > 0) {
		var descricao_estado = "";
		switch (uf) {
			case "ac": descricao_estado = "Acre"; break;
			case "al": descricao_estado = "Alagoas"; break;
			case "ap": descricao_estado = "Amapa"; break;
			case "am": descricao_estado = "Amazonas"; break;
			case "ba": descricao_estado = "Bahia"; break;
			case "ce": descricao_estado = "Ceara"; break;
			case "df": descricao_estado = "Distrito Federal"; break;
			case "es": descricao_estado = "Espirito Santo"; break;
			case "go": descricao_estado = "Goias"; break;
			case "ma": descricao_estado = "Maranhao"; break;
			case "mt": descricao_estado = "Mato Grosso"; break;
			case "ms": descricao_estado = "Mato Grosso do Sul"; break;
			case "mg": descricao_estado = "Minas Gerais"; break;
			case "pa": descricao_estado = "Para"; break;
			case "pb": descricao_estado = "Paraiba"; break;
			case "pr": descricao_estado = "Parana"; break;
			case "pe": descricao_estado = "Pernambuco"; break;
			case "pi": descricao_estado = "Piaui"; break;
			case "rj": descricao_estado = "Rio de Janeiro"; break;
			case "rn": descricao_estado = "Rio Grande do Norte"; break;
			case "rs": descricao_estado = "Rio Grande do Sul"; break;
			case "ro": descricao_estado = "Rondonia"; break;
			case "rr": descricao_estado = "Roraima"; break;
			case "sc": descricao_estado = "Santa Catarina"; break;
			case "sp": descricao_estado = "Sao Paulo"; break;
			case "se": descricao_estado = "Sergipe"; break;
			case "to": descricao_estado = "Tocantins"; break;
		}
		
		for (var i=0; i<combo.length; i++) {
			if (combo.options[i].text == descricao_estado) {
				combo.selectedIndex = i;
			}
		}
	} else {
		combo.selectedIndex = 0;
	}
}
/**********************************************************************/
/* Fim da Seleção estado											  											*/
/**********************************************************************/

/**********************************************************************/
/* Formatação dos campos de telefone							      							*/
/**********************************************************************/
function formatarTelefone(telefone){
	var mascara = '(##)####-####';
	var i = telefone.value.length;
	var texto = mascara.substring(i);
	
	if (texto.substring(0,1) != '#'){
		telefone.value += texto.substring(0,1);
	} 
}
/**********************************************************************/
/* Fim da formatação dos campos de telefone`					      					*/
/**********************************************************************/

/**********************************************************************/
/* Formatação dos campos de data								      								*/
/**********************************************************************/
function formatarData(data){
	var mascara = '##/##/####';
	var i = data.value.length;
	var texto = mascara.substring(i);
	
	if (texto.substring(0,1) != '#'){
		data.value += texto.substring(0,1);
	} 
}
/**********************************************************************/
/* Fim da formatação dos campos de telefone`					      					*/
/**********************************************************************/
/**********************************************************************/
/* Funções da Descrição do Produto                                    */
/**********************************************************************/
function gE(ID) {
	return document.getElementById(ID);
}

function mostrarDiv(ID){
 gE(ID).style.display = "block";
}

function escondeDiv(ID){
 gE(ID).style.display = "none";
}
function onclick_img(nro_imgs,valor) {

	var i;
  for (i=0;i<=nro_imgs;i++) {
		if (i == valor ){
			gE('divImagem_grande'+i).style.display = "block";	
			gE('image_adic'+i).style.border = "1px solid  #666666";	
		}else{
			gE('divImagem_grande'+i).style.display = "none";
			gE('image_adic'+i).style.border = "1px solid  #CCCCCC";	
		}
	}
}
var contador_ini = 0;
var contador = 0;

function troca_img(nro_imgs) {
	
	if (nro_imgs != 0){
	
	var i;
		
	if (contador_ini == 0){
	  contador = (nro_imgs * 2) + 2;
		contador_ini = (nro_imgs * 2) + 2;
	}	
	
	if (contador == 0){
	  contador = (nro_imgs * 2) + 2;
		contador_ini = (nro_imgs * 2) + 2;
	}
  
	for (i=0;i<=nro_imgs;i++){
		
		if (contador == (contador_ini - (i*2))){	   
		 onclick_img(nro_imgs,i);
		}
		 
	}
	
	if (contador != 0){
		contador = contador-1;
		setTimeout("troca_img("+nro_imgs+")", 2000);
	}
	}	
	
}	
/**********************************************************************/
/* Funções da Descrição do Produto                                    */
/**********************************************************************/

/**********************************************************************/
/* INICIO REMOVE PRODUTO CARRINHO                                     */
/**********************************************************************/
function remove_product(string){
	document.remove_product_form.string_remove.value = string;
	document.remove_product_form.submit();
}
/**********************************************************************/
/* FIM REMOVE PRODUTO CARRINHO                                     		*/
/**********************************************************************/
/**********************************************************************/
/* INICIO VERIFICA SE JÀ FOI CALCULADO O CEP                         */
/**********************************************************************/
function verifica_calculo(){
	
  /*existe_cep = document.frete.value_shipping.value;
	if (existe_cep != ''){*/
	document.session_cart.submit();	
	/*}else{
	alert('O calculo de frete e necessario para continuar a transacao');
	}*/

}
/**********************************************************************/
/* FIM VERIFICA SE JÀ FOI CALCULADO O CEP                            */
/**********************************************************************/

/**********************************************************************/
/* Função para pegar os tamanhos de determinada cor									  */
/**********************************************************************/
function load_sizes(size_id, product_id) {
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	}
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	var params = "&idlink="+id_link;
	params = params + "&size_id="+size_id;
	params = params + "&product_id="+product_id;
	
	obj_ajax.open("GET", "index.php?route=product/colors"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState != 4) {
			document.getElementById('sizes').innerHTML = '<img src="catalog/view/theme/nataliaj/image/ajax_load.gif" /><br /><span style="color=#666666">Atualizando cores...</span>';
		} else if (obj_ajax.readyState == 4) {
			document.getElementById('sizes').innerHTML = obj_ajax.responseText;
		}
	}
	obj_ajax.send(null);
	
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/


/**********************************************************************/
/* Função para pegar os tamanhos de determinada cor									  */
/**********************************************************************/
function load_module_sizes(module, size_id, product_id) {
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	}
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	var params = "&idlink="+id_link;
	params = params + "&size_id="+size_id;
	params = params + "&product_id="+product_id;
	params = params + "&module="+module;
	
	obj_ajax.open("GET", "index.php?route=product/module"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState != 4) {
			document.getElementById('sizes_'+module+'_'+product_id).innerHTML = '<img src="catalog/view/theme/nataliaj/image/ajax_load.gif" /><br /><span style="color=#666666">Atualizando cores...</span>';
		} else if (obj_ajax.readyState == 4) {
			document.getElementById('sizes_'+module+'_'+product_id).innerHTML = obj_ajax.responseText;
		}
	}
	obj_ajax.send(null);
	
	document.getElementById('quantity_'+module+'_'+product_id).value = 1;
	
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Função para resetar os valores de quantidade do produto  				  */
/**********************************************************************/
function reset_quantity(module, product_id) {
	
	document.getElementById('quantity_'+module+'_'+product_id).value = 1;
	
}

/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Função para selecionar o tamanho																	  */
/**********************************************************************/
function seleciona_tamanho(size_id, selecionado, total) {
		
	for (i = 1; i <= total; i++){
		document.getElementById('size_'+i).style.color = '#333333';
		document.getElementById('size_'+i).style.background = '#FFFFFF';
	}
	
	document.getElementById('size_'+selecionado).style.color 	  = '#FFFFFF';
	document.getElementById('size_'+selecionado).style.background = '#55680A';
	
	document.getElementById('size_id').value = size_id;
	
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Função que valida dados antes de enviar para o carrinho					  */
/**********************************************************************/

function verifica_dados() {

	var i, cor;
	
	for (i=0;i<document.formProduct.color_id.length;i++){
		 if (document.formProduct.color_id[i].checked) {
			 	cor = document.formProduct.color_id[i].value;
				break;
		 }
		 else {
			 cor = '';
		 }
	}
	
	if (cor == ''){
		alert('Selecione uma cor');
		return false;
	}
	
	if (document.getElementById('curso_id').value == '0') {
		alert('Selecione o Curso');
		return false;
	}	
	
	// Se for aliança 
	if (document.getElementById('size_id').value == '1') {	
		
		if (document.getElementById('size_id_m').value == '0' && document.getElementById('size_id_f').value == '0') {
			alert('Selecione um aro masculino e um feminino');
			return false;
		}
		else if (document.getElementById('size_id_m').value == '0') {
			alert('Selecione o aro masculino');
			return false;
		}
		else if (document.getElementById('size_id_f').value == '0') {
			alert('Selecione o aro feminino');
			return false;
		} else {
			document.formProduct.submit();
		}
	
	}
	// Se não for
	else {
		if (document.getElementById('size_id').value == '' || document.getElementById('size_id').value == '0') {
			alert('Selecione um tamanho');
			return false;
		}
		else {
			document.formProduct.submit();
		}
	}
	
}

/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* Função que valida dados dos módulos antes de enviar para o carrinho*/
/**********************************************************************/

function verifica_dados_mod(modulo,prod) {
	
	if (document.getElementById('size_id_'+modulo+'_'+prod).value == '0' || document.getElementById('size_id_'+modulo+'_'+prod).value == '') {
		alert('Selecione um tamanho');
		return false;
	}
	if (document.getElementById('color_id_'+modulo+'_'+prod).value == '0' || document.getElementById('color_id_'+modulo+'_'+prod).value == '') {
		alert('Selecione uma cor');
		return false;
	}
	else {
		//document.getElementById('product_'+modulo+'_'+prod).submit();
		
		var product_id = prod;
		var size_id = document.getElementById('size_id_'+modulo+'_'+prod).value;
		var color_id = document.getElementById('color_id_'+modulo+'_'+prod).value;
		var quantity = document.getElementById('quantity_'+modulo+'_'+prod).value;
	
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		} 
		
		/* Cria um identificador para o link, para evitar cache */
		var datahora = new Date();
		var ano 	 = datahora.getYear();
		var mes 	 = datahora.getMonth();
		var dia 	 = datahora.getDay();
		var hora 	 = datahora.getHours();
		var minuto 	 = datahora.getMinutes();
		var segundos = datahora.getSeconds();
		var id_link  = ano+mes+dia+hora+minuto+segundos;
		
		/* Captura os dados do formulário */
		
		var params = "&idlink="+id_link;
		params = params + "&action=add_from_module";
		params = params + "&product_id="+product_id;
		params = params + "&size_id="+size_id;
		params = params + "&color_id="+color_id;
		params = params + "&quantity="+quantity;
	
		document.getElementById('div_quantity_'+modulo+'_'+prod).innerHTML = '<div class="loading_ajax"><img src="catalog/view/theme/nataliaj/image/ajax_load.gif" width="25" border="0">&nbsp;<b>Aguarde...</b></div>';
	
		
		obj_ajax.open("GET", "index.php?route=checkout/cart"+params, true);
		obj_ajax.onreadystatechange = function() {
			
			if (obj_ajax.readyState == 4) {
				var resposta = obj_ajax.responseText;
				resposta_quebrada = resposta.split('|');
				resposta_header = resposta_quebrada[0];
				resposta_avalible = resposta_quebrada[1];
				resposta_quantidade = resposta_quebrada[2];
				document.getElementById('div_quantity_'+modulo+'_'+prod).innerHTML = '';
				document.getElementById('header_itens_text').innerHTML = resposta_header;
				if (resposta_avalible == '0') {
					document.getElementById('quantity_'+modulo+'_'+prod).value = 1;
				}
				else {
					document.getElementById('product_available_'+modulo+'_'+prod).innerHTML = resposta_avalible;
				}
				alert("Adicionado ao carrinho "+resposta_quantidade+" iten(s)");
			}
		}	
		obj_ajax.send(null);
		
		return false;							
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		}
	}

}

/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* PEGA POSICAO DO OBJETO NA LOJA				  											      */
/**********************************************************************/
function pegarPosicao(e) {
	if (typeof e == 'string') e = document.getElementById(e);
	var left = 0;
	var top = 0;
	while (e.offsetParent) {
		left += e.offsetLeft;
		top += e.offsetTop;
		e = e.offsetParent;
	}
	left += e.offsetLeft;
	top += e.offsetTop;
	return {x:left, y:top};
}
/**********************************************************************/
/* FIM PEGA POSICAO DO OBJETO NA LOJA														      */
/**********************************************************************/

/**********************************************************************/
/* SETAR POSICAO PARA OBJETO NA LOJA	    											      */
/**********************************************************************/
function setarPosicao(obj, x, y) {
	with (obj.style) {
		top = x+'px';
		left = y+'px';
	}
}
/**********************************************************************/
/* FIM SETAR POSICAO PARA OBJETO NA LOJA												      */
/**********************************************************************/
// Retorna o tamanho de um objeto
function pegarTamanho(e) {
	if (typeof e == 'string') e = gE(e);
	return {x:e.offsetWidth, y:e.offsetHeight};
}

function somenteNumeros(Campo,evt){
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
var key = evt.keyCode ? evt.keyCode : evt.which ;

    var tecla = evt.keyCode;
		var vr = new String(Campo.value);
		vr = vr.replace("-", "");
		tam = vr.length + 1;
			if (tecla != 8){
				if (tam == 6)
				Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, 5);
		}

return (key <= 40 || (key >= 48 && key <= 57));
} 


/**********************************************************************/
/* Função para pegar o valor do frete																  */
/**********************************************************************/
function simulador_frete() {													
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	/* Captura os dados do formulário */
	var pais = "BR";
	var peso 		= document.getElementById('peso').value;
	var cep_format 		= document.getElementById('cep_simulador').value;
	cep = cep_format.replace('-', '');
	cep = cep.replace(' ', '');
	
	if (cep.length < 8){
	  document.getElementById('carregando_frete').innerHTML = 'Cep Invalido!';
	  return false;
	}
	
	var valor_declarado 		= document.getElementById('valor_declarado').value;
	
	if (peso == ''){
	 document.getElementById('resultado_frete').innerHTML = 'Erro ao enviar o peso do produto!';
	 return false;
	}
	
	
	if (valor_declarado == ''){
	 document.getElementById('resultado_frete').innerHTML = '<strong>VALOR DECLARADO</strong> Invalido !';
	 document.getElementById('cep_simulador').focus();
	 return false;
	}
	
	
	var params = "&idlink="+id_link
	params = params + "&pais="+pais;
	params = params + "&peso="+peso;
	params = params + "&cep="+cep;
	params = params + "&type_simulator=product";
		params = params + "&valor_declarado="+valor_declarado;
	
	//alert(params);
	
	document.getElementById('resultado_frete').innerHTML = '<strong>Calculando...</strong><br /><img src="catalog/view/theme/nataliaj/image/loading_payment.gif">';
	
	
	obj_ajax.open("GET", "index.php?route=checkout/simulator"+params, true);
	obj_ajax.onreadystatechange = function() {

		if (obj_ajax.readyState == 4) {
			document.getElementById('resultado_frete').innerHTML = obj_ajax.responseText;
			document.getElementById('resultado_frete').style.display = 'block';
		}
	}		
	obj_ajax.send(null);
	
	return false;							
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/

/**********************************************************************/
/* ATUALIZA SIMULAÇÃO DE FRETE NO CARRINHO											      */
/**********************************************************************/
function simula_frete_cart(){
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 		= datahora.getYear();
	var mes 	 		= datahora.getMonth();
	var dia 	 		= datahora.getDay();
	var hora 	 		= datahora.getHours();
	var minuto 	 	= datahora.getMinutes();
	var segundos 	= datahora.getSeconds();
	var id_link  	= ano+mes+dia+hora+minuto+segundos;
	var pos 			= pegarPosicao('cel_simular_frete');
	
	/* Captura os dados do formulário */
	var params = "&idlink="+id_link;
	params = params + "&cep="+document.cart.simulador_cep.value;

	obj_ajax.open("GET", "index.php?route=checkout/simulator"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readystate != 4) {
			var div_conteudo_simulador = document.getElementById('conteudo_simulacao_frete');
			setarPosicao(div_conteudo_simulador, pos.y+55, pos.x);
			div_conteudo_simulador.style.display = "block";
			div_conteudo_simulador.innerHTML = '<div style="text-align:center;"><img src="catalog/view/theme/nataliaj/image/ajax-loader.gif" align="absmiddle" width="32" height="32" border="0" />&nbsp;carregando...</div>';
		}
		
		if (obj_ajax.readyState == 4) {
			var div_conteudo_simulador = document.getElementById('conteudo_simulacao_frete');
			setarPosicao(div_conteudo_simulador, pos.y+55, pos.x);
			div_conteudo_simulador.style.display = "block";
			div_conteudo_simulador.innerHTML = obj_ajax.responseText;
		}
	}	
	obj_ajax.send(null);
	
	return false;							
}
/**********************************************************************/
/* FIM SIMULAÇÃO DE FRETE NO CARRINHO  													      */
/**********************************************************************/
/**********************************************************************/
/* SELECIONAR FRETE										 													      */
/**********************************************************************/
function selecionar_frete(frete, valor){
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	/* Captura os dados do formulário */
	var params = "&idlink="+id_link;
	params += "&frete_selecionado="+frete;
	params += "&valor_frete_selecionado="+valor;

	obj_ajax.open("GET", "catalog/controller/checkout/selectfrete.php?"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState == 4) {
			var retorno = obj_ajax.responseText;
			if (retorno) {
				document.getElementById('conteudo_simulacao_frete').style.display = "none";
				window.location = "index.php?route=checkout/cart";
			} else {
				document.getElementById('conteudo_simulacao_frete').style.display = "none";
				alert("Problema ao selecionar o tipo de frete. Por favor tente novamente!");
			}
		}
	}	
	obj_ajax.send(null);
	
	return false;							
}
/**********************************************************************/
/* FIM SELECIONAR FRETE                     										      */
/**********************************************************************/

/*Mudar cor das formas de entrega ao selecionar uma*/
function mudaCorFormas(id){
	
	total = parseInt(document.getElementById('total_formas_entrega').value);
	
	
	for (i = 1; i <= total; i++){
		if (i == id){
			document.getElementById('forma_'+i).style.color = '#FF0000';
			document.getElementById('valor_'+i).style.color = '#FF0000';
		}else{
			document.getElementById('forma_'+i).style.color = '#000000';
			document.getElementById('valor_'+i).style.color = '#000000';
		}
	}
	
}

/**********************************************************************/
/* INICIO VERIFICA SE JÀ FOI SELECIONADO O ENDERECO                      */
/**********************************************************************/
function change_shipping(int){			

if (int == 0){
	document.getElementById('valida_shipping').value = '1';
}

if (int == 1){
  value = document.getElementById('valida_shipping').value;
	if (value != ''){
	 document.getElementById('address_1').submit();
	}else{
	  alert('E necessario seleciona um endereco cadastrado ou cadastrar um novo endereco!');
	}
}

}
/**********************************************************************/
/* FIM VERIFICA SE JÀ FOI SELECIONADO O ENDERECO                             */
/**********************************************************************/
/**********************************************************************/
/* Fechar DIV NEWSLETTER																				      */
/**********************************************************************/
$(document).ready(function () {  

   // if user clicked on button, the overlay layer or the dialogbox, close the dialog    
   $('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {       
        $('#dialog-overlay, #dialog-box').hide();
				document.getElementById('banner').style.display = 'block';
				document.getElementById('banner_flash').style.display = 'block';
				document.getElementById('banner_image').style.display = 'none';
        return false;  
    });  
     
   // if user resize the window, call the same function again  
   // to make sure the overlay fills the screen and dialogbox aligned to center      
     $(window).resize(function () {
          
        //only do it if the dialog box is not hidden  
        if (!$('#dialog-box').is(':hidden')) popup();         
    });      
		 
      
});

function popup(message) {

	// get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	// calculate the values for center alignment
	var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();

	// display the message
	$('#dialog-message').html(message);

}
/**********************************************************************/
/* Fechar DIV NEWSLETTER	`					    														  */
/**********************************************************************/
/**********************************************************************/
/* Div subcategorias																						      */
/**********************************************************************/
function stop_div(){		
			document.getElementById('menu').style.display = 'none';			
	}
	function start_div(){		  
	   	document.getElementById('menu').style.display = 'block';
	}
/**********************************************************************/
/* Div subcategorias`																						      */
/**********************************************************************/

/**********************************************************************/
/* Abas Product Details																					      */
/**********************************************************************/
function show_text_details(aba){	

	if (aba == 0) {
		document.getElementById('product_description').style.display = 'block';
		document.getElementById('product_description_text').style.color = '#1D1D1D';
		document.getElementById('product_opnions').style.display = 'none';
		document.getElementById('product_opnions_text').style.color = '#999999';
		document.getElementById('product_share').style.display = 'none';
		document.getElementById('product_share_text').style.color = '#999999';
		document.getElementById('product_gift').style.display = 'none';
		document.getElementById('product_gift_text').style.color = '#999999';
	} 
	else if (aba == 1) {
		document.getElementById('product_description').style.display = 'none';
		document.getElementById('product_description_text').style.color = '#999999';
		document.getElementById('product_opnions').style.display = 'block';
		document.getElementById('product_opnions_text').style.color = '#1D1D1D';
		document.getElementById('product_share').style.display = 'none';
		document.getElementById('product_share_text').style.color = '#999999';
		document.getElementById('product_gift').style.display = 'none';
		document.getElementById('product_gift_text').style.color = '#999999';
	}
	else if (aba == 2) {
		document.getElementById('product_description').style.display = 'none';
		document.getElementById('product_description_text').style.color = '#999999';
		document.getElementById('product_opnions').style.display = 'none';
		document.getElementById('product_opnions_text').style.color = '#999999';
		document.getElementById('product_share').style.display = 'block';
		document.getElementById('product_share_text').style.color = '#1D1D1D';
		document.getElementById('product_gift').style.display = 'none';
		document.getElementById('product_gift_text').style.color = '#999999';
	}
	else if (aba == 3) {
		document.getElementById('product_description').style.display = 'none';
		document.getElementById('product_description_text').style.color = '#999999';
		document.getElementById('product_opnions').style.display = 'none';
		document.getElementById('product_opnions_text').style.color = '#999999';
		document.getElementById('product_share').style.display = 'none';
		document.getElementById('product_share_text').style.color = '#999999';
		document.getElementById('product_gift').style.display = 'block';
		document.getElementById('product_gift_text').style.color = '#1D1D1D';
	}
}
/**********************************************************************/
/* Abas Product Details					  															      */
/**********************************************************************/

/**********************************************************************/
/* Mostrar mais alvaliações			  															      */
/**********************************************************************/
function show_more_reviews(tipo) {
	if (tipo == 1) {
		document.getElementById('one_review').style.display = 'none';
		document.getElementById('more_reviews').style.display = 'block';
	}
	else if (tipo == 0) {
		document.getElementById('one_review').style.display = 'block';
		document.getElementById('more_reviews').style.display = 'none';
	}
}
/**********************************************************************/
/* Mostrar mais alvaliações			  															      */
/**********************************************************************/

/**********************************************************************/
/* ATUALIZA QUANTIDADE CARRINHO																	      */
/**********************************************************************/
function update_quantity(param){
	
	var array_product = param.split(':');
	var product_id = array_product[0];
	var size_id = array_product[1];
	var color_id = array_product[2];
	var size_id_f = array_product[3];
	var size_id_m = array_product[4];
	var recording_m = array_product[5];
	var recording_f = array_product[6];
	var recording_anel = array_product[7];
	var curso_id = array_product[8];		
	var quantity = array_product[9];
	var quantity_origin = array_product[10];

	var entry_quantity = document.getElementById('text_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).value;

	if (entry_quantity <= '0' || entry_quantity == '') {
		document.getElementById('text_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).value = quantity_origin;
		alert('Quantidade invalida');
		return false;
	}
	else if (isNaN(entry_quantity) == true) {
		alert('Quantidade deve ser numerica');
		document.getElementById('text_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).value = quantity_origin;
		return false;
	}
	else {
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		} 
		
		/* Cria um identificador para o link, para evitar cache */
		var datahora = new Date();
		var ano 	 = datahora.getYear();
		var mes 	 = datahora.getMonth();
		var dia 	 = datahora.getDay();
		var hora 	 = datahora.getHours();
		var minuto 	 = datahora.getMinutes();
		var segundos = datahora.getSeconds();
		var id_link  = ano+mes+dia+hora+minuto+segundos;
		
		/* Captura os dados do formulário */
		
		var params = "&idlink="+id_link;
		params = params + "&action=update";
		params = params + "&product_id="+product_id;
		params = params + "&size_id="+size_id;
		params = params + "&color_id="+color_id;
		params = params + "&size_id_f="+size_id_f;
		params = params + "&size_id_m="+size_id_m;
		params = params + "&recording_m="+recording_m;
		params = params + "&recording_f="+recording_f;
		params = params + "&recording_anel="+recording_anel;
		params = params + "&curso_id="+curso_id;			
		params = params + "&quantity="+quantity;quantity_origin
		params = params + "&quantity_origin="+quantity_origin;	
		
		document.getElementById('div_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).innerHTML = '<img src="catalog/view/theme/nataliaj/image/ajax_load.gif"> carregando ...</b>';
		
		obj_ajax.open("GET", "index.php?route=checkout/cart"+params, true);
		obj_ajax.onreadystatechange = function() {
			
			if (obj_ajax.readyState == 4) {
				var resposta = obj_ajax.responseText;
				if (resposta == 1){
					document.getElementById('div_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).innerHTML = '<a style="text-decoration:underline;" href="index.php?route=checkout/cart"><img src="catalog/view/theme/nataliaj/image/cart_updateItens.jpg" border="0" /></a>';
					document.frete.value_shipping.value = '1';
				}else{
					document.getElementById('div_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).innerHTML = resposta;
					document.getElementById('text_quantity_'+product_id+':'+size_id+':'+color_id+':'+size_id_f+':'+size_id_m+':'+recording_m+':'+recording_f+':'+recording_anel+':'+curso_id).value = quantity_origin;
				}
			}
		}	
		obj_ajax.send(null);
		
		return false;							
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		}
	
	}

}
/**********************************************************************/
/* FIM ATUALIZA QUANTIDADE CARRINHO															      */
/**********************************************************************/

/**********************************************************************/
/* ATUALIZA QUANTIDADE DE PRODUTOS NOS MODULOS									      */
/**********************************************************************/
function update_quantity_mod(modulo,prod) {
	
	if (document.getElementById('size_id_'+modulo+'_'+prod).value == '0' || document.getElementById('size_id_'+modulo+'_'+prod).value == '') {
		alert('Selecione um tamanho para alterar a quantidade');
		document.getElementById('quantity_'+modulo+'_'+prod).value = 1;
		return false;
	}
	else if (document.getElementById('color_id_'+modulo+'_'+prod).value == '0' || document.getElementById('color_id_'+modulo+'_'+prod).value == '') {
		alert('Selecione uma cor para alterar a quantidade');
		document.getElementById('quantity_'+modulo+'_'+prod).value = 1;
		return false;
	}
	else if (document.getElementById('quantity_'+modulo+'_'+prod).value <= '0' || document.getElementById('quantity_'+modulo+'_'+prod).value == '') {
		//alert('Quantidade invalida');
		document.getElementById('quantity_'+modulo+'_'+prod).value = 1;
	}
	else if (isNaN(document.getElementById('quantity_'+modulo+'_'+prod).value) == true) {
		//alert('Quantidade deve ser numerica');
		document.getElementById('quantity_'+modulo+'_'+prod).value = 1;
	} else {
		var product_id = prod;
		var size_id = document.getElementById('size_id_'+modulo+'_'+prod).value;
		var color_id = document.getElementById('color_id_'+modulo+'_'+prod).value;
		var quantity = document.getElementById('quantity_'+modulo+'_'+prod).value;
		var quantity_origin = 1;
	
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		} 
		
		/* Cria um identificador para o link, para evitar cache */
		var datahora = new Date();
		var ano 	 = datahora.getYear();
		var mes 	 = datahora.getMonth();
		var dia 	 = datahora.getDay();
		var hora 	 = datahora.getHours();
		var minuto 	 = datahora.getMinutes();
		var segundos = datahora.getSeconds();
		var id_link  = ano+mes+dia+hora+minuto+segundos;
		
		/* Captura os dados do formulário */
		
		var params = "&idlink="+id_link;
		params = params + "&action=stock_verify";
		params = params + "&product_id="+product_id;
		params = params + "&size_id="+size_id;
		params = params + "&color_id="+color_id;
		params = params + "&quantity="+quantity;quantity_origin
		params = params + "&quantity_origin="+quantity_origin;
	
		document.getElementById('div_quantity_'+modulo+'_'+prod).innerHTML = '<img src="catalog/view/theme/nataliaj/image/ajax_load.gif" width="25" border="0">&nbsp;<b>Aguarde...</b>';
	
		
		obj_ajax.open("GET", "index.php?route=checkout/cart"+params, true);
		obj_ajax.onreadystatechange = function() {
			
			if (obj_ajax.readyState == 4) {
				var resposta = obj_ajax.responseText;
				if (resposta == 1){
					document.getElementById('div_quantity_'+modulo+'_'+prod).innerHTML = '';
				}else{
					resposta_quebrada = resposta.split('|');
					resposta_texto = resposta_quebrada[0];
					resposta_qtd = resposta_quebrada[1];
					document.getElementById('div_quantity_'+modulo+'_'+prod).innerHTML = resposta_texto;
					document.getElementById('quantity_'+modulo+'_'+prod).value = resposta_qtd;
				}
			}
		}	
		obj_ajax.send(null);
		
		return false;							
		/* Inicia o Objeto Ajax */
		obj_ajax = ajax();
		
		/* Verifica se o navegador da suporte a Ajax */
		if (obj_ajax == null) {
			alert ("Seu navegador não da suporte a este tipo de ação!");
			return false;
		} 
	}
}
/**********************************************************************/
/* FIM ATUALIZA QUANTIDADE DE ITENS NOS MODULOS									      */
/**********************************************************************/

/**********************************************************************/
/* Função de buscar palavras  	  															      */
/**********************************************************************/
function search_bar() {
	
	if ((document.search_header.keyword.value.length < 3) || (document.search_header.keyword.value == 'Buscar em todo o site')) {
		alert('A palavra deve ter no minimo 3 letras');
		document.search_header.keyword.value = 'Buscar em todo o site';
		return false;
	}
	else {
		document.search_header.submit();
	}
	
}
/**********************************************************************/
/* Função de buscar palavras		  															      */
/**********************************************************************/

/**********************************************************************/
/* Mostrar divs de pagamento		  															      */
/**********************************************************************/
function mostra_div() {

	if(document.getElementById('card_payment').style.display != 'block') {
		document.getElementById('card_payment').style.display = 'block';
	} else {
		document.getElementById('card_payment').style.display = 'none';
	}
}

function mostra_div_prazo() {

	if(document.getElementById('text_prazo').style.display != 'block') {
		document.getElementById('text_prazo').style.display = 'block';
	} else {
		document.getElementById('text_prazo').style.display = 'none';
	}
}

function fecha_div() {

		document.getElementById('card_payment').style.display = 'none';
		
}
/**********************************************************************/
/* Mostrar divs de pagamento		  															      */
/**********************************************************************/

/**********************************************************************/
/* Âncora para review						  															      */
/**********************************************************************/
function make_review() {
	
	document.getElementById('product_description').style.display = 'none';
	document.getElementById('product_description_text').style.color = '#999999';
	document.getElementById('product_opnions').style.display = 'block';
	document.getElementById('product_opnions_text').style.color = '#1D1D1D';
	document.getElementById('product_share').style.display = 'none';
	document.getElementById('product_share_text').style.color = '#999999';
	document.getElementById('product_gift').style.display = 'none';
	document.getElementById('product_gift_text').style.color = '#999999';
	
	document.getElementById('text').focus();

}
/**********************************************************************/
/* Âncora para review						  															      */
/**********************************************************************/

/**********************************************************************/
/* Funções div categorias					                                    */
/**********************************************************************/
function mostra_submenu(sub_nome,sub_qtd) {
	
	if (document.getElementById('submenu_'+sub_nome).style.display == 'block') {
		document.getElementById('submenu_'+sub_nome).style.display = 'none'
	}
	else {
		for (i = 1; i <= sub_qtd; i++){
			document.getElementById('submenu_'+i).style.display = 'none';
		}
		document.getElementById('submenu_'+sub_nome).style.display = 'block';
	}
	
}
/**********************************************************************/
/* Funções div categorias					                                    */
/**********************************************************************/

/**********************************************************************/
/* Funções div sexshop  					                                    */
/**********************************************************************/
function mostra_sexshop(sub_nome,sub_qtd) {
	
	if (document.getElementById('submenu_'+sub_nome).style.display == 'block') {
		document.getElementById('submenu_'+sub_nome).style.display = 'none'
	}
	else {
		for (i = 1; i <= sub_qtd; i++){
			document.getElementById('submenu_'+i).style.display = 'none';
		}
		decisao = confirm("Maior de 18 anos?");
		if (decisao){
			document.getElementById('submenu_'+sub_nome).style.display = 'block';
		}
	}
	
}
/**********************************************************************/
/* Funções div sexshop   					                                    */
/**********************************************************************/

/**********************************************************************/
/* PASSA OS DADOS DO FORMULARIO DE FORMA DE PAGAMENTO                 */
/**********************************************************************/
function validaPaymentMethod(form){
	
  var flag = true;
	
	if ((document.forms[form].total_price.value == "0") && (document.forms[form].payment_method.value != "boleto") && (document.forms[form].payment_method.value != "boleto_brasil") && (document.forms[form].payment_method.value != "boleto_itau")){
		alert("Selecione uma forma de pagamento.");
		flag = false;
	}
	
	return flag;
	
}
/**********************************************************************/
/* FIM PASSA OS DADOS DO FORMULARIO DE FORMA DE PAGAMENTO             */
/**********************************************************************/
/**********************************************************************/
/* PASSA OS DADOS DO FORMULARIO DE FORMA DE PAGAMENTO                 */
/**********************************************************************/

function preencheDadosPagamento(formulario, parcela_preco){

	data_parc = parcela_preco.split(":");

	parcelas = data_parc[0];

	total_price = data_parc[1];

	var d = formulario;

	document.forms[''+d].payment_quantity.value = parcelas;

	document.forms[''+d].total_price.value = total_price;	

}

/**********************************************************************/
/* FIM PASSA OS DADOS DO FORMULARIO DE FORMA DE PAGAMENTO             */
/**********************************************************************/
/**********************************************************************/
/* PASSA OS DADOS PARA O GATEWAY DE PAGAMENTO                 */
/**********************************************************************/
function validaGateway(total_price, payment_method, payment_quantity, afiliacao, order_id, administrator) {
							
	/* Inicia o Objeto Ajax */
	obj_ajax = ajax();
	
	/* Verifica se o navegador da suporte a Ajax */
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	/* Cria um identificador para o link, para evitar cache */
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	/* Captura os dados do formulário */
	var total_price = total_price.toFixed(2);
	
	var params = "idlink="+id_link;
	params = params + "&total_price="+total_price;
	params = params + "&payment_method="+payment_method;
	params = params + "&payment_quantity="+payment_quantity;
	params = params + "&afiliacao="+afiliacao;
	params = params + "&order_id="+order_id;
	params = params + "&administrator="+administrator;
	
	document.getElementById("return").innerHTML = '<img src="catalog/view/theme/nataliaj/image/ajax_load.gif"> carregando ...';
	
	obj_ajax.onreadystatechange = function() {
		
		if (obj_ajax.readyState == 4) {
			if (obj_ajax.status == 200){
				document.getElementById("return").innerHTML = obj_ajax.responseText ;

			}else{
				document.getElementById("return").innerHTML = "<b>Pagina nao encontrada!</b>";

			}

		}
	}
	obj_ajax.open("POST", "catalog/controller/payment/gateway.php", true);
	obj_ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    obj_ajax.setRequestHeader("Content-length", params.length);
    obj_ajax.setRequestHeader("Connection", "close");
	
	obj_ajax.send(params);		
}
/**********************************************************************/
/* FIM PASSA OS DADOS PARA O GATEWAY DE PAGAMENTO        					    */
/**********************************************************************/

/**********************************************************************/
/* Funções para carregar e recarregar valores de inputs de texto	    */
/**********************************************************************/
function load_value(input_name,value) {
	if (document.getElementById(input_name).value == value) {
		document.getElementById(input_name).value = '';
	}
}

function reload_value(input_name,new_value) {
	if (document.getElementById(input_name).value == '') {
		document.getElementById(input_name).value = new_value;
	}
}
/**********************************************************************/
/* Funções para carregar e recarregar valores de inputs de texto      */
/**********************************************************************/


/**********************************************************************/
/* Função para carregar a sessão de sexshop	como nao autorizada		    */
/**********************************************************************/
function cancela_sexshop() {
	
		document.getElementById('agree').value = 'nao';
		document.sexshop.action = "index.php?route=common/home";
		document.sexshop.submit();

}
/**********************************************************************/
/* Função para carregar a sessão de sexshop	como nao autorizada		    */
/**********************************************************************/

/**********************************************************************/
/* Função desabilitar combobox de seleção de cores								    */
/**********************************************************************/
function update_color() {
	
	if (document.getElementById('size_id').value == 0) {
		document.getElementById('color_id').disabled = true;
	}
	else {
		document.getElementById('color_id').disabled = false;
	}
	
}
/**********************************************************************/
/* Função desabilitar combobox de seleção de cores								    */
/**********************************************************************/
function select_type_product(id){
	if(id == 'type_bestseller'){
		document.getElementById(id).style.color = '#316094';
		document.getElementById(id).style.fontWeight = 'bold';
		document.getElementById('type_promotions').style.fontWeight = '100';
		document.getElementById('type_latest').style.fontWeight     = '100';			
		document.getElementById('type_promotions').style.color      = '#000';
		document.getElementById('type_latest').style.color          = '#000';
		document.getElementById('bestseller_content').style.display = 'block';
		document.getElementById('special_content').style.display    = 'none';
		document.getElementById('latest_content').style.display     = 'none';
	}else if(id == 'type_promotions'){
		document.getElementById(id).style.color = '#316094';
		document.getElementById(id).style.fontWeight = 'bold';
		document.getElementById('type_bestseller').style.fontWeight = '100';
		document.getElementById('type_latest').style.fontWeight     = '100';		
		document.getElementById('type_bestseller').style.color      = '#000';
		document.getElementById('type_latest').style.color          = '#000';
		document.getElementById('bestseller_content').style.display = 'none';
		document.getElementById('special_content').style.display    = 'block';
		document.getElementById('latest_content').style.display     = 'none';
	}else if(id == 'type_latest'){
		document.getElementById(id).style.color = '#316094';
		document.getElementById(id).style.fontWeight = 'bold';
		document.getElementById('type_promotions').style.fontWeight = '100';
		document.getElementById('type_bestseller').style.fontWeight = '100';			
		document.getElementById('type_bestseller').style.color      = '#000';
		document.getElementById('type_promotions').style.color      = '#000';
		document.getElementById('bestseller_content').style.display = 'none';
		document.getElementById('special_content').style.display    = 'none';
		document.getElementById('latest_content').style.display     = 'block';		
	}
}

/**********************************************************************/
/* EXIBIR/OCULTAR MENUS DINAMICOS */
/**********************************************************************/
function exibe_div(div, categ_id){

		if(document.getElementById(div+categ_id).style.display == 'none') 
		{
			document.getElementById(div+categ_id).style.display = 'block';
			document.getElementById(div+categ_id).style.color = '#CC3300';
					
		} else if(document.getElementById(div+categ_id).style.display == 'block') 
		{
			document.getElementById(div+categ_id).style.display = 'none';
		}
}
/**********************************************************************/
/* FIM EXIBIR/OCULTAR MENUS DINAMICOS */
/**********************************************************************/
/**********************************************************************/
/* VALIDACAO DO INDICAR PRODUTO */
/**********************************************************************/
function validaIndicate(indicate){
	if(indicate.yourName.value == '' || indicate.yourName.value.length < 3){
		alert('Digite Seu Nome !');
	}
	else if (indicate.yourEmail.value == ''){
		alert('Seu Email e Necessario !');
	} 
	else if (!checkMail(indicate.yourEmail.value)){
		alert('O Seu Email foi Digitado Incorretamente !');
	}
	else if(indicate.friendsName.value == '' || indicate.friendsName.value.length < 3){
		alert('Digite o Nome de Seu Amigo !');
	}
	else if (indicate.friendsEmail.value == ''){
		alert('O Email do Amigo e Necessario !');
	} 
	else if (!checkMail(indicate.friendsEmail.value)){
		alert('O Email do Amigo foi Digitado Incorretamente !');
	}
	else if(indicate.comments.value == '' || indicate.comments.value.length < 3){
		alert('Mensagem de Indicacao nulo ou muito pequeno!');
	}
	else{
		indicate.submit();
	}
		
}
/**********************************************************************/
/* FIM VALIDACAO DO INDICAR PRODUTO */
/**********************************************************************/
/***********************************************************************/
/****************FUNCAO JAVASCRIPT DE VALIDAR EMAIL*********************/
/***********************************************************************/

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
		if(!er.test(mail)){
			return false;
		}
	}else if(typeof(mail) == "object"){
		if(!er.test(mail.value)){ 
			return false;
		}
	}else{
		return false;
		}
	return true;
}

/***********************************************************************/
/****************FIM DE FUNCAO JAVASCRIPT DE VALIDAR EMAIL**************/
/***********************************************************************/

/**********************************************************************/
/* Atualizar endereço do cliente								      */
/**********************************************************************/
function buscaEndereco() {
	// Inicia o Objeto Ajax 
	var obj_ajax;
	obj_ajax = ajax();
	
	// Verifica se o navegador da suporte a Ajax 
	if (obj_ajax == null) {
		alert ("Seu navegador não da suporte a este tipo de ação!");
		return false;
	} 
	
	// Cria um identificador para o link, para evitar cache 
	var datahora = new Date();
	var ano 	 = datahora.getYear();
	var mes 	 = datahora.getMonth();
	var dia 	 = datahora.getDay();
	var hora 	 = datahora.getHours();
	var minuto 	 = datahora.getMinutes();
	var segundos = datahora.getSeconds();
	var id_link  = ano+mes+dia+hora+minuto+segundos;
	
	var params = "?id_link="+id_link;
	params += "&busca=endereco";
	params += "&cep="+document.getElementById('cep_simulate').value;
	obj_ajax.open("GET", "catalog/controller/account/correios.php"+params, true);
	obj_ajax.onreadystatechange = function() {
		if (obj_ajax.readyState == 4) {
			if (obj_ajax.responseText != "0") {
				var endereco = obj_ajax.responseText.split("#");
				
				if (endereco[0] == "sim") { //Se é apenas 1 CEP por cidade
					document.getElementById('address_1').innerHTML	= '';
					document.getElementById('city').innerHTML 		= endereco[1];
					
				} else if (endereco[0] == "nao") { //Se é + de 1 CEP por cidade
					document.getElementById('address_1').innerHTML	= endereco[3]+" "+endereco[4];
					document.getElementById('city').innerHTML 		= endereco[1];
					
				} else {
					document.getElementById('address_1').innerHTML	= '';
					document.getElementById('city').innerHTML 		= '';
					
				}
			} else {
				document.getElementById('address_1').innerHTML	= '';
				document.getElementById('city').innerHTML 		= 'N&atilde;o encontrado !';
			}
		}
	}	
	
	obj_ajax.send(null);
	
	return false;
}
/**********************************************************************/
/* Fim da Função                                                      */
/**********************************************************************/
