function TPlausibility()
{
var alphabetValueArray;
var alphabetPosArray; // "u" ... don't use positions
var minLen;
var maxLen;

this.Init=Init;
this.Reset=Reset;
this.SetMinLen=SetMinLen;
this.SetMaxLen=SetMaxLen;
this.AddChar=AddChar;
this.AddCharAtPos=AddCharAtPos;				// Characters on these positions MUST exist (mind. 1 of the pos)
this.AddSmallLetters=AddSmallLetters;
this.AddBigLetters=AddBigLetters;
this.AddNumbers=AddNumbers;
this.AddUmlauts=AddUmlauts;
this.LoadSettings_Tel=LoadSettings_Tel;
this.LoadSettings_Zip=LoadSettings_Zip;
this.LoadSettings_City=LoadSettings_City;
this.LoadSettings_Street=LoadSettings_Street;
this.LoadSettings_PersonName=LoadSettings_PersonName;
this.LoadSettings_EMail=LoadSettings_EMail;
this.LoadSpecialChars=LoadSpecialChars;
this.LoadSpecialChars_Francais=LoadSpecialChars_Francais;
this.Check=Check;
this.ListAlphabet=ListAlphabet;

this.Init();


function Init() {this.Reset();}

function Reset()
{
this.alphabetValueArray=new Array();
this.alphabetPosArray=new Array();
this.minLen=0;
this.maxLen=65536;
}

function SetMinLen(value) {this.minLen=value;}

function SetMaxLen(value) {this.maxLen=value;}

function AddChar(value) {this.AddCharAtPos(value,"u");} // u...undefined

function AddCharAtPos(value,pos) // negative positions: from last character. Example: "123456789" pos-3 ist the char "6"
{
this.alphabetValueArray.push(value);
this.alphabetPosArray.push(pos);
}

function AddSmallLetters()
{
var i;
for (i=97;i<=122;i++)
{
this.AddChar(chr(i));
}
}

function AddBigLetters()
{
var i;
for (i=65;i<=90;i++)
{
this.AddChar(chr(i));
}
}

function AddNumbers()
{
var i;
for (i=48;i<=57;i++)
{
this.AddChar(chr(i));
}
}

function AddUmlauts()
{
this.AddChar(chr(223)); // ß
this.AddChar(chr(228)); // ä
this.AddChar(chr(246)); // ö
this.AddChar(chr(252)); // ü
this.AddChar(chr(196)); // Ä
this.AddChar(chr(214)); // Ö
this.AddChar(chr(220)); // Ü

this.LoadSpecialChars();
}

function LoadSettings_EMail()
{
this.SetMinLen(5);
this.SetMaxLen(100);
this.AddSmallLetters();
this.AddBigLetters();
this.AddUmlauts();
this.AddNumbers();
this.AddChar("/");
this.AddChar("(");
this.AddChar(")");
this.AddChar("-");
this.AddChar(" ");
this.AddChar("@");
}

function LoadSettings_Tel()
{
this.SetMinLen(6);
this.SetMaxLen(25);
this.AddNumbers();
this.AddCharAtPos("0",0);
this.AddCharAtPos("+",0);
this.AddChar("/");
this.AddChar("(");
this.AddChar(")");
this.AddChar("-");
this.AddChar(" ");
}

function LoadSettings_Zip()
{
this.SetMinLen(4);
this.SetMaxLen(10);
this.AddNumbers();
this.AddSmallLetters();
this.AddBigLetters();
this.AddUmlauts();
this.AddChar("-");
this.AddChar("(");
this.AddChar(")");
this.AddChar(".");
this.AddChar(",");
this.AddChar(" ");
}

function LoadSettings_Street()
{
this.SetMinLen(4);
this.AddNumbers();
this.AddSmallLetters();
this.AddBigLetters();
this.AddUmlauts();
this.AddChar("-");
this.AddChar("/");
this.AddChar("(");
this.AddChar(")");
this.AddChar(".");
this.AddChar(",");
this.AddChar(" ");
}

function LoadSettings_City()
{
this.SetMinLen(3);

var i;
for (i=33;i<=47;i++)
{
this.AddChar(chr(i));
}
for (i=58;i<=255;i++)
{
this.AddChar(chr(i));
}
this.AddUmlauts();
this.AddChar("-");
this.AddChar("/");
this.AddChar("(");
this.AddChar(")");
this.AddChar(".");
this.AddChar(",");
this.AddChar(" ");
}

function LoadSettings_PersonName()
{
this.SetMinLen(3);

var i;
for (i=33;i<=47;i++)
{
this.AddChar(chr(i));
}
for (i=58;i<=255;i++)
{
this.AddChar(chr(i));
}
this.AddUmlauts();
this.AddChar("-");
this.AddChar("/");
this.AddChar("(");
this.AddChar(")");
this.AddChar(".");
this.AddChar(",");
this.AddChar(" ");
}

function LoadSpecialChars()
{
this.LoadSpecialChars_Francais();
}

function LoadSpecialChars_Francais()
{
this.AddChar("à");
this.AddChar("â");
this.AddChar("é");
this.AddChar("è");
this.AddChar("ê");
this.AddChar("ë");
this.AddChar("î");
this.AddChar("ï");
this.AddChar("ô");
this.AddChar("ù");
this.AddChar("û");
this.AddChar("¦");
this.AddChar("œ");
this.AddChar("æ");
this.AddChar("ç");
this.AddChar("'");
this.AddChar("À");
this.AddChar("Â");
this.AddChar("É");
this.AddChar("È");
this.AddChar("Ê");
this.AddChar("Ë");
this.AddChar("Î");
this.AddChar("Ï");
this.AddChar("Ô");
this.AddChar("Ù");
this.AddChar("Û");
this.AddChar("‘");
this.AddChar("Œ");
this.AddChar("Æ");
this.AddChar("Ç");
}

function Check(str)
{
var i,j,charFound,posFlag=0,usePosMode=false,posCharAtThisChar;

if (str.length<this.minLen) return false;
if (str.length>this.maxLen) return false;

for (i=0;i<str.length;i++)
{
charFound=false;
posFlag=0;
posCharAtThisChar=false;
for (j=0;j<this.alphabetValueArray.length;j++)
{
if (str.charAt(i)==this.alphabetValueArray[j])
{
charFound=true;
}

if (usePosMode==false&&this.alphabetPosArray[j]!="u") usePosMode=true;

if (this.alphabetPosArray[j]!="u")
{
var tmpPos;
if (this.alphabetPosArray[j]<0)
{
tmpPos=str.length+this.alphabetPosArray[j];
}
else tmpPos=this.alphabetPosArray[j];


if (tmpPos==i&&posFlag!=1)
{
posCharAtThisChar=true;
if (str.charAt(tmpPos)!=this.alphabetValueArray[j])
{
posFlag=-1;
}
else
{
posFlag=1;
}
}
}
}

if (usePosMode==true&&posFlag==-1&&posCharAtThisChar==true) return false;
if (!charFound) return false;
}
return true;
}

function ListAlphabet()
{
var i,tmpStr="";
for (i=0;i<this.alphabetValueArray.length;i++)
{
tmpStr+="char: "+this.alphabetValueArray[i]+" pos: "+this.alphabetPosArray[i]+"\n";
}
alert(tmpStr);
}
}
