/*****************************************
* Rivello.net all rights reserved
* www.rivello.net
******************************************/

function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

/*
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
var EnableRightClick = 0;
//if(isNS) document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
  if(EnableRightClick==1){ return true; }
  else {return false; }
}
function mousehandler(e){
  if(EnableRightClick==1){ return true; }
  var myevent = (isNS) ? e : event;
  var eventbutton = (isNS) ? myevent.which : myevent.button;
  if((eventbutton==2)||(eventbutton==3)) return false;
}
function keyhandler(e) {
  var myevent = (isNS) ? e : window.event;
  if (myevent.keyCode==96)
    EnableRightClick = 1;
  return;
}
document.oncontextmenu = mischandler;
document.onkeypress = keyhandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
*/
function ratresp(ra,tn,pg,mt,pr){
	if(!document.getElementById(tn)){
	    alert("[NAV] Seu navegador não dá suporte a esse tipo de tecnologia, atualize ou instale um mais atual.");
	   }
		else
		{
		document.getElementById(tn).innerHTML = "Carregando...";
		 var c = new XHConn();
        if (!c) alert("[CNX] Seu navegador não dá suporte a esse tipo de tecnologia, atualize ou instale um mais atual.");

        var pronto = function (oXML) { document.getElementById(tn).innerHTML = oXML.responseText; };
         c.connect(pg+'.php', mt, "ra="+Math.random()+"&"+pr, pronto);
		}

}



function keyenter(botao,e)
{
 var key;
 if(window.event)
  key = window.event.keyCode;    
 else
  key = e.which;     

 if (key == 13)
 {
  var btn = document.getElementById(botao);
  if (btn != null)
  { 
   btn.click();
   event.keyCode = 0
  }
 }
}

function rat_lista_programas_sessao_usr(cod_sessao)
{
 var buscar = document.getElementById('pr_buscar').value;
 ratresp(Math.random(),'pr_lista','rat_lista_programas','GET', "b="+escape(buscar)+"&cod_sessao="+escape(cod_sessao));
}


function rat_lista_filmes_sessao_usr(cod_sessao)
{
 var buscar = document.getElementById('p_buscar').value;
 ratresp(Math.random(),'f_lista','rat_lista_filmes','GET', "b="+escape(buscar)+"&cod_sessao="+escape(cod_sessao));
}

function rat_lista_add_filme_sessao_usr(cod_filme, cod_sessao)
{
 ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_sessao_filme=0&op=1&cod_programa=0&cod_filme="+escape(cod_filme)+"&cod_sessao="+escape(cod_sessao));
 
}

function rat_lista_add_programa_sessao_usr(cod_programa, cod_sessao)
{
 ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_sessao_filme=0&op=4&cod_filme=0&cod_programa="+escape(cod_programa)+"&cod_sessao="+escape(cod_sessao));
 
}

function rat_lista_atualiza_filmes_sessao_usr(cod_sessao)
{
 ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_sessao_filme=0&cod_programa=0&op=0&cod_filme=0&cod_sessao="+escape(cod_sessao));
}



function rat_lista_atualiza_img_sessao_usr(cod_sessao)
{
 ratresp(Math.random(),'p_arq','rat_lista_imagens','GET', "cod_sessao="+escape(cod_sessao));
}


function rat_lista_excluir_img_sessao_usr(cod_sessao, cod_img)
{
 ratresp(Math.random(),'p_arq','rat_lista_imagens','GET', "cod_sessao_filme=0&cod_programa=0&op=0&cod_filme=0&cod_sessao="+escape(cod_sessao));
}







function rat_lista_remove_filme_sessao_usr(cod_sessao_filme,cod_sessao)
{
 ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_sessao_filme="+escape(cod_sessao_filme)+"&op=3&cod_programa=0&cod_filme=0&cod_sessao="+escape(cod_sessao));
}











