 //GESTION DU MENU
 sfHover = function() {
   var sfEls = document.getElementById("menu-main").getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
     sfEls[i].onmouseover=function() {
             this.className+=" sfhover";
     }
     sfEls[i].onmouseout=function() {
             this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
     }
   }
 }
 if (window.attachEvent) window.attachEvent("onload", sfHover);
 
 function	show(id)
 	{
		var	i = 1;
		while (i <= 4)
		{
			document.getElementById('tabs-' + i).style.display = 'none';
			i++;
		}
		document.getElementById(id).style.display = 'block';
	}
	
 	function	show_avis(id)
 	{
		var	i = 5;
		while (i <= 6)
		{
			document.getElementById('tabs-' + i).style.display = 'none';
			i++;
		}
		document.getElementById(id).style.display = 'block';
	}

function popup(mylink, windowname, width, height)
        {
        if (! window.focus)return true;
        var href;
        if (typeof(mylink) == 'string')
           href=mylink;
        else
           href=mylink.href;
        window.open(href, windowname, 'width='+width+',height='+height+',scrollbars=yes');
        return false;
        }

function AddUpload(){
    photos = document.getElementById('photo_div');

    if(photos.childNodes.length < 19){
        jQuery('#photo_div').append('<input type="file" name="photo[]" style="width:auto;"><br/>');
        if(photos.childNodes.length == 18){
            add_button = document.getElementById('photo_button');
            add_button.innerHTML = '';
        }
    }
}

function calcul_note(){
    var children = document.getElementById('notes').getElementsByTagName('select');
    var total = 0;
    for (var i=0; i<children.length; i++)
    {
        var note = children[i];
        if((typeof(note.name) != "undefined") && !isNaN(note.value)){
            total = total + parseInt(note.value);
        }
    }
    //children.forEach(function(element, index, array){
    //    if((typeof(element.name) != "undefined") && !isNaN(element.value)){
    //        total = total + parseInt(element.value);
    //    }
    //});
    var votre_note = total / children.length;
    document.getElementById('votre_note').innerHTML = Math.round(votre_note*2)/2;
}

function checkboxlimit(checkgroup, limit){
	var checkgroup=checkgroup
	var limit=limit
	for (var i=0; i<checkgroup.length; i++){
		checkgroup[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<checkgroup.length; i++)
			checkedcount+=(checkgroup[i].checked)? 1 : 0
		if (checkedcount>limit){
			alert("Vous pouvez sélectionner un maximum de "+limit+" modèles à comparer")
			this.checked=false
			}
		}
	}
}

function formatCurrency(num) {
            num = num.toString().replace(/\ /g,"");
            if(isNaN(num))
            num = "0";
            num = Math.floor(num*100+0.50000000001);
            num = Math.floor(num/100).toString();
            for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++){
                num = num.substring(0,num.length-(4*i+3)) + " " + num.substring(num.length-(4*i+3));
            }
            return num;
        }

// Rollover v2.0.1
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function isDefined(property) {
return (typeof property != 'undefined');
}

var rolloverInitialized = false;
function rolloverInit() {
if (!rolloverInitialized && isDefined(document.images)) {

// get all images (including all &lt;input type="image"&gt;s)
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }

// otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }

// get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('_off.') != -1) {
            var image = images[i];

// store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;

// store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;

// add onmouseover and onmouseout event handlers once the on state image has loaded
            // Safari's onload is screwed up for off-screen images; temporary fix
            if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }

// set src of on state image after defining onload event handler
            // so cached images (that load instantly in IE) will trigger onload
            image.onImage.src = image.src.replace(/_off\./, '_on.');
         }
      }
   }
   rolloverInitialized = true;
}

// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
window.attachEvent('onload', rolloverInit);
}


function goback() {
    history.go(-1);
}

