function calculateOrder(selindex,prodInd)
{
    var typeP, quantity, price, stock, divs, subtot, fee, um;
	quantity=Number(document.mail.quantity[prodInd].value);
	um=document.mail.um[prodInd].value;
	
	if (quantity<=50){
	    
		price=Number(document.mail.price[prodInd].value);
	}
	else{
	  
		price=Number(document.mail.price2[prodInd].value);  
	}
    stock=Number(document.mail.stock[prodInd].value);
	
	
	if (stock<quantity){
		alert("The ordered product is currently not available in stock.");
		eval('document.mail.codeproducts'+selindex+'.selectedIndex=""');
		eval('document.mail.quantityPr'+selindex+'.value=""');
		setElement("um",selindex, "");
		setElement("deltime",selindex, "");	
		setElement("unitprice",selindex, "");	
		setElement("subtotal",selindex, "");
		setElement("feequantity","", "0");
		setElement("handlingfee","","&#36; 0.00");
		setElement("handlingfee1","","&#36; 0.00");
			
		recalculateTotal(); 
	
		
	}
    else{ 	
   		eval('document.mail.quantityPr'+selindex+'.value=quantity');
        
		if (prodInd!=0)
		{ 
		    
			subtot=quantity*price;
			setElement("um",selindex, document.mail.um[prodInd].value);	
      		setElement("deltime",selindex, document.mail.deliverytime[prodInd].value);	
			setElement("unitprice",selindex,"&#36; "+price.toFixed(2));
			setElement("subtotal",selindex,"&#36; "+subtot.toFixed(2));
			
			
		}
		else
		{
		    eval('document.mail.quantityPr'+selindex+'.value=""');
		 	setElement("um",selindex, "");
			setElement("deltime",selindex, "");	
			setElement("unitprice",selindex, "");	
			setElement("subtotal",selindex, "");
			
			setElement("feequantity","", "0");
			setElement("handlingfee","","&#36; 0.00");
			setElement("handlingfee1","","&#36; 0.00");
		 	
		}  
    	
		recalculateTotal(); 
	}	
}

function setElement(strName,intIndex, strValue)
{
	eval('document.getElementById("'+strName + intIndex+'").innerHTML="'+strValue+'"');
}



function recalculateAmount(index)
{
  var quantity, minqty, stock, prodInd, uprice, subtot, code; 
  prodInd=eval('document.mail.codeproducts'+index+'.selectedIndex');
  
  code=eval('document.mail.codeproducts'+index+'.value');
  quantity=eval('document.mail.quantityPr'+index+'.value');
  minqty=parseFloat(document.mail.quantity[prodInd].value);
  stock=parseFloat(document.mail.stock[prodInd].value);
  if (isNaN(parseFloat(quantity)))
	{
	 	quantity=minqty;
     	eval('document.mail.quantityPr'+index+'.value=quantity');
     	alert("The entered quantity is not a number. Please enter a number >1.");
		 //eval('document.mail.quantityPr'+index+'.focus()');
	}
	else if (parseFloat(quantity)<minqty)
	{
	   	quantity=document.mail.quantity[prodInd].value;
        eval('document.mail.quantityPr'+index+'.value=quantity');
        alert("The entered quantity is less than the required minimum order quantity for " + code +".\n\t\t\t\t\tPlease enter a quantity >1.");
   	}
   	else
   	{
	  if (parseFloat(quantity)>stock){
	    quantity=document.mail.quantity[prodInd].value;
        eval('document.mail.quantityPr'+index+'.value=quantity');
        alert("The quantity entered is bigger than the available stock.");
	  } 
	}
	
  
  if (parseFloat(quantity)<=50)	{   
  	uprice=Number(document.mail.price[prodInd].value);
  }
  else{
      uprice=Number(document.mail.price2[prodInd].value); 
  }
  quantity=quantity.replace(",",".");
  
  subtot=parseFloat(quantity)*uprice;
  setElement("subtotal",index,"&#36; "+subtot.toFixed(2));
  setElement("unitprice",index,"&#36; "+uprice.toFixed(2));
  //document.getElementsByName("subtotal")[index-1].innerHTML=subtot+"&euro;"; 
  recalculateTotal();
}

function recalculateTotal()
{
  var i, selIndex;
  var typeP, quantity, prodInd, uprice, subtot, vat, total, fee, nrFee,handlingFee; 
  subtot = 0;
  fee=40;
  nrFee=0;
  handlingFee=0;
  for (i=1;i<=7;i++)
  {
	
	selIndex = eval('document.mail.codeproducts'+i+'.selectedIndex');
	if (selIndex != 0)
	{
	    
		typeP=document.mail.typeP[selIndex].value;
		if ((typeP==1) || (typeP==2) || (typeP==3)){
		   handlingFee+=fee;
		   nrFee+=1;
		}
		setElement("feequantity","",+nrFee);
		setElement("handlingfee","","&#36; "+fee.toFixed(2));
		setElement("handlingfee1","","&#36; "+handlingFee.toFixed(2));
		
		quantity=eval('document.mail.quantityPr'+i+'.value');
		
		if ((typeP==4) || (typeP==7)){
		  q=quantity.toString();
		  if ((q.indexOf('.')!=-1) || (q.indexOf(',')!=-1)){
		    alert("The entered quantity is not valid.\nPlease enter a integral number >1.");
		    q=q.replace(",","."); 
		    quantity=Math.floor(q);
		  }
		}
		else{
			quantity=quantity.replace(",","."); 
		}
		if (parseFloat(quantity)<=50){
			uprice=document.mail.price[selIndex].value;	
		}
		else{
		   uprice=document.mail.price2[selIndex].value;	 
		}	
		subtot += parseFloat(quantity)*uprice;
		eval('document.mail.quantityPr'+i+'.value='+parseFloat(quantity));
	}

  }
  
  subtot+=handlingFee;
  
  setElement("Allsubtotal","","&#36; "+subtot.toFixed(2));	
  	
}
