/* Scripts JavaScript qui concernent les ABONNEMENTS */

var currentUsername = '';
var currentEmail = '';
var value_cell = 'true';
var web_root = 'http://' + document.domain + '/';

// initialize AJAX
var xmlhttp;
if (window.XMLHttpRequest) {
 	xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
 	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
else{
	xmlhttp = false;
}



function ConfirmerPINCell (uid) {

	xmlhttp.open ("POST", web_root + "/montreal/registration/validatecellphone", true);
	xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	
	if (xmlhttp) {
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
				if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */																				
				
					switch (xmlhttp.responseText) {
						case '0':
							document.getElementById ('ValiderCell').style.visibility = "hidden";
							document.getElementById ('ConfirmerCell').style.visibility = "hidden";
							document.getElementById ('Response_cell_confirme').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/ok.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='green'><strong>Merci, ton num&eacute;ro de t&eacute;l&eacute;phone cellulaire est valid&eacute;&nbsp;!</strong></font></td></tr></table>";							
							break;							
						case '1':
							document.getElementById ('Response_cell_confirme').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='55' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Erreur' /></td><td height='55'><p><font color='red'><strong>D&eacute;sol&eacute;, nous ne pouvons confirmer ton num&eacute;ro pour le moment...</strong></font></td></tr></table>";
							break;
						case '2':
							document.getElementById ('Response_cell_confirme').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Erreur' /></td><td height='45'><p><font color='red'><strong>D&eacute;sol&eacute;, le NIP entr&eacute; n\'est pas valide...</strong></font></td></tr></table>";
							break;
					}
				
				}
			} 
		}
	}
		
	cell_pin = document.getElementById ('PINCell').value;	
	xmlhttp.send ("uid=" + uid + "&cell_pin=" + cell_pin + "");
}


function reset_cell_pin (uid) {
	
	xmlhttp.open ("POST", web_root + "sms/generatepin", true);
	xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	
	if (xmlhttp) {
		xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
				if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */																				
					if (xmlhttp.responseText == 'ok') {
						document.getElementById ('ConfirmerCell').style.visibility = "visible";
					}
				}
			} 
		}
	}
		
	no_cell = document.getElementById ('cell_maison').value;
	xmlhttp.send ("uid=" + uid + "&no_cell=" + no_cell + "");
}


function termesConditions () {
	var termes;
	termes = window.open("termes_conditions.php", "desabonnement", "width=650,height=400,menubar=no,scrollbars=yes,alwaysRaised=yes,dependent=yes,resizable=no,status=no,screenX=20,screenY=20,innerHeight=0,innerWidth=0,outerHeight=0,outerWidth=0");
	termes.focus();		
	
}


function validerUsername (value) {
	if (document.getElementById ('new_username').value != '') {
		if (value){
			checkInfos ('username',value);
		}
		else{
			checkInfos ('username');
		}
	}
}


function validerEmail() {
	if (document.getElementById ('courriel').value != '') {
		//checkInfos ('email');
		checkIfValidEmailFormat();
	}
}
	
// Fait afficher le message d'erreur AJAX
function afficherErreur (objet, div) {
	document.getElementById(div).innerHTML = xmlhttp.responseText;									
	document.getElementById(objet).style.color = 'red';
	document.getElementById(objet).style.background = '#FCF7BC';
}


// Fait disparaitre le message d'erreur AJAX, retour au champ de form normal
function effacerErreur (objet, div) {
	document.getElementById(div).innerHTML = '';									
	document.getElementById(objet).style.color = 'black';
	document.getElementById(objet).style.background = '#FFFFFF';
}

// Fait DISPARAITRE le DHTML full-screen pour le traitement background AJAX
function rem() {
	var objLink = document.createElement ('a');
	Lightbox.prototype.end (objLink);
}


// Fait AFFICHER le DHTML full-screen pour le traitement background AJAX
function afficherDiv (url) {
	var objLink = document.createElement ('a');
	objLink.setAttribute('href', url);
	objLink.setAttribute('rel', 'lightbox');
	objLink.setAttribute('title', caption);
	Lightbox.prototype.start (objLink);
	setTimeout ("rem()", 6000 );
}


