var loader='<center><img src="/imagenes/cargando.gif" /><br><b>CARGANDO CONTENIDO...</b></center>';
var loader='<center><img src="/imagenes/cargando.gif" /><br><b>CARGANDO CONTENIDO...</b></center>';
var loader2='<img src="/radio/chat_loader.gif" />';
var ver=0;
var css_row_on="jQuery(this).css({'background-color' : '#FF6600'});";
var css_row_out="jQuery(this).css({'background-color' : 'black'});";
var style_row='font-weight:normal;';
var actual='';
var xartist='';
var xtitle='';
var xtid='';
var prg=1;
var live=0;
var dj=0;
var xml_prog='';
			if(!eluser){
			eluser='anonimo';
			}
			
var txt="deDesparche.com Radio";

jQuery(document).ready(

    function(){
	 		jQuery.get('/radio/registro_ajax1/verify.php', {action: 'count'}, function(data){
            if(data!=ver){
                ver=data;
            }
    });
    jQuery('#chat_loader').hide();
    jQuery('#chat_loader').html(loader2);
	
	jQuery( "#tabs-6" ).tabs({
		select: function(event, ui) { actualizar_last(); }
	});

//TOP
actualizar_top();
actualizar_pending();
actualizar_last();


var result='';

//jurl='http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?';
        jQuery("#form_search").submit( function () {
            search_cancion(jQuery("#search").val());
			jQuery("#search2").val(jQuery("#search").val());
            return false;
        } );
        jQuery("#form_search2").submit( function () {
            search_cancion(jQuery("#search2").val());
			jQuery("#search").val(jQuery("#search2").val());
            return false;
        } );		


        jQuery("#form_comment").submit( function () {
            jQuery.ajax({
                data:jQuery.param(jQuery(this).serializeArray()),
                dataType:'script',
                type:'post',
                url:'/radio/registro_ajax1/registro.php',
				beforeSend:function(obj){
				jQuery('#chat_loader').fadeIn("slow");
				document.nuevo_empleado.Submit.disabled='disabled';
				document.nuevo_empleado.comentario.disabled='disabled';
				document.nuevo_empleado.Submit.value='Enviando Mensaje...';
				},
				success:function(request){
					jQuery('#resultado').html(request);
                    jQuery('#chat_loader').fadeOut("slow");
				document.nuevo_empleado.Submit.disabled='';
				document.nuevo_empleado.comentario.disabled='';
				document.nuevo_empleado.Submit.value='Enviar Mensaje!';
				document.nuevo_empleado.comentario.value='';
	 		jQuery.get('/radio/registro_ajax1/verify.php', {action: 'count'}, function(data){
            if(data!=ver){
                ver=data;
            }
    });
				}
			});
            return false;
            jQuery('form .message').value = "";
        } );

    })
function estado() {
                var t=new Date();
            
	 		jQuery.get('/radio/registro_ajax1/verify.php?time='+t.getTime(), {action: 'count'}, function(data){
            //alert(data+' ****'+ ver);
            if(data!=ver){
                
                ver=data;
                actualizar_comentarios();
                play_chat();

            }
    });



}

function estado2(){
actualizar_last();
actualizar_top();
actualizar_pending();

}

function actualizar_comentarios(){
    jQuery.ajax({
		beforeSend:function(obj){
			jQuery('#chat_loader').fadeIn("slow");
            jQuery('#notificacion').html('');
		},        
		success:function(request){
            jQuery('#resultado').html(request);
            jQuery('#chat_loader').fadeOut("slow");
        },

        url:'/radio/registro_ajax1/consulta.php',
        cache: false
    })
    actualizar_pending();
}


var chat_win = null;
var w = 480, h = 340;
function openBrWindow(theURL,winName,features) {
  chat_win=window.open(theURL,winName,features);
  if (chat_win.moveTo) {
  chat_win.moveTo(w/2,h/2);
  }
}

function abrechat(url_chat){
openBrWindow(url_chat,'chat','toolbar=no,scrollbars=no,scrollbars=0,width=800,height=600');
}

function selectHTML(elementID)
{
	document.getElementById(elementID).select();
}

//setTimeout("actualizar_comentarios()", 2000);
timerID = setInterval("estado()", 2000);
timerID2 = setInterval("estado2()", 60000);

