function Produto()
{
	this.posicao_atual = 0;
	this.preloaded = 0;
	
	this.id_popup = null;
	this.popup_indique = null;
	this.popup_produto = null;
}
/**
 * imagemPreload
 * 
 * realiza o preload das imagens do produto
 * relacionado ao template (produto-miolo.tpl)
 */
Produto.prototype.imagemPreload = function()
{
	var img_loaded = new Array();
	for(var x=0;x<array_imagens_box.length;x++)
	{
		img_loaded[x] = new Image();
		img_loaded[x].src = array_imagens_box[x];
	}
}

Produto.prototype.adicionar_dois = function(idProdutoRecomendado)
{
	document.getElementById('produto_recomendado').value = idProdutoRecomendado;
	document.form_produto.submit();
}

/**
 * trocaImagem
 * 
 * realiza a troca das imagens do produto
 * relacionado ao template (produto-miolo.tpl)
 */
Produto.prototype.trocaImagem = function(direcao)
{
	if(!this.preloaded) this.imagemPreload();
	
	var seta_dir_on = urlimg + 'fotos-dir.gif';
	var seta_dir_off = urlimg + 'fotos-dir-off.gif';
	var seta_esq_on = urlimg + 'fotos-esq.gif';
	var seta_esq_off = urlimg + 'fotos-esq-off.gif';
	
	if(direcao == '+')
	{
		this.posicao_atual++;
		if(this.posicao_atual < array_imagens_box.length)
		{
			document.getElementById('seta_esq_produto_foto').src = seta_esq_on;
			document.getElementById('seta_dir_produto_foto').src = seta_dir_on;
			document.getElementById('produto_foto').src = array_imagens_box[this.posicao_atual];
		}
		else this.posicao_atual--;
	}
	else if(direcao == '-')
	{
		this.posicao_atual--;
		if(this.posicao_atual > -1)
		{
			document.getElementById('seta_esq_produto_foto').src = seta_esq_on;
			document.getElementById('seta_dir_produto_foto').src = seta_dir_on;
			document.getElementById('produto_foto').src = array_imagens_box[this.posicao_atual];
		}
		else this.posicao_atual++;
	}
	
	if(this.posicao_atual == array_imagens_box.length - 1)
		document.getElementById('seta_dir_produto_foto').src = seta_dir_off;
	else if(this.posicao_atual == 0)
		document.getElementById('seta_esq_produto_foto').src = seta_esq_off;
}

Produto.prototype.popup_cd = function(url_cd)
{
	sizey = '190';
	sizex = '268';
	dateobject = new Date();
	jan = window.open(url_cd,"jan"+dateobject.getTime(),'width='+sizex+',height='+sizey+',scrollbars=yes,resizable=no,location=no,directories=no,status=no,menubar=no,top=150,left=150');
}

Produto.prototype.popup_impressao = function(url_impressao)
{
	sizey = '600';
	sizex = '800';
	jan = window.open(url_impressao,"janImpressao",'width='+sizex+',height='+sizey+',scrollbars=yes,resizable=no,location=no,directories=no,status=no,menubar=yes,top=150,left=150');
}

Produto.prototype.imprime_popup = function()
{	
	window.print();
}

Produto.prototype.popup_agendamento = function(url_destino)
{
	sizey = '600';
	sizex = '700';
	jan = window.open(url_destino,"janAgendamento",'width='+sizex+',height='+sizey+',scrollbars=yes,resizable=no,location=no,directories=no,status=no,menubar=yes,top=150,left=150');
}

Produto.prototype.fecha_popup = function()
{	
	window.close();
}

Produto.prototype.salva_popup = function()
{	
	alert('Falta propriedade');
}

/**
 * Layer flutuante geral
 */
Produto.prototype.appear = function()
{
	if(!this.popup_indique)
	{
		this.popup_indique = document.getElementById('layerGeral_popup').innerHTML;
	}	
	else
	{
		document.getElementById('layerGeral_popup').innerHTML = this.popup_indique;
	}	
	
	document.getElementById('layerGeral_popup').style.display = '';
	document.getElementById('layerGeral_popup').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerGeral_popup').style.width = document.body.offsetWidth + 'px';
	
	document.getElementById('layerOpaco_popup').style.display = '';
	document.getElementById('layerOpaco_popup').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerOpaco_popup').style.width = document.body.offsetWidth + 'px';
}


/**
 * Layer flutuante geral
 */
Produto.prototype.visualizar = function(urlParam)
{
	LinkAjax.send(urlParam, 'layerAux_resultado', 'layerAux_carregando');
	
	document.getElementById('layerAux_popup').style.display = '';
	document.getElementById('layerAux_popup').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerAux_popup').style.width = document.body.offsetWidth + 'px';
	
	document.getElementById('layerOpaco_popup').style.display = '';
	document.getElementById('layerOpaco_popup').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerOpaco_popup').style.width = document.body.offsetWidth + 'px';
}


/**
 * Layer flutuante opaco
 */
Produto.prototype.disappear = function()
{
	document.getElementById('layerOpaco_popup').style.display = 'none';
	document.getElementById('layerGeral_popup').style.display = 'none';
	document.getElementById('layerAux_popup').style.display = 'none';	
}


/**
 * Layer flutuante geral
 */
Produto.prototype.popup = function(id_popup)
{
	window.scrollTo(0,0);
	if(id_popup)
	{
		if(this.id_popup)
		{
			document.getElementById(this.id_popup).style.display = 'none';
		}
		document.getElementById(id_popup).style.display = '';
		this.id_popup = id_popup;
	}
	document.getElementById('layerGeral_alert').style.display = '';
	document.getElementById('layerGeral_alert').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerGeral_alert').style.width = document.body.offsetWidth + 'px';
	
	document.getElementById('layerOpaco_alert').style.display = '';
	document.getElementById('layerOpaco_alert').style.height = document.body.offsetHeight + 'px';
	document.getElementById('layerOpaco_alert').style.width = document.body.offsetWidth + 'px';
}

/**
 * Layer flutuante opaco
 */
Produto.prototype.popup_close = function()
{
	document.getElementById('layerOpaco_alert').style.display = 'none';
	document.getElementById('layerGeral_alert').style.display = 'none';
}

/**
 * Cria os campos de forma din�mica
 */
Produto.prototype.adicionarCampoEmail = function(qtde)
{
	var varHtml = '';
	for(var x=0;x<qtde;x++)
	{
		varHtml+= '<label>E-mail '+(x+1)+' ';
		if(x == 0)
		{
			varHtml+= '*';
		}
		
		valor = '';
		if(document.getElementById('campoEmail'+(x+1)))
		valor = document.getElementById('campoEmail'+(x+1)).value;
		
		varHtml+= ':</label> <input id="campoEmail'+(x+1)+'" name="emailDestinatario[]" value="'+valor+'" type="text" class="inputtext" />';
		
		if(x < (qtde-1))
		{
			varHtml+= '<br /><br />';
		}
	}
	document.getElementById('idCampoEmail').innerHTML = varHtml;
}

var Produto = new Produto();
