// Copyright 1999-2005 Alexandre CABADET


var g_IE5 = false;
var g_XPSP2 = false;
var g_VALIDBROWSER = true;
var isFunctionLoaded = false;


///////////////////////////////////////////////////////////
// Window functions
///////////////////////////////////////////////////////////
function openWin(url, windowname, w, h)
{
    newWin=window.open(url, windowname, "scrollbars=yes,width="+w+",height="+h+",resizable=1");
    if (newWin) newWin.focus(true);
}

function calculateDimension(w, h)
{
    widthWin = w;
    heightWin = h;
    leftWin = (screen.availWidth-widthWin)/2;
    topWin = (screen.availHeight-heightWin)/2;
}


///////////////////////////////////////////////////////////
// General functions
///////////////////////////////////////////////////////////
function setStatus()
{
    window.status = siteTitle;
    return true;
}

function setDefaultStatus()
{
    window.defaultStatus = siteTitle;
}

function addTofavorites()
{
  browserName = navigator.appName;
  browserVer = parseInt(navigator.appVersion);
  if (browserName == "Microsoft Internet Explorer" & browserVer >= 4)
  {
    window.external.AddFavorite('index.html', siteTitle);
  }
} 

function checkBrowserVersion()
{
  var verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);

  if (top.document.location.href.substr(0, 4).toLowerCase() == "file")
  {
    top.g_VALIDBROWSER = false;
    return false;
  }

  if (app.indexOf('Microsoft') != -1)
  {
    if (version >= 4.0)
    {
      var msie = "MSIE ";
      var nPos = verStr.toUpperCase().indexOf(msie);
      if (nPos >= 0)
      {
        var verMsie = verStr.substr(nPos+msie.length, 2);
        version = parseFloat(verMsie);
        if (version >= 5)
        {
          // La version du navigateur est supérieur à IE5
          top.g_IE5 = true;

          // Vérification de l'installation de Windows XP SP2
          top.g_XPSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
          
          return true;
        }
      }
    }
  }
  else
    if (navigator.appCodeName == "Mozilla")
    {
      if (version >= 5.0)
        return true;
    }

  top.g_VALIDBROWSER = false;
  return false;
}

function getURL(filename)
{
    var url = new String(filename);
    window.mainFrame.mainWorkFrame.location = url;
}

function StringToFloat(str)
{
    var s = new String("");
    if (str.indexOf(",") >= 0) {
        s = str.substring(0, str.indexOf(",")) + "." + str.substring(str.indexOf(",")+1, str.length);
    } else s = str;  
    return(parseFloat(s));
}

function getWindowFile(currentWindow)
{
    var w_location = currentWindow.location.href;
    var w_position = w_location.lastIndexOf('/');
    if (w_position > 0)
        return w_location.substring(w_position+1,w_location.length);
    else
    {
        w_location = currentWindow.location.pathname;
        w_position = w_location.lastIndexOf('\\');
        if (w_position > 0)
            return w_location.substring(w_position+1,w_location.length);
    }
    
    return "";
}


///////////////////////////////////////////////////////////
// Helper functions
///////////////////////////////////////////////////////////
function isEmpty(inputVal)
{
    inputStr = inputVal.toString()
    if ((inputStr == null) || (inputStr == "") || (inputStr.length == 0))
    {
        return(false);
    }
    return(true);
}

