function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function MM_validateForm() { //v4.1
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=MM_nameOf(val).replace(/_/g, ' '); while (nm.substr(0,1)==' ') nm=nm.substr(1);
        if ((val=MM_valueOf(val))!="") {
        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'; }
    }
// snip... insert custom checks

//Check for purchased from
if (getElementsByClass('purchased_from')) {
    var noError = false;
    var purchasedFrom = getElementsByClass('purchased_from');
    var purchasedFromInputs = purchasedFrom[0].getElementsByTagName('input');
    for (i=0;i<purchasedFromInputs.length;i=i+2) { 
        if (purchasedFromInputs[i].checked == true && purchasedFromInputs[i+1].value !='') { 
        noError=true;
        break;
        } else if (purchasedFromInputs[i].checked == true) {
            errors += '- Please specify \''+purchasedFromInputs[i].value+'\' for where you purchased the machine from.\n';
            noError = true;
            break;
        }
    }
    if (noError == false) { 
    errors+= '- Please tell us where you purchased the machine.\n';
    }
}

// Check for contributing factors
if (getElementsByClass('contributing_factors')) {
    var noError = false;
    var factors = getElementsByClass('contributing_factors');
    var factorsInputs = factors[0].getElementsByTagName('input');
    for (i=0;i<factorsInputs.length; i++) { 
        if (factorsInputs[i].checked == true) { 
            noError=true;
            break;
        }
    }
    if (noError == false) { 
    errors+= '- Please tell us the contributing factors for your purchase.\n';
    }
}

if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
    return document.MM_returnValue;
}