// JavaScript Document

// Copyright 2004 Alain Duchesneau

function modifierCookieBoutique(boutiqueActive){
	//alert("modifierCookieBoutique() = "+boutiqueActive)
	var d = new Date();d.setDate(d.getDate()+360);
	Set_Cookie("boutique",boutiqueActive,d,"/");
}

function initLayout(){
	if(arguments.length > 0){
		pageCourante = arguments[0];
	}else{
		pageCourante = getQueryVariable(top.menu,"page");
	}
	masterSwap(MM_findObj(pageCourante,top.menu.document),"in");
	/*if(typeof top.contenu.selecteur != "undefined"){
		top.contenu.selecteur.document.location.href = pageCourante + ".asp";
	}*/
}

function resetframes(nouv){
	var sectionCourante = trouveSection();
	var oldPC = pageCourante;
	pageCourante = nouv;
	if(sectionCourante == "boutique"){
		//alert("sectionCourante == "+sectionCourante);
		modifierCookieBoutique(pageCourante);
	}
	if(oldPC) masterSwap(MM_findObj(oldPC,top.menu.document),"");
	masterSwap(MM_findObj(pageCourante,top.menu.document),"in");
}

function getQueryVariable(scopeOfIt,vari) {
	var requete, variab, output
	requete = scopeOfIt.location.search.substr(1);
	variab = requete.split("&");
	for (var i=0;i<variab.length;i++) {
		var pair = variab[i].split("=");
		if (pair[0] == vari) output = pair[1];
	}
	return output; 
}
function trouveSection(){
	var section = "acc";
	var elem = top.location.pathname.split("/");
	if(elem.length > 2){
		section = elem[elem.length-2];
	}
	return section;
}
function buildState(d,s){
	var dataOut;
		switch(s) { 
			case "in":
				dataOut = "b_in-" + d + ".png";
break
			case "over":
				dataOut = "b_over-" + d + ".png";
break
			default:
				dataOut = "b-" + d + ".png";
		}
		return dataOut;
}


function swapImage(qui){
	masterSwap(qui,"over")
}

function swapRestore(qui){
	masterSwap(qui,"")
}

function masterSwap(qui,targetState){
	window.status = typeof qui
	var img, state, objImg, pathImg;
	img = qui.id;
	if((pageCourante!=img && sectionCourante!=img) || targetState=="in"){
		state = buildState(img,targetState);
		objImg = MM_findObj(img,top.menu.document);
		pathImg = objImg.src.substring(0,objImg.src.lastIndexOf("/")) + "/";
		objImg.src = pathImg + state;
		//objImg.src = URLimages + state;
	}
}

function findIT(qui,scopeOfIt){
	if(document.getElementById){
		return scopeOfIt.document.getElementById(qui);
	}else if (document.all){
		return scopeOfIt.document.all[qui];
	} else {
		return scopeOfIt.document.images[qui];
	}
}

function testReloadFrame(){
	var bypass=getQueryVariable(top.contenu.selecteur,'bypass');
	var qindex=getQueryVariable(top.contenu.selecteur,'index');
	var qOffset=getQueryVariable(top.contenu.selecteur,'offset');
	if(!bypass && !qOffset && !qindex && typeof top.contenu.description.resetAfficheImage != "undefined"){
		top.contenu.description.resetAfficheImage();
	}
	/*var pathCourant = document.location.pathname.split("/") || "index.asp"
	var pageCourante = pathCourant.toString().split(".")
	//alert(pageCourante[pageCourante.length-1])
	top.menu.initLayout(pageCourante[0])
	*/
}

