
function handle(item){                    
    if(item.id=='login')        handleLogin();
    if(item.id=='password')     handlePassword();
    if(item.id=='name')         handleName();
    if(item.id=='firstname')    handleFirstname();
    if(item.id=='lastname')     handleLastname(); 
    if(item.id=='address')      handleAddress();
    if(item.id=='zip')          handleZip();       
    if(item.id=='city')         handleCity(); 
    if(item.id=='phone')        handlePhone();
    if(item.id=='email')        handleEmail();
}           

function handleLogin() { 
    if(!handleField('login', 'Benutzername ist ein Pflichtfeld.')) { return false; }
    else {
        return $.post("config.php", { action: "check_login", login:$('#login').val() },   
            function(data){ 
                result = data.split(':');
                if(result[0]=='false'){
                    infoMsg('login',result[1]);  
                    return false;
                }
                if(result[0] == 'true') {
                    return true;
                }
            });
    }                       
}
function handlePassword()   { return handleField('password', 'Passwort ist ein Pflichtfeld.'); }
function handleName()       { return handleField('name', 'Firmenname ist ein Pflichtfeld.'); }
function handleFirstname()  { return handleField('firstname', 'Vorname ist ein Pflichtfeld.'); }
function handleLastname()   { return handleField('lastname', 'Nachname ist ein Pflichtfeld.'); }
function handleAddress()    { return handleField('address', 'Stra&szlig;e ist ein Pflichtfeld.'); }
function handleZip()        { return handleField('zip', 'Postleitzahl ist ein Pflichtfeld.'); }
function handleCity()       { return handleField('city', 'Ort ist ein Pflichtfeld.'); }
function handlePhone()      { return handleField('phone', 'Telefon ist ein Pflichtfeld.');} 
function handleEmail()      { return handleField('email', 'Email ist ein Pflichtfeld.'); }                                                                                              
function handleAgb()        { 
     if($('#agb').is(':checked')==false) {
        $('#info_agb').html('Einstimmung mit die AGB\'s ist Pflicht.');
        $('#info_agb').show('slow');
        return false;
     } else {
        $('#info_agb').hide('slow');  
        $('#info_agb').empty(); 
        return true;
     }
}
  
function infoMsg(name,msg){
    $('#info_'+name).html(msg);
    $('#info_'+name).show('slow');
    $('#'+name).focus(); 
}

function handleField(name, msg){
    if($('#'+name).val()==''){
        $('#'+name).addClass('req');
        infoMsg(name, msg);
        return false;
    }
    else {
        $('#'+name).removeClass('req');
        $('#info_'+name).hide('slow');  
        $('#info_'+name).empty(); 
        return true;
    }
}
