function init() {
	if(fonc == true) {
		var perimetre = document.getElementById('convertisseur');
		
		var a = perimetre.getElementsByTagName('a');
		var class_temp = new Array;
		
		for(i = 0; i < a.length; i++) {
			a[i].setAttribute('href', '#');
			a[i].onclick = function() {clickLien(this); return false};
		}
	}
}

function clickLien(act) {
	if(act.className.search('devise') != -1) {
		format = act.className.split('vise');
		format = format[1];
		format = format.substr(0,3);
		
		envoyer('inc/conversion.php', 'format='+format+'&amount='+amount);
	}
}

function changeValue() {
	var montant = document.getElementById('amount').value;
	if(montant != amount) {
		amount = montant;
		
		envoyer('inc/conversion.php', 'format='+format+'&amount='+amount);
	}
}

function envoyer(fichier, data) {
	if(data != "") {
		var xhr_object = null;
		
		if(window.XMLHttpRequest)
			xhr_object = new XMLHttpRequest();
		else if(window.ActiveXObject)
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
		else {
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			return;
		}
		
		xhr_object.open("POST", fichier, true);
		
		xhr_object.onreadystatechange = function anonymous() {
			if(xhr_object.readyState == 4)
				eval(xhr_object.responseText);
		}
		
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr_object.send(data);
	}
}

function addEvent(obj, type, fn) {
	if(obj.attachEvent) {
		obj['e'+'load'+fn] = fn;
		obj['load'+fn] = function(){obj['e'+'load'+fn]( window.event );};
		obj.attachEvent( 'on'+'load', obj['load'+fn] );
	}
	else {
		obj.addEventListener("DOMContentLoaded", fn, false);
		obj.addEventListener('load', fn, false);
	}
	
	return false;
}

addEvent(window, 'load', init);