﻿

var http = getHTTPObject();
var progantiguo;
function inserta_view(){
var id = document.getElementById("hidenvideo_id").value;

document.getElementById("video").setAttribute("onClick","");
var url = "../ajax/inserta_view_home.aspx?id="+id;
http.open("GET", url, true);
http.send(null);
}


function busqueda(busca,ci, ps, pagina){
if (pagina != "")
{
var r = "/home/megagaleria/busqueda/pagina/" + pagina;
cert_registerHit(25559, r);
}

document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "<div style='padding-top:200px;padding-left:300px'><span><img src='../images/loading.gif' width='32' height='32' alt=''></span></span><div>";
document.getElementById("ctl00_Contenido_hidencategoria").value = 0;
document.getElementById("ctl00_Contenido_hidensubcategoria").value = 0;
var orden = " fecha desc";
    var url = "../ajax/busqueda.aspx?b="+busca+"&ci="+ci+"&ps="+ps+"&orden="+orden;
    
    http.open("GET", url, true);
    http.onreadystatechange = procesar;
    http.send(null);
}  

function cambia_orden(cbo){
var ci = 0;
var ps = 10;
var url = "";
cbo = "ctl00_Contenido_"+cbo;

var orden = document.getElementById(cbo).options[document.getElementById(cbo).selectedIndex].value
document.getElementById('ctl00_Contenido_hidenorden').value = orden;
var categoria = document.getElementById("ctl00_Contenido_hidencategoria").value ;
var subcategoria = document.getElementById("ctl00_Contenido_hidensubcategoria").value;
var r = "/home/megagaleria/"+tipo+"orden/"+orden;

cert_registerHit(25559, r);

if (categoria != 0 && subcategoria != 0){
url = nivel + "../ajax/listaprogramas.aspx?categoria="+categoria+"&subcategoria="+subcategoria+"&ci="+ci+"&ps="+ps+"&orden="+orden+"&nivel="+nivel;
}else{
        if (document.getElementById("ctl00_Contenido_hidenbusca")){
            url = nivel + "../ajax/busqueda.aspx?b=" + document.getElementById("ctl00_Contenido_hidenbusca").value + "&ci=0&ps=10&orden=" + orden+"&nivel="+nivel;
            
        }
        else{
        url = "../ajax/listaprogramas.aspx?categoria="+categoria+"&subcategoria="+subcategoria+"&ci="+ci+"&ps="+ps+"&orden="+orden+"&nivel="+nivel;
        }
 
}

document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "<div style='padding-top:200px;padding-left:300px'><span><img src='"+nivel+"../images/loading.gif' width='32' height='32' alt=''></span></span><div>";
http.open("GET", url, true);

http.onreadystatechange = procesar;
http.send(null);
 
}



function setcolor(id){
    if(progantiguo == undefined){
        progantiguo = id;
    document.getElementById(id).style.fontWeight = "bold";    
    }else{
        if(progantiguo != id){
            
            document.getElementById(progantiguo).style.color = "#979797";
            document.getElementById(progantiguo).style.fontWeight = "normal";  
            document.getElementById(id).style.fontWeight = "bold";     
            progantiguo = id;
        }
    }
    
}

function CargarDocumentoXML(categoria, subcategoria, ci, ps, nivel, programa) {


var orden = document.getElementById('ctl00_Contenido_hidenorden').value;
if (programa != ''){
var r = "/home/megagaleria/"+tipo+"Categorias/" +  programa.replace(" ", "_").replace(" ", "_").replace(" ", "_").replace(" ", "_").replace(" ", "_")

cert_registerHit(25559, r);
}
if (orden == '0')
{
orden = " fecha desc";
}


var url =  nivel+ "../ajax/listaprogramas.aspx?categoria="+categoria+"&subcategoria="+subcategoria+"&ci="+ci+"&ps="+ps+"&orden="+orden+"&nivel="+nivel;

document.getElementById("ctl00_Contenido_hidencategoria").value = categoria;
document.getElementById("ctl00_Contenido_hidensubcategoria").value = subcategoria;
document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "<div style='padding-top:200px;padding-left:300px'><span><img src='"+nivel+"../images/loading.gif' width='32' height='32' alt=''></span></span><div>";

http.open("GET", url, true);
http.onreadystatechange = procesar;
http.send(null);
  
}