function rappelerUsername () {
	value = document.getElementById ('new_username').value;
	var rappeler;
	rappeler = window.open( web_root + "abonnement/rappeler.php?value=" + value + "", "rappeler", "width=550,height=400,menubar=no,scrollbars=no,alwaysRaised=yes,dependent=yes,resizable=no,status=no,screenX=20,screenY=20,innerHeight=0,innerWidth=0,outerHeight=0,outerWidth=0");
	rappeler.focus();		
}


function uncheckBox(element_id){
	
	if (document.getElementById(element_id)){
		document.getElementById(element_id).checked = false;	
	}
}

function checkBox(element_id){
	
	if (document.getElementById(element_id)){
		document.getElementById(element_id).checked = true;	
	}
}

function cellulaire() {
	
	if (document.getElementById ('pas_cell').checked) {
		document.getElementById ('cell_maison').disabled = 1;
		document.getElementById ('cell_maison').style.background = '#4D4D4D';
		document.getElementById ('ValiderCell').style.visibility = "hidden";
		
		// Uncheck ALL SMS checkboxes...
		for (x=18;x<=33;x++){
			uncheckBox('ckb_' + x + 'sms');
		}
		
		uncheckBox('ckb_musique_sms');
		uncheckBox('ckb_commerciale_sms');
		uncheckBox('ckb_palmares_sms');
		uncheckBox('ckb_nouv_artistique_sms');
		uncheckBox('ckb_meteo_sms');
		uncheckBox('ckb_boutique_sms');
		uncheckBox('ckb_horoscope_sms');
		uncheckBox('ckb_circulation_sms');
		uncheckBox('ckb_ski_sms');
		uncheckBox('ckb_top5Palmares_sms');
} else {
		document.getElementById ('cell_maison').disabled = 0;
		document.getElementById ('cell_maison').style.background = '#FFFFFF';
		document.getElementById ('ValiderCell').style.visibility = "visible";
	}
}


function verifierSiCell (caseACocher) {
	
	if (document.getElementById (caseACocher).checked) {
		if (document.getElementById ('pas_cell').checked) {
			alert ("Tu d\351sires recevoir cette infolettre par SMS, mais tu as mentionn\351 que tu n'as pas de cellulaire !!");
			document.getElementById ('cell_maison').disabled = 0;
			document.getElementById ('cell_maison').style.background = '#FCF7BC';
			document.getElementById ('ValiderCell').style.visibility = "visible";
			document.getElementById ('PINCell').style.background = '#FCF7BC';
			document.getElementById ('pas_cell').checked = false;
			document.getElementById (caseACocher).checked = false;
			form.pas_cell.focus();			
		}
		
	}
}


function modifierPasswd() {
	if (!document.getElementById ('modifier_passwd').checked) {
		document.getElementById ('pass').disabled = 1;
		document.getElementById ('pass').style.background = '#4D4D4D';
	} else {
		document.getElementById ('pass').disabled = 0;
		document.getElementById ('pass').style.background = '#FFFFFF';
	}
}


function showLoading(div_element){		
	div_element.innerHTML = "<img src='" + web_root + "images/icones/loading_re.gif' width='28' height='12' alt='LOADING' />";	
}


function closeLoading(div_element){	
	div_element.innerHTML = "";
}


function goToNextBox(max_chars,current_box,next_box_ID){

	if (current_box.value.length == max_chars){
		document.getElementById(next_box_ID).focus();
	}	
}


function updateCellPhoneField(){

	document.getElementById("cell_maison").value = document.getElementById("cell_1").value + document.getElementById("cell_2").value + document.getElementById("cell_3").value;
	if (((document.getElementById("cell_validated").innerHTML == "") || (document.getElementById("cell_validated").style.display == "none")) && (document.getElementById("cell_maison").value != '') && (document.getElementById("cell_maison").value.length == 10)) {
		document.getElementById("ValiderCell").style.display = "block";
	} else
		document.getElementById("ValiderCell").style.display = "none";
} 

function changeCellPhone(){

	document.getElementById("cell_1").removeAttribute("readOnly");
	document.getElementById("cell_2").removeAttribute("readOnly");
	document.getElementById("cell_3").removeAttribute("readOnly");
	document.getElementById("cell_validated").style.display = "none";
	document.getElementById("ValiderCell").style.display = "block";
	document.getElementById("cell_1").select();
	document.getElementById("cell_1").focus();
	unconfirmCellPhone();
}

