/**********************************************************************
*
*					 CARROUSSEL
*					@author Eric Browet
*					Société  WEBNET
*
*********************************************************************/
/**
*TODO transformer la verifie de la presence du bouton en fonction
*TODO creation automatique des guetteurs d'evenement()onclick , onmouse etc..
*TODO auto generation des boutons;
*
**/

function Carroussel(){
	this.dom_image = null;// element dom de l'image
	this.dom_texte = null;// element dom du texte
	this.path_folder = '';// path où les images sont stocké si le path est mis a vide  on peut mettre le lien absolu ou relatif  directment dans image_name_array
	this.image_name_array = null;// tableau contenant le nom des images
	this.texte_array = null;// tableau contenant le texte associé aux images
	this.methode = 0;//( 0 = mouse 1= timer)
	this.numero = 0;// index de l'image en cours
	this.btn = new Array;// tableau des element dom servant de bouton declencheur 
	this.switchPresentation = function( numero ){
		//verifions la presence du bouton
		if( this.btn[this.numero]){
			this.btn[this.numero].style.color="#d1d1d1";// on modifie le bouton de l'ancien numero
		}
		if( numero > this.image_name_array.length || numero < 0){
			numero = 0;
		}
		this.numero = numero;
		this.dom_image.src = this.path_folder + this.image_name_array[ this.numero ] ;
		this.dom_texte.innerHTML = this.texte_array[ this.numero ];
		// verifions la presence du bouton 
		if(this.btn[ this.numero ]){
			this.btn[ this.numero ].style.color="#ffffff";//on modifie le bouton du nouveau numero
		}
	}
	this.switchPresentationTimer = function(){
		//verifions la presence du bouton
		if( this.btn[this.numero]){
			this.btn[this.numero].style.color="#d1d1d1";
		}
		this.numero ++;
		if( this.numero >= this.image_name_array.length || this.numero < 0){
			this.numero = 0;
		}
		this.dom_image.src = this.path_folder + this.image_name_array[ this.numero ] ;
		this.dom_texte.innerHTML = this.texte_array[ this.numero ];
		// verifions la presence du bouton 
		if(this.btn[ this.numero ]){
			this.btn[this.numero].style.color="#ffffff";
		}
	}
	/**
	*Function permettant de regler la transparence de la div de texte
	*
	*/
	this.setTransparentDivTexte = function (){
	
		$(this.dom_texte).setStyle({
					opacity: 0.8
					});
	
	}
	/**
	*function pour  initialiser les attributs de l'objet carroussel
	*C'est la méthode standart lorsque les elments dom qui composent
	*le carroussel sont créer avec les id standart etc..
	*/
	this.initiate = function(){
		this.dom_image = document.getElementById("carroussel_image");
		this.dom_texte = document.getElementById("carroussel_texte");
		this.setTransparentDivTexte();
		//controle si un div pour les commande a était crée si elle n'existe pas on lance alors le timer
		if( !document.getElementById( 'carroussel_commande' ) ){
			this.methode = 1;
		}else{
			commande = document.getElementById('carroussel_commande');
			btn_array = commande.getElementsByTagName('div'); /*!!! voir pour trouver une methode plus  carre*/ 
			var reg1 = new RegExp("carroussel_btn","g");
			count = btn_array.length;
			for (i = 0 ; i < count ; i++){
				if( btn_array[i].id.match( reg1 )){
					index = parseInt(btn_array[i].id.substring(14));
					this.btn[index] = btn_array[i];
				}
			}
			
		}
		
	}
	this.initiate();
}

function init(){
	carroussel = new Carroussel();
	carroussel.texte_array = texte_array;// cette  variable est défini dans la page html 
	carroussel.image_name_array = image_array;// cette  variable est défini dans la page html
	carroussel.methode = 1;//active le timer
	if( carroussel.methode == 1 ){
			setInterval("carroussel.switchPresentationTimer()" , 5000 );
	}
	
}
function code_postal( postal ){
  var text_postal ="";
   
  if( postal.length != 5 ){
    text_postal += "Saisir 5 chiffres \n";
  }
  
  if( postal.substr( 0 , 2 ) == '00'){
    text_postal += "Votre code postal commence par 00 \n";
  }
  if( text_postal !="" ){
    alert("Le code postal saisie n'est pas valide \n " + text_postal);
  }
}
// fonction a tester et vérifier avant de l'utiliser
function attributs_objet(arbo){

  	for (propriete in window.navigator) {
  		 document.write(propriete + "=" + arbo[propriete] + "<BR>");
	}
}

