var div_load_alpha_carrinho, iIntervalID_carrinho, div_atualizando_carrinho, carrinho_aberto, div_open_carrinho, iIntervalID_carrinho_time;
carrinho_aberto = false;


function abreCarrinho(Visivel, pagina){
	div_atualizando_carrinho = false;
	div_open_carrinho = true;
	
	if(screen.availWidth <= 800){
		document.getElementById('representantes').style.visibility = 'hidden';
	}
	
	if(carrinho_aberto == false){
		exec_ajax(pagina, 'GET', 'true', 'representantes');
		carrinho_aberto = true;	
	}
	
		if (div_atualizando_carrinho == false){
			if (Visivel == true){
				div_load_alpha_carrinho = 0;
			
			}else{
				div_load_alpha_carrinho = 100;
			}
			iIntervalID_carrinho = 0;
			//document.getElementById('area_forma').style.top = tempY + 10;
			if (navigator.appName.indexOf("Netscape")!=-1   && parseInt(navigator.appVersion)>=5)	  {
					document.getElementById('representantes').style.MozOpacity= (Visivel ? 0 : 100)/100;
				}else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)	  {
					document.getElementById('representantes').style.filter = 'alpha(opacity=' + Visivel ? 0 : 100 + ')';
			}
			document.getElementById('representantes').style.visibility  = Visivel ? "visible" : "hidden";
			document.getElementById('representantes').style.display  = Visivel ? "inline" : "none";

			if (Visivel == true){
				load_div(Visivel, 'representantes');
				
				if (iIntervalID_carrinho_time > 0 ){
					window.clearInterval(iIntervalID_carrinho_time);
					iIntervalID_carrinho_time = 0;
				}
				iIntervalID_carrinho_time  = setTimeout ("abreCarrinho(false);", 15000);
			}else{
				document.getElementById('representantes').style.visibility = 'visible';
			}	
			
			
		}
}

function fechaCarrinho(){
		document.getElementById('representantes').style.display = 'none';
}

function muda_estado( )
{ var retorno;
// if xmlhttp mostrar "loaded"
if (xmlhttp.readyState==4)
  {
  retorno = xmlhttp.responseText;

  // if "OK"

  if (xmlhttp.status==200)
    {
		document.getElementById('representantes').innerHTML=retorno;
		//findScript(retorno)

		
    }
  else
    {
	   document.getElementById('representantes').innerHTML= "Falha no carregamento. " + httpStatus(xmlhttp.status);
    }
  }
}

 function httpStatus(stat){ //retorna o texto do erro http

        switch(stat){

            case 0: return "Erro desconhecido de javascript";

            case 400: return "400: Solicita&ccedil;&atilde;o incompreensível"; break;

            case 403: case 404: return "404: N&atilde;o foi encontrada a URL solicitada"; break;

            case 405: return "405: O servidor n&atilde;o suporta o m&eacute;todo solicitado"; break;

            case 500: return "500: Erro desconhecido de natureza do servidor"; break;

            case 503: return "503: Capacidade m&aacute;xima do servidor alcançada"; break;

            default: return "Erro " + stat + ". Mais informa&ccedil;&otilde;es em http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"; break;

        }

    }