function unconfirmCellPhone(){
	
	if (document.getElementById("cell_uid")){
		var uid = document.getElementById("cell_uid").value;
	
		if (uid != ''){
			xmlhttp.open("POST",  web_root + "abonnement/cell_phone_unconfirmation.php", true);
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	
			post_vars = "uid=" + uid;
			xmlhttp.send (post_vars);
		}
	}
}

function cell_phone_confirmation(uid,from_bell){
		
	if (document.getElementById("cell_1").value == ''){		
		alert('Le champ de cellulaire est vide');		
		document.getElementById("cell_1").focus();
	}
	else{		
		loading_running = false;
		if (document.getElementById('loading_confirmer_cell')){
			closeLoading(document.getElementById('loading_cell_phone'));
		}
		
		xmlhttp.open ("POST",  web_root + "abonnement/cell_phone_confirmation.php", true);
		xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");	
		
		if (xmlhttp) {
			
			xmlhttp.onreadystatechange = function () {			
				
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					if (loading_running){
						if (document.getElementById('loading_confirmer_cell')){
							closeLoading(document.getElementById('loading_confirmer_cell'));
						}
					}
					loading_running = false;
				}
				else{
					if (!loading_running){
						if (document.getElementById('loading_confirmer_cell')){
							showLoading(document.getElementById('loading_confirmer_cell'));
						}
						loading_running = true;
					}
				}			
				
				if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
					if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */		
	
						//alert("responseText : " + xmlhttp.responseText);
						switch (xmlhttp.responseText) {
							case '0': // invalid PIN
								document.getElementById("confirmation_return").innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='red'><strong>Le code de validation est invalide&nbsp;!</strong></font></td></tr></table>";
								break;
							case '1': // valid PIN
								document.getElementById("cell_valid").value = "1";
								document.getElementById("ConfirmerCell").style.display = "none";
								document.getElementById("newly_validated").value = "1";
								document.getElementById("confirmation_return").innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/ok.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='#90d690'><strong>Num&eacute;ro de cellulaire valid&eacute;&nbsp;!</strong></font></td></tr></table>";
								if (from_bell == "true"){	
									submitBellForm();
								}
								break;
						}
					}
				}
			}
		}
		
		if (uid != '0'){
			var post_vars = "no_cell=" + document.getElementById("cell_maison").value + "&pin=" + document.getElementById("PINCell").value + "&uid=" + uid;
		}
		else{
			var post_vars = "no_cell=" + document.getElementById("cell_maison").value + "&pin=" + document.getElementById("PINCell").value;
		}
		//alert("no_cell=" + document.getElementById("cell_maison").value + "&pin=" + document.getElementById("PINCell").value);
		xmlhttp.send (post_vars);
	}
}


function cell_phone_validation(){
		
	if (document.getElementById("cell_1").value == ''){		
		alert('Le champ de cellulaire est vide');		
		document.getElementById("cell_1").focus();
	}
	else{		
		document.getElementById("ValiderCell").style.display = "none";
		loading_running = false;
		if (document.getElementById('loading_cell_phone')){
			closeLoading(document.getElementById('loading_cell_phone'));
		}
		
		xmlhttp.open ("POST",  web_root + "montreal/registration/validatecellphone", true);
		xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");	
		
		if (xmlhttp) {
			
			xmlhttp.onreadystatechange = function () {			
				
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					if (loading_running){
						if (document.getElementById('loading_cell_phone')){
							closeLoading(document.getElementById('loading_cell_phone'));
						}
					}
					loading_running = false;
				}
				else{
					if (!loading_running){
						if (document.getElementById('loading_cell_phone')){
							showLoading(document.getElementById('loading_cell_phone'));
						}
						loading_running = true;
					}
				}			
				
				if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
					if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */		
	
						//alert("responseText : " + xmlhttp.responseText);
						switch (xmlhttp.responseText) {
							case '0': // error
								document.getElementById('ConfirmerCell').style.display = "none";
								document.getElementById('ErreurSMS').innerHTML = "Ce numero de cellulaire est invalide";
								document.getElementById('ErreurSMS').style.display = "block";
								break;
								
							case '1': // SMS sent
								document.getElementById('ErreurSMS').style.display = "none";
								document.getElementById('ErreurSMS').innerHTML = "";
								document.getElementById('ConfirmerCell').style.display = "block";
								break;
								
							case '2': // error
								document.getElementById('ConfirmerCell').style.display = "none";
								document.getElementById('ErreurSMS').innerHTML = "Erreur lors de l'envoi du SMS";
								document.getElementById('ErreurSMS').style.display = "block";								
								break;
						}
					}
				}
			}
		}
		
		var post_vars = "no_cell=" + document.getElementById("cell_maison").value;
		//alert("no_cell=" + document.getElementById("cell_maison").value);
		xmlhttp.send (post_vars);
	}
}


