// JavaScript Document

function atualizaPreco(precoItens){
	precoFinal = 0;
	for(var index in precoItens){
		precoFinal += precoItens[index];
	}
	var valorPedido = document.getElementById("valorPedido");
	precoFinal = precoFinal.toFixed(2);
	precoFinal = precoFinal.replace(".", ",");
	valorPedido.innerHTML = "<strong>Valor do pedido: R$ " + precoFinal + "</strong>";
}

function atualizaEsteItem(item, size, qty){

// 10x15 = R$14,80
// 15x21 = R$16,90
// 20x30 = R$20,00
// Arquivo Digital = R$14,90
// Download = R$4,60


	var dica = document.getElementById("boxAviso" + item);

	//Libera as caixas de cor quantidade
	libera_cor(item);
	libera_quantidade(item);

	if(size==1){
		//1 = 15x21 - R$ 16,90

		window.tamanho[item] = 1;
		window.quantidade[item] = qty;
		window.precoItens[item] = 16.9*qty;

		dica.innerHTML = "ATENÇÃO: As fotos serão enviadas via Correios.";

	}else if(size==2){
		//2 = 20x30 - R$ 20,00

		window.tamanho[item] = 2;
		window.quantidade[item] = qty;
		window.precoItens[item] = 20*qty;

		dica.innerHTML = "ATENÇÃO: As fotos serão enviadas via Correios.";

	}else if(size==3){
		//3 = Arquivo digital - R$ 14,90, bloqueia quantidade (apenas 1 unidade)

		bloqueia_quantidade(item);

		window.tamanho[item] = 3;
		window.quantidade[item] = 1;
		window.precoItens[item] = 14.9;//Apenas uma unidade permitida

		dica.innerHTML = "ATENÇÃO: A resolução para ampliação é de até 20x30 cm.";

	}else if(size==4){
		//4 = 10x15 - R$ 14,80

		window.tamanho[item] = 4;
		window.quantidade[item] = qty;
		window.precoItens[item] = 14.8*qty;

		dica.innerHTML = "ATENÇÃO: As fotos serão enviadas via Correios.";

	}else if(size==5){
		//5 = Download - R$ 4,60, bloqueia cor, bloqueia quantidade (apenas 1 unidade)

		bloqueia_cor(item);
		bloqueia_quantidade(item);

		window.tamanho[item] = 5;
		window.quantidade[item] = 1;
		window.precoItens[item] = 4.6;//Apenas uma unidade permitida

		dica.innerHTML = "ATENÇÃO: A resolução para ampliação é de até 15x21 cm.";

	}
	atualizaPreco(window.precoItens);
}

function bloqueia_cor(item){
	var esteInput = document.getElementById('cor' + item);
	esteInput.selectedIndex = 0;
	esteInput.disabled = true;
}
function libera_cor(item){
	var esteInput = document.getElementById('cor' + item);
	esteInput.disabled = false;
}
function bloqueia_quantidade(item){
	var esteInput = document.getElementById('quantidade' + item);
	esteInput.value = 1;
	esteInput.readOnly = true;
}
function libera_quantidade(item){
	var esteInput = document.getElementById('quantidade' + item);
	esteInput.readOnly = false;
}

function votar(q,r){
	windowWidth = 435;
	windowHeight = 300;

	var w = (screen.width/2)-(windowWidth/2+10);
	var h = (screen.height/2)-(windowHeight/2+20);

	for(var i = 0; i < r.length; i++) {
		if(r[i].checked) {
			var r = r[i].value;
		}
	}

	var janela ='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=435,height=300';
	var url = "resultadoEnquete.php?cdEnquete="+q+"&cdResp="+r+"";
	//var url = "resultadoEnquete.php?cdEnquete="+qualEnquete+"&cdResp="+resp;
	//var url = "hhtp://digitaltree.com.br";
	var win = window.open(url,'enquete',janela);
	win.moveTo(w,h);
}

function verResultado(url){
	var winl = (screen.width - 770) / 2;
	var wint = (screen.height - 500) / 2 - 50;
	//winprops = 'height=' + h + ', width=' + w + ', top=' + wint + ', left=' + winl + ',status=yes, scrollbars=yes, resizable=no, menubar=no'
	winprops = 'height=500, width=770, top=' + wint + ', left=' + winl + ',status=yes, scrollbars=yes, resizable=yes, menubar=no'
	win = window.open (url, 'Resultado', winprops);
}

function fechaBanner(){
	conteudo = document.getElementById("floatCenter");
	conteudo.style.display = "none";
}

function moreInfoHide(){
	conteudo = document.getElementById("saibaMais");
	conteudo.style.display = "none";
}

function moreInfoShow(){
	conteudo = document.getElementById("saibaMais");
	conteudo.style.display = "block";
}

$(document).ready(function() {
	//Função para rollover de imagens. No html, use apenas a marcação normal sem nehuma chamada javascript
	// Preload all rollovers
	$(".rollovers img").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.gif$/ig,"_over.gif");
		$("<img>").attr("src", rollON);
	});

	// Navigation rollovers
	$(".rollovers a").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_over/);

		// don't do the rollover if state is already ON
		if (!matches) {
		imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // strip off extension
		$(this).children("img").attr("src", imgsrcON);
		}

	});
	$(".rollovers a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});


});

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var w=1
var h=1

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;left:0px;top:-1000px;width:1px;height:1px;border:2px solid #000000;background:#FFFFFF;padding:10px;z-index:1;"><img id="ttimg" src="img/s.gif" style="border:1px solid #000000;" /></div>')

function gettrailobj()
{
	if (document.getElementById) return document.getElementById("trailimageid").style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('ttimg').src='/img/s.gif'
	gettrailobj().visibility="hidden"
	gettrailobj().left=-1000
	gettrailobj().top=0
}


function showtrail(width,height,file)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{
		w=width
		h=height

		// followmouse()

		document.getElementById('ttimg').src=file
		document.onmousemove=followmouse
		gettrailobj().visibility="visible"
		gettrailobj().width=w+"px"
		gettrailobj().height=h+"px"


	}
}

function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{

		var xcoord=20
		var ycoord=20

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		//alert("xcoord: "+xcoord+"w: "+w)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj().left=xcoord+"px"
		gettrailobj().top=ycoord+"px"

	}

}

function limpaCampo(este){
	este.value = '';
}