function carga_pagina(categoria, subcategoria, ci, ps, nivel, pagina)
{

var orden = document.getElementById('ctl00_Contenido_hidenorden').value;

if (pagina!= ''){
var r = "/home/megagaleria/"+tipo+  "paginas/" + pagina;

cert_registerHit(25559, r);
}
if (orden == '0')
{
orden = " fecha desc";
}


var url = nivel + "../ajax/listaprogramas.aspx?categoria="+categoria+"&subcategoria="+subcategoria+"&ci="+ci+"&ps="+ps+"&orden="+orden+"&nivel="+nivel;
document.getElementById("ctl00_Contenido_hidencategoria").value = categoria;
document.getElementById("ctl00_Contenido_hidensubcategoria").value = subcategoria;
document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "<div style='padding-top:200px;padding-left:300px'><span><img src='../images/loading.gif' width='32' height='32' alt=''></span></span><div>";

http.open("GET", url, true);
http.onreadystatechange = procesar;
http.send(null);
}




function procesar() {

    
    if (http.readyState == 4) {
        if (http.status == 200) {
       
           var xmlDocument = http.responseXML;
           var i ;
           var total = xmlDocument.getElementsByTagName("idprod").length;
           
            var total_pag = xmlDocument.getElementsByTagName("pagina").length;
            
         
           document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "";
           var texto = "";
           var pagina = "";
           for (i=0;i<total_pag;i++)
           {
             var pag = xmlDocument.getElementsByTagName("pagina")[i];
           
               if (pag.childNodes[0] != undefined ){
              pagina += pag.childNodes[0].nodeValue;
           
          
           
           }
            document.getElementById("ctl00_Contenido_barrapaginabottomrptpag").innerHTML = pagina;
            document.getElementById("ctl00_Contenido_barrapaginatoprptpag").innerHTML = pagina;
           }
           
           for (i=0;i<total;i++)
           {
          
            var text = xmlDocument.getElementsByTagName("idprod")[i];
          
            
           if (text.childNodes[0] != undefined ){
           
           texto += text.childNodes[0].nodeValue;
          
           
           }else{
           
           document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = "Categoria sin contenido";}
           }
         
            document.getElementById("ctl00_Contenido_dvgaleriaprincipal").innerHTML = texto;
           
            
           
           
         } else {
            alert("Hubo un problema al intentar obtener el contenido: " + http.statusText);
         }
    }
}


function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}



function copy(text2copy) {

  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
    
  } else {
  
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
  
  document.getElementById('embed').style.backgroundColor = 'green';
  
  

}



function kickStart() {

copy(document.getElementById('embed').value);
var r = "/home/megagaleria/"+tipo+  "copiar_embed";

cert_registerHit(25559, r);



}

function btncopiar_in(){
document.getElementById("btncopiar").style.color = 'red';
document.getElementById("btncopiar").style.textDecoration = 'underline';
}
function btncopiar_out(){
 document.getElementById("btncopiar").style.color = 'black';
document.getElementById("btncopiar").style.textDecoration = 'none';
}

