
function donner_title(chaine)
{
	var resultat=chaine.match(/<title>(.*)<\/title>/i);
	if(resultat && resultat.length==2)
		return resultat[1];
	else
		return false;
}

function donner_description(chaine)
{
	var resultat=chaine.match(/(<meta[^>]*\/>)/gi);
	for(i=0;resultat && i<resultat.length;i++)
	{
		if(resultat[i].search(/name="description"/i)!=-1 && resultat[i].search(/content="[^"]*"/i)!=-1)
		{
			var content=resultat[i].match(/content="([^"]*)"/i);
			if(content && content.length==2)
				return content[1];
		}
	}
	return false;
}

function donner_keywords(chaine)
{
	var resultat=chaine.match(/(<meta[^>]*\/>)/gi);
	for(i=0;resultat && i<resultat.length;i++)
	{
		if(resultat[i].search(/name="keywords"/i)!=-1 && resultat[i].search(/content="[^"]*"/i)!=-1)
		{
			var content=resultat[i].match(/content="([^"]*)"/i);
			if(content && content.length==2)
				return content[1];
		}
	}
	return false;
}

function donner_avatar(chaine)
{
	var resultat=chaine.match(/<embed src="([^"]*)"/i);
	if(resultat) return resultat[1];
	return false;
}

var test_avatar = function(xhr) {
	avatar_courant = donner_avatar(document.getElementById('avatar').innerHTML);
	avatar_suivant = donner_avatar(xhr.responseText);
	if(avatar_courant!=avatar_suivant) {
		removeChildrenFromNode('avatar');
		/** AVEC utilisation de la fonction RunFLash pour l'avatar **/
		//code = xhr.responseText.substring((xhr.responseText.indexOf('<noscript>'))+10, xhr.responseText.indexOf('</noscript>'));
		/** SANS utilisation de la fonction RunFLash pour l'avatar **/
		code = xhr.responseText;
		try {
			document.getElementById('avatar').innerHTML = code;
		}
		catch(e) {
			//alert('test avatar: ' + e);
		}
	}
	return true;
}

var maj_titre_description = function(xhr) {
	code_titre=donner_title(xhr.responseText);
	code_description=donner_description(xhr.responseText);
	code_keywords=donner_keywords(xhr.responseText);
	try {
		if(code_titre) document.title = code_titre;
		if(navigator.appName != 'Microsoft Internet Explorer') {
			for(i=0;i<document.getElementsByTagName('title').length;i++) {
				document.getElementsByTagName('title')[i].firstChild.nodeValue=code_titre;
			}
		}
		for(i=0;i<document.getElementsByTagName('meta').length;i++)
		{
			if(document.getElementsByTagName('meta')[i].getAttribute('name')=='keywords' && code_keywords)
				document.getElementsByTagName('meta')[i].setAttribute('content',code_keywords);
			if(document.getElementsByTagName('meta')[i].getAttribute('name')=='description' && code_description)
				document.getElementsByTagName('meta')[i].setAttribute('content',code_description);
		}
	}
	catch(e) {
		//alert('maj titre et description: ' + e);
	}
	return true;
}

function affiche_avatar(ou, id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		with(xhr) {
			xhr.setCible('avatar');
			razData();
			ajouteData(ou, id);
			xhr.sendAndLoad('avatar/index.php', "GET", test_avatar);
		}
		return true;
	} else {
		return false;
	}
}

