var secs
var timerID = null
var timerRunning = false
var delay = 1000

function bookmark(){
var title = 'Zigg Download';
var url = 'http://www.ziggi.com.br/';
   if (document.all)
     window.external.AddFavorite(url, title);
   else if (window.sidebar)
     window.sidebar.addPanel(title, url, "")
   else if (window.sidebar&&window.sidebar.addPanel)
     window.sidebar.addPanel(title,url,"");
}

function downloadnow(url , rediURL , tipo) {
    if (tipo==24){
         window.open(url,'download','toolbar=0,location=no,directories=0,status=0,scrollbars=yes,resizable=yes,width=800,height=600,top=0,left=0');
    }else{
        window.open(url,'download','toolbar=0,location=no,directories=0,status=0,scrollbars=yes,resizable=0,width=10,height=10,top=0,left=0');
    }
        location.href = rediURL
}


function download(url , rediURL , tipo) {

if (tipo==3 || tipo==11){


	 window.open(url,'download','toolbar=0,location=no,directories=0,status=0,scrollbars=yes,resizable=yes,width=800,height=600,top=0,left=0');
	    //window.focus();
	    location.href = rediURL


} else{

		if (tipo==5 || tipo==7 || tipo==8 || tipo==9 || tipo==12 || tipo==14 || tipo==15 || tipo==17 || tipo==18){

	    	location.href = rediURL

		}else{


		window.open(url,'download','toolbar=0,location=no,directories=0,status=0,scrollbars=yes,resizable=0,width=10,height=10,top=0,left=0');
	    window.focus();
	    	location.href = rediURL

		}

}


}

function abrir_screenshot(URL) {
var width = 640;
var height = 550;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function abrir_janela_game(URL) {
var width = 900;
var height = 550;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function abrir_janela(URL) {
var width = 400;
var height = 250;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function enviar_pagina(URL) {
var width = 380;
var height = 400;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}
function videos_show(URL) {
var width = 450;
var height = 400;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function Abrir_Avaliacao(URL) {
var width = 380;
var height = 400;
var left = 200;
var top = 100;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function abrir_site(URL) {
var width = 777;
var height = 600;
var left = 0;
var top = 0;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function abrir_janela_maior(URL) {
var width = 777;
var height = 600;
var left = 0;
var top = 0;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function upload(URL) {
var width = 400;
var height = 200;
var left = 0;
var top = 0;
window.open(URL,'janela1', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

//-----Requisicoes Ajax do Meu Zigg
function retorno(url,destino){
		$('#S'+destino).css('display', 'block');
		$('#load'+destino).append('<img src="/img/ajax-loader.gif">');
		$('#load'+destino).ajaxStart(function () {


		});
         $.ajax({
              type:        "GET",
              url:          url,
              cache:		false,
              data:         null,
              success:      function(data) {
        	  $('#'+destino).html(data);
              },
              complete: 	function(){
            	$('#load'+destino).hide();
                }

         });

  }

//função Filtro Página principal meuZigg ->Meus Posts (usa Jqry
function filtro(url){


	$('#filtro').ajaxStart(function () {

    $('#filtro').append('<img src="/img/ajax-loader.gif">');
	});
     $.ajax({
          type:        "GET",
          url:          url,
          cache:		false,
          data:         null,
          success:      function(data) {
    	  $('#filtro').html(data);
          }
     });
}

function fechar(destino){
	$('#'+destino).html('');
	jQuery('.some').css('display', 'none');
}

function filesize (url) {
    // Get file size
    //
    // version: 909.322
    // discuss at: http://phpjs.org/functions/filesize
    // +   original by: Enrique Gonzalez
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: T. Wild
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes.
    // *     example 1: filesize('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '3'
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {throw new Error('XMLHttpRequest not supported');}

    req.open('HEAD', url, false);
    req.send(null);

    if (!req.getResponseHeader) {
        try {
            throw new Error('No getResponseHeader!');
        } catch (e){
            return false;
        }
    } else if (!req.getResponseHeader('Content-Length')) {
        try {
            throw new Error('No Content-Length!');
        } catch (e2){
            return false;
        }
    } else {
        document.write(req.getResponseHeader('Content-Length'));
        alert(req.getResponseHeader('Content-Length'));
        return req.getResponseHeader('Content-Length');
    }
}


function tempo(speed, size) {

var tmpo;
var novo;
var horas;
var mins;
var sec_f;
var secs;
var text;




size = size/1024
speed = parseInt(speed);

if(isNaN(speed)) { speed=256; }
if(speed<=0) { speed=256; }

tmpo = size / (speed / 8);
tmpo = Math.round(tmpo);
horas = tmpo / 3600;
horas = Math.floor(horas);

if(horas >= 1) {
        novo = horas;
        sec_f = tmpo % 3600;
        if(sec_f > 60) {
                mins= sec_f / 60;
                mins = Math.floor(mins);
                novo = novo + ':' + mins;
                secs= sec_f % 60;
                novo = novo + ':' + secs;
         }else{
                mins = 0;
                novo = novo + ':' + mins;
                secs = sec_f;
                novo = novo + ':' + secs;
         }
}else{
         mins= tmpo / 60;
         mins = Math.floor(mins);
         if(mins >= 1) {
            novo = '00:' + mins;
            secs = tmpo % 60;
            if(secs < 10) {
                secs = '0' + secs;
            }
            novo = novo + ':' + secs;
         }
         else {
            secs = tmpo % 60;
            if(secs == '00') {
            secs = '01';
            }
            novo = '00:00:' + secs;
         }
}

if(horas > 0) { horas = horas + 'h ';} else { horas ='';}
if(mins > 0) { mins = mins + 'min ';} else { mins ='';}
if(secs > 0) { secs = secs + 's';} else { secs ='';}

if(speed>=1000) { text = 'Mbps'; speed = Math.floor(speed/1000); } else { text ='Kbps';}

document.getElementById("tempo").innerHTML = horas + mins + secs;
document.getElementById("velo").innerHTML = ' a ' + speed + ' ' + text;

}

function tmpdow(size) {
 var velo = document.getElementById('user_speed').value;
 tempo(velo,size);
}


function add(id,programa_id,programa){
    link='/comparar/'+programa_id;
    var k=0
    for (i=0; i<document.test.checkgroup.length; i++){
        if (document.test.checkgroup[i].checked==true){
                k++
                if (k<=2){
                    link = link + '/'+document.test.checkgroup[i].id;
                    document.getElementById('btn_cmp').innerHTML = '<a href="'+link+'"><img src="/img/compare-bt.jpg"></a>';
                }else{
                    alert('Só é permitido adicionar 2 programas na comparação com o '+programa);
                    document.getElementById(id).checked=false
                }
        }

    }
}





