
function menge(e,i){
  
  var ele = document.getElementById(i);
  //ele.onkeyup = null;
  e = window.event ? event : e;
  unicode = e.charCode ? e.charCode : e.keyCode;
  
  if(unicode == 8 || unicode >= 48 && unicode <= 57 || unicode >= 95 && unicode <= 106){
  
     ele.onkeyup = function(){
              getTotal();
      }
      
      //alert(unicode);
  
  }else{
  
      ele.onkeyup = function(){
              this.value = "";
      }
      //alert(unicode);
      
  }



}


function calc(x,y,sign,ele){

//var result = 1555;
    
    if(window.ActiveXObject){
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }else if(window.XMLHttpRequest){
    
    var xmlhttp = new XMLHttpRequest();
    
    }else{
    
    }
    
    
   function stateChanged(){
    
        if(xmlhttp.readyState == 4){
            
            document.getElementById(ele).innerHTML = xmlhttp.responseText;
        
        }else{
          document.getElementById(ele).innerHTML = "Calculating";
        }
        
        
        
        
    
    }
    
var url = "cmd_files/ajax/price_calc.php?num1="+x+"&num2="+y+"&sign="+sign;
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null); 



}

var price = 0;
var main;
var tax;
var total;

function setPrice(val){
    
    
    var qty = document.getElementById("qty");
    if( qty.value == ""){
        price = parseFloat(val);
      
    }else{
        price = parseFloat(val);
        getTotal();
    }
}

function getTotal(){
    
    
    if(price > 0){
        var qty = document.getElementById("qty");
    
        var net = document.getElementById("net");
        var total = document.getElementById("total");
        var mwst = document.getElementById("mwst");
        
        
        var main = price * parseInt(qty.value); 
        var tax = (main / 119) * 19;
        var netpreis = main - tax;
        
        
        calc(main,tax,"minus","net"); 
        calc(tax,0,"plus","mwst");
        calc(netpreis,tax,"plus","total");
        
    }else{
    
    return;
    }
    
    
    
}

function showSuccess(){

clearTimeout("fadeForm()");
$(".successWrapper").fadeIn(1000);
$(".wrapper").css("cursor","default");

}

function animForm(){
    
    var mainBody = $(".mainbody").height();
    //var formWrapper = $(".formWrapper").height() + 10;
    $(".mainbody").css("height",mainBody+"px");
    $(".formWrapper").animate({"height":"40px"},1100);
    
    setTimeout("fadeForm()",1100);
        //$(".formWrapper").hide();
    
    
}
function fadeForm(){
clearTimeout("animForm()");
//$(".formWrapper").hide();

$(".formWrapper").fadeOut(1000);

setTimeout("showSuccess()",1000);
}

function valForm(){
    
    var error = 0;
    var Name = document.getElementById("first_name");
    var surname = document.getElementById("surname");
    var email = document.getElementById("email");
    var artikel = document.getElementById("article");
    var qty = document.getElementById("qty");
    var comments = document.getElementById("comments");
     
    if(Name.value.length > 0){
        
        var n = Name.value;
        Name.style.backgroundColor = "#fff";
    }else{
     error++;
        
        Name.style.backgroundColor = "#ff0000";
    }
    
    if(surname.value.length > 0){
        
        var sur = surname.value;
        surname.style.backgroundColor = "#fff";
    }else{
     error++;
        surname.style.backgroundColor = "#ff0000";
    }
    
    if(email.value.length >= 6){
        
        var em = email.value;
        email.style.backgroundColor = "#fff";
    }else{
     error++;
        email.style.backgroundColor = "#ff0000";
    }
    
    if(artikel.value != 0){
        
        var art = artikel.value;
        artikel.style.backgroundColor = "#fff";
    }else{
     error++;
        artikel.style.backgroundColor = "#ff0000";
    }
    
    if(qty.value.length > 0){
        
        var qt = qty.value;
        qty.style.backgroundColor = "#fff";
    }else{
     error++;
        qty.style.backgroundColor = "#ff0000";
    }
    
    if(comments.value.length > 0){
        
        var com = comments.value;
        comments.style.backgroundColor = "#fff";
    }else{
        error++;
        comments.style.backgroundColor = "#ff0000";
    }
    
    if(error == 0){
    //$(".wrapper").css("cursor","wait");
    var mainBody = $(".mainbody").height();
    $(".mainbody").css("height",mainBody+"px");
    $(".formWrapper").queue("fx");
    //animForm();
    runIt();
    }
    

   
}

function runIt(){
  
    $(".formWrapper").animate({"height":"40px"},1100);
    $(".formWrapper").fadeOut(1000);
    setTimeout("showSuccess()",2100);

}




