/*
	Auteurs : 
		Dominic Gauthier 	: 6924
		Martin Rancourt 	: 7526
		
	Dernière modification :
		Martin Rancourt 	: 2005-07-07	Optimiser le code
		Martin Rancourt		: 2005-07-19	Ajouter le system d'exeption pour le hightlight
*/
var domaine = "http://"+location.host;
var pathURL = location.pathname.toString().toLowerCase();
if (pathURL.indexOf("regions") != -1) pathURL = "/nouvelles" + pathURL.replace("/regions", "/regional");
var arrayPathURL = pathURL.split("/");
$url = document.location.href;
function construireMenu(objUl) {
	//loop dans les childs du UL
	for(var i=0;i<objUl.childNodes.length;i++) {
		//valide si le node est un LI
		if (objUl.childNodes[i].tagName == "LI") {
			//loop dans les childs du LI
			for(j=0;j<objUl.childNodes[i].childNodes.length;j++) {
				//reset la valeur de la varible qui indique si on doit sélectionné ou ouvrir l'item
				needProcess = false;
				//valide si le node est un A
				if(objUl.childNodes[i].childNodes[j].tagName == "A") {
					//Regarde si il y a un class sur le A 
					//on gère par exeption l'ouverture et la selection de l'item
					if (objUl.childNodes[i].childNodes[j].getAttribute('class') != null) {
						//Si le contenu du class se trouve dans l'url de la page
						if ($url.indexOf(objUl.childNodes[i].childNodes[j].getAttribute('class').toLowerCase()) != -1 ) {
							//On doit faire l'ouverture ou la selection de l'item
							needProcess = true;
						}
						
					// on gère automatiquement l'ouverture et la selection de l'item
					} else {
						//garde le path du lien trouvé
						var path = objUl.childNodes[i].childNodes[j].getAttribute('href').toString().toLowerCase();
						//enlève le domaine si il le contien
						if(path.indexOf(domaine) != -1){
							path = path.slice(domaine.length);
						}
						//Créé un array du path
						var arrayPath = path.split("/");
						//Garde le dernier folder du path
						if(arrayPath[(arrayPath.length-1)].indexOf(".") != -1 || arrayPath[(arrayPath.length-1)] == "") {
							var position = (arrayPath.length-2);
						} else {
							var position = (arrayPath.length-1);
						}
						//Si dernier folder de la page = le dernier folder du lien
						if(arrayPathURL[position] == arrayPath[position]) {
							needProcess = true;
						}
					}
					//Si on doit ouvrir ou sélectionner l'item
					if (needProcess) {
						//loop dans les childs du LI
						for(k=0;k<objUl.childNodes[i].childNodes.length;k++) {
							//valide si c'est un élément A
							if (objUl.childNodes[i].childNodes[k].tagName == "A") {
								// Allume le menu -> mets un class "On" au A
								objUl.childNodes[i].childNodes[k].setAttribute("className", "On");
								objUl.childNodes[i].childNodes[k].setAttribute("class", "On");
							}
							//valide si il y a un UL
							if(objUl.childNodes[i].childNodes[k].tagName == "UL") {
								//Ouvre le sous menu
								objUl.childNodes[i].childNodes[k].style.display = "block";
								//Recall la fonction pour appliquer le processus au child
								construireMenu(objUl.childNodes[i].childNodes[k]);			
								break;					
							}
						}
					}
				}
			}
		}
	}
	

}

function construireMenuRegion() {
	var regionArray=[  "/atlantique/" , "/alberta/" , "/colombie-britannique/",  "/manitoba/", "/saskatchewan/",   "/ontario/", "/abitibi/", "/bas-st-laurent/", "/cote-nord/", "/estrie/", "/gaspesie-lesiles/" ,"/ottawa/index.asp#qc" ,"/mauricie/"  ,"/montreal/" ,"/quebec/", "/saguenay-lac/" , "/ottawa/"] ; 
	var indexarray=[ 3 , 0 , 0, 0, 0 ,1 , 2 ,2 ,2 ,2 ,2 ,2 , 2 ,2 ,2 ,2  ,1  ] ; 
	var i = 0 ;
	var found = false ; 
 	var complete = $url;
	var surligner;
	while(i < 18 && found == false) {
		if( complete.indexOf(regionArray[i] ) > -1 ) {
			switchRegion(indexarray[i]);
			surligner = document.getElementById("rg" + regionArray[i]);
			surligner.setAttribute("className", "On");
			surligner.setAttribute("class", "On");
			found = true ; break ;
		}
		i ++ ;
	}
	if( complete.indexOf("cyberlettre") > -1 ) { cybLettre(); }
}

var provinces = new Array( false , false , false , false ) ;
var provinces_class = new Array("prov_ouest", "prov_ontario", "prov_quebec") ;
var provinces_li_class = new Array("li_ouest", "li_ontario", "li_quebec") ;
function switchRegion(region) {
	if(region == 3 ) return;
	provinces[region] = ! provinces[region]; 
	var elem = document.getElementById(provinces_class[region]);
	var elemLI = document.getElementById(provinces_li_class[region]);
	if (provinces[region] ==  true ) {
			elem.style.display = "block";
			elemLI.setAttribute("className", "On");
			elemLI.setAttribute("class", "On");				
	} else {
			elemLI.setAttribute("className", "");
			elemLI.setAttribute("class", "");
			elem.style.display = "none";
	}
} 
function cybLettre(){
	var complete = $url;
	var toOpen ; 
	var openWhat ; 
	if( complete.indexOf("arts-spectacles%2fcyberlettre") > -1 ) {
	 	toOpen = true ;
		openWhat = "niv1arts-spectacles" ; 
	}
	if( complete.indexOf("sports%2fcyberlettre") > -1 ) {
		toOpen = true ;
		openWhat = "niv1Sports" ; 
	}
	if(toOpen){
		var elem =  document.getElementById(openWhat) ;	
		elem.style.display = "block";
		var t0 = elem.childNodes[0] ; 
	 
	 	t0.setAttribute("class", "On");		
		t0.setAttribute("className", "On");		
		t0.style.display = "block";
		
		elem.childNodes[2].style.display = "block";
	}
}
