<!-- -
	
/***** Styleswitcher : pour l'agrandissement et la réduction de la taille du texte *****/
function setActiveStyleSheet(title) {
  var linkList = document.getElementsByTagName("link"), i, a, main;
  for(i=0; (a = linkList[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 linkList = document.getElementsByTagName("link"), i, a;
  for(i=0; (a = linkList[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
        return a.getAttribute("title");
    }
  }
  return false;
}

/******************************************************************************/
function getPreferredStyleSheet() {
  var linkList = document.getElementsByTagName( "link" ),i, a;
  for(i=0; (a = linkList[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) {
        return a.getAttribute("title");
    }
  }
  return false;
}

/******************************************************************************/
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 ca = document.cookie.split(';'),
      i, l, c, splited;
  for( i = 0, l = ca.length;i < l; ) {
    c = ca[i++].trim();
    splited = c.split( "=" );
    if( splited.length < 2 ) {
        continue;
    }
    if( splited.shift() == name ) {
        return splited.join( "=" );
    }
  }
  return false;
}

/******************************************************************************/
window.onload = function() {
    var title = readCookie("style") || getPreferredStyleSheet();
    if( title != "normal" && title != "gros" ) {
        title = "normal";
    }
	setActiveStyleSheet(title);
    setSocialNetworkIcons();
}

/******************************************************************************/
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();
  }
}

/******************************************************************************/
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 setSocialNetworkIcons() {
  var metaList = document.getElementsByTagName( "meta" ),
      length = metaList.length,
      target, rowString, linkList, metaItem, i, name, content, splitedName, icon, div;

  // meta exists
  if( !length ) {
    return false;
  }

  // get target
  div = false;
  target = document.getElementById( "social_networks" );
  if( target ) {
    div = target;
  } else {
    target = document.getElementById( "front_right" ) ||
             document.getElementsByClassName( "content_right" );
    if( !target ) {
      return false;
    }
    if( target.length ) {
      target = target[0];
    }
  }

  // get list
  linkList = [];
  rowString = "<a href='{url}' class='sn_{icon}' target='_blank'> </a>";
  for( i = 0; i < length; ) {
    metaItem = metaList[i++];

    // name exists
    name = metaItem.getAttribute( "name" );
    if( !name ) {
      continue;
    }

    // content exists
    url = metaItem.getAttribute( "content" );
    if( !url ) {
      continue;
    }

    // split name
    splitedName = name.split( /-/ );

    // name with udes-social-[media]
    if( ( splitedName.length != 3 ) ||
        ( splitedName[0] != "udes" ) ||
        ( splitedName[1] != "link" ) ) {
      continue;
    }

    // get social network icon
    icon = splitedName[2];

    // push into list
    linkList.push(
      rowString
        .replace( /{url}/, url )
        .replace( /{icon}/, icon )
    );    
  }

  // append dom
  if( linkList.length ) {
    if( div ) {
        div.innerHTML = linkList.join( "&nbsp;" ) + "&nbsp;" + div.innerHTML;
    } else {
        div = document.createElement( "div" );
        div.id = "social_networks";
        div.innerHTML = linkList.join( "&nbsp;" );
        target.appendChild( div );
    }
  }
}

// -->

