nav = new browser();

var _sf_startpt=(new Date()).getTime();

function saltaCampo(atual,camponext,e,t){
	if(nav.ie){
		if(document.form1.elements[atual].value.length==t){
			document.form1.elements[camponext].focus();
		}
	}else{
		
	}
}
//Esconde o carregador
function escondeCarregador(p){
	var objLoader				= document.getElementById(p);
	objLoader.style.display		="none";
	objLoader.style.visibility	="hidden";
}

function fecharJanelaJS(){
	window.close();
}
function abrePonline(p)
{
	javascript:MM_openBrWindow(p,'lances_online','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}


function abreDetalhesHistorico(p,tp,secao){
	javascript:MM_openBrWindow('m_detalhe_lance_online_historico_'+secao+'.php?IDLeilaoLote='+p+'&TP='+tp+'','lances_online','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}

function abreDetalhes(p,tp,secao)
{
	javascript:MM_openBrWindow('m_detalhe_lance_online_previo_'+secao+'.php?IDLeilaoLote='+p+'&TP='+tp+'','lances_online','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}

function abreDetalhes2(p,tp,secao){
	javascript:MM_openBrWindow(secao+'?IDLeilaoLote='+p+'&TP='+tp+'','lances_online','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}

function abreHabilitacao(p,tp)
{
	javascript:MM_openBrWindow('habilitacao_leilao.php?IDLeilao='+p+'&TP='+tp+'','habilitacao','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}

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

function irpara(theURL)
{
	window.open(theURL,"_parent"); 
}

function abreTesteConexao(){
	javascript:MM_openBrWindow('teste_conexao_principal.php','teste_conexao','menubar=no,status=yes,scrollbars=no,width=790,height=530,top=0,left=0');
}

function get_random(){
    var ranNum= Math.floor(Math.random()*5);
    return ranNum;
}

function qry_no_cx(){
    var ranqry= "&RD1="+String(get_random())+"&RD2="+String(get_random())+"&RD3="+String(get_random());
    return ranqry;
}

function trimJS(str)
{
str=str.replace(/\s+/g," "); // elimina sequências de espaços
// (\t\r\n ) por um espaço em branco
str=str.replace(/^ /,""); //inicio de linha
str=str.replace(/ $/,""); //fim de linha
return str;
}

function validaData(pStr)
{
	var reDate1 = /^\d{1,2}\/\d{1,2}\/\d{1,4}$/;
	var reDate2 = /^[0-3]?\d\/[01]?\d\/(\d{2}|\d{4})$/;
	var reDate3 = /^(0?[1-9]|[12]\d|3[01])\/(0?[1-9]|1[0-2])\/(19|20)?\d{2}$/;
	var reDate4 = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
	var reDate5 = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
	var reDate = reDate4;

	pFmt="5";
	eval("reDate = reDate" + pFmt);
	if (reDate.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}

function validaEmail(pStr)
{
	var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var reEmail = reEmail3;
	
	pFmt='1';
	
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}

function eLetrasNumeros(pStr)
{
	var reDigits = /^[A-Za-z\d]+$/;
	if (reDigits.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}

function eNumeros(pStr)
{
	var reDigits = /^\d+$/;
	if (reDigits.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		return false;
	}
}

function validaNumero(p){
	var tecla;
	if(nav.ie){
		tecla = event.keyCode;
	}
	else{
		tecla = event.which;
	}
	
	if((((tecla) > 47) && ((tecla) < 58))){
		return(true);
	}
	else{
		return(false);
	}
}

function cnpj(pcgc)
{
// verifica o tamanho

	pcgc=pcgc.toString().replace(".","");
	pcgc=pcgc.toString().replace(".","");
  	pcgc=pcgc.toString().replace("-","");
	pcgc=pcgc.toString().replace("-","");
  	pcgc=pcgc.toString().replace("/","");
   
if (pcgc.length != 14) {
sim=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}
// alert (d1)
// alert (d2)
if ((d1==pcgc.charAt(12)) && (d2==pcgc.charAt(13)))
{ return true; }
else 
return false;
}
}
return false;
}


function cpf(pcpf)
{
   	pcpf=pcpf.toString().replace(".","");
	pcpf=pcpf.toString().replace(".","");
  	pcpf=pcpf.toString().replace("-","");
	pcpf=pcpf.toString().replace("-","");
  	pcpf=pcpf.toString().replace("/","");

if (pcpf.length != 11) 
	{
	sim=false;
	}
	else 
	{
		if(pcpf=='00000000000' || (pcpf=='11111111111') || (pcpf=='22222222222') || (pcpf=='33333333333') || (pcpf=='44444444444') || (pcpf=='55555555555') || (pcpf=='66666666666') || (pcpf=='77777777777') || (pcpf=='88888888888') || (pcpf=='99999999999'))
		{
			sim=false;
		}
		else
		{
			sim=true;
		}
	}

if (sim ) // valida o primeiro digito
{
for (i=0;((i<=(pcpf.length-1))&& sim); i++)
{
val = pcpf.charAt(i)
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)
{
soma = 0
for (i=0;i<=8;i++)
{
val = eval(pcpf.charAt(i))
soma = soma + (val*(i+1))
}

resto = soma % 11
if (resto>9) dig = resto -10
else dig = resto
if (dig != eval(pcpf.charAt(9))) { sim=false }
else // valida o segundo digito
{

soma = 0
for (i=0;i<=7;i++)
{
val = eval(pcpf.charAt(i+1))
soma = soma + (val*(i+1))
}

soma = soma + (dig * 9)
resto = soma % 11
if (resto>9) dig = resto -10
else dig = resto
if (dig != eval(pcpf.charAt(10))) { sim = false }
else sim = true
}
}
}

if (sim) { 
return true; }
else
return false;
}

function validaTecla(p){
	var tecla;
	if(nav.ie){
		tecla = event.keyCode;
	}
	else{
		tecla = event.which;
	}
	
	if(((tecla>96) && (tecla<123)) || ((tecla>64) && (tecla<91)) || (tecla==13) || (((tecla) > 47) && ((tecla) < 58))){
		return(true);
	}
	else{
		return(false);
	}
}

function stopPropagation(){
	var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function browser () {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua = navigator.userAgent.toLowerCase();	
	this.v = parseInt(v);
	this.safari = ua.indexOf("safari")>-1;	// always check for safari & opera 
	this.opera = ua.indexOf("opera")>-1;	// before ns or ie
	this.ns = !this.opera && !this.safari && (b=="Netscape");
	this.ie = !this.opera && (b=="Microsoft Internet Explorer");
	this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
	if (this.ns) {
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);	
		this.b = "Netscape";
	}else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
		this.b = "MSIE";
	}else if (this.opera) {
		this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
		this.opera6=(this.v>=6);
		this.opera7=(this.v>=7);
		this.b = "Opera";
	}else if (this.safari) {
		this.ns6 = (this.v>=5);	// ns6 compatible correct?
		this.b = "Safari";
	}
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
	this.def = (this.ie||this.dom);
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
	this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
};

function escreve_flash(nome,largura,altura,versao){

document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'+ 
' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+versao+',0,0,0"'+
' width="'+largura+'" height="'+altura+'" id="'+nome+'" align="middle">');

document.write('<param name="allowScriptAccess" value="sameDomain" />');

document.write('<param name="movie" value="'+nome+'.swf" />');

document.write('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');

document.write('<embed src="'+nome+'.swf" quality="high" bgcolor="#ffffff"'+
' width="'+largura+'" height="'+altura+'" name="'+nome+'" align="middle"'+
' allowScriptAccess="sameDomain" type="application/x-shockwave-flash"'+
' pluginspage="http://www.macromedia.com/go/getflashplayer" />');

document.write('</object>');

}

function escreve_flash_online(nome,largura,altura,versao,par){

document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'+ 
' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+versao+',0,0,0"'+
' width="'+largura+'" height="'+altura+'" id="'+nome+'" align="middle">');

document.write('<param name="allowScriptAccess" value="sameDomain" />');

document.write('<param name="movie" value="'+nome+'.swf" />');

document.write('<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />');
document.write('<param name="flashvars" value="par='+par+'">');
document.write('<embed src="'+nome+'.swf" quality="high" bgcolor="#ffffff"'+
' width="'+largura+'" height="'+altura+'" name="'+nome+'" align="middle"'+
' allowScriptAccess="sameDomain" type="application/x-shockwave-flash"'+
' pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="par='+par+'" />');

document.write('</object>');

}
