/**
* Constants
***/
var CheckDomForms = new Array();
var TestIt = true;
var pseudoForm  ="_form";
var formCaption ="Form";
var ErrorColor = "#ff0000";
var RequiredLabel= "*";

var MonthDays = [0,31,28,31,30,31,30, 31, 31,30,31,30,31];

var AllowedList = new Array();
AllowedList['Nummer'] = '0123456789';
AllowedList['LowAlpha'] = 'abcdefghijklmnopqrstuvwxyz';
AllowedList['UpAlpha'] = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
AllowedList['Umlauts'] = 'äöüÄÖÜß';
AllowedList['Alpha'] = ''+AllowedList['LowAlpha'] + AllowedList['UpAlpha'];
AllowedList['Email'] = '@.-_';
AllowedList['Telephon'] = ''+AllowedList['Nummer'];
AllowedList['Telephon2'] = '-/ ,.+()'+AllowedList['Telephon'];
AllowedList['Mathematic'] = '+/*-=%';
AllowedList['ExtraAlpha'] = ' .,&+*%/$-';
AllowedList['Betrag'] = '.,-'+AllowedList['Nummer'];
AllowedList['Comma'] = ',';
AllowedList['Blank'] = ' ';
AllowedList['Dot'] = '.';
AllowedList['And'] = '&';
AllowedList['Date'] = '.'+AllowedList['Nummer'];
AllowedList['User1'] = ' -.'+AllowedList['Alpha']+AllowedList['Nummer']+AllowedList['Umlauts'];  // for city, etc...
AllowedList['User2'] = ' /&.-'+AllowedList['Alpha']+AllowedList['Nummer']+AllowedList['Umlauts'];  // ie. for company
AllowedList['User3'] = '-'+AllowedList['Alpha']+AllowedList['Nummer'];  // ie. for hausnummer
AllowedList['User4'] = ','+AllowedList['User2'];  // ie. bankverbindung, kontoname
AllowedList['User5'] = ' .-'+AllowedList['Alpha']+AllowedList['Umlauts'];  // ie. nachname, vorname
AllowedList['User6'] = "'"+AllowedList['User1'];  // for streetnames

//** FUNCTIONS
function getLabel(fID,Parent){
	Parent=Parent ? Parent : document;
	var attrn=is.opera ? 'htmlFor' : 'for';
	var tLa=getElementsByAttributeValue(attrn,fID,'label',Parent,true);
	if(tLa && tLa[0]) return tLa[0];else return null;
}

function setRequiredLabel(fID,Req,Parent){
	//expects: <label for="fID">labeltext<span>*</span></label>
	var tLab=getLabel(fID,Parent);
	if(tLab){
		var tSpa=tLab.getElementsByTagName('span');
		if(tSpa && tSpa.item(0)){
			if(Req) tSpa.item(0).innerHTML=RequiredLabel;else tSpa.item(0).innerHTML='';
		}
	}
}

function setStatus(s){
  top.self.status=s;
  return true;
}


function submitForm(CHK_FormName, doCheck, command, popup, doSubmit){
	if(doSubmit!=false) doSubmit=true;
	dbWrite('SUBMIT');
	var CHK_Form=CheckDomForms[CHK_FormName];
	var retvalue;
	if(CHK_Form){
		if(CHK_Form.Ref.elements['command']) CHK_Form.Ref.elements['command'].value=command;	//set command before actual submit!
		retvalue = CHK_Form.Check(doSubmit, doCheck);			// do submit!
		if(command=="reset"){
			 CHK_Form.Ref.reset();
			 return false;
		}else{
			if(retvalue && popup && popup!=null)  openWinMedium(popup,'winXtraInfo');
			return retvalue;
		}
	}
}


function VerifyList(PrintList){
  var j=0;
  dummy = new Array();
  for (var i in PrintList){
  	if (i%2==1)if (PrintList[i][0]!=""){
  			 dummy[j]=PrintList[i-1];
  			 dummy[j+1]=PrintList[i];
  			 j+=2;
  	}
  }
  return dummy;
}
/**
*  used for handling the errors
***/
function TErrorlist(ErrorObject){
  this.ErrorObject=ErrorObject;
  this.Errorlist = new Array(2);
  this.Errorlist[0]= new Array();
  this.Errorlist[1]= new Array();
}
TErrorlist.prototype.ClearErrorlist = function(){
  this.Errorlist[0].length=0;
  this.Errorlist[1].length=0;
}
TErrorlist.prototype.AddError = function(where,message){
  this.Errorlist[0][this.Errorlist[0].length]=where;
  this.Errorlist[1][this.Errorlist[1].length]=message;
}
/**
* have an Output for server-error-messages********
***/
function TPseudoForm(CheckFormRef){
  this.Name = pseudoForm;
  this.setFocus = false;
  this.ErrorX=0;
  this.ErrorY=0;
  this.ErrorW=0;
  this.ErrorH=0;
  this.Caption=formCaption;
  this.Errorlist= new TErrorlist(this);
  this.setFocus=false;
  this.CheckFormRef=CheckFormRef;
}
TPseudoForm.prototype.FindError = function(){ return false;}
TPseudoForm.prototype.lighten = function(a){}

