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 menudrop(n) {
    var div = document.getElementById("menudrop" + n);
    if (div.style.display == "none")
        div.style.display = '';
    else
        div.style.display = 'none';
}



function aplica_mascara_cpfcnpj(campo, tammax, teclapres) {
    var tecla = teclapres.keyCode;

    if ((tecla < 48 || tecla > 57) && (tecla < 96 || tecla > 105) && tecla != 46 && tecla != 8) {
        return false;
    }

    var vr = campo.value;
    vr = vr.replace(/\//g, "");
    vr = vr.replace(/-/g, "");
    vr = vr.replace(/\./g, "");
    var tam = vr.length;

    if (tam <= 2) {
        campo.value = vr;
    }
    if ((tam > 2) && (tam <= 5)) {
        campo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam);
    }
    if ((tam >= 6) && (tam <= 8)) {
        campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
    }
    if ((tam >= 9) && (tam <= 11)) {
        campo.value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam);
    }
    if ((tam == 12)) {
        campo.value = vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam);
    }
    if ((tam > 12) && (tam <= 14)) {
        campo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam);
    }
}

//Verifica se CPF ou CGC e encaminha para a devida função, no caso do cpf/cgc estar digitado sem mascara
function verifica_cpf_cnpj(cpf_cnpj) {
    if (cpf_cnpj.length == 11) {
        return (verifica_cpf(cpf_cnpj));
    } else if (cpf_cnpj.length == 14) {
        return (verifica_cnpj(cpf_cnpj));
    } else {
        return false;
    }
    return true;
}

//Verifica se o número de CPF informado é válido
function verifica_cpf(sequencia) {
    if (Procura_Str(1, sequencia, '00000000000,11111111111,22222222222,33333333333,44444444444,55555555555,66666666666,77777777777,88888888888,99999999999,00000000191,19100000000') > 0) {
        return false;
    }
    seq = sequencia;
    soma = 0;
    multiplicador = 2;
    for (f = seq.length - 3; f >= 0; f--) {
        soma += seq.substring(f, f + 1) * multiplicador;
        multiplicador++;
    }
    resto = soma % 11;
    if (resto == 1 || resto == 0) {
        digito = 0;
    } else {
        digito = 11 - resto;
    }
    if (digito != seq.substring(seq.length - 2, seq.length - 1)) {
        return false;
    }
    soma = 0;
    multiplicador = 2;
    for (f = seq.length - 2; f >= 0; f--) {
        soma += seq.substring(f, f + 1) * multiplicador;
        multiplicador++;
    }
    resto = soma % 11;
    if (resto == 1 || resto == 0) {
        digito = 0;
    } else {
        digito = 11 - resto;
    }
    if (digito != seq.substring(seq.length - 1, seq.length)) {
        return false;
    }
    return true;
}

//Verifica se o número de CNPJ informado é válido
function verifica_cnpj(sequencia) {
    seq = sequencia;
    soma = 0;
    multiplicador = 2;
    for (f = seq.length - 3; f >= 0; f--) {
        soma += seq.substring(f, f + 1) * multiplicador;
        if (multiplicador < 9) {
            multiplicador++;
        } else {
            multiplicador = 2;
        }
    }
    resto = soma % 11;
    if (resto == 1 || resto == 0) {
        digito = 0;
    } else {
        digito = 11 - resto;
    }
    if (digito != seq.substring(seq.length - 2, seq.length - 1)) {
        return false;
    }

    soma = 0;
    multiplicador = 2;
    for (f = seq.length - 2; f >= 0; f--) {
        soma += seq.substring(f, f + 1) * multiplicador;
        if (multiplicador < 9) {
            multiplicador++;
        } else {
            multiplicador = 2;
        }
    }
    resto = soma % 11;
    if (resto == 1 || resto == 0) {
        digito = 0;
    } else {
        digito = 11 - resto;
    }
    if (digito != seq.substring(seq.length - 1, seq.length)) {
        return false;
    }
    return true;
}

//Procura uma string dentro de outra string
function Procura_Str(param0, param1, param2) {
    for (a = param0 - 1; a < param1.length; a++) {
        for (b = 1; b < param1.length; b++) {
            if (param2 == param1.substring(b - 1, b + param2.length - 1)) {
                return a;
            }
        }
    }
    return 0;
}

//Retira a máscara do valor de cpf_cnpj
function retira_mascara(cpf_cnpj) {
    return cpf_cnpj.replace(/\./g, '').replace(/-/g, '').replace(/\//g, '')
}

var offX = -150;          // X offset from mouse position
var offY = 10;          // Y offset from mouse position

function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function follow(evt,divName) 
{
	if (document.getElementById) {
		var obj = document.getElementById(divName).style;
		obj.display = '';
		obj.left = (parseInt(mouseX(evt))+offX) + 'px';
		obj.top = (parseInt(mouseY(evt))+offY) + 'px';
	}
}

function Hd(divName)
{
    document.getElementById(divName).style.display = 'none';
}
function ShowDiv(divName)
{
    document.getElementById(divName).style.display = 'block';
}

function identificaWH() {
	var img = arguments[0];
	var largura = img["width"];
	var altura = img["height"];
	y = -(altura/2);
	x = -(largura/2);
	img.style.marginBottom =  "0px";
	img.style.marginRight =  "0px";
	img.style.marginTop =  y.toString() + "px";
	img.style.marginLeft =  x.toString() + "px";
}

