///////////////////////////////////////POP-UP FUNCTIONS///////////////////////////////////////////////


/////////////////////////////////////////////CONCURSO VÍDEOS//////////////////////////////////////////

//función q abre pop-up con las bases del concurso
function muestra_bases(){

    var ventana =  window.open('bases.jsp','bases','top=0,left=0,width=530,height=400,status=yes,scrollbars=yes');
}

//función q abre pop-up con las condiciones del concurso
function muestra_condiciones(){

    var ventana =  window.open('condiciones.jsp','condiciones','top=0,left=0,width=720,height=400,status=yes,scrollbars=yes');
}

//función q abre pop-up del upload de vídeo
function upload_video(){
    
    //llamada a google analythics
    urchinTracker("/upload_vídeo"); 
    
    ventana =  window.open('./pop-ups/upload.jsp','tonos','left=0,top=0,width=395,height=552,status=yes');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////BARRA LEGAL////////////////////////////////////////////

//función q abre pop-up 
function muestra_directa(){
    
    ventana =  window.open('./pop-ups/directa.jsp','directa','left=0,top=0,width=386,height=340,status=yes');
}

//función q abre pop-up con la clausula de privacidad
function muestra_clausula(type){
    
    if(type != null ) var ventana =  window.open('./pop-ups/politica.jsp','clausula','left=0,top=0,width=386,height=285,status=yes');
    else var ventana =  window.open('clausula.jsp','clausula','left=0,top=0,width=386,height=285,status=yes');
}


//función q abre pop-up 
function muestra_contacto(){
    
    ventana =  window.open('./pop-ups/contacto.jsp','contacto','left=0,top=0,width=386,height=320,status=yes');
}

//función q envia el mail 
function envia_mail_contacto(){
    
    div=1;

    var receiver = "directatv@gmail.com";

    var sender = document.getElementById("email").value;
    
    var subject = "CONTACTO: "+document.getElementById("nombre").value; 
   
    var body = "T^i^tulo: "+encode_text(document.getElementById("titulo").value)+"<br><br>Comentario: "+encode_text(document.getElementById("comentario").value);
    
    if(document.getElementById("email").value.split("@").length <= 1 || document.getElementById("email").value.split(".").length <= 1) alert("Debes introducir un email valido para continuar!");
    else{
        if(document.getElementById("nombre").value == "") alert("Debes introducir un nombre!");
        else{
    
            setTimeout("mail_enviado(\"contacto\");",1000);
            
            //alert("Enviando mail --> Sender: "+sender+" receiver: "+receiver+" subject: "+subject+" body: "+body);
            refresco = Math.round(Math.random()*10000);
            http.open("GET","../send_mail?refresco="+refresco+"&tipo=contacto&sender="+sender+"&receiver="+receiver+"&subject="+subject+"&body="+body, true); 
            http.onreadystatechange = handleHttpResponse; 
            http.send(null);
        
        }
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//función q abre pop-up tonos
function muestra_tonos(type){
    
    //llamada a google analythics
    urchinTracker("/descarga_móviles-->" + type); 
    
    //jsp q cargaremos
    var jsp;
    if(type == 0){ params = 'top=0,left=0,width=386,height=611,status=no'; jsp='./pop-up/tonos_pamplonesa.jsp'; }
    if(type == 1){ params = 'top=0,left=0,width=531,height=521,status=no'; jsp='./pop-ups/tonos_ferminmusic.jsp'; }
    
    ventana =  window.open(jsp,'tonos',params);
}

///////////////////////////////////////////////////////ENVIAR AMIGO////////////////////////////////////////////////////////

//función q abre el popup de enviar a un amigo
function enviar_amigo(){
    
    //alert(titles[current]);
    
    //llamada a google analythics
    urchinTracker("/enviar_amigo-->"+titles[current]); 
    
    var ventana =  window.open("./pop-ups/amigo.jsp?id_channel="+current_channel+"&id_element="+playing_element+"&id_playlist="+playlists_id[playing_playlist]+"&title="+encode_text(titles[current]),'amigo','width=403,height=235,scrollbars=yes,status=yes');
}

//función q envia el mail 
function envia_mail_amigo(chan,play,ele,tit){
    
    div=1;
    
    var receiver = document.getElementById("receiver").value;
    var sender = document.getElementById("sender").value;
    if(sender == "") 
        sender = "videos@directa.tv";
    var name = encode_text(document.getElementById("nombre").value);
    var subject = name + " te recomienda este v^i^deo"; 
    
    var jsp;
    
    if(chan == 1) jsp="anterior.jsp";
    if(chan == 2) jsp="musica.jsp";
    if(chan == 3) jsp="zapping.jsp";
    if(chan == 5) jsp="sanfermines.jsp";
    if(chan == 7) jsp="tus_videos.jsp";
    if(chan == 8) jsp="index.jsp";
    
    var link = "<a href='http://www.directa.tv/latelequeteve/"+jsp+"?id_e="+ele+"[]id_p="+play+"'>";
    
    //var link="<a href='"+window.opener.location+"?id_e="+ele+"[]id_p="+play+"'>";
    
    var body = link+"Haz click aqu^i^ para ver el v^i^deo</a><br><br>"+encode_text(document.getElementById("mensaje").value);
    
    if(document.getElementById("acepta").checked == false) alert("Debes aceptar la clausula de privacidad para continuar!");
    else if(receiver.split("@").length <= 1 || receiver.split(".").length <= 1) alert("Debes introducir un email valido!");
    else{
        if(document.getElementById("nombre").value == "") alert("Debes introducir un nombre!");
        else{
            
            setTimeout("mail_enviado(\"amigo\");",1000);
            
            //alert("Enviando mail --> Sender: "+sender+" receiver: "+receiver+" subject: "+subject+" body: "+body);
            refresco = Math.round(Math.random()*10000);
            http.open("GET","../send_mail?refresco="+refresco+"&tipo=amigo&sender="+sender+"&receiver="+receiver+"&subject="+subject+"&body="+body+"&name="+name+"&title="+tit+"&id_element="+ele, true); 
            http.onreadystatechange = handleHttpResponse; 
            http.send(null);
        }
    }
}

//funcion q muestra una imagen en funcion del mail enviado
function mail_enviado(tipo){
    
    if(tipo == "amigo"){
        document.getElementById("formulario").innerHTML="";
        document.getElementById("fondo").innerHTML="<img src='http://media.directa.tv/images_web/fondo_enviado.gif'>";
        setTimeout("window.close();",3000);
    }
    
    if(tipo == "contacto"){
        document.getElementById("formulario3").innerHTML="";
        document.getElementById("fondo").innerHTML="<img src='http://media.directa.tv/images_web/contacto_enviado.gif'>";
        setTimeout("window.close();",3000);
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////VALORACIÓN VÍDEO///////////////////////////////////////////////////////////

//función q abre pop-up con la valoracion
function valoracion(){

    //llamada a google analythics
    urchinTracker("/valoracion -->"+titles[current]);
    
    var ventana =  window.open("./pop-ups/valoracion.jsp?id_element="+playing_element+"&id_playlist="+playlists_id[playing_playlist],'clausula','width=386,height=285,status=yes');
}

//función q obtiene la valoración de un elemento de BD
function get_valoration(id_e,id_p){
    
    div=1;
    
    //alert("Guardando valoracion --> valoracion: "+valoracion_actual);
    refresco = Math.round(Math.random()*10000);
    http.open("GET","../DB_management?refresco="+refresco+"&operation=get_valoration&id_element="+id_e+"&id_playlist="+id_p, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null);
    
}

//función q muestra la valoración/votos de un elemento
function set_valoration(val,vot){
    
    document.getElementById("valoration").innerHTML="VALORACI&Oacute;N MEDIA&nbsp;&nbsp;<img src='http://media.directa.tv/images_web/stars"+val+".gif'>&nbsp;&nbsp;("+vot+" valoraciones)";
}

//función q guarda la valoracion en BD
function add_valoration(id_e,id_p){
    
    div=1;
    
    var valoracion_actual=0;
    
    if(document.getElementById("valoracion5").checked == true) valoracion_actual=5;
    if(document.getElementById("valoracion4").checked == true) valoracion_actual=4;
    if(document.getElementById("valoracion3").checked == true) valoracion_actual=3;
    if(document.getElementById("valoracion2").checked == true) valoracion_actual=2;
    if(document.getElementById("valoracion1").checked == true) valoracion_actual=1;
   
    //alert("Guardando valoracion --> valoracion: "+valoracion_actual);
    refresco = Math.round(Math.random()*10000);
    http.open("GET","../DB_management?refresco="+refresco+"&operation=add_valoration&id_element="+id_e+"&id_playlist="+id_p+"&valoration="+valoracion_actual, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null);
    
}

//funcion q muestra una imagen de valoración enviada
function valoration_ok(id_e,id_p){
    
    document.getElementById("formulario").innerHTML="";
    document.getElementById("fondo").innerHTML="<img src='http://media.directa.tv/images_web/fondo_valorado.gif'>";
    setTimeout("window.close();",3000);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////COMENTARIOS////////////////////////////////////////////////////

//función q abre el popup con los comentarios del video
function ver_comentarios(type){
    
    if(type == "video"){
        //llamada a google analythics
        urchinTracker("/ver_comentarios -->"+titles[current]);
        var ventana =  window.open("./pop-ups/comments.jsp?id_element="+playing_element,'comments','width=403,height=273,scrollbars=yes,status=yes');
    }
    
    if(type == "station"){
        //llamada a google analythics
        urchinTracker("/opina");
        var ventana =  window.open("./pop-ups/comments_station.jsp?id_station=1",'comments','width=403,height=273,scrollbars=yes,status=yes');
    }
}

//función q carga los comentarios de la station o de un video
function load_comments(type,id){
    
    div=1;
    
    refresco = Math.round(Math.random()*10000);
    http.open("GET","../DB_management?refresco="+refresco+"&operation=load_comments&type="+type+"&id="+id, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null);
    
}

//función q guarda un comentario de la station o de un video
function save_comment(type,id){
    
    div=1;
    
    var user="";
    var comment=null;
    
    if(document.getElementById("comentario").value != "") comment=document.getElementById("comentario").value;
    user=encode_text(document.getElementById("usuario").value);
   
    //alert("Guardando comentario --> comentario: "+comment+" usuario: "+user);
    refresco = Math.round(Math.random()*10000);
    http.open("GET","../DB_management?refresco="+refresco+"&operation=save_comment&type="+type+"&id="+id+"&text="+encode_text(comment)+"&user="+user, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null);
    
}

//funcion q muestra una imagen en funcion del mail enviado
function comment_ok(){
    
    document.getElementById("formulario").innerHTML="";
    document.getElementById("fondo").innerHTML="<img src='http://media.directa.tv/images_web/fondo_anadido.gif'>";
    setTimeout("window.close();",3000);
}

//función q carga comentarios de la station
function load_station_comments(id_s){
    
    div=1;
    
    refresco = Math.round(Math.random()*10000);
    http.open("GET","../DB_management?refresco="+refresco+"&operation=load_station_comments&id_station="+id_s, true); 
    http.onreadystatechange = handleHttpResponse; 
    http.send(null);
    
}

//funcion q muestra una imagen en funcion del mail enviado
function station_comment_ok(){
    
    document.getElementById("formulario").innerHTML="";
    document.getElementById("fondo").innerHTML="<img src='http://media.directa.tv/images_web/opinion_anadida.gif'>";
    setTimeout("window.close();",3000);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
