function UpdateTotal()
{
// CREATING A VARIABLE TO HOLD THE TOTAL AMOUNT
var totalAmount = 0;
var hasCoupon = 0;
// CHECK IF NEW STUDENT
if(document.form1.newStudent[0].checked == true)
{
totalAmount = 20;
}
// APPLYING THE MULTIPLICATION
totalAmount = totalAmount + (document.getElementById('classRate').value * document.getElementById('programLength').value);
// CHECK COUPON
if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') != "")
{
if(document.getElementById('classRate')[0].selected == false && document.getElementById('programLength')[0].selected == false)
{
// COUPON CODE 1 (10% OFF LESSON 1/2 HR. PROGRAM)
if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "half hour discount")
{
document.getElementById('couponDescription').innerHTML = '10% off 1/2 hour lesson program -- A $15.50 value';
totalAmount = totalAmount - 15.50;
document.getElementById('on0').value = document.getElementById('programLength').value + ' weeks';
document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per lesson. Coupon Code: half hour discount - 10% off.';
hasCoupon = 1;
}
// COUPON CODE 2 (10% OFF LESSON HR. PROGRAM)
else if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "hour discount")
{
document.getElementById('couponDescription').innerHTML = '10% off hour lesson program -- A $31.00 value';
totalAmount = totalAmount - 31.00;
document.getElementById('on0').value = document.getElementById('programLength').value + ' weeks';
document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per lesson. Coupon Code: hour discount - 10% off.';
hasCoupon = 1;
}
// COUPON CODE 3 (TRIAL LESSON)
else if(document.getElementById('coupon').value.replace(/^\s*/, '').replace(/\s*$/, '') == "trial")
{
document.getElementById('couponDescription').innerHTML = 'Trial Lesson';
totalAmount = totalAmount - 125.00;
document.getElementById('on0').value = document.getElementById('programLength').value + '';
document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' Coupon Code: Trial.';
hasCoupon = 1;
}
else
{
document.getElementById('couponDescription').innerHTML = 'Invalid code';
hasCoupon = 0;
}
}
}
else
{
document.getElementById('couponDescription').innerHTML = ' ';
}
// DISPLAYING THE TOTAL AMOUNT IN THE RIGHT FORM ELEMENT
document.getElementById('tot').value = '$' + Dollar(totalAmount);
// NOW UPDATE PAYPAL'S FORM
document.getElementById('amount').value = Dollar(totalAmount);
document.getElementById('on0').value = document.getElementById('programLength').value + ' weeks';
if(hasCoupon == 0)
{
document.getElementById('os0').value = '$' + document.getElementById('classRate').value + ' per lesson.';
}
}
// FORM VALIDATION
function formValidation()
{
if(document.getElementById('classRate')[0].selected == true)
{
alert('Please select the Rate');
document.getElementById('classRate').focus();
return false
}
if(document.getElementById('programLength')[0].selected == true)
{
alert('Please select the Length');
document.getElementById('programLength').focus();
return false
}
if(document.getElementById('os1').value.replace(/^\s*/, '').replace(/\s*$/, '') == "")
{
alert('Please enter the student name and instrument');
document.getElementById('os1').focus();
return false;
}
// APPEND THE OPTIONS FIELD FOR THE NEW STUDENT FEE
if(document.form1.newStudent[0].checked == true)
{
document.getElementById('os0').value = document.getElementById('os0').value + ' (+$20 registration fee)'
}
return true;
}
function Dollar (val)
{
// force to valid dollar amount
var str,pos,rnd=0;
if (val < .995) rnd = 1; // for old Netscape browsers
str = escape (val*1.0 + 0.005001 + rnd); // float, round, escape
pos = str.indexOf (".");
if (pos > 0) str = str.substring (rnd, pos + 3);
return str;
}