var total_price_dk;
var total_price_eu;

function processCountry(country){
    var idx = country.selectedIndex;
    var val = country.options[idx].value;
    if(val != "DK" && val != "" && val != "none")
    document.getElementById('div_country_spec').style.display="inline";
    else
    document.getElementById('div_country_spec').style.display="none";
    
    updatePrices();
}

function updatePrices(){
    var countryid = document.getElementById('form_country');
    var country = countryid.options[countryid.selectedIndex].value;

    var unitid = document.getElementById('form_currency');
    var unit = unitid.options[unitid.selectedIndex].value;
    
    var shiparray = get_shipping(country);
    
    if(unit == "DKK"){
        var handling = (total_price_dk<500?50:0);
        var itemprice = total_price_dk;
        var shipping = shiparray[1];
    }else{
        var handling = (total_price_eu<70?7:0); 
        var itemprice = total_price_eu;
        var shipping = shiparray[0];   
    }


    
    document.getElementById('itemprice').innerHTML = itemprice;
    document.getElementById('handling').innerHTML = handling;
    
    if(country != "none" && country != ""){
        document.getElementById('selectCountryAbove').style.display="none";
        document.getElementById('shipping').innerHTML = shipping;        
    }else{
        document.getElementById('selectCountryAbove').style.display="inline";
        document.getElementById('shipping').innerHTML = '';
        shipping = 0;
    }
    
    var total = itemprice+shipping+handling;
    document.getElementById('total').innerHTML = total;
    
    document.basketForm.elements['amount'].value = total;
    document.basketForm.elements['shipping'].value = shipping;
    document.basketForm.elements['handling'].value = handling;
    
}

function updateUnit(){
    var unitid = document.getElementById('form_currency');
    var unit = unitid.options[unitid.selectedIndex].value;    
    var newunit = '&euro;';
    if(unit == "DKK") newunit = "DKK";
    
    var allHTMLTags=document.getElementsByTagName("span");
    for (i=0; i<allHTMLTags.length; i++) {
        if (allHTMLTags[i].className=='unit') {
            allHTMLTags[i].innerHTML = newunit
        }
    }
    
    updatePrices();
}

function get_shipping(landcode){
    if(landcode == "" || landcode == "none") return Array(0,0);
    else if(landcode == "DK") return Array(10,70);
    else if(landcode == "DE") return Array(25,175);
    else if(landcode == "EU") return Array(25,175);
    else return Array(50,350);
}

function validate_basket_form(){

  var post_name                 = document.getElementById('basketFormID').name.value;
  var address                   = document.getElementById('basketFormID').address.value;
  var country_spec              = document.getElementById('basketFormID').country_spec.value;
  var email                     = document.getElementById('basketFormID').email.value;
  var accept                    = document.getElementById('form_accept').checked;
  
  var countryid = document.getElementById('form_country');
  var country = countryid.options[countryid.selectedIndex].value;

  var regexp = /^[a-zA-Z]?[\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9]?[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/gi;  
    
  if(post_name.length <1 ){
    window.alert("Please type your name.");
    document.getElementById('basketFormID').name.focus();
  }else if(address.length <1 ){
    window.alert("Please type your address.");
    document.getElementById('basketFormID').address.focus();
  }else if(country == "none"){
    window.alert("Please choose your country from the list.");
  }else if(country != "DK" && country_spec.length<1){
    window.alert("Please specify your country.");
    document.getElementById('basketFormID').country_spec.focus();
  }else if(!email.match(regexp)){
    window.alert("Please type in a valid email.");
    document.getElementById('basketFormID').email.focus();        
  }else if(!accept){ 
      alert('Please read and accept the terms and conditions of sale.');
  }else{
    updatePrices();
    document.basketForm.submit();
    //alert('OK');
  }

    
}



  

    
  