function escribevideo(){
                                                  
                                                  var video = document.getElementById('hidenvideourl').value;
                                                    var vthumb = document.getElementById('vthumb').value + "jpg";
                                                  if (document.getElementById('hidenvideourl1')){
                                                 
                                                  var video1 = document.getElementById('hidenvideourl1').value;
                                                  }
                                                    
                                                  if (document.getElementById('hidenvideourl2')){
                                                
                                                  var video2 = document.getElementById('hidenvideourl2').value;
                                                  }
                                                  if (document.getElementById('hidenvideourl3')){
                                                  var video3 = document.getElementById('hidenvideourl3').value;
                                                  }
                                                  if (document.getElementById('hidenvideolink1')){
                                                  var link1 = document.getElementById('hidenvideolink1').value;
                                                
                                                  }
                                                  if (document.getElementById('rel0'))
                                                  {
                                                    var rel1 = document.getElementById('rel0').value + "jpg";
                                                  }
                                                  if (document.getElementById('hidenvideolink2')){
                                                  var link2 = document.getElementById('hidenvideolink2').value;
                                                   
                                                  }
                                                  
                                                  if (document.getElementById('rel1'))
                                                  {
                                                   var rel2 = document.getElementById('rel1').value + "jpg";
                                                  }
                                                  if (document.getElementById('hidenvideolink3')){
                                                  var link3 = document.getElementById('hidenvideolink3').value;
                                                 
                                                  
                                                  }
                                                  if (document.getElementById('rel2'))
                                                  {
                                                   var rel3 = document.getElementById('rel2').value + "jpg";
                                                  }
                                                  if (document.getElementById('hidenvideotitulo')){
                                                  var titulo = document.getElementById('hidenvideotitulo').value;
                                                  }
                                                  if (document.getElementById('hidenvideotitulo1')){
                                                  var titulo1 = document.getElementById('hidenvideotitulo1').value;
                                                  }
                                                  if (document.getElementById('hidenvideotitulo2')){
                                                  var titulo2 = document.getElementById('hidenvideotitulo2').value;
                                                  }
                                                  if (document.getElementById('hidenvideotitulo3')){
                                                  var titulo3 = document.getElementById('hidenvideotitulo3').value;
                                                  }
                                                  var urlplayer = nivel + "../player/player.swf";
                                                  
                                                  var so = new SWFObject(urlplayer, "video", "400", "300", "9", "000000");
                                                  so.addVariable("vintro", "http://media.mega.cl/videos/introanima.flv");
                                                  so.addVariable("vcont", video);
                                                  so.addVariable("voutro", "http://media.mega.cl/videos/megaloop.flv");
                                                  so.addVariable("vthumb", vthumb.replace("\\", "/"));
                                                  so.addVariable("tcont", titulo);
                                                  
                                                 if (video1){
                                                  so.addVariable("rel1", video1);
                                                  }
                                                  if (video2){
                                                  so.addVariable("rel2", video2);
                                                  }
                                                  if (video3){
                                                  so.addVariable("rel3", video3);
                                                  }
                                                  if (titulo1){
                                                  so.addVariable("reltext1", titulo1.replace("\"", "'").replace("\"", "'"));
                                                  }
                                                   if (titulo2){
                                                  so.addVariable("reltext2", titulo2.replace("\"", "'").replace("\"", "'"));
                                                  }
                                                  if (titulo3){
                                                  so.addVariable("reltext3", titulo3.replace("\"", "'").replace("\"", "'"));
                                                  
                                                  }
                                                  
                                                  if (link1){
                                                  so.addVariable("relink1", link1);
                                                  
                                                  }
                                                  if (rel1){
                                                  so.addVariable("rel1", rel1.replace("\\", "/"));
                                                  }
                                                  if (link2){
                                                  so.addVariable("relink2", link2);
                                                   
                                                  }
                                                 
                                                  if (rel2){so.addVariable("rel2", rel2.replace("\\", "/"));}
                                                  
                                                  if (link3){
                                                  so.addVariable("relink3", link3);
                                                
                                                 
                                                  
                                                  }
                                                  if (rel3){so.addVariable("rel3", rel3.replace("\\", "/"));}
                                                  
                                                  so.addParam("wmode", "transparent");
                                                  so.addParam("menu", "false");
                                                  so.addParam("allowFullScreen", "true");
                                               
                                                 
                                                  var agrega = "" ;
                                                   if (video1){
                                                  agrega += "&rel1=" + video1;
                                                  }
                                                   if (titulo1){
                                                  agrega += "&reltext1="+  titulo1;
                                                  }
                                                   if (link1){
                                                  agrega += "&relink1=" +link1;
                                                  }
                                                  
                                                    if (video2){
                                                  agrega += "&rel2=" + video2;
                                                  }
                                                   if (titulo2){
                                                  agrega += "&reltext2="+  titulo2;
                                                  }
                                                   if (link2){
                                                  agrega += "&relink2=" +link2;
                                                  }
                                                  
                                                  
                                                   if (video3){
                                                  agrega += "&rel3=" + video3;
                                                  }
                                                   if (titulo3){
                                                  agrega += "&reltext3="+  titulo3;
                                                  }
                                                   if (link3){
                                                  agrega += "&relink3=" +link3;
                                                  }
                                                  if(rel1){
                                                    agrega += "&rel1="+rel1;
                                                   
                                                  }
                                                  
                                                  if(rel2){
                                                    agrega += "&rel2="+rel2;
                                                  }
                                                  
                                                  if(rel2){
                                                    agrega += "&rel3="+rel3;
                                                  }
                                                  
                                                  
                                                  
                                                   so.write("video");
                                                   
                                                 document.getElementById('embed').value = "<p><embed src='"+urldireccion+"player/megaplayer.swf'  wmode='transparent'   width='400'   height='300'   allowscriptaccess='always'   allowfullscreen='true'   flashvars='vcont="+video+"&tcont="+titulo+"&vthumb="+vthumb+ agrega +"' /></p>";
                                                 
                                                 }
                                                 
 
