// Language and cookies Functions: Copyright Sébastien Routier 
var langCookieName = "wawaL10n"; // Customize this to a unique string. Ex: "WawaL10n".
var defaultLang    = "fr";         // Set the default language. Ex: "en" or "fr".
var jsl10nKey      = "_jsl10n-";   // The key substring to use for the id of your DIVs. No need to change it.

function fnJsl10n() {
    var lang = fnGetCookie(langCookieName);
//     alert("Cookie: (" + langCookieName + "):[" + lang + "]");
	 if ( !lang || '' == lang ) {
		  lang = defaultLang;
	 }
//     alert("Cookie: (" + langCookieName + "):[" + lang + "]");
    fnShowLang(document.body, lang);
}

function fnShowLang(elem, lang) {
    var aChildren = elem.childNodes;
	 var i = 0;
    for (i = 0; i < aChildren.length; i++) {
        var sChildId = aChildren[i].id;
		  if ( sChildId && '' != sChildId ) {
				if (-1 != sChildId.indexOf(jsl10nKey + lang)) {
					 aChildren[i].style.display= "block";
				}
				else if (-1 != sChildId.indexOf(jsl10nKey)) {
					 aChildren[i].style.display = "none";          
				}
				fnShowLang(aChildren[i], lang);
		  }
    }
}

function fnSetL10nLang(lang) {
    var nextYear = new Date();
    nextYear.setFullYear(nextYear.getFullYear() + 1); // Cookie will expire in one year!
    fnSetCookie(langCookieName, lang, nextYear);
    fnShowLang(document.body, lang);
}

// [Cookie] Clears a cookie
function fnClearCookie(cookieName) {
   var now = new Date();
   var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
   fnSetCookie(cookieName, 'DummyCookieValue', yesterday);
}

// [Cookie] Sets value in a cookie
function fnSetCookie(cookieName, cookieValue, expires, path, domain, secure) {
   document.cookie =
      escape(cookieName) + '=' + escape(cookieValue)
      + (expires ? '; expires=' + expires.toGMTString() : '')
      + (path ? '; path=' + path : '')
      + (domain ? '; domain=' + domain : '')
      + (secure ? '; secure' : '');
}

// [Cookie] Gets a value from a cookie
function fnGetCookie(cookieName) {
   var cookieValue = '';
   var posName = document.cookie.indexOf(escape(cookieName) + '=');
   if (posName != -1) {
      var posValue = posName + (escape(cookieName) + '=').length;
      var endPos = document.cookie.indexOf(';', posValue);
      if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
      else cookieValue = unescape(document.cookie.substring(posValue));
   }
   return (cookieValue);
}


// WAWA Design specific functions 


// Menu Functions: Copyright Sébastien Routier 
function highlightPage(menuno) {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById(menuno)) return false;
  var nav = document.getElementById(menuno);
  var links = nav.getElementsByTagName("a");
  var currenturl = window.location.href;
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "current";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
		//break;
    }
  }
}

/*function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function fnSetL10nLang( sLang ) {
	 true;
}*/

