function form_submit() {
/*
	Set listselect and listunselect var and submit the form.
*/
/*
	if (document.form1.sms_nb_submit.value == 0) {
	    document.form1.sms_nb_submit.value = 1;
	} else {
   		alert('Veuillez patienter ...');
		exit();
	}
*/
	var i = 0;//offset var
	var NbCol1 = document.form1.listselect.length;
	var NbCol2 = document.form1.listunselect.length;
	document.form1.listselect_post.value = '';
	document.form1.listunselect_post.value = '';

    for(a=0; a<NbCol1; a++)
		document.form1.listselect_post.value += "|" + document.form1.listselect.options[a].text;

    for(a=0; a<NbCol2; a++)
		document.form1.listunselect_post.value += "|" + document.form1.listunselect.options[a].text;

	document.form1.submit();
}



function setfocus(zone){
/*
	Change the focus of the checkbox
*/

	if (zone=='account')
	{
		document.form1.payment_choice[1].checked=true;
		document.form1.payment_choice[0].checked=false;

	}

	if (zone=='card')
	{

		document.form1.payment_choice[1].checked=false;
		document.form1.payment_choice[0].checked=true;
	}
	
	return true;
}



function countCharAndCost() {

/*
	Check the lenght of the textarea
*/

		var nbchar = document.form1.nbchar;
		var mes	= document.form1.elements["mess"];
		var taillMax=143;
		var nbRC=0;
		var i=0;

		while(i<mes.value.length){
			var ind=mes.value.indexOf("\r\n",i);
			if (ind>=0){
				nbRC++;
				i=ind+1;
			}
			i++;
		}

		nbRC = nbRC - (nbRC*2);

		if ((mes.value.length+nbRC) > taillMax){
			mes.value=mes.value.substring(0,taillMax-nbRC);
		}

		nbchar.value = mes.value.length + nbRC;

		if (nbchar.value == taillMax+1){
			mes.value=mes.value.substring(0,mes.value.length-2);
			nbchar.value=taillMax;
		}

} 


//Fonctions de gestion de la page des sms
function DeplacerNouveau(l1)
{
  var pers='';
  var regtel = /^[0-9]{6,20}$/;
  var regpers = /^([A-Za-z0-9\- éèàçäëïöüâêîôû]{1,30})$/;
  var tel_ok = true;//Le regex est ok par défaut
  
  //On vérifie le nombre max de sms
  if (document.form1.nbsms.value >= 10) {

	alert("Vous ne pouvez pas envoyer un message à plus de 10 destinataires en même temps");
	tel_ok = false;
  }
  
  
  //On vérifie le format du numéro de téléphone saisi
	if ( !regtel.test(document.form1.tel.value) ) {
		alert("Le numéro de téléphone doit comporter entre 6 et 20 chiffres maximum");
		tel_ok = false;
	}	
		

  //On vérifie le format du nom
  if ( !regpers.test(document.form1.pers.value) ) {

			alert("Le nom du correspondant ne doit comporter que des chiffres, des lettres, tirets ou espaces pour un total de 30 caractères maximum.");
			tel_ok = false;
  }

	
  if (tel_ok == true) {
	  // On vérifie s'il ne s'agit pas d'un nouveau destinataire
  	if (document.form1.tel.value!="" && document.form1.tel.value!="06"  && document.form1.tel.value!="00")
  	{
    	// On rajoute 1 au compteur de SMS
    	document.form1.nbsms.value=l1.options.length+1;

			//On rajoute le nouveau numéro
			if (document.form1.pers.value=='Nom - facultatif -')
				pers='non précisé';
			else 
				pers=document.form1.pers.value;
			
    	var nouvo = document.form1.tel.value + " | " + pers;
    	o=new Option(nouvo,l1.options.length+1);
    	l1.options[l1.options.length]=o;
		
			document.form1.tel.value="06";
			document.form1.pers.value="Nom - facultatif -";
  	}
  }
}

function Deplacer(l1,l2,ope)
{
//L1 = liste de gauche, L2= liste de droite

  for (i=0; i < l1.options.length ; i++)
          {
          if (l1.options[i].selected && l1.options[i]!= "" )
            {
               o=new Option(l1.options[i].text,l1.options[i].value);
               l2.options[l2.options.length]=o;
               l1.options[i]=null;
               i = i -1 ;
            }
          }
		  
    // On rajoute ou enleve 1 au compteur de SMS		  
    if (ope=='ajout') document.form1.nbsms.value=l2.options.length;
    else document.form1.nbsms.value=l1.options.length;
}


function DeleteFromList(l1)
{
	//Delete one element from a list
	//On récupère les données
	tab_value = new Array(255);
	tab_text = new Array(255);
	p=0;//number of unselected elements
	
	//Save the unselected elements
	for (i=0; i < l1.options.length ; i++) {

 		if (!l1.options[i].selected && l1.options[i] != "" ) {
 
 	  	tab_value[p] = l1.options[i].value;
 		tab_text[p]  = l1.options[i].text;
    	p++;
	 }
	}

	//Erase the list
	for (k=0; k < l1.options.length ; k++) {
		
		l1.options[k] = null;
	//	k = k - 1;
	}

	//Create the new list
  for (j=0; j <= p ; j++) {
   
	 	o=new Option(tab_text[j],tab_value[j]);
    l1.options[j]=o;
  }
  
  //Update the number of elements
	l1.options.length=p; 
	
	// On rajoute ou enleve 1 au compteur de SMS		  
  document.form1.nbsms.value=p;
}


function DeplacerTout(l1,l2,ope)
{
	for (i=0; i < l1.options.length ; i++) {

		o=new Option(l1.options[i].text,l1.options[i].value);
        l2.options[l2.options.length]=o;
        l1.options[i]=null;
        i = i -1 ;
    }

  	// On rajoute ou enleve 1 au compteur de SMS
  	if (ope=='ajout') document.form1.nbsms.value=l2.options.length;
  	else document.form1.nbsms.value=l1.options.length;
}


function jump( form, elt, i, n ) {
/*
	Function used for the pincodes in sms.php
*/
	if ( document.forms[ form ].elements[ elt + i ].value.length == n ) {
			document.forms[ form ].elements[ elt + (i+1) ].focus() ;
	} 
}


