/**
 * 
 */

function loginSubmit(){
	var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;
    adrcompte();
	if(email != "" && pass != "" && Utils.verifierEmail(email)!=false){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/login",
			data	: {'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok" || response=="redirect"){
					parent.location.href = adr;
				}
				else{
					if(response == "ko"){
						response = "Erreur d'authentification";
					}
					Utils.affNotifyMsg("notifMsgLogin", response, "ko");
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function onTestLogSubmit(redir){
	var nom=document.getElementById('nom').value;
    var dossier=document.getElementById('dossier').value;
    var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;
    adrcompte();
    if((dossier != "" && nom != "") || (email != "" && pass != "")){
    	jQuery.ajax({
			type	: 'post',
			url		: "/ajax/logcomplet",
			data	: {'nom':nom, 'dossier':dossier, 'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok")
					parent.location.href = adr;
				else if (response=="oktemp"){
					if (redir == 1)
						parent.location.href = "http://www.mareussite.com/users/creaoldcompte?layout=1";
					else
						parent.$.colorbox.next();
				}else if (response=="faux")
					Utils.affNotifyMsg("notifMsgLogin", "Erreur d'authentification", "ko");
				else
					Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
    else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}



function onDossierSubmit(){
	var nom=document.getElementById('nom').value;
    var dossier=document.getElementById('dossier').value;
    var type=document.getElementById('type').value;
	var url="/ajax/checklog";
	if(dossier != "" && nom != ""){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/checklog",
			data	: {'nom':nom, 'dossier':dossier, 'type':type},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok" || response=="redirect"){
					if (type=="dossier"){
						parent.$.colorbox.next();
					}
				}
				else{
					if(response == "ko"){
						response = "Erreur d'authentification";
					}
					Utils.affNotifyMsg("notifMsgLogin", response, "ko");
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function onNewPassSubmit(){
	var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;	
	var url="/ajax/updateclient";
	adrcompte();
	if(email != "" && pass != "" && Utils.verifierEmail(email)!=false){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/updateclient",
			data	: {'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok" || response=="redirect"){
					parent.location.href = adr;
				}else if (response=="oktemp"){
					parent.$.colorbox.next();
				}
				else{
					if(response == "ko"){
						response = "Erreur d'authentification";
					}
					Utils.affNotifyMsg("notifMsgLogin", response, "ko");
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}



function onNewConfSubmit(){
	var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;	
    adrcompte();
	var url="/ajax/newclient";
	if(email != "" && pass != "" && Utils.verifierEmail(email)!=false){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/newclient",
			data	: {'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="erreurmail"){
					Utils.affNotifyMsg("notifMsgLogin", "votre mail n'est pas identique au précédent", "ko");
				}else if (response=="erreurpass"){
					Utils.affNotifyMsg("notifMsgLogin", "votre mot de passe n'est pas identique au précédent", "ko");
				}else if (response=="ok"){
					parent.location.href = adr;
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}



function onPreEnregSubmit(){
	var sex=document.getElementById('sex').value;
    var valid=document.getElementById('valid').checked;
	if(sex != null && valid != null){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/preenregvalid",
			data	: {'sex':sex, 'valid':valid},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="erreursex"){
					Utils.affNotifyMsg("notifMsgLogin", "Vous devez renseigner votre sexe.", "ko");
				}else if (response=="erreurseul"){
					Utils.affNotifyMsg("notifMsgLogin", "Vous devez cocher la case qui atteste que vous avez lu nos recommandations.", "ko");
				}else if (response=="ok"){
					parent.location.href = "/questionnaire";
				}else
					Utils.affNotifyMsg("notifMsgLogin", "Parametres incorrects", "ko");
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function checkCodePart(){
	var codepart=document.getElementById('codepart').value;	
	if(codepart != ""){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/checkcodepart",
			data	: {'checkCodePart':codepart},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok")
					parent.location.href = "/questionnaire/preenreg";
				else
					Utils.affNotifyMsg("notifMsgLogin", "Code partenaire incorrect", "ko");
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}

function checkCodePartPreenreg(){
	var codepart=document.getElementById('codepart').value;	
	if(codepart != ""){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/checkcodepart",
			data	: {'checkCodePart':codepart},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok"){
					$('#codepart2').css('display','none');
					$('#imgPart').html("<img style='position:absolute;top:90px;left:460px;' src='/images/questionnaire/code-part-gratuit.gif'>");
				}else
					Utils.affNotifyMsg("notifMsgLogin", "Code partenaire incorrect", "ko");
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function checkCodePartPaiement(){
	var codepart=document.getElementById('codepart').value;	
	var adrredir = adrcompte();
	if(codepart != ""){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/checkcodepartpaiement",
			data	: {'checkCodePart':codepart},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="ok"){
					location.href = adrredir;
				}else
					Utils.affNotifyMsg("notifMsgLogin", "Code partenaire incorrect", "ko");
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function onCreaCompteSubmit(){
	var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;	
    adrcompte();
	var url="/ajax/newclient";
	if(email != "" && pass != "" && Utils.verifierEmail(email)!=false){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/creacompte",   
			data	: {'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="mailvide"){
					Utils.affNotifyMsg("notifMsgLogin", "veuillez entrer un email", "ko");
				}else if (response=="mauvaismail"){
					Utils.affNotifyMsg("notifMsgLogin", "votre email n'est pas valide", "ko");
				}else if (response=="passvide"){
					Utils.affNotifyMsg("notifMsgLogin", "veuillez entrer un mot de passe", "ko");
				}else if (response=="pass4"){
					Utils.affNotifyMsg("notifMsgLogin", "votre mot de passe doit faire au moins 4 caracteres", "ko");
				}else if (response=="mailtrouve"){
					Utils.affNotifyMsg("notifMsgLogin", "votre email existe deja dans notre base, veuillez vous identifier ou saisir un autre email", "ko");
				}else if (response=="ok"){
					parent.location.href = "/index/rediraprespaiement";
				}else{
					$("#propMail").html(response);
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function onValideCompteSubmit(){
	var email=document.getElementById('email').value;
    var pass=document.getElementById('pass').value;
    adrcompte();
	var url="/ajax/validclient";
	if(email != "" && pass != "" && Utils.verifierEmail(email)!=false){
		jQuery.ajax({
			type	: 'post',
			url		: "/ajax/validclient",   
			data	: {'email':email, 'pass':pass},
			success	: function(data, textStatus, XMLHttpRequest){
				var response = data || "no response text";
				if(response=="mailvide"){
					Utils.affNotifyMsg("notifMsgLogin", "veuillez entrer un email", "ko");
				}else if (response=="mauvaismail"){
					Utils.affNotifyMsg("notifMsgLogin", "votre email n'est pas valide", "ko");
				}else if (response=="passvide"){
					Utils.affNotifyMsg("notifMsgLogin", "veuillez entrer un mot de passe", "ko");
				}else if (response=="pass4"){
					Utils.affNotifyMsg("notifMsgLogin", "votre mot de passe doit faire au moins 4 caracteres", "ko");
				}else if (response=="conf"){
					parent.location.href = "/users/confvalidepaiement";
				}else{
					parent.location.href = adr;
				}
			},
			error	: function(xhr, textStatus, errorThrown){Utils.affNotifyMsg("notifMsgLogin", "Erreur", "ko"); }
		});
	}
	else{
		Utils.affNotifyMsg("notifMsgLogin", "Paramètres incorrects", "ko");
	}
	return false;
}


function adrcompte(){
	jQuery.ajax({
		url		: "/ajax/returnurl",
		success	: function(data, textStatus, XMLHttpRequest){
			var response = data || "no response text";
			adr = response;
			return adr
		}
	});
}






