<!--




function updateTotals() {
	tempTotal = 0;
	
	for(i=1;i<=10;i++) {//i starts at 1, keep looping while i is less than nine, increment i by 1 after each loop
		
		((i<=4) || (i==10)) ? tourMod = "swt" : tourMod = "eco"; //if i is less than or equal to 4, tourMod = swt, else tourMod = eco
			
		aObj = eval("document.orderForm."+tourMod+i+"Adults"); //eval tries to create an object from a string and store the object as a varible. 
		aPrice = eval("document.orderForm."+tourMod+i+"AdultsPrice");
		sObj = eval("document.orderForm."+tourMod+i+"Supp");
		sPrice = eval("document.orderForm."+tourMod+i+"SuppPrice");
		cObj = eval("document.orderForm."+tourMod+i+"Children");
		cPrice = eval("document.orderForm."+tourMod+i+"ChildrensPrice");
		
		tempTotal += aObj.options[aObj.selectedIndex].value * aPrice.value; //work out the price for adult, student and child. and add this to tempTotal
		if(tourMod=="swt") { tempTotal += sObj.value * sPrice.value; }
		tempTotal += cObj.options[cObj.selectedIndex].value * cPrice.value;
	}
	
	
	for(j=2;j<=5;j++) {
	
		bObj = document.orderForm.elements['bonanzaTours'+j+'[]']; //eval tries to create an object from a string and store the object as a varible. 
		bAdultPrice = eval("document.orderForm.bonanzaAdultsPrice"+j);
		bChildPrice = eval("document.orderForm.bonanzaChildrenPrice"+j);
		bDate = eval("document.orderForm.bonanzaDate"+j);
		bAdultQty = eval("document.orderForm.bonanzaAdults"+j);
		bChildQty = eval("document.orderForm.bonanzaChildren"+j);
		
		if ((bAdultQty.options[bAdultQty.selectedIndex].value!=0) || (bChildQty.options[bChildQty.selectedIndex].value!=0)) {
			if (checkBonanza(bObj,j)) {
				tempTotal += bAdultQty.options[bAdultQty.selectedIndex].value * bAdultPrice.value;
				tempTotal += bChildQty.options[bChildQty.selectedIndex].value * bChildPrice.value;			
			}
		}


	}
	

		document.orderForm.grandTotal.value = formatCurrency(tempTotal, false);
		//alert(document.orderForm.grandTotal.value);
	
}

function checkBonanza(fObj,maxNum) {
var numSelected = 0;
var x = false;

	if (fObj) {
		for(i=0;i<fObj.options.length;i++) {
			if(fObj.options[i].selected) {
				numSelected++;
			}
		}
		
		if(numSelected>maxNum) {
			alert("You can only select "+maxNum+" tours for Bonanza Package "+maxNum+". Please try again");
			for(i=0;i<fObj.options.length;i++) {
				fObj.options[i].selected=false;
			}
		x=false;
		} else if(numSelected<maxNum) {
			alert("You must select "+maxNum+" tours for Bonanza Package "+maxNum+". Please try again.");
		x=false;
		} else {
			x=true;
		}
		
	}
	
	return x;
}


function formatCurrency(num,unpure) {
/*
   Syntax:

   formatCurrency(num[,unpure])
   num:     The string or number to format.
   unpure:  true/false (optional)
            If true, dollar signs and commas
            are removed before formatting.

*/
   if (unpure) num = num.replace(/\,/g,"").replace(/^\$/g,"");
   num = !isNaN(num) ? Math.round(num * 100) / 100 : 0;
   if (num.toString().indexOf(".") == -1) num += ".";
   while (/\.\d{0,1}$/.test(num)) num += "0";
   num = num.toString().split(".");
   var objRegExp  = new RegExp('(-?\[0-9]+)([0-9]{3})');
   while (objRegExp.test(num[0])) num[0] = num[0].replace(objRegExp,'$1,$2');
   return "$" + num.join(".");
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  
  if(!document.orderForm.Accepted.checked) {
  		alert("Please agree to accept our cancellation policy.");
		document.MM_returnValue = false;
	} else {
  
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
  }
}
//-->