// -------------------------------------------------------------------
// ---- Form Validation and Querystring Transfers with JS
// -------------------------------------------------------------------
// ---- Designed by Active Media, 2001
// ---- (Daniel Saw; Freelance Mouse Pilot - Aust)
// ---- http://www.active-media.com.au/
// ---- If you use this script, include the above credits.
// -------------------------------------------------------------------
//**Start Encode**

// Format price function
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);
	}
// -------------------------------------------------------------------


// Set Line Selection Totals on Order Form
function lineItemTotal(productcode) {
	if(!productcode){
		return parseInt(0)
	} else {
		var oForm = document.conferenceapplication
		var intQty = eval("parseInt(oForm.qty"+productcode+"[oForm.qty"+productcode+".selectedIndex].value)");
		var regPrice = eval("parseFloat(oForm.price"+productcode+".value)");
		eval("oForm.total"+productcode+".value = formatCurrency(intQty*regPrice)");
		return parseFloat(intQty*regPrice)
		}
	}
// -------------------------------------------------------------------

// Write to form "grandtotalorder" field value for Conferences
function grandtotal(){
	var lineItemTotalAdd
	var oForm = document.conferenceapplication
	lineItemTotalAdd = parseInt(0)
	lineItemTotalAdd += lineItemTotal("fullasra");
	lineItemTotalAdd += lineItemTotal("fullnonasra");
	lineItemTotalAdd += lineItemTotal("singleasra");
	lineItemTotalAdd += lineItemTotal("singlenonasra");
	lineItemTotalAdd += lineItemTotal("dinner");
	oForm.grandtotalorder.value = formatCurrency(lineItemTotalAdd)
	return lineItemTotalAdd
	}
// -------------------------------------------------------------------

// Write to form "grandtotalorder" field value for Conference type "B"
function grandtotalb(){
	var lineItemTotalAdd
	var oForm = document.conferenceapplication
	lineItemTotalAdd = parseInt(0)
	lineItemTotalAdd += lineItemTotal("fullasra");
	lineItemTotalAdd += lineItemTotal("fullnonasra");
	lineItemTotalAdd += lineItemTotal("daysession");
	lineItemTotalAdd += lineItemTotal("asradinner");
	oForm.grandtotalorder.value = formatCurrency(lineItemTotalAdd)
	return lineItemTotalAdd
	}
// -------------------------------------------------------------------

// Write to form "grandtotalorder" field value for Seminars
function grandtotala(){
	var lineItemTotalAdd
	var oForm = document.conferenceapplication
	lineItemTotalAdd = parseInt(0)
	lineItemTotalAdd += lineItemTotal("fullasra");
	lineItemTotalAdd += lineItemTotal("fullnonasra");
	oForm.grandtotalorder.value = formatCurrency(lineItemTotalAdd)
	return lineItemTotalAdd
	}
// -------------------------------------------------------------------


// Validation script for Order form; called on submit (validate contact)
function ContactValidate(){
	var oForm = document.conferenceapplication;
	var msg = '';
	if(oForm.realname.value==''){msg+='- Contact Name\n'}
	if(oForm.email.value.indexOf('@')==-1 || oForm.email.value.indexOf('\.')==-1){msg+='- Contact Email Address\n'}
	if(oForm.address.value==''){msg+='- Postal Address\n'}
	if(oForm.phone.value==''){msg+='- Telephone Number\n'}
	if(oForm.country.value==''){msg+='- Delivery Country\n'}
	if(oForm.postcode.value==''){msg+='- Delivery Postcode or Zip\n'}

	if(msg!=''){
		window.alert('The following required field\/s\nmust be completed:\n\n'+msg)
		return false
		}
	return true
	}
// -------------------------------------------------------------------


