//site dev
//var urlHatier='';
//site validation
//var urlHatier='http://webmaster.hatier.hachette-livre.fr';
//site production
var urlHatier='http://sed.enseignants.editions-hatier.fr';

// breadcrumb
var myBreadcrumb = {
	1:"\311cole",
	100:"Toutes les classes", 101:"PS", 102:"MS", 103:"GS", 104:"CP", 105:"CE1", 106:"CE2", 107:"CM1", 108:"CM2",
	2:"Coll\350ge",
	201:"Fran\347ais", 202:"Latin-Grec", 203:"Math\351matiques", 204:"SVT", 205:"Physique-Chimie", 206:"Histoire-G\351ographie", 207:"\311ducation civique", 208:"Anglais", 209:"Espagnol",
	3:"Lyc\351e",
	301:"Fran\347ais", 302:"Latin-Grec", 303:"Math\351matiques", 304:"SVT", 305:"Physique-Chimie", 306:"Philosophie", 307:"Histoire-G\351ographie", 308:"SES", 309:"Anglais", 310:"Espagnol", 311:"Allemand",
	4:"Documentaliste",
	401:"Coll\350ge", 402:"Lyc\351e",
	5:"P\351dagogie/Formation/Concours"
}

// Redimensionnement dynamique du site.
var BASE_HEIGHT = 581;
var TALL_HEIGHT = 791;
var H_DELTAS = [0, 143, 148];

// encode fragment d'url
var __encodeCtx = {
	1:"Ecole", 2:"College", 3:"Lycee", 4:"Documentaliste", 5:"PedagogieConcoursFormation"
}
var __encodeSec = {
	1:{ 100:"Tout", 101:"PS", 102:"MS", 103:"GS", 104:"CP", 105:"CE1", 106:"CE2", 107:"CM1", 108:"CM2" },
	2:{ 201:"Francais", 202:"LatinGrec", 203:"Mathematiques", 204:"SVT", 205:"PhysiqueChimie", 206:"HistoireGeographie", 207:"EducationCivique", 208:"Anglais", 209:"Espagnol" },
	3:{ 301:"Francais", 302:"LatinGrec", 303:"Mathematiques", 304:"SVT", 305:"PhysiqueChimie", 306:"Philosophie", 307:"HistoireGeographie", 308:"SES", 309:"Anglais", 310:"Espagnol", 311:"Allemand" },
	4:{ 401:"College", 402:"Lycee" },
	5:{ 500:"Tout" }
}
var __encodeTi = {
	1:"Ouvrages", 2:"Collections", 3:"Numeriques"
}

// decode fragment d'url
var __decodeCtx = {
	Ecole:"1", College:"2", Lycee:"3", Documentaliste:"4", PedagogieConcoursFormation:"5"
}
var __decodeSec = {
	Ecole:{ Tout:"100", PS:"101", MS:"102", GS:"103", CP:"104", CE1:"105", CE2:"106", CM1:"107", CM2:"108" },
	College:{ Francais:"201", LatinGrec:"202", Mathematiques:"203", SVT:"204", PhysiqueChimie:"205", HistoireGeographie:"206", EducationCivique:"207", Anglais:"208", Espagnol:"209" },
	Lycee:{ Francais:"301", LatinGrec:"302", Mathematiques:"303", SVT:"304", PhysiqueChimie:"305", Philosophie:"306", HistoireGeographie:"307", SES:"308", Anglais:"309", Espagnol:"310", Allemand:"311" },
	Documentaliste:{ College:"401", Lycee:"402" },
	PedagogieConcoursFormation:{ Tout:"500" }
}
var __decodeTi = {
	Ouvrages:"1", Collections:"2", Numeriques:"3"
}


function popupCentree(width,height,url,nomFenetre,withScroll) {
	var sw=screen.width;
	var sh=screen.height;
	var x=(sw-width)/2;
	var y=(sh-height)/2;
	var settings='toolbar=NO,status=NO,resizable=YES,directories=no,';
	if(withScroll == 0) {
		settings+='scrollbars=NO,';
	} else {
		settings+='scrollbars=YES,';
	}
	settings+='width='+width+',height='+height+',left='+x+',top='+y;
	var fenetre = window.open(url,nomFenetre,settings);
	fenetre.focus();
	return true;
}
function rand(number) {
	return Math.ceil(rnd()*number);
}
function rnd() {
	rnd.seed=(rnd.seed*9301+49297)%233280;
	return rnd.seed/(233280.0);
}
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function popupIdentification(idcontcomp) {
	//return popupCentree(456,217, urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationDepuisMenu'+'&nocache='+rand(99999999),'inscription',0);
	return popupCentree(456,217, 'identification.php?contcomp='+idcontcomp,'identification',0);
	}
