function sortSelect(obj){
    var o = new Array();
    for (var i=0; i<obj.options.length; i++){
        o[o.length] = new Option(obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected);
    }
    o = o.sort(
        function(a,b){ 
            if ((a.text+"") < (b.text+"")) { return -1; }
            if ((a.text+"") > (b.text+"")) { return 1; }
            return 0;
        } 
    );

    for (var i=0; i<o.length; i++){
        obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
    }
}

function fecha(div) {
	eval(div + ".style.visibility = 'hidden'");
	eval(div + ".innerHTML = ''");
}

function tmpFecha(div, campo) {
	eval("document.formadm." + campo + ".value = '';");
	setTimeout("fecha(' " + div + "')", 300);
}

function strReplace(value, antStr, newStr) {
	value = value.toString();
	while (value.indexOf(antStr) != -1) {
		value = value.replace(antStr, newStr);
	}
	return value;
}

function mostraCatalogo(codigo) {
    document.princ.acao.value = 'VERCAT';
    document.princ.codi.value = codigo;
    document.princ.submit();
}


function strToFloat(value) {
	value = strReplace(value, ".", "");
	value = (strReplace(value, ",", ".")*1);
	return value;
}

function testFloat(obj) {
	if (!obj.value)
	return;

	val2 = strToFloat(obj.value);
	val1 = parseFloat(val2)
	if ((val1*1) != (val2*1)) {
		alert("Valor inválido!")
		obj.focus();
		obj.select();
	}
}

function formatFloat(value) {
	if (value == 0)
	return "0,00";
	value = value.toString();

	if (value == parseFloat(value)) {
		value = strReplace(value, ".", ",");
	}
	else {
		value = strReplace(value, ".", "");
	}

	Dec = '00';
	Int = '0';
	if (value.indexOf(',') != -1) {
		Int = value.substring(0, value.indexOf(','));
		Dec = value.substring(value.indexOf(',') + 1);
	}
	else {
		Int = value;
	}

	if (Dec.length > 2) {
		Dec = Dec.substring(0, 2);
	}
	else {
		while (Dec.length < 2)
		Dec += '0';
	}

	Int = (Int*1);
	Int = Int.toString();
	aux = '';
	for (x = 1 ; x <= Int.length; x++) {
		sep = (((x % 3) == 0) && (x != Int.length))?'.':'';
		aux = sep + (Int.substring(Int.length - x, Int.length - x+1)) + aux;
	}
	Int = aux;

	return (Int + ',' + Dec);
}

function testKey(obj, eve) {
	var keyPode = '48,49,50,51,52,53,54,55,56,57,58,59';
	if ((eve.keyCode == 46 || eve.keyCode == 44) && (obj.value.indexOf(',') == -1)) {
		eve.keyCode = 44
		return true;
	}
	if (keyPode.indexOf(eve.keyCode) != -1) {
		return true;
	}
	return false
}

function atendimento(){
	welcomeWindow = window.open("http://atendimento.ajudaaovivo.com.br:23061/aj361530/at.pl?online=s&corfundo=D3E2FF&corfontes=000040&coredits=FFFFFF&corfonteedits=2A2A2A&corfontebotoes=000000&carregaimagem=S&textol1=Nosso%20atendimento%20é%20no%20horário%20comercial.&textol2=Para%20suporte%20técnico,%20ligue%20(47)%209973%203793.", "welcomeWindow", "width=295,height=340")
}

function Get_Cookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
	var cookieString = name + "=" +escape(value) +
	( (expires) ? ";expires=" + expires.toGMTString() : "") +
	( (path) ? ";path=" + path : "") +
	( (domain) ? ";domain=" + domain : "") +
	( (secure) ? ";secure" : "");
	document.cookie = cookieString;
}

