function addZero(x,n,separator) {
	n = isNaN(n) ? 2 : n;
	if(!separator) {
		separator = translation.decimalSeparator;
	}
	/**
	 * Gestion des nombres décimaux :
	 * 	On extrait la partie décimale pour l'ajouter à la fin.
	 */
	x = new String(x);
	tmp = x.indexOf(separator,0)>-1 ? x.substr(x.indexOf(separator,0)) : '';
	
	x = parseInt(x,10);
	if(!isNaN(x) && x<Math.pow(10,n)) {
		z = (x>0) ? x*10 : 10;
		for(z;z<Math.pow(10,n);z*=10) {
			x = '0'+x;
		}
	}
	return x+tmp;
}

function formatNumber(n,decimalNumber,separator) {
	n = (isNaN(n)||n==null) ? '0' : new String(n);
	// Secure parameter for prevent infinite loop
	currentParse = 0;
	maxParse = 10;
	if(!decimalNumber) {
		decimalNumber = 2;
	}
	if(!separator) {
		separator = n.indexOf(',')>-1 ? ',' : '.';
	}
	
	if(n.search(/\./)>-1) {
		reg = new RegExp('(\\d*)(\\d{3,3})((['+translation.integerSeparator+']{0,1}\\d{3,3})*)(\\.\\d*){1,1}','g');
		while(n.search(/\d{4,}( {1,1}\d{3,3})*(\.\d*){1,1}/)>-1&&currentParse<maxParse) {
			n = n.replace(reg,'$1'+translation.integerSeparator+'$2$3$5');
			currentParse++;
		}
		
		if(n.indexOf(separator,0)>-1) {
			n=n.substr(0,n.indexOf(separator,0)+decimalNumber+1);
		}
		
		for(i=n.length-1;i<(n.indexOf(separator,0)+decimalNumber);i++) {
			n = n+'0';
		}
	}
	else {
		reg = new RegExp('(\\d*)(\\d{3,3})((['+translation.integerSeparator+']{1,1}\\d{3,3})*)','g');
		while(n.search(/\d{4,}( {1,1}\d{3,3})*/)>-1&&currentParse<maxParse) {
			n = n.replace(reg,'$1'+translation.integerSeparator+'$2$3');
			currentParse++;
		}
		n = n+separator;
		for(i=0;i<decimalNumber;i++) {
			n = n+'0';
		}
	}
	
	n = n.replace(/(\d*)\.(\d*)/,'$1'+translation.decimalSeparator+'$2');
	return n;
}

function setLinksWithAnchor(element) {
	//back to top scroll function. Any link with a hash (#) will scroll to that id on the page
	$(element).find('a[href*=#]').click(function() {
		if(
			location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')&&
			location.hostname == this.hostname
		) {
			var $target = $(this.hash);
			var hash = this.hash.slice(1);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if($target.length) {
				targetOffset = $target.offset().top;
				$('div.provider,div.product').removeClass('focus');
				if(hash=='top') {
					$('div.provider:first').addClass('focus');
				}
				else {
					$target.parents('div.provider,div.product').addClass('focus');
				}
				$('html,body').animate(
					{scrollTop: targetOffset},
					500,
					'linear',
					function() {
						location.hash = hash;
					}
				);
				return false;
			}
		}
		return true;
	});
}

function setOpacity(obj, opacity) {
	opacity = (opacity>=100) ? 99.999 : opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function sortIntegerAsc(x,y) {
	rtn = parseInt(x,10)-parseInt(y,10);
	return (rtn == 0) ? 0 : Math.abs(rtn)/rtn;
}

function sortIntegerDesc(x,y)	{
	rtn = parseInt(y,10)-parseInt(x,10);
	return (rtn == 0) ? 0 : Math.abs(rtn)/rtn;
}
