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


// breadcrumb
var myBreadcrumb = {
	1:"Maternelle",
	100:"Toutes les sections", 101:"PS", 102:"MS", 103:"GS",
	2:"\311cole",
	200:"Toutes les classes",  201:"CP", 202:"CE1", 203:"CE2", 204:"CM1", 205:"CM2",
	3:"Coll\350ge",
	300:"Toutes les classes", 301:"6e", 302:"5e", 303:"4e", 304:"3e",
	4:"Lyc\351e",
	400:"Toutes les classes", 401:"2de", 402:"1re", 403:"Terminale",
	5:"\311tudiants / Formation Continue",
	501:"\311tudiants", 502:"Formation Continue"
}

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

// encode fragment d'url
var __encodeCtx = {
	1:"Maternelle", 2:"Ecole", 3:"College", 4:"Lycee", 5:"EtudiantsFormationContinue"
}
var __encodeSec = {
	1:{ 100:"ToutesLesSections", 101:"PS", 102:"MS", 103:"GS"},
	2:{ 200:"EcoleToutesLesClasses", 201:"CP", 202:"CE1", 203:"CE2", 204:"CM1", 205:"CM2"},
	3:{ 300:"CollegeToutesLesClasses", 301:"Sixieme", 302:"Cinquieme", 303:"Quatrieme", 304:"Troisieme"},
	4:{ 400:"LyceeToutesLesClasses", 401:"Seconde", 402:"Premiere", 403:"Terminale"},
	5:{ 501:"Etudiants", 502:"FormationContinue" }
}
var __encodeTi = {
	1:"Ouvrages", 2:"Collections", 3:"Numeriques"
}

// decode fragment d'url
var __decodeCtx = {
	Maternelle:"1", Ecole:"2", College:"3", Lycee:"4", EtudiantsFormationContinue:"5"
}
var __decodeSec = {
	Maternelle:{ ToutesLesSections:"100", PS:"101", MS:"102", GS:"103"},
	Ecole:{ EcoleToutesLesClasses:"200", CP:"201", CE1:"202", CE2:"203", CM1:"204", CM2:"205" },
	College:{ CollegeToutesLesClasses:"300", Sixieme:"301", Cinquieme:"302", Quatrieme:"303", Troixieme:"304", Troisieme:"304"},
	Lycee:{ LyceeToutesLesClasses:"400", Seconde:"401", Premiere:"402", Terminale:"403"},
	EtudiantsFormationContinue:{ Etudiants:"501", FormationContinue:"502" }
}
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,';
	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(600,365, 'identification.php?contcomp='+idcontcomp,'identification',0);
	}
function popupRecupMdp(){
	return popupCentree(530,230, 'recupererMdp.php');
}

function popupProfil(){
	return popupCentree(530,230, 'profil.php');
}



function popupPourquoiSinscrire(){
	return popupCentree(530,230, 'pourquoi_sinscrire.php');
}

function popupFeuilletage(codarisc) {
	return popupCentree(456,217, 'identification.php?codarisc='+codarisc,'identification',0);
	}
function popupTelechargement(idcontcomp) {
	return popupCentree(456,217, 'identification.php?contcomp='+idcontcomp+'&dontreload=true','identification',0);
	}
function popupAvis(type, id, label, ssid) {
	return popupCentree(800,600, 'contact.php?id='+id.toString()+'&type='+type.toString()+'&titre='+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) {
	//urlHatier='http://www.enseignants.editions-hatier.fr';
	//return popupCentree(456,217,urlHatier+'/siteseducation/SiteSED?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE'+'&nocache='+rand(99999999),'inscription',0);
	targetUrl='identification.php?dest=cele';
	var tmpArticle = idArticle.toString();
	if((tmpArticle != "undefined") && (tmpArticle != "")) {
		targetUrl+='&article='+tmpArticle;
	}
	return popupCentree(456,227, targetUrl,'identification',1);
}
function popupInscriptionPourCELE(idArticle) {
	return popupCentree(845,845,'edition.php?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE&TXT_IDARTLPC='+idArticle+'&nocache='+rand(99999999),'inscription',0);
}
function popupInscriptionPourMotdePassePerdu() {
	return popupCentree(456,217,'edition.php?controlerCode=CtlIdentification&requestCode=afficherDemandeMotDePasse&wCode=1','inscription',0);
}
function popupAjoutDansPanierAvecAuthentification(idArticle) {
	targetUrl = 'edition.php?controlerCode=CtlGestionIdentification&requestCode=afficherAuthentificationPourCELE&TXT_IDARTLPC=' + idArticle+'&nocache='+rand(99999999);
	window.open(targetUrl, 'inscription', 'width=456,height=217',0);
}
function popupAjoutDansPanierSansAuthentification(idInternaute, idArticle) {
	targetUrl = 'edition.php?controlerCode=CtlPanier&requestCode=ajouterArticlePanierCele&idsitcom=017&TXT_IDACCIED=' + idInternaute + '&TXT_IDARTLPC=' + idArticle;
	window.open(targetUrl, 'inscription', 'width=456,height=217',0);
}

function recharge() {
	document.location = urlHatier+"/?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,500, '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) {
	urlHatier='';
	urlHatier+='panier.php?dest=cele&article='+idArticle;
	return popupCentree(456,227, urlHatier,'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;
}
