var Pressed=0;
var Maximized=0;
var isOut=0;
var intId = 0;
var currentPlayer;
function maximizeChat()
{   
    if(Maximized==0)
    {
        Maximized=1;
        var Cht=document.getElementById('Chat');
        Cht.style.left=0;
        Cht.style.top=0;
        Cht.style.width=document.body.clientWidth;
        Cht.style.height=document.body.clientHeight;
        var MoveDv=document.getElementById('Move');
        MoveDv.onmousedown='';
        var FrameChatDv=document.getElementById('FrameChat');
        FrameChatDv.style.width=document.body.clientWidth;
        FrameChatDv.style.height=document.body.clientHeight;
    }
    else
    {
        Maximized=0;
        var Cht=document.getElementById('Chat');
        Cht.style.width=300;
        Cht.style.height=300;
        var MoveDv=document.getElementById('Move');
        MoveDv.onmousedown=startMove;
        var FrameChatDv=document.getElementById('FrameChat');
        FrameChatDv.style.width=300;
        FrameChatDv.style.height=300;
    }
    
}

function CloseChat()
{
 var Cht=document.getElementById('Chat');
 Cht.style.visibility='hidden';


}



function startMove()
{   

 isOut=1;
 Pressed=1;
 
  var Cht=document.getElementById('Chat');
  var ChtWnd=document.getElementById('chatWindow');
  
 Cht.onmouseout=MouseSetInterval;
 Cht.onmouseover=function(){isOut=1;};
 
 document.onmousemove=CheckMove;
 
 window.onmouseup=checkPressed;
 window.onmouseout=checkPressed;
 document.onmouseup=checkPressed;
 Cht.style.filter = "alpha(opacity=70);"; 
 ChtWnd.onmouseup=StopChat;
 
}


function MouseSetInterval()
{   
    if(Pressed==1)
    {
        isOut=0;
        intId=setTimeout('isMouseOut()',3000)
    }
}

function isMouseOut()
{   

    if(isOut==0)
    {
     StopChat();
    }
}






function checkPressed()
{
    if(Pressed==1)
    {
    Pressed=0;
    isOut=0;
    }
}

function StopChat()
{   
    Pressed=0;
    isOut=0;
    var Cht=document.getElementById('Chat');
	Cht.style.filter = "alpha(opacity=100);";
    Cht.onmouseout='';
    Cht.onmouseover='';
}

function CheckMove()
{   
    var Cht=document.getElementById('Chat');
    var scrollTopValue=0;
    var scrollLeftValue=0;
    
    if(event.clientX + 320 <= document.body.clientWidth && event.clientX  >20)
    {
        if(Pressed==1)
        {
            if(document.body.scrollLeft>0)
            {
                scrollLeftValue=document.body.scrollLeft;
            }
            Cht.style.left=event.clientX-10+scrollLeftValue;
        }
    }
    else
    {
    
    }
    
    if( event.clientY + 320 <= document.body.clientHeight && event.clientY  >20)
    {
        if(Pressed==1)
        {   
            if(document.body.scrollTop>0)
            {
                scrollTopValue=document.body.scrollTop;
            }
            Cht.style.top=event.clientY-10+scrollTopValue;

        }
    }
    
   return false;
    
}

function OpenChat(value)
{
    var chat=document.getElementById("chatWindow");
    chat.innerHTML='<iframe id="FrameChat" src="'+value+'" width=300 height=300 border="0" frameborder="0" y framespacing="0"></iframe>';
   var ChatDv=document.getElementById("Chat");
    ChatDv.style.visibility='visible';
    ChatDv.style.zIndex=100;
    chat.onmouseover=checkPressed;
     
}

function onTimeout()
{
return false;
}

function LoadVideos(idCanal)
{
    LoadingDiv("grid");
    Master_MasterPage.LoadVideos(idCanal,LoadVideos_Callback);
}

