function centro(p,n,l,a,v1,v2,v3,v4,v5,v6,v7,v8,v9){var l = l; var a = a; var t = (screen.height/2)-(a/2); var d = (screen.width/2)-(l/2); window.open(p,n,'width='+l+',height='+a+',top='+t+',left='+d+',scrollbars='+v1+',menubar='+v2+',directories='+v3+',location='+v4+',copyhistory='+v5+',status='+v6+',toolbar='+v7+',maximized='+v8+',resizable='+v9+'');}
function MarcaTodos(botao,nome){var sa=true; erro=0; if(document.all){f = document.all[nome];}else{if(getElementById){f = getElementById(nome);}else{erro=1;}} if(erro==0){var sa=true; if(botao.checked)sa=false; for(var i=0;i<f.elements.length;i++){var e = f.elements[i]; if(sa)e.checked=false; else e.checked=true;} if(sa)botao.checked=false; else botao.checked=true;}}
function escolha(valor,janela){
	if(valor!="" && janela!=""){
	window.open(valor,janela);
	}
}
function trocar_string(velho,novo,texto) {
	for (var i=0; i<texto.length; i++) {
		if (texto.substring(i,i+velho.length) == velho) {
		texto = texto.substring(0,i)+novo+texto.substring(i+velho.length,texto.length)
		}
	}
	return texto;
}
function trim(str){
	str=str.replace(/\s+/g," ");
	str=str.replace(/^ /,"");
	str=str.replace(/ $/,"");
	return str;
}
function validar_formulario(f,f_acao,f_metodo,campos_sep,campos_obr,campos_des){
	obrigatorios = campos_obr.split(campos_sep);
	descricoes = campos_des.split(campos_sep);
	if(obrigatorios.length == descricoes.length){
		erro=0;
		for(i=1;i<=(obrigatorios.length-1);i++){
			if(trim(f[obrigatorios[i]].value)==""){
				alert(descricoes[i]);
				f[obrigatorios[i]].focus();
				erro = 1;
				return false;
				break;
			}
		}
		//if(erro==0){f.action = f_acao; f.method = f_metodo; f.submit();}
	}else{
		alert("\nERRO!\ncada campo obrigatório deve possuir uma descrição\n");
		return false;
	}
}


function meses(x){
	mes = "Janeiro,Fevereiro,Março,Abril,Maio,Junho,Julho,Agosto,Setembro,Outubro,Novembro,Dezembro";
	mes = mes.split(",");
	return mes[x];
}


function anobissexto(){
	return (ano % 4 == 0 &&(ano % 100 != 0 || ano % 400 == 0));
}

function nome_area(valor,pular){
return valor.substr(pular,valor.length).toUpperCase();
}

var markedRow = new Array();
function setPointer(theRow, thePointerColor, theNormalBgColor){
	var theCells = null;

	if (thePointerColor == '' || typeof(theRow.style) == 'undefined'){
	//return false;
	}
	if (typeof(document.getElementsByTagName) != 'undefined') {
	theCells = theRow.getElementsByTagName('td');
	}else if (typeof(theRow.cells) != 'undefined'){
		theCells = theRow.cells;
		}else{
		return false;
	}
	
	var rowCellsCnt  = theCells.length;
	var currentColor = null;
	var newColor     = null;

	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined'){
		currentColor = theCells[0].getAttribute('bgcolor');
		newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
		? theNormalBgColor
		: thePointerColor;
		for(var c = 0; c < rowCellsCnt; c++){
		theCells[c].setAttribute('bgcolor', newColor, 0);
		}
	}else{
		currentColor = theCells[0].style.backgroundColor;
		newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
		? theNormalBgColor
		: thePointerColor;
		for(var c = 0; c < rowCellsCnt; c++){
		theCells[c].style.backgroundColor = newColor;
		}
	}
	return true;
}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) {
if (sMask.charAt(i-1) == "9") {
return ((nTecla > 47) && (nTecla < 58)); }
else {
return true;
} }
else {
return true;
}
}


function valida_data(form,objeto,valor){
	var mNomes = "JanFebMarAprMayJunJulAugSepOctNovDec"
	var mValores = "312831303130313130313031"
	var alertMsg = ""
	var forFocus = form+"."+objeto+".focus()"
	var erro = true
	var args = valida_data.arguments
    dia   	= parseInt(valor.substring(0,2),10)
	mes   	= parseInt(valor.substring(3,5),10)
	ano   	= parseInt(valor.substring(6,10),10)
	objeto = args[1]	
	valor  = args[2]
	var lastDate = 0
	if (mes == 2){
		if (anobissexto(ano)) {
			lastDate = 29
		}
		else{
			lastDate = 28
		}
	} 
	else {
		lastDate = mValores.substring((mes-1)*2, (mes-1)*2+2)
	}
	if (valor.length<10){
		eval(forFocus)
		return false
	}
	else if ( (valor.substring(2,3) != "/" ) || (valor.substring(5,6) != "/") ) {
		eval(forFocus)
		return false
	}
	else if (ano < 1890){
		eval(forFocus)
		return false
	}

	else if ( (isNaN(dia)) || (isNaN(mes)) || ( isNaN(ano)) ){
		eval(forFocus)
		return false
	}
	else if ( (mes > 12) || (mes <= 0) ){
		eval(forFocus)
		return false
	}
    else if ( (dia > lastDate) || (dia <=0) ){
		eval(forFocus)
		return false
	}
	else {
      var newValue = ""
	if (dia<10){
		dia = "0"+dia
	}
	if (mes<10){
		mes = "0"+mes
	}
	return true}
}

