function popupcentree(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function Delete(date) {
	if (confirm("Supprimer cette question ?")) location.href = BasePath + "/delete.php?date=" + date;
}

function checkQuote() {
	var obj = document.FRMQuote;
	if (obj.quote1.value == "" || obj.quote1.value == "" || obj.quote2.value == "") alert(error);
	else {
		obj.action = BasePath + "/register.php";
		obj.submit();
	}
}

function checkQuoteAndGo() {
	var obj = document.FRMQuote;
	if (obj.quote1.value == "" || obj.quote1.value == "" || obj.quote2.value == "") alert(error);
	else {
		obj.action = BasePath + "/php_quote.php";
		obj.submit();
	}
}

function checkModif() {
	var obj = document.FRMModif;
	if ((obj.question.value == "") || (obj.reponseA.value == "") || (obj.reponseB.value == "") || (obj.quote.value == "")) alert(error);
	else {
		obj.action = BasePath + "/backoffice/php_modif.php";
		obj.submit();
	}
}

function checkAjout() {
	var obj = document.FRMAjout;
	if ((obj.question.value == "") || (obj.reponseA.value == "") || (obj.reponseB.value == "") || (obj.detail.value == "") || (obj.QUOTE.value == "")) alert(error);
	else {
		obj.action = BasePath + "/backoffice/php_ajout.php";
		obj.submit();
	}
}

function checkLogin() {
	var obj = document.FRMLogin;
	if (obj.email.value == "") alert(error);
	else if (obj.password.value == "") alert(error);
	else {
		obj.action = BasePath + "/php_login.php";
		obj.submit();
	}
}

function checkLost() {
	var obj = document.FRMLost;
	if (obj.email.value == "") alert('Champ email vide !');
	//else if (obj.password.value == "") alert(error);
	else {
		obj.action = BasePath + "/php_lost.php";
		obj.submit();
	}
}

function checkInvestir() {
	var obj = document.FRMInvestir;
	if (obj.page.value == "") alert(error);
	else {
		obj.action = BasePath + "/php_investir.php";
		obj.submit();
	}
}

function alertInvestir() {
	alert("Merci de vous inscrire avant de participer.");
}

function checkRadioEmpty(args) {
	for (var j = 0 ; j < args.length ; j++) if (args[j].checked) return true;
	return false;
}

var reNumeric = /^[0-9]+$/;
var reEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([0-9a-zA-Z](-?[0-9a-zA-Z])*\.)+[a-zA-Z]{2}([zmuvtgZMUVTG]|fo|me|FO|ME)?$/;
function isEmail(s) {
	return reEmail.test(s);
}
function isNumeric(s) {
	return reNumeric.test(s);
}

function checkRegister() {
	var obj = document.FRMRegister;
	if (obj.lname.value == "") goAlert(obj.lname, 'Champ NOM non renseigné');
	else if (obj.fname.value == "") goAlert(obj.fname, 'Champ PRENOM non renseigné');
	else if (obj.address.value == "") goAlert(obj.address, 'Champ ADRESSE non renseigné');
	else if (obj.zip.value == "") goAlert(obj.zip, 'Champ CODE POSTAL non renseigné');
	else if (!isNumeric(obj.zip.value)) goAlert(obj.zip, 'Champ CODE POSTAL NON NUMERIQUE');
	else if (obj.zip.value.length != 5) goAlert(obj.zip, 'Champ CODE POSTAL contient moisn de 5 caractères');
	else if (obj.city.value == "") goAlert(obj.city, 'Champ VILLE non renseigné');
	else if (obj.email.value == "") goAlert(obj.email, 'Champ EMAIL non renseigné');
	else if (obj.email.value != obj.email2.value) goAlert(obj.email2, 'Confirmation du EMAIL erronée');
	else if (!isEmail(obj.email.value)) goAlert(obj.email, 'EMAIL invalide');
	else if (obj.password.value == "") goAlert(obj.password, 'Champ MOT DE PASSE non renseigné');
	else if (obj.password.value != obj.password2.value) goAlert(obj.password2, 'Confirmation du MOT DE PASSE erronée');
	else if (!checkRadioEmpty(obj.sg)) goAlert(obj.sg[0], 'Case à cocher SG non cochée');
	else if (!checkRadioEmpty(obj.boursier)) goAlert(obj.boursier[0], 'Case à cocher BOURSIER non cochée');
	else if (!checkRadioEmpty(obj.fortuneo)) goAlert(obj.fortuneo[0], 'Case à cocher FORTUNEO non cochée');
	else if (obj.cgv.checked==false) goAlert(obj.cgv, 'Acceptation du règlement non validée');
	else {
		obj.action = BasePath + "/php_register.php";
		obj.submit();
	}
}

function goAlert(field, msg) {
	alert(msg);
	focus(field);
}