function DHTMLSound(surl) {
  document.getElementById("dummyspan").innerHTML=
    "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
function play_chat(){
   if(mySound){
       mySound.play();
   }
}
var mySound;
soundManager.debugMode = false;
soundManager.defaultOptions.volume = 10;
soundManager.onload = function() {
   mySound = soundManager.createSound({
    id: 'aSound',
    url: 'http://mdigitalplus.com/chat.mp3'
    // onload: [ event handler function object ],
    // other options here,
  });
}
function search_cancion(q){
            jQuery('#chat_loader').fadeIn("slow");
            var jurl='http://emisora.dedesparche.com/radio/search_json.php?q='+q+'&genid='+genid+'&callback=?';
            result='Haz click en la canci&oacute;n que deseas programar<br><table border="0">';
            jQuery.getJSON(jurl,
            function(json) {
                var i=0;
                if(json.total>0){
                result=result+'Resultados:'+json.total+'<br>';

                jQuery.each(json.data, function(i,item){
                i++;
//'<a href="#top">'
                //result=result+'<tr style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'"><td><img src="http://www.dedesparche.com/fuente.php?size=8&text=%20'+i+'%20&color=ffffff&bg=333333" ></td><td><a href="'+location.href+'">'+item.artist+'</a></td><td> <a href="'+location.href+'">'+item.title+'</a></td></tr>';
				result=result+'<tr style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'"><td><b>'+i+'</b></td><td>'+item.artist+'</td><td> '+item.title+'</td></tr>';
                //result=result.anchor('top');
                 //result=result+'<tr style="cursor:pointer; '+style_row+'" onclick="programar_cancion('+item.tid+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'"><td><img src="http://www.dedesparche.com/fuente.php?size=8&text=%20'+i+'%20&color=ffffff&bg=333333" ></td><td>'+item.artist+'</td><td> '+item.title+'</td></tr>';
                });
                 result=result+'</table>';
                }else{
                  result='No hay resultados';

                }
    jQuery('#program_resul').html(result);
    jQuery('#chat_loader').fadeOut("slow");
	jQuery('#tabs').tabs("select",1);
     result='';
            });

			
}

function programar_cancion(tid,a,t){
            var jurl='http://emisora.dedesparche.com/radio/program.php?prog='+tid+'&genid='+genid+'&user='+eluser+'&callback=?';
            var  notify='';
            var last_m='';
			if(!eluser){
			eluser='anonimo';
			}
            if(eluser){
            jQuery.getJSON(jurl,

             function(json) {

            // alert('adrentro');
            //res='<a href="javascript:actualizar_cancion2(xartist,xtitle,xtid);"><img height="50" src="'+json.u+'"></a>';
            //jQuery('#img_artista').html(res);
            //alert(json.h1);
            //alert(json.h8);
            if(json.h1=='0'){
                jQuery('#notificacion').html('Esta canci&oacute;n ya fue programada duranete la última hora, intenta con otra');
            }

            if(json.h8=='0'){
                jQuery('#notificacion').html(eluser+', esta canci&oacute;n ya la programaste en las ultima horas, intenta con otra');
            }

            if(json.h1=='1'){


             jQuery('#notificacion').html('<b>Canci&oacute;n Programada: '+t+' de '+a+'!!!</b>');

            }
			search_cancion(jQuery("#search").val());
            });

           


            actualizar_comentarios();
            }else{
                jQuery('#notificacion').html('<b>Para programar debes ingresar como usuario!</b>');
            }
}

function votar_cancion(tid,a,t){
            var jurl='http://emisora.dedesparche.com/radio/votar.php?prog='+tid+'&genid='+genid+'&user='+eluser+'&callback=?';
            var  notify='';
            var last_m='';
            if(eluser){
            jQuery.getJSON(jurl,

             function(json) {

            // alert('adrentro');
            //res='<a href="javascript:actualizar_cancion2(xartist,xtitle,xtid);"><img height="50" src="'+json.u+'"></a>';
            //jQuery('#img_artista').html(res);
            //alert(json.h1);
            //alert(json.h8);
            if(json.h1=='0'){
               // jQuery('#notificacion').html('Esta canci&oacute;n ya fue programada duranete la última hora, intenta con otra');
            }

            if(json.h8=='0'){
                jQuery('#notificacion').html(eluser+', esta canci&oacute;n ya la votaste en las ultima horas');
            }

            if(json.h8=='1'){


             jQuery('#notificacion').html('<b>Votaste por: '+t+' de '+a+'!!!</b>');

            }
            });




            actualizar_comentarios();
            }else{
                jQuery('#notificacion').html('<b>Para votar debes ingresar como usuario!</b>');
            }
}

function actualizar_top(){

            var top='';
            jQuery.getJSON('http://emisora.dedesparche.com/radio/top.php?gen='+gen+'&genid='+genid+'&callback=?',
            function(json) {
                jQuery.each(json.data, function(i,item){
                 top=top+'<li style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'">'+item.artist+' - '+item.title+'</li>';
                });
            jQuery('#top_list').html(top);

            });
}

function go_top(){

            var top='<ol>';
            jQuery.getJSON('http://emisora.dedesparche.com/radio/top.php?gen='+gen+'&genid='+genid+'&limit=100&callback=?',
            function(json) {
                jQuery.each(json.data, function(i,item){
                 top=top+'<li style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'">'+item.artist+' - '+item.title+'</li>';
                });
                top=top+'</ol>';
            jQuery('#top_list').html(top);

            });
}

function actualizar_pending(){

            var top='';
            jQuery.getJSON('http://emisora.dedesparche.com/radio/cola.php?genid='+genid+'&callback=?',
            function(json) {
                if(json.total>0){
                jQuery.each(json.data, function(i,item){
				
				if(item.user==undefined){
				top=top+'<li style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'">'+item.artist+' - '+item.title+'</li>';
				}else{
                 top=top+'<li style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'">'+item.artist+' - '+item.title+' por '+item.user+'</li>';
				 }
                });
                }else{
                    top='<b>No hay canciones programadas.</b>';
                }
            jQuery('#pending_list').html(top);

            });
}

function actualizar_last(){

             var t=new Date();
            var top='';
            var vote='...';
            var vote_split;
            var im=1;
            jQuery.getJSON('http://emisora.dedesparche.com/radio/last.php?genid='+genid+'&callback=?',
            function(json) {

                jQuery.each(json.data, function(i,item){
                    if(im==1){
                        jQuery('#last_song').html(item.artist+' - '+item.title);

                        actualizar_foto(item.artist);
                        
                        if(xtid==item.tid){
                        }else{
                        actualizar_cancion3(item.artist,item.title,item.tid);
                        }
                        xartist=item.artist;
                        xtitle=item.title;
                        xtid=item.tid;
						

                        
                         //if(item.tid){

                         //}
                    
                jQuery.get('/radio/leexml.php', {nd: t.getTime(), port: port}, function(data){
					if(data){
						//alert(xtitle);
								vote='<a href="javascript:votar_cancion('+"'"+xtid+"'"+','+"'"+xartist+"'"+','+"'"+xtitle+"'"+')">'+
									'<img src="http://www.dedesparche.com/fuente.php?size=8&text=%20Votar!%20&color=ff6600&bg=333333" ></a>'+
									'<a href="javascript:actualizar_cancion3('+"'"+xartist+"'"+','+"'"+xtitle+"',"+"'"+xtid+"'"+')"><img src="http://www.dedesparche.com/fuente.php?size=9&text=%20Letra%20&color=ffffff&bg=f5f5f5" ></a>';
								
								//TITULO BAR
								txt="deDesparche.com Radio |  "+data+ " .:. ";

								if(live==1){
								vote='<img src="http://www.dedesparche.com/fuente.php?size=8&text=%20en%20Vivo!%20&color=ff6600&bg=333333" >';
								txt+=xml_prog+" .:. ";
								}
						jQuery('#song_title').html(data+vote);

					}
                });
                    }
                 top=top+'<li style="cursor:pointer; '+style_row+'" onclick="actualizar_cancion('+"'"+item.artist+"','"+item.title+"','"+item.tid+"'"+');" onMouseOver="'+css_row_on+'" onMouseOut="'+css_row_out+'">'+item.artist+' - '+item.title+'</li>';

                im++;
            });

            jQuery('#last_songs').html(top);

            });

         	jQuery.get('leexml.php', {nd: t.getTime(), port: port, server: 1}, function(data){
            if(data){
				xml_prog=data;
                jQuery('#song_artist').html('<b>Escuchas:</b> <br>'+data);
                vote_split=data.split('EN VIVO');
                if(vote_split.length>1){
                    live=1;
                }else{
                    live=0;
                }
				
				
				
				
                vote_split=data.split('Susu');
                if(vote_split.length>1){
                    dj='susu';
                }else{
                    dj=0;
					vote_split=data.split('Arleth');
					if(vote_split.length>1){
					dj='Arleth';
					}
                }

            }
            });

}
function actualizar_foto(x){

var res='';
            jQuery.getJSON('http://mdigitalplus.com/json_artista_img.php?par='+x+'&callback=?',
            function(json) {

            if(live==0){
            res='<a href="javascript:actualizar_last();"><img height="50" src="'+json.u+'"></a>';
            }else if(dj=='susu'){
				
				res='<img height="50" src="/usuarios/2/portada_peq.jpg">';
			}else if(dj=='Arleth'){
				res='<img height="50" src="/radio/aire.jpg">';
			}else{

              res='<img height="50" src="/radio/aire.jpg">';

            }

            
            jQuery('#artimg').html(res);

            });
}
function actualizar_foto2(x){

var res='';
            jQuery.getJSON('http://mdigitalplus.com/json_artista_img.php?par='+x+'&callback=?',
            function(json) {
            res='<a href="javascript:actualizar_cancion2(xartist,xtitle,xtid);"><img height="50" src="'+json.u+'"></a>';
            jQuery('#img_artista_prog').html(res);

            });
}

function actualizar_foto3(x){

var res='';
            jQuery.getJSON('http://mdigitalplus.com/json_artista_img.php?par='+x+'&callback=?',
            function(json) {
            res='<a href="javascript:actualizar_cancion2(xartist,xtitle,xtid);"><img height="50" src="'+json.u+'"></a>';
            jQuery('#img_artista').html(res);

            });
}

function actualizar_cancion(a,t,tid){
//window.open('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?');
var res='';
last_a=a;
last_t=t;
//var link='<br><br><br><a href="javascript:programar_cancion('+"'"+tid+"'"+','+"'"+a+"'"+','+"'"+t+"'"+')"><img src="http://www.dedesparche.com/fuente.php?size=10&text=%20Programar%20Y%20Votar!%20&color=ffffff&bg=333333" ></a>';
var link='<br><br><br><a href="javascript:programar_cancion('+"'"+tid+"'"+','+"'"+a+"'"+','+"'"+t+"'"+')"><span style="font-size:20px; font-weight:bold;">Programar y/o Votar</span></a>';
            jQuery.getJSON('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?',
            function(json) {
                
                res+='<div id="img_artista_prog" align="left"></div>';
                if(json.num){
                    jQuery.each(json.data, function(i,item){
                        if(item.text!=''){
                        res+='<h2>'+a+': '+t+link+'</h2>'+item.text+'<br>'+item.video;
						}else{
							res+='<h2>'+a+': '+t+link+'</h2>Esta canción no tiene letra disponible...<br>'+item.video;
						}
                       
                    });
                }else{
                    res+='<h2>'+a+': '+t+link+'</h2>';
                }
                jQuery('#program_resul').html(res);
                actualizar_foto2(a);
				jQuery('#tabs').tabs("select",1);
            

            });
}

function actualizar_cancion2(a,t,tid){
//window.open('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?');
var res='';
var link='<br><br><br><a href="javascript:programar_cancion('+"'"+tid+"'"+','+"'"+a+"'"+','+"'"+t+"'"+')"><img src="http://www.dedesparche.com/fuente.php?size=10&text=%20Programar!%20&color=ffffff&bg=333333" ></a>';
            jQuery.getJSON('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?',
            function(json) {


                if(json.num){
                    jQuery.each(json.data, function(i,item){
                        if(item.text){
                            res+='<div id="img_artista" align="left"></div>';
                            res+='<h2>'+a+': '+t+link+'</h2>'+item.text+'<br>'+item.video;
                            jQuery('#info-music').html(res);
                            actualizar_foto2(a);
                        }else{
                            actualizar_comentarios();
                        }
                    });
                    
 
                       
                    
                }





            });
}

function actualizar_cancion3(a,t,tid){
//window.open('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?');
var res='';
last_a=a;
last_t=t;

//var link='<br><br><br><a href="javascript:programar_cancion('+"'"+tid+"'"+','+"'"+a+"'"+','+"'"+t+"'"+')"><img src="http://www.dedesparche.com/fuente.php?size=10&text=%20Programar%20Y%20Votar!%20&color=ffffff&bg=333333" ></a>';

var link='<br><br><br><a href="javascript:programar_cancion('+"'"+tid+"'"+','+"'"+a+"'"+','+"'"+t+"'"+')"><span style="font-size:20px; font-weight:bold;">Programar y/o Votar</span></a>';
            jQuery.getJSON('http://mdigitalplus.com/json_song.php?a='+a+'&t='+t+'&callback=?',
            function(json) {
                
                res+='<div id="img_artista" align="left"></div>';
                if(json.num){
                    jQuery.each(json.data, function(i,item){
                        if(item.text!=''){
                        res+='<h2>'+a+': '+t+'</h2>'+item.text+'<br>'+item.video;
						if(genid==3){
							jQuery('#tabs').tabs("select",4);
						}else{
							jQuery('#tabs').tabs("select",5);
						}
						}else{
							res+='<h2>'+a+': '+t+'</h2>Esta canci&oacute;n no tiene letra disponible...<br>'+item.video;
						}
                       
                    });
                }else{
                    res+='<b>Escuchas: </b><br><h2>'+a+': '+t+'</h2>Esta canci&oacute;n no tiene letra disponible...<br>';
                }
                jQuery('#info-music').html(res);
                actualizar_foto3(a);
				
            

            });
}



var refresco=null;

function titulo() {
	document.title=txt;
	txt=txt.substring(1,txt.length)+txt.charAt(0); 
	refresco=setTimeout("titulo()",300);
}
titulo();
// -->
