meuAjax = function (){   
    try{   
        xmlhttp = new XMLHttpRequest();   
    }catch(ee){   
        try{   
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");   
        }catch(e){   
            try{   
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");   
            }catch(E){   
                xmlhttp = false;   
            }   
        }   
    }   
}  
ajaxGet = function( nomeUrl, divRetorno ){   

    divInsereResposta = parent.document.getElementById( divRetorno );   
	divInsereResposta.innerHTML = '<img src=\'../imagens/ajax-loader.gif\'>';
    meuAjax();   
    xmlhttp.abort();   
    xmlhttp.open ("GET", nomeUrl ,true);   
       
    xmlhttp.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");   
    xmlhttp.onreadystatechange = function() {   
            if( xmlhttp.readyState == 4 ){   
                   
                var valorRetorno            = xmlhttp.responseText;   
                divInsereResposta.innerHTML = valorRetorno;   
                       
            }   
    }   
    xmlhttp.send(null);   
 
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function mostra(id){
  if(document.all)
    document.getElementById(id).style.display='block';
  else
    document.getElementById(id).style.display='table-cell'
}
function esconde(id){
  document.getElementById(id).style.display='none';
}
function scbg(objRef, state) {
	objRef.style.backgroundColor = (1 == state) ? '#DDDDDD' : '';
	return;
}
function scbg_geral(objRef, state) {
	objRef.style.backgroundColor = (1 == state) ? '#ff9900' : '#D71920';
	return;
}
function scbg_consult(objRef, state) {
	objRef.style.backgroundColor = (1 == state) ? '#ff9900' : '#FF6600';
	return;
}
function scbg_prod(objRef, state) {
	objRef.style.backgroundColor = (1 == state) ? '#ff9900' : '#ff0000';
	return;
}
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_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_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 MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function valida(bt,nbt,msg1,msg2,cmp1,cmp2){
	var vlr1 = document.getElementById(cmp1);
	var vlr2 = document.getElementById(cmp2);
	
	if(vlr1.value==''){
		alert(msg1); return false;
	}
	
	if(vlr2.value==''){
		alert(msg2); return false;
	}
	
	if(vlr1.value!=''&&vlr2.value!=''){
		document.getElementById(bt).disabled = true;
		document.getElementById(bt).value = nbt;
		return true;
	}
}
// Tiago
function redirect(url)
{
	window.location = url;
}
function openUrl(url,target)
{
	
	window.open(url,target);
}
function openIten(value)
{
	if(value)
	{
		if(value == "conselheiro_nome")
		{
			document.getElementById("conselheiro_nome").style.display = '';	
			document.getElementById("outros_meios").style.display = 'none';
		}else
			{
				document.getElementById("conselheiro_nome").style.display = 'none';	
				document.getElementById("outros_meios").style.display = '';
			}
	}
	else
		{
			document.getElementById('outros_meios').style.display = 'none';
			document.getElementById('conselheiro_nome').style.display = 'none';
		}
}
function contarCheck(id) 
{
	//Número máximo de checkbox que podem ser marcados
	var maxi=3;
	// valor do contador
	var count = parseInt($('contador').value);
   //Comprovo se o campo está marcado
   if ($(id).checked==true)
   {
	   // Aumento em 1 o valor do contador
		count += 1;
		// Envio o valor para o hidden
		$('contador').value = count;
       //comprovo se o contador chegou ao máximo permitido
       if (count>maxi)
	   {
          //se tiver chegado ao máximo, mostro mensagem de erro
          alert('Limite de '+maxi+' campos ao mesmo tempo.');
          //desmarco o campo, porque não se pode permitir marcar
          $(id).checked=false;
          //diminuo uma unidade ao contador de grupo, porque desmarquei um campo
		  count -= 1;
		  // Atribuo o valor ao hidden
          $('contador').value = count;
     	}
   }else
   {
	   // Se estiver desmarcando tiro 1 do contador
        count -= 1;
		/// Atribuo o valor ao hiddden
        $('contador').value = count;
   }
} 

function abreMenuProdutos()
{
	// Fecha menu institucional
    document.getElementById('menu_inst').style.display = 'none';
    // Abre menu produtos
    document.getElementById('menu_prod').style.display = '';
}
// Marca todos os checkbox da página meus clientes (conselheiros)
function checkAllClient()
{
	var total = document.getElementById('totalClient').value;
	if(total > 0)
	{
		if(document.getElementById('countClient').checked == true)
		{
			for(i=1;i<=total;i++)
			{
				document.getElementById('client_'+i).checked = true;
			}
		}else
			{
				for(i=1;i<=total;i++)
				{
					document.getElementById('client_'+i).checked = false;
				}
			}
	}else
		{
			alert("nenhum cliente cadastrado!");
		}
}
function checkAllBox()
{
	var total = $('total').value;
	if(total > 0)
	{
		if($('all').checked == true)
		{
			for(i=1;i<=total;i++){$('email_'+i).checked = true;}
		}else
			{
				for(i=1;i<=total;i++){$('email_'+i).checked = false;}
			}
	}else
		{
			if($('all').checked == true)
			{
				alert("nenhum contato foi selecionado!");
			}
		}
}
function opcao_de_compra(id)
{
	if($(id).checked == true)
	{
		if(id == "buscar_na_asta")
		{
			$('frete_valor').set('text', 'R$0,00');
		}
		var req = new Request.HTML({
		method: 'post',
		url: '_processa_opcao.php',
		data: { 'opcao' : id, 'valor_total' : $('valor_total').value },
		update: $('exibe_valor_total')
		}).send();
	}else
		{
			if(id == "buscar_na_asta")
			{
				$('frete_valor').set('text', $('valor_do_frete').value);
				cancelar = "cancelar_buscar_na_asta";
			}else
				{
					cancelar = "cancelar_pagamento_direto";
				}
			var req = new Request.HTML({
			method: 'post',
			url: '_processa_opcao.php',
			data: { 'opcao' : cancelar, 'valor_total' : $('valor_total').value },
			update: $('exibe_valor_total')
			}).send();
		}
}
function msg_direto(id)
{
	if($(id).checked == true)
	{
		if(confirm($('msg_direto').value))
		{
			opcao_de_compra(id);
		}else
			{
				$(id).checked = false;
				opcao_de_compra(id);
			}
	}else
		{
			opcao_de_compra(id);
		}
}
	
	