//
//	Modul     : Standardvalidation mit Email und Passwort
//	Version   : 1.0
//	Datei     : validate.js
//	Autor     : René Jossen
//	Erstellt  : 03.11.2006
//	
//	Aenderung : 
//	WER -------- WANN ------ WAS --------------------------------------------------------
//
//
//

falseColor = "#FFAAAA";
trueColor = "#fafbf5";
var usrField = "";
var usrForm = "";

function validate(theForm){
	var fromDayFields = new Array();
	var fromMonthFields = new Array();
	var fromYearFields = new Array();
	var toDayFields = new Array();
	var toMonthFields = new Array();
	var toYearFields = new Array();
	var iDropDateFrom = 0;
	var iDropDateTo = 0;
	
	usrField = "";
	usrForm = "";
	var f = theForm;
	returnor = true;
	prevPass = "";
	for(i = 0;i<f.length;i++){
		if(f[i].getAttribute("needed") != null){
			if(f[i].value == ""){
				f[i].style.backgroundColor = falseColor;
				if(returnor){
					f[i].focus();
				}
				returnor = false;				
				
			}else if(f[i].getAttribute("needed") == "password" && prevPass == ""){
				prevPass = f[i].value;
				f[i].style.backgroundColor = trueColor;
			}else if(f[i].getAttribute("needed") == "password" && prevPass != ""){
				if(prevPass == f[i].value){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "email"){
				if(ValidateEmail(f[i].value)){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "select"){
				if(f[i].selectedIndex != 0){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "telephone"){
				if(f[i].value.search("00") == 0 || f[i].value.search(/\+/) == 0){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "username"){
				if(ValidateEmail(f[i].value)){
					usrField = f[i];
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "date"){
				if(ValidateDate(f[i].value)){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else if(f[i].getAttribute("needed") == "number"){
				if(f[i].value*1 == f[i].value){
					f[i].style.backgroundColor = trueColor;
				}else{
					f[i].style.backgroundColor = falseColor;
					if(returnor){
						f[i].focus();
					}
					returnor = false;
				}
			}else{
				f[i].style.backgroundColor = trueColor;
			}
		}
	}
	return returnor;
}

	