﻿

var AxAddVideoToPlayList = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(SecurityKey,NewPlayList,IdPlayList,IdVideo,MemberId,NomPlayList,CommentVideo);
	},
	call: proxies.AjaxFunc.AddVideoToPlaylist,
	finish: function (p) 
	{ 
		if (p != "KO")
		{
			alert("La vidéo a été rajoutée à votre playlist");
			HideAddToPlayList();
			if (NewPlayList == "TRUE")
				appendToList(document.frm_detail.lst_playlist,NomPlayList,p)
		}
		else
			alert("La vidéo existe déjà dans la playlist sélectionnée");
			
			
	},
	onException: ajax.alertException
}

var AxAddPlaylistToFavoris = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(SecurityKey,IdPlayList,MemberId);
	},
	call: proxies.AjaxFunc.AddPlaylistToFavoris,
	finish: function (p) 
	{ 
		document.getElementById("Favoris").innerHTML = "<img border='0' src='/images/favoris_off.gif'><span class='ActionText disable'>Vous êtes abonnés à cette playlist.</span>";
	},
	onException: ajax.alertException
}

var AxGetInfoVideoFromPlayList = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(IdPlayList,IdVideo);
	},
	call: proxies.AjaxFunc.GetInfoVideoFromPlayList,
	finish: function (p) 
	{ 
		
		ReturnLaunchVideo(p);
	},
	onException: ajax.alertException
}


var AxGetListePlaylistByUsager = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(MemberId);
	},
	call: proxies.AjaxFunc.GetListePlaylistByUsager,
	finish: function (p) 
	{ 
		
		
		var ComboDest = document.getElementById("lst_playlist");
		
		ComboDest.options.length = 0;
		var Item = new Option("Choisissez une playlist", "", false, false);
		ComboDest.options[0] = Item;
		
		if (p != "NO")
		{
			var LstPl = p.split("|MPMR|");
			
			for (var i=0; i<LstPl.length; i++) {
				
				if (LstPl[i] != "")
				{
					var APlayList = LstPl[i].split("|MPMF|"); 
					if (APlayList[0] != "")
					{				
						var j = i +1;
						Item = new Option(APlayList[1], APlayList[0], false, false);
						ComboDest.options[j] = Item;	
					}
				}
			}
		}
			
	},
	onException: ajax.alertException
}


function AddToPlayList()
{
	
	if (NoMember)
	{
		
		IdDivToDisplay = "AddToPlayList";
		var target = $('Resume');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -415});
		
		
		target = $('ActionsLogin');
		$('ActionsLogin').style.display = "inline";
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -410});
		
	}
	else
	{
		var target = $('Resume');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -415});
		
		target = $('AddToPlayList');
		$('AddToPlayList').style.display = "inline";
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -410});
		GetListePlaylistByUsager();
		document.frm_detail.lst_playlist.selectedIndex = 0;
		document.frm_detail.nom_playlist.value = "";
	}
	
	
	
}


function ExecAddToPlayList()
{
	NewPlayList = "FALSE";
	NomPlayList = document.frm_detail.nom_playlist.value;
	CommentVideo = document.frm_detail.comment_video.value;
	IdPlayList = document.frm_detail.lst_playlist.options[document.frm_detail.lst_playlist.selectedIndex].value;
	if (NomPlayList == "" && IdPlayList == "")
	{
		alert("Vous devez choisir une playlist ou en créer une nouvelle");
		return false;
	}
	if (NomPlayList != "")
		NewPlayList = "TRUE";
	SoapMethod = "POST";
	ajax.Start(AxAddVideoToPlayList);
}

function HideAddToPlayList()
{
	var target = $('Resume');
	
	var fx = new Fx.Styles(target, {duration: 1000, wait: false});
	fx.options.transition = Fx.Transitions['Expo']['easeOut'];
	fx.options.duration = 1000;
	
	fx.start({'left': 0});
	
	
	target = $('AddToPlayList');
	$('AddToPlayList').style.display = "none";
	fx = new Fx.Styles(target, {duration: 1000, wait: false});
	fx.options.transition = Fx.Transitions['Expo']['easeOut'];
	fx.options.duration = 1000;
	fx.start({'left': 0});
}


