//---------------------------------------------------------------------
// simple orderform system (C)2005 Sichemsoft V.o.F.
// page 1 of 4: order1.js
// Based of free JavaScript snippets provided by http://javascriptsource.com
//---------------------------------------------------------------------

// language specific strings

var NOSELECTION = [ 
    "U hebt geen enkel pakket gekozen.",
    "You have not selected any package."
];
var	PACKAGE = [
    "Pakket",
	"Package"
];
var PRICE = [
    "Prijs &euro;",
	"Price &euro;"
];
var AMOUNT = [
	"Bedrag &euro;",
	"Amount &euro;"
];
var SUBTOTAL = [
    "Subtotaal: ",
    "Subtotal: "
];
var REDUCTION1 = [
    "% " + fat("korting") + " voor non-profit onderwijsinstellingen",
    "% " + fat("discount") + " for non-profit educational institutions"
];
var REDUCTION2 = [
    "% " + fat("korting") + " voor studenten",
    "% " + fat("discount") + " for students"
];
var REDUCTION3 = [
    "% " + fat("actiekorting"),
    "% " + fat("action discount")
];
var POSTAGE = [
    "Administratiekosten:",
    "Handling:"
];
var TOTALEXCL = [
	"Totaal bedrag van uw bestelling excl.BTW: ",
	"Total amount of your order excl. sales tax: ",
];
var TOTALINCL = [
	"Totaal bedrag van uw bestelling incl.BTW: ",
	"Total amount of your order incl. sales tax: ",
];
var BACK = [
    "<- Terug",
    "<- Back"
];
var SUBMIT = [
    "Verder ->",
    "Next ->"
];
var RESET = [
    "Opnieuw",
    "Clear"
];

var CONDITIONS = [
[ // NL
	"Klanten in Nederland betalen "+BTW+"% BTW.<br>",
	"Klanten binnen de Europese Unie die op de volgende<br>",
	"pagina hun BTW-nummer invullen betalen geen BTW.<br>",
	"Klanten buiten de Europese Unie betalen geen BTW.<br>",
	"Alle prijzen zijn in euros."
],
[ // UK
	"Customers in the Netherlands must pay "+BTW+"% BTW (Dutch sales tax).<br>",
	"Customers from the European Union must enter their sales tax number<br>",
	"on the next page, otherwise they too have to pay "+BTW+"% BTW.<br>",
	"Customers from outside the European Union don't pay BTW.<br>",
	"All prices are stated in euros."
]];

var SUFFIX   = "_total"; 

//---------------------------------------------------------------------

function ProcessChoice(nonprofitChecked, studentChecked)
{
    with (document.orderform1)
	{
		if (nonprofitChecked && nonprofit.checked)
		{	
			student.checked = false;
		}
		if (studentChecked && student.checked)
		{
			nonprofit.checked = false;
		}
	    var total=0;
    	var deduct1=0;
    	var deduct2=0;
    	var deduct3=0;
		if (nonprofit.checked)
		{
		    deduct1=-DISCOUNT/100;
	    }
		else if (student.checked)
		{
		    deduct2=-STUDENT/100;
	    }
	    if (ACTION)
	    {
		    deduct3=-ACTION/100;
	    }
		for (var i=0; i<numberOfProducts; ++i)
		{
		    elements[productNames[i]+SUFFIX].value = 
			    FormatCurrency(productPrices[i] * parseInt(elements[productNames[i]].value));
	    	total += parseInt(elements[productNames[i]+SUFFIX].value);
		}
		
		subtotal   .value=FormatCurrency(total);
		edudiscount.value=FormatCurrency(deduct1*eval(subtotal.value));
		studiscount.value=FormatCurrency(deduct2*eval(subtotal.value));
		netto      .value=FormatCurrency(eval(subtotal.value)+eval(edudiscount.value)+eval(studiscount.value)+ HANDLING);
		if (ACTION>0)
		{
			actdiscount.value=FormatCurrency(deduct3*eval(netto.value));
			actnetto   .value=FormatCurrency(eval(actdiscount.value)+eval(netto.value));
			tax        .value=FormatCurrency(BTW/100*eval(actnetto.value));
    	    totalorder .value=FormatCurrency(eval(actnetto.value)+eval(tax.value));
	    }
	    else
		{
			tax        .value=FormatCurrency(BTW/100*eval(netto.value));
        	totalorder .value=FormatCurrency(eval(netto.value)+eval(tax.value));
        }
    }
}

//---------------------------------------------------------------------

function CheckOK(language)
{
    if (eval(document.orderform1.subtotal.value)==0)
    {
        alert(NOSELECTION[language]);
        return false;
    }
    return true;
}

//---------------------------------------------------------------------

