var bezWGlobal=0;
function validallformfields(steepID,subID,nextID,nSubID,savedAt){
	//alert(steepID)
	with (document.FOaddnewuser){
	if (saving_method.value=="updateuserdata"){
		if (steepID==1 || steepID=='save'){
			if (steepID=='save')
				moveToNext(1)
			if (userPassUpdateTwo.value!="" || userPassUpdateOne.value!=""){
				if (userPassOne.value=="" || userPassOne.value!=userPassOLD.value){
					alert("Bisheriges Passwort ist falsch!");
					return false;
				}
				if (userPassUpdateTwo.value!="" && userPassUpdateOne.value==""){
					alert("Bitte das neue Passwort eingeben, bevor du es bestätigst!");
					return false;
				}
				if (userPassUpdateOne.value!="" && userPassUpdateTwo.value==""){
					alert("Bitte dein neues Passwort bestätigen!");
					return false;
				}
				if (userPassUpdateOne.value==userPassOLD.value){
					alert("Das neue Passwort kann nicht gleich sein wie das Alte!");
					return false;
				}
				if (chkIdentity(userPassUpdateOne,userPassUpdateTwo, "Bestätigungspasswort", "Passwort") == false) return false	
			}
			if (userEmail.value=="")
				userEmail.value=userEmailOLD.value
			if (chkEmail(userEmail, "Email") == false) return false
		}
		if (steepID==2 || steepID =='save'){
			if (steepID=='save')
				moveToNext(2)
			if (userZIP.value!='' || userZIP.value!=0)
				if (chkNumber(userZIP, "Postleitzahl") == false) return false
			
			
		}
	}
	
	if (saving_method.value=="updateuserinserat"){
		if (steepID=='3' && subID=='1' || steepID=='save'){
			if (chkText(userPictureUrl, "Bild") == false) return false
	
		}else if (steepID=='3' && subID=='2' || steepID=='save'){
			if (steepID=='save')
				moveToNextSub(3,2)
				
			if(userPW_h.checked==true){bezWGlobal++;}
				
			if(userPW_a.checked==true){bezWGlobal++;}
			
			if(userPW_b.checked==true){bezWGlobal++;}
			
			if(userPW_e.checked==true){bezWGlobal++;}
			
			if(userPW_f.checked==true){bezWGlobal++;}
				
			if(userPW_p.checked==true){bezWGlobal++;}
				
			//alert(bezWGlobal);
			if (bezWGlobal==0){
				alert("Bitte mindestens eine Beziehungsart auswählen");
				return false;
			}
		}
		if (steepID==3 && subID==3 || steepID=='save'){
			if (steepID=='save')
				moveToNextSub(3,3)
					
		}
	}
	
	if (saving_method.value=="addnewuser"){
		if (steepID=='save'){
			moveToNext(0)
			if (userIsGut.value=="" || userIsGut.value==0){
				alert("Du musst die AllesLiebe-Spielregeln akzeptieren bevor du deine Daten speichern willst!");
				return false;
			}
		}
		if (steepID==1 || steepID=='save'){
			if (steepID=='save')
				moveToNext(1)
				
			if (chkText(userName, "Benutzername") == false) return false	
			if (chkText(userPassOne, "Passwort") == false) return false	
			if (chkText(userPassTwo, "Passwortbestätigung") == false) return false	
			if (chkIdentity(userPassOne,userPassTwo, "Passwortbestätigung", "Passwort") == false) return false	
			if (chkEmail(userEmail, "E-Mail") == false) return false
			if (chkText(userNickName, "Spitzname/Nickname") == false) return false
			if (chkNumber(userDay, "Geburtstag") == false) return false
			if (chkNumber(userMonth, "Geburtsmonat") == false) return false
			if (chkNumber(userYear, "Geburtsjahr") == false) return false
			testDate.value=userDay.value+'.'+userMonth.value+'.'+userYear.value
			if(checkValidDate(testDate.value)==false){
				alert('Eingebenes Geburtsdatum ist ungültig');
				userDay.focus();
				userDay.select();
				return false;
			}
			//if(chkDatePassed(testDate,'Geburts',eventOBDay)==false)return false;
			userBirth = userDay.value+'.'+userMonth.value+'.'+userYear.value;
			if (checkValidDate(userBirth) == false){
				alert("Das Geburtsdatum ist nicht korrekt!\n(Gültiges Format: TT.MM.JJJJ)");
				userDay.focus();
				return false;
			}
			var todayDate= new Date();
			if (((todayDate.getMonth())+1)<10)
				todayMonth='0'+(todayDate.getMonth()+1);
			else
				todayMonth=(todayDate.getMonth()+1);
			
			if (todayDate.getDate()<10)
				todayDay='0'+(todayDate.getDate());
			else
				todayDay=(todayDate.getDate());
			
			if (userMonth.value<10){
				if (userMonth.value.indexOf('0',0)==-1)
					userMonth.value='0'+userMonth.value;
			}
			if (userDay.value<10){
				if (userDay.value.indexOf('0',0)==-1)
					userDay.value='0'+userDay.value;
			}
				
			var nowYear=(((todayDate.getFullYear())-18)+''+todayMonth+''+todayDay);
			var userYearEdit=(userYear.value+''+userMonth.value+''+userDay.value);
			var isYear=(nowYear-userYearEdit);
			//alert(userYearEdit+'...'+nowYear+"---."+isYear+"");
			if (isYear<0){
				alert("Alles AllesLiebe-Services stehen nur Personen ab 18 Jahren zur Verfügung!");
				return false;
			}
			
			var userGender=0;
			for (u=0;u<userSex.length;u++){
				if (userSex[u].checked==true){
					userGender++;
				}
			}
			if (userGender==0){
				alert("Geschlecht ist Pflichtfeld, bitte auswählen!");
				return false;
			}
			if (steepID==1){
				document.FOaddnewuser.action="check_for_identity.asp";
				document.FOaddnewuser.submit();
			}
		}
		if (steepID==2 || steepID =='save'){
			if (steepID=='save')
				moveToNext(2)
			if (userURL.value!="http://" || userURL.value !=''){
				if (userURL.value.indexOf('.',0)==-1 && userURL.value!="http://" && userURL.value.indexOf('http://',0)==-1){
					if (userURL.value!="")
						alert("Das Homepage-URL - Format ist nicht korrekt!\n(Gültiges Format: http://www.yourWebSite.com)");
						userURL.focus();
						return false;
			}
			if (userZIP.value!='' || userZIP.value!=0)
				if (chkNumber(userZIP, "Postleitzahl") == false) return false
			
			if (userDay.value!='' || userDay.value!=0)
				if (chkNumber(userDay, "Geburtstag") == false) return false
				
			if (userMonth.value!='' || userMonth.value!=0)
				if (chkNumber(userMonth, "Geburtsmonat") == false) return false
			
			if (userYear.value!='' || userYear.value!=0)
				if (chkNumber(userYear, "Geburtsjahr") == false) return false
				
			if ((userDay.value!=0 || userDay.value!='') || (userMonth.value!=0 || userMonth.value!='') || (userYear.value!=0 || userYear.value!='')){
				userBirth = userDay.value+'.'+userMonth.value+'.'+userYear.value;
				if (checkValidDate(userBirth) == false){
					alert("Das Geburtsdatum-Format ist nicht korrekt!\n(Gültiges Format: TT.MM.JJJJ)");
					userDay.focus();
					return false;
				}
			}
		}
		if (steepID==3 || steepID =='save'){
			if (steepID=='save')
				moveToNext(3)
			
			if (subID == 1 || steepID == 'save'){
				if (userWeight.value!=0 || userWeight.value !='')
					if (chkNumber(userWeight, "Gewicht") == false) return false
			
				if (userHeight.value!=0 || userHeight.value!='')
					if (chkNumber(userHeight, "Größe") == false) return false
					
			}
			if (subID == 2 || steepID == 'save'){
				if (steepID=='save')
					moveToNextSub(3,2)	
				
					if (userURL.value.indexOf('<',0)!=-1 || userURL.value.indexOf('>',0)!=-1){
						if (userURL.value!="")
							alert("Bitte im Feld Homepage keine HTML-Tags verwenden!");
							userURL.focus();
							return false;
					}
				}
			}
		}
	}
	}
	
	if (nextID!=0 && nSubID == '' && steepID!='save')
		moveToNext(nextID)
	
	if (nextID!=0 && nSubID!=0 && steepID!='save')
		moveToNextSub(nextID,nSubID)
	
	if (steepID=='save')
		DoSubmitForm(savedAt)
		
}

