af = {};

af.set_child_text = function(id, text) {
    t = document.getElementById(id);
    t.removeChild(t.firstChild);
    t.appendChild(document.createTextNode(text));
}

af.update_basket = function() {
    total  = 0;
    for (key = 0; ; key++) {
        price  = document.getElementById("price"+key);
        if (price) {
            price  = price.firstChild.data;
            count  = document.getElementById("count"+key);
            amount = parseInt(price) * parseInt(count.value);
            //          document.getElementById("amount"+key).setAttribute("value", amount > 0 ? amount + ",00" : "");
            af.set_child_text("amount"+key, amount > 0 ? amount + ",00" : "");
            if (amount.value != "") {
                total += amount;
            }
        } else {
            break;
        }
    }

//    document.getElementById("total"    ).setAttribute("value", total > 0 ?  total + ",00" : "");

    af.set_child_text("total" ,    total > 0 ?  total + ",00" : "");
    af.set_child_text("surcharge", total > 0 ? "25.00"        : "");
    af.set_child_text("shipping",  total > 0 ? "Tillkommer"   : "");
}

af.check_and_send = function(inparam) {  
    message = "";
    if (document.form1.elements["fname" ].value == "") { message += "Fyll i förnamn\n";      }
    if (document.form1.elements["lname" ].value == "") { message += "Fyll i efternamn\n";    }
    if (document.form1.elements["adress"].value == "") { message += "Fyll i adress\n";       }
    if (document.form1.elements["postnr"].value == "") { message += "Fyll i postnummer\n";   }
    if (document.form1.elements["ort"   ].value == "") { message += "Fyll i ort\n";          }
    if (document.form1.elements["email" ].value == "") { message += "Fyll i epost-adress\n"; }

    if (message != "") { 
        alert(message);
    } else {
        document.form1.submit();
    }
}

af.valid = function(f) {
    if (!/^\d*$/.test(f.value)) {
        alert("Fyll i siffror!");
        f.value = f.value.replace(/[^\d]/g,"");
    }
} 

function printWindow() {
    if (parseInt(navigator.appVersion) >= 4) window.print()
}

