function GetId(id) {
	return document.getElementById(id);
}
var mou = false;
var itemCollection;

function move(e) {

	if (document.getElementById("curseur")) {
		if (mou) {

			if (navigator.appName != "Microsoft Internet Explorer") {
				GetId("curseur").style.left = e.pageX + 5 + "px";
				GetId("curseur").style.top = e.pageY + 10 + "px";
			} else {
				var pc = GetId("mickey") ? true : false;
				var decalage_y = pc ? -2 : (4 + findPos(GetId("comparo"))[1]);
				var decalage_x = pc ? -18 : (findPos(GetId("comparo"))[0] - 14);

				if (document.documentElement.clientWidth > 0) {
					GetId("curseur").style.left = 20 + event.x
							+ document.documentElement.scrollLeft + decalage_x
							+ "px";
					GetId("curseur").style.top = 10 + event.y + decalage_y
							+ "px";
				} else {
					GetId("curseur").style.left = 20 + event.x
							+ document.body.scrollLeft + decalage_x + "px";
					GetId("curseur").style.top = 10 + event.y + decalage_y
							+ "px";
				}
			}
		}
	}
}

function montre(imgurl, name, type, price, merchant_name) {
	if (document.getElementById("curseur")) {
		if (mou == false) {
			GetId("curseur").style.visibility = "visible";
			if (name != ' ') {
				GetId("curseur").innerHTML = "<span class='comparateur_infobulle_ligne1'>"
						+ name + "</span>";
				GetId("curseur").innerHTML = GetId("curseur").innerHTML
						+ "<br \><div style=height:5px;clear:both;'></div><span class='comparateur_infobulle_ligne2'> "
						+ type + " à <span class='comparateur_infobulle_prix'>"
						+ price + "</span>";
				if (type == 'Location') {
					GetId("curseur").innerHTML = "<span class='comparateur_infobulle_prix'>"
							+ GetId("curseur").innerHTML + " / mois</span><br>";
				}
				GetId("curseur").innerHTML = GetId("curseur").innerHTML
						+ "<span class='comparateur_infobulle_ligne2'> chez <span class='comparateur_infobulle_marchand'>"
						+ merchant_name + "</span></span>";
				if (type == 'Location') {
					// salert(price);
					if (price == '9,9 &euro;') {
						GetId("curseur").innerHTML = GetId("curseur").innerHTML
								+ "<br><span class='comparateur_infobulle_prix'>avec + de 250 autres jeux</span>";
					} else {
						GetId("curseur").innerHTML = GetId("curseur").innerHTML
								+ "<br><span class='comparateur_infobulle_prix'>avec + de 300 autres jeux</span>";
					}
				}
			}
			if (imgurl != ' ') {
				if (name != ' ')
					GetId("curseur").innerHTML = GetId("curseur").innerHTML
							+ "<br \><br \>";
				GetId("curseur").innerHTML = GetId("curseur").innerHTML
						+ "<img src='" + imgurl + "'>";
			}
			GetId("curseur").innerHTML = GetId("curseur").innerHTML
					+ "<br><div style='height:8px;clear:both;'></div><span class='comparateur_infobulle_ligne3'>Cliquez sur le marchand<br>pour plus d'informations</span>";
			mou = true;
		}
	}
}

function cache() {
	if (document.getElementById("curseur")) {
		GetId("curseur").innerHTML = "";
		GetId("curseur").style.visibility = "hidden";
		mou = false;
	}
}
document.onmousemove = move;

// JavaScript Document
var xhr = null;

