// Eigentum von und Copyright by TVC The Virtual Company New Media GmbH, Austria - www.tvc.at

// ErrBgColor muß gesetzt sein (z.B. var ErrBgColor = "#CDCFFF";)
var SetBgColor = true;
var crlf = "\x0d";
var IsFocusSet = false;
var msg = '';
var theForm;

var TxtSubmit, TxtNichtLeer, TxtAuswahlTreffen, TxtWertAusListe, TxtFeldWaehlen
var TxtKeineEMail, TxtZuKurz, TxtKeinAt, TxtKeinPkt, TxtUnGueltZeichen

function ChkInit(Lang) {

	switch (Lang) {
	case 'de':
		TxtNichtLeer = "Bitte füllen Sie dieses Feld aus."
		TxtAuswahlTreffen = "Bitte Auswahl treffen."
		TxtWertAusListe = "Bitte Wert aus Liste wählen."
		TxtFeldWaehlen = "Dieses Feld muss gewählt sein."
		TxtKeineEMail = "Keine gueltige E-Mail-Adresse"
		TxtZuKurz = "zuwenig Zeichen"
		TxtKeinAt = "kein @-Zeichen"
		TxtKeinPkt = "kein Punkt vorhanden"
		TxtUnGueltZeichen = "ungültiges Zeichen"
		TxtNurZiffern = "Bitte nur Ziffern eingeben."
		TxtZuLang = "Eingabe zu lang"
		TxtKeinDatum = "Kein gueltiges Datum [tt.mm.jjjj]"
		TxtFalschesFormat = "Falsches Format."
		TxtKeineZeit = "Keine gueltige Uhrzeit"
		TxtFalscheExt = "Falscher Dateityp."
		TxtWertUngueltig = "Wert ungültig."
		break;
		
	case 'it':
		TxtNichtLeer = "Per favore compilare questo campo."
		TxtAuswahlTreffen = "Scegliere, per favore."
		TxtWertAusListe = "Scegliere un valore dalla lista per favore."
		TxtFeldWaehlen = "Questo campo deve essere selezionato."
		TxtKeineEMail = "Indirizzo e-mail non valido."
		TxtZuKurz = "Caratteri insufficienti." //should be to
		TxtKeinAt = "Manca il simbolo @"
		TxtKeinPkt = "Manca il punto." 
		TxtUnGueltZeichen = "Carattere non valido."
		TxtNurZiffern = "Digitare solo cifre per favore."
		TxtZuLang = "Testo troppo lungo." //should be to too :-)
		TxtKeinDatum = "Formato data non valido [gg.mm.aaaa]"
		TxtFalschesFormat = "Formato errato."
		TxtKeineZeit = "Orario non valida."
		TxtFalscheExt = "Tipo dati errato."
		TxtWertUngueltig = "Valore errato."
		break;
		
	case 'fr':
		TxtNichtLeer = "Veuillez remplir cette case."
		TxtAuswahlTreffen = "Veuillez faire un choix."
		TxtWertAusListe = "Veuillez sélectionner un chiffre dans la liste."
		TxtFeldWaehlen = "Cette case doit être sélectionnée."
		TxtKeineEMail = "Ceci n'est pas une adresse E-mail valide."
		TxtZuKurz = "Nombre de signes insuffisant."
		TxtKeinAt = "Pas d'aérobase."
		TxtKeinPkt = "Pas de point." 
		TxtUnGueltZeichen = "Signe non valide."
		TxtNurZiffern = "Veuillez seulement taper des chiffres."
		TxtZuLang = "Trop long."
		TxtKeinDatum = "Date non valide [jour.mois.année]"
		xtFalschesFormat = "Format incorrect."
		TxtKeineZeit = "Heure non valide."
		TxtFalscheExt = "Type de dossier incorrect."
		TxtWertUngueltig = "Chiffre non valide."
		break;
		
	case 'hu':
		TxtNichtLeer = "Please insert information."
		TxtAuswahlTreffen = "Please make a selection."
		TxtWertAusListe = "Please choose item from list."
		TxtFeldWaehlen = "This field must be selected."
		TxtKeineEMail = "Invalid e-mail address."
		TxtZuKurz = "too few characters"
		TxtKeinAt = "no character @"
		TxtKeinPkt = "Contains no dot" 
		TxtUnGueltZeichen = "Invalid character."
		TxtNurZiffern = "Do only enter digits, please."
		TxtZuLang = "too many characters"
		TxtKeinDatum = "Not a valid date [dd.mm.yyyy]"
		TxtKeineZeit = "Not a valid time"
		TxtFalscheExt = "Wrong file-type."
		TxtWertUngueltig = "Invalid value."
		break;
	
	default:
		TxtNichtLeer = "Please insert information."
		TxtAuswahlTreffen = "Please make a selection."
		TxtWertAusListe = "Please choose item from list."
		TxtFeldWaehlen = "This field must be selected."
		TxtKeineEMail = "Invalid e-mail address."
		TxtZuKurz = "too few characters"
		TxtKeinAt = "no character @"
		TxtKeinPkt = "Contains no dot" 
		TxtUnGueltZeichen = "Invalid character."
		TxtNurZiffern = "Do only enter digits, please."
		TxtZuLang = "too many characters"
		TxtKeinDatum = "Not a valid date [dd.mm.yyyy]"
		TxtKeineZeit = "Not a valid time"
		TxtFalscheExt = "Wrong file-type."
		TxtWertUngueltig = "Invalid value."
		break;
	}
	
	if (!document.layers && SetBgColor) {
		for (i=0; i < theForm.length; i++){
			theForm[i].style.backgroundColor = "";
		}
	}
}

