
var combodropoffsetY=2; //offset of drop down menu vertically from default location (in px)
var combozindex=100;

if (combodropimage!=""){
	combodropimage='<img class="downimage" src="'+combodropimage+'" title="Select an option" />';
}
function dhtmlselect(selectid){
	var selectbox=document.getElementById(selectid);
	document.write('<div id="dhtml_'+selectid+'" class="dhtmlselect"><span val="0" id="'+selectid+'_val">'+selectbox.title+"</span> "+combodropimage+'<div id="box_'+selectid+'" class="dropdown">');
	for (var i=0; i<selectbox.options.length; i++){
		if (selectid == 'ddprix') {
			document.write('<a href="#" prix="'+selectbox.options[i].value+'">'+selectbox.options[i].text+'</a>');
		}
		else{
			document.write('<a href="#" km="'+selectbox.options[i].value+'">'+selectbox.options[i].text+'</a>');
		}
	}
	document.write('</div></div>');
	selectbox.style.display="none";
	var dhtmlselectbox=document.getElementById("dhtml_"+selectid);
	dhtmlselectbox.style.zIndex=combozindex;
	combozindex--;
	if (typeof selectwidth!="undefined")
		dhtmlselectbox.style.width=selectwidth;
	if (typeof optionwidth!="undefined")
		dhtmlselectbox.getElementsByTagName("div")[0].style.width=optionwidth;
	dhtmlselectbox.getElementsByTagName("div");
	if (combodropimage!="")
		dhtmlselectbox.getElementsByTagName("img")[0];
	dhtmlselectbox.onmouseover=function(){
		this.getElementsByTagName("div")[0].style.display="block";
	};
	dhtmlselectbox.onmouseout=function(){
		this.getElementsByTagName("div")[0].style.display="none";
	};
};

function modif(val, selectid){
	if (selectid == 'ddprix') {
		document.getElementById(selectid+'_val').innerHTML = val + '';
		$('#ddprix_val').attr('val', val);
		document.getElementById('box_ddprix').style.display="none";
	}
	if (selectid == 'ddkm') {
		document.getElementById(selectid+'_val').innerHTML = val + '000';
		$('#ddkm_val').attr('val', val);
		document.getElementById('box_ddkm').style.display="none";
	}
	
	if ($('#ddprix_val').attr('val') != '0' && $('#ddkm_val').attr('val') != '0') {
		calcul();	
	}
};

function calcul(){
		var economie = $('#ddkm_val').attr('val') * 1000 * (0.07 *  $('#ddprix_val').attr('val') / 1.4);
		var reduction =  $('#ddkm_val').attr('val') * 1000 * 0.10916667;
		document.getElementById('economie').innerHTML = Math.round(economie/10)*10 + ' $';
		document.getElementById('reduction').innerHTML = Math.round(reduction)+ ' kg';
	};
