var seconds1 = 0,seconds2 = 0;
var tseconds1 = 5,tseconds2 = 5;

function reload1()
{
  seconds1++;
  if (seconds>tseconds) window.location.replace(window.location.href);
  else
  {
  document.monitor.clock.value = "Reload in "+(tseconds-seconds)+" seconds";
  setTimeout("reload1()", 1000);
  }
}

var checkLogin = function(id,usuario){

    validar = $('hvalidate').value;
    if(validar=='logueado'){
        $(id).toggle();
        $(usuario).hide();
        
    }else{
        openw('redirect.php','twitter');
    }
}

var checkLogin2 = function(id,usuario){

    validar = $('hvalidate').value;

    if(validar=='logueado'){
        $(id).toggle();
        $(usuario).hide();
    }else{
        openw('redirect.php','twitter');
    }
}

var getSidebar1 = function(p){
    var rnd=Math.floor(Math.random()*99999999)

    new Ajax.Request('/sidebar1/'+rnd, {
      method: 'post',
      parameters: { page: sd1page },
      onLoading: function(){
        $('load1').show();
        $('moresd1').hide();
      },
      onSuccess: function(transport) {
        $('load1').hide();
        var txt =transport.responseText;
        
        $('sidebar1').insert({bottom: txt});

        if(sd1page>4 || txt=='' || $('count1').innerHTML<10 ){ $('moresd1').hide(); }
        else{
            $('moresd1').show();
        }
        $('count1').remove();
        sd1page++; 
      }
    });

}

var getSidebar2 = function(p){
    var rnd=Math.floor(Math.random()*99999999)

    new Ajax.Request('/sidebar2/'+rnd, {
      method: 'post',
      parameters: { page: sd2page },
      onLoading: function(){
        $('load2').show();
        $('moresd2').hide();
      },
      onSuccess: function(transport) {
        $('load2').hide();
        var txt =transport.responseText;

        $('sidebar2').insert({bottom: txt});

        if(sd2page>4 || txt==''  || $('count2').innerHTML<10){ $('moresd2').hide(); }
        else{
            $('moresd2').show();
        }
        $('count2').remove();
        sd2page++;

      }
    });

}

var getSidebar3 = function(p){
    var rnd=Math.floor(Math.random()*99999999)

    new Ajax.Request('/sidebar3/'+rnd, {
      method: 'post',
      parameters: { page: sd3page, tag: p },
      onLoading: function(){
        $('load3').show();
        $('moresd3').hide();
      },
      onSuccess: function(transport) {
        $('load3').hide();
        var txt =transport.responseText;

        $('sidebar3').insert({bottom: txt});

        if(sd3page>4 || txt=='' || $('count3').innerHTML<10 ){ $('moresd3').hide(); }
        else{
            $('moresd3').show();
        }
        sd3page++;
        $('count3').remove();

      }
    });

}

var getSidebar4 = function(p){
    var rnd=Math.floor(Math.random()*99999999)

    new Ajax.Request('/sidebar4/'+rnd, {
      method: 'post',
      parameters: { page: sd4page, tag: $('scrit').value },
      onLoading: function(){
        $('load4').show();
        $('moresd4').hide();
      },
      onSuccess: function(transport) {
        $('load4').hide();
        var txt =transport.responseText;

        $('sidebar4' || txt=='').insert({bottom: txt});

        if(sd4page>4 || txt=='' || $('count4').innerHTML<10){ $('moresd4').hide(); }
        else{
            $('moresd4').show();
        }
        $('count4').remove();
        sd4page++;

      }
    });

}


var llenarTextarea = function(id){
    $('tweet').value=id;
    $('tweet').focus();    
}


var selectPeli = function(p){
    if(p!=''){
        location.href='/'+p;
    }
}

var isfollower = function(flag){

    new Ajax.Request('_switchfollow.php', {
      method: 'post',
      parameters: { flag: flag }
    });
}

function limita(obj,elEvento, maxi)
{
  var elem = obj;

  var evento = elEvento || window.event;
  var cod = evento.charCode || evento.keyCode;

    // 37 izquierda
    // 38 arriba
    // 39 derecha
    // 40 abajo
    // 8  backspace
    // 46 suprimir

  if(cod == 37 || cod == 38 || cod == 39
  || cod == 40 || cod == 8 || cod == 46)
  {
    return true;
  }

  if(elem.value.length < maxi )
  {
    return true;
  }

  return false;
}

function cuenta(obj,evento,maxi,div)
{
    var elem = obj.value;
    var info = document.getElementById(div);

    info.innerHTML = maxi-elem.length;
    infofo = info.innerHTML;
}

function buscarPelis(){

    if($('spelicula').value=='0' && $('scine').value=='0'){
        alert('Elija una Pel\xEDcula o Cine');
    }else{
        location.href = '/'+$('spelicula').value + '/' + $('scine').value;
    }



}
function buscarPelis2(){

    if($('spelicula').value=='0' && $('scine').value=='0'){
        alert("Elija una Pel\xEDcula o Cine");
    }else{
        window.open('/'+$('spelicula').value + '/' + $('scine').value);
    }



}

function activeTab(ta){

    $(ta).show().addClassName('active');

    if(ta=='tab1'){
        $('sidebara3').show();
        $('sidebara4').hide();
        $('tab2').removeClassName('active');

    }else{
        $('sidebara3').hide();
        $('sidebara4').show();
        $('tab1').removeClassName('active');
    }


}

function openw(url,windowName,windowOptions,inTimeOut)
{
if(typeof windowOptions=='undefined'){windowOptions='menubar=0,toolbar=0,resizable=1,width=960,height=680';}
var wo=windowOptions;try{w=windowOptions.split('width=')[1].split(',')[0];h=windowOptions.split('height=')[1].split(',')[0];var wleft=(screen.width-w)/2;var wtop=(screen.height-h)/2;if(wleft<0){w=screen.width;wleft=0;}
if(wtop<0){h=screen.height;wtop=0;}
wo+=',top='+wtop+',left='+wleft;}catch(e){}
var newWin=window.open(url,windowName,wo);if(!newWin)
{newWin=window.open('',windowName,wo);if(newWin&&newWin.location)
{newWin.location.href=url;}}
if(!newWin&&!inTimeOut)
{window.setTimeout('gigya.global._OpenWindow("'+url+'", "'+windowName+'", "'+windowOptions+'", true)',10);return;}
if(newWin&&newWin.focus)
{newWin.focus();}
}

