<!-- 
//
// Written for: My Devine Things Pty Ltd.
// Copyright: A Better Deal for ALL (C) 2010 all rights reserved.
// Designed & Developed by: A Better Deal for All ABN: 64 648 123 459
// URL: http://www.ABetterDealForAll.net.au/
// Author: Graham Hagney.
// Program Name: EX001.js
// Date Created: February 2010
// Description: 
//    Validation form.....


var PostageHandling=5.00;
var CDPrice=20.00;	//General CD Price

var Book01Title="'The Many Parts of You'";	
var Book01Price=19.95;

var CD01Title='BEING PROFESSIONAL';	
var CD01Price=CDPrice;

var CD02Title='INNER SELF';	
var CD02Price=CDPrice;

var CD03Title='GETTING THE JOB';	
var CD03Price=CDPrice;

var CD04Title='STOP SMOKING CD';	
var CD04Price=30.00;	

var Book01Total=0;
var CD01Total=0;
var CD02Total=0;
var CD03Total=0;
var CD04Total=0;
var SubTotal=0;
var Freight=0;
var TotalCost=0;






  function validEmailAddress(EmailAddress) {
//----------------------------
     invalidChars = " /:,;"
     if (EmailAddress == "") {                                                // cannot be empty
         return false
     }
     for (i=0; i<invalidChars.length; i++) {        // does it contain any invalid characters?
         badChar = invalidChars.charAt(i)
         if (EmailAddress.indexOf(badChar,0) > -1) {
             return false
             }
     }
     atPos = EmailAddress.indexOf("@",1)                        // there must be one "@" symbol
     if (atPos == -1) {
        return false
     }
     if (EmailAddress.indexOf("@",atPos+1) != -1) {        // and only one "@" symbol
        return false
     }
     periodPos = EmailAddress.indexOf(".",atPos)
     if (periodPos == -1) {                                        // and at least one "." after the "@"
         return false
     }
     if (periodPos+3 > EmailAddress.length)        {                // must be at least 2 characters after the "."
         return false
     }
     return true
}

  function submitIt(Enquiry) {
//-------------------------
// Check that First Name field has been entered
  if (Enquiry.Name.value == "") {
      alert("Please enter your Name.")
      Enquiry.Name.focus()
      Enquiry.Name.select()
      return false
  }
// Check that Address field has been entered
  if (Enquiry.Address.value == "") {
      alert("Please enter your Address.")
      Enquiry.Address.focus()
      Enquiry.Address.select()
      return false
  }
// Check that Suburb field has been entered
  if (Enquiry.Suburb.value == "") {
      alert("Please enter your Suburb.")
      Enquiry.Suburb.focus()
      Enquiry.Suburb.select()
      return false
  }
// Check that PostCode field has been entered
  if (Enquiry.Postcode.value == "") {
      alert("Please enter your Postcode.")
      Enquiry.Postcode.focus()
      Enquiry.Postcode.select()
      return false
  }
// Check that Phone field has been entered
  if (Enquiry.Phone.value == "") {
      alert("Please enter your Phone.")
      Enquiry.Phone.focus()
      Enquiry.Phone.select()
      return false
  }
// Check that Position field has been entered
  if (Enquiry.Position.value == "") {
      alert("Please enter your Position.")
      Enquiry.Position.focus()
      Enquiry.Position.select()
      return false
  }
// Check that Reason for Doing the Course field has been entered
  if (Enquiry.Reason.value == "") {
      alert("Please enter your Reason for Doing the Course.")
      Enquiry.Reason.focus()
      Enquiry.Reason.select()
      return false
  }
// check to see if the Email Address's valid
  if (Enquiry.EmailAddress.value == "") {
      alert("Email Address is not a valid Email address!\nPlease re-enter.")
      Enquiry.EmailAddress.focus()
      Enquiry.EmailAddress.select()
      return false
  }
  if (!validEmailAddress(Enquiry.EmailAddress.value)) {
      alert("Email Address is not a valid Email address!\nPlease re-enter.")
      Enquiry.EmailAddress.focus()
      Enquiry.EmailAddress.select()
      return false
  }

// Check that At least1 product has been purchased....
  if ((Enquiry.SubTotal.value == "0.00") || (Enquiry.SubTotal.value == "0")) {
      alert("You must purchase at least 1 Book or CD.");
      Enquiry.Book01Qty.focus();
      Enquiry.Book01Qty.select();
      return false;
  }

//  if (Enquiry.Terms.checked==false) {
//      alert(" You must read and agree to the terms and conditions!")
//      Enquiry.Terms.focus()
//      Enquiry.Terms.select()
//      return false
//  }
 
  
// If we made it to here, everything's valid, so return true
  return true
}

function formatCurrency(num) {
//------------------------------
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/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 (((sign)?'':'-') + '$' + num + '.' + cents);
return (((sign)?'':'-') + num + '.' + cents);
}

 function SetDefaultValues() {
//-----------------------------------------
 document.getElementById('FreightCost').value = formatCurrency(PostageHandling);
 }

 function CalcBook01Price(qty) {
//---------------------------------
   Book01Total = ((Book01Price * 1) * (qty * 1));
   CalcTotalPrice();
   document.getElementById('Book01Total').value = formatCurrency(Book01Total);
 }

 function CalcCD01Price(qty) {
//-----------------------------------------
   CD01Total = ((CD01Price * 1) * (qty * 1));
   CalcTotalPrice();
   document.getElementById('CD01Total').value = formatCurrency(CD01Total);
 }

 function CalcCD02Price(qty) {
//-----------------------------------------
   CD02Total = ((CD02Price * 1) * (qty * 1));
   CalcTotalPrice();
   document.getElementById('CD02Total').value = formatCurrency(CD02Total);
 }

 function CalcCD03Price(qty) {
//-----------------------------------------
   CD03Total = ((CD03Price * 1) * (qty * 1));
   CalcTotalPrice();
   document.getElementById('CD03Total').value = formatCurrency(CD03Total);
 }

 function CalcCD04Price(qty) {
//-----------------------------------------
   CD04Total = ((CD04Price * 1) * (qty * 1));
   CalcTotalPrice();
   document.getElementById('CD04Total').value = formatCurrency(CD04Total);
 }

// -->

 function CalcTotalPrice() {
//-----------------------------
   document.getElementById('SubTotal').value = formatCurrency((Book01Total * 1) + (CD01Total * 1) 
											 + (CD02Total * 1) + (CD03Total * 1) + (CD04Total * 1)); 
   document.getElementById('Total').value = formatCurrency((Book01Total * 1) 
										  + (CD01Total * 1) + (CD02Total * 1) + (CD03Total * 1) + (CD04Total * 1) + (PostageHandling * 1)); 
 }

 
 function ClearFields() {
//-----------------------------
var Book01Total=0;
var CD01Total=0;
var CD02Total=0;
var CD03Total=0;
var CD04Total=0;
var SubTotal=0;
var Freight=0;
var TotalCost=0;


document.getElementById('Book01Qty').value = 0;
document.getElementById('CD01Qty').value = 0;
document.getElementById('CD02Qty').value = 0;
document.getElementById('CD03Qty').value = 0;
document.getElementById('CD04Qty').value = 0;

document.getElementById('Book01Total').value = formatCurrency(0);
document.getElementById('CD01Total').value = formatCurrency(0);
document.getElementById('CD02Total').value = formatCurrency(0);
document.getElementById('CD03Total').value = formatCurrency(0);
document.getElementById('CD04Total').value = formatCurrency(0);
document.getElementById('SubTotal').value = formatCurrency(0);
document.getElementById('Total').value = formatCurrency(0);

}
// -->

