function ajustarMenuCarrinho() { 
 parent.document.getElementById("iMeuCarrinho").height = document.getElementById("conteudo").scrollHeight; 
}

function ajustarPagina(bw) { 
 var altura = document.getElementById("conteudo").scrollHeight;
 
 if (parent.document.getElementById("publicidadeDir")) {
	   
		 if (bw=='ie')		 { 
		      if ( (parent.document.getElementById("publicidadeDir").scrollHeight - (parent.document.getElementById("publicidadeDir").scrollHeight * 0.35)) > altura)
		            altura =parent.document.getElementById("publicidadeDir").scrollHeight  - (parent.document.getElementById("publicidadeDir").scrollHeight * 0.35); 
		 } else {
		               if ( (parent.document.getElementById("publicidadeDir").scrollHeight > altura))
		                       altura =parent.document.getElementById("publicidadeDir").scrollHeight; 
							 }
 }
 
 parent.document.getElementById("iConteudo").height = altura; 
}

function pesqMenu(id){
	var f = document.formPesqMenu;
	f.action = 'http://www.centralirrigacao.com.br/';
	//f.action = 'http://baru04/central_irrigacao';
	f.target = '';	
	f.pesqCatMenu.value = id;
	f.submit();
}

function abrir(id, p) {
 var esqPos = (screen.width) ? (screen.width/2)-(p.getElementById("conteudo").scrollWidth * 0.3) : 0;
 var topoPos = (screen.height) ? (screen.height/2)-(p.getElementById("conteudo").scrollHeight * 0.2) : 0;
 window.open('pop_up.php?id='+id,'detalhe_produto'+id,'resizable=no,scrollbars=no,width=620, height=380, left='+ esqPos +', top='+topoPos);
}

function adicionaQtde(id, qtde) {
 var campo = document.getElementById(id);
 var valor = (campo.value == '') ? qtde : parseInt(campo.value) + qtde; 
 campo.value = (valor <= 0) ? 1 : (  (valor > 999) ? 999 :  valor); 
}

function verifica_se_vazio(str){
 var i=0;
 while(str.charAt(i)==' ')
     i++; 	  
	 	 
 if (str.length == i)
    return true;
 else return false;	
}

function limparCamposCesta() {
	var f = parent.document.formCesta;
	f.idNovoProduto.value = '';
	f.idQtdeProduto.value = '';
	f.pagina.value = '';
	f.delItem.value = '';	
	f.limparQCesta.value = '';
	f.acao.value = '';
	f.idNoticia.value = '';
	f.finalizarCesta.value = '';
}

function adicionaCesta(idProduto, id) {
	
	limparCamposCesta();
	
	if (verifica_se_vazio(document.getElementById(id).value) ) {
		 alert("Por favor, informe a qtde!");
	   return;
  } 
	
	if (parseInt(document.getElementById(id).value) <= 0) {
	alert("Por favor, informe a qtde!");
	return;
 }
 
  var f = parent.document.formCesta; 
 f.idNovoProduto.value = idProduto;
 f.idQtdeProduto.value = document.getElementById(id).value;
 f.action = 'iCarrinho.php';
 f.target = 'iMeuCarrinho';
 f.submit();
}

function irPagina(pagina, limpar) {
		var f = parent.document.formCesta;

	if (limpar)
	     limparCamposCesta();
	
	f.pagina.value = pagina;	
	f.action = 'pagina.php';
	f.target = 'iConteudo';
	f.submit();
}

function irPagina2(pagina, limpar) {
		var f = parent.document.formCesta;

	if (limpar)
	     limparCamposCesta();
	
	f.pagina.value = pagina;	
	f.action = 'http://www.centralirrigacao.com.br/';
//	f.action = 'http://baru04/central_irrigacao/';
	f.target = '';
	f.submit();
}

function irAut(pagina, limpar) {
	var f = parent.document.formCesta;

	f.pagina.value = pagina;	
	f.action = 'https://centralirrigaca.sslblindado.com/';
	f.target = '';
	f.submit();
}


function irPaginaIndex(pagina, limpar) {
	var f = document.formCesta;
	f.pagina.value = pagina;	
	f.action = 'http://www.centralirrigacao.com.br/';
//	f.action = 'http://baru04/central_irrigacao/';	
  f.target = '';
	f.submit();
}

