//self.status='FORQUIMICA - SOLUÇÕES PARA UMA PRODUTIVIDADE PLANEJADA.';

function apagar(url,label,myFrame){
 if(confirm("Deseja realmente excluir o item \""+label+"\"?")){
  if(myFrame){
	document.frames[myFrame].location.href=url
  } else {
	location.href=url
  }
 }
}

function Cancelar(url,label){
 if(confirm("Deseja realmente cancelar o item \""+label+"\"?")){
  location.href=url
 }
}

/* Mantém a sessão do usuário ativa, no frame da esquerda :))) */
function sempre_conectado(flag){
	if(flag.checked==true){
		top.frames['left'].location.href = '/logged.php?SID='+SID;
	} else {
		top.frames['left'].location.href = 'about:blank';	
	}
}

function verifica_sempre_conectado(){
	if (document.getElementById) {
		if(top.frames['left'].location.href != 'about:blank'){
			document.getElementById('sempre_conectado').checked = true;
		}
	}
}

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}

function maxLength(textAreaField, limit) {
	var ta = document.getElementById(textAreaField);
	
	if (ta.value.length > limit) {
		ta.value = ta.value.substring(0, limit);
	}
}

function is_numeric(event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if((keyCode < 48 || keyCode > 57) && keyCode!=8 && keyCode!=13) {
	return false	
	}
}

function campo_date(event){
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var campo = event.srcElement;
	var valor = campo.value;

	if((keyCode < 48 || keyCode > 57) && keyCode!=8 && keyCode!=13 && keyCode!=46) {
		return false
	}

	if(keyCode == 13){
		return handleEnter(campo,event);
	}
	
	out='/';
	while (valor.indexOf(out)>-1) {
		valor = valor.replace(out, "");		
	}

	out='.';
	while (pos=valor.indexOf(out)>-1) {
			valor = valor.replace(out, "");	
	}

	tamanho = valor.length+1;

	if(keyCode==46 && (tamanho!=9 || tamanho!=10)){
		return false;
	}

	if(tamanho==6){
		campo.value=valor.substr( 0, 2 ) + '/' + valor.substr( 2, 2 ) + '/' + valor.substr( 4, 2 );
	}
}