function DoSubmitForm(sID)
{
	if (sID==0){
		document.FOaddnewuser.savedatsteep.value=0
		document.FOaddnewuser.savedatsub.value=0
	}
	document.FOaddnewuser.submit()
}

function saveThisForm(steepID,subID)
{
	if (subID==0)
		document.FOaddnewuser.savedatsteep.value=steepID
	else{
		document.FOaddnewuser.savedatsteep.value=steepID
		document.FOaddnewuser.savedatsub.value=subID
	}
	validallformfields('save',0,0,0,1)
}
function chkText(fname,ftext){
		if (!fname.value){
			alert(ftext + " ist ein Pflichtfeld. Bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}

	function chkAlphanum(fname,ftext){
		if (fname.value.length > 0){
			var x = fname.value;
			var filter  = /([a-zA-Z0-9])/;
			if (!filter.test(x)){
				alert("Das Feld " + ftext + " darf nur Zahlen und Buchstaben enthalten!");
				fname.focus();
				fname.select();
				return false;
			}
		} else {
			alert(ftext + " ist ein Pflichtfeld, bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}

	function chkNumber(fname,ftext){
		if (fname.value.length > 0){
			var x = fname.value;
			var filter  = /^([0-9]+)$/;
			if (!filter.test(x)){
				alert("Das Feld " + ftext + " darf nur Zahlen enthalten!");
				fname.focus();
				fname.select();
				return false;
			}
		} else {
			alert(ftext + " ist ein Pflichtfeld, bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}


	function chkList(fname,ftext){
		if (!fname.options[fname.selectedIndex].value){
			alert(ftext + " ist ein Pflichtfeld, bitte auswählen!");
			fname.focus();
			return false;
		}
	}
	
function chkIdentity(firstField,secondField,firstTxt, secondTxt)
{
	if (secondField.value!=firstField.value){
		alert("Deine "+firstTxt+" ist nicht identisch mit deinem "+secondTxt+".\nBitte korrigiere die Eingabe und klick \"weiter\".");
		secondField.focus();
		return false;
	}
}
	
function checkadd() {
	var ext1 = document.FOanmeldung.upfile.value;
  ext1 = ext1.substring(ext1.length-3,ext1.length);
  ext1 = ext1.toLowerCase();
  if(ext1 != 'jpg' && ext1 != 'gif' && ext1 != 'JPG' && ext1 != 'GIF')
	{ 
  	alert('Du hast eine .'+ext1+' Datei ausgewählt, bitte wähle nur *.jpg oder *.gif Dateien!');
		document.FOanmeldung.upfile.focus();
		return false;
  }
}

	function chkEmail(fname, ftext){
		if (fname.value.length > 0){
			var x = fname.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(x)){
				alert(ftext+" ist keine gültige E-Mail-Adresse!");
				fname.focus();
				return false;
			}
		} else {
			alert(ftext + " ist ein Pflichtfeld. Bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}

	function chkDate(fname, ftext){
		if (fname.value.length > 0){
			if (checkValidDate(fname) == false){
				alert("Das Datum " + ftext + " ist nicht korrekt!\n(Gültiges Format: TT.MM.JJJJ)");
				fname.focus();
				return false;
			}
		} else {
			alert(ftext + " ist ein Pflichtfeld, bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}

	function chkDatePassed(fname, ftext){
		if (fname.value.length > 0){
			var jetzt = new Date();
			d = fname.value.split(".");
			if ( Date.UTC(d[2],d[1]-1,d[0]) - Date.UTC(jetzt.getYear(),jetzt.getMonth(),jetzt.getDate()) < 0){
				alert("Das Datum " + ftext + " liegt in der Vergangenheit!")
				fname.focus();
				fname.select();
				return false;
			}
		} else {
			alert(ftext + " ist ein Pflichtfeld, bitte ausfüllen!");
			fname.focus();
			return false;
		}
	}

	function isDigit(theDigit){
		var digitArray = new Array('0','1','2','3','4','5','6','7','8','9'),j;
		for (j = 0; j < digitArray.length; j++)
			if (theDigit == digitArray[j])
				return true
		return false 
	}

	function isPositiveInteger(theString){
		var theData = new String(theString);
		if (!isDigit(theData.charAt(0)))
			if (!(theData.charAt(0)== '+'))
				return false
		
		for (var i = 1; i < theData.length; i++)
			if (!isDigit(theData.charAt(i)))
				return false
		return true 
	}

	function isDate(s){
		// datum in tag, monat, jahr zerlegen
		var a1=s.split(".");
		var e=true;
		// test auf tag UND monat UND jahr
		if (a1.length!=3)
			e=false
		else{
			if (isPositiveInteger(a1[0]) && isPositiveInteger(a1[1]) && isPositiveInteger(a1[2])){
				var d=a1[0];
				var m=a1[1];
				var y=a1[2];
				if (((e) && (y<1000)||y.length>4))
					e=false
				
				if (e){
					v=new Date(m+"/"+d+"/"+y);
					if (v.getMonth()!=m-1)
						e=false
				}
			}else
				e=false
		}
		return e;
	}

	function checkValidDate(v){
		if (!isDate(v))
			return false
		else
			return true
	}
	



