
<!--

    // configuration area starts --
    
    //by default, the total number of groups
	var number_of_group = 4;
	
    //the number of questions of each group
    //by default,
    //the first group has a total of 4 questions.
    //the second group has a total of 4 questions.
    //the third group has a total of 3 questions.
    //the fourth group has a total of 3 questions.
	var number_of_questions = new Array(4,4,3,3);
	
    //the number of "yes" for each group which is required for a positive recommendation
    //by default, 
    //the first group requires 3 "yes" of 4 questions to get a positive recommendation
    //the second group requires 3 "yes" of 4 questions to get a positive recommendation
    //the third group requires 2 "yes" of 3 questions to get a positive recommendation
    //the fourth group requires 3 "yes" of 3 questions to get a positive recommendation
	var number_of_yes = new Array(3,3,2,2); //contains the minimum number of "Yes" for each group to qualify a course

  //original value  
	var originalTextFontFamily = "Verdana"; //Verdana
	var originalTextFontSize = "9";
	var originalTextFontColor = "black";
	var originalTextFontBold = "false";  //bold if true; 
	var originalTextFontUnderline = "false"; //underline if true;
	
	//font type, font size, font color, attributes (bold, underline) of the recommendation phrases 
	var textFontFamilyPositive = new Array("Verdana","Verdana","Verdana","Verdana");
	var textFontFamilyNegative = new Array("Verdana","Verdana","Verdana","Verdana");
	var textFontSizePositive = new Array("9", "9","9","9");
	var textFontSizeNegative = new Array("9", "9","9","9");
	var textFontColorPositive = new Array("green", "green", "green", "green");
	var textFontColorNegative = new Array("red", "red", "red", "red");
	var textFontBoldPositive = new Array("true", "true", "true", "true");   
	var textFontBoldNegative = new Array("true", "true", "true", "true");   
	var textFontUnderlinePositive = new Array("false", "false", "false", "false"); 
	var textFontUnderlineNegative = new Array("false", "false", "false", "false"); 
	
	// -- configuration area ends -- 
	
	//var div_qualification;
	
    //recommendation phrases
  var original_message = "<span style='font-size: 0.9em;'>Please complete the form...</span>";
  var message_for_applicable = "This training course is applicable to your needs.";
	var message_for_not_applicable = "This training course may not be applicable to your needs.";
	
	//id for course qualification
	var qualification_prefix = "group_";
	var qualification_postfix = "_qualification";
	var phrase_postfix = "_phrase";
	
    //id for question
	var question_prefix = "group_";
	var question_body = "_question_";

	function resetPhraseByGroup(groupNumber) 
	{
      var idOfQua = qualification_prefix+groupNumber+ qualification_postfix;
      var idOfPhr = qualification_prefix+groupNumber+phrase_postfix;
      var div_qua = document.getElementById(idOfQua);
      
      var outblock = div_qua.innerHTML;
      //var innerBlock = div_phr.innerHTML;
      var u_elem = div_qua.getElementsByTagName("U")[0];
      if(u_elem) 
      {
      	outblock = u_elem.innerHTML;	
      }
      var b_elem = div_qua.getElementsByTagName("B")[0];
      if(b_elem) 
      {
      	outblock = b_elem.innerHTML;	
      }
      div_qua.innerHTML = outblock;
      
	    var sp_elem = div_qua.getElementsByTagName('span')[0];
	   
	    sp_elem.style.fontSize = originalTextFontSize+"pt";
	    sp_elem.style.fontFamily = originalTextFontFamily;
	    sp_elem.style.color = originalTextFontColor;
      
      sp_elem.innerHTML = original_message+"<o:p><\/o:p>";
      
      
      var iobj = div_qua.getElementsByTagName('i')[0];
      iobj_inner = "<i><span style='font-size:8.0pt;font-family:Verdana' id='group_"+groupNumber+"_phrase'>"+sp_elem.innerHTML+"</span></i>";
      div_qua.innerHTML = iobj_inner;
	}

  function resetPhrase() 
  {
  	for(var i=1;i<=number_of_group;i++) 
  	{
	  	resetPhraseByGroup(i);   
  	}
  }

  
  function configPhrase(div_qualification, groupNumber, positive) 
  {
    var div_block = div_qualification.innerHTML;
    var textFontBold;
    var textFontUnderline;
    var textFontSize;
    var textFontFamily;
    var textFontColor;

    if(positive == "true"){
    	textFontBold = textFontBoldPositive[groupNumber-1];
    	textFontUnderline = textFontUnderlinePositive[groupNumber-1];
    }else {
    	textFontBold = textFontBoldNegative[groupNumber-1];
    	textFontUnderline = textFontUnderlineNegative[groupNumber-1];
    }
    if(textFontBold == "true") {
        div_block = '<b>'+div_block+'</b>';
    }
   	
    if(textFontUnderline == "true") {
        div_block = '<u>'+div_block+'</u>';
    }
    div_qualification.innerHTML = div_block;
    var span_elem = div_qualification.getElementsByTagName('span')[0];
    if(positive == "true") {
    	textFontSize = textFontSizePositive[groupNumber-1];
    	textFontFamily = textFontFamilyPositive[groupNumber-1];
    	textFontColor = textFontColorPositive[groupNumber-1];		
    } else {
    	textFontSize = textFontSizeNegative[groupNumber-1];
    	textFontFamily = textFontFamilyNegative[groupNumber-1];
    	textFontColor = textFontColorNegative[groupNumber-1];		
    }
   
    span_elem.style.fontSize = textFontSize+"px";
    span_elem.style.fontFamily = textFontFamily;
    span_elem.style.color = textFontColor;
  }	
  
  function ifqualify(groupNumber, questionId)
  {
      if(groupNumber-1 >= number_of_questions.length) return false;
      var numberOfQuestions = number_of_questions[groupNumber-1];
      if(groupNumber-1 >= number_of_yes.length) return false;
      var numberOfYes = number_of_yes[groupNumber-1];
      resetPhraseByGroup(groupNumber);
      var idOfQualification = qualification_prefix+groupNumber+qualification_postfix;
      div_qualification = document.getElementById(idOfQualification);
      var positive = "true";
      if(div_qualification) 
      {
	      var idOfPhrase = qualification_prefix+groupNumber+phrase_postfix;
	      div_phrase = document.getElementById(idOfPhrase);
	      if(div_phrase) 
	      {
		      var i = 1;
		      var count = 0;
		      var countOfAnswered = 0;
		      for(;i<=numberOfQuestions;i++) {
		      	nameOfQuestionX = question_prefix+groupNumber+question_body+i;
		      	//alert(nameOfQuestionX);
		      	valueOfInput = $RF(nameOfQuestionX);
		  	  	if(valueOfInput) {
		    	  	countOfAnswered++;
		            if(valueOfInput.toLowerCase() == "yes") {
		    	  		count++;	
		    	  	}
		  	  	} 
		      }
		      //alert('count = '+count+'  required = '+numberOfYes);
		      
		      if(countOfAnswered == numberOfQuestions) {
		        
		        if(count < numberOfYes) {
		      	     div_phrase.innerHTML = message_for_not_applicable;
		      	     positive = "false";
		      	     
		        } else {
		      	     div_phrase.innerHTML = message_for_applicable;
		      	     
		        }
		        
		        configPhrase(div_qualification, groupNumber, positive);
		      }
	    	}
	    }
  }
  
function clear_all_radios(){
    var lb = "\x5B";
    var rb = "\x5D" 
    var elements = document.getElementsByTagName('input');
    var elnum;
    for(elnum=0;elnum<elements.length;elnum++){
        var el = eval("elements"+lb+"elnum"+rb);
        if ( el.type == 'radio') {
            el.checked = false;
        }
    }
}

  function resetAll() 
  {
  clear_all_radios();

  	resetPhrase();
  }
  
	function $RF(idOrName) {
	    var value = null;
	  
	    var element = document.getElementById(idOrName);
	    var radioGroupName = null;  
	    // if null, then the id must be the radio group name
	    if (element == null) {
	        radioGroupName = idOrName;
	    } else {
	        radioGroupName = element.name;  
	    }
	    if (radioGroupName == null)
		return null;    
	    var radios = document.getElementsByTagName('input');
	    for (var i=0; i<radios.length; i++) {
	        var input = radios[ i ]; 
	        if (input.type == 'radio' && input.name == radioGroupName && input.checked) {        
	            value = input.value;
	            break;
	        }
	    }
	    return value;
	}
 
-->


