/////////////////////////// LES VARIABLES GLOBALS
var VALIDATION_EMPTY = "Vous devez remplir tous les champs obligatoires.";
var VALIDATION_EXIST = "Le nom d'usager inscrit existe déjà";
var VALIDATION_USERNAME = "Votre nom d\'usager ne doit contenir que des chiffres et des lettres.  Les caractères spéciaux  (*&?%-_  etc.)  ne sont pas acceptés.";
var MESSAGE_SAVE = "Félicitations !\n\r Votre inscription a été acceptée. Vous allez recevoir une confirmation par e-mail. \n\r Vous pouvez dès maintenant créer votre premier article et générer des revenus avec le Réseau CMI.";
var MESSAGE_IMAGE = "<img src=\"http://www.reseaucmi.com/ads/images/force_network.jpg\" alt=\"Image\" />";
var MESSAGE_SLOGAN = "<strong>Rejoignez</strong> des<br>milliers de membres<br> qui <strong>GAGNENT</strong> de<br><em>l\'argent sur<br>Internet !</em>";

/////////////////////////// CHECK LE PARRAIN
var host = window.location.hostname;
if(nex_host == "YES") {
	host = host.split(".");
	if(host[0] == "") { host[0] = 'cmi'; }
	nex_parrain = host[0];
}

/////////////////////////// LES FUNCTIONS
///////// checkrequired
function checkrequired(tempobj, txtError) {
	if ((tempobj.value=='') || (tempobj.selectedIndex==-1)) {	
		tempobj.focus();	
		 alert(txtError);			
		return 1;				
	} else {
		return 0;	
	}	
}
/////////////////////////// LES FUNCTIONS
///////// NexCall
//////// CopyRight 2007 Alain Paquet, Technologies Inexia. 
function NexCall() {
	var param = "username=" + document.frm.username.value + "&pass1=" + document.frm.pass1.value + "&fname=" + document.frm.fname.value + "&lname=" + document.frm.lname.value  + "&email=" + document.frm.email.value + "&parrain=" + document.frm.parrain.value ;
	var newJS = document.createElement('script');
	newJS.type='text/javascript';
	newJS.src='http://www.reseaucmi.com/ads/nex_agent_network.php?' + param;
	document.getElementsByTagName('head')[0].appendChild(newJS);
} 

/////////////////////////// LES FUNCTIONS
///////// updateSequence
function updateSequence(str) {	
	switch(str) {
		case "USER_EXIST":			
			alert(VALIDATION_EXIST);				
		break;
		case "USER_SAVE":
			alert( MESSAGE_SAVE );			
			document.getElementById("nexmsg").innerHTML = 	MESSAGE_LINK;			
		break;	
	}	
}

/////////////////////////// LES FUNCTIONS
///////// submit_this_form
function submit_this_agent() {
	var checkCompte = /^[\w]{2,}[\_]*$/;
	var verified = 0;	
	document.frm.username.value = document.frm.username.value.toLowerCase();
	if (verified == 0) { 
		if(!checkCompte.test(document.frm.username.value))  {
			alert(VALIDATION_USERNAME);
			document.frm.username.focus();
			verified++;
		} else {
			if (document.frm.username.value.indexOf("_") != -1) {
				alert(VALIDATION_USERNAME);
				document.frm.username.focus();
				verified++;
			}
		}
	}	
	if (verified == 0) { verified += checkrequired(document.frm.username, VALIDATION_EMPTY); }		
	if (verified == 0) { verified += checkrequired(document.frm.pass1, VALIDATION_EMPTY); }		
	if (verified == 0) { verified += checkrequired(document.frm.fname, VALIDATION_EMPTY); }	
	if (verified == 0) { verified += checkrequired(document.frm.lname, VALIDATION_EMPTY); }		
	if (verified == 0) { verified += checkrequired(document.frm.email, VALIDATION_EMPTY); }		
	
	if (verified == 0) {	
		//document.getElementById("nexmsg").innerHTML = "<img src=\"http://www.reseaucmi.com/ads/images/loading.gif\" />";			
		//document.getElementById("nexmsg").style.backgroundColor = "#ffffff";
		NexCall();
	}
}

/////////////////////////// LE HTML WRITE
document.write('<div id="nexagent" style="text-align:center; color:#'+nex_fontcolor+'; background-color:#'+nex_backcolor+'; border:#'+nex_bordercolor+' 1px solid; width:158px; ">'); 
document.writeln('<form name="frm" action="" method="POST">'); 
document.writeln('<input type="hidden" name="parrain" value="'+nex_parrain+'">');
document.writeln('<table width="158" border="0" cellspacing="0" cellpadding="0">');
document.writeln('<tr>');
document.writeln('<td valign="top"><table width="158"  border="0" cellpadding="0" cellspacing="0" >');
document.writeln('<tr>');
document.writeln('<td align="center"><img src="http://www.reseaucmi.com/ads/images/reseaucmi_top.jpg" width="158" height="276"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="center" ><div id="nexform"><table width="100%" height="148" border="0" cellspacing="0" cellpadding="2">');
document.writeln('<tr>');
document.writeln('<td align="right">&nbsp;</td>');
document.writeln('<td>&nbsp;</td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td width="46%" align="right" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; ">Pseudo</td>');
document.writeln('<td width="54%"><input type="text" name="username" id="username" style="width:83px;"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="right" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; ">Mot de passe</td>');
document.writeln('<td><input type="text" name="pass1" id="pass1" style="width:83px;"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="right" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; ">Prénom</td>');
document.writeln('<td><input type="text" name="fname" id="fname" style="width:83px;"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="right" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; ">Nom</td>');
document.writeln('<td><input type="text" name="lname" id="lname" style="width:83px;"></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="right" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; ">E-mail</td>');
document.writeln('<td><input type="text" name="email" id="email" style="width:83px;"></td>');
document.writeln('</tr>');
document.writeln('</table></div></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td height="122" align="center" style="font-family: Arial, Helvetica, sans-serif; font-size: 16px; "><div id="nexmsg">'+MESSAGE_SLOGAN+'</div></td>');
document.writeln('</tr>');
document.writeln('<tr>');
document.writeln('<td align="center" onClick="submit_this_agent()" style="cursor:pointer;" valign="bottom"><img src="http://www.reseaucmi.com/ads/images/reseaucmi_bottom.jpg" width="158" height="52"></td>');
document.writeln('</tr>');
document.writeln('</table></td>');
document.writeln('</tr>');
document.writeln('</table>');
document.writeln('</form>');
document.write("</div>");

var MESSAGE_LINK = "<strong><em>Connectez-vous maintenant en suivant le lien ci-dessous :</em></strong> <br><a href=\"http://"+document.frm.username.value+".reseaucmi.com\" target=\"_blank\">www.reseaucmi.com</a>";
