// affiche le code promo
function showBR (id_hide, id_show, url) {
	document.getElementById(id_hide).style.display = 'none';
	document.getElementById(id_show).style.display = 'block';

	sitemarchand = top.window.open(url);
	sitemarchand.blur();
	top.window.focus();
}

/* Cookie, inscription newsletter */
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

/*
** nom : nom du cookie a traiter
** script_name : nom de la page sur laquelle a été appele la fonction
** cookie_domain : le(s) domaine(s) sur lequel va être présent le cookie
** id_race : si le popup est appelé depuis race_fiche_chien.php
** id_eshop_landing : on recupere l'id_eshop de la page d'arrivée d'un internaute
*/
function LireCookie(nom, script_name, cookie_domain, id_race, id_eshop_landing)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	var race = '';
	var eshop = '';

	// race_fiche_chien.php
	if (id_race != '') {
		race = 'id_chien='+ id_race +'&amp;';
	}

	// race_fiche_chien.php
	if (id_eshop_landing != '') {
		eshop = 'id_eshop='+ id_eshop_landing +'&amp;';
	}

	//alert(race);
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) {
			if (getCookieVal(j) != 'true') {
				// on appel la thickbox pour inscription newsletter
				$(document).ready(function() {
				//tb_show('', 'template/popupEmail.php?height=306&amp;width=500&amp;page=' + script_name, 'false');
				// pour une url réécrite avec un répertoire virtuel
				// toute variable transmises doit l'être avant TB_iframe !
				tb_show('', '/template/popupEmail.php?'+ race + eshop +'page='+ script_name +'&amp;TB_iframe=true&amp;height=320&amp;width=515&amp;modal=true', 'false');			
				});
				
				// on modifie la valeur du cookie
				var origine = new Date();
				origine.setTime(origine.getTime() + (60 * 60 * 24 * 30 * 1000 * 12)); // un an
				ModifCookie(nom,'true',origine, '/', cookie_domain);
			}
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;

	function ModifCookie (nom,valeur,expire,path,domaine,securise) {
	
		//document.cookie = nom + "=" + escape (valeur) + ((expire) ? "; expires=" + expire.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domaine) ? "; domain=" + domaine : "") + ((securise) ? "; secure" : "");
		document.cookie = nom + "=" + escape (valeur) + ((expire) ? "; expires=" + expire.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domaine) ? "; domain=" + domaine : "");
	}

}

// ajout favori
function addBookmark(url, title) {
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}
