// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function calculateTotals() {
	var cst20v, cst50v, cst100v, cstTotal;
    cst20v=document.vouchform.qty20.value*20;
    cst50v=document.vouchform.qty50.value*50;
    cst100v=document.vouchform.qty100.value*100;
	cstTotal=cst20v+cst50v+cst100v;
	
	MM_setTextOfLayer('cst20','','$'+cst20v);
	MM_setTextOfLayer('cst50','','$'+cst50v);
	MM_setTextOfLayer('cst100','','$'+cst100v);
	MM_setTextOfLayer('csttot','','$'+cstTotal);
	
	
}
function validateVouchForm(){
	returnValue=true;
	error="no";
	theForm = document.vouchform;
		if(theForm.qty20.value < "1" && theForm.qty50.value < "1" && theForm.qty100 .value <"1"){
			error = "yes";
			returnValue=false;
			alert("You must order at least 1 voucher");
		}
		if(error!="yes"){
			var chck20 = parseInt(theForm.qty20.value);
			if (theForm.qty20.value != chck20 && chck20 != "NaN") {
				error = "yes";
				returnValue=false;
				alert("You can only order whole quantities of $20.00 gift vouchers");
			}
			var chck50 = parseInt(theForm.qty50.value).toString();
			if (theForm.qty50.value != chck50 && chck50 != "NaN") {
				error = "yes";
				returnValue=false;
				alert("You can only order whole quantities of $50.00 gift vouchers");
			}
			var chck100 = parseInt(theForm.qty100.value).toString();
			if (theForm.qty100.value != chck100 && chck100 != "NaN") {
				error = "yes";
				returnValue=false;
				alert("You can only order whole quantities of $100.00 gift vouchers");
			}
		}
		
		if(error!="yes"){
			if(theForm.baddress.value==""){
				error = "yes";
				returnValue=false;
				alert("You must provide an address.");
			}	
		
		}
		if(error!="yes"){
			if(theForm.bsuburb.value==""){
				error = "yes";
				returnValue=false;
				alert("You must provide a suburb.");
			}	
		
		}
		if(error!="yes"){
			if(!IsNumeric(theForm.bpostcode.value)||theForm.bpostcode.length<4){
				error = "yes";
				returnValue=false;
				alert("You must provide a valid post code.");
			}	
		
		}
		if(error!="yes"){
			if(!IsNumeric(theForm.bphone.value)||theForm.bphone.length < 8){
				error = "yes";
				returnValue=false;
				alert("You must provide a valid phone number.");
			}	
		
		}
		if(error!="yes"){
			if(!IsEmail(theForm.bemail.value)){
				error = "yes";
				returnValue=false;
				alert("You must provide a valid email address.");
			}	
		
		}

	return returnValue;
}

function IsEmail(strString)
   //  check for @	
   {
   var strValidChars = '@';
   var strChar;
   var blnResult = false;
   if (strString.length == 0) return false;
   //  test strString consists of valid character listed above
   for (i = 0; i < strString.length && blnResult == false; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == 0)
         {
         blnResult = true;
         }
      }
   return blnResult;
   }
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = '0123456789.-';
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
