<!--------------------------------------------------------------------------------->

<!-- Title         : Singaradja                                                  -->

<!-- Description   : Berekeningen invullijst catering                            -->

<!-- Date created  : 06-08-2004                                                  -->

<!-- Version       : 2.0                                                         -->

<!-- Copyright     : Pixelvreters 2004                                           -->

<!-- E-mail        : mail@pixelvreters.nl                                        -->

<!--------------------------------------------------------------------------------->



// ### VARIABELEN ### //



var btw = 1.06;

var B1P = 25;

var B2P = 25;

var B3P = 25;





// ### BUFFET ### //



function sel_buffet(whichbox)



{

	with (whichbox.form)

	{

		if (buffet.value == 0)

            {     

			buffet.value = eval(buffet.value) + 1;

	            hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value) * btw;

	      }

		else

			if (buffet.value == 1)

            	{      

				if (whichbox.checked == true)

				{

            			whichbox.checked = false;

					//hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value) * btw;

					return (false);	

	     			}

	            	else

				{

			      	buffet.value = eval(buffet.value) - 1;

		             	hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value) * btw;

 	            	}

                	}

	           total.value=formatCurrency(hiddentotal.value);

        }



}



// ###  BORRELBUFFET1 ### //



function sel_borrelbuffet1()

{

	with(document.myform)

        {

           if (B2.checked == true | B3.checked == true ) 

	     {

              	B1.checked = false;

              	return (false);

	     }

           else

           {

	           checkChoice(B1);

	      	if (B1.checked == false)

                  {

                  	if (B2.checked == false)

	                  {

      		         	if (B3.checked == false)

	            	      {

	                  	     if (S1.checked == true)

	                       	     {

			           			S1.checked = false;

			                  	checkChoice(S1);

		                        	return (false);

						}

		                 }

	                  }

                 }

              // -- Werk aantal personen bij. -- //

              if (B1.checked == true) 

              {

                 quantity.value = B1P;

              }

              else

              {

                 quantity.value = 0;

              }

           }

        }

}





// ###  BORRELBUFFET2 ### //

function sel_borrelbuffet2()

{

	with(document.myform)

      {

	      if (B1.checked == true | B3.checked == true ) 

		{

	            B2.checked = false;

		      return (false);

		}

	      else

	      {

	            checkChoice(B2);

		      if (B2.checked == false)

	            {

	                 if (B1.checked == false)

	                 {

	                 		if (B3.checked == false)

	                 		{

	                    		if (S1.checked == true)

	                    		{

				       		S1.checked = false;

			             		checkChoice(S1);

		                   		return (false);

						}

		                 }

	              	}

	            } 

	            // -- Werk aantal personen bij. -- //

	            if (B2.checked == true) 

		      {

	                 quantity.value = B2P;

	            }

	            else

	            {

	                 quantity.value = 0;

	            }

	    }

     }

}



// ###  BORRELBUFFET3 ### //

function sel_borrelbuffet3()

{

	with(document.myform)

      {

	      if (B1.checked == true | B2.checked == true ) 

		{

	           B3.checked = false;

	           return (false);

		}

	      else

	      {

	            checkChoice(B3);

		      if (B3.checked == false)

	            {

	                 if (B1.checked == false)

	                 {

	                 		if (B2.checked == false)

	                 		{

	                    		if (S1.checked == true)

	                    		{

				       		S1.checked = false;

			             		checkChoice(S1);

		                   		return (false);

						}

		                 }

	              	}

	            } 

	            // -- Werk aantal personen bij. -- //

	            if (B3.checked == true) 

		      {

	                 quantity.value = B3P;

	            }

	            else

	            {

	                 quantity.value = 0;

	            }

	    }

     }

}





// ###  COMBINATIE #### //

function sel_soort_comb1(whichbox)