function InitForm()
{
  	// Reset all values on form
	with (document.orderform1)
	{
	    subtotal        .value=FormatCurrency(0);
	  	edudiscount     .value=FormatCurrency(0);
	  	studiscount     .value=FormatCurrency(0);
  		netto           .value=FormatCurrency(0);
	  	tax             .value=FormatCurrency(0);
	    totalorder      .value=FormatCurrency(0);
	}

    // Set all checkboxes and radio buttons on form to unchecked
	for (xx=0; xx<document.orderform1.elements.length; xx++)
  	{
	    if (document.orderform1.elements[xx].type=='checkbox' | 
		    document.orderform1.elements[xx].type=='radio')
	    {
	        document.orderform1.elements[xx].checked=false;
        }
    }
}

//---------------------------------------------------------------------

function OrderForm1(language)
{
    PreloadImages("image/euroflag.gif");
    
	formbegin("get", "orderform1", "", "order2"+XY[language]+".html");

	text("<center>");

	tablebegin("table");

	rowbegin("row");
	emptycell("");
	cell("tablehead", PACKAGE[language]);
	cell("tablehead", PRICE[language]);
	cell("tablehead", AMOUNT[language]);
	rowend();

	for (i=0; i<numberOfProducts; ++i)
	{
		rowbegin("row");
	    cellbegin("");
    	document.write('<select name="'+productNames[i]+'" size="1" onChange="ProcessChoice(false, false);">');
	    for (j = 0; j <= 4; ++j)
		{
			document.write('<option value="'+j+'">'+j);
		}
    	document.write('</select>');
	    cellend();
		cell("leftalign", productCaptions[language][i]);
		cell("price", FormatCurrency(productPrices[i]));
    	cell("", editboxro("amount", productNames[i]+SUFFIX, FormatCurrency(0)));
		rowend();
	}

	rowbegin("");
	emptycell("");
	cell("rightalign", SUBTOTAL[language]);
	emptycell("");
	cell("", editboxro("total", "subtotal", FormatCurrency(0)));
	rowend();

	rowbegin("");
	cell("", center(checkbox("", "nonprofit", "", "ProcessChoice(true, false)")));
	cell("leftalign", DISCOUNT + REDUCTION1[language]);
	emptycell("");
	cell("", editboxro("amount", "edudiscount", FormatCurrency(0)));
	rowend();

	rowbegin("");
	cell("", center(checkbox("", "student", "", "ProcessChoice(false, true)")));
	cell("leftalign", STUDENT + REDUCTION2[language]);
	emptycell("");
	cell("", editboxro("amount", "studiscount", FormatCurrency(0)));
	rowend();

	rowbegin("");
	cell("", center(checkboxro("", "", "", "", 1)));
	cell("leftalign", POSTAGE[language]);
	cell("price", FormatCurrency(HANDLING));
	cell("", editboxro("amount", "postage", FormatCurrency(HANDLING)));
	rowend();

	rowbegin("");
	emptycell("");
	cell("rightalign", TOTALEXCL[language]);
	emptycell("");
	cell("", editboxro("total", "netto", FormatCurrency(0)));
	rowend();

	if (ACTION > 0)
	{
		rowbegin("");
		cell("", center(checkboxro("", "action", "", "", 1)));
		cell("leftalign", ACTION + REDUCTION3[language]);
		emptycell("");
		cell("", editboxro("amount", "actdiscount", FormatCurrency(0)));
		rowend();
        hiddenfield("action","1");
        
		rowbegin("");
		emptycell("");
		cell("rightalign", TOTALEXCL[language]);
		emptycell("");
		cell("", editboxro("total", "actnetto", FormatCurrency(0)));
		rowend();

    }

	rowbegin("");
	cell("", center(checkboxro("", "", "", "", 0)));
//	cell("", fat(center("?")));
	cell("leftalign", BTW + "% BTW (tax)");
	emptycell("");
	cell("", editboxro("amount", "tax", FormatCurrency(0)));
	rowend();

	rowbegin("");
	emptycell("");
	cell("rightalign", TOTALINCL[language]);
	emptycell("");
	cell("rightalign", editboxro("total", "totalorder", FormatCurrency(0)));
	rowend();

	rowbegin("");
	emptycell("");
	cell("", center(backbutton("button", BACK[language])+" "+
	         fat(submitbutton("button bold", "CheckOK("+language+")", SUBMIT[language]))));
	emptycell("");
	cell("", center(resetbutton("button", RESET[language])));
	rowend();

	rowbegin("");
	cell("", center(font("standout",fat("!"))));
	cellbegin("");
	text(font("conditions",CONDITIONS[language][0]));
	text(font("conditions",CONDITIONS[language][1]));
	text(font("conditions",CONDITIONS[language][2]));
	text(font("conditions",CONDITIONS[language][3]));
	text(font("fatconditions",CONDITIONS[language][4]));
	cellend();
	emptycell("");
	cell("", center("<img src=\"image/euroflag.gif\" alt=\"euroflag\">"));
	rowend();

	tableend();
	
	text("</center>");

	formend();
}

//---------------------------------------------------------------------