if (document.location.hash && document.location.hash.substr(1,1)=='/') {
	document.location=document.location.hash.substr(1);
} else {
	var lsth = '';
	function hashCheck() {
		var thsh = document.location.hash.substr(1);
		if (lsth !== thsh) {lsth = thsh;hashBrowse(lsth,0);}
	}
	setInterval(hashCheck, 100);
}

var base = '/';

function checkall(f,n,b) {
	for (var i = 0; i < f.elements.length; i++) {
		while (f.elements[i].name != n+"[]" && f.elements[i].name != n) {
			i++;
			if (!f.elements[i]) {
				return;
			}
		}
		f.elements[i].checked = b;
	}
}

function currencies(c) {
	if (c) {
		$.getScript(base+'scripts/currencies/?c='+c);
	} else {
		document.getElementById('currencies_more').className=(document.getElementById('currencies_more').className=='open'?'':'open');
	}
}

function features(p,i) {
	$('#features').fadeTo('fast', 0.01, function() {
		$('#features').load(p+'?a=features&p='+i, function() {
			$('#features').fadeTo('fast', 1);
		});
	});
}

function formatNumber(v,d) {
	v = v.replace(/,/,'.');
	v = parseFloat(v);
	if (isNaN(v)||v=='') v = 0;
	return v.toFixed(d);
}

function formSubmit(f) {
	$.post($('#'+f).attr("action"), $('#'+f).serializeArray(), function(){}, 'script');
}

function formToUrl(f) {
	return $('#'+f).attr("action")+'?'+$('#'+f).serialize();
}

function hashBrowse(q,s) {
	if ($('#ads').length) $('#ads').mbStopAutoscroll();
	h = document.domain;
	if(q.indexOf(h)!=-1)q=q.substr(q.indexOf(h)+h.length);
	$('#col-main').load(q+(q.indexOf('?')!=-1?'&':'?')+'ajax', function() {
		if ($('#ajaxtitle')) document.title=$('#ajaxtitle').html();
		if (s) {
			o = s==1?140:460;
			if ($(window).scrollTop() > o) $('html,body').animate({scrollTop: o}, 500);
		}
	});
	location.hash = q;
	lsth = location.hash.substr(1);
	pageTracker._trackPageview(q);
}

function hashRefresh() {
	hashBrowse((document.location.hash&&document.location.hash.substr(1,1)=='/')?location.hash.substr(1):window.location.pathname);	
}

function productViews(p,o) {
	$('#product_img').load(base+'scripts/zoom/?a=refresh&p='+p+'&o='+o);
	arrImages = document.getElementById('product_views').getElementsByTagName("a");
	for (i = 0; i < arrImages.length; i++) {
		arrImages[i].className = arrImages[i].id == 'product_views_'+o ? 'actif' : '';
	}
}

function productZoom(p,o) {
	window.open(base+'scripts/zoom/?p='+p+'&o='+o, '_blank', 'width=400,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-400)/2)+',scrollbars=no,resizable');
}

function showElement(d,b) {
	if (document.getElementById && document.getElementById(d)) { objLayer = document.getElementById(d); } else if (document.all && document.all[d]) { objLayer = document.all[d]; } else if (document.layers && document.layers[d]) { objLayer = document.layers[d]; } else { objLayer = null; }
	if (objLayer !== null) { objLayer.style.display = (b == 1) ? 'block' : 'none'; }
}

function trackPrices(l,c) {
	f = document.getElementById('frm_tracks_format').value;
	a = document.getElementById('frm_tracks').getElementsByTagName('span');
	for (var i = 0; i < a.length; i++) {
		p = document.getElementById(a[i].id.replace(/_price/,'_'+f));
		a[i].innerHTML = (p?'('+(l=='EN'?c+'&nbsp;':'')+p.value+(l=='FR'?'&nbsp;'+c:'')+')':'');
		document.getElementById(a[i].id.replace(/_price/,'')).disabled = (p?0:1);
	}
}

function widgetUpdate(u,b) {
	if (b || $('#widget').contents().find('#elapsed').length==0) {
		if (document.getElementById('widget').src != u) {
			document.getElementById('widget').src = u;
		}
	}
}
