// JavaScript Document

function onbeforesubmit()
{
return true;
}
//-->

var error;
var form_lanuage = 'de';
function is_0_valid(){
  count = 0;
  if(document.ProfileForm.optin){
    if(document.ProfileForm.optin.checked){
      if(document.getElementsByName('interest[]')){
        if(document.getElementsByName('interest[]').length > 0 ){
          Interest = document.getElementsByName('interest[]');
          for(i = 0 ; i < Interest.length;i++){
           if(Interest[i].checked)
         ++count;
 }
          if(count == 0){
            error  += "Interessen:";
            return false;
  }
        }
      }
    }
  }
 return  true;
}
function is_3_valid(input)
{
            if(input == "")
            {
                        error += "E-Mail: Eingabe fehlt!\n";
                        return false;
            }
 
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
 
 
var matchArray=input.match(emailPat)
if (matchArray==null) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // check @ and .
return false
}
var user=matchArray[1]
var domain=matchArray[2]
 
if (user.match(userPat)==null) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // username doesn't seem to be valid
return false
}
 
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
  for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // Destination IP address is invalid
return false
    }
    }
    return true
}
 
var domainArray=domain.match(domainPat)
if (domainArray==null) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // The domain name doesn't seem to be valid
   return false
}
 
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // The address must end in a three-letter domain, or two letter country
return false
}
 
if (len<2) {
error += "E-Mail: Bitte geben Sie eine g\u00fcltige E-Mail Adresse an!\n"; // This address is missing a hostname
return false
}
 
 
            return true;
}
 
function CheckInputs()
{
            var check_ok = true;
            error = "Fehler in der Eingabe!\n";
 
            check_ok = (is_0_valid('null') && check_ok);
            check_ok = (is_3_valid(document.ProfileForm.inp_3.value) && check_ok);
            if(check_ok == false)
                        alert(error);
            return check_ok;
}


function SubmitIt(){
                if(CheckInputs() == true){
                                if(window.onbeforesubmit)
                                                onbeforesubmit();
                                document.ProfileForm.submit();
                }
}
 
function MailIt(){
                if(CheckInputs()){
                                if((document.ProfileForm.subject.value=='') || (document.ProfileForm.msg.value==''))
                                                alert('Bitte f\u00fcr Sie die Nachrichtenfelder aus!');
                                else
                                                document.ProfileForm.submit();
    }
}
 
function FieldWithName(frm, fieldname, numofield)
{
    if(!numofield)
        numofield = 0;
    field_count = 0;
    for(i = 0; i < frm.elements.length; ++i)
    {
        if(frm.elements[i].name == fieldname)
        {
            if(field_count == numofield)
                return frm.elements[i];
            else
                field_count++;
        }
    }
}
function NumChecked(frm, fieldname)
{
                        var count = 0;
                        for(i = 0; i < frm.elements.length; ++i)
                        {
                                               if(frm.elements[i].name == fieldname && frm.elements[i].checked == true)                      
                                                                       ++count;
                        }
                        return count;
}