/**********************************************************************
*
*                     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.dom_url = null;// element dom du lien
    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.image_url_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_url.href = this.image_url_array[ this.numero ] ;
        this.dom_url.title = this.image_url_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_url.href = this.image_url_array[ this.numero ] ;
        this.dom_url.title = this.image_url_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.dom_url = document.getElementById("carroussel_url");
        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'); /*!!! */ 
            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.image_url_array = url_array;// cette  variable est défini dans la page html
    carroussel.methode = 1;//active le timer
    if( carroussel.methode == 1 ){
            setInterval("carroussel.switchPresentationTimer()" , 4000 );
    }
    
}
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;
}
function switchTri( formulaire , valeur )
{
    formulaire.tri.value=valeur;
    formulaire.submit();
}
function switchOnglet(onglet){
    var ongletdescriptif = window.document.getElementById('DESCRIPTIF'); 
    var ongletInformations = window.document.getElementById('INFORMATIONS'); 
    var ongletacces = window.document.getElementById('ACCES');
    var onglet1 = window.document.getElementById('ONGLET1');
    var onglet2 = window.document.getElementById('ONGLET2');
    var onglet3 = window.document.getElementById('ONGLET3');
    switch (onglet) {
    case 'DESCRIPTIF':
        ongletdescriptif.style.display="block";
        ongletInformations.style.display="none";
        if( ongletacces != null ){
        	ongletacces.style.display="none";
        }
        if( onglet3 != null ){
             onglet3.className="etiquette";
        }
        onglet2.className="etiquette";
        onglet1.className="etiquette selected";
        break;
    case 'ACCES':
        ongletdescriptif.style.display="none";
        ongletInformations.style.display="none";
        if( ongletacces != null ){
        	ongletacces.style.display="block";
        }
        onglet2.className="etiquette";
        onglet1.className="etiquette";
        if( onglet3 != null ){
        	onglet3.className="etiquette selected";
        	initialize();
        }
        break;
    case 'INFORMATIONS':
        ongletdescriptif.style.display="none";
        ongletInformations.style.display="block";
        if( ongletacces != null ){
        	ongletacces.style.display="none";
        }
        if( onglet3 != null ){
        	onglet3.className="etiquette";
        }
        onglet2.className="etiquette selected";
        onglet1.className="etiquette";
        break;

    default:
        break;
    }
    replacecacher()
}
function switchOngletListe(onglet){
	var ongletListe = window.document.getElementById('LISTE'); 
	var ongletMap = window.document.getElementById('MAP_LISTE'); 
	var onglet1 = window.document.getElementById('ONGLETLISTE'); 
	var onglet2 = window.document.getElementById('ONGLETMAPLISTE'); 
	var ongletPaginationHaut = window.document.getElementById('TRI_HAUT'); 
	var ongletPaginationBas = window.document.getElementById('PAGINATION'); 
	switch (onglet) {
	case 'LISTE':
		ongletListe.style.display="block";
		if( ongletMap != null){
			ongletMap.style.display="none";
		}
		ongletPaginationHaut.style.visibility="visible";
		if( ongletPaginationBas != null){
			ongletPaginationBas.style.visibility="visible";
		}
		onglet1.className="etiquette selected";
		onglet2.className="etiquette";
		break;
	case 'MAP_LISTE':
		ongletListe.style.display="none";
		if( ongletMap != null){
			ongletMap.style.display="block";
		}
		ongletPaginationHaut.style.visibility="hidden";
		if( ongletPaginationBas != null){
			ongletPaginationBas.style.visibility="hidden";
		}
		onglet2.className="etiquette selected";
		onglet1.className="etiquette";
		initialize();
		break;
		
	default:
		break;
	}
}
function survolOn(picto)
{
	picto.style.display="block";
}
function survolOff(picto)
{
	picto.style.display="none";
}
var srcZoom="";
function swicthImage( src , alt , credit , zoom )
{
	var img = window.document.getElementById('IMAGE_FICHE_PRODUIT');
	var creditSpan = window.document.getElementById('CREDIT');
	img.src = src;
	img.alt = alt;
	srcZoom= zoom;
	creditSpan.innerHTML = credit;
}
function CheckFormulaireRecherche( texte , formulaire){
	 var recherche = formulaire.q;
	 if( recherche.value != texte && recherche.value !='' )
	 {
		 return true;
	 }
	 return false;
} 

function checkInput( champs , texte){
	if( champs.value =='' )
	{
		champs.value = texte;
	}
}

// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}
function HideContent(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
dd.style.display = "block";
}
function ReverseContentDisplay(d) {
if(d.length < 1) { return; }
var dd = document.getElementById(d);
AssignPosition(dd);
if(dd.style.display == "none") { dd.style.display = "block"; }
else { dd.style.display = "none"; }
}
var theTimeout=-1, animEnCours;
function opacifier(o){
	if(!o.filters && o.style && o.style.opacity){
		if(theTimeout==-1)animEnCours=o;
		if(animEnCours==o)
		{
			var oso=+o.style.opacity;
			if(oso)
			o.style.opacity=oso;
		}
		else
		{
			theTimeout=-1;
			return;
		}
	}
	theTimeout=setTimeout(function(){opacifier(o)},25);


if(o.filters && o.filters.item("DXImageTransform.Microsoft.Alpha")){
	if(theTimeout==-1)animEnCours=o;
	if(animEnCours==o){
		var oso=+o.filters.item("DXImageTransform.Microsoft.Alpha").Opacity;
		if(oso<100) {
			if(oso<34)
				oso+=1;
			else oso+=3;
			o.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=oso;
		}
		else
		{
			theTimeout= -1;
			return ;
		}
	}
	theTimeout=setTimeout(function(){opacifier(o)},25);
}
}

function cookieok(texte,obj)
{
    if ( !navigator.cookieEnabled )
    {
    	alert(texte);
    	obj.href="#";
    	return false;
    }
}
function cookieform(texte,obj)
{
    if ( !navigator.cookieEnabled )
    {
    	alert(texte);
    	return false;
    }
    return true
}

function preload_over(obj,image)
{
    obj.style.backgroundImage = 'url('+image.src+')';
    return false;
}