function cell_phone_validation_bell(){
		
	if (document.getElementById("cell_1").value == ''){		
		alert('Le champ de cellulaire est vide');		
		document.getElementById("cell_1").focus();
	}
	else{		
		document.getElementById("ValiderCell").style.display = "none";
		loading_running = false;
		if (document.getElementById('loading_cell_phone')){
			closeLoading(document.getElementById('loading_cell_phone'));
		}
		
		xmlhttp.open ("POST",  web_root + "abonnement/cell_phone_validation_bell.php", true);
		xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");	
		
		if (xmlhttp) {
			
			xmlhttp.onreadystatechange = function () {			
				
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					if (loading_running){
						if (document.getElementById('loading_cell_phone')){
							closeLoading(document.getElementById('loading_cell_phone'));
						}
					}
					loading_running = false;
				}
				else{
					if (!loading_running){
						if (document.getElementById('loading_cell_phone')){
							showLoading(document.getElementById('loading_cell_phone'));
						}
						loading_running = true;
					}
				}			
				
				if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
					if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */		
	
						//alert("responseText : " + xmlhttp.responseText);
						switch (xmlhttp.responseText) {
							case '0': // error
								document.getElementById('ConfirmerCell').style.display = "none";
								document.getElementById("confirmation_return").innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='red'><strong>Ce num&eacute;ro de t&eacute;l&eacute;phone cellulaire est invalide!</strong></font></td></tr></table>";
								//clickThisLink('bas_de_page_click');
								break;
								
							case '1': // SMS sent
								document.getElementById('ErreurSMS').style.display = "none";
								document.getElementById('ErreurSMS').innerHTML = "";
								document.getElementById('ConfirmerCell').style.display = "block";
								break;
								
							case '2': // error
								document.getElementById('ConfirmerCell').style.display = "none";
								document.getElementById("confirmation_return").innerHTML = "<table cellpadding='8' width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font size='4' face='arial' color='#dc0000'><strong>D&eacute;sol&eacute;. Le Club Privil&egrave;ge du Studio &Eacute;nergie de Bell est EXCLUSIF aux abonn&eacute;s de Bell Mobilit&eacute;. Inscription non valide.</strong></font></td></tr></table>";
								//clickThisLink('bas_de_page_click');
								break;
						}
					}
				}
			}
		}
		
		var post_vars = "no_cell=" + document.getElementById("cell_maison").value;
		//alert("no_cell=" + document.getElementById("cell_maison").value);
		xmlhttp.send (post_vars);
	}
}


