function popUpWindow(URLStr, left, top, width, height)
{
/*var popUpWin=0;
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }*/
  x= Math.random();
  popUpWin = open(URLStr,'', 'toolbar=no,location=no,directories=no,Ativo=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}

//Desabilita as teclas numerica
function isNum(key){ 
	if((key <48)||(key>57)) 
//		if((key!=46)&&(key!=45))//permitir o "."  e o  "-"
			return false 
}
function isFloat(key){ 
//window.alert(key);
	if((key <48)||(key>57)) 
		if((key!=46)&&(key!=45) && (key!=44))//permitir o "." , "-",  ","
			return false 
}
//Desabilita as teclas alfa
function isTexto(key){ 
	if((key >42) & (key<58)) 
			return false 
}

function formataCNPJ (s){
	aux = s.value;
	if((aux.length==2) || (aux.length==6))
		s.value += '.';
	else
		if(aux.length==10)   
			s.value += '/';
		else
			if(aux.length==15)   
				s.value += '-';

}
// valida CNPJ
function isCNPJ( s ) {
  var r = s.value;
  r = r.substring(0,2) +'' +  r.substring(3,6) +''+ r.substring(7,10) + '' + r.substring(11,15) + '' + r.substring(16,19);
 // window.alert(r);
  var iError = 0 ;
  var nCGC_ = r ;
	if (r.length == 0){
		return true
	} 
  if ( (r * 1) == 0 ) iError++ ;
 
  if ( nCGC_.length == 15 && nCGC_.charAt(0) == "0") nCGC_ = nCGC_.substring(1 , nCGC_.length) ;
  if ( nCGC_.length != 14 ) iError++ ;
 
  var nCGC = new Array() ;
 
  for ( i = 0 ; i < 15 ; i++ ) {
    nCGC[i] = nCGC_.charAt(i) ;
  }
 
  iDV1=(nCGC[0]*5+nCGC[1]*4+nCGC[2]*3+nCGC[3]*2+nCGC[4]*9+nCGC[5]*8+nCGC[6]*7+nCGC[7]*6+nCGC[8]*5+nCGC[9]*4+nCGC[10]*3+nCGC[11]*2)%11;
  if ( iDV1 == 1 || iDV1 == 0 ) { iDV1 = 0 } else { iDV1 = 11 - iDV1 }
  if ( iDV1 != nCGC[12] ) iError++ ;
 
  iDV2=(nCGC[0]*6+nCGC[1]*5+nCGC[2]*4+nCGC[3]*3+nCGC[4]*2+nCGC[5]*9+nCGC[6]*8+nCGC[7]*7+nCGC[8]*6+nCGC[9]*5+nCGC[10]*4+nCGC[11]*3+nCGC[12]*2)%11 ;
  if ( iDV2 == 1 || iDV2 == 0 ) { iDV2 = 0 } else { iDV2 = 11 - iDV2 }
  if ( iDV2 != nCGC[13] ) iError++ ;
 
  if ( iError > 0 ) {
   //  alert ( "O CGC/CNPJ está incorreto. Por favor, verifique.\n" ) ;
    return false ;
  } else {
   return true ;
  }
}





function isEmail(email){
	var vmail = email.value;
//	window.alert(vmail.length  + '')
	if (vmail.length == 0){
		return true
	}
		 //verifica a existência de espaços em brancos
		if(vmail.indexOf(" ") > -1){
			return false;
		}
		//verifica a existência de apóstrofes campo E-MAIL
		if(vmail.indexOf("'") > -1){
			return false;
		}		
		//Consistência de e-mail:
		// 2 @
		if(vmail.lastIndexOf("@") != vmail.indexOf("@")){
			return false;
		}
		//sem @
		if(vmail.indexOf("@") == -1){
			return false;
		}
		// @ no início
		if(vmail.charCodeAt(0) == 64){
			return false;
		}	
		// @ no final
		if(vmail.charCodeAt((vmail.length)-1) == 64){
			return false;
		}
		//VERIFICA EXISTÊNCIA DE PONTO APÓS DO @
		if(vmail.indexOf("@.") > 0){   
			return false; 
		}   
		//não aceita caracteres diferentes				de  alfanuméricos e_ e   -e.				
		for(I=0;I<=(vmail.length);I++){
			if((vmail.charCodeAt(I)<48||vmail.charCodeAt(I)>57)&&(vmail.charCodeAt(I)<65||vmail.charCodeAt(I)>90)&&(vmail.charCodeAt(I)<97||vmail.charCodeAt(I)>122)&&(vmail.charCodeAt(I)!=95&&vmail.charCodeAt(I)!=45&&vmail.charCodeAt(I)!=46&&vmail.charCodeAt(I)!=64)){
							returnfalse;
		}
	return true;
	}
  }

function formataCPF (s){
	aux = s.value;
	if((aux.length==3) || (aux.length==7) )
		s.value += '.';
	else
		if(aux.length==11)   
			s.value += '-';
}

function isCPF (x) {
  var r = x.value;
  r = r.substring(0,3) +'' +  r.substring(4,7) +''+ r.substring(8,11) + '' + r.substring(12,14);
//window.alert(r);
 CPF =r;
	 if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
	  CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
	  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
	  CPF == "88888888888" || CPF == "99999999999")
		  return false;
	 soma = 0;
	 for (i=0; i < 9; i ++)
	  soma += parseInt(CPF.charAt(i)) * (10 - i);
	
	 resto = 11 - (soma % 11);
	 if (resto == 10 || resto == 11)
	  	resto = 0;
	 if (resto != parseInt(CPF.charAt(9)))
		  return false;
	 soma = 0;
	 for (i = 0; i < 10; i ++)
	  	soma += parseInt(CPF.charAt(i)) * (11 - i);
	 
	 resto = 11 - (soma % 11);
	 if (resto == 10 || resto == 11)
	 	 resto = 0;
	 if (resto != parseInt(CPF.charAt(10)))
		  return false;
//			alert('Correto');
	 return true;
 }

function Excluir(){
	return confirm('Você irá excluir o registro!');
}
function ExcluirRegistros(){
	return confirm('Você irá excluir todos os registros selecionados!');
}
function trocaFigura(idAux, campo){
   document.getElementById(idAux).innerHTML='<img src=\''+campo.value+'\' width=50 height=50>';
}
