// JavaScript Document


/*---------------------------------------------------
Criado:				RODRIGO KULB (rodrigo@levitron.com.br)
Data:				22/04/2008 - 15:12
Intenção:			SUBSTITUI O DOCUMET.GETELEMENTBYID PELA VARIAVEL $D
Chamada em:		(Todos JS)
{
-----------------------------------------------------*/ 
var  $D = function(id) 
{
	//alert(id);
	return document.getElementById(id);
}
function colocaValue(id,valor)
{
	alert(id);
	alert(valor);
	$D(id).value = valor;
}
///////////////////////////////////////////////////////////////////
// função relogio index///////////////////////////////////////////
/////////////////////////////////////////////////////////////////

function Relogio() { 
  
data = new Date() 
    
var horas= data.getHours() 
var minutos= data.getMinutes() 
var segundos= data.getSeconds() 
    

if (horas < 10) 
{ 
horas = "0" +  horas 
} 
if (minutos < 10) 
{ 
minutos = "0" + minutos 
} 
if (segundos < 10) 
{ 
segundos = "0" + segundos 
} 

    
  var rellx=  document.theClock.theTime.value = "" 
                                   + horas + ":" 
                                   + minutos + ":" 
                                   + segundos; 
                                    
                                
    

 var Actualizar =setTimeout("Relogio()",  "1000"); 

} 


///////////////////////////////////////////////////////////////////
// função abre fecha//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////


function abreFecha(obj) {
	
		var el = document.getElementById(obj);
		if ( el.style.display != "none" ) {
			el.style.display = 'none';
		}
		else {
			el.style.display = '';
		}
	}

///////////////////////////////////////////////////////////////////
// opacidade no botao/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////


function opacBtn(id)
{
	$D(id).style.opacity="0.4";
	$D(id).style.filter="alpha(opacity=40)";

}

function opacBtnNo(id)
{
	$D(id).style.opacity="";
	$D(id).style.filter="";
}
// JavaScript Document
$D = function(id) 
{
	return document.getElementById(id);
}

$DN = function(id) 
{
	return document.getElementsByName(id);
}
//ALTERA A COR DO CAMPO
function alteraCampoCor(id,status)
{
	//alert('ok');
	if(status=='on')
	{
		$D(id).style.backgroundColor="#EDECFF";
	}
	else
	{
		$D(id).style.backgroundColor="";
	}
}
function tiraDiv(div,div2)
{
	if(div2 != '')
	{
		$D(div2).style.display = 'none';	
	}
	$D(div).style.display = 'none';	
}

//APARECE A DIV NA PAGINA INICIAL
function apareceDiv(idOn,idOn2,idOff,idOff2)
{
	$D(idOn).style.display = '';
	$D(idOn2).style.display = '';
	$D(idOff).style.display = 'none';
	$D(idOff2).style.display = 'none';
	$DN('publico')[0].checked  = false;
	$DN('publico')[1].checked  = false;
}
//COLOCA O VALOR NO HIDDEN
function valorHidden(id)
{
	$D(id).value = '1';
}

//APARECE CAMPO CPF OU PASSAPORT
function mostraCampo(id)
{
	if($D(id).value == '')
	{
		$D('trPassaport').style.display = 'none';
		$D('trCpf').style.display = 'none';
	}
	else if($D(id).value == 'Brasil')
	{
		$D('trCpf').style.display = '';
		$D('passaporte').value = '';
		$D('trPassaport').style.display = 'none';
	}
	else if($D(id).value != 'Brasil')
	{
		$D('cpf').value = '';
		$D('trCpf').style.display = 'none';
		$D('trPassaport').style.display = '';
	}
}
//PULA CPF
function cpfPula(id,nextId)
{
	var cpf = $D(id).value;
	if(cpf.length == 3)
	{
		$D(id).value = cpf+".";
	}
	if(cpf.length == 7 )
	{
		$D(id).value = cpf+".";	
	}
	if(cpf.length == 11 )	
	{
		$D(id).value = cpf+"-";
	}
	if(cpf.length == 14 )	
	{
		$D(nextId).focus();
	}
}
//PULA CNPJ
function cnpjPula(id,nextId) 
{
	var cnpj = $D(id).value;
	if(cnpj.length == 2)
	{
		$D(id).value = cnpj+".";
	}
	if(cnpj.length == 6 )
	{
		$D(id).value = cnpj+".";
	}
	if(cnpj.length == 10 )
	{
		$D(id).value = cnpj+"/";
	}
	if(cnpj.length == 15 )
	{
		$D(id).value = cnpj+"-";
	}
	if(cnpj.length == 18 )	
	{
		$D(nextId).focus();
	}
}
function cnpjPula2(id,nextId) 
{
	var cnpj = $D(id).value;
	if(cnpj.length == 4)
	{
		$D(id).value = cnpj+"-";
	}
	if(cnpj.length == 7 )	
	{
		$D(nextId).focus();
	}
}
//PULA DATA
function mudaData(id,nextId)
{	
	var data = $D(id).value;	
	if(data.length == 2)	
	{		
		$D(id).value = data+'/';	
	}	
	else if(data.length == 5)	
	{			
		$D(id).value = data+'/';
	}
	else if(data.length == 10)	
	{	
		$D(nextId).focus();	
	}
}
//MUDA DDD
function mudaDDD(id,nextId)
{	
	var ddd = $D(id).value;	
	if(ddd.length == 2)	
	{		
		$D(nextId).focus();	
	}
}
//MUDA TEL
function mudaTel(id,nextId)
{	
	var tel = $D(id).value;	
	if(tel.length == 4)	
	{		
		$D(nextId).focus();;	
	}	
}



