// JavaScript Document


function newsletter_signup(action)
{
document.getElementById('newsletter_signup_sendbtn').disabled = 'disabled';

   xajax.config.requestURI='./ajax_main.php';
   
   var arg=Array();
   arg[0]=action;
   arg[1]=document.getElementById('email').value;
   
   xajax.call("newsletter_signup", { parameters: arg } , 1);


 xajax.callback.global.onComplete = function()
 	{
 	document.getElementById('newsletter_signup_sendbtn').disabled = '';
	};
}

/****************************************************************************
 * 
 ***************************************************************************/ 
function sendtofriend(action)
{
oldvalue = document.getElementById('sendbtn').value;
document.getElementById('sendbtn').value = 'Veuillez patienter...';
document.getElementById('sendbtn').disabled = 'disabled';

xajax.config.requestURI='./ajax_main.php';

if(action=='article' || action=='actualites' || action=='histoire')
	{
	var arg=Array();
	arg[0]=document.getElementById('from_nom').value;
	arg[1]=document.getElementById('from_email').value;
	arg[2]=document.getElementById('to_nom').value;
	arg[3]=document.getElementById('to_email').value;
	arg[4]=document.getElementById('commentaire').value;
	arg[5]=document.getElementById('rubrique').value;
	arg[6]=document.getElementById('id').value;
	arg[7]=document.getElementById('copytosender').checked==true ? '1' : '0' ;
	
	if(action=='actualites')arg[5]='actualites';
	if(action=='histoire')arg[5]='histoire';
	
	xajax.call("sendtofriend", { parameters: arg } , 1);
	}
else if(action=='website')
	{
	var arg=Array();
	arg[0]=document.getElementById('from_nom').value;
	arg[1]=document.getElementById('from_email').value;
	arg[2]=document.getElementById('to_nom').value;
	arg[3]=document.getElementById('to_email').value;
	arg[4]=document.getElementById('commentaire').value;
	arg[5]=document.getElementById('copytosender').checked==true ? '1' : '0' ;
	
	xajax.call("sendtofriend_website", { parameters: arg } , 1);
	}



 xajax.callback.global.onComplete = function()
 	{
 	document.getElementById('sendbtn').value = oldvalue;
 	document.getElementById('sendbtn').disabled = '';
	};

}

function participerSendmail()
{
oldvalue = document.getElementById('sendbtn').value;
document.getElementById('sendbtn').value = 'Veuillez patienter...';
document.getElementById('sendbtn').disabled = 'disabled';

xajax.config.requestURI='./ajax_main.php';

var arg=Array();
arg[0]=document.getElementById('rubrique').value;
arg[1]=document.getElementById('id').value;
arg[2]=document.getElementById('email').value;

xajax.call("participerSendmail", { parameters: arg } , 1);

 xajax.callback.global.onComplete = function()
 	{
 	document.getElementById('sendbtn').value = oldvalue;
 	document.getElementById('sendbtn').disabled = '';
	};

}

/****************************************************************************
 * 
 ***************************************************************************/ 
function participerThematique(chp,chpformats)
{

   valid=true;

	// case tel cochée et pas de tel rentré
	if(valid==true)
	  {
     contact = document.forms['form'].contact.options[document.forms['form'].contact.selectedIndex].value;
     if(contact=='telephone' && !document.forms['form'].teldom.value && !document.forms['form'].telport.value)
      {
      alert("Nous vous remercions de remplir le champ telephone pour être contacté.");
      valid=false;
      }
     }
	// case email cochée et pas de email rentré
	if(valid==true)
	  {
     contact = document.forms['form'].contact.options[document.forms['form'].contact.selectedIndex].value;
     if(contact=='email' && !document.forms['form'].email.value )
      {
      alert("Nous vous remercions de remplir le champ email pour être contacté.");
      valid=false;
      }
     }     
     
	// pas de dispo sélectionnée
	if(valid==true)
	  {
	  nbdispo = getOptionCount('dispo[]');
     if(nbdispo=='0')
         {
         valid=false;
         alert('Vous devez préciser vos disponibilités (choix multiple)');
         }
     }     
   //validation du reste
   if(valid==true)
     {
     valid=ValidateForm('form',chp,chpformats);
     }	
   	
   if(valid==true)
      {
      oldvalue = document.getElementById('sendbtn').value;
      document.getElementById('sendbtn').value = 'Veuillez patienter...';
      document.getElementById('sendbtn').disabled = 'disabled';

      xajax.config.requestURI='./ajax_main.php';
      
      var arg=Array();
      arg[0]=xajax.getFormValues('form');
      arg[1]=document.getElementById('rubrique').value;
      arg[2]=document.getElementById('id').value;
      
      xajax.call("participerThematique", { parameters: arg } , 1);
      
       xajax.callback.global.onComplete = function()
       	{
       	document.getElementById('sendbtn').value = oldvalue;
       	document.getElementById('sendbtn').disabled = '';
      	};


      }

}