/**
* used for the form itself
***/
function CreateCheckForms(destWin){
  if(!destWin) destWin=self;
  var formElems=destWin.document.getElementsByTagName("form");
  for(var i=0;i<formElems.length;i++){
    if(getAttributeValue(formElems[i],"chkOn")=="true"){
	var FName	= formElems[i].name;
      	var CHKName	= getAttributeValue(formElems[i],"chkName");
	if(FName!='' && CHKName!=''){
	  	var NF=new TCheckForm(destWin,FName,CHKName);
	  	dbWrite('CREATED CHECKFORM',CHKName);
	    	NF.Ref=destWin.document.forms[i];
  		NF.CheckFields[pseudoForm] = new TPseudoForm(NF);
	    	var SetFocus=NF.initDom();
  		if(SetFocus){
   			NF.win.focus();
   		 	SetFocus.Ref.focus();
  		}
  		NF.Reminder=SetFocus;
  		if(is.opera){
			var tL=getElementsByAttributeValue('type','radio','input',NF.Ref);
			var tLab=null;
			for(var j=0;j<tL.length;j++){
				tLab=getLabel(tL[j].id, NF.Ref);
				if(tLab){
					AddRefHandler('onclick',handle_opera_label_click,tL[j],tLab);
					AddRefHandler('onfocus',handle_opera_radio_focus,tL[j],tL[j]);
				}
			}
			tL=getElementsByAttributeValue('type','checkbox','input',NF.Ref);
			tLab=null;
			for(var j=0;j<tL.length;j++){
				tLab=getLabel(tL[j].id, NF.Ref);
				if(tLab) AddRefHandler('onclick',handle_opera_label_click,tL[j],tLab);  //(EventName,Handler,pointer,eventObj)
			}
  		}

  		for(var j in NF.CheckFields)
			if (j!=pseudoForm) NF.CheckFields[j].start();
		CheckDomForms[CHKName]=NF;
        }
    }
  }
}

function handle_opera_radio_focus(a,b){
  if(!a.disabled && a.checked) a.click();
  return false;
}
function handle_opera_label_click(a,b,c){
  if(!a.disabled) a.click();
  a.focus();
  b.stopPropagation();
  return false;
}

function TCheckForm(win,FormName,instName){
  this.win=self;
  this.instName=instName;
  this.FormName=FormName;
  this.CheckFields = new Array();
  this.CheckSelects = new Array();
  this.WrongElements=new Array();
  this.ActuelError=0;
  this.ErrorCount=-1;
  this.Reminder="";
  this.CheckFocus=true;
  this.FirstCheck=false;
 //eval(instName+'=this;');
 // if(is.ns) win.document.captureEvents(Event.KEYPRESS);
}

TCheckForm.prototype.addField = function(Name,Type,Required,MinL,MaxL,MinValue,MaxValue,RegEx,RegExMsg,TstCode,KeyFlag,Caption,DefaultValue,ErrCntr,ExtraCheck){
  return this.CheckFields[Name]= new TCheckField(Name,Type,Required,MinL,MaxL,MinValue,MaxValue,RegEx,RegExMsg,TstCode,this,KeyFlag,Caption,DefaultValue,ErrCntr,ExtraCheck);
}

TCheckForm.prototype.SearchNewReminder = function(){
  if(!this.Reminder.activ){
    for(var i in this.CheckFields){
      if(this.CheckFields[i].activ) this.Reminder=this.CheckFields[i];
    }
  }
}