function LoadVideosAuto()
{       
    
    if('<%Response.Write(Param); %>'!='Private')
    {
     if('<%Response.Write(Param); %>'!='Valid' &&'<%Response.Write(Param); %>'!='')
     {
        inicio('<%Response.Write(Param); %>');
     }
      else
    {
    LoadingDiv("grid");
    Master_MasterPage.LoadVideosU(LoadVideos_Callback);
    LoadingDiv("canales");
    Master_MasterPage.LoadChannels(LoadChannels_Callback);
    }
     
 }
 else
 {
    if('<%Response.Write(Param); %>'=='Private')
    {
      var gridVideos=document.getElementById("grid");
      gridVideos.innerHTML="<p><span class=\'Trans\'>Esta intentando acceder a un video privado o que no existe.<br /><br />Si es usuario registrado identifiquese <a href=\"#\" onclick='PrintLoginControl()'>aquí</a></span></p>";
    }
    else
    {
    LoadingDiv("grid");
    Master_MasterPage.LoadVideosU(LoadVideos_Callback);
    LoadingDiv("canales");
    Master_MasterPage.LoadChannels(LoadChannels_Callback);
    }
 }
 
    
}

function LoadVideos_Callback(response)
{
    if(response.error!=null)
    {}
    else
    { var gridVideos=document.getElementById("grid");
      gridVideos.innerHTML=response.value;}
}
function SearchVideo()
{
 var SearcherT=document.getElementById("Searcher")
    if(SearcherT.value!="")
    {
         LoadingDiv("grid");
         Master_MasterPage.SearchVideo(SearcherT.value,SearchVideo_Callback);
    }
    else
    {
         SearcherT.value="Introduzca un criterio";
    }
}

function SearchVideo_Callback(response)
{
    if(response.error!=null)
    {}
    else
    { var gridVideos=document.getElementById("grid");
      gridVideos.innerHTML="" +response.value;+""}
}

function CloseSession()
{



LoadingDiv("grid");
LoadingDiv("canales");
Master_MasterPage.CloseSession(CloseSession_Callback);
}


function CloseSession_Callback(response)
{
	document.location.href = "http://www.febtv.com/default.aspx?Log=1"

    var gridVideos=document.getElementById("grid");
    LoadingDiv("grid");
    Master_MasterPage.LoadVideosU(LoadVideos_Callback);
             
    var gridcanales=document.getElementById("canales");
    LoadingDiv("canales");
    Master_MasterPage.LoadChannels(LoadChannels_Callback);
}

function inicio (urlVideo)
{   
  if(urlVideo!='<%Response.Write(Param); %>')
  {

        LoadingDiv("infoVideo");
       Master_MasterPage.getInfoVideo(urlVideo,getInfoVideo_callback);
       Master_MasterPage.TitleVideo_Div(urlVideo,TitleVideo_Div_callback);
       
        if(ValidateVideo(urlVideo)=='false')
        {
             return false;
        }

    
            var cnt = document.getElementById("container");
            var src = '/resources/wmvplayer.xaml';
            var cfg = {
                file: urlVideo,
                autostart: 'true',
                image:'/images/default_imge.gif',
                height: '320',
                width: '399',
				backcolor:'#A6A6A6',
                 overstretch: 'fit', shownavigation: 'true', showdigits: 'false', autostart: 'true', linkfromdisplay: 'false', repeat: 'true' 
            }


            var ply = new jeroenwijering.Player(cnt, src, cfg);
           // ply.addListener('STATE',stateChange);
            currentPlayer = ply;
			
			       
		
        
    }
}

function stateChange(oldState,newState) { 

}
function playPlayer() {
	if(currentPlayer != undefined)
	{
    currentPlayer.sendEvent('PLAY');
    $('#container').show();
    hideImages();
	}
}

function pausePlayer() {
	if(currentPlayer != undefined)
	{
    currentPlayer.sendEvent('STOP');
    showImages();
	}
}

function fullScreen() {
	if(currentPlayer != undefined)
	{
    currentPlayer.sendEvent('FULLSCREEN');
	}
}


function stopPlayer() {
	if(currentPlayer != undefined)
	{
    currentPlayer.sendEvent('STOP');
  
    showImages();
	}
}

function showImages() {
    $('#video_cortinilla').show();
    $('#videos_images').css('position', 'relative');
}

function hideImages() {
    $('#video_cortinilla').hide();
    $('#videos_images').css('position', 'absolute');
}


