// copyright MaCS GmbH, Kathrin Middelhoff
// by Kathrin Middelhoff
// expanded by Thomas Striegel, Computerwelt

// version for macs website by Harald Junkermann 12.07.03
// new : 
// - all error msgs can be set up in html page
// funktionTxt[0] : "Please fill in" (textfield) error msg
// funktionTxt[1] : "Please select" (checkbox, radio & dropdown) error msg
// funktionTxt[2] : "Value has to be numeric" error msg
// funktionTxt[3] : "Please enter a valid e-mail adress" error msg
// funktionTxt[4] : "Input fields do not match. Please check for typos." - error msg
// funktionTxt[5] : Other-and-textfield (double input) - error msg
// - modified input field comparision function - fldComp(i,j,k,l,feldTxt,funktionTxt);


	//txtfld(i,feld,feldTxt,funktionTxt)
	//fldComp(i,j,k,l,feld,feldTxt,funktionTxt); 
	//drpd(i,feld,feldTxt,funktionTxt)
	//chkbx(i,feld,feldTxt,funktionTxt)
	//radio(i,feld,feldTxt,funktionTxt)
	//drpdPlusOther(i,feld,feldTxt,funktionTxt);	
	//emailFilter(i,k,feld,feldTxt,funktionTxt)         Email: Abfrage nach @ und .
	//numericfld(i,k,feld,feldTxt,funktionTxt)          nur Zahlen
	
	

var status;
var msg;

	// 27.03.03 TS nur Zahlen zulassen
	function numericfld(i,k,feld,feldTxt,funktionTxt)	{
	var col;
			if(feld[i].value=="")	{
			status = true;
			feld[i].focus();
			col="red";
			color(k,col);
			msg += feldTxt[i] + ": " + funktionTxt[0] + "\n";
			}
			else 
			var x;
			var numschalter;
			numschalter = 0
			for (x=0;x<feld[i].value.length;x++)	
			{
				if(feld[i].value.charAt(x) < "0" || feld[i].value.charAt(x) > "9")
				{
					numschalter = 1;
				}
			}
			if(numschalter == 1)
			{
				//feld[i].value="";
				status = true;
				feld[i].focus();
				col="red";
				color(k,col);
				msg += feldTxt[i] + ": " + funktionTxt[2] + "\n";			
			}
			else if(numschalter == 0)
			{
				col="black";
				color(k,col);
			}		
		}
		
		

	// text, textarea, password
	function txtfld(i,k,feld,feldTxt,funktionTxt)	{
	var col;
			if(feld[i].value=="")	{
			status = true;
			feld[i].focus();
			col="red";
			color(k,col);
			msg += feldTxt[i] + ": " + funktionTxt[0] + "\n";
			}
			else	{
			col="black";
			color(k,col);
			}
		}
	// vergleich von 2 eingabefeldern
	function fldComp(i,j,k,l,feld,feldTxt,funktionTxt) 	{
			if((feld[i].value!=feld[j].value)&&((feld[i].value!="")&&(feld[j].value!="")))	{
			status = true;
			col="red";
			color(k,col);
			color(l,col);
			msg += feldTxt[i] + ", " + feldTxt[j] + ": " + funktionTxt[4] + "\n";
			}
			else  {
			col="black";
			color(k,col);
			color(l,col);
			}
		}	
	//Email Abfrage nach @ und .	
	function emailFilter(i,k,feld,feldTxt,funktionTxt)	{
	var col;
	var valju = feld[i].value;
	var emailFilter=/^.+@.+\..{2,5}$/;
	if(valju != ""){
	if (!(emailFilter.test(valju))) {
		status = true;
		feld[i].focus();
		col="red";
		color(k,col);
		msg += feldTxt[i] + ": " + funktionTxt[3] + "\n";					
		}
		else {
		col="black";
		color(k,col);
		}}		
	}		
	// checkbox (jeder Checkbox ist ein eigener Name zugeordnet)
	function chkbx(i,k,feld,feldTxt,funktionTxt)	{
        	if (!feld[i].checked) {
			status = true;
			var col="red";
			color(k,col);
			msg += feldTxt[i] + ": " + funktionTxt[1] + "\n";					
			}
			else	{
			col="black";
			color(k,col);
			}
		}
			
	//dropdowns	(select-one, select-multiple)				
	function drpd(i,k,feld,feldTxt,funktionTxt)	{
	var col="black";
	color(k,col);
    for (n=0 ; n<feld[i].length ; n++) {	
		var element;
		element = feld[i];
        if (element[n].value == "" && element[n].selected == true) {				
			status = true;
			col="red";
			color(k,col);
			msg += feldTxt[i] + ": " + funktionTxt[1] + "\n";								
			}
		}
	}
	
//dropdowns	mit zusätzlichem Textfeld : "other ..."			
function drpdPlusOther(i,k,feld,feldTxt,funktionTxt)	{
	var statusDrop = false
	var statusTxt = false
	var col="black";
	var color1 = false;
	var color2 = false;
	color(k,col);
	color(k+1,col);


    for (var n=0 ; n<feld[i].length ; n++) {	

		var element;
		element = feld[i];
		
        if (((element[n].value == "") || (element[n].value == "other")) && (element[n].selected == true) ) {	
			statusDrop = true;	
			if (element[n].value == "")	{	
				color1 = true;				
			}
			else if	(element[n].value == "other")	{	
				color2 = true;					
			}								
		}
	}

	if(feld[i+1].value=="")	{
		statusTxt = true;
	}
	if(statusDrop==true && statusTxt==true)	{
		status = true;
		if	(color1 == true)	{
			col="red";
			color(k,col);	
		}	
		else if		(color2 == true)	{
			col="red";
			k+=1;
			color(k,col);	
		}							
		msg += feldTxt[i+1] + ": " + funktionTxt[0] + "\n";													
	}
	else if(statusDrop==false && statusTxt==false)	{
		status = true;
		msg += feldTxt[i+1] + ": " + funktionTxt[5] + "\n";	
		col="red";
		color(k,col);
		color(k+1,col);
	}
}

	//radio und checkboxes in einer Namensgruppe				
	function radio(i,k,feld,feldTxt,funktionTxt)	{
	var statusRadio = false;
	var col = "";
    		for (n=0 ; n<feld[i].length ; n++) {	
			var element;
			element = feld[i];
        		if (!element[n].checked) {						
				}
				else	{
				statusRadio = true;
				}
			}
			if(statusRadio == false)	{
			status = true;
			col="red";
			color(k,col);
			msg += feldTxt[i] + ": " + funktionTxt[1] + "\n";	
			}
			else	{
			col="black";
			color(k,col);
			}														
	}	
	
	function color(i,rgb)	{
	with (navigator)	{if(((appName=="Netscape")&&(parseInt(appVersion)>4))||((appName=="Microsoft Internet Explorer")&&(parseInt(appVersion)>=4)))	{
	if(document.getElementsByTagName)	{
	var labelColor = document.getElementsByTagName("label")
	labelColor[i].style.color =  rgb;
	}}}}
					
				
	