//************************************************************************
//------------------------------------------------------------------------
// --- SECTION DE DETECTION DES COOKIES
//------------------------------------------------------------------------
//************************************************************************

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function renameCookie(name, rename) {
  var iPlanet = getCookie(name);	
  //alert("Rename = " + iPlanet); 
  if(window.location.hostname.indexOf("bnquebec.ca") == -1) {
      setCookie(rename,iPlanet,null,"/",".banq.qc.ca",null);
  } else {
	  setCookie(rename,iPlanet,null,"/",".bnquebec.ca",null);
  }
  //alert("rename after set iPlanetTemp:" + getCookie("iPlanetTemp") + rename);
  
}
function sortieExtranet(targetUrl) {
   //alert(" iPlanetDirectoryPro:" + getCookie("iPlanetDirectoryPro"));
   renameCookie("iPlanetDirectoryPro", "iPlanetTemp");	
   if(window.location.hostname.indexOf("bnquebec.ca") == -1) {
	   setCookie("iPlanetDirectoryPro","",null,"/",".banq.qc.ca",null);
   } else {
	   setCookie("iPlanetDirectoryPro","",null,"/",".bnquebec.ca",null);
   }
   //alert("Sortie iPlanetDirectoryPro:" + getCookie("iPlanetDirectoryPro"));
   //alert("Sortie iPlanetTemp:" + getCookie("iPlanetTemp"));
   top.document.location.replace(targetUrl);
}
function refreshLogin(){
   //alert("iPlanetTemp:" + getCookie("iPlanetTemp"));	
   renameCookie("iPlanetTemp", "iPlanetDirectoryPro");
   //alert("After refresh iPlanetDirectoryPro:" + getCookie("iPlanetDirectoryPro"));		
   //setCookie("iPlanetDirectoryPro","",null,"/",".banq.qc.ca",null);
   top.document.location.replace("/");
}
function sortieInternet(url_courant) {
   //alert(" iPlanetDirectoryPro:" + getCookie("iPlanetDirectoryPro"));
   //renameCookie("iPlanetDirectoryPro", "iPlanetTemp");	
   if(window.location.hostname.indexOf("bnquebec.ca") == -1) {
	   setCookie("iPlanetDirectoryPro","",null,"/",".banq.qc.ca",null);
   } else {
	   setCookie("iPlanetDirectoryPro","",null,"/",".bnquebec.ca",null);   
   }
   //alert("Sortie iPlanetDirectoryPro:" + getCookie("iPlanetDirectoryPro"));
   //alert("Sortie iPlanetTemp:" + getCookie("iPlanetTemp"));
   top.document.location.replace(url_courant);
}