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 cadastro(check, input) {
    for (var i in input) {
        if (input[i].id.indexOf("txtIE") > -1) {
            if (check.checked) {
                input[i].value = '';
                input[i].disabled = 'disabled';
            }
            else {
                input[i].disabled = '';
            }
        }
    }
}
    
    

 
function validacpf(){
 
var i;
 
s = document.frmCli.txtCpf.value;
 
var c = s.substr(0,9);
 
var dv = s.substr(9,2);
 
var d1 = 0;
 
for (i = 0; i < 9; i++)
 
{
 
d1 += c.charAt(i)*(10-i);
 
}
 
if (d1 == 0){
 
alert("CPF Invalido")
 
return false;
 
}
 
d1 = 11 - (d1 % 11);
 
if (d1 > 9) d1 = 0;
 
if (dv.charAt(0) != d1)
 
{
 
alert("CPF Invalido")
 
return false;
 
}
 
 
d1 *= 2;
 
for (i = 0; i < 9; i++)
 
{
 
d1 += c.charAt(i)*(11-i);
 
}
 
d1 = 11 - (d1 % 11);
 
if (d1 > 9) d1 = 0;
 
if (dv.charAt(1) != d1)
 
{
 
alert("CPF Invalido")
 
return false;
 
}
 
return true;
 
}
 

function addFav() {
    var url = "http://www.metalpan.com.br";
    var title = "Metal Pan";
    if (window.sidebar) window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) {
        var mbm = document.createElement('a');
        mbm.setAttribute('rel', 'sidebar');
        mbm.setAttribute('href', url);
        mbm.setAttribute('title', title);
        mbm.click();
    }
    else if (document.all) { window.external.AddFavorite(url, title); }
}

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 carregaPagina(select,i){    
    window.location="subcategorias.aspx?idsubcategoria="+ i +"&idmodelo=" + select.value;
}

function validarBusca(){
    f = document.forms[0];
    if(f.busca.value.length < 4)
    {
        alert(unescape('Sua pesquisa deve conter no m%EDnimo 4 caracteres.'));
        return false;
    }
}

function validarTeste(){
    

        alert(unescape('Sua pesquisa deve conter no m%EDnimo 4 caracteres.'));
        return false;
   
}
function ajustar_cnpj(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 2 || input.value.length == 6) {
            input.value += ".";
        }
        if (input.value.length == 10) {
            input.value += "/";
        }
        if (input.value.length == 15) {
            input.value += "-";
        }
    }
    return true;
}

function ajustar_cpf(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9 || (evento.ctrlKey == true && tecla == 97) || (evento.ctrlKey == true && tecla == 99) || (evento.ctrlKey == true && tecla == 118) || (evento.ctrlKey == true && tecla == 120)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 3 || input.value.length == 7) {
            input.value += ".";
        }
        if (input.value.length == 11) {
            input.value += "-";
        }        
    }
    return true;
}

/*
function blockError() {
	return true;
}

window.onerror = blockError;

function disableselect(e) {
	return false;
}

function reEnable() {
	return true;
}

//Se o browser for IE4+
document.onselectstart = new Function("return false");

//Se o browser for NS6
if(window.sidebar) {
	document.onmousedown = disableselect;
	document.onclick = reEnable;
}
*/

function enviaNewsletter() {
    debugger;
    var email = document.forms[0].txtEmail.value;
    if (!email.match(/^([a-zA-Z0-9_-][a-zA-Z0-9_.-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4})$/)) {
        alert(unescape('E-mail inv%E1lido.'));
        return false;
    }
    doRequest('server.aspx?act=incluir&email=' + email, retornoNewsletter);
    return false;
}

function retornoNewsletter(f) {
    alert(f);
    document.forms[0].txtEmail.value = "";
}

function enviaNewsletterEnter(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode : evento.which ? evento.which : evento.charCode);

    if (tecla < 13) {
        enviaNewsletter();
        evento.returnValue = false;
        return false;
    }
    
    return true;
}

function EmptyField(id)
	{
		var Fid             = document.getElementById(id);
		var TheDefaultValue = Fid.defaultValue;
		var TheValue        = Fid.value;
		
		if(TheDefaultValue == TheValue)
		{
			Fid.value = '';
		}
}

function Calcula() {
debugger
    var tbl = document.getElementById("TabelaProduto").getElementsByTagName("input");
    var tot = document.getElementById("Calcula");
    var i, Inp, Qtde, Ipi;
    var Total = 0;
    debugger;
    for (i = 0; i < tbl.length; i++) {
        Inp = tbl[i].name.split('_');
        if (Inp[0] == "txtQuantidade")
            Qtde = parseFloat(tbl[i].value);
        if (Inp[0] == "txtIpi")
            Ipi = tbl[i].value.replace(",", ".");
         if (Inp[0] == "txtValor") {

             if (Ipi != '0.00') {
                 Total += Qtde * tbl[i].value.replace(",", ".") + (((tbl[i].value.replace(",", ".") * Ipi) / 100) *  Qtde);
             }
             else {
                 Total += Qtde * tbl[i].value.replace(",", ".");
             }
        }
    }
    tot.innerHTML = "R$" + Total.toFixed(2).replace(".", ",");
}

function Aceita() {

    var Btn = document.getElementById(arguments[1]);

    if (arguments[0])
        Btn.style.display = "";
    else
        Btn.style.display = "none";
}

