function soNumeros(e){
     var key;
     var keychar;

     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) ) {
        return true;
     } else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}

//Impede que caracterec não numéricos entrem em campos de formulário html
//Usar onChange
function soNumerico(tammax){
	event.srcElement.maxLength=tammax;
	if (event.srcElement.value.length+1>tammax) { 
		event.KeyCode=0;
	}
	if ( (event.keyCode >= 48) && (event.keyCode <= 57)) {
		return true;
	} else {
		if (event.keyCode != 8){
			 event.keyCode = 0;
			 return false;
		 }
	}
}

//Verifica se CPF é válido
//Se for válido, retorna TRUE, caso contrário retorna FALSE
function isCpf (numcpf)
{
	x = 0;
	soma = 0;
	dig1 = 0;
	dig2 = 0;
	texto = "";
	numcpf1="";
	len = numcpf.length; x = len -1;
	// var numcpf = "12345678909";
	for (var i=0; i <= len - 3; i++) {
		y = numcpf.substring(i,i+1);
		soma = soma + ( y * x);
		x = x - 1;
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ;
	if (dig1 == 11) dig1=0 ;
	numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (numcpf1.substring(i,i+1) * x);
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0;
	if (dig2 == 11) dig2=0;
	//alert ("Digito Verificador : " + dig1 + "" + dig2);
	if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
		return true;
	}
	return false;
}



function visForm(pe){
	booForm = (pe == 0)?"hidden":"visible";
	objForm = document.forms;
	for(i=0; i<objForm.length; ++i){
		objFormInt = objForm[i].elements;
		for(j=0; j<objFormInt.length; ++j){
			if(objFormInt[j].tagName == "SELECT"){
				objFormInt[j].style.visibility = booForm;
			}
		}
	}
}
function ocultar(camada){
	MM_findObj(camada).style.display = "none";
	visForm(1);
}
function exibir(camada){
	MM_findObj(camada).style.display = "block";
	visForm(0);
}
function abreJanela(caminho,janela,parametros){
	MM_openBrWindow(caminho,janela,parametros);
	janelaNova.focus();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  janelaNova=window.open(theURL,winName,features);
}
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 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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//
function checa(nform) {
	//validacao de radio buttons sem saber quantos sao
	marcado = -1;
	resposta = "";
	for (i=0; i<nform.length; i++) {
		if (nform[i].checked) {
			//caso algum item do radioButton esteja selecionado, marcado deixa de valer -1
			marcado = i;
			resposta = nform[i].value;
		}
	}
	return resposta;
}

//Exibe e esconde
function showhide(what){
//	alert('teste');
	if (what.style.display=='none'){
		what.style.display='block';
		//what2.src=Open.src
	}
	else{
		what.style.display='none';
		//what2.src=Closed.src
	}
}
//Testa se string passada é email ou não
//Retorna falso se não for email, caso contrario retorna verdadeiro
function isEmail(value){
	value = new String(value)
	 p=value.indexOf('@');
	if (p<1 || p==(value.length-1)){
		return false;
	} else {
		if (value.indexOf('.',p+2)<1 || value.length < (p+4)){
			return false
		} else {
			return true;
		}
	}
}
//Impede que caracterec não numéricos entrem em campos de formulário html. Permite formato moeda (0,00)
//Usar onChange
function soMoney(tammax){
	event.srcElement.maxLength=tammax;
	if (event.srcElement.value.length+1>tammax) { 
		event.KeyCode=0;
	}
	if ( (event.keyCode >= 48) && (event.keyCode <= 57 ) || (event.keyCode == 44)) {
		if (event.keyCode == 44){
			if (event.srcElement.value.indexOf(",") > -1) {			
				event.keyCode = 0;
				return false;
			}
		}
		return true
	} else {
		if (event.keyCode != 8){
			 event.keyCode = 0;
			 return false;
		 }
	}
}



//Testa se uma data é valida
//Retorna true caso a data seja válida, e false caso não.
function isDate(Data){
    strData = new String(Data);   
    //Verifica se a data veio formatada com / ou -
    if (strData.indexOf('/') >= 0)    {
        arrData = strData.split('/');
    }else if(strData.indexOf('-') >= 0){
        arrData = strData.split('-');
    }else{
        arrData = new Array()
    }   
    //Se contém os três valores de dia, mês e ano ou ano, mês e dia
    if(arrData.length == 3){
        //Testa de os valores de dia mês e ano não foram passados vazios
        if(arrData[0] != '' &&  arrData[1] != ''  && arrData[2] != '' ){
            //Cria objeto de data considerando que a data estava no padrão americano
            objData = new Date(arrData[0],arrData[1]-1,arrData[2]);
            //Se a data for inválida, tenta criar objeto de data com padrão brasileiro
            if(isNaN(objData)){
                objData = new Date(arrData[2],arrData[1]-1,arrData[0]);
            }   
            //Testa o objeto de data. Se a data inicial não era válida o objeto será NaN
            if(isNaN(objData)){
                bolRetorno = false;
            } else {//Se for válida
				bolData = true;
				 var dia = arrData[0];
				 var mes = arrData[1];
				 var ano = arrData[2];
				 if (ano % 4 == 0)  var ano_bi = true
				 else var ano_bi = false;

				 if (mes >= 1 && mes <= 12){
				   if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12 ){
					 if (dia < 1 || dia > 31){
					   bolData = false;
					 }
				   }
				   else if (mes == 4 || mes == 6 || mes == 9 || mes == 11 ){
					 if (dia < 1 || dia > 30){
					   bolData = false;
					 }           
				   }
				   else if (mes == 2 && ano_bi ){
					 if (dia < 1 || dia > 29){
					   bolData = false;
					 }          
				   } 
				   else { 
					 if (dia < 1 || dia > 28){
					   bolData = false;
					 }           
				   }
				 } else{
					   bolData = false;
				 }


				if(bolData){
					bolRetorno = true;
				} else {
					bolRetorno = false;
				}
//                alert(objData);
            }
        } else {//Se dia, mês ou ano foram vazios
            bolRetorno = false;
        }
    } else {
            bolRetorno = false;
    }
//        alert(objData);
    return bolRetorno;   
}


document.write('<link rel="stylesheet" href="../../css/default.css" type="text/css">')


function popup(arquivo,w,h) {
	window.open(arquivo, "pop", "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h+"");
}

function demonstracoes(arquivo) {   
	window.open(arquivo,'pdf','width=700,height=500,top=10,left=10,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}


