var output='';
	var k=1;
	var e = 1;
	var c,y;
	var total=0;
	var score=0;
	var arrHeader= new Array;
	var flag_firstRadioButton= 0;   //flag for unchecking the radio buttons of the div which is hidden
	var flag_activeResult = 0;      // flag for displaying the result div   
	var flag_dottedline=0;         // flag for displaying the dotted line
	var flag_stopModel = 0;  
	var exportCodeString = '';   
	
	
	function  fillScreenContent_Step1()
	{ 
		currentStep = 1;
		document.getElementById('txtAnswerText').style.paddingRight ="4px";
		updateComponent('txtStep1_subHeading',strStep1_subHeading);
		if(strStep1_introTxt_1 == '')
			hideComponent('txtStep1_introTxt_1');
		else
			updateComponent('txtStep1_introTxt_1',strStep1_introTxt_1);
		
		updateComponent('imgtextResult_active',strLabel_imgtextResult);
		hideComponent('divanswer');
		hideQuestions();
	}   
	
	function hideQuestions()
	{
		var i=0;
		
		{
			var t=1;
			var o=1;
		
		while(i<Generic_Array.length)
		{	
			i=i+1; //NoOfParentQt
			
			if(i!=0)
			{	
				hideComponent('questiongroup'+o+'highlighted');
				unhideComponent('questiongroup'+o);
				hideComponent('imgtext'+o+'_active');
				unhideComponent('imgtext'+o+'_inactive');
			}
			o++;
			var NoOfParentQts = Generic_Array[i];
			
			for(j=1;j<=NoOfParentQts;j++)
			{	
				i=i+2;  //NoOfSubQt
				var NoOfSubQt = Generic_Array[i];
				var a=t.toString();
				if(a.length==1)
					a=0+a; 
				if('divradiogrp'+a != 'divradiogrp01')
				{	
					hideComponent('divradiogrp'+a);
					hideComponent('dottedline'+a);
				}
				i=i+2;  //NoOfOptions
				i=i+Generic_Array[i]*2; //End score
				
				var code=AsciiCode;
				//to hide sub qts 
				for(l=1;l<=NoOfSubQt;l++)
				{
					var subqt_id =String.fromCharCode(code);
					code++; 
					i=i+2;
					hideComponent('divradiogrp'+a+subqt_id);
					hideComponent('dottedline'+a+subqt_id);
					i=i+2;  //NoOfOptions
					i=i+Generic_Array[i]*2; //End score
				}		
				t++;
			}
		}
   }
    unhideComponent('imgtext1_active');
	
	}

	function createDynamicDiv()
	{
		var value = 0;
		var i=0;
		var p=0;
		while(i<Generic_Array.length)
		{	
			flag_dottedline =1;
			arrHeader[p]=k-1;            //last parent question of the header
			value = div1(i);   
			i = i + value+1;	
			p++;
			if(i+3 > Generic_Array.length)   //last header
				break;
		}
	
	return document.write(output);
	}
	
	
	function div1(l)
	{	
		var t=l;  
		
		if(l == 0)    // header above the 1st parent question
		{	
			output+='<div style="margin-bottom:31px;">';
			output+='<img src="/nl/images/Systeem/abnamroNL/Content/includes/images/System/Includes/gfx/green-header_HOOG.gif" style="position:relative;" name="questiongroup'+e+'" id="questiongroup'+e+'" />';
			output+='<div style="position:relative;z-index:10; margin-left:14px; margin-top:-27px;">';
			output+='<h3 id="imgtext'+e+'_active" style="position:absolute;left:-1px;text-align:left; color:#F3F3F3; font-size:12px; padding-left:0px;background:none;font-family:verdana;">'+Generic_Array[l]+'</h3>';
			output+='</div>';
			output+='</div>';
			
		}
		
		else           //Header above the parent questions other than the 1st parent qt
		{	
			output+='<div style="padding-bottom:34px;">';
			output+='<img src="/nl/images/Systeem/abnamroNL/Content/includes/images/System/Includes/gfx/grey-header_HOOG.gif" style="position:relative;" name="questiongroup'+e+'" id="questiongroup'+e+'" />';
			output+='<div style="position:relative;z-index:10;margin-left:14px; margin-top:-27px;">';
			output+='<h3 id="imgtext'+e+'_inactive" style="position:absolute;color:#005b5d;z-index:1; text-align:left; font-size:12px;left:-1px; padding-left:0px;background:none;font-family:verdana;">'+Generic_Array[l]+'</h3>';
			output+='</div>';
													  
			output+='<img src="/nl/images/Systeem/abnamroNL/Content/includes/images/System/Includes/gfx/green-header_HOOG.gif" style="position:relative;padding-top:15px;" name="questiongroup'+e+'highlighted" id="questiongroup'+e+'highlighted" />';
			output+='<div style="position:relative;z-index:10; margin-left:14px; margin-top:-27px;">';
			output+='<h3 id="imgtext'+e+'_active" style="position:absolute;z-index:1;left:-1px;color:#F3F3F3;text-align:left; font-size:12px; padding-left:0px;background:none;font-family:verdana;">'+Generic_Array[l]+'</h3>';
			output+='</div>';
			output+='</div>';	
		}
		e++;
		l=l+1;   //no of parent qts 
	    var value1 = 0;
		//loop for parent qt
		var NoOfParentQts = Generic_Array[l];
		for(j=1;j<=NoOfParentQts;j++)
		{ 
			var a=k.toString();
			if(a.length==1)
				a=0+a;     
			value1 =  div2(l,a);		
			l = l + value1; 	
			k=k+1;
		}
		t = l-t;
		return t;
	}
	
	function div2(m,id)
	{
		var u=m;  
		m=m+1; //parent qt   
		if(flag_dottedline == 0)    //display dotted line only if value of flag is 0
		{
			output+='<div class="dottedlinebottom" style="margin-left:1px;margin-bottom:15px;';
			if(navigator.appName == "Microsoft Internet Explorer")
			{
				output+='margin-top:-18px;" id="dottedline'+id+'">';
			}
			else
			{
				output+='margin-top:-8px;" id="dottedline'+id+'">';
			}
			output+='</div>';
		}
		else
		{
			flag_dottedline = 0;
		}
		output+='<div id="divradiogrp'+id+'" class="answers clearfix" style="margin-left:-12px;position:relative:z-index:-1;" >';
		//parent question text
		output+='<span id="lblradiogrp'+id+'" style="width:701px;margin-bottom:2px;margin-top:-2px;font-family:Verdana;">'+Generic_Array[m]+'</span>'; 
		m=m+1; //no of sub qt 
		var NoOfSubQt=Generic_Array[m];
		
		var p;
		m=m+1;  //flag for hiding the next independent sub-question
		var flag_HidingSubQt = Generic_Array[m];
		m=m+1; //no of options
		var NoOfOptions = Generic_Array[m];
		
		var code=AsciiCode;
		//loop for displaying options
		for(s=1;s<=NoOfOptions;s++)
		{	
			var count;
			var subqt_id =String.fromCharCode(code);
		    code++; 
			m=m+1;
			count = Generic_Array[m+1];
			output+='<input style="height:17px;margin-left:51px;margin-top:2px;" type="radio" id="question'+id+subqt_id+'" class="radiobttns" flag='+flag_HidingSubQt+' labelId="lblradiogrp'+id+subqt_id+'" name="vraag'+id+'" value="'+count+'" onclick="javascript:showForm(\''+id+'\',\''+s+'\',\'question'+id+subqt_id+'\');"  /><label style="width:635px;font-weight:normal;margin-left:4px;" for="question'+id+subqt_id+'" class="radiobttns_txt" id="lblradiogrp'+id+subqt_id+'">'+Generic_Array[m]+'</label>';
			output+='<br />';
			m=m+1;
			
		}
		
		output+='</div>';
		
		var value2=0;
		var code=AsciiCode;
		//loop for displaying subqt 
		for(p=1;p<=NoOfSubQt;p++)
		{  
		   
		   var subqt_id =String.fromCharCode(code);
		   value2 = div2(m,id+subqt_id);
		   m=m+value2;
		   code++; 
		}
		u = m-u;
		return u;	
	}
	
	
	function showForm(id,option,subid)
	{	
		var subid1=subid.substring(10,11);
		var countDiv = 0;
		var label_id = document.getElementById(subid).getAttribute('labelId');
		if(id == '01' && document.getElementById(label_id).innerHTML == "Nee" && flag_Hide_Unhide_StopModel == 0)//to display the stop model if qt 1 is answered with "Nee"
		{		
				
				hideQuestions();
				var node,nodes;
				var div = document.getElementById('interactie_SSForm_Step1');
				nodes = div.getElementsByTagName('input');
				
				var i = nodes.length;
				while (i--)
				{
					node = nodes[i];
					if (node.getAttribute('type') == "radio" && node.id != 'question01a' && node.id != 'question01b' ) //uncheck the radio buttons of the div which should be hidden
					{
							
							document.getElementById(node.id).checked = false;
							
					}
				}
				unhideComponent('divanswer');
				updateComponent('txt_AnswerHeading',strLabel_StopModelHeading);
				updateComponent('txtAnswerText',strLabel_StopModelText);
				if(flag_StopModelButton == 1) 	//if value of flag is 1 in case of result 1,show button else hide button
				{
					unhideComponent('GenericButton');
						
				}
				else
					hideComponent('GenericButton');
				document.getElementById('divtextanswer').style.backgroundColor='#e7e8d7';
				flag_activeResult = 0;
				document.getElementById('GenericButton').src = ButtonImage_StopModel ;
				document.getElementById('GenericButton').title=strText_StopModelButtonAlt;
				flag_stopModel = 1;
				document.getElementById('divanswer').style.position = '';
				setTimeout("document.getElementById('divanswer').style.position = 'relative'",1);
				setTimeout("document.getElementById('divanswer').style.position = ''",100);
				setTimeout("document.getElementById('divanswer').style.position = 'relative'",100);
		}
				
		else  //normal flow of questions
		{	
			flag_stopModel = 0;
			flag_hideDottedLine = 0;
			var flag_hideSubQt = document.getElementById(subid).getAttribute('flag');
			if(flag_activeResult == 0)  
			{
				hideComponent('divanswer');
			}
			if(id.length>2)    //Sub question exists for the parent qt
			{		
					var numOption=id.substring(0,2);
					if(numOption == (k-1))     //Last sub question before displaying the result
					{
						
						flag_activeResult=1;      
					}
					skipNextQuestion(option,flag_hideDottedLine,id,flag_hideSubQt);
			}
			
			else    //Not a  subqt
			{	
			
				countDiv = getNoOfSubQts(id);
				
				if(countDiv > 1)   //sub qt is present
				{
					hideUnhideSubQt(option,countDiv,id,flag_hideSubQt);
					//unhideComponent('divradiogrp'+a);
				}
				else  //no subqt(only independent question)
				{	
					skipNextQuestion(option,flag_hideDottedLine,id,flag_hideSubQt);
					
				}
				
				var numOption = parseFloat(id);
				if(numOption == (k-1) && countDiv == 1)
				{
					flag_activeResult=1;
				}
				
				if(numOption==01 && flag_firstRadioButton == 0)  //uncheck the radio button of the div which is hidden
				{
					flag_firstRadioButton=1;
					var node,nodes;
					var div = document.getElementById('interactie_SSForm_Step1');
					
			
					nodes = div.getElementsByTagName('input');
					
					var i = nodes.length;
					while (i--)
					{
						node = nodes[i];
						var check_idVal = node.id.substring(8,10);
						if (node.getAttribute('type') == "radio" )
						{
							if(check_idVal != '01' || node.id.length>11)
								document.getElementById(node.id).checked = false;
						}
					}
				}
			}
			
			if(flag_activeResult==1)  
			{	
				calculateScore(id);
			}
		}
	}
	
		function getNoOfSubQts(id)
		{
				var countDiv=0;
				var node, nodes;
				var div = document.getElementById('divGeneric');
				nodes = div.getElementsByTagName('div');
				var i = nodes.length;
				
				while (i--)
				{
					node = nodes[i];
					if (node.id.substring(0,11) =='divradiogrp' && node.id.substring(11,13) == id) 
					{
						countDiv++;
					}
				   
				}
			return countDiv;	
		}
		
		function hideUnhideSubQt(option,countDiv,id,flag_hideSubQt)
		{
					var code=AsciiCode;
			
					for(p=1;p<countDiv;p++)
					{  
						var subqt_id =String.fromCharCode(code);
						
						if(p==option && !(((countDiv-1) == option) && (flag_hideSubQt == 1)))
						{	
							unhideComponent('divradiogrp'+id+subqt_id);
							unhideComponent('dottedline'+id+subqt_id);
						}	
						else
						{
							
							var subnode,subnodes;
							
							var subdiv = document.getElementById('divradiogrp'+id+subqt_id);
							
							subnodes = subdiv.getElementsByTagName('input');
							var i = subnodes.length;
							
							while (i--)
							{
								subnode = subnodes[i];
								document.getElementById(subnode.id).checked = false;
							}
							hideComponent('divradiogrp'+id+subqt_id);
							hideComponent('dottedline'+id+subqt_id);
						
						}
						code++; 
					}
					if(((countDiv-1) == option) && (flag_hideSubQt == 1))
						{	
							var numOption = parseFloat(id);
							
							for(i=2;i<=arrHeader.length;i++)
							{	
								
								if(numOption == arrHeader[i-1]) //Header should be displayed if this condition is true
								{
									
									unhideComponent('questiongroup'+i+'highlighted');
									hideComponent('questiongroup'+i);
									hideComponent('imgtext'+i+'_inactive');
									unhideComponent('imgtext'+i+'_active');
									
								}
							}
							var val1=numOption;
							numOption = numOption +1;
							var a=numOption.toString();
							if(a.length==1)
								a=0+a;
						
							unhideComponent('divradiogrp'+a);
							unhideComponent('dottedline'+a);
						}
	}				
		
		function skipNextQuestion(option,flag_hideDottedLine,id,flag_hideSubQt,subid)
		{
						var numOption = parseFloat(id);
					
						for(i=2;i<=arrHeader.length;i++)
						{	
							if(numOption == arrHeader[i-1]) //Header should be displayed if this condition is true
							{
								unhideComponent('questiongroup'+i+'highlighted');
								hideComponent('questiongroup'+i);
								hideComponent('imgtext'+i+'_inactive');
								unhideComponent('imgtext'+i+'_active');
								
							}
						}
					
						var subnode,subnodes;
						var subdiv = document.getElementById('divradiogrp'+id);
						subnodes = subdiv.getElementsByTagName('input');
						
						var i = subnodes.length;
						
					
						if(i == option && flag_hideSubQt == 1 && numOption != (k-1))  //to hide immediate independent sub-qt
						{		
							var val = id.substring(0,2);	
							for(i=2;i<=arrHeader.length;i++)  
							{	
								
								if(val == arrHeader[i-1])    //Header should be displayed if this condition is true,if this is the last question 
															 //in a particular header group
								{
									unhideComponent('questiongroup'+i+'highlighted');
									unhideComponent('imgtext'+i+'_active');
									hideComponent('questiongroup'+i);
									hideComponent('imgtext'+i+'_inactive');	
									flag_hideDottedLine = 1;
								}
							}
							val=parseFloat(val)+parseFloat(1);
							
							if(flag_hideDottedLine == 0)
							{	
								for(i=2;i<=arrHeader.length;i++)  
								{	
									if(val == arrHeader[i-1])    //Header should be displayed if this condition is true
									{							//if this is the 2nd last qt in a particular header group
										unhideComponent('questiongroup'+i+'highlighted');
										unhideComponent('imgtext'+i+'_active');
										hideComponent('questiongroup'+i);
										hideComponent('imgtext'+i+'_inactive');	
									}
								}
								var m=val.toString();
								if(m.length == 1)
									m=0+m;	
								
								hideComponent('divradiogrp'+m);
								
								hideComponent('dottedline'+m);
								if(val == (k-1))     //Last sub question before displaying the result
								{
									
									flag_activeResult=1;      
								}
								var subnode,subnodes,subdiv1;
								var subdiv1 = document.getElementById('divradiogrp'+m);
								
								if(subdiv1 != null)
								{
									subnodes = subdiv1.getElementsByTagName('input');
								
								
									var i = subnodes.length;
									while (i--)
									{
										subnode = subnodes[i];
										if (subnode.getAttribute('type') == "radio")
										{
												
											document.getElementById(subnode.id).checked = false;
												
										}
									}
								}	
								numOption = numOption +1;
								var m=numOption.toString();
								if(m.length == 1)
									m=0+m;
								countDiv = getNoOfSubQts(m);
				
								if(countDiv > 1)   //sub qt is present
								{
									hideUnhideSubQt(option,countDiv,m,flag_hideSubQt);
								
								}
								
							
							}
						}
						
						var val1=numOption;
						numOption = numOption +1;
						
						var a=numOption.toString();
						if(a.length==1)
							a=0+a;
						
						unhideComponent('divradiogrp'+a);
						unhideComponent('dottedline'+a);
	}					
		
		function calculateScore(id)
	{	
		score=0;
		var i=0;
		
		var t=1;//for id
		 exportCodeString = '';
		 
		while(i<Generic_Array.length)
		{	
			i=i+1; //NoOfParentQt
			
			var NoOfParentQts = Generic_Array[i];
			
			for(j=1;j<=NoOfParentQts;j++)  //for parent qts with no sub qts
			{	
				i=i+2;  //NoOfSubQt
				var NoOfSubQt = Generic_Array[i];
				var a=t.toString();
				if(a.length==1)
				{
					a=0+a; 	
				}
						var node  , nodes;
						var div = document.getElementById('divradiogrp'+a);
						nodes = div.getElementsByTagName('input');
						var i2 = nodes.length;
						var inputName ='';
						
						while (i2--)
						{
							
							node = nodes[i2];
							
							if(inputName != node.name)
							{
								
								var value = getRadioValue(document.getElementsByName(node.name));
								if(value!='')
								{	
									score=score+parseFloat(value);
									
								}
							}
							if(document.getElementById(node.id).checked == true)
							{
								
									var code1 = AsciiCode;
							
									var temp =node.id.substring(10,11);
									var num;
									for (num = AsciiCode; num < 123; num++)
									{
										var val=String.fromCharCode(num);
										
										if (val == temp)
										{
											
											var val1 = num - (code1-1);
											val1 = val1.toString();
											if(val1.length==1)
											{
														val1=0+val1; 	
											}
											
											exportCodeString += 'q'+ node.id.substring(8,10) +'='+ val1 +'&';
											break;
										}	
									}
							}
								
							inputName = node.name;
						}
				
				i=i+2;  //NoOfOptions
				
				i=i+Generic_Array[i]*2; //Points
				var code=AsciiCode;
				for(l=1;l<=NoOfSubQt;l++)  //for subqt
				{
					var subqt_id =String.fromCharCode(code);
					code++; 
					i=i+2;
					var node1  , nodes1;
						var div1 = document.getElementById('divradiogrp'+a+subqt_id);
						
						nodes1 = div1.getElementsByTagName('input');
						var i1 = nodes1.length;
						var inputName1 ='';
						while (i1--)
						{
							
							node1 = nodes1[i1];
							
							if(inputName1 != node1.name)
							{
								var value = getRadioValue(document.getElementsByName(node1.name));
								if(value!='')
								{	
									score=score+parseFloat(value);
									
								}
							}
							
						if(document.getElementById(node1.id).checked == true)
							{
									var code1 = AsciiCode;
							
									var temp =node1.id.substring(11,12);
								
									var num;
									for (num = AsciiCode; num < 123; num++)
									{
										var val=String.fromCharCode(num);
										
										if (val == temp)
										{
											
											var val1 = num - (code1-1);
											val1 = val1.toString();
											if(val1.length==1)
											{
														val1=0+val1; 	
											}
											
											exportCodeString += 'q'+ node1.id.substring(8,11) +'='+ val1 +'&';
											break;
										}									
									}
							}
						inputName1 = node1.name;
						}
				
					
					i=i+2;  //NoOfOptions
					i=i+Generic_Array[i]*2; //Points
				}		
				t++;
			}
		
   }
  
   var x=0;
  
 
  while(x < (Result_Array.length-1))
   {
		if(score>=Result_Array[x] && score<=Result_Array[x+1])  //display no-advice
		{	
			unhideComponent('divanswer');
			updateComponent('txt_AnswerHeading',Result_Array[x+2]);	
			updateComponent('txtAnswerText',Result_Array[x+4]);
			document.getElementById('divtextanswer').style.backgroundColor='#e7e8d7';
			document.getElementById('GenericButton').src = Result_Array[x+5] ;
			document.getElementById('GenericButton').title=Result_Array[x+6];
			if(Result_Array[x+3] == 1)      //if value of flag is 1 in case of result 1,show button else hide button
			{
				unhideComponent('GenericButton');
				
			}
			else
				hideComponent('GenericButton');
		    break;
			
		}
		else
			hideComponent('divanswer');
		x=x+8;
		
		}
	
	}
	function gotoOnlineForm()
	{	
		var x=0;
		if(typeof(strExportCode_ModelName) !="undefined" )
			exportCodeString += 'form=' + strExportCode_ModelName ; 
		if(flag_stopModel == 1)	
		{
			if(strOnlineForm_StopModel != '')
				location.href = strOnlineForm_StopModel + '?' + exportCodeString;
		}	
		else
		{	
			 while(x < Result_Array.length)
			 {
			 
			if(score>=Result_Array[x] && score<=Result_Array[x+1])
			{
				if(Result_Array[x+7] != '')
					location.href = Result_Array[x+7] + '?' + exportCodeString;
			}
		
			x=x+8;
			
		}	
		
	}
	return false;
	}
