function setLang(strValue)
{
  set_cookie("language",strValue);
}
    
function toggleLang()
{
  var strHRef = window.location.href;

  var objRegExpEn = new RegExp("lang=en", "i")   
  var objRegExpFr = new RegExp("lang=fr", "i") 
      
  if(strHRef.search(objRegExpEn) != -1)
  {
    var strURL = strHRef.replace(objRegExpEn,'lang=fr');
    window.location.replace(strURL); 
  }
  else if(strHRef.search(objRegExpFr) != -1)
  {
    var strURL = strHRef.replace(objRegExpFr,'lang=en');
    window.location.replace(strURL);
  }
  else
  {  
    var strCurLang = get_cookie("language");
  
    if(strCurLang == "en")
      set_cookie("language","fr");
    else
      set_cookie("language","en");

    window.location.reload(true);
  }
}

function set_cookie(strName, strValue)
{
  var objDate = new Date()
  objDate.setFullYear(objDate.getFullYear() + 1);
      
  window.document.cookie = strName + "=" + strValue + ";Expires=" + objDate;
}

function get_cookie(Name)
{
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

//***** Code to handle 'Add to favorite' feature on main page
function AddFavorite()
{
  window.external.addFavorite( window.location.href, window.document.title );
}

//***** Code to handle 'Print PDF version' feature on main page

function PrintPDF()
{
  var strLoc = window.location.href;
	var i = strLoc.lastIndexOf("?");
  var strParams = strLoc.substr(i, strLoc.length - i)
  var strURL = 'report_pdf.asp' + strParams
  window.open(strURL,"report_pdf", "height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
}

//***** Code to handle 'Print this page' feature on main page

function PrintPage()
{
  var objWin = window.open("_blank","print","width=600,height=500,scrollbars=yes,toolbar=no,status=no,location=no,resizable=yes")
  var objMainSection = window.document.getElementById("BodyMain");

  objWin.document.open("text/html",true);
  objWin.document.write("<head><link rel='stylesheet' type='text/css' href='styles/styles.css'></head>");
    
  objWin.document.write("<body style='background-color: #ffffff;'>" + objMainSection.innerHTML + "</body>");
  objWin.document.close();
  objWin.print();
}

//***** Code to handle 'Send to a friend' feature on main page

function EMailFriend()
{
	var oWnd = 	window;
	var oDoc = oWnd.document;
	var oDescription = oDoc.getElementById("description");
	
	var strDescription = ( (oDescription == null) || (oDescription.content == "") ) ? oDoc.title : oDescription.content;	

	if( oDoc.title == "" )
		oWnd.location.href = "mailto:?body="+BuildEmailDescription(strDescription, oWnd.location.href);
	else
		oWnd.location.href = "mailto:?subject="+escape(oDoc.title)+"&body="+BuildEmailDescription(strDescription, oWnd.location.href);


}
function BuildEmailDescription(strDescription,hRef){
	return escape("Here is information you might be interested in ----- Voici de l'information qui peux t'intéresser:" + 
				      String.fromCharCode(13)+ String.fromCharCode(13)+ "URL: " + hRef + 
				      String.fromCharCode(13)+ String.fromCharCode(13)+ strDescription);
}
function AddParamToURL(strLoc,strParam){
	var i = strLoc.lastIndexOf("?");
	if(strLoc.indexOf(strParam, i) >= 0)
		return strLoc;
				
	strLoc += ((i >= 0) && (i > strLoc.lastIndexOf("/"))) ? "&" : "?";
	return strLoc + strParam;
}
