function validateCompEntry(form) {
  	var quest_answered = true;
  	var old_qname = form.elements[0].name;
  	var cur_qname = old_qname;
  	var bad_qname = "";
  	var i = 0;
  	var elementCount = form.elements.length;
  	var allowedExtensions = ['doc', 'mov','wmv','mpeg','mpg','mpe','mp3',
  	                         'avi','wav','gif','jpg','jpeg','pjpeg','png','tif','tiff','txt',
  	                         'rtx','rtf','mp4'];
  	var extensionOK = false;
	var fileUploadExists = false;
	
  	var invalidExtensionString="";
	//var elementCount = form.elements[i].length;

  	// loop through all the elements in the form
  	while (i < elementCount) {
    		question_ok = false;
    		// loop through all the answers in the same question.
    		while (old_qname == cur_qname) {
        		//alert("i is " + i + " and elementCount is " + elementCount);
        		
        		if (!question_ok) {
          			// radio question
          			if (form.elements[i].type == "radio") {
            				question_ok = form.elements[i].checked;
        
          			// checkbox question
          			} else if (form.elements[i].type == "checkbox") {
            				question_ok = form.elements[i].checked;
        
          			// text answer
          			} else if (form.elements[i].type == "text" || form.elements[i].type == "textarea") {
            				question_ok = (form.elements[i].value != "");
        
          			// select box 
          			} else if (form.elements[i].type == "select-one") {
            				question_ok = (form.elements[i].value != "");
          			// file box 
          			} else if (form.elements[i].type == "file") {
          				if( form.elements[i].value != "" ) { 
          					fileUploadExists = true;
							var filename = form.elements[i].value;
          					var extPos = filename.lastIndexOf(".") + 1;
          					question_ok = (filename.substring(extPos).toLowerCase() in arrayToOjectLiteral(allowedExtensions));
          					extensionOK = question_ok;
          					invalidExtensionString = "" + filename.substring(extPos).toLowerCase();
          				} else {
          					question_ok = false;
          				}
          			
          			// debugging escape clause.  Shouldn't arrive here
          			} else {
          				if (form.elements[i].type != "button"){ // ignore the submit button
                				alert("Error: form type not allowed for found: " + form.elements[i].type);
            				question_ok = false;
          				} else {
          					question_ok = true;
          				}
          			}
        		}
      			
      			i++;
      			if (i < elementCount) {
        				// get the question name of the next answer
        				cur_qname = form.elements[i].name;
      			} else {
        				cur_qname = "question_num" + i;
      			}
      			// check to see if there has been a valid answer for this question.
      			if ((old_qname != cur_qname) && !question_ok) {
        				quest_answered = false;
        				bad_qname = old_qname;
        				break; // bad question found, stop looping
      			}
      			
    		} // end while old_qname == cur_qname
    		
    		old_qname = cur_qname; // synch old and current question name
  
    		// if there has been a non-answered question, then break
    		if (!quest_answered)
    		    break;
  	}
  	
  	// check if there has been a bad answer, if so, prompt and jump to it
  	if (!quest_answered) {
    	if(fileUploadExists && !extensionOK){	
    		window.alert("File with extensions of \""+invalidExtensionString+"\" are not allowed.");
    	} else {
    		window.alert("Please ensure all fields are filled out.");
    	}
    	document.location= "#" + bad_qname;
    	return false;
  	} else {
  	    // comp entry is valid
  		  return true;		  
  	}
}

function arrayToOjectLiteral(a)
{
  var o = {};
  for(var i=0;i<a.length;i++)
  {
    o[a[i]]='';
  }
  return o;
}