function affiche_description(ou, id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		with(xhr) {
			razData();
			ajouteData(ou, id);
			xhr.sendAndLoad('referencement.php', "GET", maj_titre_description);
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actualite_pied(type, id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		with(xhr) {
			xhr.setCible('actualite_pied');
			razData();
			ajouteData(type, id);
			xhr.sendAndLoad('actualite_pied.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actualite_liste(id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actualite_liste');
		with(xhr) {
			xhr.setCible('actualite_liste');
			razData();
			if(id.length==1)
				ajouteData('etage_courant', id);
			else
				ajouteData('place_courante', id);
			xhr.sendAndLoad('actualite_liste.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actu_liste_code_promo(pos) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actualite_liste');
		with(xhr) {
			xhr.setCible('actualite_liste');
			razData();
			ajouteData('position_code', pos);
			xhr.sendAndLoad('actualite_liste.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actualite_liste_annonceur(id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actualite_liste');
		with(xhr) {
			xhr.setCible('actualite_liste');
			razData();
			ajouteData('annonceur_courant', id);
			xhr.sendAndLoad('actualite_liste.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actualite_hasard() {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actu_hasard_produit');
		with(xhr) {
			xhr.setCible('actu_hasard_produit');
			xhr.sendAndLoad('actualite_hasard.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_produits(id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actu_hasard_produit');
		with(xhr) {
			xhr.setCible('actu_hasard_produit');
			razData();
			ajouteData('annonceur_courant', id);
			xhr.sendAndLoad('produit.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_produits_position(n) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actu_hasard_produit');
		with(xhr) {
			xhr.setCible('actu_hasard_produit');
			razData();
			ajouteData('position_produit', n);
			xhr.sendAndLoad('produit.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_actualites_position(n) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('actu_hasard_produit');
		with(xhr) {
			xhr.setCible('actu_hasard_produit');
			razData();
			ajouteData('position', n);
			xhr.sendAndLoad('actualite_annonceur.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_plan(ou, id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('plan');
		with(xhr) {
			setCible('plan');
			razData();
			ajouteData(ou, id);
			sendAndLoad('plan.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_recherche(ou, id) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('recherche');
		with(xhr) {
			setCible('recherche');
			razData();
			ajouteData(ou, id);
			sendAndLoad('recherche.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_recherche_typee(type, valeur) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('recherche');
		with(xhr) {
			setCible('recherche');
			razData();
			ajouteData(type, valeur);
			sendAndLoad('recherche.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_annonceur_similaire(type, valeur) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('boutiques');
		with(xhr) {
			setCible('boutiques');
			razData();
			ajouteData(type, valeur);
			sendAndLoad('boutiques.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_boutiques_locales(type, valeur) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('boutiques');
		with(xhr) {
			setCible('boutiques');
			razData();
			ajouteData(type, valeur);
			sendAndLoad('boutiques.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_bandeau() {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('bandeau');
		with(xhr) {
			setCible('bandeau');
			razData();
			sendAndLoad('bandeau.php', "GET");
			//sendAndLoad('bandeau.php', "GET", affich);
		}
		return true;
	} else {
		return false;
	}
}

function affiche_menu() {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		with(xhr) {
			setCible('menu');
			razData();
			sendAndLoad('menu.php', "GET");
		}
		return true;
	} else {
		return false;
	}
}

function affiche_place(id,rafraichir_plan) {
	return false;
	if(affiche_place.arguments.length<2)
		rafraichir_plan=true;
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('place_annonceur');
		try{
			document.getElementById('place_annonceur').style.filter='blendTrans(Duration=3)';
		} catch(e){}
		with(xhr) {
			setCible('place_annonceur');
			razData();
			if(id.length==1)
				ajouteData('etage_courant', id);
			else
				ajouteData('place_courante', id);
			sendAndLoad('place.php', "GET");
		}
		if(rafraichir_plan)
			if(!affiche_plan('place_courante', id)) return false;
		if(!affiche_boutiques_locales('place_courante', id)) return false;
		if(!affiche_actualite_hasard()) return false;
		if(!affiche_avatar('place_courante', id)) return false;
		if(!affiche_description('place_courante', id)) return false;
		if(document.getElementById('div_annonceur_similaire')!=null)
			if(!affiche_recherche('place_courante',id)) return false;
		if(!affiche_bandeau()) return false;
		return true;
	} else {
		return false;
	}
}

function affiche_annonceur(id,rafraichir_plan) {
	return false;
	if(affiche_annonceur.arguments.length<2)
		rafraichir_plan=true;
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		removeChildrenFromNode('place_annonceur');
		try{
			document.getElementById('place_annonceur').style.filter='blendTrans(Duration=3)';
		}
		catch(e){}
		with(xhr) {
			setCible('place_annonceur');
			razData();
			ajouteData('annonceur_courant', id);
			sendAndLoad('annonceur.php', "GET");
		}
		if(rafraichir_plan)
			if(!affiche_plan('annonceur_courant', id)) return false;
		if(!affiche_annonceur_similaire('annonceur_courant', id)) return false;
		if(!affiche_avatar('annonceur_courant', id)) return false;
		if(!affiche_actualite_hasard()) return false;
		if(!affiche_description('annonceur_courant', id)) return false;
		if(!affiche_recherche('annonceur_courant',id)) return false;
		if(!affiche_bandeau()) return false;
		return true;
	} else {
		return false;
	}
}

function affiche_annonceur2(id,objet) {
	xhr=new XHRConnection();
	test=xhr.getInit();
	if(test) {
		with(xhr) {
			setCible('');
			razData();
			url = objet.split("?");
			query = url[1];
			liste_var = query.split("&");
			for(var i=0; i<liste_var.length; i++) {
			    key_val= liste_var[i].split("=");
				ajouteData(key_val[0], key_val[1]);
			}
			sendAndLoad(url[0], "GET");
		}
		return affiche_annonceur(id);
	} else {
		return false;
	}
}