// bast 23.08.2005 Function soll die g&auml;ngigsten Hack-Versuche aufsp&uuml;ren
// momentan wird nur nach den tags (<SCRIPT, <SECURITY, <EXPLOIT) gesucht und wenn gefunden false zur&uuml;ckgeliefert
function IsPossibleHack(sInput)
{
	var sVerboten = /(<)+(\s*)+(script|security|exploit)/ig;
	if (sVerboten.test(sInput))
		return true;

	return false;
}

function ChkInpText(FldName, FriendlyName, iCheckHack) {

	if (theForm[FldName].value.length < 1) {
		if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
		if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
		msg += FriendlyName + ":  " + TxtNichtLeer + crlf;
		return false;
	}
	
	// bast 23.08.2005 
	if (iCheckHack == 1)
	{
		if (IsPossibleHack(new String(theForm[FldName].value))) 
		{
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ":  " + TxtUnGueltZeichen + crlf;
			return false;
		}
		
	}
	
	return true;
}

function ChkInpNumber(FldName, FriendlyName) {

	reason = "";
	ValidChar = "0123456789"
	theValue = theForm[FldName].value;

	
	if (theForm[FldName].value.length > 0) {
	
		for (i=0; i < theValue.length; i++) {
			if (ValidChar.indexOf(theValue.charAt(i)) < 0) {

				reason = " " + TxtNurZiffern;
				break;			
			}		
		}	
	
		if (reason.length) {
			
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ":  " + reason + crlf;
			return false;
		}
	}
	return true;
}

function ChkInpCheckbox(FldName, FriendlyName) {

	if (!theForm[FldName].checked) {
	
		if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
		if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
		msg += FriendlyName + ":  " + TxtFeldWaehlen + crlf;
		return false;
	}
	return true;
}

function ChkInpRadio(FldName, FriendlyName) {

	theFld = theForm[FldName];

	var i = 0;
	var CheckNr = -1;
	for (i=0; i<theFld.length; i++) {
		if (theFld[i].checked) { CheckNr = i; }
	}

	if (CheckNr < 0) {
	
		if (!document.layers && SetBgColor) {
			for (i=0; i<theFld.length; i++) {
				theFld[i].style.backgroundColor = ErrBgColor;
			}
		}
		if (!IsFocusSet) { theFld[0].focus(); IsFocusSet = true; }
		msg += FriendlyName + ":  " + TxtAuswahlTreffen + crlf;
		return false;
	}
	return true;
}

function ChkSelect(FldName, FriendlyName) {

	if (!theForm[FldName].selectedIndex) {
	
		if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
		if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
		msg += FriendlyName + ":  " + TxtWertAusListe + crlf;
		return false;
	}
	return true;
}

function ChkInpEMail(FldName, FriendlyName) {

	reason = "";
	ValidChar = "@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"
	theValue = theForm[FldName].value;
	
	if (theValue.length) {
	
		if (theValue.length < 7) { reason = " " + TxtZuKurz; };
		if (theValue.indexOf("@") < 0) { reason = " " + TxtKeinAt; };
		if (theValue.indexOf(".") < 0) { reason = " " + TxtKeinPkt; };

		for (i=0; i < theValue.length; i++) {
			if (ValidChar.indexOf(theValue.charAt(i)) < 0) {

				reason = " " + TxtUnGueltZeichen;
				break;			
			}		
		}	
	
		if (reason.length) {
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ": " + " " + TxtKeineEMail + "(" + reason + ")" + crlf;
			return false;
		}
		else {
			return true;
		}
	}
	return true;
}

function ChkInpDate(FldName, FriendlyName) {

	reason = "";
	ValidChar = "0123456789.-/"
	theValue = theForm[FldName].value;
	
	if (theValue.length) {
	
		if (!CheckDateFormat(theValue))
		{
			reason = " ";
		}
		
		if (theValue.length < 6) { reason = TxtZuKurz; };
		if (theValue.length > 10) { reason = TxtZuLang; };

		for (i=0; i < theValue.length; i++) {
			if (ValidChar.indexOf(theValue.charAt(i)) < 0) {

				reason = " " + TxtUnGueltZeichen;
				break;			
			}		
		}	
		
		if (reason.length) {
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ": " + " " + TxtKeinDatum
			if (reason != " ")
			{
				msg = msg + " (" + reason + ")";
			}
			msg = msg + crlf;
			return false;
		}
		else {
			return true;
		}
	}
	return true;
}