function muda_estado_cesta( )
{ var retorno;
// if xmlhttp mostrar "loaded"
if (xmlhttp.readyState==4)
  {
  retorno = xmlhttp.responseText;

  // if "OK"

  if (xmlhttp.status==200)
    {
		var valores
		
		valores = retorno.split('*')
		
		document.getElementById('total_liquido').innerHTML= 'R$' + valores[1];
		
		document.getElementById(objeto_retorno).innerHTML= 'R$' + valores[0];
		//findScript(retorno)
		document.getElementById('btn_prosseguir').innerHTML = btn_prosseguir;
		document.getElementById('desconto_frm_pgto').value = retorno.replace('R$', '');
	
    }
  else
    {
		document.getElementsByName('desconto_frm_pgto').value = '0';	
	   document.getElementById(objeto_retorno).innerHTML= "Ocorreu um problema, tente mais tarde";
    }
  }
}
var objeto_retorno;
function exec_ajax_desc_pagto(url, metodo, modo, divRetorno) {

	objeto_retorno = divRetorno;
document.getElementById(divRetorno).innerHTML='<div align="center" class="carregando"><img src="http://www.magazineluiza.com.br/imagens/layout2007/hourglass.gif" /> carregando...</div>'
xmlhttp=null;
if (window.XMLHttpRequest)
  {
 
  xmlhttp=new XMLHttpRequest()
  }
// IE
else if (window.ActiveXObject)
  {

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }


if (xmlhttp!=null)
  {
            if(metodo == "GET") {
                xmlhttp.open("GET", url + '&rnd' + Math.random(), true);
            } else {        
                xmlhttp.open("POST", url + '&rnd' + Math.random(), true);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    

            
            xmlhttp.onreadystatechange = muda_estado_cesta; 
			
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
  }
	else
  {
   document.getElementById(divRetorno).innerHTML= "Seu navegador não suporta esta operação.";
  }
	
	
}

function exec_ajax(url, metodo, modo, divRetorno) {
document.getElementById(divRetorno).innerHTML='<div align="center" class="carregando"><br/><br/><br/>carregando...</div>'
xmlhttp=null;
if (window.XMLHttpRequest)
  {
 
  xmlhttp=new XMLHttpRequest()
  }
// IE
else if (window.ActiveXObject)
  {

  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }


if (xmlhttp!=null)
  {
            if(metodo == "GET") {
                xmlhttp.open("GET", url + '&rnd' + Math.random(), true);
            } else {        
                xmlhttp.open("POST", url + '&rnd' + Math.random(), true);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    

            
            xmlhttp.onreadystatechange = muda_estado; 
			
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
  }
	else
  {
   document.getElementById(divRetorno).innerHTML= "Seu navegador não suporta esta operação.";
  }
	
	
}
function enviaPagina(url, metodo, modo, tagId, parametros)
{

    exec_ajax( url+"?"+parametros+"&rnd"+ Math.random() , metodo, modo , tagId); 
}

function load_div(Visible, Id){

	if (navigator.appName.indexOf("Netscape")!=-1   && parseInt(navigator.appVersion)>=5)	  {
			window.document.getElementById(Id).style.MozOpacity= (div_load_alpha_carrinho)/100;
		}else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)	  {
			//window.document.getElementById(Id).filters.alpha.opacity= div_load_alpha;
			document.getElementById(Id).style.filter = 'alpha(opacity=' + div_load_alpha_carrinho + ')';
	}
	//document.getElementById(Id).style.overflow = 'hidden';
	div_load_alpha_carrinho = Visible ? 0 : 100;
	iIntervalID_carrinho =  setTimeout('load_alpha_carrinho('+ Visible +', "' + Id + '");', 100);
		
}



 function load_alpha_carrinho(aparecer, id){
		div_atualizando_carrinho = true;
	    div_open_carrinho = true;
		
		if (((aparecer == true) && (div_load_alpha_carrinho <= 100) ) || ((aparecer == false) && (div_load_alpha_carrinho >= 0) )){


		document.getElementById(id).style.filter = 'alpha(opacity=' + div_load_alpha_carrinho + ')';
		document.getElementById(id).style.MozOpacity= (div_load_alpha_carrinho)/100;
		//document.getElementById('area_forma').style.filter = 'alpha(opacity=' + div_load_alpha + ')';
		//document.getElementById('area_forma').style.MozOpacity =  div_load_alpha/100 ;
		

			if (aparecer == true){
				div_load_alpha_carrinho = div_load_alpha_carrinho +  10 ;
			}else{
				div_load_alpha_carrinho = div_load_alpha_carrinho   -10;
			}
			
			window.clearInterval(iIntervalID_carrinho);
			iIntervalID_carrinho  = setTimeout ('load_alpha_carrinho('+ aparecer +', "' + id + '");', 100);			
		}else{
			window.clearInterval(iIntervalID_carrinho);
			
			//document.getElementById('area_forma').style.overflow = div_scroll;
			div_atualizando_carrinho = false;
			document.getElementById(id).style.filter = 'alpha(opacity=100)';
			document.getElementById(id).style.MozOpacity= 1;
			

		}
	 }


