﻿var AxIsAlwaysMember = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(document.getElementById("txt_mail").value);
	},
	call: proxies.AjaxFunc.IsAlwaysMember,
	finish: function (p) 
	{ 
		if (p == "YES")
			DisplayError("un compte existe déjà avec cette adresse mail.");
		else
		{
			SoapMethod = "POST";
			ajax.Start(AxCreateMember);
		}
			
	},
	onException: ajax.alertException
}

var AxIsMember = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(document.getElementById("txt_mail").value,document.getElementById("txt_password").value);
	},
	call: proxies.AjaxFunc.IsMember,
	finish: function (p) 
	{ 
		if (p == "KO")
			DisplayError("il n'existe aucun compte avec ces informations.");
		else
		{
			var tableau = p.split("|");
			MemberId = tableau[0];
			SecurityKey = tableau[3];
			SetCookie("MPMADAUTH","NUMUSAGER=" + tableau[0] + "&PSEUDO=" +  tableau[1] + "&KEY=" +  tableau[2],30);
			NoMember = false;
			var target = $('CmLogin');
			var fx = new Fx.Styles(target, {duration: 1000, wait: false});
			fx.options.transition = Fx.Transitions['Expo']['easeOut'];
			fx.options.duration = 1000;
			fx.start({'left': -1318});
			
			target = $('CmPost');
			fx = new Fx.Styles(target, {duration: 1000, wait: false});
			fx.options.transition = Fx.Transitions['Expo']['easeOut'];
			fx.options.duration = 1000;
			fx.start({'left': -1318});
			
			if (ExecGetListePlaylistByUsager)
				GetListePlaylistByUsager();
		}
			
	},
	onException: ajax.alertException
}


var AxCreateMember = {
	delay: 200,
	prepare: function() {
		var sexe = "M";
		if (document.getElementById("rdb_feminin").checked)
			sexe = "F";
		InputVar = new Array(document.getElementById("txt_mail").value,document.getElementById("txt_pseudo").value,sexe,document.getElementById("txt_password").value);
	},
	call: proxies.AjaxFunc.CreateMember,
	finish: function (p) 
	{ 
		var tableau = p.split("|");
		MemberId = tableau[0];
		SecurityKey = tableau[3];
		SetCookie("MPMADAUTH","NUMUSAGER=" + tableau[0] + "&PSEUDO=" +  tableau[1] + "&KEY=" +  tableau[2],30);
		NoMember = false;
		var target = $('CmLogin');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -1318});
		
		target = $('CmPost');
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -1318});
		
		if (ExecGetListePlaylistByUsager)
			GetListePlaylistByUsager();
	
	},
	onException: ajax.alertException
}

var AxAddCommentVideo = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(IdVideo,MemberId,document.getElementById("txt_comment").value);
	},
	call: proxies.AjaxFunc.AddCommentVideo,
	finish: function (p) 
	{ 
		DisplayComments("1");
		ShowComments();	
	},
	onException: ajax.alertException
}


function ShowAddComment()
{
	if (NoMember)
	{
		
		var target = $('CmLogin');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -659});
		
		
		target = $('CmContenu');
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -665});
		
	}
	else
	{
		var target = $('CmContenu');
		var fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -665});
		
		target = $('CmPost');
		fx = new Fx.Styles(target, {duration: 1000, wait: false});
		fx.options.transition = Fx.Transitions['Expo']['easeOut'];
		fx.options.duration = 1000;
		fx.start({'left': -1318});
	}
}

function DisplayError(aError)
{
	document.getElementById('log_erreur').innerHTML = aError;	
}

function ShowChampsInscr()
{
	document.getElementById('log_pseudo').style.display = '';
	document.getElementById('log_sexe').style.display = '';
}


function HideChampsInscr()
{
	document.getElementById('log_pseudo').style.display = 'none';
	document.getElementById('log_sexe').style.display = 'none';
}

function ExecLogin()
{
	
	if (document.getElementById("txt_mail").value == "")
	{
		DisplayError("le champs e-mail est obligatoire.")	
		return true;
	}
	
	if (document.getElementById("txt_password").value == "")
	{
		DisplayError("le champs mot de passe est obligatoire.")	
		return true;
	}
			
	if (document.getElementById('rdb_no_member').checked)
	{
		
		if (document.getElementById("txt_pseudo").value == "")
		{
			DisplayError("le champs pseudo est obligatoire.")	
			return true;
		}
		
		SoapMethod = "POST";
		ajax.Start(AxIsAlwaysMember);	
	}
	else
	{
		SoapMethod = "POST";
		ajax.Start(AxIsMember);
	}

}

function ShowComments()
{
	var target = $('CmLogin');
	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 = $('CmPost');
	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 = $('CmContenu');
	fx = new Fx.Styles(target, {duration: 1000, wait: false});
	fx.options.transition = Fx.Transitions['Expo']['easeOut'];
	fx.options.duration = 1000;
	fx.start({'left': 0})
	
	
}

var ax_request;

function DisplayComments(AbsPage)
{
	ax_request = GetXmlHttpObject(CallBackDisplayComments);
	SendXmlHttpRequest(ax_request, "/avideo/comments.aspx?ID_VIDEO=" + IdVideo + "&ABS_PAGE=" + AbsPage + "&t=" + String(Math.floor((new Date()).getTime() / 1000))); 
}

   

function CallBackDisplayComments() 
{ 
    
    try
    {
        if (ax_request.readyState == 4 || 
            ax_request.readyState == 'complete')
        {
            
            var ax_response = ax_request.responseText; 
            if (ax_response.length > 0)
            {
                document.getElementById("LstComments").innerHTML = ax_response; 
            } 
        }
    }
    catch(e){}
}

function AddCommentVideo()
{
	if (document.getElementById("txt_comment").value == "")
	{
		DisplayError("veuillez saisir un commentaire.")	
		return true;
	}
	SoapMethod = "POST";
	ajax.Start(AxAddCommentVideo);
}