/* subnavigation ein-/ausblenden */
function sub(id,action){
    document.getElementById(id).style.display = action;			
}

/* emailadresse prŸfen */
function check(s) {
    var a = false;
    var res = false;
    if(typeof(RegExp) == 'function'){
    	var b = new RegExp('abc');
    	if(b.test('abc') == true){a = true;}
    }
    
    if(a == true){
    	reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                       '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                       '(\\.)([a-zA-Z]{2,4})$');
    	res = (reg.test(s));
    }
    else{
    	res = (s.search('@') >= 1 &&
        s.lastIndexOf('.') > s.search('@') &&
        s.lastIndexOf('.') >= s.length-5)
    }
    return(res);
}

/* trim funktion */
function trim(str, chars){
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars){
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars){
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/* kontaktformular prŸfen und senden */
function send(id){
    var form = document.getElementById(id);
    
    error = 1;
    
    if(trim(form.nachricht.value) && trim(form.name.value) && trim(form.email.value) && check(form.email.value)) error = 0;
    
    if(error == 0) {
    	form.submit();
    } else {
    	alert('Bitte füllen Sie alle Formularfelder aus und prüfen Ihre E-Mailadresse.');
    	return false;
    }
}