function testUpload(form)
{
   alert(form);
   xajax.config.requestURI='./ajax_main.php';
   
   var arg=Array();
   arg[0]=xajax.getFormValues(form);
   
   xajax.call("testUpload", { parameters: arg } , 1);
   	
	xajax.callback.global.onComplete = function()
	 	{
	 	
		};   

}

/***************************************************
 * MISE A JOUR PROFIL
 **************************************************/ 
function validprofil(form/*,chp,chpformats*/)
{
var valid=true;

   //email
   if(valid==true)
     {
     validemail = ValidateField(form, 'email', '#COURRIEL');
     if(validemail==false)
       {
       valid=false;
       alert('L\'adresse e-mail renseignée ne possède pas le bon format.');
       document.forms[form].email.focus();
       }
     }
   
   //passwords
   if((document.forms[form].pass.value=='' || document.forms[form].pass2.value=='')  && valid==true)      
     {
     valid=false;
     alert('Vous devez renseigner le mot de passe et le confirmer.');
     document.forms[form].pass.focus();
     }
   if(document.forms[form].pass.value!=document.forms[form].pass2.value  && valid==true)      
     {
     valid=false;
     alert('Votre mot de passe confirmé ne correspond pas à l\'original; les 2 doivent être identiques.');
     document.forms[form].pass2.focus();
     }
   //validation du reste
   if(valid==true)
     {
     valid=ValidateForm(form,chp,chpformats);
     }
   if(valid==true)
      {
    	xajax.config.requestURI='./ajax_main.php';
    
   	
   	var arg=Array();
   	arg[0]=xajax.getFormValues(form);
   	
		//alert(arg[0]);
   	
      oldvalue = document.getElementById('sendbtn').value;
   	document.getElementById('sendbtn').value = 'Veuillez patienter...';
   	document.getElementById('sendbtn').disabled = 'disabled'; 
        	
   	xajax.call("validprofil", { parameters: arg } , 1);
   	
   	xajax.callback.global.onComplete = function()
   	 	{
   	 	document.getElementById('sendbtn').value = oldvalue;
   	 	document.getElementById('sendbtn').disabled = '';
   		};     
      
      }
  
return valid;
}


/****************************************************
 * DEVENEZ ACTEUR
 ***************************************************/ 
function registration_submit(chp,chpformats)
{
	valid=true;

	
	// agreements
   if(document.getElementById('agreements').checked==false)
		{
		alert("Vous n'avez pas coché la case qui certifie que les informations sont exactes.");
		valid=false;
		}
	// case tel cochée et par de tel rentré
	if(valid==true && document.forms['form'].contact)
	  {
     contact = document.forms['form'].contact.options[document.forms['form'].contact.selectedIndex].value;
     if(contact=='telephone' && !document.forms['form'].teldom.value)
      {
      alert("Pour être contacté par téléphone, vous devez en indiquer un.");
      valid=false;
      }
     
     
     }
   //validation du reste
   if(valid==true)
     {
     valid=ValidateForm('form',chp,chpformats);
     }	
   	
   if(valid==true)
      {
    	xajax.config.requestURI='./ajax_main.php';
   	
   	var arg=Array();
   	arg[0]=xajax.getFormValues('form');
   	
      oldvalue = document.getElementById('sendbtn').value;
   	document.getElementById('sendbtn').value = 'Veuillez patienter...';
   	document.getElementById('sendbtn').disabled = 'disabled'; 
        	
   	xajax.call("registration_submit", { parameters: arg } , 1);
   	
   	xajax.callback.global.onComplete = function()
   	 	{
   	 	document.getElementById('sendbtn').value = oldvalue;
   	 	document.getElementById('sendbtn').disabled = '';
   		};     
      
      }
	


}


