<!-- -
	
/***** Styleswitcher : pour l'agrandissement et la réduction de la taille du texte *****/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title){
	  	a.disabled = false;
		}
    }
  }
  createCookie("style", title, 365);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function() {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

function clearInput() {
   document.getElementById("query").value = "";
}

function setCriteria( newValue, action, method, query, imgId ) {
  document.getElementById("criteriaImg").src = document.getElementById(imgId).src;
  document.getElementById("criteria").value = newValue;
                    
  document.getElementById('search').action= action;
  document.getElementById('search').method= method;
  document.getElementById('query').name= query;
  document.getElementById('criteriaList').style.display = 'none';
}
                  
function changeBeforeSubmit() {
  if( document.getElementById("query").value == "Chercher" ) {
    document.getElementById("query").value = "";
  } else if ( document.getElementById("criteria").value == "section" ) {
    document.getElementById("query").value = document.getElementById("query").value + " site:www.usherbrooke.ca/" + getHost();
  } else {
    document.getElementById("query").value = replaceAccents( document.getElementById("query").value );
  }
}

function getHost() {
  var urlString = window.location;
  var urlparts = urlString.toString().split("/");
  var host = "";
  
  for( var i = 0; i < urlparts.length; i++ ) {
    if( urlparts[i].toLowerCase() == "www.usherbrooke.ca" ) {
      if( urlparts[i + 1] ) {
        host = urlparts[i + 1];
      }
      
      i = urlparts.length;
    }
  }
  
  return( host );
}

function replaceAccents( withAccents ) {
  var withoutAccent = "";
  withoutAccent = withAccents.replace( /[àáâãäå]/g , "a" );
  withoutAccent = withoutAccent.replace( /[æ]/g, "ae" );
  withoutAccent = withoutAccent.replace( /[þÞ]/g, "b" );
  withoutAccent = withoutAccent.replace( /[ç]/g, "c" );
  withoutAccent = withoutAccent.replace( /[ð]/g, "d" );
  withoutAccent = withoutAccent.replace( /[éèêë]/g, "e" );
  withoutAccent = withoutAccent.replace( /[ìíîï]/g, "i" );
  withoutAccent = withoutAccent.replace( /[ñ]/g, "n" );
  withoutAccent = withoutAccent.replace( /[òóôõöø]/g, "o" );
  withoutAccent = withoutAccent.replace( /[ß]/g, "s" );
  withoutAccent = withoutAccent.replace( /[ùúûü]/g, "u" );
  withoutAccent = withoutAccent.replace( /[ýýÿ]/g, "y" );
  withoutAccent = withoutAccent.replace( /[ÀÁÂÃÄÅ]/g, "A" );
  withoutAccent = withoutAccent.replace( /[Æ]/g, "AE" );
  withoutAccent = withoutAccent.replace( /[þ]/g, "B" );
  withoutAccent = withoutAccent.replace( /[Ç]/g, "C" );
  withoutAccent = withoutAccent.replace( /[Ð]/g, "D" );
  withoutAccent = withoutAccent.replace( /[ÈÉÊË]/g, "E" );
  withoutAccent = withoutAccent.replace( /[ÌÍÎÏ]/g, "I" );
  withoutAccent = withoutAccent.replace( /[Ñ]/g, "N" );
  withoutAccent = withoutAccent.replace( /[ÒÓÔÕÖØ]/g, "O" );
  withoutAccent = withoutAccent.replace( /[ÙÚÛÜ]/g, "U" );
  withoutAccent = withoutAccent.replace( /[Ý]/g, "Y" );
    
  return ( withoutAccent );
}

// -->

