// Javascript validation functions
// http://www.designplace.org/


//function to check empty fields

function isEmpty(strfield1, strfield2, strfield3, strfield4) {


//change "field1, field2 and field3" to your field names
strfield1 = document.forms["formname"].name.value 
strfield2 = document.forms["formname"].gemeinde.value
strfield3 = document.forms["formname"].telefon.value
strfield4 = document.forms["formname"].F_SUBJECT.value

  //name field
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
    {
    alert("Der Name ist erforderlich.\nBitte korrigieren Sie Ihre Eingabe!")
    return false;
    }

  //url field 
    if (strfield2 == "" || strfield2 == null || strfield2.charAt(0) == ' ')
    {
    alert("Die Gemeinde ist erforderlich.\nBitte korrigieren Sie Ihre Eingabe!")
    return false;
    }

  //title field 
    if (strfield3 == "" || strfield3 == null || strfield3.charAt(0) == ' ')
    {
    alert("Die Telefonnummer ist erforderlich.\nBitte korrigieren Sie Ihre Eingabe!")
    return false;
    }

  //title field 
    if (strfield4 == "" || strfield4 == null || strfield4.charAt(0) == ' ')
    {
    alert("Der Betreff ist erforderlich.\nBitte korrigieren Sie Ihre Eingabe!")
    return false;
    }
    return true;
}


//function to check valid email address
function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms["formname"].email.value;

   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) 
   {
      alert('Eine gültige Mailadresse ist erforderlich.\nBitte korrigieren Sie Ihre Eingabe!');
      return false;
    } 
    return true; 
}


//function that performs all functions, defined in the onsubmit event handler

function check(form){
if (isEmpty(form.name)){
  if (isEmpty(form.gemeinde)){
    if (isEmpty(form.telefon)){
    if (isEmpty(form.F_SUBJECT)){
		if (isValidEmail(form.email)){
		  return true;
		}
	  }
	  }
  }
}
return false;
}
function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine)
{
	var strTemp = "";
	var strLineCounter = 0;
	var strCharCounter = 0;

	for (var i = 0; i < theField.value.length; i++)
	{
		var strChar = theField.value.substring(i, i + 1);

		if (strChar == '\n')
		{
			strTemp += strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		}
		else if (strCharCounter == maxPerLine)
		{
			strTemp += '\n' + strChar;
			strCharCounter = 1;
			strLineCounter += 1;
		}
		else
		{
			strTemp += strChar;
			strCharCounter ++;
		}
	}

	theCharCounter.value = maxChars - strTemp.length;
	theLineCounter.value = maxLines - strLineCounter;
}