function CheckDateFormat(aktDate)
{
   var ergebnis_punkt;
   var ergebnis_strich;
   var ergebnis_slash;
   var Trennzeichen;
   
   ergebnis_punkt = aktDate.search(".");
   if (ergebnis_punkt != -1)
   	{Trennzeichen = ".";}
   	
   ergebnis_strich = aktDate.search("-");
   if(ergebnis_strich != -1)
   	{Trennzeichen = "-";}
   
   ergebnis_slash = aktDate.search("/");
   if (ergebnis_slash != -1)
   	{Trennzeichen = "/";}
   
   //alert("Trennzeichen: " + Trennzeichen);
   
   var datum = aktDate.split(Trennzeichen);
   
   var Day = datum[0];
   var Month = datum[1];
   var Year = datum[2];
   
   //alert(Day + "." + Month + "." + Year);  

   //if ((FldName.charAt(2)==Trennzeichen) && (FldName.charAt(5)==Trennzeichen))
   //{
       if ((Day<=31) && (Day>=1) && (Month>=1) && (Month<=12))
       {
         if((Month==1) || (Month==3) || (Month==5) || (Month==7) || (Month==8) || (Month==10) || (Month==12)) { return true; }
         else
         {
            if ((Day<=30) && (Day>=1))
            {
                if((Month==4) || (Month==6) || (Month==9) || (Month==11)) { return true; } 
                else
                {
                  if ((Day<=28) && (Day>=1)) { return true; }
                  else
                  {
                      if(Day==29)
                      {
                           if ((Year%4)==0)
                           {
                               if ((Year%100)!=0) { return true; }
                               else
                               {
                                     if ((Year%400)==0) { return true; }
                                     else { return false; }
                               }
                           }
                           else { return false; }
                      }
                      else { return false; }
                  }
                }
            }
            else { return false; }
         }
       }
       else { return false; }
}
//  else { return false; }
//}

function ChkInpTime(FldName, FriendlyName) {

	reason = "";
	ValidChar = "0123456789:"
	theValue = theForm[FldName].value;
	
	if (theValue.length) {
	
		if (theValue.length < 4) { reason = " " + TxtZuKurz; };
		if (theValue.length > 8) { reason = " " + TxtZuLang; };

		for (i=0; i < theValue.length; i++) {
			if (ValidChar.indexOf(theValue.charAt(i)) < 0) {

				reason = " " + TxtUnGueltZeichen;
				break;			
			}		
		}	
	
		if (reason.length) {
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ": " + " " + TxtKeineZeit + "(" + reason + ")" + crlf;
			return false;
		}
		else {
			return true;
		}
	}
	return true;
}

function ChkInpFile(FldName, FriendlyName) {
	
	theValue = theForm[FldName].value.toLowerCase();
	
	if (theValue.length) {
	
		Ext = '---';
		DotPos = theValue.lastIndexOf('.');
		
		if (DotPos >= 0) { Ext = theValue.substr(++DotPos); }
		
		if (ExtAllowed.indexOf(Ext) < 0) {
		
			if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
			if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
			msg += FriendlyName + ":  " + TxtFalscheExt + crlf; 
			return false;
		}
	}
	return true;
}

function ChkInpPassword(FldName, FriendlyName) {
	
	return ChkInpLen(FldName, FriendlyName, 4, 20);
}

function ChkInpLen(FldName, FriendlyName, FldLenMin, FldLenMax) {
	
	if (theForm[FldName].value.length < FldLenMin) {
		
		if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
		
		if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
		msg += FriendlyName + ": " + TxtZuKurz + " (min. " + FldLenMin + ")" + crlf;
		return false;
	}
	
	if (theForm[FldName].value.length > FldLenMax) {
		
		if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
		
		if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
		msg += FriendlyName + ": " + TxtZuLang + " (max. " + FldLenMax + ")" + crlf;
		return false;
	}
	
	return true;
}

function ChkInpAllEqual(FldName, FriendlyName) {

	var theValue = theForm[FldName].value;
	
	for (var i=0; i < theValue.length; i++) {
		
		if (theValue.charAt(0) != theValue.charAt(i)) {
		
			return true;	
		}
	}

	if (!document.layers && SetBgColor) { theForm[FldName].style.backgroundColor = ErrBgColor; }
	if (!IsFocusSet) { theForm[FldName].focus(); IsFocusSet = true; }
	msg += FriendlyName + ":  " + TxtWertUngueltig + crlf;
	return false;
}

function ChkInpPLZ(FldName, FriendlyName) {
	// Check Postleitzahl fuer Oesterreich, Deutschland, ...
	// Achtung: Geht nicht f&uuml;r England, Canada, ... (Buchstaben!)
	
	if (theForm[FldName].value.length) {
	
		if (ChkInpLen(FldName, FriendlyName, 4, 5)) {
			
			if (ChkInpNumber(FldName, FriendlyName)) {
				
				return ChkInpAllEqual(FldName, FriendlyName);
			}
			else {
				
				return false;
			}
		}
		else {
			
			return false;
		}
	}
	else {
		
		return false;
	}

	return false;
}