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;
}

function stripSpaces(s){
	var t = '';
	sArr = s.split(" ");
	for(i=0; i < sArr.length; i++){
		t += sArr[i];
	}
	return t;
}

function validateForm(){
	var i,p,q,nm,test,num,min,max,errors='';
	var args = validateForm.arguments;
	for(i = 0; i < (args.length - 2); i += 3){
		test = args[i+2];
		label = args[i+1];
		if(args[i].indexOf('|') != -1){
			nm = label.split('|');
			vals = args[i].split('|');
			val1 = findObj(vals[0]);
			val2 = findObj(vals[1]);
			if((val1.value == "") && (val2.value == "")){
				errors += '- '+nm[0]+' or '+nm[1]+' is required.\n';
			}
		}else{
			val = findObj(args[i]);
			if(val){
				nm = label;
				rb = val;
				if((val = val.value) != "" || test.charAt(0) == 'S'){
					if(test.indexOf('E|') != -1){
						p=test.indexOf('|');
						d=test.substring(p+1);
						if(d == val || val.value == "" || (val.substring(0,d.length) != d)){
							if(val.substring(0,d.length) != d){
								errors += '- '+nm+' is required and must start with ' + d + '.\n';												}else{
								errors += '- '+nm+' is required.\n';
							}
						}				
					}else 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 == 'B'){
						valcheck = false;
						if(rb.checked){
							valcheck = true;
						}else{
							for(a=0;a<rb.length;a++){
								if(rb[a].checked){
									valcheck = true;
								}
							}
						}
						if(!valcheck){
							errors += '- '+nm+' is required.\n';
						}
					}else if(test.indexOf('L:') !=-1){
						p=test.indexOf(':');
						num=test.substring(p+1);
						if(val.length != num){
							errors+='- '+nm+' must contain '+num+' characters.\n'
						}
					}else if(test == 'N'){
						num = parseFloat(stripSpaces(val));
						if(isNaN(num)){
							errors+='- '+nm+' must contain a number.\n';
						}
					}else if(test.indexOf('N:') != -1){
						p=test.indexOf('|');
						min=test.substring(2,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.indexOf('SL') != -1){
						if(rb.selectedIndex==0){
							errors += '- '+nm+' is required.\n';
						}
					}else if(test.charAt(0) == 'S'){
						if(rb.options.length==0){
							errors += '- '+nm+' is required.\n';
						}
					}
				}else if(test.charAt(0) == 'E'){
					errors += '- '+nm+' is required.\n';
				}
			}
		}		
	}
	if(errors){
		alert('The following error(s) occurred:\n'+errors);
		return false;
	}else{
		return true;
	}
}