// input validation
function verifInput(name){
	// RegEx: if entry contain [A-Za-z0-9_], all tabulation-space-..., (\b\d are not a obligation). Contain all of this at least for one caracter. And if entry does not contain >, < and &
	var vfname = /^[\w\s\b\d.]{1,}[^<>&]+$/
	
	if(name=="")  {	// if entry is empty
		alert("Thanks to insert your name!");
		document.form.name.focus();
		return false;
	}

	if(vfname.test(name)==false){	//if entry is okay with the RegEx
		alert('For security reasons you cannot use the following letters in your name field: <, >, &.');
		document.form.name.focus();
		return false;
  	}
}

function verifEmail(email){
	// RegEx: if entry contain [A-Za-z0-9_] AND @ AND at least 2 caracter of [a-z0-9.-] AND between 2 and 3 caracter of [a-z]
	var vfmail = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/

	if(email=="") {	// if entry is empty
   		alert("Thanks to insert the email of your friend!");
   		document.form.email.focus();
   		return false;
  	}

  	if(vfmail.test(email)==false){	//if entry is okay with the RegEx
		alert('Tanks to insert a valid email adress !');
		document.form.email.focus();
		return false;
  	}
}


function verifTextArea(comments){
	// RegEx: if entry contain [A-Za-z0-9_], all tabulation-space-..., (\b\d are not a obligation). And if entry does not contain >, < and &
	var vfcomments = /^[\w\s\b\d.][^<>&]+$/

	if(comments=="") {	// if entry is empty
 	  alert("Thanks to insert some comments");
 	  document.form.comments.focus();
 	  return false;
 	}  
	  
  	if(vfcomments.test(comments)==false){	//if entry is okay with the RegEx
		alert('For security reasons you cannot use the following letters in your comments field: <, >, &.');
		document.form.comments.focus();
		return false;
  	}
}


function verifNewsletter() {
	verifEmail(document.formNewsletter.emailNewsletter.value);	//email validation
}
	

function verif(){
	verifInput(document.form.name.value);						// input validation
	verifEmail(document.form.email.value);						//email validation
 	verifTextArea(document.form.comments.value);				// textarea validation
}

function toggleLayer( whichLayer ){
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
	 elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
	 elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
	 elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here 
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  vis.display = (vis.display==''||vis.display=='block')?'none':'block';}
	

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- Bitte geben Sie eine gültige Email-Adresse ein!.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' wird benötigt.\n'; }
  } if (errors) alert('Folgender Fehler trat auf:\n'+errors);
  document.MM_returnValue = (errors == '');
}