function rat_listar_municipios(cod_sel, campo_estado, campo_municipio)
{
 var estado = document.getElementById(campo_estado).options[document.getElementById(campo_estado).selectedIndex].value;
//ratresp(Math.random(),campo_municipio+'_resp','rat_municipios','GET',"cod_estado="+parseInt(estado)+"&cod_sel="+parseInt(cod_sel)+"&nome_campo="+escape(campo_municipio));

document.getElementById(campo_municipio).disabled = true;
document.getElementById(campo_municipio).options[document.getElementById(campo_municipio).selectedIndex].text = "Carregando...";    
  var c = new XHConn();
  var pronto = function (oXML) 
   { 
     var m = new Array();
	 var r = oXML.responseText;
	 
	 for(var i=0; i <  document.getElementById(campo_municipio).options.length; i++) 
      document.getElementById(campo_municipio).remove(i) ;
 
	 eval(r);

	 for(var i=0; i < m.length; i++) 
	 {
	  var a = m[i].split(":");
	  document.getElementById(campo_municipio).options[i] = new Option(a[1],parseInt(a[0])); 
	  
	  if(parseInt(cod_sel) == parseInt(a[0]))
	   document.getElementById(campo_municipio).options[i].selected = true;
	  
	  
	 }
     document.getElementById(campo_municipio).disabled = false;
   };
   
   document.getElementById(campo_municipio).options[document.getElementById(campo_municipio).selectedIndex].text = "Carregando...";  
   
   var url = "ra=" + Math.random() + "&cod_estado=" + parseInt(estado) + "&cod_sel=" + parseInt(cod_sel) + "&nome_campo=" + escape(campo_municipio);
   c.connect('/rat_municipios.php', 'GET', url, pronto);
   
//   document.getElementById(campo_municipio).options[document.getElementById(campo_estado).selectedIndex].selected = true;
   
}
 /*
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};
*/
 
 
function rat_listar_filmes()
{
 var cod_programa = document.getElementById('p_codigo').value;

if(cod_programa == 0) {alert('Programa não selecionado'); return; }

 document.getElementById('filmes').disabled = true;
 document.getElementById('filmes').options[0].text = "Carregando...";    

 var c = new XHConn();
  var pronto = function (oXML) 
   { 
     var f = new Array();
	 var r = oXML.responseText;
	 
	 for(var i=0; i <  document.getElementById('filmes').options.length; i++) 
      document.getElementById('filmes').remove(i) ;
 
	 eval(r);

	 for(var i=0; i < f.length; i++) 
	 {
	  var a = f[i].split(":");
	  document.getElementById('filmes').options[i] = new Option(unescape(a[1]),parseInt(a[0])); 
	 }
     document.getElementById('filmes').disabled = false;
   };
   
   
   var url = "ra=" + Math.random() + "&c=" + parseInt(cod_programa);
   c.connect('rat_filmes.php', 'GET', url, pronto);
    
}
 
 
function moeda(num){
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'0') + num + '.' + cents);
}

function rat_lista_filmes(cod_programa)
{
 var buscar = document.getElementById('p_buscar').value;
 ratresp(Math.random(),'p_lista','rat_lista_filmes','GET', "b="+escape(buscar)+"&cod_programa="+escape(cod_programa));
}
 

function rat_lista_add_filme(cod_filme, cod_programa)
{
ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_programa_filme=0&peso=1&op=1&cod_filme="+escape(cod_filme)+"&cod_programa="+escape(cod_programa));

}



function rat_lista_atualiza_series(cod_programa)
{
 ratresp(Math.random(),'s_sacola','rat_series','GET', "cod_programa_serie=0&op=4&cod_serie=0&cod_programa="+escape(cod_programa));
}


function rat_lista_series(cod_programa)
{
 var buscar = document.getElementById('p_buscar').value;
 ratresp(Math.random(),'s_lista','rat_lista_series','GET', "b="+escape(buscar)+"&cod_programa="+escape(cod_programa));
}
 
 
function rat_lista(tipo,pg)
{
 var buscar = document.getElementById(tipo+'_buscar').value;
 ratresp(Math.random(),tipo+'_lista',pg,'GET', "b="+escape(buscar)+"&t="+escape(tipo));
} 
 
 
function rat_lista_add(cod_prop, nome, tipo)
{
 document.getElementById(tipo+'_nome').value = nome;
 document.getElementById(tipo+'_codigo').value = cod_prop;
 document.getElementById(tipo+'_lista').innerHTML = "";
}

function rat_lista_add_programa(cod_prop, nome, tipo)
{
 document.getElementById(tipo+'_nome').value = nome;
 document.getElementById(tipo+'_codigo').value = cod_prop;
 document.getElementById(tipo+'_lista').innerHTML = "";
 rat_listar_filmes();
  //ratresp(Math.random(),'f_lista','rat_filmes','GET', "c="+escape(cod_prop));
}
 
function rat_add_cesta(cod_programa)
{
 ratresp(Math.random(),'r_resposta','rat_addcesta','GET', "cod_programa="+escape(cod_programa));
 return false;
} 
 

function rat_lista_add_serie(cod_serie, cod_programa)
{
 ratresp(Math.random(),'s_sacola','rat_series','GET', "cod_programa_serie=0&op=1&cod_serie="+escape(cod_serie)+"&cod_programa="+escape(cod_programa));
}

function rat_lista_remove_serie_programa(cod_programa_serie,cod_programa)
{
ratresp(Math.random(),'s_sacola','rat_series','GET', "cod_programa_serie="+escape(cod_programa_serie)+"&op=3&cod_serie=0&cod_programa="+escape(cod_programa));
}

function rat_lista_atualiza_filmes(cod_programa)
{
 ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_programa_filme=0&peso=0&op=4&cod_filme=0&cod_programa="+escape(cod_programa));
}

function rat_lista_atualiza_filme_programa(cod_programa_filme,cod_programa,peso)
{
 var peso = document.getElementById('p_'+cod_programa_filme).value;
  if(peso <1){
	 alert("O peso deve ser maior que 0.");
	 return false;
	 }

ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_programa_filme="+escape(cod_programa_filme)+"&peso="+escape(peso)+"&op=2&cod_filme=0&cod_programa="+escape(cod_programa));
}