TCheckForm.prototype.initDom = function(){
  var inpElems=new Array();
  inpElems=this.Ref.elements;
  var DefaultField=null;
  for(var i=0;i<inpElems.length;i++){
    if(inpElems[i]){
      if(getAttributeValue(inpElems[i],"chkOn")=="true"){
      	var Name	= getAttributeValue(inpElems[i],"name");
      	if(Name=='') Name = getAttributeValue(inpElems[i],"id");
        var Required 	= getAttributeValue(inpElems[i],"chkRequired") 	? new Boolean(getAttributeValue(inpElems[i],"chkRequired")) 	: false;
        var MinL 	= getAttributeValue(inpElems[i],"chkMinLength") 	? getAttributeValue(inpElems[i],"chkMinLength") 			: 0;
        var MaxL	= getAttributeValue(inpElems[i],"chkMaxLength") 	? getAttributeValue(inpElems[i],"chkMaxLength") 			: 1000000;
        var MinValue 	= getAttributeValue(inpElems[i],"chkMinValue") 	? getAttributeValue(inpElems[i],"chkMinValue") 			: null;
        var MaxValue	= getAttributeValue(inpElems[i],"chkMaxValue") 	? getAttributeValue(inpElems[i],"chkMaxValue") 			: null;
        var TstCode	= getAttributeValue(inpElems[i],"chkAllowedChars")	? eval(getAttributeValue(inpElems[i],"chkAllowedChars")) 		: new Array();
        var KeyFlag	= getAttributeValue(inpElems[i],"chkOnKeyCheck") 	? new Boolean(getAttributeValue(inpElems[i],"chkOnKeyCheck")) 	: false;
        var Caption	= getAttributeValue(inpElems[i],"chkCaption")	? new String(getAttributeValue(inpElems[i],"chkCaption")) 	: new String('');
        var RegEx	= getAttributeValue(inpElems[i],"chkRegEx")	? new String(getAttributeValue(inpElems[i],"chkRegEx")) 	: new String('');
        var RegExMsg	= getAttributeValue(inpElems[i],"chkRegExMsg")	? new String(getAttributeValue(inpElems[i],"chkRegExMsg")) 	: new String('');
	var DefaultValue	= getAttributeValue(inpElems[i],"chkDefaultValue")	? new String(getAttributeValue(inpElems[i],"chkDefaultValue")) 	: new String('');
        var ErrContainer	= getAttributeValue(inpElems[i],"chkErrContainer") 	? new String(getAttributeValue(inpElems[i],"chkErrContainer"))			: new String('');
        var ExtraCheck	= getAttributeValue(inpElems[i],"chkXtraCheck") 	? new String(getAttributeValue(inpElems[i],"chkXtraCheck")) 	: null;
	var Type=inpElems[i].type;
        var FLD = this.addField(Name,Type,Required,MinL,MaxL,MinValue,MaxValue,RegEx,RegExMsg,TstCode,KeyFlag,Caption,DefaultValue,ErrContainer,ExtraCheck,inpElems[i]);
	//dbWrite('Found ',Name, 'Errorcontainer:',ErrContainer,inpElems[i].type);
        if(!DefaultField && getAttributeValue(inpElems[i],"chkDefaultField")=="true")
          DefaultField	= FLD;
      }
    }
  }
  return DefaultField;
}

TCheckForm.prototype.Print = function(PrintList){
  this.CheckFocus=false;
  PrintList = VerifyList(PrintList);
  if (PrintList.length>0){
  	this.ErrorCount = Math.floor(PrintList.length/2);
  	this.WrongElements.length = this.ErrorCount;
  	for (j=0; j<this.ErrorCount ;j++) this.WrongElements[j]=this.CheckFields[PrintList[(j*2)]];
  	for (i=0; i<this.ErrorCount ;i++){
  	  	this.WrongElements[i].Errorlist.ClearErrorlist();
    		var DummyList = PrintList[(i*2+1)];
    		for (k in DummyList) {
    			if (isNaN(DummyList[k])){
    				this.WrongElements[i].Errorlist.AddError(-1,DummyList[k]);
    			}else{
    				this.WrongElements[i].Errorlist.AddError(DummyList[k],'');
    			}
    		}
  	}
  	this.ActuelError=-1;
  	TestIt=false;
  	this.Next();
  }
}

TCheckForm.prototype.Next = function(){
  if(!TestIt) this.ActuelError++;
  if(this.ActuelError<this.ErrorCount){
    var RefField=this.WrongElements[this.ActuelError];
  /*  if(TestIt){
      if(!RefField.FindError()){
//	RefField.lighten(false);
        this.ActuelError++;
        if (this.ActuelError<this.ErrorCount)
          RefField=this.WrongElements[this.ActuelError];
      }
    }*/
    if(this.ActuelError<this.ErrorCount){
      if(RefField.setFocus){
      	 this.PrintError(2,RefField);
	 this.Reminder=RefField;
	 dbWrite('ERROR#', this.ActuelError,' FOR',RefField.Name,RefField.Ref,RefField.Ref.type);

      	 if(RefField.Type!='radio'){
      	 	if(RefField.Ref) RefField.Ref.focus();
      	 }else{
      	 	if(RefField.Ref[0]) RefField.Ref[0].focus();
      	 }
      	 //this.CheckFocus=true;
      }
    }else{
      this.PrintError(3,RefField);
    }
  }else{
   // this.CheckFocus=true;
    this.PrintError(3,this.WrongElements[(this.ErrorCount-1)]);
  }
}


