//POUR AFFICHER UNE GRANDE IMAGE SOUS FORME D'UNE POPUS
function PopupImage(img) { 
	w=open("",'image','weigth=toolbar=no,scrollbars=no,resizable=no, width=320, height=272, left=300, top=200'); 
	w.document.write("<HTML><BODY topmargin='0px' bottommargin='0px'   leftmargin='0px' rightmargin='0px' onblur=\"window.close();\"><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=320 height=272><param name=movie value='animations/diaporama.swf'><param name=quality value=high><embed src='animations/diaporama.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=320 height=272></embed></object>"); 		
	w.document.write("</BODY></HTML>"); 
	w.document.close(); 
} 
function mailtoo(email){    
	chaine_mail = "mailto:"+email+"?subject=" + document.title;      
	chaine_mail += "&body="; 
	chaine_mail += ""; location.href = chaine_mail;     
} 
function changeImages(name,image) {
	document.images[name].src=image
}

var ancien="";

function getHTTPObject() {
	var xmlhttp;
	if (navigator.appName=="Microsoft Internet Explorer")
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		//il faut remplacer "Microsoft.XMLHTTP" par "Msxml2.XMLHTTP.5.0" pour eviter l'erreur system : 1072896748 
		//pour les actentuées : test réussi est validé		
	else 	
		var xmlhttp = new XMLHttpRequest();  

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      	xmlhttp = false;
      }
    }
  return xmlhttp;
}
var http = getHTTPObject();

var marked_row = new Array;

function setPointer_(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	if (theAction=='over'){
		if (document.getElementById(theRow).className!=theMarkColor)
			document.getElementById(theRow).className=thePointerColor
	}
	if (theAction=='out'){
		if (document.getElementById(theRow).className!=theMarkColor)
			document.getElementById(theRow).className=theDefaultColor
	}
	if (theAction=='click'){
		if (document.getElementById(theRow).className!=theMarkColor){
			document.getElementById(theRow).className=theMarkColor
		}else{
			document.getElementById(theRow).className=thePointerColor			
		}
			
	}
	
	return true
} // end of the 'setPointer()' function


function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



function setCheckboxColumn(theCheckbox){
    if (document.getElementById(theCheckbox)) {
        document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
        }
    } else {
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
            if (document.getElementById(theCheckbox)) {
                document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
            }
        }
    }
}


function isExtsAllowed(path) {
	var lastDot = path.lastIndexOf("."); //index of last dot, the extension will follow this dot
	if(lastDot != 1) { //if we found a dot, that means we have an extension
		var fileExts = path.substring(lastDot + 1, path.length).toLowerCase();
		//loop through array of allowed extensions and check if this one is allowed
		for(var i = 0; i < allowedExts.length; i++) {
			//alert (fileExts);
			if(fileExts == allowedExts[i]) //if the extension is in the list of allowed
				return true;
		}
	}
	
	return false;
}