function popupFeuilletage(codarisc) {
	return popupCentree(456,217, 'identification.php?codarisc='+codarisc,'identification',0);
	}
function popupListeCatalogue() {
	return popupCentree(720,323, 'liste_feuilletage.php',0);
}
function popupTelechargement(idcontcomp) {
	//return popupCentree(456,217, urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationDepuisMenu'+'&nocache='+rand(99999999),'inscription',0);
	return popupCentree(456,217, 'identification.php?contcomp='+idcontcomp+'&dontreload=true','identification',0);
	}
function popupAvis(type, id, label, ssid) {
	//return popupCentree(456,217, urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationDepuisMenu'+'&nocache='+rand(99999999),'inscription',0);
	return popupCentree(800,600, 'contact.php?id='+id.toString()+'&type='+type.toString()+'&titre='+encodeURIComponent(label.toString())+'&PHPSESSID='+ssid.toString() ,'Avis',0);
	}
function popupMotdePasse() {
	return popupCentree(456,217, urlHatier+'/siteseducation/SiteSED?controlerCode=CtlIdentification&requestCode=afficherDemandeMotDePasse&wCode=1','MotdePasse',0);
	}
function popupIdentificationPourCELE(idArticle) {
	//return popupCentree(456,217,urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE'+'&nocache='+rand(99999999),'inscription',0);
	popUrl='/identification.php?dest=cele';
	var tmpArticle = idArticle.toString();
	if((tmpArticle != "undefined") && (tmpArticle != "")) {
		popUrl+='&article='+tmpArticle;
	}
	return popupCentree(456,227, popUrl,'identification',1);
}
function popupInscriptionPourCELE(idArticle) {
	return popupCentree(456,217,urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE&TXT_IDARTLPC='+idArticle+'&nocache='+rand(99999999),'inscription',0);
}
function popupInscriptionPourMotdePassePerdu() {
	return popupCentree(456,217,urlHatier+'/siteseducation/SiteSED?controlerCode=CtlIdentification&requestCode=afficherDemandeMotDePasse&wCode=1','inscription',0);
}
function popupAjoutDansPanierAvecAuthentification(idArticle) {
	url = urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE&TXT_IDARTLPC=' + idArticle+'&nocache='+rand(99999999);
	window.open(url, 'inscription', 'width=456,height=217',0);
}
function popupAjoutDansPanierSansAuthentification(idInternaute, idArticle) {
	url = urlHatier+'/siteseducation/SiteCELE?controlerCode=CtlPanier&requestCode=ajouterArticlePanierCele&idsitcom=017&TXT_IDACCIED=' + idInternaute + '&TXT_IDARTLPC=' + idArticle;
	window.open(url, 'inscription', 'width=456,height=217',0);
}

function recharge() {
	document.location = urlHatier+"/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=rafraichirPageAppelante&nocache="+rand(99999999);
}
function popupEnvoiMail(urlEnvoiMail,email,objet,modifiable) {
	return popupCentree(600,360, urlEnvoiMail +'&adresseMailDestinataire='+email+'&objetMail='+objet+'&objetModifiable='+modifiable+'&nocache='+rand(99999999),'mail',0);
}
function popupContact() {
	return popupCentree(800,600, 'contact.php','Contact_FAQ',1);
}
function popupFooter(typeContenu) {
	var targetUrl=typeContenu + ".php";
	var targetTitle="";
	switch (typeContenu) {
		case "hatier":
			targetTitle = "\311ditions_Hatier";
			targetUrl = "editions-hatier.php";
		break;
		case "mentions":
			targetTitle = "Mentions_l\350gales";
		break;
		case "foreign-rights":
			targetTitle = "Foreign_rights";
			targetUrl = "http://www.editions-hatier.fr/droits.htm";
		break;
		case "aide":
			targetTitle = "Aide";
		break;
		case "contact":
			targetTitle = "Contact";
			targetUrl = "contact.php?target=contact";
		break;
		default:
			targetTitle = "Mentions_l\350gales";
		break;
	}
	return popupCentree(800,600, targetUrl,targetTitle,1);
}
function popupPanier(idAccesInternaute, current_book) {
	targetUrl = urlHatier + "/siteseducation/SiteCELE?controlerCode=CtlPanier&requestCode=";
	var tmpBook = current_book.toString();
	if((tmpBook != "undefined") && (tmpBook != "")) {
		targetUrl += "ajouterArticlePanierCele&idsitcom=017&TXT_IDACCIED="+idAccesInternaute+"&TXT_IDARTLPC="+current_book;
	} else {
		targetUrl += "afficherPanier";
	}
	targetTitle = "MonPanier";
	return popupCentree(800,800, targetUrl,targetTitle,1);
}
function popupCommande(idAccesInternaute) {
	targetUrl = urlHatier + "/siteseducation/SiteCELE?controlerCode=CtlEcrDeConnexion&requestCode=afficherListeOffres&idsitcom=017&TXT_IDACCIED="+idAccesInternaute;
	targetTitle = "MaCommande";
	return popupCentree(800,800, targetUrl,targetTitle,1);
}
function popupCatalogue() {
	targetUrl = "catalogue.php";
	targetTitle = "MaCommandeCatalogue";
	return popupCentree(510,550, targetUrl,targetTitle,1);
}
function popupContPayant(idContComp) {
	targetUrl = "emailform.php?contcomp=" + idContComp;
	targetTitle = "MaCommande";
	return popupCentree(456, 217, targetUrl,targetTitle,0);
}
function popupCELE(idArticle) {
	targetUrl = 'panier.php?dest=cele&article='+idArticle;
	return popupCentree(456,227, targetUrl,'panier',1);
}
function Inscription() {
	window.location="../dsi/inscription.php";
}
function Deconnexion() {
	return popupCentree(456,217, '../systeme/logout.php','Deconnexion',0);
}


function changeHeight(divid, newH) {
	var element = document.getElementById(divid);
	if (newH != element.offsetHeight) {
		element.style.height = newH +"px";
	}
}

function switchToTallHeight() {
	changeHeight("wrapper", TALL_HEIGHT);
	changeHeight("rightcolumn", (TALL_HEIGHT-H_DELTAS[1]));
	__setFlashPlayerHeight("maincontent", (TALL_HEIGHT-H_DELTAS[2]));
	return false;
}
function switchToBaseHeight() {
	__setFlashPlayerHeight("maincontent", (BASE_HEIGHT-H_DELTAS[2]));
	changeHeight("rightcolumn", (BASE_HEIGHT-H_DELTAS[1]));
	changeHeight("wrapper", BASE_HEIGHT);
	return false;
}

function encodeCtxSec(result, ctx, sec) {
	if (!ctx || 'null'==ctx || !__encodeCtx[ctx])
		return false;
	result[result.length] = encodeURIComponent(__encodeCtx[ctx]);
	if (!sec || 'null'==sec || !__encodeSec[ctx][sec])
		return false;
	result[result.length] = encodeURIComponent(__encodeSec[ctx][sec]);
	return true;
}
function encodeArt(result, ti) {
	if (!ti || 'null'==ti)
		return false;
	var chunks= ti.split('.');
	if (! __encodeTi[ chunks[0] ])
		return false;

	result[result.length] = __encodeTi[ chunks[0] ];
	result[result.length] = chunks[1];
	return true;
}


function decodeCtx(result, ctx) {
	if (! (ctx in __decodeCtx))
		return false;
	result[result.length] = 'ctx:"'+ __decodeCtx[ctx] +'"';
	return true;
}
function decodeSec(result, ctx, sec) {
	if (! (sec in __decodeSec[ctx]))
		return false;
	result[result.length] = 'sec:"'+ __decodeSec[ctx][sec] +'"';
	return true;
}
function decodeArt(result, kind, code) {
	if (! (kind in __decodeTi))
		return false;
	if ((! code) || isNaN(code)) {
		result[result.length] = 'ti:"null"';
	} else {
		result[result.length] = 'ti:"'+ __decodeTi[kind] +'.'+ code +'"';
	}
	return true;
}

function display_Nouveaute(){
	document.getElementById("nouveaute_numerique_cont").style.display="block";
	document.getElementById("nouveaute_numerique_cont_empty").style.display="none";
}

function hide_Nouveaute(){
	document.getElementById("nouveaute_numerique_cont").style.display="none";
	document.getElementById("nouveaute_numerique_cont_empty").style.display="block";
}

// controle de la visibilite du badge "manuels numeriques"
function updateDigitalBadge(ctx, sec) {
	if (!ctx || 'null'==ctx || !__encodeCtx[ctx]) {
		hide_Nouveaute();
	} else if (!sec || 'null'==sec || !__encodeSec[ctx][sec]) {
		hide_Nouveaute();
	} else {
		display_Nouveaute();
	}
}