TCheckForm.prototype.Check = function(doSubmit, doCheck){
  var GetASubmit=true;
if(doCheck){
  this.FirstCheck=true;
  this.CheckFocus=false;
  this.ErrorCount=0;
  if(this.Reminder && this.Reminder.FindError()){
//  	dbWrite('CHECK2:');
      	this.WrongElements[this.ErrorCount]=this.Reminder;
      	this.ErrorCount++;
  }else{
  	for(var q in this.CheckFields){
    	  if (this.CheckFields[q].FindError()){
//	    dbWrite('CHECK FOUND ERROR:',q);
	    this.WrongElements[this.ErrorCount]=this.CheckFields[q];
      	    this.ErrorCount++;
      	    break;
    	  }//else this.CheckFields[q].lighten(false);
  	}
  }
  if (this.ErrorCount>0) {
    this.ActuelError=0;
    TestIt=true;
    this.Next();
    GetASubmit=false;
  }
  this.CheckFocus=true;
}
if (GetASubmit && doSubmit) this.Submit(doSubmit);	//changed 01.10.
return GetASubmit;  // <-- neu  01.10.
}

TCheckForm.prototype.PrintError = function(art,FieldRef,fehler){
var ErrCntr=document.getElementById(FieldRef.ErrCntr);
var ErrCntrContent=document.getElementById(FieldRef.ErrCntr+'Content');
if(ErrCntr && ErrCntrContent){
  var text="";
  if(art==0){
    if (fehler){
      text=FieldRef.Errorlist.Errorlist[1][(FieldRef.Errorlist.Errorlist[1].length-1)];
      setStatus(text);
    }else setStatus('');
  }
//  dbWrite("Printing error ART",art);
  if((art==1)||(art==2)||(art==4)){
    for (var i in FieldRef.Errorlist.Errorlist[1]){
       if (FieldRef.Errorlist.Errorlist[0][i]==-1) text+=FieldRef.Errorlist.Errorlist[1][i]+" ";
    }
    ErrCntrContent.innerHTML=text;
    self.setTimeout('switchStyleClass(document.getElementById("'+FieldRef.ErrCntr+'"), "errContainerVisible");',180);
    //ErrCntr.setAttribute("class", "errContainerVisible");

  }
  if(art==3){
     // ErrCntrContent.innerHTML='';
     self.setTimeout('switchStyleClass(document.getElementById("'+FieldRef.ErrCntr+'"), "errContainerHidden");',180);

//    FieldRef.lighten(false);
    this.checkIt=0;
    if (FieldRef.Name!=pseudoForm) FieldRef.result=FieldRef.Ref.value;
  }
}
}


TCheckForm.prototype.Submit = function(doSubmit){
  for(var q in this.CheckFields){
    var ii=this.CheckFields[q];
    if(ii.Ref && (ii.Ref.type=="text" || ii.Ref.type=="textarea") && ii.Ref.value==ii.DefaultValue) ii.Ref.value="";
  }
  if(doSubmit) this.Ref.submit();
}


/******************************************************************************************
******************** used for Input-text-,-password and textarea-fields **************
******************************************************************************************/
function TCheckField(Name,Type,Required,MinL,MaxL,MinValue,MaxValue,RegEx,RegExMsg,TstCode,CheckFormRef,KeyFlag,Caption,DefaultValue,ErrCntr,ExtraCheck, Ref){
  this.Name = Name;
  this.Required=Required;
  this.DefaultRequired=Required;
  this.MinL=MinL;	// Zeichen
  this.MaxL=MaxL;
  this.MinValue=MinValue;	// Werte, zb. datum
  this.MaxValue=MaxValue;
  this.Type=Type;
  this.RegEx=RegEx;
  this.RegExMsg=RegExMsg;
  this.TstCode=TstCode;
  this.ErrCntr=ErrCntr;
  this.Caption=Caption;
  this.DefaultValue=DefaultValue;
  this.ExtraCheck=ExtraCheck || '0';
  this.CharCondition=0;
  this.Errorlist=new TErrorlist(this);
  this.CheckFormRef=CheckFormRef;	// Ref auf CheckFormClasse
  this.Ref=Ref || CheckFormRef.Ref[Name];	// Ref auf HTML-Name des HTML-Objektes in der Form
  this.KeyFlag=KeyFlag;
  this.FocusFlag=false;
  if ((is.ie)&&(is.os=="mac")) this.KeyFlag=false;
  this.result=this.getCurrentValue();
  this.activ=true;
  this.setFocus = true;
	this.aOnKeyPressFunctions = new Array();	// zus. Events-Functions, die aus der jew. KlassenMethode aufgerufen werden, z.B. "obj.CheckFormRef.win.Test()";
	this.aOnFocusFunctions = new Array();
	this.aOnBlurFunctions = new Array();
}

