// Copyright 1999-2002 Alexandre CABADET - HEADWAY CREATIVE


var isFunctionLoaded = false;
var siteTitle = "HEADWAY CREATIVE - One soft ahead!";
var siteLanguage = ((((self.location.href.lastIndexOf('/fr/')) || (self.location.pathname.lastIndexOf('\\fr\\'))) > 0) ? 'fr' : 'us');


///////////////////////////////////////////////////////////
// Mail functions
///////////////////////////////////////////////////////////
function openContactEmail(sType)
{
	// Chaîne de cryptage email à générer sur http://w2.syronex.com/jmr/safemailto/fr/
	switch (sType)
	{
	  case 'support' :
	  {
    	// Demande de support technique
  	  var sSubject = (top.siteLanguage == 'fr') ? "Demande de support technique" : "Technical support request";
      var v2="HINKFXCD5Z445454WPHQGVTQ28RU";var v7=unescape("%3B%3C%3E%3B%29*7%04%5D%3FUPBUL%194%22-03%3F%224%1C%5B%3D8");var v5=v2.length;var v1="";
      break;
	  }
	  default :
	  {
    	// Demande de contact
  	  var sSubject = (top.siteLanguage == 'fr') ? "Demande de contact" : "Contact request";
  	  var v2 = "W5VYXM5BJCM8V48QT6NCNP6M8KYC"; var v7 = unescape("4Z8-9.A%02%22%26%2C%5C%21UA%7C7D+%22%3A9@%28%16%286."); var v5=v2.length; var v1="";
	  }
	}

	for (var v4=0;v4<v5;v4++) {v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));}
	window.location = 'mail\u0074o\u003a'+v1+'?subject=' + sSubject;
}


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

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


///////////////////////////////////////////////////////////
// General functions
///////////////////////////////////////////////////////////
function goToURL(oWin)
{
  /*
  var searchUrl = oWin.location.href;
  var rightUrl = top.mainFrame.mainRightFrame.location.pathname;
  top.mainFrame.mainRightFrame.location.assign(rightUrl + "?" + searchUrl);
  top.mainFrame.mainLeftFrame.setSearchValue();
  */
  return true;
}

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;