function deletarItem(id){
 var f = parent.document.formCesta;
 limparCamposCesta();
 
 if (id == 'todos') {
	if (!confirm("Tem certeza que deseja limpar o Carrinho?"))
	    return false;
 }
 else if (!confirm("Tem certeza que deseja Deletar este Item?"))
	    return false;  
  
 f.delItem.value = id;
 irPagina('cesta', false);
}

function limparQuadroCesta() {
 var f = parent.document.formCesta; 
 f.action = 'iCarrinho.php';
 f.target = 'iMeuCarrinho';
 f.limparQCesta.value = '1';
 f.submit();
}

function atualizarItens(){
 var f = document.formListaCesta; 
 f.atualizarCesta.value = '1';
 f.submit();
}

function finalizarCesta(){
 var f = document.formListaCesta; 
 f.finalizarCesta.value = '1';
 f.submit();
}

function irCadCliente(){
 var f = document.formLogin; 
 f.pagina.value = 'cadastroCliente';
 f.submit();
}

function enviarDadosCadCliente(){
 var f = document.formCadCliente;
 f.processar.value = '1';
 f.submit();
}

function cadNovoCliente() {
	var f = document.formLogin;
 f.pagina.value = 'cadastroCliente';
 f.acao.value = 'INC';
 f.submit();
}

function loginCliente() {
	var f = document.formLogin; 
 f.pagina.value = 'login';
 f.acao.value = 'LOG';
 f.submit();
}

function RecuperarSenha(){
  var f = document.formLogin;
  
  if (f.login_email.value==''){
	   alert('O campo email não foi preenchido!');
		f.login_email.focus();		
	  } else {  
					 f.pagina.value = 'esqueceu_senha';
					 f.submit();
	             }
}

function logout(){
	if (confirm('Tem certeza que deseja fazer Logout?'))
     	irPagina('logout', true);
}

function alterarDados(){
 limparCamposCesta();	
 var f = parent.document.formCesta; 
 f.pagina.value = 'cadastroCliente';
 f.acao.value = 'ALT';
 
 f.action = 'pagina.php';
 f.target = 'iConteudo';
 f.submit();
}

function tipoPessoa() {
 document.getElementById('txtTipoPessoa').innerHTML= (document.formCadCliente.tipo_pessoa[1].checked) ? 'CNPJ *' : 'CPF *'; 
}

function irNoticia(id){
	var f = parent.document.formCesta;
	limparCamposCesta();
	f.idNoticia.value = id;	
	irPagina('conteudoNoticia', false);
}

function irPaginaConteudo(id){
	var f =document.formCesta;
	limparCamposCesta();
	f.idNoticia.value = id;	
	irPaginaIndex('conteudoPagina',false);
}

function limparFormContato() {
	var f = document.formContato;
	f.nome.value = '';
	f.email.value = '';
	f.assunto.value = '';
	f.texto.value = '';
}

function limparFormInsc() {
	var f = document.formInsc;
	f.nome.value = '';
	f.email.value = '';
	f.profissao.value = '';
	f.ddd_res.value = '';
	f.prefixo_res.value = '';
	f.fone_res.value = '';
	f.ddd_com.value = '';
	f.prefixo_com.value = '';
	f.fone_com.value = '';
	f.end_corresp.value = '';	
}

 function pDir() {
   document.getElementById('publicidadeDir').style.display = (screen.width > '800') ? 'block' : 'none';	
	 document.getElementById('conteudoDireita').style.display = (screen.width > '800') ? 'block' : 'none';	
 }
 
function  mudarCPF() {
	if (document.getElementById('cep1').value.length == 5)
	    document.getElementById('cep2').focus();
}

function buscarCEPCarrinho(){
	document.getElementById('lnOKCep').style.display = 'none';
	document.getElementById('lnOKCepCarregando').style.display = '';
	xajax_buscaCEPCarrinho(document.getElementById('cep1').value + document.getElementById('cep2').value);
}

function cadNews(){
	var f = document.formNews;
	
	if (document.getElementById('newsNome').value == '') {
		alert("Por favor, preencha o campo nome!");
		document.getElementById('newsNome').focus();
		return false;
	}
	
	if (document.getElementById('newsEmail').value == '') {
		alert("Por favor, preencha o campo email!");
		document.getElementById('newsEmail').focus();
		return false;
	}
	
	f.newsFormNome.value = document.getElementById('newsNome').value;
	f.newsFormEmail.value = document.getElementById('newsEmail').value;
	
	f.submit();
}