function checkIfValidEmailFormat(){
	
	var loading_div_suffix = "email";
	var loading_running = false;
	
	if (document.getElementById("courriel").value == '' || document.getElementById("courriel").value == ' '){		
		alert('Le champ courriel est vide!');		
		document.getElementById("courriel").focus();
	}
	else{		
		loading_running = false;
		if (document.getElementById('loading_' + loading_div_suffix)){
			closeLoading(document.getElementById('loading_' + loading_div_suffix));
		}
		
		xmlhttp.open ("POST",  web_root + "abonnement/check_email_format.php", true);
		xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");	
		
		if (xmlhttp) {
			
			xmlhttp.onreadystatechange = function () {			
				
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					if (loading_running){
						if (document.getElementById('loading_' + loading_div_suffix)){
							closeLoading(document.getElementById('loading_' + loading_div_suffix));
						}
					}
					loading_running = false;
				}
				else{
					if (!loading_running){
						if (document.getElementById('loading_' + loading_div_suffix)){
							showLoading(document.getElementById('loading_' + loading_div_suffix));
						}
						loading_running = true;
					}
				}			
				
				if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
					if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */		
	
						switch (xmlhttp.responseText) {							
								
							case '0' : // email format is invalid
								document.getElementById('Response_courriel').style.display = "block";
								document.getElementById('Response_courriel').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='55' align='left'><img src='" + web_root + "/library/images/icons/errorDisplay.gif' width='30' height='23' alt='Avertissement' /></td><td height='55'><p><font color='#000000'><strong>L'adresse de courriel que vous avez entr&eacute; est invalide!</strong></font></td></tr></table>";
								document.getElementById("courriel").select();
								document.getElementById("courriel").focus();
								break;
							case '1' : // email format is valid, continue to other validations
								document.getElementById('Response_courriel').innerHTML = "";
								checkInfos ('email');
								break;
						}
					}
				}
			}
		}
		
		var email =  document.getElementById("courriel").value;
		email = email.replace("@","%40");
		
		var post_vars = "email=" + email;
		xmlhttp.send (post_vars);
	}
}


function checkEmailTypo(){
	
	var loading_div_suffix = "email";
	var loading_running = false;
	
	if (document.getElementById("courriel").value == ''){		
		alert('Le champ courriel est vide');		
		document.getElementById("courriel").focus();
	}
	else{		
		loading_running = false;
		if (document.getElementById('loading_' + loading_div_suffix)){
			closeLoading(document.getElementById('loading_' + loading_div_suffix));
		}
		
		xmlhttp.open ("POST",  web_root + "abonnement/check_email_typo.php", true);
		xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");	
		
		if (xmlhttp) {
			
			xmlhttp.onreadystatechange = function () {			
				
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
					if (loading_running){
						if (document.getElementById('loading_' + loading_div_suffix)){
							closeLoading(document.getElementById('loading_' + loading_div_suffix));
						}
					}
					loading_running = false;
				}
				else{
					if (!loading_running){
						if (document.getElementById('loading_' + loading_div_suffix)){
							showLoading(document.getElementById('loading_' + loading_div_suffix));
						}
						loading_running = true;
					}
				}			
				
				if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
					if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */		
	
						switch (xmlhttp.responseText) {
							case '0' : // no match found
								document.getElementById('Response_courriel').innerHTML = "";
								break;
								
							default : // afficher la suggestion de typo
								document.getElementById('Response_courriel_typo').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='55' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Avertissement' /></td><td height='55'><p><font color='#000000'><strong>Il semble y a voir une erreur de frappe dans votre adresse de courriel. Suggestion : <font color=blue>" + xmlhttp.responseText + "</font><br><a href=\"javascript:setCorrectedEmail('" + xmlhttp.responseText + "');\">Cliquez ici pour appliquer la correction</a></strong><br></font></td></tr></table>";
						}
					}
				}
			}
		}
		
		var email =  document.getElementById("courriel").value;
		email = email.replace("@","%40");
		
		var post_vars = "email=" + email;
		xmlhttp.send (post_vars);
	}
}


function setCorrectedEmail(email){
	document.getElementById("courriel").value = email;	
	document.getElementById("courriel_verif").value = email;	
	document.getElementById('Response_courriel_typo').innerHTML = "";
	document.getElementById("courriel_verif").focus();	
}


