
window.onload = function(){
	controlNumberList({actionType:'LIST'});
}

/****************** CHOIX DU NUMERO ******************/

/** Bloque un numéro
*/
function lockNumber(number){
	controlNumberList({actionType:'LOCK',ln_numberLocked:number});
}

/** Débloque un numéro
*/
function unlockNumber(){
	controlNumberList({actionType:'UNLOCK'});
}

/** Controle de la liste des numéros
*/
function controlNumberList(paramObject){
	if (ajx == null){ajx = new tncaAjax();}
	if (ajx != null){
		var query = new Object();
		query.url = SITE_URL+'/ajax-register-list-numbers';
		query.responseType = 'TARGET';
		query.paramForm = 'Register_Form';
		if (typeof(paramObject) != 'object'){paramObject = new Object();}
		query.paramObject = paramObject;
		query.target = 'Box_Step01_Content';
		query.onLoading = function(){addLoader('Box_Step01_Content');}
		query.onCompletion = responseNumberList;
		ajx.setQuery(query);
	}
}

/** Gestion du retour
*/
function responseNumberList(){
	if (this.queryObject.vars.actionType == 'LOCK' && $('ln_error').value == ''){
		// Affichage du bouton 'Changer'
		$('btnBox01_Actualize').style.display = 'none';
		$('btnBox01_Change').style.display = 'block';
	}else{
		// Affichage du bouton 'Actualiser'
		$('btnBox01_Change').style.display = 'none';
		$('btnBox01_Actualize').style.display = 'block';
	}
}

/****************** ENREGISTREMENT INFOS ******************/

function submitUserInfos(paramObject){
	if (ajx == null){ajx = new tncaAjax();}
	if (ajx != null){
		var query = new Object();
		query.url = SITE_URL+'/ajax.php?script=register';
		query.responseType = 'GETVARS';
		query.paramForm = 'Register_Form';
		if (typeof(paramObject) != 'object'){paramObject = new Object();}
		query.paramObject = paramObject;
		query.onLoading = function(){addLoader('infos');}
		query.onCompletion = responseUserInfos;
		ajx.setQuery(query);
	}
}

function responseUserInfos(){
	if (this.responseFRT['actionType'] == 'CANCEL'){
		location.href = window.location;
	}else{
		if (this.responseFRT['error'] != 'false'){
			var errorView = this.responseFRT['errstr'].replace(/\+/g," ");
			$('infos').innerHTML = errorView;
		}else{
			// Désactivation des boutons du BOX numberList
			if (obtn=$('btnBox01_Actualize')){obtn.style.display = 'none';}
			if (obtn=$('btnBox01_Change')){obtn.style.display = 'none';}
			// Désactivation du BOX Step02
			if (obtn=$('Box_Step02')){obtn.style.display = 'none';}
			// Activation des BOX d'activation
			if (obtn=$('Box_Step03')){obtn.style.display = 'block';}
			if (obtn=$('Box_Step03_Next')){obtn.style.display = 'block';}
			if (obtn=$('Box_Step04')){obtn.style.display = 'block';}
			// Requete affichage "Recapitulatif"
			controlActivation('Box_Step03_Content',{actionType:'RECAP',userId:this.responseFRT['userId']});
			// Requete affichage "Activation
			controlActivation('Box_Step04_Content',{actionType:'ACTIVIEW',userId:this.responseFRT['userId']});
	
			
/*
			var total = "";
			for (var cle in this.responseFRT){
				total += cle + " : " + this.responseFRT[cle]+ "\n";
			}
			alert(total);
*/
		}
	}
}

/****************** ACTIVATION ******************/

function controlActivation(target,paramObject){
	if (ajx == null){ajx = new tncaAjax();}
	if (ajx != null && typeof(paramObject) == 'object'){
		var query = new Object();
		query.url = SITE_URL+'/ajax-register-activation';
		query.responseType = 'TARGET';
		query.target = target;
		query.paramForm = 'Register_Form';
		query.paramObject = paramObject;
		query.onLoading = function(){addLoader(target);}
		query.onCompletion = responseActivation;
		ajx.setQuery(query);
	}
}

function responseActivation(){
	if (obT=$('ac_error')){
		if (obT.value != ''){
			if (obtn=$('btnBox031')){obtn.style.display = 'none';}
			if (obtn=$('btnBox032')){obtn.style.display = 'none';}
		}
	}
	if (obT=$('actionType')){
		if (obT.value == 'ACTIVATE'){
			if (obtn=$('btnBox031')){obtn.style.display = 'none';}
			if (obtn=$('btnBox032')){obtn.style.display = 'none';}
		}
	}
}