function test_email(my_email) {
        var new_string = new String(my_email);
        if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
                return false;
        }
        else {
                return true;
        }
}
 function alert_test_email(my_email){
   	var new_string = new String(my_email);
   	if (!new_string.match("^[\'-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$")) {
                alert("Email saisi invalide");
        }
        
 }
/*
    controle du formulaire de bulletin d'adhesion
*/
function WebnetFormBulletinCheck()
{
    var msg = '', ret;
    
    if (document.getElementById('form_bulletin_nom').value == '')
    {
        msg = msg + '\n_ Nom';
    }
    if (document.getElementById('form_bulletin_prenom').value == '')
    {
        msg = msg + '\n_ Pr\351nom';
    }
    if (document.getElementById('form_bulletin_organisation').value == '')
    {
        msg = msg + '\n_ Organisation';
    }
    if (document.getElementById('form_bulletin_type_organisation').value == '')
    {
        msg = msg + '\n_ Type d\'Organisation';
    }
    if (document.getElementById('form_bulletin_adresse').value == '')
    {
        msg = msg + '\n_ Adresse';
    }
    if (document.getElementById('form_bulletin_codepostal').value == '')
    {
        msg = msg + '\n_ Code postal';
    }
    if (document.getElementById('form_bulletin_ville').value == '')
    {
        msg = msg + '\n_ Ville';
    }
    if (document.getElementById('form_bulletin_fonction').value == '')
    {
        msg = msg + '\n_ Fonction';
    }
    if (document.getElementById('form_bulletin_mail').value == '')
    {
        msg = msg + '\n_ Email';
    }
    if (!test_email(document.getElementById('form_bulletin_mail').value))
    {
        msg = msg + '\n_ Email Invalide';
    }

    if (msg != '')
    {
        alert('Les champs suivants doivent \352tre remplis :' + msg);
        ret = false;
    }
    else
    {
        ret = true;
    }

    return ret;
}
/*
    Controle du formulaire de commande
*/
        function WebnetFormCommandeCheck()
        {
            var msg = '', ret;
            
            if (document.getElementById('form_commande_nbrexemple').value == '')
            {
                msg = msg + '\n_ Nombre d\'exemplaires';
            }
        
            if (document.getElementById('form_commande_entreprise').value == '')
            {
                msg = msg + '\n_ Entreprise';
            }
        
            if (document.getElementById('form_commande_numintra').value == '')
            {
                msg = msg + '\n_ N\260 intracommunautaire';
            }
        
            if (document.getElementById('form_commande_codeape').value == '')
            {
                msg = msg + '\n_ Code APE';
            }
        
            if (document.getElementById('form_commande_email').value == '')
            {
                msg = msg + '\n_ Adresse e-mail';
            }
            if (!test_email(document.getElementById('form_commande_email').value))
            {
                msg = msg + '\n_ Adresse e-mail invalide';
            }
            if (document.getElementById('form_commande_nom').value == '')
            {
                msg = msg + '\n_ Nom';
            }
        
            if (document.getElementById('form_commande_prenom').value == '')
            {
                msg = msg + '\n_ Pr\351nom';
            }
        
            if (document.getElementById('form_commande_adresse').value == '')
            {
                msg = msg + '\n_ Adresse';
            }
        
            if (document.getElementById('form_commande_codepostal').value == '')
            {
                msg = msg + '\n_ Code Postal';
            }
        
            if (document.getElementById('form_commande_ville').value == '')
            {
                msg = msg + '\n_ Ville';
            }
        
            if (document.getElementById('form_commande_pays').value == '')
            {
                msg = msg + '\n_ Pays';
            }
        
            if (msg != '')
            {
                alert('Les champs suivants doivent \352tre remplis :' + msg);
                ret = false;
            }
            else
            {
                ret = true;
            }
        
            return ret;
}
/*
    Controle du formulaire de contact
*/
function WebnetFormContactCheck()
{
    var msg = '', ret;
    
    if (document.getElementById('form_contact_nom').value == '')
    {
        msg = msg + '\n_ Nom';
    }
    if (document.getElementById('form_contact_prenom').value == '')
    {
        msg = msg + '\n_ Pr\351nom';
    }
    if (document.getElementById('form_contact_adr').value == '')
    {
        msg = msg + '\n_ Email';
    }
    if (!test_email(document.getElementById('form_contact_adr').value))
    {
        msg = msg + '\n_ Email Invalide';
    }
    
    if (document.getElementById('form_contact_quest').value == '')
    {
        msg = msg + '\n_ Question';
    }

    if (msg != '')
    {
        alert('Les champs suivants doivent \352tre remplis :' + msg);
        ret = false;
    }
    else
    {
        ret = true;
    }

    return ret;
}



