function typeCheck(fieldName,fieldType) {
  countLetters = 0;
  
  if (fieldType == 'N') {
    cmp = "0123456789 "
  }
  else if (fieldType == 'L') {
    cmp = "0123456789"
  }  
  
  for (var i=0;i<fieldName.length;i++) {
    wer=fieldName.substring(i,i+1)
    if (cmp.indexOf(wer)<0) {
      countLetters++;
    }
  }
  
  if (fieldType == 'N') {
    if (countLetters == 0) {
      return true; // Contains only numbers
    }
    return false; // Contains numbers and letters
  }

  if (fieldType == 'L') {  
    if (fieldName.length > countLetters) {
      return false; // Contains numbers and letters
    }
    return true; // Contains only letters
  }
  
}

function validateForm() {
	
	strErrors = "";
	
	if (document.f1.namn.value == "") {
		strErrors += "- Namn saknas\n";  
	}
	else {
		if (!typeCheck(document.f1.namn.value,'L')) {
			strErrors += "- Namn f\u00E5r bara inneh\u00E5lla bokst\u00E4ver\n";
		}  
	}  

	if (document.f1.adress.value == "") {
		strErrors += "- Adress saknas\n";  
	}
  
	if (document.f1.postnr.value == "") {
		strErrors += "- Postnummer saknas\n";  
	}
	else {
		if (!typeCheck(document.f1.postnr.value,'N')) {
			strErrors += "- Postnr f\u00E5r bara inneh\u00E5lla siffror\n";
		}    
		else {
			if (document.f1.postnr.value.length != 5) {
				strErrors += "- Postnummret m\u00E5ste var 5 nummer l\u00E5ngt\n";
			}
		}
	}
  
	if (document.f1.ort.value == "") {
		strErrors += "- Ort saknas\n";  
	}
	else {
		if (!typeCheck(document.f1.ort.value,'L')) {
			strErrors += "- Ortsnamnet f\u00E5r bara inneh\u00E5lla bokst\u00E4ver\n";
		}  
	}

	if (document.f1.telefonnr.value == "") {
		strErrors += "- Telefonnr saknas\n";  
	}

	if (document.f1.personnr_ar.value == "0") {
		strErrors += "- Personnr. \u00E5r saknas\n";  
	}
	else if (document.f1.personnr_manad.value == "") {
		strErrors += "- Personnr. m\u00E5nad saknas\n";  		
	}
	else if (document.f1.personnr_datum.value == "") {
		strErrors += "- Personnr. dag saknas\n";  		
	}
	
	
	if (document.f1.email.value == "") {
		strErrors += "- E-post saknas\n";  
	}
	else {
		validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  		strEmail = document.f1.email.value

   		// search email text for regular exp matches
    	if (strEmail.search(validRegExp) == -1) 
   		{
      		strErrors += "- Felaktig e-postadress\n";
	    }    	 
	}
	
	if(document.f1.medlemsvillkoren.checked != true) { 	
		strErrors += "- Du har inte godk\u00E4nt medlemsvillkoren\n";  	
	}

	if (strErrors == "") {
		strSent = document.f1.wassent.value;
                if (strSent == 'true') {
                	return false;
                } else {
                	document.f1.wassent.value="true";
                        return true;
                }            
	} 
	else {
		alert(
		"Du har ej fyllt i formul\u00E4ret korrekt.\n" +
		"Var god korrigera f\u00F6ljande fel:\n" +
		"\n" +
		strErrors);
		return false;
	}
}