function mclick(src,e)
{
 if (!e)
 var e=window.event;
 if(agent_isIE){
 var S=e.srcElement;
 } else {
 var S=e.target;
 }
 if(S.tagName=='TD' || S.tagName=='IMG')
 {
  if(src.children.tags('a')[0])
  {
   src.children.tags('a')[0].click();
  }
 }
}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	
		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 && tecla != 144 ){
		
			if ( tam == tammax ){
				if ( prox == "senhaConta" || (document.form.elements[prox] && document.form.elements[prox].name == "senhaConta"))
				{
					if ( document.applets['tclJava'] )
						document.applets['tclJava'].setFocus();
					else if ( document.form.senhaConta )
						document.form.senhaConta.focus();
				}
				else if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function FormataData(idcampo,evento) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	var obj = document.getElementById(idcampo);
	var valor = obj.value;

	if((keyCode < 48 || keyCode > 57) && keyCode!=8 && keyCode!=13) {
		return false	
	}

	valor = valor.replace( ".", "" );
	valor = valor.replace( "/", "" );
	valor = valor.replace( "/", "" );
	tamanho = valor.length + 1;

	if ( keyCode != 9 && keyCode != 8 ){
		if ( tamanho > 2 && tamanho < 5 )
			obj.value = valor.substr( 0, tamanho - 2  ) + '/' + valor.substr( tamanho - 2, tamanho );
		if ( tamanho >= 5 && tamanho <= 10 )
			obj.value = valor.substr( 0, 2 ) + '/' + valor.substr( 2, 2 ) + '/' + valor.substr( 4, 4 ); 
	}
}

function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

function valida(formulario,campos) {
campos=campos.split(',');
	for(var i=0;i<campos.length;i++) {
		var campo=eval('formulario.' + campos[i]);				
		if(campo.value.length==0 && campos[i]!='email') {
			alert('Preencha o campo ' + campos[i] + ' corretamente.');
			campo.focus();
			return false;
		} else {
			var mailtest = /^(.+)@(.+)\.(.+)[^\.]$/;
			if(campos[i]=='email' && !mailtest.test(campo.value) && campo.value!='') {
				alert('Preencha o campo email corretamente');
				campo.focus();
				return false;
			}
		}
	}
}

function imprimir(){
	/*
	w=800;
	h=600;
	t=(screen.height-h)/2;
	l=(screen.width-w)/2;
	window.open(url,'imprimir','status=0,width='+w+',height='+h+',top='+t+',left='+l);
	//window.open('imprimir.php?str='+str,'imprimir','status=0,width=800,height=600,top=0,left=0');
	*/
	document.all.frmprint.submit();
	//ifrprint.focus();
}

function popit(winurl,winname,w,h){
	t=(screen.height-h)/2;
	l=(screen.width-w)/2;
	if(winurl.indexOf('?')==-1){
		winurl=winurl+'?SID='+SID;
	} else {
		winurl=winurl+'&SID='+SID;
	}

	window.open(winurl,winname,'status=1,scrollbars=1,width='+w+',height='+h+',top='+t+',left='+l+',resizable=1');
}

function showmodal(winurl,mwidth,mheight){
	if(winurl.indexOf('?')==-1){
		winurl=winurl+'?SID='+SID;
	} else {
		winurl=winurl+'&SID='+SID;
	}

	if (document.all&&window.print) //if ie5
		eval('window.showModelessDialog(winurl,"win","help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
	else
		eval('window.open(winurl,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")')
}


function show_div(id) {
	if (document.getElementById) {
		if(eval("document.getElementById('a" + id + "').style.display")=='none') {
			eval("document.getElementById('a" + id + "').style.display='block'")
			eval("document.getElementById('i" + id + "').src='images/tree_o1.gif'")
		} else {
			eval("document.getElementById('a" + id + "').style.display='none'")
			eval("document.getElementById('i" + id + "').src='images/tree_c1.gif'")
		}
	}
}

function showthis(id) {
	if (document.getElementById) {
		if(eval("document.getElementById('" + id + "').style.display")=='none') {
			eval("document.getElementById('" + id + "').style.display='block'")
		} else {
			eval("document.getElementById('" + id + "').style.display='none'")
		}
	}
}

function expand(id) {
id=id.split(',');
	for(var i=0;i<id.length;i++) {
		eval("document.getElementById('a" + id[i] + "').style.display='block'")
		eval("document.getElementById('i" + id[i] + "').src='images/tree_o1.gif'")
	}
}

function collapse(id) {
id=id.split(',');
	for(var i=0;i<id.length;i++) {
		eval("document.getElementById('a" + id[i] + "').style.display='none'")
		eval("document.getElementById('i" + id[i] + "').src='images/tree_c1.gif'")
	}
}

function setlistusuar(){
	var objsrc = document.frmci
	var mylist = new Array();
	var mysel = objsrc.admusuar[objsrc.admusuar.selectedIndex].value
    var duplicado = false;
	var size = objsrc.CD_COLABORADOR_COPIA.length;
	
	for (var j=0; j<size; j++) {
		if(objsrc.CD_COLABORADOR_COPIA.options[j].value==mysel)
			duplicado = true;
	}

	if(objsrc.CD_COLABORADOR_DESTINO.value == mysel)
		duplicado = true;

	if(duplicado == false){
		if(objsrc.CD_COLABORADOR_DESTINO.value.length==0){
			objsrc.CD_COLABORADOR_DESTINO.value=mysel
		} else {
			objsrc.CD_COLABORADOR_COPIA.options[size] = new Option(mysel, mysel, false, false);
		}
	} else {
		alert(mysel +' já foi definido como cópia.');
	}
}

function setalllistusuar(){
	var objsrc = document.frmci
	var mylist = new Array();

	for(var x=0;x<objsrc.admusuar.length;x++){
	    var duplicado = false;
		var mysel=objsrc.admusuar[x].value;
		var size = objsrc.CD_COLABORADOR_COPIA.length;

		for (var j=0; j<size; j++) {
			if(objsrc.CD_COLABORADOR_COPIA.options[j].value==mysel)
				duplicado = true;
		}

		if(objsrc.CD_COLABORADOR_DESTINO.value == mysel)
			duplicado = true;

		if(duplicado == false){
			if(objsrc.CD_COLABORADOR_DESTINO.value.length==0){
				objsrc.CD_COLABORADOR_DESTINO.value=mysel
			} else {
				objsrc.CD_COLABORADOR_COPIA.options[size] = new Option(mysel, mysel, false, false);
			}
		} else {
			alert(mysel +' já foi definido como cópia.');
		}
	}
	objsrc.admdepto.focus();
}

function setlistrn(){
	objsrc = document.frmci
	mylist = new Array();
	mysel = objsrc.admusuar[objsrc.admusuar.selectedIndex].value
    var duplicado = false;
	var size = objsrc.CD_USUARIO_REUNIAOCONVITE.length;

	for (var j=0; j<size; j++) {
		if(objsrc.CD_USUARIO_REUNIAOCONVITE.options[j].value==mysel)
			duplicado = true;
	}

	if(duplicado == false){
		objsrc.CD_USUARIO_REUNIAOCONVITE.options[size] = new Option(mysel, mysel, false, false);
	} else {
		alert(mysel +' já foi convidado(a) para esta reunião.');
	}
}

function setalllistrn(){
	objsrc = document.frmci
	mylist = new Array();

	for(var x=0;x<objsrc.admusuar.length;x++){
	    var duplicado = false;
		var mysel=objsrc.admusuar[x].value;
		var size = objsrc.CD_USUARIO_REUNIAOCONVITE.length;

		for (var j=0; j<size; j++) {
			if(objsrc.CD_USUARIO_REUNIAOCONVITE.options[j].value==mysel)
				duplicado = true;
		}

		if(duplicado == false){
			objsrc.CD_USUARIO_REUNIAOCONVITE.options[size] = new Option(mysel, mysel, false, false);
		} else {
			alert(mysel +' já foi convidado(a) para esta reunião.');
		}
	}
	objsrc.admdepto.focus();
}

function mymenu(div,act){
	obj=document.getElementById(div).style
	if(act==1){
		obj.top	=document.body.scrollTop+event.clientY+1
		obj.left=document.body.scrollLeft+event.clientX+1
		obj.display='block'
		return false
	} else {
		obj.display='none'		
	}	
}

function showhide(id,act) {
	if (document.getElementById) {
		eval("document.getElementById('div" + id + "').style.display='" + act + "'")
      if(act=='none'){
   		eval("document.getElementById('" + id + "').checked=false")
      }
	}
}

function is_float(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13) return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';
if (len == 1) fld.value = '0'+ decSep + '0' + aux;
if (len == 2) fld.value = '0'+ decSep + aux;
if (len > 2) {
aux2 = '';
for (j = 0, i = len - 3; i >= 0; i--) {
if (j == 3) {
aux2 += milSep;
j = 0;
}
aux2 += aux.charAt(i);
j++;
}
fld.value = '';
len2 = aux2.length;
for (i = len2 - 1; i >= 0; i--)
fld.value += aux2.charAt(i);
fld.value += decSep + aux.substr(len - 2, len);
}
return false;
}

function TRMO(obj){
	obj.className;
	if(obj.className=='TRMO')
		obj.className=''
	else
		obj.className='TRMO';
}


//VALIDAÇÃO DE CPF E CNPJ - EDER 30/01/2009
var NUM_DIGITOS_CPF  = 11;
var NUM_DIGITOS_CNPJ = 14;
var NUM_DGT_CNPJ_BASE = 8;
String.prototype.lpad = function(pSize, pCharPad)
{
    var str = this;
    var dif = pSize - str.length;
    var ch = String(pCharPad).charAt(0);
    for (; dif>0; dif--) str = ch + str;
    return (str);
} //String.lpad

String.prototype.trim = function()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
} //String.trim

