$(document).ready( function () { 
 
 
	 

$("#theForm").validate({
	
	 
		
   rules: {
		 raisonsocial:  {
				required: true
			 },
			 
		 emailNew: {
				required: true,
				email: true
			},
   		 countryNew:{ required: true
			},
		 
		 secretcode:{ required: true
			}
 
		},
	
	messages: {
		   raisonsocial:  {
				required: "Ce Champ est obligatoire"
				 
			}, 
   	    emailNew: {
				required: "Ce Champ est obligatoire",
				email: "Le format de l'email est incorrect"
			},

		countryNew:{ required: "Ce Champ est obligatoire"
				 
			},
		
		secretcode:{ required: "Ce Champ est obligatoire"
				 
			}
				 
		},
		 onsubmit: true

	});

	
$("#theFormEN").validate({
	
	 
		
   rules: {
		 raisonsocial:  {
				required: true
			 },
			 
		 emailNew: {
				required: true,
				email: true
			},
   		 countryNew:{ required: true
			},
		 
		 secretcode:{ required: true
			}
 
		},
	
	 
		 onsubmit: true

	});




				
$("div#creataccountDiv #theForm").submit( function() {	 			 
	
		$.ajax({  
		   type: "GET",  
		     contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
          url: "../fr/__include/espace_exposant/AJAX_createAccount.php",  
		   data: "operation=checkALL&raisonsocial="+$("#raisonsocialNew").val()+"&emailNew="+$("#emailNew").val()+"&pays="+$("#countryNew").val()
		         +"&secretcode="+$("#secretcode").val(),    
           beforeSend: function() {
                 	
                     if ($('div#creataccountDiv #theForm').validate().form()==true){
                             $("div#creataccountDiv span#erreur").html("&nbsp;Validation en cours ... Veuillez patienter");
					         $("div#creataccountDiv #theForm #submitbtn").hide()  ;
							  return true;
					 }else{
					       return false;
					 }
			   },
		  
		  success: function(msg){  
				    if(msg!="PHPException")  
				   {   //alert(msg);
				   var dataRet=eval(msg);
				    
					  if(dataRet[0]!='1'){
					 // alert(dataRet[0]+" "+dataRet[1]);
					  var errMsg=dataRet[1].split('|');
					  $("div#creataccountDiv  span#erreur").html("Erreur lors de la validation:<br/><br/>"+errMsg[1]+"<br/>"+errMsg[0]);
					  $("div#creataccountDiv #theForm #submitbtn").show()  ;
					 }else{
					  //$("div#creataccountDiv ").html("<span id=\"standsignmsg\">Votre Texte d\'enseigne a &eacute;t&eacute; enregistr&eacute; avec Succ&#232;s.<br/><a style=\"margin-top:50px;margin-left:120px;font-size:12px;font-weight:bold;\" href=\"espace_exposant.php\"> retour &#224; la page principale</a></span>");
				     $("div#creataccountDiv ").html("<span id=\"standsignmsg\">"+$("#successmsgDiv").html()+"</span>");
					   $("label#unmgen").text(dataRet[2]);
					   $("label#pwdgen").text(dataRet[3]);
					    $("#unmgeninput").val(dataRet[2]);
					   $("#pwdgeninput").val(dataRet[3]);
					  }
						 
				   }
				   else 
				  {
					 $("div#creataccountDiv  span#erreur").html("&nbsp;Une Exception est survenue lors de la validation");
				     $("div#creataccountDiv #theForm #submitbtn").show();  
				  }
		       }
		});
		return false; 
	});


	$("div#creataccountDiv #theFormEN").submit( function() {	 			 
	
		$.ajax({  
		   type: "GET",  
		     contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
          url: "../en/__include/espace_exposant/AJAX_createAccount.php",  
		   data: "operation=checkALL&raisonsocial="+$("#raisonsocialNew").val()+"&emailNew="+$("#emailNew").val()+"&pays="+$("#countryNew").val()
		         +"&secretcode="+$("#secretcode").val(),    
           beforeSend: function() {
                 	
                     if ($('div#creataccountDiv #theFormEN').validate().form()==true){
                             $("div#creataccountDiv span#erreur").html("&nbsp;Validation in progress ... Please wait");
					         $("div#creataccountDiv #theFormEN #submitbtn").hide()  ;
							  return true;
					 }else{
					       return false;
					 }
			   },
		  
		  success: function(msg){  
				    if(msg!="PHPException")  
				   {   //alert(msg);
				   var dataRet=eval(msg);
				    
					  if(dataRet[0]!='1'){
					 // alert(dataRet[0]+" "+dataRet[1]);
					  var errMsg=dataRet[1].split('|');
					  $("div#creataccountDiv  span#erreur").html("Account creation error:<br/><br/>"+errMsg[1]+"<br/>"+errMsg[0]);
					  $("div#creataccountDiv #theFormEN #submitbtn").show()  ;
					 }else{
					  //$("div#creataccountDiv ").html("<span id=\"standsignmsg\">Votre Texte d\'enseigne a &eacute;t&eacute; enregistr&eacute; avec Succ&#232;s.<br/><a style=\"margin-top:50px;margin-left:120px;font-size:12px;font-weight:bold;\" href=\"espace_exposant.php\"> retour &#224; la page principale</a></span>");
				     $("div#creataccountDiv ").html("<span id=\"standsignmsg\">"+$("#successmsgDiv").html()+"</span>");
					   $("label#unmgen").text(dataRet[2]);
					   $("label#pwdgen").text(dataRet[3]);
					    $("#unmgeninput").val(dataRet[2]);
					   $("#pwdgeninput").val(dataRet[3]);
					  }
						 
				   }
				   else 
				  {
					 $("div#creataccountDiv  span#erreur").html("&nbsp;Une Exception est survenue lors de la validation");
				     $("div#creataccountDiv #theForm #submitbtn").show();  
				  }
		       }
		});
		return false; 
	});

	
	
	
	
	
}); 