TCheckField.prototype.start = function(){
  if((this.Ref.type=="text" || this.Ref.type=="textarea") && this.Ref.value=="" && this.DefaultValue!=""){
	this.Ref.value=this.DefaultValue;
	this.Ref.defaultValue=this.DefaultValue;
  }
  if (this.KeyFlag) this.AddHandler("onkeypress",this.onKP);

  this.AddHandler("onblur",this.ResetStatus);
    this.AddHandler("onfocus",this.MadeACheckLight);
  if(this.Type=='radio') this.AddHandler("onchange",this.ResetStatus);
 // if(this.Type=='checkbox') this.AddHandler("onclick",this.ResetStatus);
}

TCheckField.prototype.AddHandler = function(EventName,Handler){
  var TCheck = this;
	if(TCheck.Type=='radio'){
	  for(var i=0;i<TCheck.Ref.length;i++){
	  	TCheck.Ref[i][EventName] = function(Ev){
	  		return Handler(TCheck,Ev);
  	  	}
  	  }
  	}else{
  		TCheck.Ref[EventName] = function(Ev){
    	  		return Handler(TCheck,Ev);
  	  	}
  	}
}

TCheckField.prototype.lighten = function(err){
  if(is.dom)
    if(err){
    	 this.Ref.style.color=ErrorColor;
    }else{
    	 this.Ref.style.color="#000000";
    }
}

TCheckField.prototype.IsItEmail = function(){
	if(this.Ref.value.length>0){
		var email=this.Ref.value.split("@");
		if (email.length==2){
			if (email[0].match(/^([\w\-]+[\w\-\.])*[\w\-]+$/)==null){
				 this.Errorlist.AddError(-1,'Bitte eine gültige E-Mail-Adresse angeben.');
			}
			var host=new Array();
			host[0]=email[1].substring(0,email[1].lastIndexOf('.'));
			host[1]=email[1].substring(email[1].lastIndexOf('.')+1,email[1].length);
			if(host[0]=='' ||  host[0].length<2 || host[0].match(/^([\w\-]+[\w\-\.])*[\w\-]+$/)==null)
				this.Errorlist.AddError(-1,'Bitte einen gültigen Domainnamen für die E-Mail-Adresse angeben.');
			else
				if(host[1]=='' || host[1].match(/^([a-zA-Z]{2,5})$/)==null) this.Errorlist.AddError(-1,'Bitte einen gültigen Domainnamen für die E-Mail-Adresse angeben.');
		}else{
			if(email.length<2) var message="Bitte eine gültige E-Mail-Adresse angeben."; else var message="Bitte eine gültige E-Mail-Adresse angeben.";
			this.Errorlist.AddError(-1,message);
		}
	}
}


function getDateFormat(v){
	var arrDate=v.match(/(\d{1,2})[\.](\d{1,2})[\.](\d{1,4})/);
	var res=null;
	var ErrMsg='';
	if(!arrDate)
		ErrMsg='hat nicht das erwartete Datumsformat';
	else{
		var d=parseInt(arrDate[1],10);
		var m=parseInt(arrDate[2],10);
		var y=parseInt(arrDate[3],10);
		if(y || y==0){
			if(y>=10 && y<=99) y+=1900;
			if(y<10) y+=2000;
		}
		var maxd=MonthDays[m];
		if(m==2){
			if(y%4==0 && (y%100!=0 || (y%400==0)))  maxd=29;
			else maxd=28;
		}
		if(!d || d<1 || d>maxd) ErrMsg='hat nicht das erwartete Datumsformat, die Tagesangabe ist ungültig.';
		if(!m || m<1 || m>12) ErrMsg='hat nicht das erwartete Datumsformat, die Monatsangabe ist ungültig.';
		if(!y || y<1900) ErrMsg='hat nicht das erwartete Datumsformat, die Jahresangabe ist ungültig.';
		if(ErrMsg=='') res=new Date(y,m-1,d);
	}
	dbWrite('getDateFormat',v,arrDate,res,ErrMsg);
	return [res,ErrMsg];
}

function getDateString(date){
	var td=(date.getDate()<10)?'0':'';
	td+=date.getDate()+'.';
	td+=(date.getMonth()+1<10)?'0':'';
	td+=(date.getMonth()+1)+'.'+date.getFullYear();
	return td;
}