function isNotEmpty(inputVal)
{
    inputStr = inputVal.toString()
    if (inputStr != "" && inputStr.length > 0)
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

function isLocalPart(STR)
{
    if (isDotString(STR))
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

function isDomaine(STR)
{
    var POINT = STR.indexOf(".")
    var IncDom = 0;
    if (POINT > 0)
    {
        var LeftPart = STR.slice(0,POINT);
        var RightPart = STR.slice(POINT + 1 , STR.length);
        if (!isName(LeftPart)) 
        {
            IncDom++;
        }
        if(!isDomaine(RightPart))
        {
            IncDom++;
        }
    }
    else 
    {
        if (!(isName(STR)))
        {
            IncDom++;
        }
    }
    if (IncDom == 0)
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

function isLdhStr(CAR)
{
    if (!(isLetDigHyp(CAR)))
    {
        return(false);
    }
    else
    {
        return(true);
    }
}

function isLetDigHyp(CAR)
{
    if (!(isA(CAR) || isD(CAR) || (CAR == "-")))
    {
        return(false)
    }
    else
    {
        return(true)
    }
}

function isLetDig(CAR)
{
    if (!(isA(CAR) || isD(CAR)) )
    {
        return(false)
    }
    else
    {
        return(true)
    }
}

function isName(STR)
{
    var IncName = 0;
    
    // Vérifie que les caractères de la chaine sont des [A..Z] ou [a..z]
    if (! ( isA( STR.charAt(0) ) ) )
    {
        IncName++;
    }
    
    // Vérifie que les caractères sont des [a..z] || [A..Z] || [0..9] || "-"
    for (var IndName=1; IndName < STR.length; IndName++)
    {
        if (! isLetDigHyp(STR.charAt(IndName)))
        {
            IncName++;
        } 
    }
    
    // Vérifie que l'incrément est nul
    if (IncName == 0)
    {
        return(true)
    }
    else
    {
        return(false)
    }
}

function isString(STR)
{
    var IncStr = 0;
    
    // Vérifie chaque caractère de la chaine STR
    for (var IndStr=0; IndStr < STR.length; IndStr++)
    {
        if (! (isC(STR.charAt(IndStr))) ) 
        {
            IncStr++; 
        }
    }
    
    if (IncStr == 0 )
    {
        return(true);
    }
    else
    {
        return(false);
    }
}

function isDotString(STR)
{
    var POINT = STR.indexOf(".");
    if (POINT > 0 )
    {
        var LeftPart = STR.slice(0,POINT);
        var RightPart = STR.slice(POINT + 1,STR.length);
        if ((isString(LeftPart)) && (isDotString(RightPart)))
        {
            return(true)
        }
        else
        {
            return(false)
        }
    }
    else
    {
        if (isString(STR))
        {
            return(true);
        }
        else 
        {
            return(false);
        }
    } 
}

function isA(CAR)
{
    if (((CAR >= "a") && (CAR <= "z")) ||  ((CAR >= "A") && (CAR <= "Z")))
    {
        return(true);
    }
    else
    {
        return(false)
    }
}

function isC(CAR)
{
    var IncC = 0;
    if ( (CAR.charCodeAt(0) == 127) || (CAR.charCodeAt(0) < 32) )
    {
        IncC++;
    }
    if (!isNotSpecial(CAR))
    {
        IncC++;
    }
    if ( IncC == 0) 
    {
        return(true)
    }
    else
    {
        return(false)
    }  
}

function isNotSpecial(CAR)
{
    // La liste des caractères spéciaux
    var Special = new Array("<",">","(",")","[","]","\\",".",",",";",":","#"," ")
        
    // Init des Incréments
    var IncSpecial = 0;
    var IncAutre = 0;
    
    for(var IndSpe=0;IndSpe < Special.length; IndSpe++)
    {
        if (CAR == Special[IndSpe])
        {
            IncSpecial++;
        }
    }
    IncAutre+= IncSpecial;
    if (IncAutre > 0) 
    {
        return(false); 
    }
    else
    {
        return(true);
    }
}

function isD(CAR)
{
    if ((CAR >= "0") && (CAR <= "9")) 
    {
        return(true)
    } 
    else
    {  
        return(false)
    }
}

function isValidMailString(inputStr)
{
    for (var i = 0; i < inputStr.length; i++)
    {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "a" || oneChar > "z")
        {
            if (oneChar < "0" || oneChar > "9")
            {
                if (oneChar != ".")
                {
                    if (oneChar != "_")
                    {
                        if (oneChar != "-")
                        {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}

function testEmail1(chaine)
{
    var IncEmail = 0;
    chaine = chaine.toLowerCase();
    var Arobace = chaine.indexOf("@");
    
    // Commence les tests : Arobace présente et pas en premier
    if (Arobace > 1 )
    {
        var LocalPart = chaine.slice(0,Arobace);
        var Domaine = chaine.slice(Arobace + 1,chaine.length);
        if ( !(isLocalPart(LocalPart)) || !(isDomaine(Domaine)) )
        {
            IncEmail++;
        }
    }
    else IncEmail++;
    if (IncEmail == 0) 
    {
        return(true)
    }
    else
    {
        return(false)
    }
}

function testEmail2(email)
{
    if (email == null || email == "") return false;
    var atPos = email.indexOf('@');
    if (atPos < 0) return false;
    var username = email.substring(0,atPos).toLowerCase();
    var hostname = email.substring(atPos+1,email.length).toLowerCase();
    if (!isValidMailString(username)) return false;
    if (!isValidMailString(hostname)) return false;
    if (hostname.indexOf('.') < 0) return false;
    if ((hostname.length - hostname.lastIndexOf('.') - 1) <= 1) return false;
    
    return true; 
}

function testEmail(inputVal)
{
    inputStr = inputVal.toString()
  if (!testEmail1(inputStr) || !testEmail2(inputStr)) 
  {
      return(false)
  }
  return(true)
}


///////////////////////////////////////////////////////////
// The following codeline must be the last one !!!
///////////////////////////////////////////////////////////
isFunctionLoaded = true;
