<!--
////////////////////////////////////////////////////////////////////
// copyright: IT assistance GmbH - info@itassistance.ch
// author: IT assistance GmbH - info@itassistance.ch
// date: 2001-12-20 22:01
// change: 15.04.2002 12:30
////////////////////////////////////////////////////////////////////

// requires var bw=new lib_bwcheck() called here or in an other js 

//////////////////////////////////////////////////////////////////////////////////// 
// form field check routine
var speed=70 // speed of typewriter_message
var form = new Object()
//var oWin=new Array // creating object comming from windows.js 

// Expects as first argument, the name of the form and as second the name of 
// the required fields separated by a pipe "|". 
// Caution, forms in a <layer> tag are not implemented.
function checkform(formname,required) {
	requiredlist = required.split("|");
	var formfield = new Object()
	var stop = 0
	var submit = 1
	var first_password = 0
	var errorlist = ""
	form = eval("document.forms[formname]")
	while(stop < requiredlist.length) {
		var errormsg = "";
		var popup = "";
		formfield = eval("document.forms[formname]."+requiredlist[stop])

		if (!formfield.type && formfield[0] ) { 
	        	var count = 0
        		popup = "please select option"
        		while (count < formfield.length) {
        			if (formfield[count].value || formfield[count].checked) { 
        				popup = ""
				}
				count++
        		}
			formfield = formfield[0]
		}
        	else if (formfield.type.search( /radio|checkbox/ ) != -1 ) {
        		if (!formfield.checked) { 
        			popup = "please select option"
			}
		}
		else if ( formfield.type.search( /password/ ) != -1 ) { 
			if ( formfield.value.length < 5 ) { 
				pupup = formfield.value+" is too short - min. 6 signs"
			}
			if ( first_password != 0 && first_password != formfield.value ) { 
				pupup = "Password: '"+first_password+"' not identical with '"+formfield.value+"'"
			}
			else { first_password = formfield.value; }
		}
        	else if ( formfield.type.search( /select/ ) != -1 ) { 
        		var count = 0
        		popup = "please select option"
        		while (count < formfield.length) {
        			if (formfield.options[count].value && formfield.options[count].selected) { 
        				popup = ""
				}
				count++
        		}
        	}
		else if ( formfield.value == 0 || formfield.value == "" || formfield.value == "http://" ) { 
			field_value_keep = formfield.value
			if (formfield.type == "password") { 
				popup = "please fill out"
			}  
			else { 
				errormsg = "please fill out"
			}
		}
        	else if ( requiredlist[stop].search( /email/ ) != -1 ) { 
        		if ( formfield.value.search( /\\|\(|\)|\*|\[|\]|\?|(\@.*\@)|(\.\.)|(\@\.)|(\.\@)|(<)|(^\.)/ ) !=  -1 || formfield.value.search( /^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/ ) == -1 ) { 
        			errormsg = "wrong email adress"
			}
		}
		else if ( requiredlist[stop].search( /password|username|id$/ ) != -1 ) { 
			if ( formfield.value.search( /^[a-zA-Z0-9\-\_]+$/ ) == -1 ) { 
				if (requiredlist[stop].search( /password/ ) != -1) { 
					pupup = "Do not use no special signs!"
				}
				else { 
					errormsg = "Do not use no special signs!"
				}
			}
		}
		if (errormsg||popup) {
			if (errormsg) typewriter_message(requiredlist[stop],errormsg,formfield.value) 
			if (popup) errormsg = popup
			errorlist += "<b>"+requiredlist[stop]+"</b><br>"+errormsg+"<br><br>"
			if (!bw.ns4) { formfield.className = "errorinput"}
			if (formfield.type != "hidden" ) formfield.focus()
			submit = 0
		}
		else {
			if (!bw.ns4) { formfield.style.className = "singleinput" }
		}		
		stop++;  
	}

	if (submit) document.forms[formname].submit()
	else if(oWin[0]) {
		oWin[0].oHead.writeIt("Farbige Felder korrigieren")
		oWin[0].oText.writeIt(errorlist)
		if (!bw.ns4) popupWindow(0)
	}
}

function typewriter_message(required,thiserrormsg,thisvaluekeep,thisindex) {
	if (!thisindex) thisindex = 0;
	var formfield = eval("form."+required)
	if  ( thisindex < thiserrormsg.length) {
		thisindex++
		formfield.value = thiserrormsg.substr(0,thisindex)
		window.setTimeout("typewriter_message('"+required+"','"+thiserrormsg+"','"+thisvaluekeep+"',"+thisindex+")",speed);
	}
	else { 
		formfield.value = thisvaluekeep
	}
}

function formaction(formname,statusname,status,required) {
	formfield = eval("document.forms[formname]."+statusname)
	formfield.value = status
	if (required) { checkform(formname,required) }
	else { document.forms[formname].submit() }
}

// -->