function checkInfos (check,value) {

	var loading_running = false;
	if (document.getElementById('loading_' + check)){
		closeLoading(document.getElementById('loading_' + check));
	}

	if (value){
		var requestString =  web_root + "abonnement/check_value.php?check=" + check + "&value=" + value;
		xmlhttp.open ("GET", requestString, true);
	}
	else{
		xmlhttp.open ("POST",  web_root + "abonnement/check_value.php", true);
	}
	xmlhttp.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	
	if (xmlhttp) {
			
		xmlhttp.onreadystatechange = function () {			
			
			
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
				if (loading_running){
					if (document.getElementById('loading_' + check)){
						closeLoading(document.getElementById('loading_' + check));
					}
				}
				loading_running = false;
			}
			else{
				if (!loading_running){
					if (document.getElementById('loading_' + check)){
						showLoading(document.getElementById('loading_' + check));
					}
					loading_running = true;
				}
			}
			
			
			
			if (xmlhttp.readyState == 4) { /* 4 : Etat "complete" */		
				if (xmlhttp.status == 200) { /* 200 : code HTTP pour OK */										

					switch (xmlhttp.responseText) {
						case '0':
							//setTimeout ("afficherErreur ('username', 'Response_username')", 6000 );
							document.getElementById('Response_username').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/ok.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='#90d690'><strong>Nom d'utilisateur valid&eacute;&nbsp;!</strong></font></td></tr></table>";
							document.getElementById('courriel').focus();
							break;							
						case '1':
							document.getElementById('Response_username').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='55' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Erreur' /></td><td height='55'><p><font color='#000000'><strong>D&eacute;sol&eacute;... ce nom d'utilisateur est d&eacute;j&agrave; utilis&eacute;.</strong><br><a href='JavaScript: rappelerUsername();'><u>Si tu es cet utilisateur, clique ici&nbsp;!</u></a></font></td></tr></table>";
							document.getElementById('new_username').focus();
							break;
						case '2':
							document.getElementById('Response_username').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Erreur' /></td><td height='45'><p><font color='#000000'><strong>Le nom d'utilisateur contient un ou plusieurs caract&egrave;res interdits.</strong></font></td></tr></table>";
							break;
						case '3':
							document.getElementById('Response_courriel').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='55' align='left'><img src='" + web_root + "images/icones/erreur.gif' width='35' height='37' alt='Erreur' /></td><td height='55'><p><font color='#000000'><strong>Cette adresse courriel est d&eacute;j&agrave; utilis&eacute;e.</strong><br><a href='/abonnement/mot_passe_oublie.php?a=9'>Es-tu d&eacute;j&agrave; membre de radioenergie.com?</a></font></td></tr></table>";
							document.getElementById('courriel').focus();							
					
							break;
						case '4':
							document.getElementById('courriel_verif').focus();
							//document.getElementById('Response_courriel').innerHTML = "<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td width='40' height='45' align='left'><img src='../images/icones/ok.gif' width='35' height='35' alt='OK' /></td><td height='45'><p><font color='#90d690'><strong>L'adresse courriel est valid&eacute;e&nbsp;!</strong></font></td></tr></table>";
							break;	
					}
					
					
					if (check == "email"){
						checkEmailTypo();	
					}
					
				}
			} 
		}
	}

	if (check == 'username') {	
		
		var username = document.getElementById ('new_username').value;
		
		if (username != '' && (currentUsername != username)) {
			effacerErreur ('new_username', 'Response_username');
			currentUsername = username;					
			xmlhttp.send ("check=username&value=" + username + "");
		}
		
	} else if (check == "email") {

		email = document.getElementById ('courriel').value;			
		
		if (email != "" && (currentEmail != email)) {
			effacerErreur ('courriel', 'Response_courriel');
			currentEmail = email;		
			xmlhttp.send ("check=email&value=" + email + "");
		}
		
	}

}