function appendToList(theSel, newText, newValue)
{
  if (theSel.length == 0) {
    var newOpt1 = new Option(newText, newValue);
    theSel.options[0] = newOpt1;
    theSel.selectedIndex = 0;
  } else if (theSel.selectedIndex != -1) {
    var selText = new Array();
    var selValues = new Array();
    var selIsSel = new Array();
    var newCount = -1;
    var newSelected = -1;
    var i;
    for(i=0; i<theSel.length; i++)
    {
      newCount++;
      selText[newCount] = theSel.options[i].text;
      selValues[newCount] = theSel.options[i].value;
      selIsSel[newCount] = theSel.options[i].selected;
      
      if (newCount == theSel.selectedIndex) {
        newCount++;
        selText[newCount] = newText;
        selValues[newCount] = newValue;
        selIsSel[newCount] = false;
        newSelected = newCount - 1;
      }
    }
    for(i=0; i<=newCount; i++)
    {
      var newOpt = new Option(selText[i], selValues[i]);
      theSel.options[i] = newOpt;
      theSel.options[i].selected = selIsSel[i];
    }
  }
}

function LaunchVideo(AutoStart,SelectedVideo)
{
	
	document.getElementById("PubOnPlayer").style.display = "none";
	document.getElementById("player1").style.display = "";
	document.getElementById("Video" + SelectedVideo).style.backgroundColor  = "#FCD0EB";
	if (LastSelected != "")
		document.getElementById("Video" + LastSelected).style.backgroundColor  = "#FFFFFF";
	
	LastSelected = SelectedVideo;
	AutoPlay = AutoStart;
	IdVideo = SelectedVideo;
	
	SoapMethod = "POST";
	ajax.Start(AxGetInfoVideoFromPlayList);
}

function ReturnLaunchVideo(Infos)
{
	
	var tableau = Infos.split("||");
	document.getElementById("CommentVideo").innerHTML = "";
	/*
	var FU = { 	movie:"/flash/flvplayer3.1.swf",
						width:"440",
						height:"340",
						quality:"high",
						wmode:"transparent",
						majorversion:"8",
						build:"0",
						bgcolor:"#FFFFFF",
						flashvars:"file=" + tableau[2] + "&type=flv&autostart=" + AutoPlay + "&usefullscreen=false&logo=/images/logoplayer.png&bufferlength=4&streamscript=lighttpd" };
	*/
	
	var FU = { 	movie:"/flash/mpmplayer1.1.swf",
						width:"440",
						height:"340",
						quality:"high",
						allowfullscreen:"true",
						majorversion:"8",
						build:"0",
						flashvars:"largeur=440&hauteur=340&adr=" + tableau[2] + "&allowscriptaccess=true&bufferlength=6&autostart=" + AutoPlay};
	
	UFO.create(	FU, "player1");
	document.getElementById("PlusInfos").style.visibility = "";
	document.getElementById("LinkVideo").href = "/video/" + tableau[3];
	document.getElementById("TitreVideo").innerHTML = tableau[0];
	/*
	if (tableau[1] != "")
		document.getElementById("CommentVideo").innerHTML = "<b>Commentaire de l'auteur de la playlist: </b>" + tableau[1];
	*/
	
}

function AddToFavoris()
{
		
	if (NoMember)
	{
		
		IdDivToDisplay = "Resume";
		PosDivToDisplay = 0;
		var target = $('Resume');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -268});
		
		
		target = $('ActionsLogin');
		$('ActionsLogin').style.display = "inline";
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -268});
		
	}
	else
	{
		SoapMethod = "POST";
		ajax.Start(AxAddPlaylistToFavoris);
	}
	
}

function GetListePlaylistByUsager()
{
	SoapMethod = "POST";
	ajax.Start(AxGetListePlaylistByUsager);
}

function HideAddToFavorisNoMember()
{
	document.getElementById("DivDisable").style.visibility = "hidden";
	document.getElementById("AddToFavorisNoMember").style.visibility = "hidden";
}




