// functions for testing (write your own!!)

// ------- List of Functions ----------
// * R_Text() 		: Required Text
// * O_Text() 		: Optional Text
// * R_Email() 		: Required Email
// * R_Checkbox() 	: Required checked
// * R_Option()	: Required to choose
// * R_Name()		: Required Name without Special Chars
// * R_Telefone()	: Required Telefone without Special Chars
// * R_Radio()		: Required Radio1/Radio2


// DUMMY-Funktion for new test-functions
// not Default and more than x-letters
function R_Text( msg,len ){ tF=testField;
	return ( 	tF.value.length > len  ) ? true: msg ;
}

function R_Checkbox( msg,len ){ tF=testField;
    return (   tF.checked > len  ) ? true: msg ;
}

function R_Option( msg,len ){ tF=testField;
        return (        tF.selectedIndex > len  ) ? true: msg ;
}

// not Default and a valid Email containing @ and .
function R_Email( msg ){ tF=testField;
	return ( 	tF.value.length>5
			&& 	tF.value.indexOf('@')>0
			&& 	tF.value.indexOf('.')>0 ) ? true: msg;

}

// not Default and a valid Email containing @ and .
function O_Email( msg ){ tF=testField;
	if (tF.value==tF.defaultValue ) return true;
	return ( 	tF.value.length>5
			&& 	tF.value.indexOf('@')>0
			&& 	tF.value.indexOf('.')>0 ) ? true: msg;
}

//loop through all formfield and validate them.

//make globals;
var errors		='';
var testField	='';

function checkForm( f,prefix ){

	//clear values
	var errors		='';
	var firstFocus  ='';

		for ( i=0; i<f.length ; i++ ){
			// prepare some vars from Form-Data
			fe		=f.elements[i];
			f_cmd 	=fe.name.substring(0,9);
			f_aim 	=fe.name.substring(9);
			f_test  =fe.value;

			// if Command is Validate then doValidate and add Error to stack
			if ( f_cmd == 'validate_' ){
				testField=f.elements[ f_aim ]; /* global testValue */

				if ( (msg=eval( f_test )) !=true  ) {
					errors+=msg +'\n';
					// put focus on first and only first wrong field
					if (firstFocus=='' ) { firstFocus='set'; testField.focus(); }
				}
			}
		}

	if ( errors!='') {
		alert( prefix + errors );
		return false;
	}

	return true;
}