function rat_lista_remove_filme_programa(cod_programa_filme,cod_programa)
{
ratresp(Math.random(),'p_sacola','rat_filmes','GET', "cod_programa_filme="+escape(cod_programa_filme)+"&peso=0&op=3&cod_filme=0&cod_programa="+escape(cod_programa));
}

function porcento(){

if(document.getElementById('taxa').value == '-1') {alert("Selecione a Taxa de Entrega"); return false; }

ret_taxa();
box = document.frm.desconto;
valor = box.options[box.selectedIndex].value;

if(valor == -1){return;}
document.frm.total.value= moeda(((parseFloat(document.getElementById('s_subtotal').value) + parseFloat(document.frm.taxa.value) ) - (parseFloat(document.frm.total.value)*valor /100)));
}

function criaCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function leCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function apagaCookie(name) {
        createCookie(name,"",-1);
}

function rat_abre_comenta(resp,cod)
{
 var retorno = 'comentar';
 if(resp != 0) retorno = 'cmt'+resp;

 var bloco = document.getElementById(retorno);

 if(bloco)
 {
  if (bloco.style.display != 'block')
  {
   var nome = '';
   var email = '';
   if(a=leCookie('pr_cnome')) nome = a;
   if(a=leCookie('pr_cemail')) email = a;

bloco.innerHTML = "<br class=\"limpaF\"><form action=\"javascript:rat_comenta("+resp+","+cod+");\"><table border=0><tr><td><strong>Nome:</strong></td> <td><input type=\"text\" id=\"txtNome\" value=\""+unescape(nome)+"\" /></td></tr>   <tr><td><strong>E-mail:</strong></td><td><input id=\"txtEmail\" type=\"text\" value=\""+unescape(email)+"\" /></td></tr><tr><td><strong>Comentário:</strong</td><td><textarea id=\"txtComentario\"></textarea><br /></td></tr><tr><td></td><td><input  type=\"submit\" id=\"btOk\" value=\"ok\" /></td></tr></form><br class=\"limpaF\">";
   bloco.style.display = 'block';
  }
  else
  {
   bloco.style.display = 'none';
   bloco.innerHTML = "";
  }
 }
}

function rat_comenta(resp,cod){

 var nome = document.getElementById('txtNome').value;
 var email = document.getElementById('txtEmail').value;
 var comentario = document.getElementById('txtComentario').value;
 var retorno = 'comentar';
 //document.getElementById('btOk').disable = true;

 if(resp != 0) retorno = 'cmt'+resp;

  ratresp(Math.random(),retorno,'/rat_comentario','GET', "email="+escape(email)+"&comentario="+escape(comentario)+"&nome="+escape(nome)+"&cod="+parseInt(cod)+"&resp="+parseInt(resp));
 //document.getElementById('btOk').disable = false;


}

function rat_abre_comenta_prog(resp,cod)
{
 var retorno = 'comentar';
 if(resp != 0) retorno = 'cmt'+resp;

 var bloco = document.getElementById(retorno);

 if(bloco)
 {
  if (bloco.style.display != 'block')
  {
   var nome = '';
   var email = '';
   if(a=leCookie('pr_cnome')) nome = a;
   if(a=leCookie('pr_cemail')) email = a;

bloco.innerHTML = "<br class=\"limpaF\"><form action=\"javascript:rat_comenta_prog("+resp+","+cod+");\"><table border=0><tr><td><strong>Nome:</strong></td> <td><input type=\"text\" id=\"txtNome\" value=\""+unescape(nome)+"\" /></td></tr>   <tr><td><strong>E-mail:</strong></td><td><input id=\"txtEmail\" type=\"text\" value=\""+unescape(email)+"\" /></td></tr><tr><td><strong>Comentário:</strong</td><td><textarea id=\"txtComentario\"></textarea><br /></td></tr><tr><td></td><td><input  type=\"submit\" id=\"btOk\" value=\"ok\" /></td></tr></form><br class=\"limpaF\">";
   bloco.style.display = 'block';
  }
  else
  {
   bloco.style.display = 'none';
   bloco.innerHTML = "";
  }
 }
}

function rat_comenta_prog(resp,cod){

 var nome = document.getElementById('txtNome').value;
 var email = document.getElementById('txtEmail').value;
 var comentario = document.getElementById('txtComentario').value;
 var retorno = 'comentar';
 //document.getElementById('btOk').disable = true;

 if(resp != 0) retorno = 'cmt'+resp;

  ratresp(Math.random(),retorno,'/rat_comentario_prog','GET', "email="+escape(email)+"&comentario="+escape(comentario)+"&nome="+escape(nome)+"&cod="+parseInt(cod)+"&resp="+parseInt(resp));
 //document.getElementById('btOk').disable = false;


}





