/*****************************************
* 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 = "<img src=\"/img/loading.gif\" alt=\"\" />";
		 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 e(ra,ca,na,sm){
 	if(!document.getElementById ||
       !document.getElementsByTagName ||
       !document.getElementById('b')){
	    alert("[NAV] Seu navegador não dá suporte a esse tipo de tecnologia, atualize ou instale um mais atual.");
	   }
		else
		{
		 var b = document.getElementById('b').value;
		 if(sm == true) b = "";
		 document.getElementById('respcanal').innerHTML = na;
		 document.getElementById('buscar').disable = true;
		 document.getElementById('buscar').value = "carregando...";
         ratresp(ra,'ratult','ratlista','GET','b='+escape(b)+"&c="+parseInt(ca));
		 document.getElementById('buscar').disable = false;
		 document.getElementById('buscar').value = "Buscar";
		}
}
function pl(id,ra){
	 	if(!document.getElementById ||
       !document.getElementsByTagName ||
       !document.getElementById('b')){
	    alert("[CNX] Seu navegador não dá suporte a esse tipo de tecnologia, atualize ou instale um mais atual.");
	   }
		else
		{
		 document.getElementById('player').src = "ratip.php?c="+id+"&ra="+ra;
	     ratresp(Math.random(),'ratdesc','ratcmt','GET', "c="+id+"&ra="+ra);
		}
}


function rat_lista_rapida(){
 var estado = document.getElementById('estado').options[document.getElementById('estado').selectedIndex].value;
 var busca = document.getElementById('lBusca').value;

 document.getElementById('btBuscar').disable = true;
  ratresp(Math.random(),'buscaEntrevistas','/rat_lista_rapida','GET', "estado="+parseInt(estado)+"&lBusca="+escape(busca));
 document.getElementById('btBuscar').disable = false;
 }

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('cc_cnome')) nome = a;
   if(a=leCookie('cc_cemail')) email = a;

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

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_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;


}