TCheckField.prototype.checkDateFormat = function(){
	var tD=getDateFormat(this.Ref.value);
	if(!tD[0] && tD[1]!=''){
		this.Errorlist.AddError(-1,this.Caption+' '+tD[1]);
	}
	return tD[0];
}

TCheckField.prototype.IsItDate = function(){
	if(this.Ref.value.length>0){
		var date=this.checkDateFormat();
		if(date!=null){
			if(this.ExtraCheck=='Date'){
				var refer=null;
				if(this.MinValue && this.MinValue!=''){
					if(this.MinValue=='Now()') refer=new Date();else refer=getDateFormat(this.MinValue)[0];
					if(refer && date < refer) this.Errorlist.AddError(-1,this.Caption+' nicht gültig, das Datum muß nach dem '+getDateString(refer)+' liegen.');
				}
				if(this.MaxValue && this.MaxValue!=''){
					if(this.MaxValue=='Now()') refer=new Date();else refer=getDateFormat(this.MaxValue)[0];
					if(refer && date > refer) this.Errorlist.AddError(-1,this.Caption+' nicht gültig, das Datum muß vor dem '+getDateString(refer)+'.'+' liegen.');
				}
			}
			if(this.ExtraCheck=='Age'){
				if(this.MinValue && this.MinValue!=''){
					var refer=new Date();
					var arefer=new Date(refer.getFullYear()-this.MinValue,refer.getMonth(),refer.getDate());
					if(date > arefer)
						 this.Errorlist.AddError(-1,this.Caption+' nicht gültig, sie müssen mindestens '+this.MinValue+' Jahre alt sein.');
					else
					if(date > refer)
						 this.Errorlist.AddError(-1,this.Caption+' ist kein erlaubtes Datum.');
				}
			}
			if(this.Errorlist.Errorlist[0].length==0) this.Ref.value=getDateString(date);
		}
	}
}

TCheckField.prototype.RegExCheck = function(){
	var aVal=new String(this.Ref.value);
	var test=null;
	if(aVal!='' && this.RegEx!=''){
		var d = this.RegEx.substring(0,1);
		if(d=="!"){
			d = this.RegEx.slice(1);
			test=eval('String(aVal).match('+d+')');
	        	if(test==null) this.Errorlist.AddError(-1,this.Caption+' '+this.RegExMsg+'.');
		}
		if(d=="/"){
			test=eval('String(aVal).match('+this.RegEx+')');
			if(test) this.Errorlist.AddError(-1,this.Caption+' '+this.RegExMsg+'.');
          	}
	}
}

TCheckField.prototype.TestNumber = function(){
  var digit=new Number(this.Ref.value);
  if (this.MaxValue!=null) if (digit>this.MaxValue) this.Errorlist.AddError(-1,this.Caption+' ist zu hoch.');
  if (this.MinValue!=null) if (digit<this.MinValue) this.Errorlist.AddError(-1,this.Caption+' ist zu niedrig.');
}
TCheckField.prototype.CountChar = function(CharSet){
  var count=0;
  for (var j=0;j<this.Ref.value.length;j++) if (AllowedList[CharSet].indexOf(this.Ref.value.charAt(j))>-1) count++;
  return count;
}

TCheckField.prototype.ExtraInterpret = function(){
  if(this.ExtraCheck=='Date' || this.ExtraCheck=='Age') this.IsItDate();
  for (var i=0;i<this.ExtraCheck.length;i++){
    if (this.ExtraCheck.charAt(i)=='1') this.IsItEmail();
    if (this.ExtraCheck.charAt(i)=='2') this.TestNumber();
  }
}

TCheckField.prototype.getCurrentValue = function(){
  var Res='';
  if(this.Type=="radio"){
  	var allDis=true;
  	for(var i=0;i<this.Ref.length;i++){
  		if(!this.Ref[i].disabled){
  			allDis=false;
  			if(this.Ref[i].checked) Res=this.Ref[i].value;
  		}
  	}
  	if(allDis) Res=null;
  	return Res;
  }
  if(this.Ref.type=="text" || this.Ref.type=="textarea" || this.Ref.type=="password") Res=this.Ref.value;
  if(this.Ref.type=="select-one") Res=this.Ref.selectedIndex;
  if(this.Ref.type=="checkbox" && this.Ref.checked) Res=this.Ref.value;
  return Res
}

