/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function prepareOrderForm(){
    $("#cd_count").spinner({
        max: 20,
        min: 1
    });
    calcCosts();
    
    $('#cd_count').bind('spin', function(event, ui) {
        calcCosts();
    });
 
}

function calcCosts(){
    var cd_count = $('#cd_count').val();
    $('#anzahl').val(cd_count);
    var cd_amount = cd_count*cdpreis;
    var shipping = $('#shipping').text();
    var all_costs = parseInt(cd_amount)+parseFloat(shipping);
    $('#cd_amount').text(cd_amount.toFixed(2))
    $('#all_costs').text(all_costs.toFixed(2));
}

function decorateDifferentAddress(){
    $("#differentAddress").click(function(){
        if($('#differentAddress').is(':checked')){
            $('#laddress').show("slow");
        } else{
            $('#laddress').hide("slow");
        }

    });
}

function checkForm(){
    $('#vorname').keypress();
    $('#name').keypress();
    $('#strasse').keypress();
    $('#plz').keypress();
    $('#ort').keypress();
    $('#email').keypress();
}

function decorateForm(){
    var vorname = $('#vorname');
    vorname.keypress(function(){
        validate(vorname, 2, 'string');
    });

    var name = $('#name');
    name.keypress(function(){
        validate(name, 2, 'string');
    });

    var strasse = $('#strasse');
    strasse.keypress(function(){
        validate(strasse, 4, 'string');
    });

    var plz = $('#plz');
    plz.keypress(function(){
        validate(plz, 4, 'string');
    });
    
    var ort = $('#ort');
    ort.keypress(function(){
        validate(ort, 3, 'integer');
    });
    var email = $('#email');
    email.keypress(function(){
        validate(email, 5, 'email');
    });
}

function validate(item, len, type){
    if(parseInt(item.val().length) < parseInt(len)){
        item.removeClass();
        item.addClass('error');
        return false;
    } else{
        item.removeClass();
        item.addClass('valid');
        return true;
    }
//alert(obj.name+":"+len+type);
}