function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}





function TitleVideo_Div_callback(response) {
    document.getElementById("video_display_title").innerHTML = response.value;
}
function getInfoVideo_callback(response) {
    var info = document.getElementById("infoVideo");
    info.innerHTML = response.value;
}

function ValidateVideo(urlVideo)
{   

    Master_MasterPage.ValidateVideo(urlVideo,ValidateVideo_callback);

}


function ValidateVideo_callback(response)
{   

    if(response.value=="ok")
    {
        return('true');
    }
    else
    {   
        video_loading.style.visibility='hidden';
        video_error.style.visibility='visible';
        return('false');
    }
}

function PrintSearcher()
{
Master_MasterPage.PrintSearcher(PrintSearcher_Callback);
}
function PrintSearcher_Callback(response)
{
      var gridVideos=document.getElementById("grid");
      gridVideos.innerHTML=response.value;
}

function PrintLoginControl()
{
     Master_MasterPage.PrintLoginControl(PrintLoginControl_Callback);
      
}
function PrintLoginControl_Callback(response)
{
      var gridVideos=document.getElementById("grid");
      gridVideos.innerHTML=response.value;
      
}
function LoginUser()
{     
      var user=document.getElementById("user");
      var pass=document.getElementById("pass");
      LoadingDiv("grid");
      
      Master_MasterPage.LoginUser(user.value,pass.value,LoginUser_Callback);
      
}

function LoadingDiv(name)
{
 var gridVideos=document.getElementById(name);
 gridVideos.innerHTML="<p id='LoadingDiv'><span class=\'Trans\'>Cargando...</span></p>";
}

function ShowSendMail()
{
Master_MasterPage.PrintMailControl(ShowSendMail_Callback);
}

function ShowSendMail_Callback(response)
{

var gridVideos=document.getElementById("grid");
gridVideos.innerHTML=response.value;
}

function SendMail()
{     
      var Name=document.getElementById("Myname");
      var Mail=document.getElementById("FriendMail");
      LoadingDiv("grid");
      Master_MasterPage.SendMail(Name.value,Mail.value,document.getElementById("Player").URL,SendMail_Callback);
}

function SendMail_Callback(response)
{   HiddenDiv("grid");
    var gridVideos=document.getElementById("grid");
    gridVideos.innerHTML=response.value;
}

function HiddenDiv(name)
{
 var gridVideos=document.getElementById(name);
 gridVideos.innerHTML="";
}

function LoginUser_Callback(response)
{     
        HiddenDiv("grid");
      if(response.value==null)
      { 
       

         var gridVideos=document.getElementById("grid");
         LoadingDiv("grid");
         Master_MasterPage.LoadVideosU(LoadVideos_Callback);
         
         var gridcanales=document.getElementById("canales");
         LoadingDiv("canales");
         Master_MasterPage.LoadChannels(LoadChannels_Callback);

		  var comboEquipos=document.getElementById("equipos_combo");
         Master_MasterPage.LoadEquipos(LoadEquipos_Callback);
         
         showSearchBox();
         
      }
      else
      {     
        
         var gridVideos=document.getElementById("grid");
         gridVideos.innerHTML=response.value;
      }
      
}
function LoadVideos_Callback(response)
{      
      
        var gridVideos=document.getElementById("grid");
        gridVideos.innerHTML=response.value;
}
function LoadChannels_Callback(response)
{        
        
        var gridcanales=document.getElementById("canales");
        gridcanales.innerHTML=response.value;
}


function LoadEquipos_Callback(response)
{        
       
        var gridcanales=document.getElementById("equipos_combo");
        gridcanales.innerHTML=response.value;
        
        
}



function LoadPartidos_Date(dateValue)
{           
         
          Master_MasterPage.LoadPartidosByDate(dateValue,LoadVideos_Callback);
}

function LoadVideosFromCode(code)
{   
    
    Master_MasterPage.LoadVideos_FromCode(code,LoadVideos_Callback);
}


function showSearchBox()
{
    $("#date_partidos").css({ display:"block"});
    Master_MasterPage.LoadEquipos(LoadEquipos_Callback);
  

}