function valida_email(conteudo) {
  Valor = false
  if ( conteudo.indexOf(".@") > -1 )	
  {
	return false ;	
  }
  if ( conteudo.indexOf("@.") > -1 )	
  {
	return false ;	
  }
  if ( conteudo.indexOf(";") > -1 )	
  {
	return false ;	
  }
  if ( conteudo.indexOf("www") > -1 )	
  {
	return false ;	
  }
  if ( conteudo.indexOf(" ") > -1 )	
  {
	return false ;	
  }
  if ( conteudo.substr(conteudo.length-1,1) == "." )
  {
	return false ;	
  }
  for (Count=0; Count<conteudo.length; Count++) {
      ch = conteudo.substring (Count, Count+1);
	   if ((conteudo.length - (Count+1)) >0 ){
		    if (ch=='@') {
				if ( Valor ) 	
					return (false);
				else
					Valor = true;
			}
			if(!((ch.charCodeAt(0)>=65 && ch.charCodeAt(0)<=90) || (ch.charCodeAt(0)>=97 && ch.charCodeAt(0)<=122)  || (ch.charCodeAt(0)>=48 && ch.charCodeAt(0)<=57) || ch.charCodeAt(0)==46 || ch.charCodeAt(0)==64  
			|| ch.charCodeAt(0)==95  || ch.charCodeAt(0)==45)){
				return false;
			}
		}
		
  }
  return (Valor);
}


function isNumber(sNumero, iDecimais)
{
  var bRet
  var i
  bRet = true
  if (iDecimais > 0)
  {
	 if (sNumero.length < iDecimais + 2 || (sNumero.indexOf(".", 0) == -1 && sNumero.indexOf(",", 0) == -1))
	 {
		bRet = false
	 }
  }
  if (bRet)
  {
	 i = 0
	 while(i < sNumero.length && bRet)
	 {
		if (iDecimais > 0)
		{
	if (i == sNumero.length - (iDecimais + 1))
	{
	  if (sNumero.charAt(i) != "." && sNumero.charAt(i) != ",")
	  {
		 bRet = false
	  }
	}
	else
	{
	  if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
	  {
		 bRet = false
	  }
	}
		}
		else
		{
	if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
	{
	  bRet = false
	}
		}
		i++
	 }
  }
  return bRet
}

function strreplace(str, char_busca, char_substr) {
  cnt = str.length;
  var str_novo = '';
  for (var vdigpos = 0; vdigpos < cnt; vdigpos++ ) {
    vdig = str.substr(vdigpos,1);
	if (vdig == char_busca) { 
	  str_novo += char_substr; }
	else { 
	  str_novo += vdig; }
  }
  return str_novo;
}

function chkcpf(vcic){
	  var cic_old = vcic;
	  vcic = strreplace(vcic, '.', '');
	  vcic = strreplace(vcic, '-', '');
      expr  = new RegExp("0{11}|1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}");
      if (vcic.match(expr)){
         vcic = cic_old;
         return false;
      }
      if (isNaN(vcic) || vcic.length != 11){
         vcic = cic_old;
         return false;
      }
      for (var vdigpos = 10; vdigpos < 12; vdigpos++ ){
         var vdig = 0;
         var vpos = 0;
         for (var vfator = vdigpos;vfator >= 2; vfator-- ){
            vdig = eval(vdig + vcic.substr(vpos,1) * vfator);
            vpos++;
         }
         vdig  = eval(11 -(vdig % 11)) < 10 ? eval(11 - vdig % 11) : 0;
         if (vdig != eval(vcic.substr(vdigpos-1,1))) {
         vcic = cic_old;
         return false;
      }
      }
   return true;
}

function chkcnpj(vcnpj){
	 var cnpj_old = vcnpj;
     vcnpj = strreplace(vcnpj, '.', '');
     vcnpj = strreplace(vcnpj, '/', '');
     vcnpj = strreplace(vcnpj, '-', '');
     if (isNaN(vcnpj) || vcnpj.length != 14){
		 vcnpj = cnpj_old;
         return false;
      }
      for (var vdigpos = 13; vdigpos < 15; vdigpos++ ){
         var vdig = 0;
         var vpos = 0;
         for (var vfator = vdigpos - 8 ;vfator >= 2; vfator-- ){
            vdig = eval(vdig + vcnpj.substr(vpos,1) * vfator);
            vpos++;
         }
         for (var vfator = 9 ;vfator >= 2; vfator-- ){
            vdig = eval(vdig + vcnpj.substr(vpos,1) * vfator);
            vpos++;
         }
         vdig  = eval(11 -(vdig % 11)) < 10 ? eval(11 - vdig % 11) : 0;
         if (vdig != eval(vcnpj.substr(vdigpos-1,1))) {
		 vcnpj = cnpj_old;
         return false;
      }
      }
   return true;
}