function unformatNumber(pNum)
{
    return String(pNum).replace(/\D/g, "").replace(/^0+/, "");
} //unformatNumber

function formatCpfCnpj(pCpfCnpj, pUseSepar, pIsCnpj)
{
    if (pIsCnpj==null) pIsCnpj = false;
    if (pUseSepar==null) pUseSepar = true;
    var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
    var numero = unformatNumber(pCpfCnpj);

    numero = numero.lpad(maxDigitos, '0');
    if (!pUseSepar) return numero;

    if (pIsCnpj)
    {
 reCnpj = /(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/;
 numero = numero.replace(reCnpj, "$1.$2.$3/$4-$5");
    }
    else
    {
 reCpf  = /(\d{3})(\d{3})(\d{3})(\d{2})$/;
 numero = numero.replace(reCpf, "$1.$2.$3-$4");
    }
    return numero;
} //formatCpfCnpj

function dvCpfCnpj(pEfetivo, pIsCnpj)
{
    if (pIsCnpj==null) pIsCnpj = false;
    var i, j, k, soma, dv;
    var cicloPeso = pIsCnpj? NUM_DGT_CNPJ_BASE: NUM_DIGITOS_CPF;
    var maxDigitos = pIsCnpj? NUM_DIGITOS_CNPJ: NUM_DIGITOS_CPF;
    var calculado = formatCpfCnpj(pEfetivo, false, pIsCnpj);
    calculado = calculado.substring(2, maxDigitos);
    var result = "";

    for(j = 1; j <= 2; j++)
    {
 k = 2;
 soma = 0;
 for (i = calculado.length-1; i >= 0; i--)
 {
     soma += (calculado.charAt(i) - '0') * k;
     k = (k-1) % cicloPeso + 2;
 }
 dv = 11 - soma % 11;
 if (dv > 9) dv = 0;
 calculado += dv;
 result += dv
    }

    return result;
} //dvCpfCnpj

function isCpf(pCpf)
{
    var numero = formatCpfCnpj(pCpf, false, false);
    var base = numero.substring(0, numero.length - 2);
    var digitos = dvCpfCnpj(base, false);
    var algUnico, i;

    // Valida dígitos verificadores
    if (numero != base + digitos) return false;


    algUnico = true;
    for (i=1; i<NUM_DIGITOS_CPF; i++)
    {
 algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
    }
    return (!algUnico);
} //isCpf

function isCnpj(pCnpj)
{
    var numero = formatCpfCnpj(pCnpj, false, true);
    var base = numero.substring(0, NUM_DGT_CNPJ_BASE);
    var ordem = numero.substring(NUM_DGT_CNPJ_BASE, 12);
    var digitos = dvCpfCnpj(base + ordem, true);
    var algUnico;

    // Valida dígitos verificadores
    if (numero != base + ordem + digitos) return false;

    algUnico = numero.charAt(0) != '0';
    for (i=1; i<NUM_DGT_CNPJ_BASE; i++)
    {
 algUnico = algUnico && (numero.charAt(i-1) == numero.charAt(i));
    }
    if (algUnico) return false;

    if (ordem == "0000") return false;
    return (base == "00000000"
 || parseInt(ordem, 10) <= 300 || base.substring(0, 3) != "000");
} //isCnpj

function isCpfCnpj(pCpfCnpj)
{
    var numero = pCpfCnpj.replace(/\D/g, "");
    if (numero.length > NUM_DIGITOS_CPF)
 return isCnpj(pCpfCnpj)
    else
 return isCpf(pCpfCnpj);
} //isCpfCnpj

function checkUncheckAll(theElement){
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			theForm[z].checked = theElement.checked;
		}
	}
}