// validation.js// ###########################function SubmitViewForm( ThisForm) {		return SubmitForm( ThisForm);	}function SubmitForm( ThisForm) {// alert("SubmitForm: " + ThisForm.name);if ( ValidateFormInput(ThisForm) == false ){	//return false;	return ;}// Doppelklick verhindernif( isdocbeingsaved ) {	return;}else {	isdocbeingsaved  =  true ;	ThisForm.submit();}}function ValidateFormInput(ThisForm) {var msg = "";var tmp = "" ;var formname = ThisForm.name ;FeldNamen = new Array;Warnungen = new Array;var n = 0FeldNamen[n] = "Datum";Warnungen[n] = "Bitte geben Sie ein g\u00FCltiges Datum ein.";n=n+1FeldNamen[n] = "Subject";Warnungen[n] = "Bitte geben Sie ein Thema ein.";n=n+1FeldNamen[n] = "SubjectSMS";Warnungen[n] = "Bitte geben Sie einen Text f\u00FCr die SMS ein.";n=n+1FeldNamen[n] = "netz";Warnungen[n] = "Bitte w\u00E4hlen Sie ein Mobilfunknetz aus.";n=n+1FeldNamen[n] = "nummer";Warnungen[n] = "Bitte geben Sie eine g\u00FCltige SMS-Nr ein.";n=n+1FeldNamen[n] = "Vorname";Warnungen[n] = "Bitte geben Sie einen Vornamen ein.";n=n+1FeldNamen[n] = "Nachname";Warnungen[n] = "Bitte geben Sie einen Nachnamen ein.";if( formname == "_inpKalender"  || formname == "_inpNLAbo" ){n=n+1FeldNamen[n] = "Telefon";Warnungen[n] = "Bitte geben Sie eine Telefon-Nr. ein.";}n=n+1FeldNamen[n] = "Redaktion";Warnungen[n] = "Bitte geben Sie Ihre Redation ein.";n=n+1FeldNamen[n] = "Email";Warnungen[n] = "Bitte geben Sie eine g\u00FCltige E-Mail-Adresse ein.";n=n+1FeldNamen[n] = "SendTo";Warnungen[n] = "Bitte geben Sie eine g\u00FCltige Empf\u00E4nger-E-Mail-Adresse ein.";n=n+1FeldNamen[n] = "ReplyTo";Warnungen[n] = "Bitte geben Sie eine g\u00FCltige Absender-E-Mail-Adresse ein.";n=n+1FeldNamen[n] = "Funktion";Warnungen[n] = "Bitte geben Sie Ihre Funktion ein.";if( formname == "_inpKalender" || formname == "_inpBroschOrder"  || formname == "_inpNLAbo" || formname == "_inpFootageOrder"){n=n+1FeldNamen[n] = "Strasse";Warnungen[n] = "Bitte geben Sie eine Strasse ein.";n=n+1FeldNamen[n] = "PLZ";Warnungen[n] = "Bitte geben Sie eine Postleitzahl ein.";n=n+1FeldNamen[n] = "Ort";Warnungen[n] = "Bitte geben Sie einen Ort ein.";}if( formname == "_inpBroschOrder" ){n=n+1FeldNamen[n] = "Choices";Warnungen[n] = "Bitte w\u00E4hlen Sie mindestens eine Brosch\u00FCre aus.";}if( formname == "_inpNLAbo" ){n=n+1FeldNamen[n] = "Choices";Warnungen[n] = "Bitte w\u00E4hlen Sie mindestens einen Newsletter-Bereich aus.";}for (z=0; z<FeldNamen.length; z++) {	if ( eval('ThisForm.' + FeldNamen[z]) ) { 			// Gibt es das Feld auf der Form \u00FCberhaupt?		// Feld-Wert auslesen		if(FeldNamen[z] == "Choices") {						var inp = ReadRadio( eval('ThisForm.' + FeldNamen[z] ) );		// Ist wenigstens eine Option gew\u00E4hlt			if( formname == "_inpNLAbo" && inp == "" ) {				// Auch ChoicesRegio mit einbeziehen				var inp = ReadRadio( eval('ThisForm.' + FeldNamen[z] + 'Regio' ) );		// Ist wenigstens eine Option gew\u00E4hlt			}		}		else {			if(FeldNamen[z] == "netz") {				// SMS-Vorwahl				var inp = getSelectedValueText(ThisForm.netz) ;			}			else {				var inp = eval('ThisForm.' + FeldNamen[z] + '.value') ;			}		}		if(FeldNamen[z] == "ReplyTo") {				if ( !ValidateEmail ( inp ) ) {			msg = msg + "\n" + Warnungen[z];					}		}		else if(FeldNamen[z] == "Datum") {				if ( !isDate ( inp ) ) {			msg = msg + "\n" + Warnungen[z];					}		}		else if(FeldNamen[z] == "netz") {					if ( left(inp, 1 ) != "0" ) {					msg = msg + "\n" + Warnungen[z];				}			}		else if(FeldNamen[z] == "nummer") {				tmp = ValidateMobilNr(inp) ;			if ( tmp != "") {			// Jetzt Spezial-Warnungen in ValidateMobilNr			msg = msg + "\n" + tmp;					}		}						else if(FeldNamen[z] == "Choices") {				if ( inp == "" ) {			msg = msg + "\n" + Warnungen[z];					}		}				else {			if ( inp == "" ) { 			msg = msg + "\n" + Warnungen[z];						}		}	}}// msg = "" bedeutet: Alles gutif (msg != "") {	alert(msg);	return false;}return true}// ###########################function ValidateEmail (emailStr) {/* Pattern to check if the entered e-mail address fits the user@domain format. */var emailPat=/^(.+)@(.+)$//* Pattern to check for special characters we don't want, including ( ) < > @ , ; : \ " . [ ] */var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"/* The following string represents the range of characters allowed in a username or domainname */var validChars="\[^\\s" + specialChars + "\]"/* The following pattern applies if the "user" is a quoted string, E.g. "jiminy cricket"@disney.com */var quotedUser="(\"[^\"]*\")"/* Pattern for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$//* The following string represents an atom (basically a series of non-special characters.) */var atom=validChars + '+'/* The following string represents one word in the typical username. For example, in john.doe@themorgue.hell, john and doe are words */var word="(" + atom + "|" + quotedUser + ")"// The following pattern describes the structure of the uservar userPat=new RegExp("^" + word + "(\\." + word + ")*$")/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")/* Finally, let's start trying to figure out if the supplied address is valid. *//* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */var matchArray=emailStr.match(emailPat)if (matchArray==null) {/* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. *///alert("Email address seems incorrect (check @ and .'s)")return false}var user=matchArray[1]var domain=matchArray[2]// See if "user" is valid if (user.match(userPat)==null) {// user is not valid// alert("The username doesn't seem to be valid.")return false}/* if the e-mail address is at an IP address make sure the IP address is valid. */var IPArray=domain.match(ipDomainPat)if (IPArray!=null) {// this is an IP addressfor (var i=1;i<=4;i++) {if (IPArray[i]>255) {// alert("Destination IP address is invalid!")return false}}return true}// Domain is symbolic namevar domainArray=domain.match(domainPat)if (domainArray==null) {// alert("The domain name doesn't seem to be valid.")return false}/* domain name seems valid, but now make sure that it ends in a three-letter word (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. *//* Now we need to break up the domain to get a count of how many atoms it consists of. */var atomPat=new RegExp(atom,"g")var domArr=domain.match(atomPat)var len=domArr.lengthif (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {// the address must end in a two letter or three letter word. //alert("The address must end in a 4-letter domain, or two letter country.")return false}// Make sure there's a host name preceding the domain.if (len<2) {var errStr="This address is missing a hostname!"// alert(errStr)return false}// If we've gotten this far, everything's valid!// alert(emailStr + ' seems to be a valid address!');return true;}function isDate(dtStr){	// Declaring valid date character, minimum year and maximum year	var dtCh= ".";	var minYear=2002;	var maxYear=2100;	var daysInMonth = DaysArray(12)	var pos1=dtStr.indexOf(dtCh)	var pos2=dtStr.indexOf(dtCh,pos1+1)	var strDay=dtStr.substring(0,pos1)	var strMonth=dtStr.substring(pos1+1,pos2)	var strYear=dtStr.substring(pos2+1)	strYr=strYear	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)	for (var i = 1; i <= 3; i++) {		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)	}	month=parseInt(strMonth)	day=parseInt(strDay)	year=parseInt(strYr)	if (pos1==-1 || pos2==-1){//		alert("Bitte beachten Sie das Datumsformat: dd.mm.yyyy")		return false	}	if (month<1 || month>12){//		alert("Please enter a valid month")		return false	}	if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){//		alert("Please enter a valid day")		return false	}	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)		alert("Bitte geben Sie ein Datum nach dem 01.01." + minYear + " ein.")		return false	}	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){//		alert("Please enter a valid date")		return false	}return true}function isInteger(s){	var i;    for (i = 0; i < s.length; i++){           // Check that current character is number.        var c = s.charAt(i);        if (((c < "0") || (c > "9"))) return false;    }    // All characters are numbers.    return true;}function stripCharsInBag(s, bag){	var i;    var returnString = "";    // Search through string's characters one by one.    // If character is not in bag, append to returnString.    for (i = 0; i < s.length; i++){           var c = s.charAt(i);        if (bag.indexOf(c) == -1) returnString += c;    }    return returnString;}function daysInFebruary (year){	// February has 29 days in any year evenly divisible by four,    // EXCEPT for centurial years which are not also divisible by 400.    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );}function DaysArray(n) {	for (var i = 1; i <= n; i++) {		this[i] = 31		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}		if (i==2) {this[i] = 29}   }    return this}function ValidateMobilNr( theString ) {// Gibt Fehlermeldung oder "" zur\u00FCckvar cleanString = theString ;TakeoutStrings = new Array;TakeoutStrings[0] = "/";TakeoutStrings[1] = "-";TakeoutStrings[2] = " ";TakeoutStrings[3] = "+";for (i=0; i<TakeoutStrings.length; i++) {	cleanString = searchAndReplace(cleanString,TakeoutStrings[i],"") ;}cleanString = cleanString.substring(0,160) ;if (cleanString == "") {	return 'Bitte geben Sie eine Mobilfunk-Nr. innerhalb Deutschlands ein.' ;}var checkString = cleanString ;TakeoutNrs = new Array;TakeoutNrs[0] = "0";TakeoutNrs[1] = "1";TakeoutNrs[2] = "2";TakeoutNrs[3] = "3";TakeoutNrs[4] = "4";TakeoutNrs[5] = "5";TakeoutNrs[6] = "6";TakeoutNrs[7] = "7";TakeoutNrs[8] = "8";TakeoutNrs[9] = "9";for (i=0; i<TakeoutNrs.length; i++) {	checkString = searchAndReplace(checkString,TakeoutNrs[i],"") ;}if (checkString != "") {	return 'Bitte geben Sie nur Zahlen als Mobilfunk-Nr. ein.' ;}// Alles gut, leer zur\u00FCck geben	return "" ;}