function messages(champs,libelle){
	if (document.getElementById(champs).value==""){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le champs "+libelle+" ne doit pas être une chaine vide !"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}

function adad(champs,libelle){
	if (isNaN(document.getElementById(champs).value)){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le champs "+libelle+" n'est pas une valuer numérique !"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}



function afficher_msg(champs,libelle,container){
	if (document.getElementById(champs).value==""){
		document.getElementById(container).style.visibility='visible'
		document.getElementById(container).innerHTML="<b>"+libelle+" :</b> ne doit pas être une chaine vide"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById(container).style.visibility='hidden'
		return true
	}
}

function afficher_adad(champs,libelle,container,vide_non){
	if (isNaN(document.getElementById(champs).value)){
		document.getElementById(container).style.visibility='visible'
		document.getElementById(container).innerHTML="<b>"+libelle+" :</b> n'est pas une valuer numérique"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById(container).style.visibility='hidden'
		return true
	}
}




function checkdate(champs,libelle,container){
	if(!isDate(document.getElementById(champs).value)  ) {
		document.getElementById(container).style.visibility='visible'
		document.getElementById(container).innerHTML="La date <b>"+libelle+"</b> n'est pas valide"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById(container).style.visibility='hidden'
		return true
	}
}

function isDate(d) {
	// Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
	// Par Romuald
	
	if (d == "") // si la variable est vide on retourne faux
		return false;
	
	e = new RegExp("^[0-9]{1,2}\-[0-9]{1,2}\-([0-9]{2}|[0-9]{4})$");
	
	if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
		return false; // Si pas bon, retourne faux

	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	j = parseInt(d.split("-")[0], 10); // jour
	m = parseInt(d.split("-")[1], 10); // mois
	a = parseInt(d.split("-")[2], 10); // année

	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) {
		if (a < 89)	a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a+=1900;
	}

	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 28;

	// Nombre de jours pour chaque mois
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);

	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}

function dateinf(champ1,champ2,message,champs,container){
	var reg=new RegExp("/", "g");
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	
	date1=document.getElementById(champ1).value.replace(reg,"-")
	date2=document.getElementById(champ2).value.replace(reg,"-")
	
	var date1 = dato(date1,"-");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var date2 = dato(date2,"-");

	date1 = Date.parse(date1);
	date2 = Date.parse(date2);
	
	//if (date1 == date2) { return true;}
	if (date1 < date2){
		document.getElementById(container).style.visibility='visible'
		document.getElementById(container).innerHTML=message
		document.getElementById(champs).value=''
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById(container).style.visibility='hidden'
		return true
	}

}


function visibilite(thingId){
	var targetElement;
	targetElement = document.getElementById(thingId) ;
	if (ancien!=""){
		document.getElementById(ancien).style.display = "none"
		document.getElementById(ancien).style.visibility = "hidden"
	}
	if (targetElement.style.display == "none"){
		targetElement.style.display = "" ;
		targetElement.style.visibility = "visible" ;
	} else {
		targetElement.style.display = "none" ;
		targetElement.style.visibility = "hidden" ;
	}
	ancien=thingId

}

var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

function checkmail(champs,libelle){
	if ( !filter.test(document.getElementById(champs).value) ){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="L'adresse email du champ "+libelle+" n'est pas valide "
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}


function comparerdates(date1,date2){
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	var date1 = dato(date1,"-");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var date2 = dato(date2,"-");

	date1 = Date.parse(date1);
	date2 = Date.parse(date2);

	//if (date1 == date2) { return true;}
	if (date1 > date2){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="La date début doit être inférieure ou égal (<=) à la date fin"
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}

}
function dato(date,sep){
	var elem = date.split(sep); 
	jour = elem[0]; 
	mois = elem[1]; 
	annee = elem[2]; 
	return annee+"/"+mois+"/"+jour
}

function dateact(date1,date2){
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	var date1 = dato(date1,"-");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var date2 = dato(date2,"-");

	date1 = Date.parse(date1);
	date2 = Date.parse(date2);

	//if (date1 == date2) { return true;}
	if (date1 > date2){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="La date début doit être supérieure ou égal (<=) à la date d'ajourd'hui"
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}

}

function DateSystem (){
		d= new Date();
		d.setDate(d.getDate());
		strDay = (d.getDate()<10?"0":"")+d.getDate();
		month = d.getMonth()+1;
		strMonth = (month<10?"0":"")+month;
		strDate = ""+strDay+"-"+strMonth+"-"+d.getFullYear();	
		return strDate;
}



function mailtooo(email,titre){
	chaine_mail = "mailto:"+email+"?subject=" + titre;      
	chaine_mail += "&body="; 
	chaine_mail += ""; location.href = chaine_mail;     
} 


function combo_text(champs){
	return document.getElementById(champs).options[document.getElementById(champs).selectedIndex].text	
}

function combo_remove(champs){
    var x=document.getElementById(champs)
    x.remove(x.selectedIndex)	
}

function chawaib(chaine){
	var chawa=new RegExp("'", "g");
	return chaine.replace(chawa,"\'")
}

function obj(objet){
	return document.getElementById(objet)
}

function cacher(objet){
	document.getElementById(objet).style.visibility='hidden';	
	document.getElementById(objet).style.display='none';
}
function montrer(objet){
	document.getElementById(objet).style.visibility='visible';	
	document.getElementById(objet).style.display='block';
}

function montrer_avec_message(objet,message){
	document.getElementById(objet).style.visibility='visible';	
	document.getElementById(objet).style.display='block';
	document.getElementById(objet).innerHTML=message
}

function remplacer(chaine1,chaine2,champs){
	var reg=new RegExp(chaine1, "g");	
	return document.getElementById(champs).value.replace(reg,chaine2)
}

function cible(page){
	document.location=page
}

function radioCliked(form,champ) { 
var r = false; 
var d = document.getElementById(form); 

for(var i=0; i<d.length; i++) { 

   for(var k=0; k<d.length; k++) { 
     if(d[k].type=='radio' && d[k].name==champ) { 
       for(var j=0; j<d[champ].length; j++) 
       if(d[champ][j].checked) 
          r = d[champ][j].value; 
       } 
     } 


} 
	return r?r:0; 
} 


function ckeck_div(container_id,nbr,champs,chaine){	
	var divs = document.getElementById(container_id).getElementsByTagName('span');
	for (var i=0;i<divs.length;i++){
		if(divs[i].id.substr(0,nbr)==champs){
			divs[i].innerHTML = chaine;
		}
	}
	return true;
 }

function change_prix(container_id,nbr,champs,prix_ht,remise){
	var divs = document.getElementById(container_id).getElementsByTagName('span');
	for (var i=0;i<divs.length;i++){
		if(divs[i].id.substr(0,nbr)==champs){			
			//alert(eval(divs[i].innerHTML*taux/base))
			//valeur=eval((eval(divs[i].innerHTML)*taux)/base)
			if (divs[i].innerHTML!='-' && divs[i].innerHTML!=''){
				divs[i].innerHTML = (eval(prix_ht)-eval(divs[i].innerHTML*remise/100)).toFixed(2);
			}
		}
	}
	return true;
 }

function change_prix_(container_id,nbr,champs,prix_ht,remise){
	var divs = document.getElementById(container_id).getElementsByTagName('span');
	for (var i=0;i<divs.length;i++){
		if(divs[i].id.substr(0,nbr)==champs){			
			//alert(eval(divs[i].innerHTML*taux/base))
			//valeur=eval((eval(divs[i].innerHTML)*taux)/base)
			if (divs[i].innerHTML!='-' && divs[i].innerHTML!=''){
				divs[i].innerHTML = (eval(prix_ht)+eval(divs[i].innerHTML*remise/100)).toFixed(2);
			}
		}
	}
	return true;
 }


List_combo = new Array();

function RemplirCombo(champ,libelle,valeur,division,classe,largeur){
	var sel="";
	sel ="<select size='1' name='"+champ+"' id='"+champ+"' class='"+classe+"' style='width="+largeur+"px' OnChange=\"RemplirComboo('"+champ+"','Tous les emplacements',sltvil.value,sltsup.value,'divemp','','90%');\" >";
		// Parcourir le tableau
		sel= sel + "<option value=0>"+libelle+"</option>";
		for (var i=0;i<List_combo.length;i++){
		  // tester si la ligne du tableau (Sous-catégorie) correspond r la valeur de la catéhorie
		  if (List_combo[i][1]==valeur){
			// Ajouter une rubrique sous-catégorie au variable SEL
			sel= sel + "<option value="+List_combo[i][0]+">"+List_combo[i][2]+"</option>";
		  }
		}
	sel=sel+"</select>";
	// Modifier le DIV scat par la nouvelle List r partir du variable SEL
	obj(division).innerHTML=sel;
}

List_comboo = new Array();
function RemplirComboo(champ,libelle,valeur1,valeur2,division,classe,largeur){
	var sel="";
	sel ="<select size='1' name='"+champ+"' id='"+champ+"' class='"+classe+"' style='width="+largeur+"px'>";
		// Parcourir le tableau
		sel= sel + "<option value=0>"+libelle+"</option>";
		for (var i=0;i<List_comboo.length;i++){
		  // tester si la ligne du tableau (Sous-catégorie) correspond r la valeur de la catéhorie
		  if (List_comboo[i][0]==valeur1 && List_comboo[i][1]==valeur2){
			// Ajouter une rubrique sous-catégorie au variable SEL
			sel= sel + "<option value="+List_comboo[i][2]+">"+List_comboo[i][3]+"</option>";
		  }
		}
	sel=sel+"</select>";
	// Modifier le DIV scat par la nouvelle List r partir du variable SEL
	obj(division).innerHTML=sel;
}


function messages_panier(champs,message,textasli){
	if (document.getElementById(champs).value==""){
		document.getElementById('id_message_panier').innerHTML=message
		document.getElementById(champs).value=''
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_message_panier').innerHTML=textasli
		return true
	}
}

function cacher_objet(objet){
	document.getElementById(objet).style.visibility='hidden'
}

function montrer_objet(objet){
	document.getElementById(objet).style.visibility='visible'
}

// JavaScript Document


function Mask_adad_sahih(e) { 
// if aEvent is null, means the Internet Explorer event model, 
// so get window.event. 
	var IE5 = false; 
	if (!e) var e = window.event; 
	if (e.keyCode) { IE5= true; code = e.keyCode;} 
	else if (e.which) code = e.which ;
//test du code
	if (code < 48 || code > 57) {
		if(IE5) e.returnValue = false;
		else e.preventDefault();
	}
}


function newsla(champ,libelle){
	if ( obj(champ).value==libelle ) {
		obj(champ).value=""
	}else if (obj(champ).value==""){
		obj(champ).value=libelle
	}
}