function Delete_Cookie(name,path,domain) {
	if (Get_Cookie(name)) document.cookie = name + "=" +
	( (path) ? ";path=" + path : "") +
	( (domain) ? ";domain=" + domain : "") +
	";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000));

function sortSelect(obj){
	var o = new Array();
	for (var i=0; i<obj.options.length; i++){
		o[o.length] = new Option(obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected);
	}
	o = o.sort(
	function(a,b){
		if ((a.text+"") < (b.text+"")) { return -1; }
		if ((a.text+"") > (b.text+"")) { return 1; }
		return 0;
	}
	);

	for (var i=0; i<o.length; i++){
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}

function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}
function scrollX() {return window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;}
function scrollY() {return window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;}

function processandoOpen() {
	document.getElementById('div_aguarde').style.top  = (pageHeight() + (scrollY() * 2)) / 2;
	document.getElementById('div_aguarde').style.left = (pageWidth() / 2) - 90;
	document.getElementById('div_aguarde').style.visibility = '';
}

function processandoClose() {
	document.getElementById('div_aguarde').style.visibility = 'hidden';
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function findObj(n, d) {
	//n4 - n6 - ie5 - opera
	if (window.mmIsOpera)
	return (document.getElementById(n));

	if (document.all)
	return (document.all[n]);

	if (document.getElementById) {
		if (document.getElementById(n))
		return (document.getElementById(n));
	}

	if (document.getElementsByName) {
		if (document.getElementsByName(n)[0])
		return document.getElementsByName(n)[0];
	}

	var p,i,x;
	if (!d)
	d=document;
	if ((p=n.indexOf("?"))>0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}

	if (!(x=d[n])&&d.all)
	x=d.all[n];

	for (i=0;!x&&i<d.forms.length;i++)
	x=d.forms[i][n];

	return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function pula(nc, cam, pcam) {
	if(cam.value.length == nc) {
		document.all[pcam].focus();
	}
}

function seTecla(event, tcl, comando) {
	var tecla;
	if (navigator.appName.indexOf("Netscape")!= -1)
	tecla = event.which;
	else
	tecla = event.keyCode;
	key = String.fromCharCode(tecla);
	if (tecla == tcl)
	eval(comando);
}

function seTecla2(tecla, comando, event) {
	key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

	if(tecla == key) {
		eval(comando);
	}

	return key != 13;
}

function validaTecla(campo, event) {
	var BACKSPACE = 8;
	var TAB = 0;
	var key;
	var tecla;
	CheckTAB = true;
	if (navigator.appName.indexOf("Netscape")!= -1)
	tecla = event.which;
	else
	tecla = event.keyCode;
	key = String.fromCharCode(tecla);
	if (tecla == 13)
	return false;
	else
	if (tecla == BACKSPACE)
	return true;
	else
	if (tecla == TAB)
	return true;
	else
	return (isNum(key));
}

function isNum(caractere) {
	var strValidos = "0123456789"
	if (strValidos.indexOf(caractere) == -1)
	return false;
	return true;
}

function onExitCPF(obj) {
	obj.value=deixaSoNumero(obj.value);
	if (obj.value.length>0)  {
		var valido = valida_CPF(obj);
		if (valido) {
			FormataCPF(obj);
		}
		else {
			obj.select();
			obj.focus();
		}
	}
}

function validaTecla(campo, event) {
	var BACKSPACE = 8;
	var TAB = 0;
	var key;
	var tecla;
	CheckTAB = true;
	if (navigator.appName.indexOf("Netscape")!= -1)
	tecla = event.which;
	else
	tecla = event.keyCode;
	key = String.fromCharCode(tecla);
	if (tecla == 13)
	return false;
	else
	if (tecla == BACKSPACE)
	return true;
	else
	if (tecla == TAB)
	return true;
	else
	return (isNum(key));
}

function deixaSoNumero(Data) {
	val = '';
	for (x = 0; x < Data.length; x++) {
		if (Data.charAt(x)=='0')
		val+=Data.charAt(x);
		else
		if (parseInt(Data.charAt(x)))
		val+=Data.charAt(x);
	}
	return(val)
}

function FormataCPF(obj) {
	obj.value=
	obj.value.substring(0,3) + '.' +
	obj.value.substring(3,6) + '.' +
	obj.value.substring(6,9) + '-' +
	obj.value.substring(9,11);
}

function valida_CPF(obj) {
	s=obj.value;
	var varFirstChr = s.charAt(0);
	var vaCharCPF = false;
	soma=0;
	for ( i=0; i<9; i++ ) {
		soma += (10-i) * ( eval(s.charAt(i)) );
	}
	digito_verificador = 11-(soma % 11);
	if ((soma % 11) < 2)
	digito_verificador = 0;
	if ( eval(s.charAt(9)) != digito_verificador ) {
		alert("CPF inválido!");
		return false;
	}

	soma=0;
	for ( i=0; i<9; i++ ) {
		soma += (11-i) * ( eval(s.charAt(i)) );
	}
	soma += 2 * ( eval(s.charAt(9)) );
	digito_verificador = 11-(soma % 11);
	if ((soma % 11) < 2)
	digito_verificador = 0;
	if ( eval(s.charAt(10)) != digito_verificador ) {
		alert("CPF inválido!");
		return false;
	}
	return true;
}

function Mascarar_Data(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) {
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
		if (campo.value.length == 5 ) {
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
	}
}

function Mascarar_NossoNumero(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 10 ) {
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function Mascarar_Documento(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 11 ) {
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
		if (campo.value.length == 13 ) {
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
	}
}

function Mascarar_Hora(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) {
			campo.value = campo.value;
			campo.value = campo.value + ':';
		}
	}
}

function somaHora(hrA, hrB, zerarHora) {
	if(hrA.length != 5 || hrB.length != 5) return "00:00";
	
	temp = 0;
	nova_h = 0;
	novo_m = 0;

	hora1 = hrA.substr(0, 2) * 1;
	hora2 = hrB.substr(0, 2) * 1;
	minu1 = hrA.substr(3, 2) * 1;
	minu2 = hrB.substr(3, 2) * 1;
	
	temp = minu1 + minu2;
	while(temp > 59) {
		nova_h++;
		temp = temp - 60;
	}
	novo_m = temp.toString().length == 2 ? temp : ("0" + temp);

	temp = hora1 + hora2 + nova_h;
	while(temp > 23 && zerarHora) {
		temp = temp - 24;
	}
	nova_h = temp.toString().length == 2 ? temp : ("0" + temp);

	return nova_h + ':' + novo_m;
}

function validaHrIniFin(hrI, hrF) {
	hrI = deixaSoNumero(hrI) * 1;
	hrF = deixaSoNumero(hrF) * 1;
	
	if(hrF >= hrI) {
		return false;
	}
	return true;
}

function validaHora(hora) {
	if(hora.length == 0) {
		return true;
	}
	if(hora.length != 5) {
		return false;
	}
	h = hora.substring(0, 2);
	m = hora.substring(3, 6);
	h = parseInt(h);
	m = parseInt(m);

	if(h < 0 || h > 23) {
		return false;
	}
	if(m < 0 || m > 59) {
		return false;
	}

	return true;
}

function Mascarar_Cep(keypress, objeto){
	campo = eval (objeto);
	caracteres = '1234567890';

	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) {
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 6 ) {
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function validaFone(keypress, objeto){
	campo = eval (objeto);
	caracteres = '-1234567890() ';

	if (caracteres.search(String.fromCharCode(keypress)) == -1) {
		event.returnValue = false;
	}
}

function validaTexto(keypress, objeto){
	campo = eval (objeto);
	caracteres = 'abcdefghijglmnopqrstuvwxyzABCDEFGHIJGLMNOPQRSTUVWXYZºª.,()- ';

	if (caracteres.search(String.fromCharCode(keypress)) == -1) {
		event.returnValue = false;
	}
}

function dataBr2Db(dat, hor) {
	retorno  = dat.substring(6, 10);
	retorno += dat.substring(3, 5);
	retorno += dat.substring(0, 2);
	retorno += hor.substring(0, 2);
	retorno += hor.substring(3, 5);

	return retorno;
}


function mostraNoticia(codigo) {
	document.princ.acao.value = 'VERNOT';
	document.princ.codi.value = codigo;
	document.princ.submit();
}

function outrasNoticias() {
	document.princ.acao.value = 'OUTNOT';
	document.princ.submit();
}

function mudaAno(ano) {
	document.princ.acao.value = 'OUTNOT';
	document.princ.codi.value = ano;
	document.princ.submit();
}

function BuscaCombo(in_sFormName, in_sInputName, in_sSelectName){
	sSearchString = document.forms[in_sFormName].elements[in_sInputName].value.toUpperCase();
	iSearchTextLength = sSearchString.length;

	if(document.forms[in_sFormName].onde.value == 1) {
		for (j=0; j < document.forms[in_sFormName].elements[in_sSelectName].options.length; j++){
			sOptionText = document.forms[in_sFormName].elements[in_sSelectName].options[j].text;
			sOptionComp = sOptionText.substr(0, iSearchTextLength).toUpperCase();

			if(sSearchString == sOptionComp){
				document.forms[in_sFormName].elements[in_sSelectName].selectedIndex = j;
				break;
			}
		}
	}
	else if(document.forms[in_sFormName].onde.value == 2) {
		for (j=0; j < document.forms[in_sFormName].elements[in_sSelectName].options.length; j++){
			sOptionText = document.forms[in_sFormName].elements[in_sSelectName].options[j].text;

			if(sOptionText.indexOf(sSearchString) != -1){
				document.forms[in_sFormName].elements[in_sSelectName].selectedIndex = j;
				break;
			}
		}
	}
}

function validaPlaca(obj) {
	var str, certo;
	certo=true;
	if (!obj.value)
	return false;

	if (obj.value.length<7) {
		alert('Placa inválida!');
		obj.focus();
		obj.select();
		return false;
	}
	str=obj.value.toUpperCase();
	for (x=0; x<7; x++) {
		if (x<3) {
			if (str.charAt(x)<'A' || str.charAt(x)>'Z' || str.charAt(x)==' ') {
				certo=false;
				break;
			}
		}
		else {
			if (str.charAt(x)<'0' || str.charAt(x)>'9' || str.charAt(x)==' ') {
				certo=false;
				break;
			}
		}
	}
	if (!certo) {
		alert('Placa inválida!');
		obj.focus();
		obj.select();
		return false;
	}
	obj.value=str;
}

function saiDuracao(obj) {
	dur = obj.value;

	if(dur.length == 5 || dur.length == 0) {
		obj.value = dur;
	}

	while(dur.search(':') != -1) {
		dur = dur.replace(':', '');
	}

	len = dur.length;
	if(len == 4) {
		obj.value = dur.substring(0, 2) + ':' + dur.substring(2, 5);
	}
	if(len == 3) {
		obj.value = '0' + dur.substring(0, 1) + ':' + dur.substring(1, 4);
	}
	if(len == 2) {
		obj.value = '00:' + dur;
	}
	if(len == 1) {
		obj.value = '00:0' + dur;
	}
}

function dataBr2IntAMD(dat) {
	ano = dat.substring(6, 10);
	mes = dat.substring(3, 5);
	dia = dat.substring(0, 2);
	data = ano + mes + dia;
	data = parseInt(data);
	return data;
}

function FormataValor(objeto, maxlen) {
	campo = eval(objeto);
	t = campo.value.length;

	if(t == 0) {
		campo.value = '';
	}
	else if(t > maxlen) {
		alert('Número muito grande!');
		campo.value = '';
	}
	else {
		if(t < 3) {
			campo.value = campo.value + ',00';
		}
		else {
			val = campo.value.substring(0, t - 2);
			dec = campo.value.substring(t - 2);
			if(val.length > 3) {
				val = val.substring(0, val.length - 3) + '.' + val.substring(val.length - 3);
			}
			campo.value = val + ',' + dec;
		}
	}
}

function Modulo11(obj) {
	var iPeso, iSoma, iResto, Aux;
	iPeso = 2;
	iSoma = 0;
	szValue=obj;//.value;
	var szValueAux = new String(szValue.substring(0, szValue.length-1));
	var tam = szValueAux.length;
	tam = parseInt(tam,10)-1;
	for(i=parseInt(tam,10); i>=0; i--) {
		Aux = szValue.substr(i, 1);
		iSoma = parseInt(iSoma,10) + ( parseInt(Aux,10) * iPeso);
		if( iPeso == 9 )
		iPeso = 2;
		else
		iPeso+= 1;
	}
	iResto = iSoma % 11
	if( iResto == 0 || iResto == 1 )
	iResto = 0;
	else
	iResto = 11 - parseInt(iResto,10);

	if (szValue.substring(szValue.length-1,szValue.length) != iResto)  {
		//alert('Dígito verificador inválido!');
		//obj.focus();
		//obj.select();
		return false;
	}
	return true;
}

function explode(sep, value) {
	var arr = new Array();
	index = -1;

	while (value.indexOf(sep) != -1) {
		index++;
		arr[index] = value.substring(0, value.indexOf(sep));
		value = value.substring(value.indexOf(sep) + sep.length);
	}
	index++;

	if (value)
	arr[index] = value;

	return arr;
}

function FormataCNPJ(el) {
    vr = deixaSoNumero(el.value);
    tam = vr.length;
    if (tam == 14) {
        el.maxlength="18";
        if (tam <= 2)
        el.value = vr;
        if ((tam > 2) && (tam <= 6))
        el.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
        if ((tam >= 7) && (tam <= 10))
        el.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/';
        if ((tam >= 11) && (tam <= 18))
        el.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(5, 3) + '/' + vr.substr(8, 4) + '-' + vr.substr(12, 2);
    }
    else {
        if (tam > 0) {
            alert("Voce deve digitar 14 posições!");
            el.focus();
            el.select();
        }
    }
    return true;
}

function onExitCNPJ(objeto) {
    objeto.value=deixaSoNumero(objeto.value);
    if (objeto.value.length>0)  {
        var valido = valida_CGC(objeto);
        if (valido) {
            FormataCNPJ(objeto);
        }
    }
}

function valida_CGC(obj) {
    // verifica o tamanho
    pcgc = obj.value;
    if (pcgc.length<14 && pcgc.length>0) {
        alert ("Tamanho Invalido de CNPJ")
        obj.focus();
        obj.select();
        return false;
    }
    else  {
        sim=true
    }
    if (sim )  { // verifica se e numero
    for (i=0;((i<=(pcgc.length-1))&& sim); i++)  {
        val = pcgc.charAt(i)
        // alert (val)
        if ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4") &&
        (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {
            sim=false
        }
    }
    if (sim) {// se for numero continua
    m2 = 2
    soma1 = 0
    soma2 = 0
    for (i=11;i>=0;i--) {
        val = eval(pcgc.charAt(i))
        // alert ("Valor do Val: "+val)
        m1 = m2
        if (m2<9) {
            m2 = m2+1
        }
        else {
            m2 = 2
        }
        soma1 = soma1 + (val * m1)
        soma2 = soma2 + (val * m2)
    }  // fim do for de soma

    soma1 = soma1 % 11
    if (soma1 < 2) {
        d1 = 0
    }
    else {
        d1 = 11- soma1
    }
    soma2 = (soma2 + (2 * d1)) % 11
    if (soma2 < 2) {
        d2 = 0
    }
    else {
        d2 = 11- soma2
    }
    if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))  {
        sim=true
    }
    else
    sim=false
    }
    }
    if (!sim) {
        alert('CNPJ Inválido!');
        obj.focus();
        obj.select();
    }
    else
    return true;
}

function dataSemana(data){ 
      data.toString();
      ano = data.substr(6,4);
      mes = data.substr(3,2);
      dia = data.substr(0,2);
      novaData = new Date(ano,mes-1,dia);      
      return  novaData.getDay();
}

function bgCruz(coords, cor, tip) {
	col = coords.substring(0, coords.indexOf('|'));
	lin = coords.substring(coords.indexOf('|') + 1);
	
	if(tip == 0) {
		bg = cor;
	}
	else {
		bg = '#DEDEDE';
	}
	
	//qtdeCols e qtdeLins -> aulapratica.class.php
	
	for(i = 0; i < qtdeCols; i++) {
		document.getElementById("TidC"+i+"L"+lin).style.background = bg;
		//eval("TidC"+i+"L"+lin+".style.background = '"+bg+"';");
	}
	for(x = 0; x < qtdeLins; x++) {
		document.getElementById("TidC"+col+"L"+x).style.background = bg;
		//eval("TidC"+col+"L"+x+".style.background = '"+bg+"';");
	}
}