function getXhr() {
	if (window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
	else if (window.ActiveXObject) { // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else { // XMLHttpRequest non supportï¿½ par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		xhr = false;
	}
}

// Node cleaner
function go(c) {
	if (!c.data.replace(/\s/g, ''))
		c.parentNode.removeChild(c);
}

function clean(d) {
	var bal = d.getElementsByTagName('*');
	for (i = 0; i < bal.length; i++) {
		a = bal[i].previousSibling;
		if (a && a.nodeType == 3)
			go(a);
		b = bal[i].nextSibling;
		if (b && b.nodeType == 3)
			go(b);
	}
	return d;
}

function comparo_neuf(jvpc_id) {
}

function voir_jaquette(i, type, event) {
	var elem;
	var content;

	if (itemCollection[i].getElementsByTagName("price_img_url")[0].firstChild.nodeValue == " ")
		content = "";
	else
		content = "<img src='"
				+ itemCollection[i].getElementsByTagName("price_img_url")[0].firstChild.nodeValue
				+ "' />";

	elem = document.getElementById(type + 'elem' + i + '');
	elem.innerHTML = content;

	if (document.all) {
		elem.style.top = event.clientY + document.body.scrollTop + 20;
		elem.style.left = event.clientX + document.body.scrollLeft
				- (document.body.clientWidth / 2) + 15;
	} else {
		elem.style.top = event.pageY + 10;
		elem.style.left = event.pageX + 10;
	}

	// alert($('jaquette').innerHTML);

	if (content != "")
		elem.style.display = "block";

	return true;
}

function masque_jaquette(i, type) {
	var elem;
	elem = document.getElementById(type + 'elem' + i);
	elem.style.display = "none";
	$('jaquette').style.display = "none";
}

function bouge_jaquette(i, type, event) {
	elem = document.getElementById(type + 'elem' + i);

	if (document.all) {
		var repere_x = GetId("repere") ? (findPos(GetId("repere"))[1] + 370)
				: 15;
		// var repere_y = GetId("repere") ? 10 : 20;
		elem.style.top = event.clientY + document.body.scrollTop + 20;
		elem.style.left = event.clientX + document.body.scrollLeft
				- (document.body.clientWidth / 2) + repere_x;
	} else {
		elem.style.top = event.pageY + 10;
		elem.style.left = event.pageX + 10;
	}
	$('jaquette').style.display = "block";
}

function isdefined(variable) {
	return (typeof (window[variable]) == "undefined") ? false : true;
}

function comparo_neuf_occasion(jvpc_id) {
	var occasion_exist = 0;
	var neuf_exist = 0;
	var occasion_neuf_exist = 0;

	getXhr();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			reponse = clean(xhr.responseXML.documentElement);
			var items = reponse.getElementsByTagName("offer");
			var html = '';
			count = items.length;

			document.getElementById('comparo_neuf').innerHTML = html;
			html += '<div align="center"><table width="550" border="0" align="center" cellpadding="5" cellspacing="0" style="text-align:center;margin:auto;"><tr><td width="150px"><strong>Marchand neuf</strong></td><td width="345px"><strong>Nom du jeu</strong></td><td width="130px"><strong>Prix neuf</strong></td></tr>';

			j = 0;
			var jaquette = '';
			for (i = 0; i < count; i++) {
				idmarchand = items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue;
				if (idmarchand != 1 && idmarchand != 2 && idmarchand != 3
						&& idmarchand != 4 && idmarchand != 17
						&& idmarchand != 34) {
					itemCollection = items;
					type = "'neuf'";
					neuf_exist++;
					url = "'"
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ "'";

					if (j % 2)
						html += '<tr bgcolor="#FFFFFF" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\'" onmouseout="this.style.backgroundColor=\'#FFFFFF\'">';
					else
						html += '<tr bgcolor="#F0F0F0" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#F0F0F0\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					j++;
					html += '<td onmouseout="masque_jaquette('
							+ i
							+ ','
							+ type
							+ ');" onmouseover="voir_jaquette('
							+ i
							+ ','
							+ type
							+ ',event);" onmousemove="bouge_jaquette('
							+ i
							+ ','
							+ type
							+ ',event)" style="cursor:pointer;"><a href="'
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ '" target="_blank">';
					html += '<img src="http://www.jeuxcherche.com/medias/comp/'
							+ items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue
							+ '.gif" width="80" height="24" border="0"></a></td>';

					if (items[i].getElementsByTagName("price_name")[0].childNodes.length > 0) {
						nom = items[i].getElementsByTagName("price_name")[0].firstChild.nodeValue;
						if (nom == ' ')
							nom = document.getElementById('nom_jeu_page').innerHTML;
					} else
						nom = document.getElementById('nom_jeu_page').innerHTML;

					html += '<td class="align_left" onmouseout="masque_jaquette('
							+ i
							+ ','
							+ type
							+ ');" onmouseover="voir_jaquette('
							+ i
							+ ','
							+ type
							+ ',event);" onmousemove="bouge_jaquette('
							+ i
							+ ','
							+ type
							+ ',event)" style="cursor:pointer;"><span onmouseover="txt_change(this)" onmouseout="txt_nochange(this)">'
							+ nom + '</span></td>';
					html += '<td onmouseout="masque_jaquette(' + i + ',' + type
							+ ');" onmouseover="voir_jaquette(' + i + ','
							+ type + ',event);" onmousemove="bouge_jaquette('
							+ i + ',' + type
							+ ',event)" style="cursor:pointer;"><a href=' + url
							+ ' class="prix_prix" target="_blank">';

					prix = items[i].getElementsByTagName("price")[0].firstChild.nodeValue;

					html += prix + '</a></td></tr>';
					jaquette += '<div id="neufelem'
							+ i
							+ '" style="position:absolute;background-color:#ECECEC;border:1px solid black;display:none;padding-top:10px;padding-bottom:10px;z-index:10;"></div>';
				}
			}
			html += '</table>';
			$('comparo_neuf').innerHTML += html;
			$('jaquette').innerHTML += jaquette;

			html = '';
			$('comparo_occasion').innerHTML = html;
			html += '<div align="center"><table width="550" border="0" align="center" cellpadding="5" cellspacing="0" style="text-align: center"><tr><td width="150px"><strong>Marchand d\'occasion</strong></td><td width="345px"><strong>Nom du jeu</strong></td><td width="130px"><strong>Prix d\'occasion</strong></td></tr>';

			// html += '<div align="center"><table width="300" border="0"
			// align="center" cellpadding="5" cellspacing="0"><tr><td
			// width="150px"><strong>Marchand</strong></td><td
			// width="375px"><strong>Nom du jeu</strong></td><td
			// width="75px"><strong>Prix</strong></td></tr>';

			j = 0;
			for (i = 0; i < count; i++) {
				idmarchand = items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue;
				if (idmarchand == 1 || idmarchand == 2 || idmarchand == 3
						|| idmarchand == 4 || idmarchand == 17
						|| idmarchand == 29 || idmarchand == 34) {
					itemCollection = items;
					type = "'oca'";
					occasion_exist++;

					url = "'"
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ "'";

					if (j % 2)
						html += '<tr bgcolor="#FFFFFF" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#FFFFFF\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					else
						html += '<tr bgcolor="#F0F0F0" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#F0F0F0\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					j++;
					html += '<td style="cursor:pointer;"><a href="'
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ '" target="_blank">'
					html += '<img src="http://www.jeuxcherche.com/medias/comp/'
							+ items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue
							+ '.gif" width="80" height="24" border="0"></a></td>';

					if (items[i].getElementsByTagName("price_name")[0].childNodes.length > 0) {
						nom = items[i].getElementsByTagName("price_name")[0].firstChild.nodeValue;
						if (nom == ' ')
							nom = document.getElementById('nom_jeu_page').innerHTML;
					} else
						nom = document.getElementById('nom_jeu_page').innerHTML;

					html += '<td class="align_left" style="cursor:pointer;"><span onmouseover="txt_change(this)" onmouseout="txt_nochange(this)">'
							+ nom + '</span></td>';

					html += '<td style="cursor:pointer;"><a href=' + url
							+ ' class="prix_prix" target="_blank">';
					html += items[i].getElementsByTagName("price")[0].firstChild.nodeValue
							+ '</a></td></tr>';

					jaquette += '<div id="ocaelem'
							+ i
							+ '" style="position:absolute;background-color:#ECECEC;border:1px solid black;display:none;z-index:99"></div>';
				}
			}

			if (occasion_exist == 0)
				$('achat_bloc_occasion').style.display = 'none';
			if (neuf_exist == 0)
				$('achat_bloc_neuf').style.display = 'none';

			html += '</table>';
			$('comparo_occasion').innerHTML += html;
			$('jaquette').innerHTML += jaquette;
		}
	}
	xhr.open("GET", "http://www.jeuxvideopc.com/achat/import_xml.php?id="
			+ jvpc_id, true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	$('comparo_neuf').innerHTML = "Recherche des meilleurs prix en cours ...";
	$('comparo_occasion').innerHTML = "Recherche des meilleurs prix en cours ...";
	xhr.send(null);
}