function validForm(f) {
	var ret;
	ret = true;
	if(ret && f.new_username.value==''){
		alert("Tu dois choisir un \253 Nom d\'utilisateur \273 ...");
		f.new_username.focus();
		ret = false;
	}
	if(ret && f.nom.value==""){
		alert("Le champs \253 Nom \273 est obligatoire !");
		f.nom.focus();
		ret = false;
	}
	if(ret && f.prenom.value==""){
		alert("Le champs \253 Pr\351nom \273 est obligatoire !");
		f.prenom.focus();
		ret = false;
	}
	if(ret && f.adresse.value==""){
		alert("Le champs \253 Adresse \273 est obligatoire !");
		f.adresse.focus();
		ret = false;
	}
	if(ret && f.ville.value==""){
		alert("Le champs \253 Ville \273 est obligatoire !");
		f.ville.focus();
		ret = false;
	}
	if(ret && f.codepostal.value==""){
		alert("Le champs \253 Code postal \273 est obligatoire !");
		f.cp1.focus();
		ret = false;
	}
	if(ret && f.jnais.value==""){
		alert("Le champs \253 Jour de naissance \273 est obligatoire !");
		f.jnais.focus();
		ret = false;
	}
	if(ret && f.mnais.value==""){
		alert("Le champs \253 Mois de naissance \273 est obligatoire !");
		f.mnais.focus();
		ret = false;
	}
	if(ret && f.sexe.value==""){
		alert("Le champs \253 Sexe \273 est obligatoire !");
		f.sexe.focus();
		ret = false;
	}
	if(ret && f.tel_maison.value==""){
		alert("Le champs \253 Num\351ro de t\351l\351phone \273 est obligatoire !");
		f.tel_maison.focus();
		ret = false;
	}

	// on ne peut pas obliger les gens a rentrer leur numero de cell et a savoir qu'ils faut qu'ils clique la boite
	/*
	if (ret && !document.getElementById ('pas_cell').checked) {
		if(ret && f.cell_maison.value == ""){
			alert("Le champs \253 Num\351ro de t\351l\351phone \273 pour ton cellulaire est obligatoire !");
			f.cell_maison.focus();
			ret = false;
		}
	}
	*/
	// cocher la boite pas cell automatiquement si il n'y a apas d'entree de cell
	if (ret && !document.getElementById ('pas_cell').checked) {
		if(ret && f.cell_maison.value == ""){
			document.getElementById ('pas_cell').checked = true;
		}
	}

	if (ret && document.getElementById ('veuxblogue').checked) {
		if (ret && !document.getElementById ('legal_accepted').checked){
			alert ("Tu dois accepter les \253 Conditions d'utilisation \273 pour avoir un blogue !");
			f.legal_accepted.focus();
			ret = false;
		}
	}
	
	if(ret && !emailCheck(f.courriel.value)) {
		f.courriel.focus();
		ret = false;
	}

	if(ret && f.courriel.value != f.courriel_verif.value){
		alert("Les champs : \n - \253 Confirme ton adresse courriel \273 et\n - \253 Adresse courriel \273 \nne semblent pas concorder ...");
		f.courriel_verif.focus();
		ret = false;
	}
	
	total = document.form.elements.length;
	if (ret) {
		for(i = 0; i < total; i++) {
			var chaine = new String(document.form.elements[i].name);
			if (chaine.indexOf("_element")>0){
				if (document.form.elements[i].value == "") {
					alert("Tous les champs ne sont pas remplis...");
					document.form.elements[i].focus();
					return false;
					//ret = false;
				}
			}
		}
	}

	if (ret && f.station.value == "") {
		alert("Le champs \253 Ta station pr\351f\351r\351e \273 est obligatoire !");
		f.station.focus();
		ret = false;
	}

	if (ret == true) { 
		//document.form.ajout.value = "ok";
	}
	return ret;
}


function validFormConnex(f){
	var ret = true;
	if(ret && ((f.username.value=="") || (f.username.value=="Nom d'usager"))) {
		alert("Le champ \'Nom d\'utilisateur\' est obligatoire.");
		f.username.focus();
		ret = false;
	}
	if(ret && ((f.password.value=="") || (f.password.value=="Mot de passe"))){
		alert("Le champ \'Mot de passe\' est obligatoire.");
		f.password.focus();
		ret = false;
	}
	return ret;
}


function emailCheck (emailStr) {
	var checkTLD=1; // 1 means check country tld, 0 means don't
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Le champ \253 Adresse courriel \273 semble invalide !");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Le champ \253 Adresse courriel \273 semble invalide !");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Le champ \253 Adresse courriel \273 semble contenir des caract\138res invalides !");
			return false;
	  }
	}
	if (user.match(userPat)==null) {
		alert("Le champ \253 Adresse courriel \273 semble invalide !");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Le champ \253 Adresse courriel \273 semble invalide !");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("Le champ \253 Adresse courriel \273 semble invalide !");
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Le \253 Courriel \273 doit se terminer par une extension reconnue !");
		return false;
	}
	if (len<2) {
		alert("Le champ \253 Adresse courriel \273 semble invalide !");
		return false;
	}
	return true;
}