{

	with (whichbox.form)

      {

		if (whichbox.checked == false)

		{

			comb1.value = eval(comb1.value) - 1;

		      hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value) * btw;

		}

		else

		{

		      comb1.value = eval(comb1.value) + 1;

		      hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value) * btw;

		}

           // ### Controleer of de combinatie is geselecteerd. ### //

           if (comb1.value < 2)

           {

              if (P11.checked == true)

		  {

	       	if (P07.checked == true)

			{  

				// (P07+P08)-P11

			 	hiddentotal.value = eval(hiddentotal.value) + (1.90) * btw;

		 	}

		 	else

		 	{	// (P08+P09)-P11

   				hiddentotal.value = eval(hiddentotal.value) + (2.15) * btw;

		 	}

		     P11.checked = false;

     	       }

           }



       total.value=formatCurrency(hiddentotal.value);	



	if (P11.checked == false)

	{

		return (false);

	}

   }

}	





// ###  Berekenen COMBINATIE ### //

function sel_comb1()

 {

	with (document.myform)

      {

	if (comb1.value < 2)

	{

	      P11.checked = false;

            return (false);

	}

	else

           if (P11.checked == true)

              {     

	     		if (P07.checked == false)

	   		{

		 	hiddentotal.value = eval(hiddentotal.value) - (2.15) * btw;

		      total.value=formatCurrency(hiddentotal.value);

	  		}

			else

			{

			hiddentotal.value = eval(hiddentotal.value) - (1.90) * btw;

	         	total.value=formatCurrency(hiddentotal.value);

			}

 	      }

	   else

              {

			if (P07.checked == false)

	   		{

		 	hiddentotal.value = eval(hiddentotal.value) + (2.15) * btw;

	         	total.value=formatCurrency(hiddentotal.value);

			}

			else

			{

		 	hiddentotal.value = eval(hiddentotal.value) + (1.90) * btw;

	         	total.value=formatCurrency(hiddentotal.value);

			}

 	      }

       }

}



// ###  Berekenen stokbrood  ### //



function sel_stokbrood()



 {

	with(document.myform)

      {

		if (B1.checked == true | B2.checked == true | B3.checked == true | S1.checked == false)

		{

	      	checkChoice(S1);

      	}

		else

			{

		            S1.checked = false;

	                  return (false);

                  }

        }

 }







// ###  Berekeningen op checkbox ### //



function checkChoice(whichbox)

{

	with (whichbox.form)

      {

	      if (whichbox.checked == false)

            {

	      	hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value) * btw;

            }	

	      else

	      {

	            hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value) * btw;

   	      }

		total.value=formatCurrency(hiddentotal.value);

        }

}





// ###  Formateer currency naar juiste formaat ### //



function formatCurrency(num)



{



           num = num.toString().replace(/\$|\,/g,'');



	   if(isNaN(num)) num = "0";



	   cents = Math.floor((num*100+0.5)%100);



	   num = Math.floor((num*100+0.5)/100).toString();



	   if(cents < 10) cents = "0" + cents;



	   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)



	   num = num.substring(0,num.length-(4*i+3))+'.'+num.substring(num.length-(4*i+3));



	   return ("" + num + "," + cents);



}



// ###  Bereken totaal ### //



function updateTotal()



{



	with(document.myform)



	{



	   if (quantity.value== "")



	   {	



	      alert("Het aantal personen is verplicht.");



	      quantity.focus();



	      return (false);



	   }



	   // ### Controleer of er een geldig aantal is ingevuld. ### //



	   var checkOK = "1234567890";



	   var checkStr = quantity.value;



	   var allValid = true;



	   for (i = 0;  i < checkStr.length;  i++)



		{



		ch = checkStr.charAt(i);



		for (j = 0;  j < checkOK.length;  j++)



		if (ch == checkOK.charAt(j))



	        break;



		   if (j == checkOK.length)



		   {



      		   allValid = false;



		   break;



		   }



		}



	     if (!allValid)



	     {



    	        alert("Dit is een ongeldige waarde voor het aantal personen.");



 	        quantity.focus();



    	        return (false);



  	     }



	     else



	     {



                total1.value=formatCurrency(quantity.value * hiddentotal.value);



	     }



	}



}
