function setFormAction(){
}

function setFormAction2()
{
var l=window.location.href;
if (l.indexOf('bk_sb_')!=-1) document.Beleggerstest.action="bk_sb_to_beleggingstest_resultaat.html";
else if (l.indexOf('ond_zvbko_')!=-1) document.Beleggerstest.action="ond_zvbko_pp_sfl_testres.html";
else {} 
}

function printTest(){
document.getElementById('p7ABc1_1').style.visibility='visible';
}

function clearProfile(){
document.getElementById('beleggersProfiel').innerHTML="";
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function

var score=0;
var labelText="";
var state=-1;
var upd=true;
var exception=false;

function updateLabels(tIndex,c){

if (exception==false)

{

if (c==state+1)
{
state=c;
upd=true;
}        
else 
{
upd=false;
state=state
}

if (tIndex!=-1)
{
  if (c<10)
  {
  labelText+="<tr>";
  
  if (upd)
  {
  labelText+="<td width=10% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+="<strong>Vraag "+(c+1)+" :</strong>"; 
 
  astr='header0'+c; 
  labelText+="<td width=55% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>"
  labelText+="</td>";
  }
  else 
  {
  labelText+="<td width=10% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+="";
  labelText+="</div>"
  labelText+="</td>";
  labelText+="<td width=55% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+=""
  labelText+="</div>"
  labelText+="</td>";
  }
  
  
  
  
  astr='answer0'+c+tIndex;
  labelText+="<td width=35% valign='top' class='table_main'><div align='left'>";
  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>";
  labelText+="</td>";
  labelText+="</tr>";
  }
  else
  {
  labelText+="<tr>";
  labelText+="<td width=10% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+="<strong>Vraag "+(c+1)+" :</strong>"; 
  astr='header'+c;
  labelText+="</div>"
  labelText+="</td>";

  labelText+="<td width=55% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>"
  labelText+="</td>";
  
  astr='answer'+c+tIndex;
  labelText+="<td width=35% valign='top' class='table_main'><div align='left'>";
  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>";
  labelText+="</td>";
  labelText+="</tr>";
  }
}
else
{ 
  labelText+="<tr>";
  labelText+="<td width=10% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+="<strong>Vraag "+(c+1)+" :</strong>"; 
  if (c<10)  astr='header0'+c;
  else astr='header'+c;
  labelText+="</div>"
  labelText+="</td>";

  labelText+="<td width=55% valign='top' class='table_main_toprow'><div align='left'>";

  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>"
  labelText+="</td>";
  
 
  labelText+="<td width=35% valign='top' class='table_main'><div align='left'>";
  labelText+="<span class='style4'>werd niet beantwoord</span>";
  labelText+="</div>";
  labelText+="</td>";
  labelText+="</tr>";
} 
//alert(labelText);

}// end if exception 
else 
{
  if (i==14)
  {
  labelText+="<tr>";
  labelText+="<td width=10% valign='top' class='table_main_toprow'><div align='left'>";
  labelText+="<strong>Vraag 1 :</strong>"; 
  labelText+="</div>"
  labelText+="</td>";
  
  labelText+="<td width=55% valign='top' class='table_main_toprow'><div align='left'>";
  astr='header00';
  labelText+=document.getElementById(astr).innerHTML;
  labelText+="</div>"
  labelText+="</td>";
  
  labelText+="<td width=35% valign='top' class='table_main'><div align='left'>";
  astr='answer000';
  labelText+=document.getElementById(astr).innerHTML;
  labelText+='<p>'
  labelText+="<span class='style4'>Voor minderjarigen hanteren we altijd een conservatief profiel</span>";
  labelText+='</p>';
  labelText+="</div>";
  labelText+="</td>";
  labelText+="</tr>";
  }
}


return labelText; 
}


function reportScore() {
var finalResult=updateScore(0);
var testProfile=-1;
var correctedProfile=-1;
var out="";

var profileDescription=new Array()

profileDescription[0]='ONBEPAALD';
profileDescription[1]='CONSERVATIEVE BELEGGER';
profileDescription[2]='DEFENSIEVE BELEGGER';
profileDescription[3]='NEUTRALE BELEGGER';
profileDescription[4]='DYNAMISCHE BELEGGER';
profileDescription[5]='OFFENSIEVE BELEGGER';


// TESTDATA

//out+='<div id="testdata">';
//out+='<strong>Uw totale score bedraagt: '+finalResult+' op een maximum van 101 </br></br></strong>'; 

if (finalResult>=0 && finalResult <=32) {testProfile=1;}
if (finalResult>32 && finalResult<=48)  {testProfile=2;}
if (finalResult>48 && finalResult<=74)  {testProfile=3;}
if (finalResult>74 && finalResult<=90)  {testProfile=4;}
if (finalResult>90) {testProfile=5;}

correctionIndex=getSelectedRadio(eval('document.Beleggerstest.question05'))

//out+='<h3>Correctiefactor is: '+correctionIndex+'</h3></br>';

correctedProfile=testProfile;

if (correctionIndex==0) {correctedProfile=testProfile;} 
if (correctionIndex==1) {correctedProfile=Math.min(testProfile,4);} 
if (correctionIndex==2) {correctedProfile=Math.min(testProfile,3)} 
if (correctionIndex==3) {correctedProfile=Math.min(testProfile,2);} 


//out+='<strong>profiel volgens enquête is: '+ profileDescription[testProfile]+'</strong></br></br>';
//out+='<strong>(bovenstaande gegevens worden enkel vermeld in de testomgeving)</strong></br><a href="#" onclick=document.getElementById("testdata").style.display="none"> //VERBERG DE TESTGEGEVENS </a></br></br>';
//out+='</div>'


// END TESTDATA




out+='<table border=0  align="center" cellpadding="2" cellspacing="1" class="table_header_actie">';
out+='<tr>';
out+='<td align="center">';
// Gecorrigeerd profiel (met beperking vraag 6) is
out+='UW PROFIEL: '+ profileDescription[correctedProfile]+'';
out+='</td>';
out+='</tr>';
out+='<tr>';
out+='<td class="table_main_actie">';
out+=''+profiles[correctedProfile]+'';
out+='</td>';
out+='</tr>';
out+='</table>';

out+='</br></br>';
out+='<p><strong>Uw antwoorden:</strong></p>';
out+="<table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_content'>";
out+=labelText;
out+='</table>'
document.getElementById('beleggersProfiel').innerHTML=out;
score=0;
labelText="";
state=-1;
upd=true;
exception=false;
}

function updateScore(ctr){
if (exception==false)
{
score+=ctr;
}
//*************************alert(score);
return score;
}

function validateTest() {
score=0;
var errorDetected=false;
var tmp=" ";
   for (i=0;i<15;i++) {
      if (i<10) {
      str='question0'+i+'0';
      } 
      else {
      str='question'+i+'0';
      }
      if (document.getElementById(str)) {

          if (i<10) {

          if (i!=8){

		  
           tmp=getSelectedRadioValue(eval('document.Beleggerstest.question0'+i))
		   labelIndex=getSelectedRadio(eval('document.Beleggerstest.question0'+i))
		   
		   if ((i==0) && (labelIndex==0))
		   {
		   exception=true;
		   }
		   
		   updateLabels(labelIndex,i);
		   //*************************alert(tmp);
		   //****UPDATE SCORE
		   if (tmp!="") updateScore(eval(tmp));
          }
          else {
		   tmp=getSelectedCheckboxValue(eval('document.Beleggerstest.question0'+i));
		   labelIndexArray=getSelectedCheckbox(eval('document.Beleggerstest.question0'+i));
		   //alert(labelIndexArray);
		   labelIndexArray.reverse();
		   anArrayLength=labelIndexArray.length;
		   //alert(labelIndexArray);
		   aResult=0;
		   do
		   {
		   aValue=eval(tmp.pop());
		   aLabelIndex=eval(labelIndexArray.pop());
		   if (anArrayLength>0) {updateLabels(aLabelIndex,i);} else  {updateLabels(-1,i);}
		   aResult+=aValue;
		   //*************************alert('ArrayValue while counting='+aResult);
		   } 
		   while (tmp.length>0);
		   //*************************alert(tmp);
		   
		   var selItems = getSelectedCheckbox(eval('document.Beleggerstest.question0'+i));
		   aResult=Math.round(aResult/selItems.length);
		   //*************************alert('final value ='+aResult);
		   if (isNaN(aResult))
		   {
		   //****UPDATE SCORE
		   updateScore(0);
		   }
		   else
		   {
		   //****UPDATE SCORE
  		   updateScore(aResult);
		   }

		   
		  }
         }
         else {
         tmp=getSelectedRadioValue(eval('document.Beleggerstest.question'+i));
	     labelIndex=getSelectedRadio(eval('document.Beleggerstest.question'+i))
		 updateLabels(labelIndex,i);
		 //****UPDATE SCORE
		 if (tmp!="") updateScore(eval(tmp));
         }
     
	  //*************************alert('vraag'+(i+1)+"="+tmp);

      } // end if document.getEBID
	//if ((tmp=="") && (i!=8)) {alert('Gelieve alle vragen te beantwoorden.\nVraag '+(i+1)+' werd niet beantwoord.');errorDetected=true;break;}
  } // end for
if (errorDetected==false) reportScore();
} // end function 