
var affiche = -1;
document.onmousemove=bouger;

function montrer(id,x,y,e) {
	if(document.getElementById(id)) {
		affiche = id;
		document.getElementById(id).style.visibility = "visible";
	}
} 

function Allopass() {
	posX = (screen.width - 355)/2;
    posY = (screen.height - 325)/2;
	var popup = window.open('achatAllopass.php','achatAllopass','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=355,height=325');
	popup.moveTo(posX, posY);
	popup.focus();
}

function PayPal() {
	posX = (screen.width - 360)/2;
    posY = (screen.height - 225)/2;
	var popup = window.open('achatPaypal.php','achatPaypal','toolbar=0,location=0,directories=0,status=0,scrollbars=1,copyhistory=0,menuBar=0,width=360,height=225');
	popup.moveTo(posX, posY);
	popup.focus();
}

function AffichePopupAllopass(pays,siteId,docId) {
	posX = (screen.width - 300)/2;
    posY = (screen.height - 340)/2;
	var popup = window.open('http://www.allopass.com/show_accessv2.php4?CODE_PAYS='+pays+'&SITE_ID='+siteId+'&DOC_ID='+docId+'&LG=fr','phone','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=300,height=340');
	popup.moveTo(posX, posY);
}

function AfficherPopup(lien) {
	posX = (screen.width - 440)/2;
    posY = (screen.height - 500)/2;
	var popup = window.open(lien,'popup','toolbar=0,location=0,directories=0,scrollbars=1,status=0,resizable=0,copyhistory=0,menuBar=0,width=440,height=500');
	popup.moveTo(posX, posY);
	popup.focus();
}

function ietruebody(){ 
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function cacher(id) {
	if(document.getElementById(id)) {
		affiche = -1;
		document.getElementById(id).style.visibility = "hidden";
	}
}

function bouger(e) {
	if(document.getElementById(affiche) && affiche != -1) {
		 if(navigator.appName!="Microsoft Internet Explorer"){
		  document.getElementById(affiche).style.left = (8+e.pageX-195)+"px";
		  document.getElementById(affiche).style.top = (18+e.pageY)+"px";
		} else{
		  document.getElementById(affiche).style.left = (8+event.clientX+ietruebody().scrollLeft-195)+"px";
		  document.getElementById(affiche).style.top = (18+event.clientY+ietruebody().scrollTop)+"px";
		}
	}
}

function calculChamps(self,total,base) {
	var nb = (trim(self.value) != "") ? parseInt(trim(self.value)) : 0;
	var tt = document.getElementById(total);
	var res = parseInt(tt.innerHTML);
	base = parseFloat(base);
	alert(nb);
	if(nb >= 0 && base >= 0 && res >= 0) {
		res = res + Math.round(base*nb);
		tt.innerHTML = res+'';
	}
}

function trim(str) {
	return str.replace(/^\s+/, "").replace(/\s+$/, "");
}

function alerte(msg) {
	alert(msg);
}

function goto(loc) {
	document.location = loc;
}

function hover4(num,color) {
	document.getElementById('a1_'+num).style.backgroundColor = color;
	document.getElementById('a2_'+num).style.backgroundColor = color;
	document.getElementById('a3_'+num).style.backgroundColor = color;
	document.getElementById('a4_'+num).style.backgroundColor = color;
}

function storeCaret(text) { // voided
}

function AddText(startTag,defaultText,endTag,textarea) {
	var nom_du_textarea = document.getElementById(textarea);
	if (nom_du_textarea.createTextRange) {
		var text;
		nom_du_textarea.focus(nom_du_textarea.caretPos);
		nom_du_textarea.caretPos = document.selection.createRange().duplicate();
		if(nom_du_textarea.caretPos.text.length>0) {
			nom_du_textarea.caretPos.text = startTag + nom_du_textarea.caretPos.text + endTag;
		}
		else {
			nom_du_textarea.caretPos.text = startTag+defaultText+endTag;
		}
	}
	else { 
		nom_du_textarea.value += startTag+defaultText+endTag;
	}
}

function number_format(number) {
	decimals = 0;
	dec_point = '.';
	thousands_sep = '.' ;
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? '.' : dec_point;
	var t = thousands_sep == undefined ? ',' : thousands_sep, s = n < 0 ? '-' : '';
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + '', j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}

function calculPrix(self,target,base) {
	nb = (trim(self.value) != "") ? Math.max(parseInt(trim(self.value)),0) : 0;
	nb = (!isNaN(nb)) ? nb : 0;
	document.getElementById(target).innerHTML =  number_format(base * nb);
}

function show(id) {
	document.getElementById(id).style.display = 'block';
}

function hide(id) {
	document.getElementById(id).style.display = 'none';
}

function trader(form,entreprise,nb,operation) {
	document.getElementById('operation').value = operation; 
	document.getElementById('compagnie').value = entreprise; 
	document.getElementById('quantite').value = document.getElementById(nb).value; 
	document.getElementById(form).submit();
}

function payer(salaire,nb,target) {
	sal = (trim(salaire) != "") ? Math.max(parseInt(trim(salaire)),0) : 0;
	sal = (!isNaN(sal)) ? sal : 0;
	document.getElementById(target).value =  number_format(sal*nb);
} 