//MUDA CEP
function mudaCep(id,nextId)
{	
	var cep = $D(id).value;	
	if(cep.length == 5)	
	{		
		$D(id).value = cep+'-';	
	}	
	else if(cep.length == 9)	
	{			
		$D(nextId).focus();	
	}
}
//APARECE CAMPO HIDDEN
function apareceCampo(id,idHid,valor,trHidden)
{
	if($D(id).value == valor)
	{
		$D(idHid).style.display = '';
		$D(trHidden).style.display = '';
	}
	else
	{
		$D(idHid).style.display = 'none';		
		$D(trHidden).style.display = 'none';
	}
}

//APAGA VALOR DO CAMPO
function apagaCampo(id)
{
	$D(id).value = '';
}
//COLOCA VALOR CAMPO
function escreveValor(id,idV,valor)
{
	if($DN(id)[0].checked==true)
	{
		$D(idV).value = valor;
		$D(idV).readOnly = true;
	}else
	{
		$D(idV).value = '';
		$D(idV).readOnly = false;
	}
}

//MOUSE OVER
//function mouseOver(id,idSpan,idDivImg,hidMenu)
function mouseOver(id,bgColor)
{
	$D(id).style.backgroundColor = bgColor;
	/*if($D(idSpan))
	{
		$D(idSpan).className='btnRollOver';
	}
	if($D(idDivImg))
	{
		$D(idDivImg).style.display="block";
	}
	$D(hidMenu).value = id;*/
}
//MOUSE OVER DE IMAGEM
function mouseOverImf(id,img)
{
	$D(id).style.backgroundImage = "url(imagens/"+img+".gif)";
	$D(id).className='fonteBca';
}
//MOUSE OUT
//function mouseOut(idSpan,idDivImg,hidMenu)
function mouseOut(id,bgColor)
{
	$D(id).style.backgroundColor = bgColor;
	/*var id = $D(hidMenu).value;
	$D(id).style.backgroundColor = '#FFFFFF';
	if($D(idSpan))
	{
		$D(idSpan).className='btnRollOver';
	}
	if($D(idDivImg))
	{
		$D(idDivImg).style.display="none";
	}*/
}
//MOUSE OUT IMG
function mouseOutImg(id,img)
{
	$D(id).style.backgroundImage = "url(imagens/"+img+".gif)";
	$D(id).className='fonteCinza';
}

function valorHidden(idHid)
{
	$D('idHiddenMenu').value = idHid;
}


function mudaDiv(mudaDiv,id)
{
	var a ='';
for(i=1 ; i<= 400; i++)
{
	a='btnPDV'+i;

	if($D(a))
	{
		$D(a).style.backgroundImage="url('Imagens/barraCinzaMenu.jpg')";
	}
}
	var idAberto = $D('idHiddenMenu').value;
	
	if($D(mudaDiv).style.display == '') 
	{
		$D(mudaDiv).style.display = 'none';
		$D('idHiddenMenu').value = '';
		$D(id).style.backgroundImage="url('Imagens/barraCinzaMenu.jpg')";
	}
	else
	{		
		$D(mudaDiv).style.display = '';
		$D(id).style.backgroundImage="url('Imagens/barraVermelhaMenu.jpg')";
		if($D('idHiddenMenu').value)
		{
			$D(idAberto).style.display = 'none';
		}
		$D('idHiddenMenu').value = mudaDiv;
	}
}





function buscarConteudo(Prod,idDivProd)
{
	if($D('idHiddenProduto').value)
	{
		if($D ($D('idHiddenProduto').value) )
		{
			$D($D('idHiddenProduto').value).style.backgroundImage="";
		}
	}
		$D(idDivProd).style.backgroundImage="url('Imagens/btnMenuMarca.gif')";
		$D('idHiddenProduto').value = idDivProd
		
		url = 'conteudoDivsDb.php?Pr='+Prod;
		req = null;
		if (window.XMLHttpRequest) 
		{
			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("POST",url,true);
			req.setRequestHeader( "Content-Type","text/html; charset=iso-8859-1" );  			
			req.send(null);
		} 
		else if (window.ActiveXObject) 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) 
			{
				req.onreadystatechange = processReqChange;
				req.open("POST",url,true);
				req.setRequestHeader( "Content-Type","text/html; charset=iso-8859-1" );  
				req.send();
			}
		}
		
}




function processReqChange()
{
	//alert(req.responseText);
	// apenas quando o estado for "completado"
	if (req.readyState == 4) 
	{
		// apenas se o servidor retornar "OK"
		if (req.status ==200) 
		{
			//alert(req.responseText);
				var string = req.responseText;
				
				document.getElementById('conteudoDivsDb').innerHTML = string;
				initLytebox();
		} 
		else 
		{	
			alert("Houve um problema ao obter os dados:n" + req.statusText);
		}
	}
}





//SOMENTE NUMEROS
function info()
{
	
}
