//**** Validates Form. Checks Name and Address fields for non blank and non "null" inputs, Email address for
//**** valid format and at least 8 digits in the Phone no field


function validateForm() {
  var a,i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;

//Test for spam

  test=args[15]; val=findObj(args[15]); 
  if (val) 
    { val=val.value; 
//    alert ('val=' +val);
      if (val!=14) 
	{ errors+='The total is incorrect, Please press OK and try again!\n';
	}
      else 
	for (i=0; i<(args.length-2); i+=3) 
	 { test=args[i+2]; val=findObj(args[i]); 
	  if (val) 
	     {nm=val.name; val=val.value; first=val.charAt(0);	 
	       if ((first!=" ") && (val!=""))
		 {if (test.indexOf("isEMail")!=-1) 
		    { p=val.indexOf('@');
		      a=checkemail(val);
		      if (a==false) errors+='- '+nm+' must be a valid e-mail address.\n';
		    } 
		  else if (test!='R') 
		    { if ((isNaN(val)) || (val.length<10)) errors+='- '+nm+' No. must have at least 10 digits.\n';				   
			if (test.indexOf('inRange') != -1) 
			  { p=test.indexOf(':'); 
			    min=test.substring(8,p); max=test.substring(p+1);
			    if (val<min || max<val) 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.returnValue = (errors == '');
    }
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); 
 return x;
}
