function centraliza(largura,altura){
	window.moveTo((window.screen.width-largura)/2,(window.screen.height-altura)/2);
}
function abreJanela(arquivo,nome,barra,largura,altura) {
	window.open(arquivo,nome,"resizable=no,toolbar=no,status=no,menubar=no,scrollbars="+barra+",width="+largura+",height="+altura);
}
function redimenciona(){
	var i=0;
	function resize() {
		if (navigator.appName == 'Netscape') i=40;
		if (document.images[0]) window.resizeTo(document.images[0].width +50, document.images[0].height+80-i);
		if (window.moveTo((window.screen.width-document.images[0].width)/2,(window.screen.height-document.images[0].height)/2));
	}
}
function montaSWF(arquivo,largura,altura,action){
	
	var now = new Date();	
	var dia = now.getDay();
	var mes = now.getMonth();
	var ano = now.getFullYear();
	var hora = now.getHours();
	var mintuto = now.getMinutes();
	var segundo = now.getSeconds();
	var data = ano+""+mes+""+dia+""+hora;	
	
	document.write('<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="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="swf/'+ arquivo +'.swf?ieSux='+ data +'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="FlashVars" value="'+ action +'&clearCache='+ data +'" />');
	document.write('<embed FlashVars="'+ action +'&clearCache='+ data +'" wmode="transparent" menu="false" src="swf/'+ arquivo +'.swf?ieSux='+ data +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
	document.write('</object>');
	
}

function altProduto(input,i) {
    objI = eval(input.value.replace(",","."));
    objMed = 1;
    document.getElementById("fixme").style.display = '';
    if (objI % objMed != 0 || objI == 0) {
        if (objI >= 1) {
            for (x = 0; x <= parseInt(objI); x++) {
                if ((x * objMed) >= objI) {
                    alert(unescape('A quantidade ser%E1 ajustada para ' + (x * objMed) + '.'));
                    doRequest("server.aspx?action=altCarrinho&id=" + i + "&valor=" + (x * objMed), carrinho);
                    return;
                }
            }
            alert(unescape('A quantidade ser%E1 ajustada para ' + (x * objMed) + '.'));
            doRequest("server.aspx?action=altCarrinho&id=" + i + "&valor=" + (x * objMed), carrinho);
        }
        else {
            alert(unescape('A quantidade ser%E1 ajustadada para ' + objMed + '.'));
            doRequest("server.aspx?action=altCarrinho&id=" + i + "&valor=" + objMed, carrinho);
        }
    }
    else {
        doRequest("server.aspx?action=altCarrinho&id=" + i + "&valor=" + input.value, carrinho);
    }
}

function remProduto(i) {
    doRequest('server.aspx?action=remCarrinho&id=' + i,carrinho);
}

function carrinho(f) {
    window.location.href='carrinho.aspx';
}

function formTipo(i) {
    switch(parseInt(i)) {
        case 0:
            document.getElementById("trContato").style.display = 'none';
            document.getElementById("trNascimento").style.display = '';
            if (document.getElementById("trSexo"))
                document.getElementById("trSexo").style.display = '';
            document.getElementById("trCpf").style.display = '';
            document.getElementById("trCnpj").style.display = 'none';
            break;
        case 1:
            document.getElementById("trContato").style.display = '';
            document.getElementById("trNascimento").style.display = 'none';
            if (document.getElementById("trSexo"))
                document.getElementById("trSexo").style.display = 'none';
            document.getElementById("trCpf").style.display = 'none';
            document.getElementById("trCnpj").style.display = '';
            break;
    }
}

function frete(i, valor, total) {
    var d = document.getElementById("liTotal");
    d.innerHTML = "Total: R$ " + float2moeda(valor + total);
}

function float2moeda(num) {
    x = 0;

    if (num < 0) {
        num = Math.abs(num);
        x = 1;
    }

    if (isNaN(num)) num = "0";
    cents = Math.floor((num * 100 + 0.5) % 100);

    num = Math.floor((num * 100 + 0.5) / 100).toString();

    if (cents < 10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.'
               + num.substring(num.length - (4 * i + 3));

    ret = num + ',' + cents;
    if (x == 1) ret = ' - ' + ret;
    return ret;
}