TCheckField.prototype.setCurrentValue = function(valu){
  if(this.Type=="radio"){
  	var allDis=true;
  	for(var i=0;i<this.Ref.length;i++){
  		if(!this.Ref[i].disabled){
  			allDis=false;
  			if(this.Ref[i].value==valu) this.Ref[i].checked=true;
  		}
  	}
  	if(allDis) Res=null;
  	return null;
  }
  if(this.Ref.type=="checkbox"){
  	if(valu==null || valu=='' || valu==false || valu=='false' || valu!=this.Ref.value) this.Ref.checked=false;
	else this.Ref.checked=true;
  }
  if(this.Ref.type=="text" || this.Ref.type=="textarea" || this.Ref.type=="password") this.Ref.value=valu;
  if(this.Ref.type=="select-one") if(valu==null || valu=='') this.Ref.selectedIndex=0;
  else this.Ref.selectedIndex=valu;
  return true;
}


TCheckField.prototype.FindError = function(){
  this.Errorlist.ClearErrorlist();
  var value=this.getCurrentValue();

  if(this.Type=="radio"){
  	if(this.Required && value!=null && value==''){
  	  this.Errorlist.AddError(-1,this.Caption+' ist ein Pflichteintrag, bitte wählen.');
  	  return true;
  	}else return false;
  }else{
	  if(!this.Ref.disabled){
		if(this.Ref.type=="checkbox"){
			if (this.Required && this.Ref.checked!=true){
				this.Errorlist.AddError(-1,this.Caption+' ist ein Pflichtfeld, bitte akzeptieren.');
				return true;
			}else return false;
		}


 		if(value!="" && value!=this.DefaultValue){
  			if(this.ExtraCheck && this.ExtraCheck!='0') this.ExtraInterpret();
  			if(this.RegEx!='') this.RegExCheck();
   			if(value.length<this.MinL){
				this.Errorlist.AddError(-1,this.Caption+' ist zu kurz.');
    			}else if(value.length>this.MaxL) this.Errorlist.AddError(-1,this.Caption+' ist zu lang, bitte auf maximal '+this.MaxL+' Zeichen kürzen.');
			for(var i=0;i<value.length;i++) if(!this.CheckChar(value.charAt(i))){
				this.Errorlist.AddError(-1,this.Caption+' enthält unerlaubte Zeichen ('+value.charAt(i)+').');
				this.CheckFormRef.CheckFocus=false;
				break;
			}
    		}else if(this.Required) this.Errorlist.AddError(-1,this.Caption+' ist ein Pflichteintrag, bitte das Formularfeld füllen.');
	//   dbWrite("TCheckField.FindError:",this.Name,this.Caption,'#',this.Errorlist.Errorlist[0].length);
 	 }
  }
//  dbWrite('FUNCTION FindError',this.Errorlist.Errorlist[0].length);
  if(this.Errorlist.Errorlist[0].length>0) return true; else return false;
}

TCheckField.prototype.Check = function(obj){
//  dbWrite("CHECK:",this.Name);
  var res=this.FindError();
  if (res){
    this.CheckFormRef.PrintError(1,this);
   // if (is.ns6) self.setTimeout('document.forms.'+this.CheckFormRef.FormName+'["'+this.Ref.name+'"].focus();',10); else
    this.Ref.focus();
  }else{
    this.CheckFormRef.Reminder=obj;
    this.CheckFormRef.PrintError(3,this);
  }
  return res;
}

//called onblur:
TCheckField.prototype.ResetStatus = function(obj,Erg){
if(!Erg) Erg=window.event;
//  dbWrite('Resetting Status for '+obj.Name+',REMINDER: '+obj.CheckFormRef.Reminder,obj.CheckFormRef.CheckFocus,Erg.type);
  self.setStatus('');
  if(obj.CheckFormRef.FirstCheck){
  	if(obj.FindError())
  		obj.CheckFormRef.PrintError(1,obj);
    	 else
    	 	obj.CheckFormRef.PrintError(3,obj);
		//self.setTimeout('CheckDomForms["'+obj.CheckFormRef.instName+'"].PrintError(3,CheckDomForms["'+obj.CheckFormRef.instName+'"].CheckFields["'+obj.Name+'"]);',180);
   }
  //Resetting Caption:
  if((obj.Ref.type=="text" || obj.Ref.type=="textarea")){
  	 if(obj.Ref.value==""){
  	   obj.Ref.value=obj.DefaultValue;
  	 }
  }
  return true;
//	execObj(obj.aOnBlurFunctions);	// run user defined functions
}

