//javascripts for forms
//calculation and display of cost
function CalculateAndDisplayCost(form)
{
var cost = 0;
var iBookPrice = 7.0;
var itemOrdered = form.BookTitle.value; //book that customer wants
var quantity = form.Quantity.value;     //desired quantity
//if user had already entered non-blank values for these, but then made one or more of these
//blank, then the cost must vanish and the function need not proceed any further
if (itemOrdered == 0 || quantity == 0) {
ClearCostDisplay(form);
return;
}
if (quantity == -1) {
if (!form.OtherQuantity) {
ClearCostDisplay(form);
document.getElementById("OtherQuantityField").innerHTML = 'Introducir cantidad: ' + ' '  // by GK, macro defined in cost_calculation_display_xx.ih
+ '<input type=text name=OtherQuantity' + ' '
+ 'onchange = "HandleOtherQuantityField(document.OrderForm)"' + '>';
return;
}
else
quantity = form.OtherQuantity.value;
}
//if function reaches this point, then none of the above critical fields is blank, thus cost is
//non-zero and worth displaying
//set price per copy according to language
if (itemOrdered == "GREEK" ) { iBookPrice = 7.0; }
cost = quantity * iBookPrice;
//display value to 2 decimal places; first, check if browser supports toFixed
var costToDisplay = (cost.toFixed) ? cost.toFixed(2) : cost;
document.getElementById("costDisplayQuantity").innerHTML =  costToDisplay + " Euro + Gastos de envío";   // by GK, macro defined in cost_calculation_display_xx.ih
//update hidden cost variable in form so that it may be sent to publisher upon submission of form
form.cost.value = cost;
}
function ClearCostDisplay(form)
{
document.getElementById("costDisplayQuantity").innerHTML = "";
document.getElementById("OtherQuantityField").innerHTML = "";
}
function HandleOtherQuantityField(form)
{
CalculateAndDisplayCost(form);
}
function SetActualBookTitle(form)
{
form.Actual_Book_Title.value = form.BookTitle.options[form.BookTitle.selectedIndex].text;
}
function SetActualTransport(form)
{
form.Actual_Transport.value = form.Transport.options[form.Transport.selectedIndex].text;
}
