// General utilities     [15.03.2004]

var adrs = "%6d%75%73%69%71%75%65%73"
var dom = "%70%6c%75%6d%65%62%6c%65%75%65%2e%63%68"

webServer = true
debugCaddie = false
displayJSErrors = true
dispLangSwitch = false
dispInfoEnabled = false   // prompts the user in HomePage "Question à nos clients"
dispWinPopUpEnabled = true

var op = "%40"
var opstr = "&#64;"

var cookiesServerPath = ""

cookieItemsTime = 2*24*3600   // cookies are kept for 2 days
// cookieItemsTime = 60   // cookies are kept for 1 minte... FOR TESTING ONLY!
popUpCookieDuration = 3600*24*10  // display pop-up windows again after 10 days

if (webServer) 
{ 
   cookiesServerPath = "/pages/" 
}
else // local server
{ 
   cookiesServerPath = "/plumebleue/pages/" 
} 

// alert ("WEBSERVER="+webServer)

var caddiePath = "../Caddie.htm"
var navLang = ""

window.onerror = errorHandler

msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()

function errorHandler(msg, url, lno) 
{
   if (displayJSErrors)
   {
      msgArray[msgArray.length] = msg
      urlArray[urlArray.length] = url
      lnoArray[lnoArray.length] = lno
      errorWin = window.open('','errorWindow','resizable=yes,height=100,width=550')
      for (var i=0; i < msgArray.length; i++) 
      {
         errorWin.document.writeln('<B>Error in file:</B> ' + urlArray[i] + '<BR>')
         errorWin.document.writeln('<B>Line number:</B> ' + lnoArray[i] + '<BR>')
         errorWin.document.writeln('<B>Message:</B> ' + msgArray[i] + '<P>')
      }
      errorWin.document.close()
   }   
   return true
}


function navigatorVersion (typeStr) 
{
   if (   ((typeStr == "NETSCAPE") && (navigator.appName == "Netscape"))
       || ((typeStr == "EXPLORER") && (navigator.appName.substring(0,9) == 'Microsoft')))
   {    
      return (true)
   }   
   else return (false)
}

// *** BROWSER VERSION ***

// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase()

// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion)
var is_minor = parseFloat(navigator.appVersion)

var is_ie      = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1))
var is_ie3     = (is_ie && (is_major < 4))
var is_ie4     = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) )
var is_ie4up   = (is_ie && (is_major >= 4))
var is_ie5     = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) )
var is_ie5up   = (is_ie && !is_ie3 && !is_ie4)
var is_ie5_5   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6     = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) )
var is_ie6up   = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5)

// Note: Opera and WebTV spoof Navigator. We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav     = (   (agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                  && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                  && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1))
var is_nav4    = (is_nav && (is_major == 4))
var is_nav4up  = (is_nav && (is_major >= 4))
var is_nav6    = (is_nav && (is_major == 5))
var is_nav6up  = (is_nav && (is_major >= 5))


function setCookie (name, value, expire, cookiePath) 
{
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString())) + ((cookiePath == null) ? "" : ("; path=" + cookiePath))
}


function regCookie (cookieName, cookieStr, numOfSeconds) 
{ 
   var today = new Date ()
   var expires = new Date ()
   expires.setTime (today.getTime() + numOfSeconds*1000)
   setCookie (cookieName, cookieStr, expires, cookiesServerPath)
}


function getCookie (name) 
{
   var search = name + "="
   var cookieStr = ""
   if (document.cookie.length > 0) // if there are any cookies
   { 
      offset = document.cookie.indexOf(search) 
      if (offset != -1) // if cookie exists 
      {
         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 }
         cookieStr = unescape (document.cookie.substring (offset, end))
         if ((cookieStr == null) || (cookieStr == "undefined") || (cookieStr == "")) { cookieStr = "" }
      } 
   }
   return cookieStr
}


function clearCookie (cookieName, cookiePath)
{
   var expires = new Date ()
   expires.setTime (today.getTime())
   setCookie (cookieName, "", expires, cookiePath)
   return true
}


var taggedStr = getCookie("PB_Language")


function register (cookieStr)
{
   regCookie ("PB_Language", cookieStr, 3600*24*365*3)
}


function switchLang (param) 
{
   var reload = true
   if (param == "English")
   {
      if (taggedStr == "English") { reload = false }
      else
      {
         if (dispLangSwitch) { alert ("To display the next pages in English, it is required to set a 'cookie' which will hold only your language preference.") }
         regCookie ("PB_Language", "English", 3600*24*365*3)
      }
   }
   else if (param == "French")
   {
      if (taggedStr == "French") { reload = false }
      else
      {
         if (dispLangSwitch) { alert ("Pour afficher les pages suivantes en français il est nécessaire de mettre a jour un 'cookie' qui ne portera que votre préférence de langue.") }
         regCookie ("PB_Language", "French", 3600*24*365*3)
      }
   }
   else // just toggle language setting
   {
      if (taggedStr == "English")
      {
         if (dispLangSwitch) { alert ("Pour afficher les pages suivantes en français il est nécessaire de mettre a jour un 'cookie' qui ne portera que votre préférence de langue.") }
         regCookie ("PB_Language", "French", 3600*24*365*3)
      }
      else // French assumed
      {
         if (dispLangSwitch) { alert ("To display the next pages in English, it is required to set a 'cookie' which will hold only your language preference.") }
         regCookie ("PB_Language", "English", 3600*24*365*3)
      }
   }
   taggedStr = getCookie("PB_Language")
   // alert ("LANGUAGE="+taggedStr)
   if (reload) { window.location.reload (true) }
}


function openCaddieWindow ()
{
   caddieWin = open (caddiePath, "CaddieWindow", "scrollbars=yes,resizable=yes,titlebar=yes,status=yes,height=600,width=800,screenX=0,screenY=0") 
}