//called onfocus;
TCheckField.prototype.MadeACheck = function(obj,Erg){ //obj has the new focus
  var reminder=obj.CheckFormRef.Reminder;
  if (obj.activ){
    //dbWrite("MadeACheck 1: Reminder="+reminder.Name+"; Obj="+obj.Name);
    if (reminder && (reminder!=obj)&&(obj.CheckFormRef.CheckFocus)){
     //   dbWrite("MadeACheck 2: Reminder="+reminder.Name+"; Obj="+obj.Name);
        reminder.Check(obj); //no error in reminder, go ahead!
   //     dbWrite("MadeACheck 3a: Reminder="+reminder.Name+"; Obj="+obj.Name);
     }else
        if(!obj.CheckFormRef.Reminder) obj.CheckFormRef.Reminder=obj;
     if(reminder && (reminder.Ref.type=="text" || reminder.Ref.type=="textarea") && reminder.Ref.value==reminder.DefaultValue){
	reminder.Ref.value="";
//	dbWrite("MadeACheck 4b:"+obj.Name+' SET TO EMPTY, Reminder='+reminder.Name+"; Obj="+obj.Name);
       // eval(reminder.Ref.focus());
     }

  }else reminder.Ref.focus();
//  execObj(obj.aOnFocusFunctions);	// run user defined functions
}

//called onfocus;
TCheckField.prototype.MadeACheckLight = function(obj,Erg){ //obj has the new focus
//  if (obj.activ){
     var reminder=obj.CheckFormRef.Reminder;
     if(obj && obj.Ref && (obj.Ref.type=="text" || obj.Ref.type=="textarea") && obj.Ref.value==obj.DefaultValue){
	obj.Ref.value="";
     }
//  }
}

TCheckField.prototype.CheckChar = function(zeichen){
  if(this.TstCode.length>0){
    var res=false;
    for(var i in this.TstCode) for(var j in AllowedList) if(this.TstCode[i]==j) if(AllowedList[j].indexOf(zeichen)>-1) res=true;
    return res;
  }else return true;
}

TCheckField.prototype.onKP = function(obj,Erg){
  var res=false;
  if(is.ie) Erg=obj.CheckFormRef.win.event;
  var ch = (Erg.charCode || Erg.charCode==0) ? Erg.charCode :
                Erg.keyCode ? Erg.keyCode :
		Erg.which ? Erg.which : void 0;
  var zeichen=String.fromCharCode(ch);
  //dbWrite('keypressed',this,obj,Erg,Erg.cancelable,ch,zeichen,Erg.isChar, Erg.keyCode,  Erg.charCode  );
  if(ch!=8 && ch!=0 && ch!=13){
    if( ch!=180 && ch!=94) if(!obj.CheckChar(zeichen)) obj.Errorlist.AddError(obj.Ref.value.length,'Fehler: '+zeichen+' kann nicht verwendet werden.'); else res=true;
  }else res=true;
  obj.CheckFormRef.PrintError(0,obj,!res);
  execObj(obj.aOnKeyPressFunctions);  // run user defined functions
  if(!res){
  	if(window.event && window.event.preventDefault && !window.opera) window.event.preventDefault();
  	if(Erg.preventDefault) Erg.preventDefault();
  	dbWrite('preventing');
  }
  return res;
}

TCheckField.prototype.setActive = function(activ,store){
	  if(activ){
		if(!this.activ){
			this.Ref.disabled=false;
			if(store==true) this.setCurrentValue(this.result);
			this.setRequired(this.DefaultRequired);
		}
	  }else{
	  	if(this.activ){
			this.result=this.getCurrentValue();
			if(store==true) this.setCurrentValue("");
			this.Ref.disabled=true;
			this.setRequired(false);
		}
	  }
	this.activ=activ;
}

TCheckField.prototype.setActiveRadioG = function(activ,store){
  if(activ){
  	if(!this.activ){
  		if(store==true && this.result) this.result.checked;
  		for(var i=0;i<this.Ref.length;i++){
  			if(store==true && this.result) this.result.checked=true;
	 		this.Ref[i].disabled=false;
		}
		this.setRequired(this.DefaultRequired);
	}
  }else{
    	if(this.activ){
    		this.result=null;
    		for(var i=0;i<this.Ref.length;i++){
  			if(store==true && this.Ref[i].checked){
  				 this.result=this.Ref[i];
  				 this.Ref[i].checked=false;
  			}
	 		this.Ref[i].disabled=true;
		}
		this.setRequired(false);
	}
  }
  this.activ=activ;
}

TCheckField.prototype.setRequired = function(Req){
    this.Required=Req;
    setRequiredLabel(this.Ref.id,Req,this.CheckFormRef.Ref);
    if(this.Errorlist.Errorlist[0].length>0) this.ResetStatus(this);
}

onLoadObj[onLoadObj.length]="CreateCheckForms(self);";