function txt_change(elt) {
	if (document.all) {
		elt.style.textDecoration = "underline";
		elt.style.fontWeight = "bold";
	}
}

function txt_nochange(elt) {
	if (document.all) {
		elt.style.textDecoration = "none";
		elt.style.fontWeight = "normal";
	}
}

function comparo_occasion(jvpc_id) {

}

function comparo_dematerialize_physik(jvpc_id) {
	var dematerialize_exist = 0;
	var physik_exist = 0;
	var dematerialize_physik_exist = 0;

	getXhr();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			reponse = clean(xhr.responseXML.documentElement);
			var items = reponse.getElementsByTagName("offer");
			var html = '';
			count = items.length;

			document.getElementById('comparo_dematerialize').innerHTML = html;
			html += '<div align="center"><table width="550" border="0" align="center" cellpadding="5" cellspacing="0" style="text-align:center;margin:auto;"><tr><td width="150px"><strong>Marchand</strong></td><td width="345px"><strong>Nom du jeu</strong></td><td width="130px"><strong>Prix</strong></td></tr>';

			j = 0;
			var jaquette = '';
			for (i = 0; i < count; i++) {
				idmarchand = items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue;
				if (idmarchand == 55 || idmarchand == 53) {
					itemCollection = items;
					type = "'dematerialize'";
					dematerialize_exist++;
					url = "'"
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ "'";

					if (j % 2)
						html += '<tr bgcolor="#FFFFFF" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\'" onmouseout="this.style.backgroundColor=\'#FFFFFF\'">';
					else
						html += '<tr bgcolor="#F0F0F0" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#F0F0F0\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					j++;
					html += '<td onmouseout="masque_jaquette('
							+ i
							+ ','
							+ type
							+ ');" onmouseover="voir_jaquette('
							+ i
							+ ','
							+ type
							+ ',event);" onmousemove="bouge_jaquette('
							+ i
							+ ','
							+ type
							+ ',event)" style="cursor:pointer;"><a href="'
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ '" target="_blank">';
					html += '<img src="http://www.jeuxcherche.com/medias/comp/'
							+ items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue
							+ '.gif" width="80" height="24" border="0"></a></td>';

					if (items[i].getElementsByTagName("price_name")[0].childNodes.length > 0) {
						nom = items[i].getElementsByTagName("price_name")[0].firstChild.nodeValue;
						if (nom == ' ')
							nom = document.getElementById('nom_jeu_page').innerHTML;
					} else
						nom = document.getElementById('nom_jeu_page').innerHTML;

					html += '<td class="align_left" onmouseout="masque_jaquette('
							+ i
							+ ','
							+ type
							+ ');" onmouseover="voir_jaquette('
							+ i
							+ ','
							+ type
							+ ',event);" onmousemove="bouge_jaquette('
							+ i
							+ ','
							+ type
							+ ',event)" style="cursor:pointer;"><span onmouseover="txt_change(this)" onmouseout="txt_nochange(this)">'
							+ nom + '</span></td>';
					html += '<td onmouseout="masque_jaquette(' + i + ',' + type
							+ ');" onmouseover="voir_jaquette(' + i + ','
							+ type + ',event);" onmousemove="bouge_jaquette('
							+ i + ',' + type
							+ ',event)" style="cursor:pointer;"><a href=' + url
							+ ' class="prix_prix" target="_blank">';

					prix = items[i].getElementsByTagName("price")[0].firstChild.nodeValue;

					html += prix + '</a></td></tr>';
					jaquette += '<div id="dematerializeelem'
							+ i
							+ '" style="position:absolute;background-color:#ECECEC;border:1px solid black;display:none;padding-top:10px;padding-bottom:10px;z-index:10;"></div>';
				}
			}
			html += '</table>';
			$('comparo_dematerialize').innerHTML += html;
			$('jaquette').innerHTML += jaquette;

			html = '';
			$('comparo_physik').innerHTML = html;
			html += '<div align="center"><table width="550" border="0" align="center" cellpadding="5" cellspacing="0" style="text-align: center"><tr><td width="150px"><strong>Marchand</strong></td><td width="345px"><strong>Nom du jeu</strong></td><td width="130px"><strong>Prix</strong></td></tr>';

			// html += '<div align="center"><table width="300" border="0"
			// align="center" cellpadding="5" cellspacing="0"><tr><td
			// width="150px"><strong>Marchand</strong></td><td
			// width="375px"><strong>Nom du jeu</strong></td><td
			// width="75px"><strong>Prix</strong></td></tr>';

			j = 0;
			for (i = 0; i < count; i++) {
				idmarchand = items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue;
				if (idmarchand != 55 && idmarchand != 53) {
					itemCollection = items;
					type = "'physik'";
					physik_exist++;

					url = "'"
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ "'";

					if (j % 2)
						html += '<tr bgcolor="#FFFFFF" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#FFFFFF\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					else
						html += '<tr bgcolor="#F0F0F0" onclick="window.open('
								+ url
								+ ')" onmouseover="this.style.backgroundColor=\'#F9F2D5\';voir_jaquette('
								+ i
								+ ','
								+ type
								+ ',event);" onmouseout="this.style.backgroundColor=\'#F0F0F0\';masque_jaquette('
								+ i + ',' + type
								+ ');" onmousemove="bouge_jaquette(' + i + ','
								+ type + ',event)">';
					j++;
					html += '<td style="cursor:pointer;"><a href="'
							+ items[i].getElementsByTagName("link")[0].firstChild.nodeValue
							+ '" target="_blank">'
					html += '<img src="http://www.jeuxcherche.com/medias/comp/'
							+ items[i].getElementsByTagName("merchant_id")[0].firstChild.nodeValue
							+ '.gif" width="80" height="24" border="0"></a></td>';

					if (items[i].getElementsByTagName("price_name")[0].childNodes.length > 0) {
						nom = items[i].getElementsByTagName("price_name")[0].firstChild.nodeValue;
						if (nom == ' ')
							nom = document.getElementById('nom_jeu_page').innerHTML;
					} else
						nom = document.getElementById('nom_jeu_page').innerHTML;

					html += '<td class="align_left" style="cursor:pointer;"><span onmouseover="txt_change(this)" onmouseout="txt_nochange(this)">'
							+ nom + '</span></td>';

					html += '<td style="cursor:pointer;"><a href=' + url
							+ ' class="prix_prix" target="_blank">';
					html += items[i].getElementsByTagName("price")[0].firstChild.nodeValue
							+ '</a></td></tr>';

					jaquette += '<div id="ocaelem'
							+ i
							+ '" style="position:absolute;background-color:#ECECEC;border:1px solid black;display:none;z-index:99"></div>';
				}
			}

			if (physik_exist == 0)
				$('achat_bloc_physik').style.display = 'none';
			if (dematerialize_exist == 0)
				$('achat_bloc_dematerialize').style.display = 'none';

			html += '</table>';
			$('comparo_physik').innerHTML += html;
			$('jaquette').innerHTML += jaquette;
		}
	}
	xhr.open("GET", "http://lan.jeuxvideopc.com/achat/import_xml.php?id="
			+ jvpc_id, true);
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	$('comparo_dematerialize').innerHTML = "Recherche des meilleurs prix en cours ...";
	$('comparo_physik').innerHTML = "Recherche des meilleurs prix en cours ...";
	xhr.send(null);
}


