﻿var NoMember = false;
var MemberId = "0";
var SecurityKey = "";
var IdDivToDisplay = "";
var PosDivToDisplay = -410; 
var ExecGetListePlaylistByUsager = false;
  


var AxIsAlwaysMemberActions = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(document.getElementById("txt_mail_2").value);
	},
	call: proxies.AjaxFunc.IsAlwaysMember,
	finish: function (p) 
	{ 
		if (p == "YES")
			alert("un compte existe déjà avec cette adresse mail.");
		else
		{
			SoapMethod = "POST";
			ajax.Start(AxCreateMemberActions);
		}
			
	},
	onException: ajax.alertException
}

var AxIsMemberActions = {
	delay: 200,
	prepare: function() { 
		InputVar = new Array(document.getElementById("txt_mail_2").value,document.getElementById("txt_password_2").value);
	},
	call: proxies.AjaxFunc.IsMember,
	finish: function (p) 
	{ 
		if (p == "KO")
			alert("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 = $('ActionsLogin');
			target.style.display = "none";
			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 = $(IdDivToDisplay);
			target.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': PosDivToDisplay});
			
			if (ExecGetListePlaylistByUsager)
				GetListePlaylistByUsager();
		}
			
	},
	onException: ajax.alertException
}


var AxCreateMemberActions = {
	delay: 200,
	prepare: function() {
		var sexe = "M";
		if (document.getElementById("rdb_feminin_2").checked)
			sexe = "F";
		InputVar = new Array(document.getElementById("txt_mail_2").value,document.getElementById("txt_pseudo_2").value,sexe,document.getElementById("txt_password_2").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 = $('ActionsLogin');
		target.style.display = "none";
		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 = $(IdDivToDisplay);
		target.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': PosDivToDisplay});
		
		if (ExecGetListePlaylistByUsager)
			GetListePlaylistByUsager();
	
	},
	onException: ajax.alertException
}


function ShowChampsInscr2()
{
	
	document.getElementById('log_pseudo_2').style.display = '';
	document.getElementById('log_sexe_2').style.display = '';
}


function HideChampsInscr2()
{
	
	document.getElementById('log_pseudo_2').style.display = 'none';
	document.getElementById('log_sexe_2').style.display = 'none';
}

function ExecLogin2()
{
	
	if (document.getElementById("txt_mail_2").value == "")
	{
		alert("le champs e-mail est obligatoire.")	
		return true;
	}
	
	if (document.getElementById("txt_password_2").value == "")
	{
		alert("le champs mot de passe est obligatoire.")	
		return true;
	}
			
	if (document.getElementById('rdb_no_member_2').checked)
	{
		
		if (document.getElementById("txt_pseudo_2").value == "")
		{
			alert("le champs pseudo est obligatoire.")	
			return true;
		}
		
		SoapMethod = "POST";
		ajax.Start(AxIsAlwaysMemberActions);	
	}
	else
	{
		SoapMethod = "POST";
		ajax.Start(AxIsMemberActions);
	}

}

function HideLoginActions()
{
	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 = $('ActionsLogin');
	$('ActionsLogin').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});
}
